Repository navigation
fix(audit): a rule scoped to another document is not judged by this window - #25
Merged
Merged
Conversation
…indow The live audit only ever opens a browser window, but a theme also styles the Library, DevTools and about: pages through @-moz-document. Extraction was blind to that scoping, so every such rule was compared against the browser window's DOM -- which is not evidence about it either way, and which invents renames between unrelated documents. WhiteSur's `#placesToolbar` is the case that found it. That is the Library window's toolbar, `places.xhtml:1154` in the shipped omni.ja and `places.xhtml:164` on ESR 140, so the theme is correct. The live DOM lacks it, and `_is_near_miss` then matched browser.xhtml's `#PlacesToolbar` -- the main window's bookmarks toolbar, a different element one letter of case away -- at which point --patch called the rewrite confident. Applying it would have unstyled the Library. extract_tokens now records the @-moz-document condition each token sits under, and suggest() skips every DOM-derived branch when a use is scoped to a document this audit does not open. The shipped chrome is still consulted: omni.ja carries those documents, so a name Firefox ships resolves to `offscreen` as before. Only when the pack cannot answer either does the new `other-document` confidence apply -- distinct from `unresolved`, which means "looked and found nothing" rather than "not entitled to look". Both are non-actionable, so --strict and --patch ignore them. Two things this had to get right: Findings are grouped per scope, not per token. A token can be written both globally and inside an @-moz-document block, and --patch rewrites the exact file:line sites a finding carries -- so one shared verdict let the confident half drag the unjudgeable half into the patch, the very failure the scope check exists to prevent. Caught in review by the session working #24. The findings sort gained a (file, line) tiebreak, since two findings can now share a token. A condition wrapped across lines is read whole. Evaluated from its first line alone it finds no url() at all, scores as excluding the audited window, and silently hides every finding inside -- worse than the false positive this fixes, since it fails in the direction of silence. All three shapes are pinned: the brace on the prelude's last line, the brace on its own line, and a wrapped multi-condition list. Measured against WhiteSur on Firefox 153: findings 2 -> 1, offscreen 78 -> 79, and the emitted patch no longer contains the bad rename. The remaining finding is real and fixed by that theme's #221. Co-Authored-By: Claude Opus 5 <[email protected]>
adamXbot
force-pushed
the
fix/moz-document-scope
branch
from
August 31, 2026 05:15
0165eda to
58473cf
Compare
An unbalanced brace inside an unquoted url() closes the block early if brace counting runs on anything less neutralised than `cleaned` -- and every rule after it silently goes back to being judged against the browser window, reinstating the false positive this fixes. Balanced braces cancel out, so it takes a deliberately unmatched one to catch. Found by the session working #24, against their own implementation; this one is already correct, and now says so. Also pins mixed condition lists in both directions, since `_scope_covers` handles them by construction rather than by an explicit branch. Co-Authored-By: Claude Opus 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The live audit only ever opens a browser window, but a theme also styles the Library, DevTools and
about:pages through@-moz-document. Extraction was blind to that scoping, so every such rule was compared against the browser window's DOM — which is not evidence about it either way, and which invents renames between unrelated documents.The case that found it
WhiteSur's
#placesToolbaris the Library window's toolbar. The theme is correct:omni.japlaces.xhtml:1154—<toolbar class="chromeclass-toolbar" id="placesToolbar" …>mozilla-esr140places.xhtml:164— same lowercase idbrowser.xhtml:6472id="PlacesToolbar"— a different element, the browser-window bookmarks toolbarThe live DOM lacks the Library's toolbar, so
_is_near_missmatched the capital-P name one letter of case away and--patchcalled the rewrite confident. Applying it would have unstyled the Library window.The change
extract_tokensrecords the@-moz-documentcondition each token sits under.suggest()skips every DOM-derived branch when a use is scoped to a document this audit does not open.The shipped chrome is still consulted —
omni.jacarries those documents — so a name Firefox ships resolves tooffscreenexactly as before. Only when the pack cannot answer either does the newother-documentconfidence apply. It is deliberately distinct fromunresolved: "not entitled to look" is a different claim from "looked and found nothing". Both are non-actionable, so--strictand--patchignore them.Unmodelled conditions (
domain(),regexp()) count as covering the audited window. Being wrong that way reports a finding a human resolves; being wrong the other way hides a real one.Two things this had to get right
Findings are grouped per scope, not per token. A token can be written both globally and inside an
@-moz-documentblock, and--patchrewrites the exactfile:linesites a finding carries — so one shared verdict let the confident half drag the unjudgeable half into the patch, which is the very failure the scope check exists to prevent. Caught in review by the session working #24. The findings sort gained a(file, line)tiebreak, since two findings can now share a token.A condition wrapped across lines is read whole. Evaluated from its first line alone it finds no
url()at all, scores as excluding the audited window, and silently hides every finding inside — worse than the false positive this fixes, because it fails in the direction of silence. All three shapes are pinned: brace on the prelude's last line, brace on its own line, and a wrapped multi-condition list.Measured
Against WhiteSur on Firefox 153, pristine at its master:
247 tests pass (230 existing + 17 new), covering
url/url-prefix/regexpconditions, scope ending with its block, a}inside a string, a nested@medianot closing the block early, three multi-line prelude shapes, one token under two scopes, and the#placesToolbarregression directly.Relationship to #24
Overlaps #24, does not replace it. #24 makes the shipped-chrome pack outrank the fuzzy matchers for any token Firefox ships under its own name; this fixes scope-blindness, including names absent from the pack. Both fix
#placesToolbar, by different routes, which is a useful cross-check on each.#24 should land first. This branch is off
mainand both touchsuggest(), so this one takes the rebase — a one-function conflict.The
--auditupgrade-gate fix is deliberately not here. That gate used an inverted filter (!= "unresolved"), sooffscreen— a name Firefox still ships — counted as a reason to block an upgrade, andother-documentwould have inherited it. #24 now fixes it properly by naming the predicate once inaudit.actionable()and calling it from bothreport()and the CLI, so no future confidence can regress it. That is better than the one-line version I had here, so this PR drops it and depends on #24 for it.