Skip to content

audit(ui): CSS class drift audit script (#2502)#2507

Merged
alexey-pelykh merged 1 commit intomainfrom
audit/2502-css-class-drift
Apr 23, 2026
Merged

audit(ui): CSS class drift audit script (#2502)#2507
alexey-pelykh merged 1 commit intomainfrom
audit/2502-css-class-drift

Conversation

@alexey-pelykh
Copy link
Copy Markdown

Summary

Adds scripts/audit-css-class-drift.mjs — a one-shot triage helper that surfaces fork-side class="..." tokens in ui/src/**/*.{ts,tsx} that have no matching rule anywhere in the ui/src/styles.css import graph.

Addresses #2502. The #2501 fix (nav-section + topbar vocabulary after v2026.3.13-1 sync) was the first visible symptom; this audit generalizes the detection so future drift surfaces in one pass instead of reactively, component by component, as users notice broken styling.

What this PR does

Current state on this branch

Running the script against origin/main:

  • 36 orphans across 3 drift clusters:
    1. 0667aa5596 (v2026.3.22 sync) — 21 orphans — full .config-sidebar* / .config-search__tag-* / .config-nav* / .config-subnav* family gone; upstream moved to .config-top-tabs
    2. 04a7853f0f (v2026.3.13-1 sync) — 5 orphans — residue after fix(ui): restore nav-section/topbar class names after v2026.3.13-1 sync — paired call-site update missed #2501: .nav (→ .sidebar), .nav--collapsed (→ .sidebar--collapsed), .theme-toggle* (→ .theme-orb*)
    3. 21ac4b9a8a (style(ui) clarity pass) — 1 orphan.btn-sm (→ .btn--sm)
  • 9 unresolved — no removing-commit found in CSS history. Mix of genuinely-never-defined BEM sub-elements (.cron-run-entry__main, .cron-run-entry__title, .nav-item--external, .nav-section--links), fork-side classes with no rule (.nostr-profile-form, .form-field, .monospace, .debug-event-log), and one dynamic-construction scope-out (.language- prefix from class="language-${lang}").

Design decisions

  • Reference extraction walks Lit template strings with brace+string awareness so class="btn ${cond ? \"active\" : \"\"}" doesn't confuse the parser with the inner quote (naive class="[^"]*" regex breaks here).
  • Interpolation content is scope-out per audit(ui): one-shot CSS class drift audit — surface fork-side references with no CSS definition #2502. Static tokens AROUND ${...} ARE captured; content INSIDE is not. This avoids the false-positive flood from string literals used as enum discriminants, i18n keys, or comparison values.
  • CSS selector extraction handles compound selectors (.btn.primary → both btn and primary), BEM, pseudo-classes, :not(...), and nested @media blocks.
  • Cluster attribution uses git log -S .className with a selector-boundary filter on per-commit diffs so .nav isn't conflated with .nav-section on substring pickaxe hits.

Known limitations

Documented in-script and in the report. The big ones:

  • Dynamic class composition (${variable}, classList.add(...), classMap(...)) is out of scope.
  • Cluster SHA attribution is a hint, not a guarantee — bulk search-replace renames may cluster to the rename commit rather than an earlier definition.
  • Vendored UI outside the ui/src/styles.css import graph is not analyzed.

Test plan

  • node scripts/audit-css-class-drift.mjs runs to completion, writes .tmp/audit-css-drift.md, exits 1 with 36 orphans
  • Exit code contract verified (1 on findings; logic would exit 0 if 0 orphans; 2 on import-graph resolution failure)
  • Output file is under .tmp/ (gitignored) — not accidentally committed
  • pnpm format, pnpm lint, pnpm tsgo all clean
  • Manually verified 3 cluster attributions against git show <sha> diffs
  • Manually verified compound-selector handling (.btn.primary yields both btn and primary)
  • Manually verified quote-in-interpolation parser handles class="btn ${cond ? \"active\" : \"\"}" correctly

Follow-ups

…nces with no CSS definition (#2502)

Scans ui/src TS/TSX for static class="..." tokens (and literal-only
class=\${"..."} / class=\${\`template\`} forms) and diffs against the set
of classes defined in CSS reachable from ui/src/styles.css via @import.
Orphaned references are clustered by the commit that removed the
defining rule, making fork-sync drift visible in one pass.

The script is a one-shot triage helper, not a CI gate (see #2503 for the
build-time gate that depends on this audit clearing). Runs CI-friendly:
no prompts, exit 0 when clean, exit 1 on findings, exit 2 on fatal.

Output: .tmp/audit-css-drift.md (gitignored via .tmp/).

Current state on audit/2502-css-class-drift @ origin/main: 36 orphans
across 3 drift clusters (v2026.3.22 config-sidebar family, v2026.3.13-1
nav+theme-toggle residue after #2501, btn-sm rename) plus 9 unresolved
(no removing-commit in CSS history — missing-CSS candidates, not drift).

Follow-up fix(ui) issues filed per cluster.

Design notes:
- Reference extraction walks Lit template strings with brace/string
  awareness so class="btn \${cond ? \"active\" : \"\"}" doesn't confuse the
  parser with the inner quote.
- Interpolation content is scope-out per #2502 — static tokens AROUND
  interpolations ARE captured, content INSIDE is not (avoids FP flood
  from enum-discriminant and i18n-key string literals).
- CSS selector extraction handles compound selectors (.btn.primary),
  BEM (.block__elem--mod), pseudo-class suffixes, and nested @media
  blocks. Allows a preceding word character before the dot so .btn.primary
  yields both classes.
- Cluster attribution uses git log -S .className pickaxe, then filters
  per-commit diffs with a selector-boundary regex so .nav isn't conflated
  with .nav-section on substring matches.
@alexey-pelykh alexey-pelykh enabled auto-merge (squash) April 23, 2026 21:41
@alexey-pelykh alexey-pelykh merged commit cfbfbe2 into main Apr 23, 2026
15 checks passed
@alexey-pelykh alexey-pelykh deleted the audit/2502-css-class-drift branch April 23, 2026 21:47
alexey-pelykh added a commit that referenced this pull request Apr 23, 2026
… 3 of #2502 CSS class drift audit (#2510)

Upstream `21ac4b9a8a` (style(ui) clarity pass, openclaw#53272) migrated `.btn-sm`
to `.btn--sm` under the BEM modifier convention. The fork's
`ui/src/ui/views/channels.nostr.ts:131` still referenced the pre-rename
`btn-sm` token; the CSS rule `.btn--sm` is defined at
`ui/src/styles/components.css:625`. The stale reference was surfaced as
cluster 3 (1 orphan) by the CSS class drift audit introduced in #2507.

Post-fix audit: orphans 36 → 35, clusters 3 → 2, cluster 3 eliminated
entirely.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
alexey-pelykh added a commit that referenced this pull request Apr 23, 2026
… 3 of #2502 CSS class drift audit (#2510) (#2512)

Upstream `21ac4b9a8a` (style(ui) clarity pass, openclaw#53272) migrated `.btn-sm`
to `.btn--sm` under the BEM modifier convention. The fork's
`ui/src/ui/views/channels.nostr.ts:131` still referenced the pre-rename
`btn-sm` token; the CSS rule `.btn--sm` is defined at
`ui/src/styles/components.css:625`. The stale reference was surfaced as
cluster 3 (1 orphan) by the CSS class drift audit introduced in #2507.

Post-fix audit: orphans 36 → 35, clusters 3 → 2, cluster 3 eliminated
entirely.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant