import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { classifyReportEnvelope } from "../src/components/personal-report/personal-report-page.tsx";
import type { BirthSkyPaletteName } from "../src/lib/birth-sky/draw.ts";
import { loadReportSkyCover } from "../src/lib/birth-sky/report-cover.ts";
import { goldenSky } from "./birth-sky-test-support.ts";
// Report cover (TASK-birth-sky-followup-20260928 F3).
const page = readFileSync(new URL("../src/components/personal-report/personal-report-page.tsx", import.meta.url), "utf8");
const component = readFileSync(new URL("../src/components/birth-sky/report-sky-cover.tsx", import.meta.url), "utf8");
const css = readFileSync(new URL("../src/components/birth-sky/report-sky-cover.css", import.meta.url), "utf8");
function readyEnvelope(coverSubject?: unknown) {
return {
report: {
id: "11111111-1111-4111-8111-111111111111",
status: "ready",
createdAt: "2026-09-28T00:00:00.000Z",
...(coverSubject === undefined ? {} : { coverSubject }),
},
longformMarkdown: "# 报告\n\n正文。",
};
}
test("matching fingerprint → the ready state carries coverSubject; mismatch or legacy → no cover", () => {
const bound = classifyReportEnvelope(200, readyEnvelope("self"));
assert.equal(bound.phase, "markdown-ready");
assert.equal(bound.phase === "markdown-ready" && bound.coverSubject, "self");
for (const value of [null, undefined, "", 42]) {
const state = classifyReportEnvelope(200, readyEnvelope(value));
assert.equal(state.phase, "markdown-ready");
assert.equal("coverSubject" in state, false, `coverSubject=${String(value)}`);
}
});
test("the cover sits above the body, lazy, and only when coverSubject is set", () => {
assert.match(page, /\{state\.coverSubject \? : null\}\s* import\("@\/components\/birth-sky\/report-sky-cover"\)/);
// No buttons, no placeholder, no waiting state.
assert.doesNotMatch(component, /