@@ -135,4 +135,49 @@ describe("syncMemoryWikiUnsafeLocalSources", () => {
135135 "# very private" ,
136136 ) ;
137137 } ) ;
138+
139+ it ( "preserves imported pages when configured path becomes transiently unavailable" , async ( ) => {
140+ // Use a nested path where the parent becomes empty after removal,
141+ // simulating a NAS mount point or removable drive being undocked.
142+ const mountPoint = nextCaseRoot ( "nas-mount" ) ;
143+ await fs . mkdir ( mountPoint , { recursive : true } ) ;
144+ const sourceDir = path . join ( mountPoint , "source" ) ;
145+ await fs . mkdir ( sourceDir , { recursive : true } ) ;
146+ const filePath = path . join ( sourceDir , "notes.md" ) ;
147+ await fs . writeFile ( filePath , "# my notes\n" , "utf8" ) ;
148+
149+ const { rootDir : vaultDir , config } = await createVault ( {
150+ rootDir : nextCaseRoot ( "transient-vault" ) ,
151+ config : {
152+ vaultMode : "unsafe-local" ,
153+ unsafeLocal : {
154+ allowPrivateMemoryCoreAccess : true ,
155+ paths : [ sourceDir ] ,
156+ } ,
157+ } ,
158+ } ) ;
159+
160+ const first = await syncMemoryWikiUnsafeLocalSources ( config ) ;
161+ expect ( first . importedCount ) . toBe ( 1 ) ;
162+ expect ( first . removedCount ) . toBe ( 0 ) ;
163+ const firstPagePath = first . pagePaths [ 0 ] ?? "" ;
164+
165+ // Simulate the path becoming transiently unavailable (drive undocked, NAS
166+ // rebooting). Remove both sourceDir and mountPoint so the parent of the
167+ // configured path is inaccessible.
168+ await fs . rm ( mountPoint , { recursive : true , force : true } ) ;
169+ const second = await syncMemoryWikiUnsafeLocalSources ( config ) ;
170+ expect ( second . artifactCount ) . toBe ( 0 ) ;
171+ expect ( second . removedCount ) . toBe ( 0 ) ;
172+ await expect ( fs . readFile ( path . join ( vaultDir , firstPagePath ) , "utf8" ) ) . resolves . toContain (
173+ "# my notes" ,
174+ ) ;
175+
176+ // Restore the path — next sync should re-reconcile cleanly.
177+ await fs . mkdir ( mountPoint , { recursive : true } ) ;
178+ await fs . mkdir ( sourceDir , { recursive : true } ) ;
179+ await fs . writeFile ( filePath , "# my notes\n" , "utf8" ) ;
180+ const third = await syncMemoryWikiUnsafeLocalSources ( config ) ;
181+ expect ( third . removedCount ) . toBe ( 0 ) ;
182+ } ) ;
138183} ) ;
0 commit comments