fix: allow exports with QA warnings
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
+2
-7
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import {
|
||||
ArticleInputForm,
|
||||
@@ -89,10 +89,6 @@ export default function Home() {
|
||||
const [lastTiming, setLastTiming] = useState<TimingSummary | null>(null);
|
||||
const [liveProgress, setLiveProgress] = useState<WorkflowProgress | null>(null);
|
||||
|
||||
const exportBlocked = useMemo(
|
||||
() => qaReport?.overall_status === "fail",
|
||||
[qaReport],
|
||||
);
|
||||
const canOptimize =
|
||||
Boolean(jobId) && Boolean(factCard) && factCard?.uncertain_items.length === 0;
|
||||
|
||||
@@ -209,7 +205,7 @@ export default function Home() {
|
||||
: "";
|
||||
setMessage(
|
||||
body.qaReport.overall_status === "fail"
|
||||
? `质检发现硬性失败,已阻止导出。${timingText}`
|
||||
? `质检发现需要复核的问题,已保留导出文件。${timingText}`
|
||||
: `优化完成。${timingText}`,
|
||||
);
|
||||
} catch (error) {
|
||||
@@ -267,7 +263,6 @@ export default function Home() {
|
||||
/>
|
||||
<OptimizedPreview
|
||||
article={optimizedArticle}
|
||||
exportBlocked={exportBlocked}
|
||||
jobId={jobId}
|
||||
/>
|
||||
<QaReportPanel report={qaReport} />
|
||||
|
||||
Reference in New Issue
Block a user