Skip to content

Commit e9d0dcc

Browse files
author
Peter Steinberger
committed
fix(memory-wiki): validate generated index targets
1 parent 7b43ed1 commit e9d0dcc

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

extensions/memory-wiki/src/compile.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,64 @@ describe("compileMemoryWikiVault", () => {
172172
).resolves.not.toContain("syntheses/broken.md");
173173
});
174174

175+
it.each([
176+
{
177+
name: "root index with syntax-error frontmatter",
178+
relativePath: "index.md",
179+
frontmatterLines: [
180+
"pageType: report",
181+
"sourceIds:",
182+
' - **MEMORY.md line 235**:"some quoted, value"',
183+
],
184+
error: "Unexpected scalar",
185+
},
186+
{
187+
name: "root index with sequence-root frontmatter",
188+
relativePath: "index.md",
189+
frontmatterLines: ["- pageType: report"],
190+
error: "Wiki frontmatter must be a YAML mapping",
191+
},
192+
{
193+
name: "directory index with syntax-error frontmatter",
194+
relativePath: "sources/index.md",
195+
frontmatterLines: [
196+
"pageType: report",
197+
"sourceIds:",
198+
' - **MEMORY.md line 235**:"some quoted, value"',
199+
],
200+
error: "Unexpected scalar",
201+
},
202+
{
203+
name: "directory index with scalar-root frontmatter",
204+
relativePath: "sources/index.md",
205+
frontmatterLines: ["report"],
206+
error: "Wiki frontmatter must be a YAML mapping",
207+
},
208+
])(
209+
"rejects $name without changing its bytes",
210+
async ({ relativePath, frontmatterLines, error }) => {
211+
const { rootDir, config } = await createVault({
212+
rootDir: nextCaseRoot(),
213+
initialize: true,
214+
config: { render: { createDashboards: false } },
215+
});
216+
const targetPath = path.join(rootDir, relativePath);
217+
const original = [
218+
"---",
219+
...frontmatterLines,
220+
"---",
221+
"",
222+
"# Existing Index",
223+
"",
224+
"Keep this body.",
225+
].join("\n");
226+
await fs.writeFile(targetPath, original, "utf8");
227+
228+
await expect(compileMemoryWikiVault(config)).rejects.toThrow(error);
229+
await expect(fs.readFile(targetPath, "utf8")).resolves.toBe(original);
230+
},
231+
);
232+
175233
it("discovers pages in nested subdirectories during compile", async () => {
176234
const { rootDir, config } = await createVault({
177235
rootDir: nextCaseRoot(),

extensions/memory-wiki/src/compile.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,9 @@ async function writeManagedMarkdownFile(params: {
920920
}): Promise<boolean> {
921921
const root = await fsRoot(params.rootDir);
922922
const original = await root.readText(params.relativePath).catch(() => `# ${params.title}\n`);
923+
// Generated indexes bypass page discovery. Parse existing content here so
924+
// managed-block updates cannot rewrite malformed frontmatter.
925+
parseWikiMarkdown(original);
923926
const updated = replaceManagedMarkdownBlock({
924927
original,
925928
heading: "## Generated",

0 commit comments

Comments
 (0)