新增LLM审计摘要边界

This commit is contained in:
czj
2026-07-08 13:10:36 +08:00
parent de539aecb0
commit 01c02049d4
7 changed files with 294 additions and 4 deletions
+37
View File
@@ -0,0 +1,37 @@
import { describe, expect, it } from "vitest";
import { createLlmAuditSummary, hashContent } from "../audit";
describe("LLM audit summary", () => {
it("hashes content deterministically", async () => {
await expect(hashContent("abc")).resolves.toBe(
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
);
});
it("does not retain raw prompt or response", async () => {
const summary = await createLlmAuditSummary({
provider: "deepseek",
model: "deepseek-v4-pro",
task: "renwei_copy_optimizer",
duration_ms: 12,
schema_valid: true,
prompt: "完整 prompt 不应长期保存",
output: "完整 response 不应长期保存",
error_summary: null,
});
expect(summary).toMatchObject({
provider: "deepseek",
model: "deepseek-v4-pro",
task: "renwei_copy_optimizer",
duration_ms: 12,
schema_valid: true,
error_summary: null,
});
expect(JSON.stringify(summary)).not.toContain("完整 prompt");
expect(JSON.stringify(summary)).not.toContain("完整 response");
expect(summary.input_hash).toHaveLength(64);
expect(summary.output_hash).toHaveLength(64);
});
});