feat(report): add dense personal report appendix
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,11 @@ import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import test from "node:test";
|
||||
import { startPostgresFixture } from "./helpers/postgres-fixture.ts";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { assembleReportFactTables } from "../src/lib/report-fact-tables";
|
||||
import { assembleLongformCharts } from "../src/lib/personal-report-generation";
|
||||
import { hashLongformMarkdown } from "../src/lib/personal-report-longform-appendix";
|
||||
import { LONGFORM_SNAPSHOT_SECTION_ID, validateLongformSnapshot } from "../src/lib/personal-report-longform-snapshot";
|
||||
|
||||
const runnerPath = new URL("../scripts/db-migrate.mjs", import.meta.url).pathname;
|
||||
const USER_A = "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa";
|
||||
@@ -150,6 +155,26 @@ test("personal report sections enforce owner-read RLS and service-owned durable
|
||||
),
|
||||
"SET\n0",
|
||||
);
|
||||
const packet = JSON.parse(readFileSync(new URL("./fixtures/report-density-fictional-engine.json", import.meta.url), "utf8"));
|
||||
const reader = JSON.parse(readFileSync(new URL("./fixtures/report-density-fictional-reader.json", import.meta.url), "utf8"));
|
||||
const identity = { reportId: REPORT_ID, userId: USER_A, requestId: REQUEST_ID };
|
||||
const snapshot = validateLongformSnapshot({
|
||||
...identity, kind: "longform_calculation_snapshot", version: 1,
|
||||
markdown: reader.markdown, contentSha256: hashLongformMarkdown(reader.markdown),
|
||||
factTables: assembleReportFactTables(packet), charts: assembleLongformCharts(packet, "ev-cover-longform"),
|
||||
readerDashaApplicability: reader.reader_dasha_applicability,
|
||||
}, identity);
|
||||
const encoded = JSON.stringify(snapshot).replaceAll("'", "''");
|
||||
fixture.psqlAs("service_runtime", "service-runtime-test-password", serviceSql(`
|
||||
select status from public.ensure_personal_report_section('${USER_A}', '${REQUEST_ID}', '${LONGFORM_SNAPSHOT_SECTION_ID}', 2);
|
||||
select status from public.complete_personal_report_section('${USER_A}', '${REQUEST_ID}', '${LONGFORM_SNAPSHOT_SECTION_ID}', '${encoded}'::jsonb);
|
||||
-- Late ensure and conflicting completion must preserve the first committed snapshot.
|
||||
select status from public.ensure_personal_report_section('${USER_A}', '${REQUEST_ID}', '${LONGFORM_SNAPSHOT_SECTION_ID}', 2);
|
||||
select status from public.complete_personal_report_section('${USER_A}', '${REQUEST_ID}', '${LONGFORM_SNAPSHOT_SECTION_ID}', '{"kind":"stale-worker"}'::jsonb);
|
||||
`));
|
||||
const durable = JSON.parse(fixture.psql(`select payload from public.personal_report_sections where user_id = '${USER_A}' and request_id = '${REQUEST_ID}' and section_id = '${LONGFORM_SNAPSHOT_SECTION_ID}'`));
|
||||
assert.deepEqual(validateLongformSnapshot(durable, identity), snapshot);
|
||||
assert.equal(fixture.psqlAs("app_runtime", "app-runtime-test-password", selectAsAuthenticated(USER_B, `select count(*) from public.personal_report_sections where section_id = '${LONGFORM_SNAPSHOT_SECTION_ID}'`)), `SET\n${USER_B}\n0`);
|
||||
} finally {
|
||||
fixture.stop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user