@@ -310,6 +310,7 @@ describe("executor conflict-adopt", () => {
310310
311311 expect ( result . partial ) . toBe ( false ) ;
312312 expect ( memoryProvider . findResource ) . toHaveBeenCalledTimes ( 1 ) ;
313+ expect ( memoryProvider . findResource ) . toHaveBeenCalledWith ( "memory_store" , "notes" , undefined , "managed" ) ;
313314 expect ( memoryProvider . updateMemoryStore ) . toHaveBeenCalledWith (
314315 "memstore_same_name" ,
315316 { name : "notes" , description : "Updated notes" , metadata : { } } ,
@@ -323,6 +324,65 @@ describe("executor conflict-adopt", () => {
323324 expect ( state . getResource ( address ) ?. remote_id ) . toBe ( "memstore_same_name" ) ;
324325 } ) ;
325326
327+ test . each ( [
328+ true ,
329+ false ,
330+ ] ) ( "memory store conflict only searches the actual creation name (matching store exists: %p)" , async ( matchingStoreExists ) => {
331+ const memoryProvider = makeBailianMemoryProvider ( ) ;
332+ memoryProvider . createMemoryStore . mockRejectedValue ( new ConflictError ( 409 , "exists" , "Qoder API" ) ) ;
333+ const findResource = mock ( async ( _resourceType : string , resourceName : string ) : Promise < RemoteResource | null > => {
334+ if ( resourceName === "Shared notes" && matchingStoreExists ) {
335+ return { id : "memstore_shared" , type : "memory_store" } ;
336+ }
337+ if ( resourceName === "notes" ) {
338+ return { id : "memstore_unrelated" , type : "memory_store" } ;
339+ }
340+ return null ;
341+ } ) ;
342+ const provider = {
343+ ...memoryProvider . provider ,
344+ name : "qoder" ,
345+ supportsResourceNameLookup : ( ) => true ,
346+ findResource,
347+ } as unknown as ProviderAdapter ;
348+ const declaration : MemoryStoreDecl = { name : "Shared notes" , description : "Updated notes" } ;
349+ const memoryConfig : ProjectConfig = {
350+ version : "1" ,
351+ providers : { qoder : { } } ,
352+ defaults : { provider : "qoder" } ,
353+ memory_stores : { notes : declaration } ,
354+ } ;
355+ const address = { ...memoryStoreAddress , provider : "qoder" } ;
356+ const plan : ExecutionPlan = {
357+ actions : [ { ...memoryStorePlan ( "create" ) . actions [ 0 ] ! , address } ] ,
358+ diagnostics : [ ] ,
359+ } ;
360+ const state = StateManager . initialize ( tmpPath ( ) ) ;
361+ const result = await executePlan ( plan , {
362+ config : memoryConfig ,
363+ configPath : "/tmp/agents.yaml" ,
364+ providers : new Map ( [ [ "qoder" , provider ] ] ) ,
365+ state,
366+ } ) ;
367+
368+ expect ( memoryProvider . createMemoryStore ) . toHaveBeenCalledWith ( "Shared notes" , declaration , "managed" ) ;
369+ expect ( findResource ) . toHaveBeenCalledTimes ( 1 ) ;
370+ expect ( findResource ) . toHaveBeenCalledWith ( "memory_store" , "Shared notes" , undefined , "managed" ) ;
371+ expect ( result . partial ) . toBe ( ! matchingStoreExists ) ;
372+ if ( matchingStoreExists ) {
373+ expect ( memoryProvider . updateMemoryStore ) . toHaveBeenCalledWith (
374+ "memstore_shared" ,
375+ { name : "Shared notes" , description : "Updated notes" , metadata : { } } ,
376+ "managed" ,
377+ ) ;
378+ expect ( state . getResource ( address ) ?. remote_id ) . toBe ( "memstore_shared" ) ;
379+ } else {
380+ expect ( memoryProvider . updateMemoryStore ) . not . toHaveBeenCalled ( ) ;
381+ expect ( state . getResource ( address ) ) . toBeUndefined ( ) ;
382+ }
383+ expect ( memoryProvider . deleteMemoryStore ) . not . toHaveBeenCalled ( ) ;
384+ } ) ;
385+
326386 test ( "explicit sync memory store conflict reconciles seed entries without deleting learned memories" , async ( ) => {
327387 const calls : string [ ] = [ ] ;
328388 let storeMetadata : Record < string , string > | undefined ;
@@ -348,7 +408,7 @@ describe("executor conflict-adopt", () => {
348408 updated_at : "" ,
349409 } ;
350410 } ,
351- listMemories : async ( ) => ( {
411+ listMemories : mock ( async ( ) => ( {
352412 data : [
353413 {
354414 id : "mem_seed" ,
@@ -374,7 +434,7 @@ describe("executor conflict-adopt", () => {
374434 } ,
375435 ] ,
376436 has_more : false ,
377- } ) ,
437+ } ) ) ,
378438 updateMemory : async ( _storeId : string , id : string ) => {
379439 calls . push ( `update-memory:${ id } ` ) ;
380440 return { id, type : "memory" } ;
@@ -411,6 +471,11 @@ describe("executor conflict-adopt", () => {
411471 expect ( result . partial ) . toBe ( false ) ;
412472 expect ( calls ) . toEqual ( [ "update-store:memstore_existing" , "update-memory:mem_seed" ] ) ;
413473 expect ( storeMetadata ) . toEqual ( { } ) ;
474+ expect ( provider . listMemories ) . toHaveBeenCalledWith (
475+ "memstore_existing" ,
476+ expect . objectContaining ( { limit : 100 } ) ,
477+ "managed" ,
478+ ) ;
414479 } ) ;
415480
416481 test ( "ConflictError → findResource finds existing → onExisting rebuilds via updateEnvironment" , async ( ) => {
0 commit comments