@@ -675,10 +675,15 @@ describe("agents delete command", () => {
675675
676676 it ( "deregisters the agent database after offline deletion" , async ( ) => {
677677 await withStateDirEnv ( "openclaw-agents-delete-registry-" , async ( { tempRoot, stateDir } ) => {
678+ const mainAgentDir = path . join ( tempRoot , "main-agent" ) ;
678679 const cfg : OpenClawConfig = {
679680 agents : {
680681 list : [
681- { id : "main" , workspace : path . join ( stateDir , "workspace-main" ) } ,
682+ {
683+ id : "main" ,
684+ agentDir : mainAgentDir ,
685+ workspace : path . join ( stateDir , "workspace-main" ) ,
686+ } ,
682687 { id : "ops" , workspace : path . join ( stateDir , "workspace-ops" ) } ,
683688 ] ,
684689 } ,
@@ -687,23 +692,27 @@ describe("agents delete command", () => {
687692 const databasePath = path . join ( stateDir , "agents" , "ops" , "agent" , "openclaw-agent.sqlite" ) ;
688693 const externalDatabaseDir = path . join ( tempRoot , "external-databases" ) ;
689694 await fs . mkdir ( externalDatabaseDir ) ;
695+ await fs . mkdir ( mainAgentDir ) ;
690696 const externalDatabasePath = path . join ( externalDatabaseDir , "ops.sqlite" ) ;
691697 const sharedDatabasePath = path . join ( externalDatabaseDir , "shared.sqlite" ) ;
698+ const survivorOwnedDatabasePath = path . join ( mainAgentDir , "ops.sqlite" ) ;
692699 const externalDatabasePaths = [
693700 externalDatabasePath ,
694701 `${ externalDatabasePath } -wal` ,
695702 `${ externalDatabasePath } -shm` ,
696703 `${ externalDatabasePath } -journal` ,
697704 ] ;
698705 await Promise . all (
699- [ ...externalDatabasePaths , sharedDatabasePath ] . map ( ( sqlitePath ) =>
700- fs . writeFile ( sqlitePath , "" ) ,
706+ [ ...externalDatabasePaths , sharedDatabasePath , survivorOwnedDatabasePath ] . map (
707+ ( sqlitePath ) => fs . writeFile ( sqlitePath , "" ) ,
701708 ) ,
702709 ) ;
703710 const canonicalExternalDatabaseDir = await fs . realpath ( externalDatabaseDir ) ;
711+ const canonicalMainAgentDir = await fs . realpath ( mainAgentDir ) ;
704712 registerOpenClawAgentDatabase ( { agentId : "ops" , path : databasePath } ) ;
705713 registerOpenClawAgentDatabase ( { agentId : "ops" , path : externalDatabasePath } ) ;
706714 registerOpenClawAgentDatabase ( { agentId : "ops" , path : sharedDatabasePath } ) ;
715+ registerOpenClawAgentDatabase ( { agentId : "ops" , path : survivorOwnedDatabasePath } ) ;
707716 registerOpenClawAgentDatabase ( { agentId : "main" , path : sharedDatabasePath } ) ;
708717 recordAgentProvenance ( "ops" , { createdVia : "operator" } ) ;
709718 recordAgentProvenance ( "child" , { createdVia : "agent" , creatorAgentId : "ops" } ) ;
@@ -726,6 +735,11 @@ describe("agents delete command", () => {
726735 path . join ( canonicalExternalDatabaseDir , path . basename ( sharedDatabasePath ) ) ,
727736 expect . anything ( ) ,
728737 ) ;
738+ expect ( fsSafeMocks . movePathToTrash ) . not . toHaveBeenCalledWith (
739+ path . join ( canonicalMainAgentDir , path . basename ( survivorOwnedDatabasePath ) ) ,
740+ expect . anything ( ) ,
741+ ) ;
742+ expect ( ( await fs . stat ( survivorOwnedDatabasePath ) ) . isFile ( ) ) . toBe ( true ) ;
729743 const registeredDatabases = listOpenClawRegisteredAgentDatabases ( ) ;
730744 expect ( registeredDatabases . map ( ( entry ) => entry . agentId ) ) . not . toContain ( "ops" ) ;
731745 expect ( registeredDatabases ) . toEqual (
0 commit comments