Skip to content

Make the shared Button consume the hover tokens (closes #2689) - #2710

Merged
malibio merged 3 commits into
mainfrom
issue-2689-button-hover-tokens
Sep 17, 2026
Merged

malibio merged 3 commits into
mainfrom
issue-2689-button-hover-tokens

Conversation

@malibio

@malibio malibio commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Closes #2689.

The --*-hover tokens added in #2673 were correct in app.css. The shared shadcn Button simply never used them — it hovered to bg-destructive/90, an alpha fill composited against the page. Every filled variant lost contrast on hover, and dark-mode destructive landed at 3.39:1, below AA, on the "Remove database" control.

Measured against each variant's own foreground:

Variant Theme Rest Hover (before) Hover (after)
default light 3.51:1 3.05:1 4.86:1
default dark 4.47:1 3.81:1 5.79:1
destructive light 5.36:1 4.76:1 6.66:1
destructive dark 5.97 → 6.95:1 3.39:1 8.45:1

Every hover now clears AA and rises above its rest state.

dark:bg-destructive/60 — dropped, and why it wasn't a free choice

The issue asked whether the muted dark treatment was deliberate. It turns out to be a symptom of text-white, not a design decision, and the two had to be resolved together:

  • Against the solid dark --destructive fill, text-white is 2.86:1.
  • The /60 translucency lightened that fill toward the page, which was the only thing keeping white legible there.

So removing /60 alone would have made it worse, and keeping it under an opaque hover would have been incoherent. Both go. The variant is solid in both themes and labels with --destructive-foreground, taking dark rest from 2.86:1 to 6.95:1.

Light mode is visually unchanged — light --destructive-foreground is 0 0% 100%, identical to the text-white it replaces. Only dark mode moves, which is where the defect was.

Tailwind registration

Both tokens are registered without an <alpha-value> placeholder, deliberately, so hover:bg-destructive-hover/90 does not resolve. A hover fill is opaque by definition; admitting an alpha channel would reopen the very idiom this removes.

Only --primary-hover / --destructive-hover are registered. --success / --warning have no Tailwind color entry at all today and no utility usage, so registering just their hovers would have been incoherent.

The test, and why a second suite

filled-button-hover.test.ts passed throughout the entire period this bug was live. It proves the token values obey the rule — necessary, but not sufficient. The gap between correct tokens and a component that ignores them is exactly how this shipped.

filled-button-variants.test.ts (14 tests) covers the other half: each filled variant names its hover token, no alpha hover survives on a filled variant, no translucent rest fill remains, and the config entry carries no alpha channel.

Verified by mutation rather than assumed:

Mutation Result
Variants reverted to the original stock strings 5 tests fail
<alpha-value> re-added to the config entry 2 tests fail
dark --destructive-hover 76% → 64% — wrong direction, still 7.3:1 1 test fails

The third is the case an AA floor alone would miss, and is why the load-bearing assertion compares hover contrast to rest contrast rather than to a constant.

Also compiled the real emitted class strings through PostCSS to confirm they resolve to opaque hsl(var(--*-hover)) rules and that zero alpha hover rules remain — a class-name assertion alone cannot prove the build emits anything.

Deliberately not addressed

A rest-state AA floor. --primary is 3.51:1 light / 4.47:1 dark against its own foreground at rest — both under AA, both pre-existing properties of the brand color, and unreachable by any hover change. My first draft asserted a rest floor and failed on exactly this; asserting it would make the suite fail on a defect it does not own. Worth its own issue if the brand color is up for revision.

Filed separately

Verification

  • bun run test — 250 files / 5148 tests passed (baseline 249 / 5134)
  • bun run quality:fix — clean; design-token baseline unchanged at 137; svelte-check 2540 files, 0 errors, 0 warnings
  • Pre-push gate — full pyramid green, twice (once before the rebase onto current main, once after)
  • All 18 consumers audited: none overrides the button background or label color; the only external buttonVariants users are the calendar prev/next buttons on the untouched outline variant
  • app.css untouched — scope is the component and its Tailwind registration

DESIGN.md updated separately in nodespace-docs (2c63616) to document the Tailwind consumption path and the text-white prohibition — the gap that let a component drift while the tokens stayed correct.

🤖 Generated with Claude Code

The `--*-hover` tokens were correct in app.css; the shared shadcn Button
simply never used them. It hovered to `bg-destructive/90`, an alpha fill
composited against the page, which put dark-mode destructive hover at
3.39:1 — below AA, on the "Remove database" control, at the moment of a
destructive commitment. All four filled-variant hovers LOST contrast.

Measured against each variant's own foreground, before -> after:

  default     light  3.51 -> 3.05  =>  3.51 -> 4.86
  default     dark   4.47 -> 3.81  =>  4.47 -> 5.79
  destructive light  5.36 -> 4.76  =>  5.36 -> 6.66
  destructive dark   5.97 -> 3.39  =>  6.95 -> 8.45

Every hover now clears AA and rises above its rest state.

Two stock shadcn treatments are dropped from `destructive` rather than
carried forward, because they only worked together with the alpha hover:

- `dark:bg-destructive/60` made the dark REST state translucent. Its real
  effect was to lighten the fill toward the page, which was the only thing
  propping up the `text-white` beside it. Keeping a translucent rest under
  an opaque hover would also be incoherent.
- `text-white` bypassed `--destructive-foreground`, which carries real
  per-theme values precisely because white fails on dark fills: against the
  solid dark `--destructive` it is 2.86:1. Using the token takes dark
  destructive rest from 2.86:1 to 6.95:1.

Light mode is visually unchanged — light `--destructive-foreground` is
`0 0% 100%`, identical to the `text-white` it replaces. Only dark mode
moves, which is where the defect was.

The tokens are registered in tailwind.config.js deliberately WITHOUT an
`<alpha-value>` placeholder, so `hover:bg-destructive-hover/90` does not
resolve. A hover fill is opaque by definition, and admitting an alpha
channel would reopen the idiom this removes.

`filled-button-variants.test.ts` (14 tests) covers the half the existing
`filled-button-hover.test.ts` cannot: that suite proves the token VALUES
obey the rule, and passed throughout the entire period this bug was live.
The gap between correct tokens and a component that ignores them is how
this shipped, so the new suite asserts consumption — each filled variant
names its hover token, no alpha hover survives on a filled variant, no
translucent rest fill remains, and the config entry has no alpha channel.

Verified the guard bites rather than passing vacuously, by mutation:

  1. variants reverted to the original stock strings  -> 5 tests fail
  2. `<alpha-value>` re-added to the config entry     -> 2 tests fail
  3. dark --destructive-hover 76% -> 64%, wrong        -> 1 test fails
     direction but still 7.3:1, comfortably above AA

Mutation 3 is the one the AA floor alone would miss, and is the reason the
load-bearing assertion compares hover contrast to REST contrast rather than
to a constant.

Also confirmed by compiling the real emitted class strings through PostCSS:
`hover:bg-primary-hover` and `hover:bg-destructive-hover` resolve to opaque
`hsl(var(--*-hover))` rules, and zero alpha hover rules remain.

Deliberately NOT asserted: a rest-state AA floor. `--primary` is 3.51:1
light / 4.47:1 dark against its own foreground at rest, both pre-existing
properties of the brand color that no hover change can reach. Adding that
floor would make this suite fail on a defect it does not own.

app.css is untouched. Scope is the component and its Tailwind registration.

Verification:
- bun run test: 250 files / 5148 tests passed (baseline 249 / 5134)
- bun run quality:fix: clean; design-token baseline unchanged at 137;
  svelte-check 2540 files, 0 errors, 0 warnings
- Consumers: all 18 audited. No consumer overrides the button background or
  label color; the only external buttonVariants users are the calendar
  prev/next buttons on the untouched `outline` variant.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@malibio

malibio commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #2710

Review Type: Initial Review (no prior reviews on this PR)
Scope: 3 files, +205/−3 — button/types.ts, tailwind.config.js, new filled-button-variants.test.ts


Summary

This is a well-scoped, genuinely net-positive fix that resolves a real WCAG AA failure on a destructive control. I independently recomputed every contrast ratio from the raw token values in app.css (WCAG relative luminance, with alpha compositing against each theme's --background) rather than trusting the PR description. Every single number reproduces exactly, including the alpha-composited "before" values:

Variant Theme Rest (before → after) Hover (before → after)
default light 3.51 → 3.51 3.05 → 4.86 ✅
default dark 4.47 → 4.47 3.81 → 5.79 ✅
destructive light 5.36 → 5.36 4.76 → 6.66 ✅
destructive dark 5.97 → 6.95 3.39 → 8.45 ✅

The coupled-defect argument for dropping dark:bg-destructive/60 + text-white holds up under scrutiny. I verified the load-bearing claim: the solid dark --destructive fill (0 100% 70%) against pure white is 2.86:1 — confirming /60 was propping up text-white rather than expressing a design intent. Removing /60 alone would indeed have made things worse. I also confirmed light mode is visually unchanged: light --destructive-foreground is 0 0% 100%, byte-identical to the text-white it replaces. Only dark mode moves, which is exactly where the defect was.

I also verified the deferral decision (finding 7): --primary at 3.51:1 light / 4.47:1 dark against its own foreground at rest is confirmed, and it is a property of the brand color unreachable by any hover change. Deferring is the right call — fixing it means changing the brand color, which is a design decision, not a code review outcome, and folding it in would destroy this PR's atomicity.

Secondary's exemption (finding 6) also checks out: 16.10:1 light / 14.22:1 dark at rest, rising to 16.40 / 14.84 on hover. It gains contrast. The reasoning is sound.

The test was verified by mutation rather than assumed — I ran the mutations myself rather than trusting the author's table, and mutations 1 and 2 reproduce exactly (5 failures and 2 failures respectively). This is emphatically not a vacuous suite; readHsl throws on a miss, and the sibling suite's hard-won comment explains why.

Two findings below. Neither is a correctness bug in the shipped behavior — the fix works — but one documents an enforcement guarantee that does not actually exist, which matters because it is now written into DESIGN.md as a rule future contributors will rely on.


Requirements Check — Issue #2689 Acceptance Criteria

# Criterion Status
1 --primary-hover / --destructive-hover registered in tailwind.config.js ✅ Met — verified they compile to real utilities
2 Variants use hover tokens; zero /90 alpha hovers in buttonVariants ✅ Met — verified by mutation
3 A decision recorded on dark:bg-destructive/60 ✅ Met — dropped, with the 2.86:1 evidence recorded in the component comment and DESIGN.md
4 destructive uses --destructive-foreground rather than text-white ✅ Met
5 Every hover ≥ AA and ≥ its rest contrast, both themes ✅ Met — independently recomputed; all 4 combinations pass
6 Spot-check the ~18 consumers ✅ Met — I re-audited: the only external buttonVariants users are calendar-prev-button.svelte:22 / calendar-next-button.svelte:22, both on the untouched outline variant. grep for text-white across all .svelte files returns zero hits

All 6 criteria met.

Verified 📁 packages/desktop-app/src/lib/components/settings/sections/database-settings.svelte:226 — <Button variant="destructive" onclick={confirmRemove}>Remove</Button> passes no class prop and overrides nothing. It inherits the fix cleanly. This is the control the issue was filed about.


Code Review Findings

🟡 Important

📁 packages/desktop-app/tailwind.config.js:21-25 — the <alpha-value> omission does not enforce what the comment claims it enforces.

The comment states that omitting <alpha-value> means "admitting an alpha channel here would re-enable the hover:bg-primary/90 idiom", and the PR description states outright that hover:bg-destructive-hover/90 "does not resolve." I compiled the actual classes through PostCSS with the repo's real config (Tailwind 3.4.19):

.hover\:bg-destructive-hover\/90:hover {
    background-color: hsl(var(--destructive-hover) / 0.9)
}
.bg-primary-hover\/50 {
    background-color: hsl(var(--primary-hover) / 0.5)
}

Both resolve. Tailwind v3 parses hsl(var(--x)) as a color function it can inject an alpha into, so the slash modifier works whether or not <alpha-value> is present. Omitting the placeholder is a no-op for enforcement.

The good news, and the reason this is 🟡 and not 🔴: the actual fix is unaffected. I confirmed the two classes the component really uses emit exactly the intended opaque rules:

.hover\:bg-primary-hover:hover      { background-color: hsl(var(--primary-hover)) }
.hover\:bg-destructive-hover:hover  { background-color: hsl(var(--destructive-hover)) }

So this is a documentation/rationale defect, not a behavioral one. It matters because the claim has been written into DESIGN.md:300 in nodespace-docs as a standing rule ("so hover:bg-destructive-hover/90 does not resolve"), where a future contributor will rely on a guarantee the build does not provide. The registers ... with no alpha channel test then reads as enforcing that guarantee when it only pins a config string.

Principle: a comment that asserts a guarantee the system doesn't provide is worse than no comment — it stops the next person from adding the check that would.

Suggested fix — keep the config exactly as-is (it is still the correct, honest declaration of intent), and correct the three claims:

  1. Reword the config comment to state the intent without the false mechanism, e.g. "No <alpha-value>: a --*-hover is the opaque fill of a hovered filled button. Note this is a declaration of intent, not an enforcement mechanism — Tailwind still resolves /90 on it; the guard against alpha hovers is the has no alpha-fill hover left on a filled variant test."
  2. Correct DESIGN.md:300 in the same way.
  3. Optionally rename the test to something like registers --primary-hover as an opaque fill so it doesn't imply an alpha channel is impossible.

Note the existing test has no alpha-fill hover left on a filled variant is the real enforcement, and it works — it caught hover:bg-primary/90 in my mutation run. The rule is genuinely guarded; only the stated mechanism is wrong.


📁 packages/desktop-app/src/tests/design/filled-button-variants.test.ts:139 — expect(classes).not.toContain('text-white') is unreachable and cannot fail.

You flagged this one to scrutinize, and it is a real (if benign) issue — with a more interesting cause than plain array-vs-substring semantics.

classes is an array, so not.toContain tests exact element membership, not substring. That part is fine and is arguably the right semantic. The problem is that the assertion can never fire, for two compounding reasons:

  1. tw-merge makes the two mutually exclusive. buttonVariants is tv(), which runs tailwind-merge over the result. text-white and text-destructive-foreground are the same utility group, so only the last one survives. They can never both be present in classes.
  2. The positive assertion on the line above always fires first. Since exactly one text color survives, if text-white is present then text-destructive-foreground is absent, and expect(classes).toContain('text-destructive-foreground') throws before line 139 is reached.

I verified this empirically. Writing 'bg-destructive text-destructive-foreground ... text-white' — both classes present in the source — produced:

× labels with text-destructive-foreground rather than a hardcoded color
  → expected [ …(29) ] to include 'text-destructive-foreground'

tw-merge dropped text-destructive-foreground entirely, and the failure came from the positive assertion. Line 139 never evaluated. A pure text-white regression is likewise caught by line 138, never 139.

The regression is genuinely caught — which is why this is 🟡 and not 🔴. Nothing is unguarded. But line 139 is dead weight that reads as a second, independent safety net when it is unreachable, and a future reader may add a text-* literal elsewhere believing this line covers it.

Two reasonable resolutions:

  • Simplest (recommended): delete line 139. Line 138 fully subsumes it, and a one-line comment noting that tw-merge makes the positive assertion sufficient would capture the insight.
  • If you want an explicit literal-color guard with teeth, assert against the raw variant source string rather than the merged output, so tw-merge can't mask it — e.g. check that no text-<literal> (white, black, a hex) appears in the destructive variant definition. That would also extend the guard to variants this suite doesn't otherwise cover.

🟢 Suggestions

📁 packages/desktop-app/src/tests/design/filled-button-variants.test.ts:33-90 — the WCAG helpers are duplicated verbatim from the sibling suite.

hslToRgb, luminance, contrast, themeBlock and readHsl are copy-pasted byte-for-byte from filled-button-hover.test.ts. You asked me to weigh this pragmatically against codebase precedent, and precedent does exist: src/tests/helpers/test-helpers.ts and src/tests/utils/test-node-helpers.ts are both shared test-helper modules.

That said, I'd land on extract, but not as a merge blocker. The arguments each way:

For leaving it: two call sites is the classic DRY threshold, not past it. The helpers are pure, stable, and have no reason to drift in behavior. Test-local duplication is often defensible because it keeps a suite readable standalone.

For extracting: these aren't trivial one-liners — this is ~55 lines of subtle, spec-derived math (the WCAG 0.03928 cutoff, the 2.4 gamma exponent, the (?![\w-]) lookahead that stops --primary matching --primary-hover). A transcription error in one copy but not the other would produce two suites that disagree about arithmetic, and the one that silently relaxes is the one you'd never notice. Something has already been lost in the copy: the sibling's readHsl carries a substantial comment recording that an earlier draft returned null and "turned a typo in this regex into 16 vacuous passes." The new copy dropped that comment, so the hardest-won lesson in this code now lives in only one of the two places that implement it.

Suggested: extract to src/tests/design/wcag-contrast.ts (or src/tests/helpers/), carrying the full comments over. This is worth doing as follow-up cleanup — and would pay for itself the moment a third contrast suite appears, which given the trajectory of #2673 → #2689 → #2704 seems likely.

Principle: DRY applies with more force to knowledge that is hard to re-derive than to code that is merely repeated.

Nit: 📁 packages/desktop-app/src/lib/components/ui/button/types.ts:2-22 — comment length. A 21-line header on a types file is long, but I'd keep it. Every paragraph records a non-obvious why (the theme-flip mechanism, the 2.86:1 coupling) rather than restating mechanics, and this is precisely the drift that let the original defect ship. This is the good kind of comment.


Standards Compliance

Verified against CLAUDE.md:

  • ✅ No lint suppression (eslint-disable, @ts-ignore, @ts-expect-error) in any changed file
  • ✅ No any types — the two as Record<string, Record<string, string>> casts are concrete
  • ✅ No raw console.*
  • ✅ No GitHub issue numbers embedded in code comments (grep for #\d{3,} returns nothing) — issue references correctly confined to the commit message and PR body
  • ✅ Docs correctly live in nodespace-docs (DESIGN.md, commit 2c63616), not in this repo
  • ✅ Test suite passes: 14/14 on the new file; working tree clean after my mutation experiments (all reverted via git checkout)

Recommendation

✅ APPROVE

This fixes a real accessibility defect on a destructive control, and every quantitative claim in the PR description survived independent recomputation — which is not something I can usually say. The architectural judgment is sound throughout: the coupled-defect analysis on /60 + text-white is correct and well-evidenced, the scope is atomic, the deferral of the rest-state brand-color gap is the right call, and the new suite tests consumption rather than re-testing token values — closing precisely the gap that let this ship while a sibling suite stayed green.

Both 🟡 findings are rationale and dead-code issues, not behavioral ones. The button renders correctly, every hover clears AA, and the alpha-hover idiom is genuinely guarded by a test I confirmed bites. Neither blocks merge.

I'd ask for one small follow-up, ideally folded in before merge since it's a few lines: correct the <alpha-value> claim in the config comment and DESIGN.md:300. That one is worth not letting sit, because it's a false guarantee entering the design system's written rules where others will build on it. Deleting the unreachable not.toContain line and extracting the WCAG helpers are both fine as follow-ups.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

The reviewer caught a false guarantee I had written into three places. I
reproduced it through PostCSS before changing anything:

  .hover\:bg-destructive-hover\/90:hover {
      background-color: hsl(var(--destructive-hover) / 0.9)
  }

Tailwind v3 injects alpha into `hsl(var(--x))` whether or not the entry
carries an <alpha-value> placeholder, so `hover:bg-destructive-hover/90`
compiles fine. My claim that omitting the placeholder makes an alpha
variant "not resolve" was simply wrong.

The fix itself is unaffected — the two classes the component uses still
emit exactly the intended opaque rules — but the false reason had been
written into the config comment, the test, and DESIGN.md, where it was
becoming a standing rule. Corrected in all three to say what is actually
true: the bare form is a convention for a value meant to be used opaquely,
and the thing that actually forbids an alpha hover is the filled-variant
sweep in the test suite.

Also documented that `not.toContain('text-white')` cannot fail on its own.
`tv()` runs tw-merge, so a literal added after the token REPLACES it rather
than joining it — `text-destructive-foreground text-white` collapses to
`text-white` alone. Verified both orderings. The regression is still caught,
by the positive assertion on the line above; the negative one stays as a
statement of the prohibition, now labelled as such rather than reading like
an independent safety net.

Extracted the WCAG helpers to src/tests/helpers/wcag-contrast.ts, following
the existing helpers/ precedent. They had been copy-pasted byte-for-byte
between the two design suites, and the copy dropped the readHsl comment
recording that an earlier draft's regex typo produced 16 vacuous passes —
so the hardest-won lesson survived in only one of the two files that
implement it. It now lives in one place, with both suites importing it.

Not added to helpers/index.ts on purpose: that barrel re-exports DOM
fixtures and node factories, and these two suites are pure file reading
with no DOM. Importing by direct path keeps them from dragging in setup
they do not use.

Re-verified the guard still bites after the refactor rather than trusting
the passing count:

  - variants reverted to stock shadcn        -> 5 failures (unchanged)
  - dark --destructive-hover 76% -> 64%      -> 3 failures across both suites

Verification:
- bun run test: 250 files / 5148 tests passed, identical to pre-refactor
- bun run quality:fix: clean; design-token baseline unchanged at 137;
  svelte-check 2541 files, 0 errors, 0 warnings

DESIGN.md corrected separately in nodespace-docs.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@malibio

malibio commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed — 226cb606

Thanks for recomputing all the contrast figures independently and re-running both mutations rather than taking the table on faith. The <alpha-value> finding is the one that mattered, and you were right.

✅ Addressed: the <alpha-value> claim was false (🟡)

I reproduced it through PostCSS before changing anything:

.hover\:bg-destructive-hover\/90:hover {
    background-color: hsl(var(--destructive-hover) / 0.9)
}

Tailwind v3 injects alpha into hsl(var(--x)) whether or not the entry carries the placeholder. My claim that omitting it makes an alpha variant "not resolve" was simply wrong.

You called the severity correctly by flagging where it had spread. The fix itself is unaffected — the two classes the component uses still emit the intended opaque rules — but the false reason was in three places, including DESIGN.md, where it was becoming a standing rule. The real damage of a wrong guarantee there is that a reader concludes the config mechanically prevents alpha hovers and stops looking for the thing that actually does.

Corrected in all three to state what's true: the bare form is a convention for a value meant to be used opaquely, and the enforcement is the filled-variant sweep in the test suite. DESIGN.md fixed separately in nodespace-docs (d40ada3).

✅ Addressed: not.toContain('text-white') is unreachable (🟡)

Confirmed, and your diagnosis was better than the array-semantics question I'd flagged for you — tv() runs tw-merge, so the two classes are mutually exclusive and the positive assertion always throws first.

Verified both orderings, which surfaced something worth recording:

'... text-destructive-foreground text-white'  ->  'bg-destructive text-white'
'... text-white text-destructive-foreground'  ->  'bg-destructive text-destructive-foreground'

A literal added after the token silently replaces it — which is exactly the original bug's shape. So the coverage is real, it just all lives on the line above. Kept the assertion, now labelled as a statement of the prohibition rather than reading like an independent safety net.

✅ Addressed: helper duplication (🟢 — promoted)

I'd have deferred this as cosmetic. Your specific point changed my mind: my copy dropped the readHsl comment recording that an earlier draft's regex typo produced 16 vacuous passes, so the hardest-won lesson in this area survived in only one of the two files implementing it. That's a maintenance hazard, not style.

Extracted to src/tests/helpers/wcag-contrast.ts following the existing helpers/ precedent; both suites import it. Net −13 lines despite the added file.

Deliberately not added to helpers/index.ts: that barrel re-exports DOM fixtures and node factories, and these two suites are pure file reading with no DOM. Direct-path import keeps them from pulling in setup they don't use.

Re-verified the guard still bites after the refactor rather than trusting the passing count — a refactor that quietly breaks a guard looks identical to one that doesn't:

Mutation Before extraction After
Variants reverted to stock shadcn 5 failures 5 failures
dark --destructive-hover 76% → 64% 1 failure 3 failures (both suites now)

Verification

  • bun run test — 250 files / 5148 tests passed, identical to pre-refactor
  • bun run quality:fix — clean; design-token baseline unchanged at 137; svelte-check 2541 files, 0 errors, 0 warnings
  • Pre-push gate — full pyramid green

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: The <alpha-value> and not.toContain corrections are comment-only and would not warrant one on their own. The helper extraction is not — it moved ~55 lines of contrast math out of both design suites into a new shared module, changing the imports of a file that was not part of the original review (filled-button-hover.test.ts).

That file is the guard for the tokens the whole rule rests on, and it is now exercising code it didn't previously own. I re-ran both mutations and the count is unchanged, but "the author re-ran his own mutations" is exactly the evidence an independent reviewer exists to check. The refactor also touches the one function whose correctness history includes a silent-vacuous-pass failure.

A reviewer should confirm the extracted readHsl / contrast / themeBlock are byte-equivalent in behavior to both originals, and that neither suite lost an assertion in the move.

@malibio

malibio commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #2710 (Re-Review)

Review Type: Re-Review
Scope: git diff c7d102e3..226cb606 — 4 files, +104/−117 (net −13)
Previous review: APPROVE with 2 🟡 and 1 🟢


Previous Review Summary

# Finding Severity Status
1 <alpha-value> omission does not enforce what the comment claims 🟡 ✅ Addressed
2 not.toContain('text-white') is unreachable 🟡 ✅ Addressed
3 WCAG helpers duplicated across both design suites 🟢 ✅ Addressed (promoted)

3 addressed / 0 not addressed / 0 new issues.


Summary

All three findings are properly addressed, and the one that triggered this re-review — the helper extraction — holds up under independent verification. I did not take the author's mutation table on faith; I re-ran both mutations myself and re-derived the equivalence rather than reading the diff.

The headline result: the extracted helpers are byte-identical to both originals. I extracted the pre-refactor versions of both suites (git show c7d102e3:...) and compared each of the five function bodies character-for-character against the new shared module:

themeBlock   new==hover:True  new==variants:True
readHsl      new==hover:True  new==variants:True
hslToRgb     new==hover:True  new==variants:True
luminance    new==hover:True  new==variants:True
contrast     new==hover:True  new==variants:True

The specific hazard flagged for scrutiny — the readHsl regex living inside a template string, where \\w could silently become \w during the move — did not occur. The pattern source is identical in all three files:

new     pattern= `${token}(?![\\w-])\\s*:\\s*([\\d.]+)\\s+([\\d.]+)%\\s+([\\d.]+)%`
old_h   pattern= `${token}(?![\\w-])\\s*:\\s*([\\d.]+)\\s+([\\d.]+)%\\s+([\\d.]+)%`
old_v   pattern= `${token}(?![\\w-])\\s*:\\s*([\\d.]+)\\s+([\\d.]+)%\\s+([\\d.]+)%`

Worth noting the doc comment above it correctly renders the escape as (?![\w-]) in prose while the code keeps \\w — the prose describes the compiled regex, which is right, and is not a sign of drift.

AA is 4.5 in all three. readHsl still throws on a miss (if (!match) throw new Error(...)) rather than returning null, and the comment recording that an earlier draft's null-return turned a regex typo into 16 vacuous passes survived the move intact (wcag-contrast.ts:43). That comment was previously present in only one of the two copies; it is now in the single place both suites depend on, which was the actual argument for the extraction.


Verification Performed

No assertions or tests were lost. I ran both suites at c7d102e3 and at 226cb606:

Pre-refactor Post-refactor
filled-button-hover.test.ts 41 tests 41 tests
filled-button-variants.test.ts 14 tests 14 tests
Total 55 passed 55 passed

I also diffed the full set of it(...) / describe(...) titles in both files. They are identical except for the one deliberate rename (registers ${token}-hover with no alpha channel → registers ${token}-hover in its bare, opaque form), which is itself part of finding 1's fix.

The guard still bites. Both mutations reproduce exactly as the author reported:

Mutation Claimed Observed
Variants reverted to stock shadcn (hover:bg-primary/90, text-white, dark:bg-destructive/60) 5 failures 5 failures ✅
Dark --destructive-hover 76% → 64% 3 failures, both suites 3 failures, both suites ✅

Mutation 2 is the one that matters for this refactor, because it is the one that exercises the extracted math. It failed in both files:

FAIL filled-button-hover.test.ts > dark theme > moves --destructive-hover lighter than --destructive
FAIL filled-button-hover.test.ts > dark theme > does not lose contrast hovering --destructive
FAIL filled-button-variants.test.ts > destructive variant > rises above AA and above rest on hover, dark theme

That confirms filled-button-hover.test.ts — the file that was not in the original review's diff — is still genuinely driving readHsl, themeBlock and contrast through the shared module, and is not passing vacuously. Working tree restored and verified clean (git status --short empty) after each mutation.

The corrected <alpha-value> claim is itself correct this time. I did not take the new wording on faith either — a second wrong claim replacing the first was the specific risk. Compiled through PostCSS with the repo's real config:

.bg-primary-hover\/50               { background-color: hsl(var(--primary-hover) / 0.5) }
.hover\:bg-destructive-hover\/90:hover { background-color: hsl(var(--destructive-hover) / 0.9) }
.hover\:bg-primary-hover\/90:hover  { background-color: hsl(var(--primary-hover) / 0.9) }
.hover\:bg-destructive-hover:hover  { background-color: hsl(var(--destructive-hover)) }
.hover\:bg-primary-hover:hover      { background-color: hsl(var(--primary-hover)) }

Alpha variants do compile (so the new "this is a convention, not a barrier" framing is accurate), and the two classes the component actually uses do emit opaque rules (so the fix remains unaffected). DESIGN.md:300-302 in nodespace-docs (d40ada3) now says exactly this, and correctly names filled-button-variants.test.ts as the real enforcement — which mutation 1 confirms works, since has no alpha-fill hover left on a filled variant was among the 5 failures.

Standards. The new wcag-contrast.ts is clean: no any, no console.*, no lint suppression, no embedded GitHub issue numbers. ESLint passes on all three changed test files; svelte-check reports 0 errors and 0 warnings.


Findings

🟢 Nits

📁 packages/desktop-app/src/tests/helpers/wcag-contrast.ts — not added to helpers/index.ts is the right call, and it matches convention.

The author's reasoning (the barrel re-exports DOM fixtures and node factories that these file-reading suites shouldn't pull in) is sound on its own terms, and I checked whether it is consistent with the codebase rather than just plausible. It is: mock-tauri-core.ts and schema-fixtures.ts are also absent from the barrel, and direct-path importing is the dominant pattern across the suite — import { mockTauriCore } from '../helpers/mock-tauri-core' appears in a dozen-plus files. Nothing inconsistent here. No change requested.

📁 packages/desktop-app/src/tests/helpers/wcag-contrast.ts:70,76 — hslToRgb and luminance are exported but no caller imports them.

Both suites import only { AA, contrast, readHsl, themeBlock }. The two exported-but-unconsumed functions are internal steps of contrast. This is defensible — they are meaningful, independently testable units of WCAG math and a reader benefits from them being named and documented — and CLAUDE.md's "no #[allow(dead_code)]" rule is a Rust directive about suppressing warnings, not a ban on a helper module exporting its parts. Flagging only so the choice is deliberate; dropping export on both would narrow the module's surface to what is actually used. Either way is fine.


Assessment

This is a textbook address-review response. The author reproduced the reviewer's finding independently before acting on it, corrected the false claim in all three places it had spread to rather than only where it was flagged, and — most importantly — re-verified the guard by mutation after the refactor instead of trusting the passing test count. The instinct that "a refactor that quietly breaks a guard looks identical to one that doesn't" is exactly right, and calling for a re-review on a change that touched a file outside the original diff was the correct judgment rather than an excess of caution.

The extraction is a genuine net improvement: −13 lines, one copy of the contrast math, and the hardest-won comment in the area now lives where both dependents see it.

No blocking issues. No new issues. Nothing outstanding from the previous review.


Recommendation: APPROVE

Both 🟡 findings and the 🟢 are fully addressed. The helper extraction is behaviorally byte-identical to both originals, neither suite lost a test or an assertion, both mutations still fire at full strength across both files, and the replacement <alpha-value> wording is verified accurate against an actual PostCSS compile. Quality gates are green. Ready to merge at the author's discretion.

🤖 Generated with Claude Code

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

Re-review flagged that both are exported but only `contrast` is imported,
asking that the choice be deliberate rather than incidental.

Keeping them. They are the two WCAG primitives `contrast` is built from,
not dead code, and an assertion about a single color — a non-ratio
threshold, or whether a surface reads as light or dark — needs the
luminance without the comparison. Hiding them would push the next such
test back to a local copy of the math, which is the duplication this
module was extracted to end.

Comment-only; no behavior change.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@malibio
malibio merged commit c82b378 into main Sep 17, 2026
@malibio
malibio deleted the issue-2689-button-hover-tokens branch September 17, 2026 09:39
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.

Shared shadcn Button variants use alpha hovers and lose contrast on hover in every variant

1 participant