新增统一案例存储仓储
This commit is contained in:
@@ -111,4 +111,122 @@ describe("createSqliteRepository", () => {
|
||||
]);
|
||||
expect(event.observations).toEqual(["表现高于预期"]);
|
||||
});
|
||||
|
||||
test("creates, lists, updates, archives, and restores optimization cases", async () => {
|
||||
const repository = createSqliteRepository(dbPath);
|
||||
|
||||
const created = await repository.createOptimizationCase({
|
||||
case_type: "human_copy",
|
||||
title: "人味文案优化:朋友圈",
|
||||
summary: "原文摘要",
|
||||
publish_target: "朋友圈",
|
||||
source_excerpt: "原文摘要",
|
||||
});
|
||||
|
||||
await repository.saveCaseInput({
|
||||
case_id: created.id,
|
||||
case_type: "human_copy",
|
||||
article_job_id: null,
|
||||
payload: {
|
||||
source_text: "原文摘要",
|
||||
goal: "自然一点",
|
||||
intensity: "light",
|
||||
user_instructions: "",
|
||||
publish_target: "朋友圈",
|
||||
},
|
||||
});
|
||||
|
||||
await expect(
|
||||
repository.listOptimizationCases({ include_archived: false }),
|
||||
).resolves.toEqual([expect.objectContaining({ id: created.id })]);
|
||||
|
||||
await expect(
|
||||
repository.updateOptimizationCaseMetadata(created.id, {
|
||||
customer_name: "客户A",
|
||||
brand_name: "品牌B",
|
||||
project_tags: ["朋友圈"],
|
||||
notes: "保留口语。",
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
customer_name: "客户A",
|
||||
project_tags: ["朋友圈"],
|
||||
});
|
||||
|
||||
await repository.archiveOptimizationCase(created.id);
|
||||
await expect(
|
||||
repository.listOptimizationCases({ include_archived: false }),
|
||||
).resolves.toHaveLength(0);
|
||||
|
||||
await repository.restoreOptimizationCase(created.id);
|
||||
await expect(repository.getOptimizationCaseDetail(created.id)).resolves.toMatchObject({
|
||||
case: { id: created.id, status: "running" },
|
||||
input: expect.objectContaining({ case_id: created.id }),
|
||||
});
|
||||
});
|
||||
|
||||
test("creates multiple result versions and binds publication to a version", async () => {
|
||||
const repository = createSqliteRepository(dbPath);
|
||||
const optimizationCase = await repository.createOptimizationCase({
|
||||
case_type: "human_copy",
|
||||
title: "人味文案优化:私域",
|
||||
summary: "原文",
|
||||
publish_target: "私域",
|
||||
source_excerpt: "原文",
|
||||
});
|
||||
|
||||
const first = await repository.createOptimizationResultVersion({
|
||||
case_id: optimizationCase.id,
|
||||
case_type: "human_copy",
|
||||
status: "optimized",
|
||||
article_job_id: null,
|
||||
article_revision: null,
|
||||
result_summary: "第一版",
|
||||
payload: {
|
||||
optimized_text: "第一版文案",
|
||||
change_notes: [],
|
||||
ai_taste_checks: [],
|
||||
warnings: [],
|
||||
},
|
||||
process_summary: [],
|
||||
llm_audit_summary: [],
|
||||
error_stage: null,
|
||||
error_summary: null,
|
||||
});
|
||||
const second = await repository.createOptimizationResultVersion({
|
||||
case_id: optimizationCase.id,
|
||||
case_type: "human_copy",
|
||||
status: "optimized",
|
||||
article_job_id: null,
|
||||
article_revision: null,
|
||||
result_summary: "第二版",
|
||||
payload: {
|
||||
optimized_text: "第二版文案",
|
||||
change_notes: [],
|
||||
ai_taste_checks: [],
|
||||
warnings: [],
|
||||
},
|
||||
process_summary: [],
|
||||
llm_audit_summary: [],
|
||||
error_stage: null,
|
||||
error_summary: null,
|
||||
});
|
||||
|
||||
expect(first.version).toBe(1);
|
||||
expect(second.version).toBe(2);
|
||||
|
||||
const publication = await repository.createPublicationRecord({
|
||||
result_version_id: second.id,
|
||||
job_id: null,
|
||||
revision: null,
|
||||
publish_target: "私域",
|
||||
url: "https://example.com/private",
|
||||
published_at: "2026-07-08T12:00:00.000Z",
|
||||
status: "published",
|
||||
notes: "客户私域发布",
|
||||
});
|
||||
|
||||
await expect(
|
||||
repository.listPublicationRecordsForResultVersion(second.id),
|
||||
).resolves.toEqual([expect.objectContaining({ id: publication.id })]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user