@@ -146,7 +146,7 @@ describe('updateAgentConfiguration', () => {
146146 } ;
147147
148148 test ( 'reuses the registry PATCH route for runtime controls and full env specs' , async ( ) => {
149- const client = { patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
149+ const client = { get : jest . fn ( async ( ) => ( { writablePodId : 'pod-9' } ) ) , patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
150150 const environment = {
151151 version : 1 ,
152152 workspace : { path : './workspace' } ,
@@ -179,7 +179,7 @@ describe('updateAgentConfiguration', () => {
179179 } ) ;
180180
181181 test ( 'keeps the complete provider block local while PATCHing environment fields' , async ( ) => {
182- const client = { patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
182+ const client = { get : jest . fn ( async ( ) => ( { writablePodId : 'pod-9' } ) ) , patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
183183 const environment = {
184184 model : 'gpt-5.4' ,
185185 provider : {
@@ -199,7 +199,7 @@ describe('updateAgentConfiguration', () => {
199199 } ) ;
200200
201201 test ( 'refuses provider configuration when the local token record is not OpenCode-bound' , async ( ) => {
202- const client = { patch : jest . fn ( ) } ;
202+ const client = { get : jest . fn ( async ( ) => ( { writablePodId : 'pod-9' } ) ) , patch : jest . fn ( ) } ;
203203 await expect ( updateAgentConfiguration ( {
204204 client,
205205 record,
@@ -215,7 +215,7 @@ describe('updateAgentConfiguration', () => {
215215 } ) ;
216216
217217 test ( 'agent config writes the adapter binding explicitly' , async ( ) => {
218- const client = { patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
218+ const client = { get : jest . fn ( async ( ) => ( { writablePodId : 'pod-9' } ) ) , patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
219219 const adapterRegistry = {
220220 listAdapterNames : ( ) => [ 'opencode' ] ,
221221 getAdapter : ( ) => ( { detect : async ( ) => ( { path : '/bin/opencode' , version : '1.18.35' } ) } ) ,
@@ -228,17 +228,17 @@ describe('updateAgentConfiguration', () => {
228228 } ) ;
229229
230230 test ( 'rejects an empty edit and an incomplete token record before making a request' , async ( ) => {
231- const client = { patch : jest . fn ( ) } ;
231+ const client = { get : jest . fn ( async ( ) => ( { writablePodId : 'pod-9' } ) ) , patch : jest . fn ( ) } ;
232232 await expect ( updateAgentConfiguration ( { client, record } ) ) . rejects . toThrow ( / a t l e a s t o n e / ) ;
233233 await expect ( updateAgentConfiguration ( { client, record, effort : 'turbo' } ) )
234234 . rejects . toThrow ( / e f f o r t m u s t b e o n e o f / ) ;
235- await expect ( updateAgentConfiguration ( { client, record : { agentName : 'juno ' } , model : 'opus' } ) )
236- . rejects . toThrow ( / p o d I d / ) ;
235+ await expect ( updateAgentConfiguration ( { client, record : { podId : 'pod-9 ' } , model : 'opus' } ) )
236+ . rejects . toThrow ( / a g e n t N a m e / ) ;
237237 expect ( client . patch ) . not . toHaveBeenCalled ( ) ;
238238 } ) ;
239239
240240 test ( 'updates an existing declared environment when only model/effort flags change' , async ( ) => {
241- const client = { patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
241+ const client = { get : jest . fn ( async ( ) => ( { writablePodId : 'pod-9' } ) ) , patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
242242 const localRecord = {
243243 ...record ,
244244 environment : {
@@ -255,7 +255,7 @@ describe('updateAgentConfiguration', () => {
255255 } ) ;
256256
257257 test ( 'materializes runtime edits into the declared environment when none exists' , async ( ) => {
258- const client = { patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
258+ const client = { get : jest . fn ( async ( ) => ( { writablePodId : 'pod-9' } ) ) , patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
259259 const result = await updateAgentConfiguration ( { client, record, model : 'new-model' , effort : 'high' } ) ;
260260 expect ( result . environment ) . toEqual ( { model : 'new-model' , effort : 'high' } ) ;
261261 expect ( client . patch . mock . calls [ 0 ] [ 1 ] . config ) . toEqual ( {
@@ -265,7 +265,7 @@ describe('updateAgentConfiguration', () => {
265265 } ) ;
266266
267267 test ( 'validates and persists a detected adapter without leaking it into ADR-008 environment' , async ( ) => {
268- const client = { patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
268+ const client = { get : jest . fn ( async ( ) => ( { writablePodId : 'pod-9' } ) ) , patch : jest . fn ( async ( ) => ( { success : true } ) ) } ;
269269 const adapter = { detect : jest . fn ( async ( ) => ( { path : '/usr/local/bin/claude' } ) ) } ;
270270 const result = await updateAgentConfiguration ( {
271271 client,
@@ -288,7 +288,7 @@ describe('updateAgentConfiguration', () => {
288288 } ) ;
289289
290290 test ( 'rejects an unknown or unavailable adapter before PATCH' , async ( ) => {
291- const client = { patch : jest . fn ( ) } ;
291+ const client = { get : jest . fn ( async ( ) => ( { writablePodId : 'pod-9' } ) ) , patch : jest . fn ( ) } ;
292292 const adapter = { detect : jest . fn ( async ( ) => null ) } ;
293293 const adapterRegistry = {
294294 getAdapter : jest . fn ( ( name ) => ( name === 'claude' ? adapter : null ) ) ,
@@ -300,6 +300,43 @@ describe('updateAgentConfiguration', () => {
300300 . rejects . toThrow ( / n o t f o u n d o n P A T H / ) ;
301301 expect ( client . patch ) . not . toHaveBeenCalled ( ) ;
302302 } ) ;
303+ test ( 'resolves a managed seat from the server source instead of its attention pod' , async ( ) => {
304+ const client = {
305+ get : jest . fn ( async ( ) => ( { runtimeManaged : true , runtimeSourcePodId : 'source-pod' , writablePodId : 'other-pod' } ) ) ,
306+ patch : jest . fn ( async ( ) => ( { } ) ) ,
307+ } ;
308+ const result = await updateAgentConfiguration ( { client, record, model : 'new-model' } ) ;
309+ expect ( client . get ) . toHaveBeenCalledWith ( '/api/registry/agents/juno/manage-settings?instanceId=writer' ) ;
310+ expect ( client . patch . mock . calls [ 0 ] [ 0 ] ) . toBe ( '/api/registry/pods/source-pod/agents/juno' ) ;
311+ expect ( result . podId ) . toBe ( 'source-pod' ) ;
312+ } ) ;
313+
314+ test ( 'a stale or absent local pod is not used when the server has a writable installation' , async ( ) => {
315+ const client = {
316+ get : jest . fn ( async ( ) => ( { writablePodId : 'real-pod' } ) ) ,
317+ patch : jest . fn ( async ( ) => ( { } ) ) ,
318+ } ;
319+ await updateAgentConfiguration ( { client, record : { ...record , podId : undefined } , model : 'new-model' } ) ;
320+ expect ( client . patch . mock . calls [ 0 ] [ 0 ] ) . toBe ( '/api/registry/pods/real-pod/agents/juno' ) ;
321+ } ) ;
322+
323+ test . each ( [
324+ { } ,
325+ { writablePodId : null } ,
326+ { runtimeManaged : true , runtimeSourcePodId : null , writablePodId : 'other-pod' } ,
327+ ] ) ( 'refuses a missing server target without PATCHing the token pod: %j' , async ( settings ) => {
328+ const client = { get : jest . fn ( async ( ) => settings ) , patch : jest . fn ( ) } ;
329+ await expect ( updateAgentConfiguration ( { client, record, model : 'new-model' } ) )
330+ . rejects . toThrow ( / N o w r i t a b l e r u n t i m e i n s t a l l a t i o n / ) ;
331+ expect ( client . patch ) . not . toHaveBeenCalled ( ) ;
332+ } ) ;
333+
334+ test ( 'a failed installation lookup never falls back to the token pod' , async ( ) => {
335+ const client = { get : jest . fn ( async ( ) => { throw new Error ( 'Forbidden' ) ; } ) , patch : jest . fn ( ) } ;
336+ await expect ( updateAgentConfiguration ( { client, record, model : 'new-model' } ) ) . rejects . toThrow ( 'Forbidden' ) ;
337+ expect ( client . patch ) . not . toHaveBeenCalled ( ) ;
338+ } ) ;
339+
303340} ) ;
304341
305342const makeClient = ( { publishOk = true , runtimeToken = null } = { } ) => {
0 commit comments