Files
writing-agent/tests/parse-json-doc.test.ts
T
chenmoranzhiandCursor bd5d88abfa Add capability-probed structured outputs and a prototype/instance creation graph.
Probe API profiles for json_schema/tools, flatten worker artifacts onto a strict schema, and let users spawn or revise graph nodes instead of a one-shot DAG.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-31 01:57:22 +08:00

32 lines
1.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
extractLastProductJson,
selectJsonPayload,
tryParseJsonDoc,
} from "../src/parse/json-doc.js";
describe("selectJsonPayload", () => {
it("keeps content when it is already the product", () => {
const json = '{"schema":"context-fragment.v1","brief":"a","正文":{}}';
expect(selectJsonPayload(json, "thinking...")).toBe(json);
});
it("falls back to reasoning when content is not JSON", () => {
const json = '{"schema":"context-fragment.v1","brief":"a","正文":{}}';
expect(selectJsonPayload("Done.", json)).toBe(json);
});
});
describe("extractLastProductJson", () => {
it("skips an earlier example object and takes the fragment", () => {
const raw = `example { "foo": 1 } then ${JSON.stringify({
schema: "context-fragment.v1",
brief: "点题",
正文: { x: 1 },
})}`;
const parsed = extractLastProductJson(raw) as { brief?: string };
expect(parsed?.brief).toBe("点题");
expect(tryParseJsonDoc(raw)).toMatchObject({ brief: "点题" });
});
});