test: expand frontmatter coverage
This commit is contained in:
@@ -256,4 +256,20 @@ metadata:
|
|||||||
expect(clawdbot?.requires?.config).toEqual(["workspace.dir"]);
|
expect(clawdbot?.requires?.config).toEqual(["workspace.dir"]);
|
||||||
expect(clawdbot?.install?.[0].kind).toBe("bundled");
|
expect(clawdbot?.install?.[0].kind).toBe("bundled");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("parses YAML metadata map", () => {
|
||||||
|
const content = `---
|
||||||
|
name: yaml-metadata
|
||||||
|
metadata:
|
||||||
|
clawdbot:
|
||||||
|
emoji: disk
|
||||||
|
events:
|
||||||
|
- command:new
|
||||||
|
---
|
||||||
|
`;
|
||||||
|
const frontmatter = parseFrontmatter(content);
|
||||||
|
const clawdbot = resolveClawdbotMetadata(frontmatter);
|
||||||
|
expect(clawdbot?.emoji).toBe("disk");
|
||||||
|
expect(clawdbot?.events).toEqual(["command:new"]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,6 +37,38 @@ metadata:
|
|||||||
expect(parsed.clawdbot?.emoji).toBe("disk");
|
expect(parsed.clawdbot?.emoji).toBe("disk");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves inline JSON values", () => {
|
||||||
|
const content = `---
|
||||||
|
name: inline-json
|
||||||
|
metadata: {"clawdbot": {"events": ["test"]}}
|
||||||
|
---
|
||||||
|
`;
|
||||||
|
const result = parseFrontmatterBlock(content);
|
||||||
|
expect(result.metadata).toBe('{"clawdbot": {"events": ["test"]}}');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("stringifies YAML objects and arrays", () => {
|
||||||
|
const content = `---
|
||||||
|
name: yaml-objects
|
||||||
|
enabled: true
|
||||||
|
retries: 3
|
||||||
|
tags:
|
||||||
|
- alpha
|
||||||
|
- beta
|
||||||
|
metadata:
|
||||||
|
clawdbot:
|
||||||
|
events:
|
||||||
|
- command:new
|
||||||
|
---
|
||||||
|
`;
|
||||||
|
const result = parseFrontmatterBlock(content);
|
||||||
|
expect(result.enabled).toBe("true");
|
||||||
|
expect(result.retries).toBe("3");
|
||||||
|
expect(JSON.parse(result.tags ?? "[]")).toEqual(["alpha", "beta"]);
|
||||||
|
const parsed = JSON5.parse(result.metadata ?? "") as { clawdbot?: { events?: string[] } };
|
||||||
|
expect(parsed.clawdbot?.events).toEqual(["command:new"]);
|
||||||
|
});
|
||||||
|
|
||||||
it("returns empty when frontmatter is missing", () => {
|
it("returns empty when frontmatter is missing", () => {
|
||||||
const content = "# No frontmatter";
|
const content = "# No frontmatter";
|
||||||
expect(parseFrontmatterBlock(content)).toEqual({});
|
expect(parseFrontmatterBlock(content)).toEqual({});
|
||||||
|
|||||||
Reference in New Issue
Block a user