fix(lex): facts index carries also-cite locators and the probe matches book also-cites exactly (S1-P10); the current tab scrolls into view on phones; book title only on licensed books; a citeless [F#] stays as text (S1)
Some checks failed
CI / lint (push) Successful in 58s
CI / notebooks-smoke (push) Successful in 2m3s
Deploy / changes (push) Successful in 18s
Infra CI / notebooks (push) Successful in 59s
CI / test (push) Failing after 4m32s
Infra CI / zotero (push) Successful in 29s
Infra CI / docs (push) Successful in 38s
Infra CI / api (push) Successful in 1m32s
Infra CI / bcda (push) Successful in 2m29s
Infra CI / llm (push) Successful in 1m26s
Deploy / notebooks (push) Has been skipped
Deploy / zotero (push) Has been skipped
Deploy / docs (push) Has been skipped
Infra CI / mc (push) Successful in 33s
Deploy / api (push) Successful in 1m42s
Deploy / report (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled

This commit is contained in:
kert
2026-11-13 03:42:52 -05:00
parent 4532b4daac
commit 0082ec80ce
8 changed files with 117 additions and 37 deletions

View File

@@ -14,7 +14,8 @@ Checks:
* ``smoke``: every view at 1440×900 and 390×844 must reach
``main[data-ready=<view>]`` within 15 s, with no page error, no console error
(failed Google Fonts loads aside) and no sideways page scroll. Screenshots go
(failed Google Fonts loads aside), no sideways page scroll, and its tab in
view inside the tab strip (which scrolls sideways on phones). Screenshots go
to ``--shots``.
* ``facts``: every fact of the family's facts index must be rendered on its
view with its citation: the link's href is the fact's url, or the locator
@@ -72,6 +73,15 @@ _CITES_JS = """el => ({
links: [...el.querySelectorAll("a.cite")].map((a) => a.getAttribute("href")),
books: [...el.querySelectorAll(".cite.book")].map((s) => s.textContent.trim()),
})"""
#: "" when the current tab lies inside the tab strip's visible box
_TAB_JS = """() => {
const on = document.querySelector("#tabs a.on");
if (!on) return "no current tab";
const w = on.closest(".tabs-wrap").getBoundingClientRect();
const r = on.getBoundingClientRect();
if (r.left >= w.left - 1 && r.right <= w.right + 1) return "";
return `the current tab is outside the tab strip (${Math.round(r.left)}-${Math.round(r.right)} of ${Math.round(w.left)}-${Math.round(w.right)})`;
}"""
_READY_JS = """v => {
const m = document.querySelector("main");
return !!m && (m.dataset.ready === v || m.dataset.ready === "error");
@@ -147,25 +157,20 @@ def fixture_file(
def fact_misses(entry: dict[str, Any], links: list[str], books: list[str]) -> list[str]:
"""What is missing of one fact's citation among the rendered cites. The
index lists the also-cites by url only; an empty one (a licensed book)
must show as one more locator span."""
"""What is missing of one fact's citation among the rendered cites: each
cite (the fact's own and every also-cite) is either a link whose href is
its url, or, with no url, a locator span whose text is its locator (else
its label), as the page renders it (R10)."""
fid = entry["id"]
out = []
if entry["url"]:
if entry["url"] not in links:
out.append(f"{fid}: link {entry['url']} not rendered")
else:
want = entry["locator"] or entry["label"]
if want not in books:
out.append(f"{fid}: locator {want!r} not rendered")
out += [
f"{fid}: also {u} not rendered" for u in entry["also"] if u and u not in links
]
empty = sum(1 for u in entry["also"] if not u)
spans = empty + (0 if entry["url"] else 1)
if empty and len(books) < spans:
out.append(f"{fid}: {spans} locator spans expected, {len(books)} rendered")
for what, c in [("", entry), *(("also ", a) for a in entry["also"])]:
if c["url"]:
if c["url"] not in links:
out.append(f"{fid}: {what}link {c['url']} not rendered")
else:
want = c["locator"] or c["label"]
if want not in books:
out.append(f"{fid}: {what}locator {want!r} not rendered")
return out
@@ -266,6 +271,9 @@ def smoke(browser: Any, args: argparse.Namespace, timeout_error: type) -> int:
if ready != view:
problems.append(f"main[data-ready] is {ready!r}")
problems += errors
tab = page.evaluate(_TAB_JS)
if tab:
problems.append(tab)
if sw > iw:
problems.append(f"the page scrolls sideways ({sw} > {iw})")
if shots:

View File

@@ -64,6 +64,19 @@ function filterRail() {
});
}
/** Bring the current tab into view inside the tab strip, which scrolls
* sideways on phones: the snapshot's scrollIntoView({inline: "nearest"}),
* done on the strip alone so the page itself never jumps to the tabs. */
function showTab() {
const on = el.tabs.querySelector("a.on");
const strip = el.tabs.parentElement;
if (!on || strip.scrollWidth <= strip.clientWidth) return;
const w = strip.getBoundingClientRect();
const r = on.getBoundingClientRect();
if (r.left < w.left) strip.scrollLeft -= w.left - r.left + 12;
else if (r.right > w.right) strip.scrollLeft += r.right - w.right + 12;
}
function fail(err, s) {
el.status.innerHTML = mastHtml(s, null, null, err);
el.mast.innerHTML = headHtml(s, null);
@@ -79,6 +92,7 @@ async function render() {
el.main.dataset.ready = "";
el.view.setAttribute("aria-busy", "true");
el.tabs.innerHTML = tabsHtml(s);
showTab();
if (s.family && (!store || store.family !== s.family)) store = new DossierStore(s.family);
const family = FAMILY_VIEWS.includes(s.view);
const modP = loadModule(s.view);
@@ -109,6 +123,7 @@ async function render() {
}
document.title = ["lex", data.header ? data.header.name : "", VIEW_TITLE[s.view]].filter(Boolean).join(" · ");
el.view.removeAttribute("aria-busy");
showTab();
el.main.dataset.ready = s.view;
if (s.fact) openFact(s.fact);
}
@@ -233,6 +248,8 @@ document.addEventListener("keydown", (e) => {
});
window.addEventListener("popstate", () => navigate(parseLocation(location), { push: false }));
window.addEventListener("resize", showTab);
if (document.fonts) document.fonts.ready.then(showTab); // tab widths change as the fonts load
el.q.addEventListener("input", filterRail);
/* ── tooltip for charts (data-tip) ── */

View File

@@ -41,12 +41,14 @@ export const CITE_KIND = {
const kindLabel = (k) => KIND_LABEL[k] || String(k || "fact").replace(/_/g, " ");
const linkable = (cite) => cite.kind !== "cpt_book" && /^https?:\/\//i.test(cite.url || "");
/** A cite as a link that opens apart, or as its locator when it has no url. */
/** A cite as a link that opens apart, or as its locator when it has no url
* (a licensed book says why its text is not shown). */
export function citeHtml(cite, { ref = "" } = {}) {
if (!cite) return "";
const r = ref ? ` data-ref="${esc(ref)}"` : "";
if (linkable(cite)) return `<a class="cite"${r} href="${esc(cite.url)}" target="_blank" rel="noopener">${esc(cite.label)}</a>`;
return `<span class="cite book"${r} title="${BOOK_TITLE}">${esc(cite.locator || cite.label)}</span>`;
const title = cite.kind === "cpt_book" ? ` title="${BOOK_TITLE}"` : "";
return `<span class="cite book"${r}${title}>${esc(cite.locator || cite.label)}</span>`;
}
const cites = (fact) => [fact.cite, ...(fact.also || [])].filter(Boolean);
@@ -63,12 +65,13 @@ export function factHtml(fact, { tag = "li" } = {}) {
}
/** Text with [F#] tags turned into the facts' cites; a run of one tag
* collapses to one cite, an unknown tag stays as text. */
* collapses to one cite. An unknown tag, or a fact with no cite, stays as
* text. */
export function tagged(text, facts) {
if (!text) return "";
return esc(text).replace(/\[(F\d+)\](?:\[\1\])*/g, (m, id) => {
const f = facts && Object.prototype.hasOwnProperty.call(facts, id) ? facts[id] : null;
return f ? citeHtml(f.cite, { ref: id }) : m;
return f && f.cite ? citeHtml(f.cite, { ref: id }) : m;
});
}

View File

@@ -303,7 +303,10 @@ def facts_index(d: Dossier) -> dict[str, Any]:
"url": f.cite.url,
"locator": f.cite.locator,
"note": f.note,
"also": [c.url for c in f.also],
"also": [
{"url": c.url, "locator": c.locator, "label": c.label}
for c in f.also
],
}
for f in d.facts.values()
],

View File

@@ -133,6 +133,10 @@ def test_fixture_file(tmp_path: Path) -> None:
}
def _also(url: str = "", locator: str = "", label: str = "") -> dict:
return {"url": url, "locator": locator, "label": label}
def test_fact_misses() -> None:
e = {"id": "F1", "url": "https://x.test/a", "locator": "", "label": "A", "also": []}
assert probe.fact_misses(e, ["https://x.test/a"], []) == []
@@ -144,30 +148,39 @@ def test_fact_misses() -> None:
]
n = {"id": "F3", "url": "", "locator": "", "label": "Comment 1", "also": []}
assert probe.fact_misses(n, [], ["Comment 1"]) == []
a = {**e, "also": ["https://x.test/s", "https://x.test/t"]}
a = {**e, "also": [_also("https://x.test/s"), _also("https://x.test/t")]}
assert probe.fact_misses(a, ["https://x.test/a", "https://x.test/s"], []) == [
"F1: also https://x.test/t not rendered"
"F1: also link https://x.test/t not rendered"
]
def test_fact_misses_book_also_cites() -> None:
# a licensed book also-cite has no url: one more locator span
"""S1-P10: a licensed-book also-cite (no url) is matched by its locator."""
e = {
"id": "F9",
"url": "https://x.test/a",
"locator": "",
"label": "A",
"also": ["", ""],
"also": [
_also(locator="CPT Changes 2023 p. 48"),
_also(locator="CPT 2024 p. 29"),
],
}
assert probe.fact_misses(e, ["https://x.test/a"], ["B 1", "B 2"]) == []
assert probe.fact_misses(e, ["https://x.test/a"], ["B 1"]) == [
"F9: 2 locator spans expected, 1 rendered"
]
b = {"id": "F8", "url": "", "locator": "B 0", "label": "x", "also": [""]}
assert probe.fact_misses(b, [], ["B 0", "B 1"]) == []
assert probe.fact_misses(b, [], ["B 0"]) == [
"F8: 2 locator spans expected, 1 rendered"
links = ["https://x.test/a"]
assert (
probe.fact_misses(e, links, ["CPT Changes 2023 p. 48", "CPT 2024 p. 29"]) == []
)
assert probe.fact_misses(
e, links, ["CPT Changes 2023 p. 48", "CPT 2024 p. 30"]
) == ["F9: also locator 'CPT 2024 p. 29' not rendered"]
# the count alone is not enough: the text must match
assert probe.fact_misses(e, links, ["x", "y"]) == [
"F9: also locator 'CPT Changes 2023 p. 48' not rendered",
"F9: also locator 'CPT 2024 p. 29' not rendered",
]
# no locator: the label stands in, as citeHtml renders it
b = {**e, "also": [_also(label="Comment 9")]}
assert probe.fact_misses(b, links, ["Comment 9"]) == []
def test_facts_line() -> None:

View File

@@ -29,6 +29,13 @@ test("the label stands in when there is neither url nor locator", () => {
ok(citeHtml({ kind: "comment", label: "Comment 9", url: "", locator: "" }).includes(">Comment 9</span>"));
});
test("a cite with no url that is not a book is a plain locator span, no book title", () => {
const h = citeHtml({ kind: "iom", label: "100-04 ch.26", url: "", locator: "IOM 100-04 ch.26" });
eq(h, '<span class="cite book">IOM 100-04 ch.26</span>');
ok(!h.includes("title") && !h.includes("not reproduced"));
ok(citeHtml({ kind: "iom", label: "x", url: "", locator: "L" }, { ref: "F7" }).includes('data-ref="F7"'));
});
test("a licensed book never links, even when a url is set", () => {
const h = citeHtml({ ...H.facts.F2.cite, url: "https://example.test/book" });
ok(!h.includes("href"));
@@ -112,6 +119,12 @@ test("tagged renders a book fact as its locator span", () => {
ok(h.includes("CPT 2019 p. 20"));
});
test("tagged keeps a known tag whose fact has no cite as visible text", () => {
const h = tagged("x [F1] y [F1][F1].", { F1: { id: "F1", kind: "origin", text: "t" } });
eq(h, "x [F1] y [F1][F1].");
eq(tagged("z [F2].", { F2: { id: "F2", cite: null } }), "z [F2].");
});
test("tagged of empty text is empty", () => {
eq(tagged("", facts), "");
eq(tagged(null, facts), "");

View File

@@ -13,7 +13,11 @@
"locator": "MZ24MX5S ¶878",
"note": "",
"also": [
"https://example.test/statute/9999"
{
"url": "https://example.test/statute/9999",
"locator": "Act section 9999",
"label": "Act section 9999"
}
]
},
{

View File

@@ -221,7 +221,13 @@ def test_facts_index_and_detail(d):
idx = {e["id"]: e for e in facts_index(d)["facts"]}
assert len(idx) == 18
assert idx["F2"]["url"] == "" and idx["F2"]["locator"] == "CPT 2019 p. 20"
assert idx["F1"]["also"] == ["https://example.test/statute/9999"]
assert idx["F1"]["also"] == [
{
"url": "https://example.test/statute/9999",
"locator": "Act section 9999",
"label": "Act section 9999",
}
]
assert idx["F2"]["note"] and idx["F4"]["view"] == "valuation"
assert idx["F4"]["label"] == d.facts["F4"].cite.label
assert fact_detail(d, "F4")["view"] == "valuation"
@@ -229,6 +235,19 @@ def test_facts_index_and_detail(d):
assert fact_detail(d, "F8")["accuracy"] == ACC
def test_facts_index_carries_book_also_locators(d):
"""S1-P10: a licensed-book also-cite has no url, so the index carries its
locator for the probe to match exactly."""
book = Cite("cpt_book", "CPT 2024 p. 29", "", "BK", locator="CPT 2024 p. 29")
f1 = replace(d.facts["F1"], also=(*d.facts["F1"].also, book))
idx = {e["id"]: e for e in facts_index(replace(d, facts={"F1": f1}))["facts"]}
assert idx["F1"]["also"][1] == {
"url": "",
"locator": "CPT 2024 p. 29",
"label": "CPT 2024 p. 29",
}
def test_last_rule_is_latest_fr_cite(d):
lr = last_rule(d)
assert lr["label"] == d.facts["F9"].cite.label