@@ -206,6 +206,74 @@ describe("syncMemoryWikiUnsafeLocalSources", () => {
206206 ) . resolves . toContain ( "remember this" ) ;
207207 } ) ;
208208
209+ it ( "skips generated source pages copied into a configured path" , async ( ) => {
210+ const privateDir = await createPrivateDir ( "copied-vault" ) ;
211+ const sourcePaths = [
212+ path . join ( privateDir , "legitimate.md" ) ,
213+ path . join ( privateDir , "bridge-not-generated.md" ) ,
214+ path . join ( privateDir , "unsafe-local-not-generated.md" ) ,
215+ ] ;
216+ await Promise . all (
217+ sourcePaths . map ( ( sourcePath ) => fs . writeFile ( sourcePath , `# ${ path . basename ( sourcePath ) } \n` ) ) ,
218+ ) ;
219+ const { rootDir : vaultDir , config } = await createVault ( {
220+ rootDir : nextCaseRoot ( "copied-vault-target" ) ,
221+ config : {
222+ vaultMode : "unsafe-local" ,
223+ unsafeLocal : {
224+ allowPrivateMemoryCoreAccess : true ,
225+ paths : [ privateDir ] ,
226+ } ,
227+ } ,
228+ } ) ;
229+
230+ const first = await syncMemoryWikiUnsafeLocalSources ( config ) ;
231+ const generatedPage = first . pagePaths . find ( ( pagePath ) => pagePath . includes ( "legitimate-md" ) ) ;
232+ expect ( generatedPage ) . toBeDefined ( ) ;
233+ const copiedPage = path . join ( privateDir , "mirror" , generatedPage ! ) ;
234+ await fs . mkdir ( path . dirname ( copiedPage ) , { recursive : true } ) ;
235+ await fs . copyFile ( path . join ( vaultDir , generatedPage ! ) , copiedPage ) ;
236+
237+ const second = await syncMemoryWikiUnsafeLocalSources ( config ) ;
238+
239+ expect ( second . artifactCount ) . toBe ( sourcePaths . length ) ;
240+ expect ( second . importedCount ) . toBe ( 0 ) ;
241+ expect ( second . skippedCount ) . toBe ( sourcePaths . length ) ;
242+ expect ( second . pagePaths ) . toHaveLength ( sourcePaths . length ) ;
243+ } ) ;
244+
245+ it ( "skips a configured source whose canonical path is inside the active vault" , async ( ) => {
246+ const privateDir = await createPrivateDir ( "canonical-vault" ) ;
247+ const sourcePath = path . join ( privateDir , "legitimate.md" ) ;
248+ await fs . writeFile ( sourcePath , "# legitimate\n" , "utf8" ) ;
249+ const { rootDir : vaultDir , config } = await createVault ( {
250+ rootDir : nextCaseRoot ( "canonical-vault-target" ) ,
251+ config : {
252+ vaultMode : "unsafe-local" ,
253+ unsafeLocal : {
254+ allowPrivateMemoryCoreAccess : true ,
255+ paths : [ sourcePath ] ,
256+ } ,
257+ } ,
258+ } ) ;
259+ const first = await syncMemoryWikiUnsafeLocalSources ( config ) ;
260+ const generatedPage = path . join ( vaultDir , first . pagePaths [ 0 ] ?? "" ) ;
261+ const configWithVaultPage = {
262+ ...config ,
263+ unsafeLocal : {
264+ ...config . unsafeLocal ,
265+ paths : [ sourcePath , generatedPage ] ,
266+ } ,
267+ } ;
268+
269+ const second = await syncMemoryWikiUnsafeLocalSources ( configWithVaultPage ) ;
270+
271+ expect ( second . artifactCount ) . toBe ( 1 ) ;
272+ expect ( second . importedCount ) . toBe ( 0 ) ;
273+ expect ( second . skippedCount ) . toBe ( 1 ) ;
274+ expect ( second . pagePaths ) . toHaveLength ( 1 ) ;
275+ } ) ;
276+
209277 it ( "caps composed unsafe-local filenames to the filesystem component limit" , async ( ) => {
210278 const privateDir = await createPrivateDir ( `${ "漢" . repeat ( 50 ) } -private` ) ;
211279 const nestedDir = path . join ( privateDir , `${ "語" . repeat ( 50 ) } -nested` ) ;
0 commit comments