From d3dce6dab98452ff0f4ff6130f859951fcfcec04 Mon Sep 17 00:00:00 2001 From: murashit Date: Wed, 27 May 2026 10:39:59 +0900 Subject: [PATCH] Clarify wikilink linktext edge cases --- .../chat/composer/obsidian-context.test.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/features/chat/composer/obsidian-context.test.ts b/tests/features/chat/composer/obsidian-context.test.ts index 04485dca..a37230f2 100644 --- a/tests/features/chat/composer/obsidian-context.test.ts +++ b/tests/features/chat/composer/obsidian-context.test.ts @@ -9,13 +9,25 @@ describe("Obsidian composer context", () => { markdownFiles: [ { basename: "Alpha", path: "notes/Alpha.md", stat: { mtime: 100 } }, { basename: "Beta", path: "Beta.md", stat: { mtime: 200 } }, + { basename: "Daily", path: "Personal/Daily Notes/Daily.md", stat: { mtime: 300 } }, ], lastOpenFiles: ["Beta.md"], + linktexts: new Map([ + ["notes/Alpha.md", "Alpha"], + ["Personal/Daily Notes/Daily.md", "Personal/Daily Notes/Daily"], + ]), }); expect(noteCandidates(app)).toEqual([ - { basename: "Alpha", path: "notes/Alpha.md", mtime: 100, linktext: "notes/Alpha", recentIndex: null }, + { basename: "Alpha", path: "notes/Alpha.md", mtime: 100, linktext: "Alpha", recentIndex: null }, { basename: "Beta", path: "Beta.md", mtime: 200, linktext: "Beta", recentIndex: 0 }, + { + basename: "Daily", + path: "Personal/Daily Notes/Daily.md", + mtime: 300, + linktext: "Personal/Daily Notes/Daily", + recentIndex: null, + }, ]); }); @@ -61,6 +73,7 @@ function appFixture(options: { lastOpenFiles?: string[]; markdownFiles?: { basename: string; path: string; stat: { mtime: number } }[]; abstractFiles?: Map; + linktexts?: Map; }): App { return { workspace: { @@ -70,7 +83,7 @@ function appFixture(options: { metadataCache: { getFirstLinkpathDest: options.getFirstLinkpathDest ?? (() => options.linkDestination ?? null), fileToLinktext: (file: TFile, _sourcePath: string, omitMdExtension?: boolean) => - omitMdExtension === true ? file.path.replace(/\.md$/i, "") : file.path, + options.linktexts?.get(file.path) ?? (omitMdExtension === true ? file.path.replace(/\.md$/i, "") : file.path), }, vault: { getMarkdownFiles: () => options.markdownFiles ?? [],