Files
oh-my-pi/packages/utils/test/frontmatter.test.ts
T
can1357 6c552e39cf fix(utils): handled unquoted YAML plain scalars containing colon-space in frontmatter
- Added preprocessing to quote ambiguous plain scalars containing a colon-space sequence when standard YAML parsing fails.
- Preserves the parsed types of unaffected fields and prevents fallback warnings for common unquoted description strings.
- Added tests to verify successful recovery of unquoted values and continued fallback warning coverage for unrecoverable syntax.
2026-06-30 17:44:19 +02:00

47 lines
1.5 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "bun:test";
import { parseFrontmatter } from "@oh-my-pi/pi-utils";
import * as logger from "@oh-my-pi/pi-utils/logger";
describe("parseFrontmatter", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("accepts unquoted skill descriptions containing colon-space without warning", () => {
const warnSpy = vi.spyOn(logger, "warn").mockImplementation(() => {});
const content = `---
name: tool-prompt-optimization
description: Optimize tool prompts. Two halves: measure schema overlap; keep scar tissue.
enabled: true
---
Skill body`;
const result = parseFrontmatter(content, { source: "bad-skill/SKILL.md" });
expect(result.frontmatter).toEqual({
name: "tool-prompt-optimization",
description: "Optimize tool prompts. Two halves: measure schema overlap; keep scar tissue.",
enabled: true,
});
expect(result.body).toBe("Skill body");
expect(warnSpy).not.toHaveBeenCalled();
});
it("still warns and falls back for unrecoverable malformed frontmatter", () => {
const warnSpy = vi.spyOn(logger, "warn").mockImplementation(() => {});
const content = `---
invalid: [unclosed array
---
Body content`;
const result = parseFrontmatter(content, { source: "broken.md" });
expect(result.frontmatter).toEqual({ invalid: "[unclosed array" });
expect(result.body).toBe("Body content");
expect(warnSpy).toHaveBeenCalledWith(
"Failed to parse YAML frontmatter",
expect.objectContaining({ err: expect.stringContaining("broken.md") }),
);
});
});