feat(lex): Politics view — counts only with accuracy, seats once per specialty, names as posted (S1)
This commit is contained in:
@@ -247,6 +247,30 @@ table.tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
|
||||
.st.oppose { background: var(--st-oppose); }
|
||||
.st.unclear { background: var(--st-unclear); }
|
||||
.st.none { background: transparent; color: var(--border); font-weight: 400; }
|
||||
.st.unclassified { background: transparent; color: var(--muted-foreground); box-shadow: inset 0 0 0 1px var(--muted-foreground); }
|
||||
|
||||
/* politics: one panel per classified comment event; the seat cell spans its specialty's rows */
|
||||
.pol-legend { margin: 12px 0 4px; }
|
||||
.pol-panel { border-top: 3px solid var(--foreground); padding-top: .75rem; margin-top: 1.75rem; min-width: 0; }
|
||||
.view .pol-panel h3 { margin: 0 0 .5rem; }
|
||||
.pol-meta { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 0 0 10px; }
|
||||
.pol-meta .pill { white-space: normal; }
|
||||
.pol-meta .acc { margin: 0; }
|
||||
table.pol-tbl { font-size: 12px; }
|
||||
.tbl.pol-tbl th, .tbl.pol-tbl td { padding: 5px; }
|
||||
.tbl.pol-tbl th { white-space: normal; letter-spacing: .05em; }
|
||||
.pol-tbl td.spec { hyphens: auto; }
|
||||
.pol-tbl td .basis { font-size: 11px; line-height: 1.35; margin-top: 2px; }
|
||||
.pol-tbl td.names { min-width: 7.5rem; }
|
||||
.pol-tbl td.exp { min-width: 6.5rem; }
|
||||
.pol-tbl td.delta { min-width: 5.5rem; }
|
||||
.pol-tbl td.stance { min-width: 3.9rem; line-height: 1.6; }
|
||||
.pol-tbl td.stance .st { margin: 0 3px 3px 0; }
|
||||
.tbl.pol-tbl tbody td.seat { background: var(--card); border-left: 2px solid var(--border); }
|
||||
.tbl.pol-tbl tbody tr.grp td { border-top: 2px solid var(--muted-foreground); }
|
||||
.pol-yr { display: grid; gap: 6px; min-width: 0; }
|
||||
.pol-yr .eyebrow { margin-top: 4px; }
|
||||
.pol-yr .cite { white-space: normal; overflow-wrap: anywhere; }
|
||||
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 13px; color: var(--secondary-foreground); }
|
||||
.legend span { display: inline-flex; gap: 6px; align-items: center; }
|
||||
.sw { width: 12px; height: 12px; display: inline-block; }
|
||||
|
||||
@@ -1,10 +1,181 @@
|
||||
// lex · Politics view. A stub until S1 Task 9 fills it in.
|
||||
// lex · Politics view: who commented on each classified rule event, by
|
||||
// organization type and specialty, then our classification, CMS's own
|
||||
// summary and the money and power stakes by year.
|
||||
//
|
||||
// A view module exports needs (the API slices it reads), render(data, state)
|
||||
// returning markup, and optionally mount(root, data, state, nav).
|
||||
// Display rules (anti-goals; each has a test):
|
||||
// - a stance count never appears before its own panel's accuracy line, and a
|
||||
// panel or stance split without one gets NO_ACCURACY (S1-P3);
|
||||
// - the payment change is the stored delta_text and the share the stored
|
||||
// share_text: delta_total and share are never formatted here;
|
||||
// - RUC seats appear once per specialty: one cell spanning its rows;
|
||||
// - commenter names are the stored names, escaped and otherwise untouched
|
||||
// (public record): never hidden, re-cased or read as prose;
|
||||
// - CMS's summaries sit in their own labelled section, apart from ours;
|
||||
// - a fact's note shows as a flag (factHtml);
|
||||
// - every panel's org type and specialty labels carry the identity marker;
|
||||
// - write actions are disabled controls marked coming · S2.
|
||||
|
||||
import { esc } from "./fmt.js";
|
||||
import { factHtml, tagged } from "./cite.js";
|
||||
import { comingButton } from "./shell.js";
|
||||
|
||||
export const needs = ["header", "politics"];
|
||||
|
||||
export function render() {
|
||||
return `<p class="muted">This view is being built.</p>`;
|
||||
/** The line shown when a stance count arrives without one. The slice
|
||||
* normally supplies the measured line; this is the JS's own (S1-P3). */
|
||||
export const NO_ACCURACY = "Stance counts are a model reading; accuracy not yet measured.";
|
||||
/** The flag for a panel that does not say how its labels were read. */
|
||||
export const NO_IDENTITY = "organization type and specialty labels: unreviewed";
|
||||
|
||||
const STANCES = ["support", "modify", "oppose", "unclear", "unclassified"];
|
||||
const STANCE_LABEL = { support: "support", modify: "asked for changes", oppose: "oppose", unclear: "unclear", unclassified: "not classified" };
|
||||
const TYPE_LABEL = {
|
||||
specialty_society: "Specialty society",
|
||||
health_system: "Health system",
|
||||
individual_clinician: "Individual clinician",
|
||||
other: "Other organization",
|
||||
patient_group: "Patient group",
|
||||
payer: "Payer",
|
||||
vendor: "Vendor",
|
||||
unknown: "Unknown",
|
||||
};
|
||||
const BASIS_LABEL = { letterhead_model: "letterhead, model", regs_gov_fields: "regulations.gov fields", both: "regulations.gov and letterhead agree" };
|
||||
const STAKES = [
|
||||
["money", "Money"],
|
||||
["seat", "Seats"],
|
||||
["impact", "CMS's estimated impact"],
|
||||
];
|
||||
|
||||
const typeLabel = (t) => TYPE_LABEL[t] || String(t || "").replace(/_/g, " ");
|
||||
const noSpec = (s) => !s || s === "NONE";
|
||||
// CMS specialty names are stored in capitals: "Physical medicine and rehabilitation"
|
||||
const specLabel = (s) => (noSpec(s) ? `<span class="muted">none identified</span>` : esc(String(s).toLowerCase().replace(/^\p{L}/u, (c) => c.toUpperCase())));
|
||||
const fid = (id) => parseInt(String(id).replace(/^\D+/, ""), 10) || 0;
|
||||
const byYearId = (a, b) => (a.year ?? 1e9) - (b.year ?? 1e9) || fid(a.id) - fid(b.id);
|
||||
|
||||
/** Units sorted by specialty (none identified last), then org type. */
|
||||
function sortUnits(units) {
|
||||
const key = (u) => [noSpec(u.specialty) ? 1 : 0, String(u.specialty || ""), String(u.org_type || "")];
|
||||
return [...units].sort((a, b) => {
|
||||
const [x, y] = [key(a), key(b)];
|
||||
return x[0] - y[0] || x[1].localeCompare(y[1]) || x[2].localeCompare(y[2]);
|
||||
});
|
||||
}
|
||||
|
||||
/** One chip per non-zero count, in stance order (unknown stances last). */
|
||||
function stanceChips(stance) {
|
||||
const entries = Object.entries(stance || {}).filter(([, n]) => Number(n) > 0);
|
||||
const rank = (k) => (STANCES.includes(k) ? STANCES.indexOf(k) : STANCES.length);
|
||||
entries.sort(([a], [b]) => rank(a) - rank(b) || a.localeCompare(b));
|
||||
if (!entries.length) return `<span class="st none" title="no stance on file">·</span>`;
|
||||
return entries.map(([k, n]) => `<span class="st ${esc(k)}" title="${esc(k)}">${esc(n)}</span>`).join("");
|
||||
}
|
||||
|
||||
function seatText(seat) {
|
||||
if (!seat) return "";
|
||||
const cpt = Number(seat.cpt) > 0 ? `, ${esc(seat.cpt)} CPT` : "";
|
||||
return `${esc(seat.ruc_permanent)} permanent, ${esc(seat.ruc_rotating)} rotating${cpt}`;
|
||||
}
|
||||
|
||||
/** The seat holders, as the roster names them, for the cell's title. */
|
||||
const seatTitle = (seat) => (seat && (seat.holders || []).length ? ` title="${esc("Held by " + seat.holders.join("; "))}"` : "");
|
||||
|
||||
function basisLine(u) {
|
||||
const parts = Object.entries(u.basis || {}).map(([k, n]) => `${esc(BASIS_LABEL[k] || k.replace(/_/g, " "))} ${esc(n)}`);
|
||||
return parts.length ? `<div class="basis muted">${parts.join(" · ")}</div>` : "";
|
||||
}
|
||||
|
||||
function unitsTable(p, facts) {
|
||||
const units = sortUnits(p.units || []);
|
||||
const seats = p.seats || {};
|
||||
let h = `<div class="tbl-wrap"><table class="tbl pol-tbl"><thead><tr><th>Org type</th><th>Specialty</th><th>Names as posted</th><th class="r">Commenters</th><th>Stance</th><th>Expected</th><th class="r">Billing share</th><th class="r">Payment change</th><th>RUC seats</th></tr></thead><tbody>`;
|
||||
units.forEach((u, i) => {
|
||||
const first = i === 0 || units[i - 1].specialty !== u.specialty;
|
||||
let span = 1;
|
||||
while (first && i + span < units.length && units[i + span].specialty === u.specialty) span++;
|
||||
const expected = u.expected ? `${esc(u.expected)}${u.expected_reason ? `<div class="small muted">${tagged(u.expected_reason, facts)}</div>` : ""}` : `<span class="muted">—</span>`;
|
||||
h += `<tr data-unit="${esc(u.specialty)}|${esc(u.org_type)}"${first && i ? ' class="grp"' : ""}>`;
|
||||
h += `<td>${esc(typeLabel(u.org_type))}${basisLine(u)}</td>`;
|
||||
h += `<td class="spec">${specLabel(u.specialty)}</td>`;
|
||||
h += `<td class="names">${esc((u.names || []).join("; "))}</td>`;
|
||||
h += `<td class="r num">${esc(u.n_commenters)}</td>`;
|
||||
h += `<td class="stance">${stanceChips(u.stance)}</td>`;
|
||||
h += `<td class="exp">${expected}</td>`;
|
||||
h += `<td class="r num">${u.share_text ? esc(u.share_text) : `<span class="muted">—</span>`}</td>`;
|
||||
h += `<td class="r delta">${u.delta_text ? esc(u.delta_text) : `<span class="muted">—</span>`}</td>`;
|
||||
if (first) h += `<td class="seat" rowspan="${span}"${seatTitle(seats[u.specialty])}>${seatText(seats[u.specialty])}</td>`;
|
||||
h += `</tr>`;
|
||||
});
|
||||
return h + `</tbody></table></div>`;
|
||||
}
|
||||
|
||||
function panelHtml(p, facts) {
|
||||
const docket = String(p.docket || "");
|
||||
const link = docket ? ` · <a href="${esc("https://www.regulations.gov/docket/" + encodeURIComponent(docket))}" target="_blank" rel="noopener">${esc(docket)}</a>` : "";
|
||||
const roster = p.roster_year ? `RUC roster ${esc(p.roster_year)}${p.roster_note ? ` (${tagged(p.roster_note, facts)})` : ""}` : "RUC roster not captured";
|
||||
const extractors = Array.from(new Set((p.units || []).flatMap((u) => u.extractor || [])));
|
||||
const by = extractors.length ? ` <span class="small muted">read by ${esc(extractors.join(", "))}</span>` : "";
|
||||
let h = `<section class="pol-panel" data-panel="${esc(p.event_key)}">`;
|
||||
h += `<h3>CY${esc(p.rule_year)} · ${tagged(p.event_text, facts)}${link}</h3>`;
|
||||
h += `<div class="pol-meta"><p class="acc">${esc(p.accuracy || NO_ACCURACY)}</p>`;
|
||||
h += `<div><span class="pill model">${esc(p.identity || NO_IDENTITY)}</span>${by}</div>`;
|
||||
h += `<div class="small">${roster}</div></div>`;
|
||||
return h + unitsTable(p, facts) + `</section>`;
|
||||
}
|
||||
|
||||
/** A stance split always shows an accuracy line: its own field, a line in
|
||||
* its text, or the constant. */
|
||||
function withAccuracy(f, lines) {
|
||||
if (f.kind !== "stance_split" || f.accuracy) return f;
|
||||
const text = String(f.text || "");
|
||||
return lines.some((l) => l && text.includes(l)) ? f : { ...f, accuracy: NO_ACCURACY };
|
||||
}
|
||||
|
||||
function yearBlocks(list, inner) {
|
||||
const years = Array.from(new Set(list.map((f) => f.year))).sort((a, b) => (a ?? 1e9) - (b ?? 1e9));
|
||||
return years
|
||||
.map((y) => {
|
||||
const its = list.filter((f) => f.year === y);
|
||||
return `<div class="tl-year"><h4>${y == null ? "Undated" : "CY" + esc(y)}<small>${its.length} ${its.length === 1 ? "fact" : "facts"}</small></h4><div class="pol-yr">${inner(its)}</div></div>`;
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
|
||||
const list = (fs) => `<ul class="facts">${fs.map((f) => factHtml(f)).join("")}</ul>`;
|
||||
|
||||
export function render(data) {
|
||||
const P = data.politics || {};
|
||||
const facts = P.facts || {};
|
||||
const panels = P.panels || [];
|
||||
const all = Object.values(facts).sort(byYearId);
|
||||
const lines = [P.stance_accuracy, ...panels.map((p) => p.accuracy)];
|
||||
const of = (kind) => all.filter((f) => f.kind === kind).map((f) => withAccuracy(f, lines));
|
||||
const shown = new Set(["stance_split", "cms_summary", ...STAKES.map(([k]) => k)]);
|
||||
const other = all.filter((f) => !shown.has(f.kind));
|
||||
|
||||
let h = `<div class="col-h"><h2>Politics</h2><span class="pill prelim">preliminary</span></div>
|
||||
<p class="lede">Who commented on each classified rule event, by organization type and specialty, with names as posted on regulations.gov. Beside each unit: our stance count, the stance its money stakes would predict, its billing share, its payment change and its RUC seats. CMS's own summaries are listed apart and never merged with our counts.</p>`;
|
||||
h += `<div class="panel warn small" data-stance-accuracy><b>Stance counts.</b> Read by a local model. ${esc(P.stance_accuracy || NO_ACCURACY)}</div>`;
|
||||
h += `<div class="legend pol-legend">${STANCES.map((s) => `<span><span class="st ${s}" aria-hidden="true"></span>${STANCE_LABEL[s]}</span>`).join("")}</div>`;
|
||||
h += `<div class="filters">${comingButton("Flag this")}<span class="small muted">Sends a stance or a label to the review queue.</span></div>`;
|
||||
|
||||
h += panels.length ? panels.map((p) => panelHtml(p, facts)).join("") : `<p class="muted">No classified comment events for this family yet.</p>`;
|
||||
|
||||
const ours = of("stance_split");
|
||||
const cms = of("cms_summary");
|
||||
const stakes = all.filter((f) => STAKES.some(([k]) => k === f.kind));
|
||||
h += `<section class="sec" data-sec="ours"><div class="col-h"><h3>Our classification</h3><span class="pill prelim">preliminary</span></div>${ours.length ? yearBlocks(ours, list) : `<p class="small muted">No stance splits on file.</p>`}</section>`;
|
||||
h += `<section class="sec" data-sec="cms"><div class="col-h"><h3>CMS's summary</h3><span class="pill cms">cms</span></div><p class="small muted">CMS's own words; never merged with our counts.</p>${cms.length ? yearBlocks(cms, list) : `<p class="small muted">No CMS summaries on file.</p>`}</section>`;
|
||||
h += `<section class="sec" data-sec="stakes"><h3>Stakes: money and power</h3><p class="small muted">What each specialty stood to gain or lose, its RUC and CPT seats, and CMS's own impact estimate, by rule year.</p>${
|
||||
stakes.length
|
||||
? yearBlocks(stakes, (fs) =>
|
||||
STAKES.map(([k, label]) => {
|
||||
const mine = fs.filter((f) => f.kind === k);
|
||||
return mine.length ? `<span class="eyebrow">${label}</span>${list(mine)}` : "";
|
||||
}).join(""),
|
||||
)
|
||||
: `<p class="small muted">No stakes on file.</p>`
|
||||
}</section>`;
|
||||
if (other.length) h += `<section class="sec" data-sec="other"><h3>Other facts</h3>${list(other)}</section>`;
|
||||
return h;
|
||||
}
|
||||
|
||||
260
tests/lex/views-politics.test.mjs
Normal file
260
tests/lex/views-politics.test.mjs
Normal file
@@ -0,0 +1,260 @@
|
||||
// lex · Politics view. One test per display rule (global-constraints.md,
|
||||
// Content rules), plus the brief's checks.
|
||||
import { test } from "node:test";
|
||||
import { equal as eq, deepEqual as deq, ok } from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
import { parseLocation } from "../../infra/gitea/custom/public/assets/dossier/state.js";
|
||||
import { esc } from "../../infra/gitea/custom/public/assets/dossier/fmt.js";
|
||||
import * as politics from "../../infra/gitea/custom/public/assets/dossier/view-politics.js";
|
||||
|
||||
const fx = (name) => JSON.parse(readFileSync(new URL(`./fixtures/${name}.json`, import.meta.url), "utf8"));
|
||||
const H = fx("header");
|
||||
const POL = fx("politics");
|
||||
const P0 = POL.panels[0];
|
||||
const st = (url) => parseLocation(new URL(url, "https://lex.test"));
|
||||
const count = (s, sub) => s.split(sub).length - 1;
|
||||
const page = (pol = POL, url = "/politics?family=HOME-VISITS") => politics.render({ header: H, politics: pol }, st(url));
|
||||
|
||||
// the live panel marker and unit fields (Plan A fix): see the live dump
|
||||
const IDENTITY = "organization type and specialty: model reading, unreviewed";
|
||||
const live = (p) => ({
|
||||
...p,
|
||||
identity: IDENTITY,
|
||||
units: p.units.map((u, i) => ({ ...u, basis: i ? { regs_gov_fields: 1 } : { letterhead_model: 1 }, extractor: ["model:qwen2.5:14b@identity-v5"] })),
|
||||
});
|
||||
|
||||
/** Each stance panel's own markup (S1-P4: checks are scoped to it). */
|
||||
const panels = (out) => out.split('<section class="pol-panel"').slice(1).map((s) => s.slice(0, s.indexOf("</section>")));
|
||||
/** A section's own markup, by its data-sec name. */
|
||||
const section = (out, name) => {
|
||||
const i = out.indexOf(`data-sec="${name}"`);
|
||||
return i < 0 ? "" : out.slice(i, out.indexOf("</section>", i));
|
||||
};
|
||||
|
||||
test("politics: the brief's checks", () => {
|
||||
const out = page();
|
||||
eq(politics.needs.join(), "header,politics");
|
||||
const [p0] = panels(out);
|
||||
ok(p0.indexOf(P0.accuracy) >= 0 && p0.indexOf(P0.accuracy) < p0.indexOf('class="st support"'));
|
||||
eq((out.match(/1 permanent, 0 rotating/g) || []).length, 1);
|
||||
ok(out.includes("a cut of at least $12,106") && !out.includes("-12105") && !out.includes("-12,106"));
|
||||
ok(out.includes("jane q. DOE") && out.includes("ACME health LLC"));
|
||||
ok(out.indexOf("Our classification") < out.indexOf("CMS's summary"));
|
||||
for (const id of Object.keys(POL.facts)) ok(out.includes(`data-fact="${id}"`), id);
|
||||
const bare = page({ ...POL, panels: [{ ...P0, accuracy: "" }] }, "/politics?family=X");
|
||||
ok(bare.includes(politics.NO_ACCURACY));
|
||||
});
|
||||
|
||||
test("politics: the page-level accuracy panel comes first and carries stance_accuracy", () => {
|
||||
const out = page();
|
||||
const top = out.indexOf("data-stance-accuracy");
|
||||
ok(top >= 0 && top < out.indexOf('<section class="pol-panel"'));
|
||||
ok(out.slice(top, out.indexOf("</div>", top)).includes(POL.stance_accuracy));
|
||||
// no page-level line: the generic constant, still before any panel
|
||||
const none = page({ ...POL, stance_accuracy: "" });
|
||||
const t2 = none.indexOf("data-stance-accuracy");
|
||||
ok(none.slice(t2, none.indexOf("</div>", t2)).includes(politics.NO_ACCURACY));
|
||||
});
|
||||
|
||||
test("rule: stance counts appear only with their accuracy line, in each panel's own container (S1-P4)", () => {
|
||||
const second = { ...P0, event_key: "HV:2023:y", event_text: "second event", accuracy: "Second panel's own line." };
|
||||
const out = page({ ...POL, panels: [P0, second, { ...P0, event_key: "HV:2023:z", accuracy: "" }] });
|
||||
const ps = panels(out);
|
||||
eq(ps.length, 3);
|
||||
const lines = [P0.accuracy, "Second panel's own line.", politics.NO_ACCURACY];
|
||||
ps.forEach((p, i) => {
|
||||
const first = p.indexOf('class="st ');
|
||||
ok(first > 0, `panel ${i} shows counts`);
|
||||
const at = p.indexOf(esc(lines[i]));
|
||||
ok(at >= 0 && at < first, `panel ${i}: accuracy before counts`);
|
||||
});
|
||||
// the page-level line cannot stand in for a panel's: panel 2 has only the constant
|
||||
ok(!ps[2].includes(POL.stance_accuracy));
|
||||
// S1-P3: the JS constant is its own, never the Python sentence
|
||||
ok(politics.NO_ACCURACY.includes("accuracy not yet measured"));
|
||||
ok(!politics.NO_ACCURACY.includes("its accuracy is not yet measured"));
|
||||
});
|
||||
|
||||
test("rule: a stance count carries its stance class and name, one chip per non-zero entry", () => {
|
||||
const u = { ...P0.units[0], stance: { oppose: 2, support: 3, modify: 0, unclassified: 4 } };
|
||||
const out = page({ ...POL, panels: [{ ...P0, units: [u] }] });
|
||||
const [p] = panels(out);
|
||||
ok(p.includes('<span class="st support" title="support">3</span>'));
|
||||
ok(p.includes('<span class="st oppose" title="oppose">2</span>'));
|
||||
ok(p.includes('<span class="st unclassified" title="unclassified">4</span>'));
|
||||
ok(!p.includes('class="st modify"'), "a zero count is not shown");
|
||||
ok(p.indexOf('class="st support"') < p.indexOf('class="st oppose"'), "support, modify, oppose, unclear, unclassified");
|
||||
});
|
||||
|
||||
test("rule: a stance split without an accuracy line gets the constant (a count never travels alone)", () => {
|
||||
const F = { ...POL.facts.F7, id: "F99", text: "Of 3 commenters we classified, 2 supported and 1 opposed." };
|
||||
delete F.accuracy;
|
||||
const out = page({ ...POL, facts: { ...POL.facts, F99: F } });
|
||||
const li = out.slice(out.indexOf('data-fact="F99"'), out.indexOf("</li>", out.indexOf('data-fact="F99"')));
|
||||
ok(li.includes(politics.NO_ACCURACY));
|
||||
// facts that carry their line (in the text, or as accuracy) are left as they are
|
||||
const f7 = out.slice(out.indexOf('data-fact="F7"'), out.indexOf("</li>", out.indexOf('data-fact="F7"')));
|
||||
ok(!f7.includes(politics.NO_ACCURACY) && f7.includes("it finds 80% of hand-coded positions"));
|
||||
const f8 = out.slice(out.indexOf('data-fact="F8"'), out.indexOf("</li>", out.indexOf('data-fact="F8"')));
|
||||
ok(!f8.includes(politics.NO_ACCURACY) && f8.includes('class="acc"'));
|
||||
});
|
||||
|
||||
test("rule: the payment change is the stored delta_text; delta_total and share are never formatted", () => {
|
||||
const u = { ...P0.units[0], delta_total: -98765.4321, share: 0.123456, share_text: "5.0%", delta_text: "a cut of at least $12,106" };
|
||||
const up = { ...P0.units[1], delta_total: 804.57, delta_lower_bound: true, delta_text: "an increase of at least $805", share: 0.00008, share_text: "<0.1%" };
|
||||
const out = page({ ...POL, panels: [{ ...P0, units: [u, up, P0.units[2]] }] });
|
||||
ok(out.includes("a cut of at least $12,106") && out.includes("an increase of at least $805"));
|
||||
ok(out.includes("5.0%") && out.includes("<0.1%"));
|
||||
for (const bad of ["98765", "98,765", "-98", "12.3", "0.123", "804.57", "804.6", "0.00008", "$-"]) ok(!out.includes(bad), bad);
|
||||
// an empty delta_text is a dash, never a number made from delta_total
|
||||
const blank = page({ ...POL, panels: [{ ...P0, units: [{ ...u, delta_text: "", share_text: "" }] }] });
|
||||
ok(!blank.includes("98765") && !blank.includes("12.3%"));
|
||||
});
|
||||
|
||||
test("rule: RUC seats appear once per specialty, one cell spanning that specialty's rows", () => {
|
||||
const out = page();
|
||||
const [p] = panels(out);
|
||||
// CARDIOLOGY has two units (a society and a clinician): one seat cell over both
|
||||
eq(count(p, 'class="seat"'), 2, "one cell per specialty: CARDIOLOGY and NONE");
|
||||
ok(p.includes('<td class="seat" rowspan="2" title="Held by American College of Cardiology">1 permanent, 0 rotating</td>'));
|
||||
ok(/<td class="seat" rowspan="1"><\/td>/.test(p), "a specialty with no seats: an empty cell");
|
||||
// rows sort by specialty, then org type; the society's row comes after the clinician's
|
||||
const rows = p.match(/<tr data-unit[^>]*>/g);
|
||||
deq(rows.map((r) => r.match(/data-unit="([^"]*)"/)[1]), ["CARDIOLOGY|individual_clinician", "CARDIOLOGY|specialty_society", "NONE|health_system"]);
|
||||
// CPT seats join the line only when there are any
|
||||
const seats = { CARDIOLOGY: { ...P0.seats.CARDIOLOGY, ruc_rotating: 1, cpt: 2 } };
|
||||
const cpt = page({ ...POL, panels: [{ ...P0, seats }] });
|
||||
eq(count(cpt, "1 permanent, 1 rotating, 2 CPT"), 1);
|
||||
// two specialties with seats: each line once, the holder named once
|
||||
const two = {
|
||||
...P0,
|
||||
units: [...P0.units, { ...P0.units[1], org_type: "specialty_society", specialty: "GERIATRIC MEDICINE", names: ["American Geriatrics Society"] }],
|
||||
seats: { ...P0.seats, "GERIATRIC MEDICINE": { ruc_permanent: 1, ruc_rotating: 0, cpt: 0, holders: ["American Geriatrics Society"], item_keys: ["X"] } },
|
||||
};
|
||||
const t = panels(page({ ...POL, panels: [two] }))[0];
|
||||
eq(count(t, "1 permanent, 0 rotating"), 2);
|
||||
eq(count(t, 'class="seat"'), 3);
|
||||
});
|
||||
|
||||
test("rule: the panel heading, docket link and RUC roster line", () => {
|
||||
const out = page();
|
||||
const [p] = panels(out);
|
||||
ok(p.includes("CY2023 · invented event · "));
|
||||
ok(p.includes('href="https://www.regulations.gov/docket/CMS-0000-0001"'));
|
||||
ok(p.includes("RUC roster 2022") && !p.includes("RUC roster 2022 ()"));
|
||||
const noted = panels(page({ ...POL, panels: [{ ...P0, roster_note: "the RUC that valued CY2023 met in 2022" }] }))[0];
|
||||
ok(noted.includes("RUC roster 2022 (the RUC that valued CY2023 met in 2022)"));
|
||||
const none = panels(page({ ...POL, panels: [{ ...P0, roster_year: null, roster_note: "" }] }))[0];
|
||||
ok(none.includes("RUC roster not captured"));
|
||||
// the line sits before the table, after the accuracy line
|
||||
ok(p.indexOf(P0.accuracy) < p.indexOf("RUC roster") && p.indexOf("RUC roster") < p.indexOf("<table"));
|
||||
});
|
||||
|
||||
test("rule: commenter names appear as posted (case, spelling, counts), escaped and joined with '; '", () => {
|
||||
const names = ["jane q. DOE", "McDONALD & sons <Clinic>", "individual commenter ×2", "Dr. [F6] Smith"];
|
||||
const u = { ...P0.units[1], names };
|
||||
const out = page({ ...POL, panels: [{ ...P0, units: [u] }] });
|
||||
ok(out.includes("jane q. DOE; McDONALD & sons <Clinic>; individual commenter ×2; Dr. [F6] Smith"));
|
||||
ok(!out.includes("<Clinic>"));
|
||||
// a name is never read as prose: "[F6]" stays text, not a citation
|
||||
const [p] = panels(out);
|
||||
ok(!p.includes('data-ref="F6"'));
|
||||
// the header says these are names as posted
|
||||
ok(p.includes("Names as posted"));
|
||||
});
|
||||
|
||||
test("rule: CMS's summaries are labelled and never merged with our classification", () => {
|
||||
const out = page();
|
||||
const ours = section(out, "ours");
|
||||
const cms = section(out, "cms");
|
||||
ok(ours.includes("<h3>Our classification</h3>"));
|
||||
ok(cms.includes("<h3>CMS's summary</h3>"), "a literal heading, not escaped");
|
||||
ok(/class="pill cms">cms</.test(cms));
|
||||
ok(cms.includes("CMS's own words; never merged with our counts"));
|
||||
for (const [id, f] of Object.entries(POL.facts)) {
|
||||
if (f.kind === "cms_summary") ok(cms.includes(`data-fact="${id}"`) && !ours.includes(`data-fact="${id}"`), id);
|
||||
if (f.kind === "stance_split") ok(ours.includes(`data-fact="${id}"`) && !cms.includes(`data-fact="${id}"`), id);
|
||||
}
|
||||
ok(out.indexOf('data-sec="ours"') < out.indexOf('data-sec="cms"'));
|
||||
ok(out.indexOf('data-sec="cms"') < out.indexOf('data-sec="stakes"'));
|
||||
});
|
||||
|
||||
test("rule: stakes list money, seat and impact facts by year", () => {
|
||||
const out = page();
|
||||
const s = section(out, "stakes");
|
||||
ok(s.includes("<h3>Stakes: money and power</h3>"));
|
||||
for (const id of ["F13", "F14", "F15"]) ok(s.includes(`data-fact="${id}"`), id);
|
||||
// years ascending: the CY2022 seat before the CY2023 money and impact
|
||||
ok(s.indexOf("CY2022") < s.indexOf("CY2023"));
|
||||
ok(s.indexOf('data-fact="F15"') < s.indexOf('data-fact="F14"'));
|
||||
ok(!s.includes('data-fact="F6"') && !s.includes('data-fact="F7"'));
|
||||
});
|
||||
|
||||
test("rule: a fact's note renders as a flag", () => {
|
||||
const facts = { ...POL.facts, F14: { ...POL.facts.F14, note: "model extract, unreviewed" }, F6: { ...POL.facts.F6, note: "model paraphrase, unreviewed" } };
|
||||
const out = page({ ...POL, facts });
|
||||
const li = (id) => out.slice(out.indexOf(`data-fact="${id}"`), out.indexOf("</li>", out.indexOf(`data-fact="${id}"`)));
|
||||
ok(li("F14").includes('<span class="pill model">model extract, unreviewed</span>'));
|
||||
ok(li("F6").includes('<span class="pill model">model paraphrase, unreviewed</span>'));
|
||||
});
|
||||
|
||||
test("rule: the identity marker flags every org type × specialty panel", () => {
|
||||
const out = page({ ...POL, panels: [live(P0), live({ ...P0, event_key: "HV:2023:y" })] });
|
||||
const ps = panels(out);
|
||||
eq(ps.length, 2);
|
||||
for (const p of ps) {
|
||||
ok(p.includes(`<span class="pill model">${IDENTITY}</span>`));
|
||||
// how the labels were read: the basis per unit, the extractor once per panel
|
||||
ok(p.includes("letterhead, model 1") && p.includes("regulations.gov fields 1"));
|
||||
eq(count(p, "model:qwen2.5:14b@identity-v5"), 1);
|
||||
}
|
||||
// a panel without the marker is still flagged unreviewed, with the JS's own words
|
||||
const [bare] = panels(page());
|
||||
ok(bare.includes(`<span class="pill model">${politics.NO_IDENTITY}</span>`));
|
||||
ok(politics.NO_IDENTITY !== IDENTITY && politics.NO_IDENTITY.includes("unreviewed"));
|
||||
});
|
||||
|
||||
test("rule: write actions are disabled and marked coming · S2", () => {
|
||||
const out = page();
|
||||
const buttons = out.match(/<button[^>]*>[^<]*<\/button>[^<]*<span[^>]*>[^<]*<\/span>/g) || [];
|
||||
ok(buttons.length >= 1);
|
||||
eq(buttons.length, count(out, "<button"));
|
||||
for (const b of buttons) ok(/disabled/.test(b) && b.includes("coming · S2"), b);
|
||||
});
|
||||
|
||||
test("politics: event text and reasons are prose: [F#] tags become cites (tagged)", () => {
|
||||
const p1 = { ...P0, event_text: "invented event [F6]", units: [{ ...P0.units[0], expected_reason: "a reason [F14][F14]" }] };
|
||||
const out = page({ ...POL, panels: [p1] });
|
||||
const [p] = panels(out);
|
||||
ok(p.includes('data-ref="F6"') && p.includes('data-ref="F14"'));
|
||||
eq(count(p, 'data-ref="F14"'), 1, "a repeated tag is one chip");
|
||||
ok(!p.includes("[F6]") && !p.includes("[F14]"));
|
||||
});
|
||||
|
||||
test("politics: expected stance with its reason, specialty and org type labels", () => {
|
||||
const [p] = panels(page());
|
||||
ok(p.includes("support") && p.includes("invented reason"));
|
||||
ok(p.includes("Specialty society") && p.includes("Individual clinician") && p.includes("Health system"));
|
||||
ok(p.includes("Cardiology"));
|
||||
ok(/<th[^>]*>Billing share<\/th>/.test(p) && /<th[^>]*>Payment change<\/th>/.test(p) && /<th[^>]*>RUC seats<\/th>/.test(p));
|
||||
const heads = p.match(/<th[^>]*>[^<]*<\/th>/g).map((h) => h.replace(/<[^>]+>/g, ""));
|
||||
deq(heads, ["Org type", "Specialty", "Names as posted", "Commenters", "Stance", "Expected", "Billing share", "Payment change", "RUC seats"]);
|
||||
});
|
||||
|
||||
test("politics: injected strings are escaped", () => {
|
||||
const evil = "<img src=x onerror=alert(1)>";
|
||||
const u = { ...P0.units[0], org_type: evil, specialty: evil, names: [evil], stance: { [evil]: 1 }, expected: evil, expected_reason: evil, share_text: evil, delta_text: evil, basis: { [evil]: 1 }, extractor: [evil] };
|
||||
const p1 = { ...P0, docket: evil, event_text: evil, roster_note: evil, accuracy: evil, identity: evil, units: [u], seats: { [evil]: { ruc_permanent: evil, ruc_rotating: 0, cpt: 0, holders: [evil] } } };
|
||||
const out = page({ ...POL, stance_accuracy: evil, panels: [p1] });
|
||||
ok(!out.includes("<img"), "no raw markup");
|
||||
ok(out.includes("<img src=x onerror=alert(1)>"));
|
||||
});
|
||||
|
||||
test("politics: no panels, and a fact of an unknown kind is still listed", () => {
|
||||
const facts = { ...POL.facts, F77: { ...POL.facts.F14, id: "F77", kind: "brand_new", text: "A new kind." } };
|
||||
const out = page({ ...POL, panels: [], facts });
|
||||
ok(out.includes("No classified comment events"));
|
||||
ok(out.includes('data-fact="F77"'));
|
||||
for (const id of Object.keys(facts)) ok(out.includes(`data-fact="${id}"`), id);
|
||||
});
|
||||
Reference in New Issue
Block a user