e87c58d6e4
Engine calls already returned markdown; the worker failed because local postgres upsert required onConflict and the appendix write omitted it. Co-authored-by: Cursor <cursoragent@cursor.com>
71 lines
2.6 KiB
TypeScript
71 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
hashLongformMarkdown,
|
|
nextLongformAppendixState,
|
|
parseLongformAppendixRow,
|
|
} from "../src/lib/personal-report-longform-appendix.ts";
|
|
import { summarizePersonalReportFailure } from "../src/lib/personal-report-failure-summary.ts";
|
|
|
|
test("hashLongformMarkdown is stable sha256", () => {
|
|
assert.equal(hashLongformMarkdown("# a"), hashLongformMarkdown("# a"));
|
|
assert.equal(hashLongformMarkdown("# a").length, 64);
|
|
assert.notEqual(hashLongformMarkdown("# a"), hashLongformMarkdown("# b"));
|
|
});
|
|
|
|
test("parseLongformAppendixRow rejects foreign or incomplete rows", () => {
|
|
assert.equal(parseLongformAppendixRow(null), null);
|
|
assert.equal(parseLongformAppendixRow({ status: "ready" }), null);
|
|
assert.equal(parseLongformAppendixRow({
|
|
report_id: "123e4567-e89b-12d3-a456-426614174000",
|
|
user_id: "user-1",
|
|
request_id: "123e4567-e89b-12d3-a456-426614174001",
|
|
status: "ready",
|
|
markdown: "# Full",
|
|
})?.status, "ready");
|
|
});
|
|
|
|
test("nextLongformAppendixState marks unavailable after two failures and never stores error bodies", () => {
|
|
const first = nextLongformAppendixState({ current: null, errorCode: "upstream_unavailable" });
|
|
assert.equal(first.status, "pending");
|
|
assert.equal(first.attemptCount, 1);
|
|
assert.equal(first.markdown, null);
|
|
assert.equal(first.lastErrorCode, "upstream_unavailable");
|
|
|
|
const second = nextLongformAppendixState({
|
|
current: {
|
|
reportId: "r",
|
|
userId: "u",
|
|
requestId: "q",
|
|
status: "pending",
|
|
markdown: null,
|
|
contentSha256: null,
|
|
attemptCount: 1,
|
|
lastErrorCode: "upstream_unavailable",
|
|
},
|
|
errorCode: "empty_markdown",
|
|
});
|
|
assert.equal(second.status, "unavailable");
|
|
assert.equal(second.attemptCount, 2);
|
|
assert.equal(second.markdown, null);
|
|
|
|
const ready = nextLongformAppendixState({ current: null, successMarkdown: "# Full" });
|
|
assert.equal(ready.status, "ready");
|
|
assert.equal(ready.markdown, "# Full");
|
|
assert.equal(ready.contentSha256, hashLongformMarkdown("# Full"));
|
|
assert.equal(ready.lastErrorCode, null);
|
|
});
|
|
|
|
test("failed longform appendix codes become readable summaries without storing bodies", () => {
|
|
const summary = summarizePersonalReportFailure({
|
|
themeCount: 5,
|
|
sections: [],
|
|
failureCode: "calculation_unavailable",
|
|
appendixLastErrorCode: "empty_markdown",
|
|
});
|
|
assert.equal(summary.appendixLastErrorCode, "empty_markdown");
|
|
assert.equal(summary.summary, "计算引擎返回了空文,请稍后重试");
|
|
assert.deepEqual(summary.lastErrorCodes, []);
|
|
});
|