Fix #11570: tokenize SVG foreignObject in fact verify

Merged
SU
1mo ago
+121-5

Summary

Fixes #11570. fact verify in the ulw-research fidelity layer skipped everything inside an SVG <foreignObject>: fact elements and unbound numerals there passed with exit 0 and defects: [], while the same text in prose (or an SVG <text> tick) was caught.

Root cause

scripts/html-lite.mjs treated the whole <svg> subtree as raw text, and fidelity-values.mjs SVG handling read only <text> nodes, so nothing inside foreignObject was tokenized.

Changes

  • packages/shared-skills/skills/ulw-research/scripts/html-lite.mjs: an <svg> node now also gains its <foreignObject> subtrees as parsed children (new html-foreign-object.mjs); the rest of the svg stays raw. Tags stay lowercased like any parsed tag, line numbers are shifted to document lines, and each file stays within the skill's 250-line convention.
  • packages/shared-skills/skills/ulw-research/scripts/fidelity-values.mjs: chart labels now include foreignObject HTML as unticked labels, so bare numerals there must trace to a chart CSV plot value. Data-fact value/unit/quote checks inside foreignObject flow through the existing main loop unchanged, so they report the same codes as in prose.
  • Tests: table-driven foreignObject cases in fidelity-values.test.ts (fact unit change, digit change, digit + value attribute, bare numeral sentence, numeral-free control, clean fact at a plot value) plus prose equivalents, and a parser test in html-lite.test.ts (raw preserved, only the foreignObject subtree parsed, line numbers).

Notes on codes

A fact mutation inside a chart figure's foreignObject reports its fact code (unit_mismatch / value_mismatch) plus chart_value_untraceable when the numeral is not a plot value of the chart CSV. That matches existing chart ownership: chart numerals must trace to the CSV, exactly as <text> labels already do. Outside a chart figure, the fact codes match prose exactly.

QA & Evidence

  • RED before the fix (standalone node repro against the fixture ledger): all four issue mutations returned defects: [].
  • GREEN after the fix: unit change -> unit_mismatch; digit change -> value_mismatch; bare numeral -> chart_value_untraceable; numeral-free control and clean fact -> [].
  • Affected-module bun tests (html-lite, fidelity-values, gates-static, gates-fidelity, fidelity-trace): 112 pass, 0 fail.
  • Full skill suite (bun test packages/shared-skills/skills/ulw-research/scripts): 4014 pass, 1 fail. The single failure is environmental, not a regression: the source-integrity test chmods a snapshot file 000 and expects EACCES, but this runner is uid 0 and root reads chmod-000 files (verified standalone). It touches snapshot readability, disjoint from the files changed here.
  • Synced copies: senpi sync + skills-sync test 16 pass; codex sync byte-equality test for ulw-research passes (its suite's single failure is a missing gitignored frontend materialization dir, unrelated); shared-skills package test 3 pass. The three synced copies are byte-identical (verified by diff).
  • No harness QA (opencode/codex/senpi live driving): this change touches no hook, tool, agent, or harness-connected component, only the zero-dependency skill scripts and their bun tests.
  • Local evidence (not committed, gitignored): .omo/evidence/20261101-11570-foreignobject/qa.md, sha256 f7cd05fc64d6f0050dc5cd0d648d0c0d1c60c2ec5cf731888f4d42ba95f01ab3.

Residual risk

  • A <foreignObject> inside a nested <svg> is attached to the outer svg node rather than the inner one; detection is unaffected (it is still in the document walk and the chart-label parse), only the exact parent differs.
  • No changes fragment yet: one will be added as changes/unreleased/<PR#>.md once this PR has its number.

Summary by cubic

Fixes fact verify so it no longer skips text inside SVG <foreignObject>: fact unit/value mutations and bare numerals there previously passed with exit 0 and defects: [], while the same text in prose or an SVG <text> tick was caught.

  • The html-lite.mjs tokenizer now parses <foreignObject> subtrees into real child nodes (new html-foreign-object.mjs); the rest of the SVG stays raw drawing markup, with line numbers shifted to document lines.
  • fidelity-values.mjs counts foreignObject HTML as unticked chart labels, so bare numerals inside a chart must trace to the chart CSV plot value; fact mutations inside a chart report their fact code plus chart_value_untraceable, and outside a chart report the same codes as prose.
  • Adds table-driven foreignObject cases to fidelity-values.test.ts and a parser test to html-lite.test.ts, plus a changes fragment for #12040.