新增人味文案评分和效果学习
This commit is contained in:
@@ -19,6 +19,10 @@ vi.mock("../../../lib/llm/client", async () => {
|
||||
});
|
||||
|
||||
import { createSqliteRepository } from "../../../lib/db/sqlite-repository";
|
||||
import {
|
||||
HUMAN_COPY_RUBRIC_V1,
|
||||
scoreHumanCopyResult,
|
||||
} from "../../../lib/calibration/scoring";
|
||||
import { GET as listCases } from "../cases/route";
|
||||
import { GET as getCase, PATCH as patchCase } from "../cases/[caseId]/route";
|
||||
import { POST as archiveCase } from "../cases/[caseId]/archive/route";
|
||||
@@ -206,6 +210,68 @@ describe("case APIs", () => {
|
||||
expect(body.calibrationEvent).toBeNull();
|
||||
});
|
||||
|
||||
it("creates calibration events for scored human-copy result-version performance", async () => {
|
||||
const repository = createSqliteRepository();
|
||||
const created = await repository.createOptimizationCase({
|
||||
case_type: "human_copy",
|
||||
title: "人味文案优化:私域",
|
||||
summary: "原文",
|
||||
publish_target: "私域",
|
||||
source_excerpt: "原文",
|
||||
});
|
||||
const result = {
|
||||
optimized_text: "优化后文案",
|
||||
change_notes: [],
|
||||
ai_taste_checks: [],
|
||||
warnings: [],
|
||||
};
|
||||
const version = await repository.createOptimizationResultVersion({
|
||||
case_id: created.id,
|
||||
case_type: "human_copy",
|
||||
status: "optimized",
|
||||
article_job_id: null,
|
||||
article_revision: null,
|
||||
result_summary: "优化后文案",
|
||||
payload: result,
|
||||
process_summary: [],
|
||||
llm_audit_summary: [],
|
||||
error_stage: null,
|
||||
error_summary: null,
|
||||
});
|
||||
await repository.saveRubricVersion(HUMAN_COPY_RUBRIC_V1);
|
||||
await repository.saveScoringRun(
|
||||
scoreHumanCopyResult({
|
||||
resultVersionId: version.id,
|
||||
result,
|
||||
}),
|
||||
);
|
||||
const publication = await repository.createPublicationRecord({
|
||||
result_version_id: version.id,
|
||||
job_id: null,
|
||||
revision: null,
|
||||
publish_target: "私域",
|
||||
url: "https://example.com/private",
|
||||
published_at: "2026-07-08T12:00:00.000Z",
|
||||
status: "published",
|
||||
notes: "",
|
||||
});
|
||||
|
||||
const response = await recordPerformance(
|
||||
request({
|
||||
window_label: "T+7d",
|
||||
views: "1200",
|
||||
feedback_summary: "客户反馈更自然",
|
||||
}),
|
||||
params({ publicationId: publication.id }),
|
||||
);
|
||||
const body = (await response.json()) as {
|
||||
calibrationEvent: { observations: string[] } | null;
|
||||
};
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(body.calibrationEvent?.observations.join(" ")).toContain("综合评分");
|
||||
});
|
||||
|
||||
it("reruns an article case into a new result version and article job", async () => {
|
||||
const repository = createSqliteRepository();
|
||||
const created = await repository.createOptimizationCase({
|
||||
@@ -333,13 +399,19 @@ describe("case APIs", () => {
|
||||
|
||||
const response = await rerunCase(request({}), params({ caseId: created.id }));
|
||||
const body = (await response.json()) as {
|
||||
result_version: { version: number };
|
||||
result_version: { id: string; version: number };
|
||||
result: { optimized_text: string };
|
||||
};
|
||||
|
||||
expect(response.status).toBe(201);
|
||||
expect(body.result_version.version).toBe(2);
|
||||
expect(body.result.optimized_text).toBe("第二版");
|
||||
await expect(
|
||||
repository.getLatestScoringRunForResultVersion(body.result_version.id),
|
||||
).resolves.toMatchObject({
|
||||
case_type: "human_copy",
|
||||
rubric_version_id: HUMAN_COPY_RUBRIC_V1.id,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user