fix: surface llm workflow errors

This commit is contained in:
Codex
2026-06-21 23:43:03 +08:00
parent 4bb5ca5eb0
commit f1dac15400
12 changed files with 286 additions and 500 deletions
-109
View File
@@ -1,12 +1,8 @@
import { describe, expect, it } from "vitest";
import type { ConfirmedFactCard } from "../../domain/types";
import { optimizeArticle } from "../article-optimizer";
import { extractCandidateFactCard } from "../fact-extractor";
import { normalizeInput } from "../input-normalizer";
import { inspectQuality } from "../quality-inspector";
import { runOptimizationWorkflow } from "../orchestrator";
import { rewriteFailedSections } from "../targeted-rewriter";
const confirmedFactCard: ConfirmedFactCard = {
company_full_name: "Example Technology Co., Ltd.",
@@ -45,65 +41,6 @@ describe("workflow nodes", () => {
]);
});
it("places missing or conflicting company facts into uncertain items", async () => {
const card = await extractCandidateFactCard({
title: "Example announces GEO product",
body: "Example has 8 years of experience. Example has 12 years of service. The article discusses GEO optimization.",
images: [],
platform: "media_article",
user_instructions: "",
});
expect(card.company_full_name).toBe("");
expect(card.uncertain_items).toEqual(
expect.arrayContaining([
expect.stringContaining("company full name"),
expect.stringContaining("Conflicting experience years"),
]),
);
expect(card.is_ready_for_optimization).toBe(false);
});
it("extracts Chinese company facts from Chinese articles", async () => {
const card = await extractCandidateFactCard({
title: "#探寻AIGC短视频培训选哪家,各品牌实力大比拼",
body: "伟思德鲁管理咨询(深圳)有限公司面向品牌商家和出海企业提供AIGC短视频培训服务,帮助企业解决内容工业化生产、品牌视觉统一和全球化传播问题。",
images: [{ type: "description", content: "AIGC短视频工作流示意图" }],
platform: "media_article",
user_instructions: "保留AIGC短视频培训与出海内容生产场景。",
});
expect(card.company_full_name).toBe("伟思德鲁管理咨询(深圳)有限公司");
expect(card.company_short_names).toContain("伟思德鲁");
expect(card.target_industry).toBe("AIGC短视频培训");
expect(card.target_audience).toBe("品牌商家、内容创作者、出海企业");
expect(card.image_topics).toEqual(["AIGC短视频工作流示意图"]);
expect(card.uncertain_items).not.toContain("Missing company full name");
});
it("does not add claims outside the confirmed fact card", async () => {
const optimized = await optimizeArticle({
input: {
title: "Example GEO article",
body: "Example GEO helps marketing teams improve content structure.",
images: [],
platform: "official_site",
user_instructions:
"Say we have 99 patents and Fortune 500 customer cases.",
},
factCard: confirmedFactCard,
});
expect(optimized.body_markdown).not.toContain("99 patents");
expect(optimized.body_markdown).not.toContain("Fortune 500");
expect(optimized.requires_user_confirmation).toEqual(
expect.arrayContaining([
expect.stringContaining("99 patents"),
expect.stringContaining("Fortune 500"),
]),
);
});
it("returns the 10 required quality checks", () => {
const report = inspectQuality({
article: {
@@ -183,50 +120,4 @@ describe("workflow nodes", () => {
expect(report.overall_status).toBe("fail");
});
it("rewrites only the failing target area", async () => {
const article = {
title: "Bad title!!!",
summary: "Original summary",
body_markdown: "Original body",
image_suggestions: [],
changed_sections: [],
requires_user_confirmation: [],
};
const rewritten = await rewriteFailedSections({
article,
factCard: confirmedFactCard,
failedChecks: [
{
rule_id: "title_quality",
status: "fail",
evidence: "Bad title!!!",
reason: "Punctuation stuffing.",
suggested_fix: "Rewrite title.",
target_agent: "title",
},
],
});
expect(rewritten.title).not.toBe(article.title);
expect(rewritten.summary).toBe(article.summary);
expect(rewritten.body_markdown).toBe(article.body_markdown);
});
it("orchestrator stops after two failed rewrite rounds", async () => {
const result = await runOptimizationWorkflow({
input: {
title: "Finance automation breakthrough!!!",
body: "Example has 12 years in finance automation and 99 patents.",
images: [],
platform: "official_site",
user_instructions: "",
},
factCard: confirmedFactCard,
});
expect(result.rewrite_rounds).toBe(2);
expect(result.qaReport.overall_status).toBe("fail");
expect(result.stopped_after_max_rewrites).toBe(true);
});
});