fix: allow exports with QA warnings

This commit is contained in:
Codex
2026-06-21 23:43:03 +08:00
parent 21aa75d240
commit 163d375a76
7 changed files with 115 additions and 26 deletions
+61 -1
View File
@@ -73,7 +73,8 @@ interface CreateJobResponse {
interface OptimizeJobResponse {
optimizedArticle: { title: string };
qaReport: { checks: unknown[] };
qaReport: { checks: unknown[]; overall_status?: string };
exportPaths?: Record<string, string>;
timing: TimingResponse;
}
@@ -314,6 +315,65 @@ describe("job API routes", () => {
expect(llmMocks.generateValidatedJson).toHaveBeenCalled();
});
it("still writes export files when the QA report fails", async () => {
const { job } = await createJobFixture();
await confirmFactCard(
request(validFactCard),
params<{ jobId: string }>({ jobId: job.id }),
);
llmMocks.generateValidatedJson
.mockResolvedValueOnce({
title: "API LLM Optimized GEO Article!!!",
summary:
"A official site article for Marketing teams about GEO optimization.",
body_markdown:
"Example has 12 years of GEO optimization experience and 99 patents.",
image_suggestions: [],
changed_sections: ["title", "body"],
requires_user_confirmation: [],
})
.mockResolvedValueOnce({ checks: [] })
.mockResolvedValueOnce({
title: "API LLM Optimized GEO Article",
summary:
"A official site article for Marketing teams about GEO optimization.",
body_markdown:
"Example has 12 years of GEO optimization experience and 99 patents.",
image_suggestions: [],
changed_sections: ["body"],
requires_user_confirmation: [],
})
.mockResolvedValueOnce({ checks: [] })
.mockResolvedValueOnce({
title: "API LLM Optimized GEO Article",
summary:
"A official site article for Marketing teams about GEO optimization.",
body_markdown:
"Example has 12 years of GEO optimization experience and 99 patents.",
image_suggestions: [],
changed_sections: ["body"],
requires_user_confirmation: [],
})
.mockResolvedValueOnce({ checks: [] });
const response = await optimizeJob(
request({}),
params<{ jobId: string }>({ jobId: job.id }),
);
const body = (await response.json()) as OptimizeJobResponse;
expect(response.status).toBe(200);
expect(body.qaReport.overall_status).toBe("fail");
expect(body.exportPaths).toEqual(
expect.objectContaining({
markdown: expect.stringContaining("optimized.md"),
docx: expect.stringContaining("optimized.docx"),
qaJson: expect.stringContaining("qa_report.json"),
}),
);
});
it("returns a clear error when LLM optimization fails", async () => {
const { job } = await createJobFixture();
await confirmFactCard(
+6 -9
View File
@@ -61,16 +61,13 @@ export async function POST(request: Request, context: RouteContext) {
result.qaReport,
);
const exportStore = getExportStoreFromRuntime();
const exportPaths =
qaReport.overall_status === "fail"
? {}
: await exportStore.writeJobExports({
jobId,
article: optimizedArticle,
qaReport,
});
const exportPaths = await exportStore.writeJobExports({
jobId,
article: optimizedArticle,
qaReport,
});
await repository.updateArticleJob(jobId, {
status: qaReport.overall_status === "fail" ? "qa_failed" : "optimized",
status: "optimized",
export_paths: exportPaths,
});