Skip to content

test: cover the CSS Module class-name resolution contract (tests/css-modules.test.mjs) - #371

Merged
mrbobbytables merged 1 commit into
mainfrom
quality/test-css-modules
Sep 21, 2026
Merged

mrbobbytables merged 1 commit into
mainfrom
quality/test-css-modules

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

Adds tests/css-modules.test.mjs, covering the CSS Module class-name
resolution contract
across the JS/CSS boundary in src/.

A CSS Module exports only the class names its stylesheet declares, so
styles.notDeclared is plain undefined property access: React renders the
element with no class attribute, docusaurus build stays green, and the
element silently loses its styling. src/ has 9 stylesheet importers and ~129
class references behind that invariant, and no existing test reads a
*.module.csstests/validate-button-contrast.test.mjs reads only the
global src/css/custom.css.

Six assertions, in both directions:

  • every import x from '*.module.css' specifier resolves to a stylesheet on disk
  • every referenced class (styles.foo, styles['foo']) is declared by its stylesheet
  • every declared class has a reader (skipped per-stylesheet when a file uses a computed styles[key] lookup, where the referenced set is not statically knowable)
  • every composes: target resolves to a declared class
  • plus two guards asserting each exemption below still describes live drift

Implementation notes: class names are read from selector preludes only, so
url(./x.png) in a declaration is not mistaken for a class, and the minified
}.note,.source { form this repo actually ships in
MetricsDashboard/styles.module.css is parsed correctly. Import statements are
stripped before the reference scan, since the specifier './styles.module.css'
otherwise reads as a styles.module reference.

Verification. npm run test:unit is green at 61 tests (55 existing + 6
new); npx prettier --check tests/css-modules.test.mjs is clean. The
assertions were mutation-tested rather than assumed: injecting an undeclared
styles.bogusMissing reference and an orphan .bogusOrphan rule fails the
forward and reverse assertions with a precise message, and declaring
.iconLink fails the staleness guard with "remove it from KNOWN_UNDECLARED".

Related Issue

Refs #319partial by lane constraint, not by choice. #319 asks for two
things, and this PR lands only the second box:

  • Remove the two dead references in src/theme/Footer/still open.
    This is a production-code change (src/theme/Footer/index.js and its
    styles.module.css), which the quality lane may not PR. It needs a human
    or a production-lane agent.
  • Add the contract test — this PR.

Because the production half cannot land here, the two live drifts #319
documents are pinned in explicit exemption lists instead of being fixed:

  • KNOWN_UNDECLARED: src/theme/Footer/styles.module.css#iconLink
  • KNOWN_ORPHANS: src/theme/Footer/styles.module.css#orgText

Both are confirmed present on main at 00b44df. This keeps the contract
enforced for all 9 importers and stops the drift spreading, while leaving the
6-line deletion to the first box. The exemptions are not permanent
carve-outs: the two staleness guards fail the moment either drift is fixed,
demanding the entry's removal, so landing box 1 tightens this test rather than
leaving a stale exemption behind. #319 stays open until then.

Disjointness: this PR touches only the new tests/css-modules.test.mjs. #347
(tests/css-variables.test.mjs) covers var(--x) custom-property resolution —
different names, different namespace; #343 covers JSX link/image hygiene; #317
covers custom.cssstatic/fonts/, a global stylesheet not scanned here;
#229 covers filterArchitectures; #268 covers useFocusTrap. No open PR reads
CSS Module class names or touches src/theme/Footer/**.


Filed by quality agent (hold-gated mode). Human review required.

— hive: agent=quality backend=copilot model=claude-opus-5

A CSS Module exports only the class names its stylesheet declares, so
`styles.notDeclared` is plain `undefined` property access: React renders the
element with no `class` attribute, `docusaurus build` stays green, and the
element silently loses its styling. src/ has 9 stylesheet importers and ~129
class references behind that unguarded invariant; no existing test reads a
*.module.css.

tests/css-modules.test.mjs resolves class names across the JS/CSS boundary in
both directions: every referenced class must be declared, every declared class
must have a reader, every import specifier must resolve, and every `composes`
target must exist. The two live drifts in src/theme/Footer/ (the undeclared
`.iconLink` reference and the orphan `.orgText` rule) are pinned in explicit
exemption lists so they cannot spread, and two further tests assert each
exemption still describes real drift, so fixing the source makes this test
demand the carve-out's removal instead of leaving it to rot.

Signed-off-by: kubestellar-hive[bot] <kubestellar-hive@hive.kubestellar.io>
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Important

Held for human review by the hive's ACMM level gate.

This PR was opened by the "quality" agent while Hive policy required a human checkpoint for that agent. Non-outreach agents are held at ACMM L3–L5; the outreach agent is always held because it publishes project-facing communication.

Hive will automatically remove the hold label once current policy no longer requires a level hold for "quality". If this is an outreach PR, a human must review it and remove the label.

@hivecommons-hive hivecommons-hive Bot added quality Approved by a Hive merger/owner for auto-merge on green CI testing Approved by a Hive merger/owner for auto-merge on green CI agent/quality Approved by a Hive merger/owner for auto-merge on green CI hive/hosted-available-lke648397-260827-5n31 Approved by a Hive merger/owner for auto-merge on green CI labels Sep 21, 2026
@mrbobbytables
mrbobbytables added this pull request to the merge queue Sep 21, 2026
Merged via the queue into main with commit ab4ce2c Sep 21, 2026
2 checks passed
@castrojo
castrojo deleted the quality/test-css-modules branch September 21, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/quality Approved by a Hive merger/owner for auto-merge on green CI hive/hosted-available-lke648397-260827-5n31 Approved by a Hive merger/owner for auto-merge on green CI hold quality Approved by a Hive merger/owner for auto-merge on green CI testing Approved by a Hive merger/owner for auto-merge on green CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant