Skip to content

test(ui): lock dark block parity and raw palette immutability (L042) - #19

Merged
constantin-jais merged 3 commits into
migrate/recover-codefrom
work/rewrite-l042
Nov 17, 2026
Merged

constantin-jais merged 3 commits into
migrate/recover-codefrom
work/rewrite-l042

Conversation

@constantin-jais

Copy link
Copy Markdown
Contributor

Door: two-way
Origin: proposal

Summary

Lot L042 of the rewrite plan: Thème sombre explicite généré de la même source (TypeScript sur Bun).

Draft pull request. Base: migrate/recover-code.

File Added Removed
packages/ui/color-system/README.md 9 0
packages/ui/color-system/dark-parity.test.ts 246 0
packages/ui/color-system/dark-parity.ts 279 0

Commits (2, merges excluded):

  • 8bfc571 test(ui): lock dark block parity and raw palette immutability
  • a120c64 fix(ui): refuse nested dark rules and widen the raw palette control

Evidence

The tests and controls below are local runs on the workstation (Bun 1.4.4), recorded in the commit messages; they were not replayed for this pull request. The CI on this head is authoritative.

Review: read by an independent reviewer (read-only, given the code, the base and the source, never the writer report); the defects found were corrected, each with a test shown red on the unfixed code (see the correction commits).

Commit messages, verbatim (sign-off lines omitted):

test(ui): lock dark block parity and raw palette immutability

The generator renders the dark theme twice per layer and color format: under
the explicit data-lai-theme="dark" selector and under prefers-color-scheme
for documents that set no theme. Both come from the same call today, but no
test compared them, and check:colors only detects drift between generated
files and generator output, not a regression of the generator itself.

Add color-system/dark-parity.ts, three pure functions over a generated sheet:
darkBlocks extracts the dark blocks by exact selector, compareDarkBlocks
reports missing, extra, differing or reordered declarations between the
explicit and automatic blocks, and rawPaletteOverrides lists any
--lai-palette-* color redeclared in a dark block. A sheet where an expected
block cannot be found throws a named error instead of reading as parity.

The test applies them to every palette, the convergence and the adopted
sheet, asserts the volume examined, and checks that the five surface roles
resolve to a different color in dark than in light. generate.ts, system.ts,
adopt.ts and the generated files are unchanged.

What makes these tests fail: a declaration added to, removed from, changed
or reordered in only one of the two dark blocks; a raw palette color added
to any dark block; a renamed automatic selector; a dark surface equal to
its light value. Each case is built by substitution in the real generator
output, and dropping one declaration from the automatic block inside
formatThemeBlocks turns the suite red.

Would an equivalent refactor fail them too: the expected selectors, layer
names and layer/format order are the published contract of the sheet,
written out in the test; a refactor that keeps the sheet byte-identical
stays green. Renaming a layer or a theme selector fails by design.

fix(ui): refuse nested dark rules and widen the raw palette control

Review findings on the dark parity controls, each reproduced by a test that
was red on the previous commit:

1. A rule nested inside a dark block (`& { ... }`, or a nested at-rule) was
   parsed as a separate rule and matched no dark selector, so a
   --lai-palette-* color declared there escaped both compareDarkBlocks and
   rawPaletteOverrides. darkBlocks now throws
   color.dark_parity_nested_rule:<layer>/<format>/<kind>, and the two
   controls inherit the error. Covered by "refuses a nesting rule / a nested
   at-rule inside a dark block" (explicit, media and high contrast blocks).
   Neutralization: replacing the throw with a no-op turns 2 tests red.

2. rawPaletteOverrides read only the three exact dark selectors: a raw color
   redeclared under :root in a prefers-color-scheme: dark media query of the
   primitives layer, or under a selector list naming the dark theme, passed.
   It now also reads every rule under a dark media query (any spacing) and
   every rule whose selector or an ancestor's names a dark data-lai-theme
   value, in any layer. Parity extraction keeps exact selectors. Covered by
   four "lists a raw palette color redeclared under ..." cases. Neutralization:
   restricting the wider context back to the exact selectors turns 4 tests
   red.

3. The previous commit also modified packages/ui/color-system/README.md
   without saying so in its message: it added the description of
   dark-parity.ts and dark-parity.test.ts. This commit updates that entry for
   the nested-rule error and the wider raw palette scope.

Departure from the brief, declared: the brief asks for extraction by exact
selector. Parity still does; the raw palette control is stricter than the
brief (wider contexts), and nested rules in a dark block are now an error.
No public name, data format or exit code changes.

Points left to the owner

None named in the commit messages.

Work package

No commit carries a Work-package: or Exempt: trailer. This repository runs no work-package link check; the link to a PRD row, if any, is the owner's to establish.

Blast radius

  • Repository libre-ai/application-development-toolkit only. While draft, nothing moves outside the branch work/rewrite-l042; a merge reaches migrate/recover-code.
  • No workflow file touched.

The generator renders the dark theme twice per layer and color format: under
the explicit data-lai-theme="dark" selector and under prefers-color-scheme
for documents that set no theme. Both come from the same call today, but no
test compared them, and check:colors only detects drift between generated
files and generator output, not a regression of the generator itself.

Add color-system/dark-parity.ts, three pure functions over a generated sheet:
darkBlocks extracts the dark blocks by exact selector, compareDarkBlocks
reports missing, extra, differing or reordered declarations between the
explicit and automatic blocks, and rawPaletteOverrides lists any
--lai-palette-* color redeclared in a dark block. A sheet where an expected
block cannot be found throws a named error instead of reading as parity.

The test applies them to every palette, the convergence and the adopted
sheet, asserts the volume examined, and checks that the five surface roles
resolve to a different color in dark than in light. generate.ts, system.ts,
adopt.ts and the generated files are unchanged.

What makes these tests fail: a declaration added to, removed from, changed
or reordered in only one of the two dark blocks; a raw palette color added
to any dark block; a renamed automatic selector; a dark surface equal to
its light value. Each case is built by substitution in the real generator
output, and dropping one declaration from the automatic block inside
formatThemeBlocks turns the suite red.

Would an equivalent refactor fail them too: the expected selectors, layer
names and layer/format order are the published contract of the sheet,
written out in the test; a refactor that keeps the sheet byte-identical
stays green. Renaming a layer or a theme selector fails by design.

Signed-off-by: Constantin Jais <74049135+constantin-jais@users.noreply.github.com>
Review findings on the dark parity controls, each reproduced by a test that
was red on the previous commit:

1. A rule nested inside a dark block (`& { ... }`, or a nested at-rule) was
   parsed as a separate rule and matched no dark selector, so a
   --lai-palette-* color declared there escaped both compareDarkBlocks and
   rawPaletteOverrides. darkBlocks now throws
   color.dark_parity_nested_rule:<layer>/<format>/<kind>, and the two
   controls inherit the error. Covered by "refuses a nesting rule / a nested
   at-rule inside a dark block" (explicit, media and high contrast blocks).
   Neutralization: replacing the throw with a no-op turns 2 tests red.

2. rawPaletteOverrides read only the three exact dark selectors: a raw color
   redeclared under :root in a prefers-color-scheme: dark media query of the
   primitives layer, or under a selector list naming the dark theme, passed.
   It now also reads every rule under a dark media query (any spacing) and
   every rule whose selector or an ancestor's names a dark data-lai-theme
   value, in any layer. Parity extraction keeps exact selectors. Covered by
   four "lists a raw palette color redeclared under ..." cases. Neutralization:
   restricting the wider context back to the exact selectors turns 4 tests
   red.

3. The previous commit also modified packages/ui/color-system/README.md
   without saying so in its message: it added the description of
   dark-parity.ts and dark-parity.test.ts. This commit updates that entry for
   the nested-rule error and the wider raw palette scope.

Departure from the brief, declared: the brief asks for extraction by exact
selector. Parity still does; the raw palette control is stricter than the
brief (wider contexts), and nested rules in a dark block are now an error.
No public name, data format or exit code changes.

Signed-off-by: Constantin Jais <74049135+constantin-jais@users.noreply.github.com>
@constantin-jais
constantin-jais marked this pull request as ready for review November 17, 2026 20:54
@constantin-jais
constantin-jais merged commit 6446aca into migrate/recover-code Nov 17, 2026
1 check passed
@constantin-jais
constantin-jais deleted the work/rewrite-l042 branch November 17, 2026 21:26
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