Skip to content

Add review checks for script re-entrancy, reactivity, CSS boundaries, and WPT traps - #6

Merged
zcorpan merged 10 commits into
whatwg:mainfrom
noamr:srcset-review-patterns
Oct 22, 2026
Merged

zcorpan merged 10 commits into
whatwg:mainfrom
noamr:srcset-review-patterns

Conversation

@noamr

@noamr noamr commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Adds generalizable HTML specification & WPT review patterns distilled from multi-round review cycles on whatwg/html#13053 and whatwg/html#12758:

SKILL.md Additions

  • Section 2.4 (Phrasing Conventions): Require <span>continue</span> and <span>break</span> markup in algorithm steps (never bare continue or break).
  • Section 3.7 (Reactivity & Mutation-Hook Parity Audit): Audit trigger completeness, event/flag parity, and a folded bullet for image candidate selection (<picture>/<img>).
  • Section 3.8 (Author Script Re-Entrancy & Mid-Algorithm DOM Mutations): Re-validate DOM invariants after author script can run (and before side-effectful element creation, not just at final insertion).
  • Section 4.5 (Shared Parser Context Audit): Verify changes to shared parser/element algorithms across all 4 parser contexts (normal document parser, fragment parsers, speculative HTML parser, and XML parser).
  • Section 6.4 (CSS Syntax & HTML Microsyntax Boundaries): Require exact CSS Syntax token types (<ident-token>, <whitespace-token>), division-by-zero / degenerate number guards, one or more / zero or more <span>ASCII whitespace</span> cardinality, and grammar vs. parser error-recovery parity.
  • Section 13.5 (Post-Fix 4-Way Synchronization Sweep): Verify normative steps, <p class="note"> / domintro blocks, PR descriptions, and companion WPT PRs stay synchronized after review fixes.
  • Section 14.6 (WPT Antipatterns to Catch): Add rule for non-masking negative tests.
  • Section 15.2 / 15.3 / 16: Document ALGO-LOOP-CONTROL-SPAN, WPT-EARLY-SCRIPT-CLOSE, and WPT-UNGUARDED-TYPEERROR, with concise matching checklist items.

Static Analyzer Additions

  • scripts/check_algorithms.py (ALGO-LOOP-CONTROL-SPAN): Deterministic check flagging bare continue. or break. in <div algorithm> blocks without <span> wrapping (including at the start of wrapped lines).
  • scripts/check_wpt_coverage.py (WPT-EARLY-SCRIPT-CLOSE & WPT-UNGUARDED-TYPEERROR):
    • WPT-EARLY-SCRIPT-CLOSE: Flags literal </script> inside JS comments or string literals in .html WPT files.
    • WPT-UNGUARDED-TYPEERROR: Flags assert_throws_js(TypeError, ...) / promise_rejects_js(..., TypeError, ...) on methods added in a spec diff when the test file lacks an existence guard (assert_implements, typeof, in).

@noamr noamr changed the title Add reactivity, candidate loop ordering, CSS/microsyntax, and WPT review rules to html-spec-review Add review checks for script re-entrancy, reactivity, CSS boundaries, and WPT traps Oct 22, 2026
@noamr
noamr requested a review from zcorpan October 22, 2026 20:10
zcorpan and others added 5 commits October 22, 2026 22:37
Tests often call `el[method](...)` from a list of method names, which the check missed. It now only covers methods added in a spec diff, and requires the guard to name the method.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Also drop a lookbehind that never matched anything.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Blocks that start after `</script><script>` on one line are now checked. To avoid false positives in existing wpt files, skip `<script>` in attribute values, one-line scripts, and `</script` not followed by whitespace, `/` or `>`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the general rule in each bullet and drop the specifics of the case it came from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zcorpan

zcorpan commented Oct 22, 2026

Copy link
Copy Markdown
Member
AI review and fixes

Reviewed at 126bfba

I reviewed the SKILL.md additions and ran the new checks on real inputs. I ran check_algorithms.py on HTML source, and check_wpt_coverage.py with the #12758 diff against web-platform-tests/wpt#61748 before and after the fixes for the issues these checks target. To look for false positives, I also ran it on wpt's html/, dom/, domparsing/, trusted-types/, sanitizer-api/, custom-elements/ and shadow-dom/. I self-reviewed the fixes the same way, plus a few synthetic test files.

Open questions

  • @noamr: I trimmed the srcset specifics from several rules in 354c4e9 (see the first suggestion). Feel free to revert any you think a reviewer needs.

Suggestions

  • SKILL.md 3.8, 6.4, and the masking, presentational hint and DPR bullets in 14: these read like notes from Support 2D sizes and height descriptors in srcset html#13053 rather than general rules (last auto-sizes size, dimension attribute source, cover 1000px var(--h, 1000px), 50w/51w). The skill is already long, and every reviewer loads all of it. Fixed in 354c4e9, which keeps the general rule in each bullet and the matching checklist items.
  • check_wpt_coverage.py (_check_unguarded_typeerror): it missed the cases it was written for. The #12758 tests call el[method](...), and the regex only matched .sink(, so none of the 6 files fixed in web-platform-tests/wpt@544374d were flagged. Instead it flagged 6 other files for .write(, a WritableStream writer method that got in through dom-document-write in the diff. Separately, any typeof anywhere in the file counted as a guard. Fixed in 9d97863: the check now also matches obj[name](...) when the file has the method name as a string and accepts cross-realm TypeError names. It only covers methods that appear only in added lines of a spec diff, and requires the guard to name the method (or use the same computed access). It now flags 4 of the 6 files. The other two build the method name or call it through a helper. It still flags stream-positional.html, where a later assertion fails the subtest anyway; I think that's acceptable for a heuristic.
  • SKILL.md 3.9 item 1: "so dropped subtrees are created in an inert document (e.g., appropriate template contents owner document with a null custom element registry)" presented one fix from #12758 as the general rule. Fixed in ac7a3cd by stopping at "Re-validate before element creation."

Nits

  • check_algorithms.py (loop control regex): the (?<!<span>) lookbehind did nothing, because the preceding group had already matched. The check also missed a keyword at the start of a wrapped line (source:106147-106148). Fixed in 51e3d4c. It now finds 6 bare continue/break in HTML source, with no false positives.
  • check_wpt_coverage.py (_check_early_script_close): it skipped the line containing the <script> start tag, so </script><script> on one line left the following block unchecked. Fixed in 4fc1cd0 by scanning each line left to right. I also suggested flagging a one-line <script>// </script>, but that was wrong: wpt uses it on purpose in shadow-dom/ and trusted-types/. Scanning those lines also turned up false positives (<script> inside srcdoc values, and "</script" + ">", which doesn't end a script). So 4fc1cd0 skips one-line scripts, <script> in attribute values, and </script not followed by whitespace, / or >. It still catches both literal </script> bugs from Un-tentative streamHTML tests web-platform-tests/wpt#61748, and has no hits in the wpt directories above.
  • SKILL.md 15.3: WPT-UNGUARDED-TYPEERROR was described as covering "newly introduced IDL methods", but it flagged any sink found in the spec input except 5 legacy ones. Fixed in 9d97863, which makes the check match the description and says it only runs on a diff.

@zcorpan

zcorpan commented Oct 22, 2026

Copy link
Copy Markdown
Member

Comment by Claude:

@noamr, I think some of the new rules overindex on the two source PRs. Each incident got a body section plus a checklist item, so one-off cases weigh as much as recurring ones. The skill grew from 600 to 668 lines. Several of the #12758 rules come from my findings there, and my trimming in 354c4e9 shortened bullets without asking whether they belong.

  • srcset/picture only: 3.8 (candidate loops), the DPR bullet and checklist item, the presentational-hint bullet, and 3.7 items 2 and 4, which still use object-fit/dimension attribute source as their examples. Few HTML PRs have candidate loops or srcset tests. Maybe fold these into one "image candidate selection" bullet?
  • Streaming parser only: 3.9 items 2–3 (AAA lastNode, a registry cached on an internal root element, SVG script guards), "displaced referenceChild" in the AAA checklist item, and "dead tokens after parser stop/abort". The general rule that opens 3.9 is worth keeping: author script can run mid-algorithm, so re-validate afterwards. The items under it describe one parser design.
  • Lists of past incidents instead of a method: "Preconditions blocked by unrelated spec rules" lists four cases (createElement("link"), parser-inserted scripts, blocking="render", window.parent). Running the tests where the feature isn't implemented, and looking at what passes, catches all of them; review-and-fix already says that. window.on_event?.() and the examples in 4.5 items 2–3 (already started replacement, Noah's Ark token attributes) are single incidents too.
  • Said several times: literal </script> is in 14, the checklist, the analyzer docs, and review-and-fix. The TypeError guard is in 14, the checklist, and the analyzer. Maybe rules the analyzer enforces only need the analyzer entry?

These seem fine as general rules: 13.5, 3.7 items 1 and 3, the four parser contexts in 4.5 item 1, loop control <span>s, and most of 6.4.

Do you want to trim these, or keep them because they're cheap to skim?

@zcorpan

zcorpan commented Oct 22, 2026

Copy link
Copy Markdown
Member
AI review and fixes

Reviewed at c42c53e (new commits d1b1954 and c42c53e)

I reviewed the two new commits against my earlier comments, and checked that the PR description and the analyzer docs still match SKILL.md. The fix only changes SKILL.md, so there was nothing to run.

Open questions

  • @noamr: if you keep c15b4d9, the 14.6 line in the PR description could mention the can't-fail and stall rules too.

Suggestions

  • SKILL.md 14.6 and the WPT checklist: c42c53e removed the "vacuously passing" and "unbounded wait" bullets entirely, so html-spec-review no longer says how to find tests that can't fail or stall. My earlier comment caused this. I meant that the general method should replace the list of incidents, not that the rule should go; review-and-fix isn't loaded for plain reviews. Fixed in c15b4d9 by adding two general bullets to 14.6 (run the tests where the change isn't implemented; time out waits on the behavior under test) and one checklist item.

@zcorpan
zcorpan merged commit 0e46c98 into whatwg:main Oct 22, 2026
@noamr
noamr deleted the srcset-review-patterns branch October 23, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants