mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
Five layers, because the defect had five places to hide. The catalogue guard checks what the compiler cannot state: every leaf resolves a label a human can read, every group resolves one, the fenced tier stays last, and the shipped template intersects the fence at nothing. The selection guard pins the three minting functions against each other. A stored blob this build cannot read resolves to the empty selection, never to a default set — that is what makes the revoked legacy links revocable rather than silently re-scoped. A request naming an id the server does not know is refused by name rather than dropped, because dropping it would narrow a scope the caller did express. The egress guard freezes the set of aggregator callers with the source of each one's selection written down. The required brand-typed parameter already stops a new path compiling without an answer; this stops one being added without a human writing the answer down, which is the moment a reviewer asks the question. The behavioural sweep aggregates every leaf in and out against a fixture that carries a row for each, and asserts the payload differs. It is parametrised over the catalogue, so a leaf added later is covered the day it is added. Its positive control asserts the all-on payload is genuinely populated first, so a "no difference" result means the gate is inert and not that the account is empty. Beside it: an unmapped measurement type is excluded rather than passed through, no table behind an unchosen leaf is queried at all, and an empty selection produces an empty record. The artefact layer runs the real route and reads what comes out — the FHIR bundle, the PDF text and the zip's contents — with a positive control beside every exclusion. Mutation-checked: making the gate admit everything reddens the sweep for every leaf; passing an unmapped type through reddens the fail-closed case; dropping the mood query's condition reddens the zero-read case; returning the BMI unconditionally reddens the sweep naming BODY_MASS_INDEX; adding a fenced leaf to the template reddens the purity guard; removing the panel's seeding block reddens the first-run and repeat-run cases; dropping the insurance refusal reddens the share-link case; adding a caller outside the frozen list reddens the egress guard naming the file. The panel suite grew past the practice name it was written for and is renamed for what it now covers: the three states, the fenced tier having no group control, and the scope line naming its sensitive inclusions. Integration coverage moves to the leaf model, including the case this release exists for: an account with data in every domain and a caller that named nothing gets an empty record. The OpenAPI contract catches up with the routes — the required selection, the refused keys, the share summary's new fields, the moved `Patient/$everything`, the Coverage search and the five typed reads.
100 lines
3.3 KiB
TypeScript
100 lines
3.3 KiB
TypeScript
/**
|
|
* The selection type's contract: what each of the three minting functions does
|
|
* with input it does not recognise, and that absence never becomes inclusion.
|
|
*
|
|
* Mutation checks:
|
|
* - make `selectionFromStoredBlob` fall back to `STANDARD_TEMPLATE_LEAVES`
|
|
* instead of the empty selection → "an unreadable blob resolves to
|
|
* nothing" goes red.
|
|
* - make `selectionFromRequest` drop unknown ids instead of rejecting →
|
|
* "a request naming an id this build does not know is refused" goes red.
|
|
* - drop the `.filter(isReportLeafId)` in `selectionFromStoredBlob` → "a
|
|
* stored blob naming a retired leaf drops it" goes red.
|
|
*/
|
|
import { describe, it, expect } from "vitest";
|
|
|
|
import {
|
|
EMPTY_REPORT_SELECTION,
|
|
isEmptySelection,
|
|
selectionFromLeaves,
|
|
selectionFromRequest,
|
|
selectionFromStoredBlob,
|
|
selectionToBlob,
|
|
} from "../selection";
|
|
import { ALL_LEAF_IDS } from "../catalogue";
|
|
|
|
describe("report selection", () => {
|
|
it("treats absence as exclusion", () => {
|
|
const selection = selectionFromLeaves(["WEIGHT"]);
|
|
expect(selection.has("WEIGHT")).toBe(true);
|
|
// Everything else in the catalogue is out, without anyone saying so.
|
|
for (const leaf of ALL_LEAF_IDS) {
|
|
if (leaf === "WEIGHT") continue;
|
|
expect(selection.has(leaf)).toBe(false);
|
|
}
|
|
});
|
|
|
|
it("orders leaves by the catalogue, not by the caller", () => {
|
|
const selection = selectionFromLeaves(["LAB_RESULTS", "PULSE", "WEIGHT"]);
|
|
const expected = ALL_LEAF_IDS.filter((leaf) =>
|
|
["LAB_RESULTS", "PULSE", "WEIGHT"].includes(leaf),
|
|
);
|
|
expect(selection.leaves).toEqual(expected);
|
|
});
|
|
|
|
it("refuses a request naming an id this build does not know", () => {
|
|
const result = selectionFromRequest({
|
|
v: 2,
|
|
leaves: ["WEIGHT", "SOMETHING_NEW"],
|
|
});
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) {
|
|
expect(result.error.unknownLeaves).toEqual(["SOMETHING_NEW"]);
|
|
}
|
|
});
|
|
|
|
it("accepts a request naming only known ids", () => {
|
|
const result = selectionFromRequest({ v: 2, leaves: ["WEIGHT"] });
|
|
expect(result.ok).toBe(true);
|
|
if (result.ok) expect(result.selection.leaves).toEqual(["WEIGHT"]);
|
|
});
|
|
|
|
it("drops a retired leaf from a stored blob rather than failing", () => {
|
|
const selection = selectionFromStoredBlob({
|
|
v: 2,
|
|
leaves: ["WEIGHT", "SOMETHING_RETIRED"],
|
|
});
|
|
expect(selection.leaves).toEqual(["WEIGHT"]);
|
|
});
|
|
|
|
it("resolves an unreadable blob to nothing, never to a default", () => {
|
|
for (const raw of [
|
|
null,
|
|
undefined,
|
|
{},
|
|
{ v: 1, leaves: ["WEIGHT"] },
|
|
{ bp: true, weight: true, pulse: true },
|
|
"WEIGHT",
|
|
[],
|
|
]) {
|
|
const selection = selectionFromStoredBlob(raw);
|
|
expect(isEmptySelection(selection), `blob ${JSON.stringify(raw)}`).toBe(
|
|
true,
|
|
);
|
|
}
|
|
});
|
|
|
|
it("round-trips through the stored shape", () => {
|
|
const selection = selectionFromLeaves(["WEIGHT", "LAB_RESULTS"]);
|
|
const blob = selectionToBlob(selection);
|
|
expect(selectionFromStoredBlob(blob).leaves).toEqual(selection.leaves);
|
|
});
|
|
|
|
it("has an empty selection that admits nothing", () => {
|
|
expect(isEmptySelection(EMPTY_REPORT_SELECTION)).toBe(true);
|
|
for (const leaf of ALL_LEAF_IDS) {
|
|
expect(EMPTY_REPORT_SELECTION.has(leaf)).toBe(false);
|
|
}
|
|
});
|
|
});
|