feat: use llm for targeted rewrite

This commit is contained in:
Codex
2026-06-21 23:43:02 +08:00
parent 9efbe1a354
commit 3d49789743
4 changed files with 92 additions and 4 deletions
@@ -16,6 +16,7 @@ vi.mock("../../llm/client", async () => {
import { extractCandidateFactCard } from "../fact-extractor";
import { optimizeArticle } from "../article-optimizer";
import { rewriteFailedSections } from "../targeted-rewriter";
describe("LLM workflow integration", () => {
const confirmedFactCard = {
@@ -127,4 +128,70 @@ describe("LLM workflow integration", () => {
"Unsupported requested claim: 99 patents",
);
});
it("uses LLM output for targeted rewrite when valid", async () => {
llmMocks.generateValidatedJson.mockResolvedValueOnce({
title: "Rewritten By LLM",
summary: "Original summary",
body_markdown:
"## Body\nExample Technology Co., Ltd. focuses on GEO optimization.",
image_suggestions: [],
changed_sections: ["title"],
requires_user_confirmation: [],
});
const rewritten = await rewriteFailedSections({
article: {
title: "Bad title!!!",
summary: "Original summary",
body_markdown: "## Body\nOriginal body",
image_suggestions: [],
changed_sections: [],
requires_user_confirmation: [],
},
factCard: confirmedFactCard,
failedChecks: [
{
rule_id: "title_quality",
status: "fail",
evidence: "Bad title!!!",
reason: "Title has punctuation stuffing.",
suggested_fix: "Rewrite title.",
target_agent: "title",
},
],
});
expect(rewritten.title).toBe("Rewritten By LLM");
expect(llmMocks.generateValidatedJson).toHaveBeenCalledOnce();
});
it("falls back to deterministic targeted rewrite when LLM returns null", async () => {
llmMocks.generateValidatedJson.mockResolvedValueOnce(null);
const rewritten = await rewriteFailedSections({
article: {
title: "Bad title!!!",
summary: "Original summary",
body_markdown: "## Body\nOriginal body",
image_suggestions: [],
changed_sections: [],
requires_user_confirmation: [],
},
factCard: confirmedFactCard,
failedChecks: [
{
rule_id: "title_quality",
status: "fail",
evidence: "Bad title!!!",
reason: "Title has punctuation stuffing.",
suggested_fix: "Rewrite title.",
target_agent: "title",
},
],
});
expect(rewritten.title).toContain("GEO optimization Guide");
expect(rewritten.summary).toBe("Original summary");
});
});