mirror of
https://github.com/anomalyco/opencode.git
synced 2026-10-26 12:50:01 +00:00
35 lines
No EOL
1.5 KiB
TypeScript
35 lines
No EOL
1.5 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { ConfigMarkdown } from "@opencode/core/config/markdown"
|
|
|
|
const invalidYaml = `---
|
|
description: Use when the user needs to crawl pages. Keywords: crawl, scrape
|
|
---
|
|
body`
|
|
|
|
describe("ConfigMarkdown.parse", () => {
|
|
test("recovers unquoted-colon frontmatter via the sanitize fallback", () => {
|
|
const parsed = ConfigMarkdown.parse(invalidYaml)
|
|
expect(parsed.data.description).toBe("Use when the user needs to crawl pages. Keywords: crawl, scrape")
|
|
expect(parsed.content.trim()).toBe("body")
|
|
})
|
|
|
|
test("recovers the same content again after a previous failed parse", () => {
|
|
// gray-matter caches by content before parsing; a poisoned entry used to
|
|
// make every later parse of the same text return silently without data.
|
|
expect(() => ConfigMarkdown.parse("---\ndescription: [unclosed\n---\nbody")).toThrow()
|
|
const parsed = ConfigMarkdown.parse(invalidYaml)
|
|
expect(parsed.data.description).toBe("Use when the user needs to crawl pages. Keywords: crawl, scrape")
|
|
})
|
|
|
|
test("keeps throwing for the same unparseable content on every call", () => {
|
|
const input = "---\ndescription: [unclosed\n---\nbody"
|
|
expect(() => ConfigMarkdown.parse(input)).toThrow()
|
|
expect(() => ConfigMarkdown.parse(input)).toThrow()
|
|
})
|
|
|
|
test("parses plain content without frontmatter", () => {
|
|
const parsed = ConfigMarkdown.parse("just body")
|
|
expect(parsed.content).toBe("just body")
|
|
expect(parsed.data).toEqual({})
|
|
})
|
|
}) |