diff --git a/apps/web/e2e/tests/warning-token-cascade.spec.ts b/apps/web/e2e/tests/warning-token-cascade.spec.ts new file mode 100644 index 000000000..052658ecd --- /dev/null +++ b/apps/web/e2e/tests/warning-token-cascade.spec.ts @@ -0,0 +1,223 @@ +import { expect, test } from '@playwright/test'; +import { renderCssFixture } from '../lib/computedStyle'; + +/** + * Computed-cascade verification for the semantic-warning token migration (#2161). + * + * `warning-token-migration.unit.spec.ts` proves the SOURCE references + * `var(--color-warning)` at each migrated site. It cannot prove the browser + * actually PAINTS that color — this codebase's `index.css`/`nocturne.css` are + * imported unlayered, while every Tailwind utility (including arbitrary-value + * ones like `border-[var(--color-warning)]/30`) lives inside `@layer + * utilities`, and an unlayered `background`/`border` shorthand always wins + * over a layered declaration regardless of specificity or source order. A + * source-string scan is byte-identical for a working migration and a no-op + * one, so it cannot see this at all — the exact trap `.hr`, nocturne's + * `.btn` padding, and the duplicate `--space-*` definitions already caught + * elsewhere in this codebase. + * + * Real re-measurement (Chromium via `renderCssFixture` against the actual + * compiled `dist` CSS, not source inspection) found FOUR of this PR's + * original sixteen candidate sites were exactly this trap — all inert, + * still painting their pre-migration fallback color despite correct source: + * `CampaignAuditPage.tsx:294` (renders through ``, whose `cf-card` + * class carries an unlayered `background`/`border` shorthand), + * `MembersPage.tsx:483` / `InboxPage.tsx:700` (both carry `cf-inset`, same + * unlayered shorthand), and `SpellbookPanel.tsx:484` (carries `.btn`, whose + * unlayered `background: 0 0` resets it to transparent before + * `.btn-primary` applies anything). Rather than paper over that with an + * `!important` escape or a new unlayered modifier class — both real design + * decisions, not mechanical fixes — those four sites were REVERTED to raw + * amber (see #2203's review) and filed as follow-up issue #2208 for a + * proper warning-semantic variant of `.cf-card`/`.cf-inset`/`.btn`. + * + * ## Why this asserts EQUALITY, not "not the fallback color" (review round 2) + * + * The first version of this suite asserted only `computed !== --color-divider` + * / `computed !== --cf-card` — the two known no-op fallback colors found + * above. Codex correctly flagged that as the SAME structural flaw one level + * up: excluding two known-bad values is not the same as confirming the right + * one. If a future Tailwind version stopped emitting + * `border-[var(--color-warning)]/35` (a config change, a build regression, + * anything), the element would fall back to the CSS default `currentColor` + * for border and `transparent` for background — NEITHER of which equals + * `--color-divider` or `--cf-card` — so the old assertion would still pass + * while zero sites actually painted warning. Verified this exact failure + * mode directly: rendering a site's markup with a nonexistent utility class + * in place of the real one resolves to `currentColor` (`rgb(233,233,237)` + * here), which the OLD `!== --color-divider` check does not catch but the + * new equality check below does. + * + * The fix computes the EXPECTED color independently of whether Tailwind's + * utility class is even present: `color-mix(in oklab, var(--color-warning) + * N%, transparent)`, built directly from the live `--color-warning` custom + * property (never hardcoded as a literal rgb/hex — if the token value ever + * changes, this recomputes against the new value automatically) and the + * browser's own `color-mix()`. This is exactly the CSS Tailwind v4 compiles + * `bg-[var(--color-warning)]/N` / `border-[...]/N` down to (verified by + * reading the compiled `dist` CSS directly) — but critically, this + * expression is evaluated independently, on an element that never carries + * the Tailwind utility class at all, so it does not depend on Tailwind + * having emitted anything. Real and expected are then compared for EXACT + * equality (canvas-normalized RGBA, zero tolerance): verified empirically + * across every opacity step used below (5/10/30/35/40/50%) that the + * independently-constructed expression and Tailwind's own compiled utility + * resolve to byte-identical RGBA — both go through the same browser + * `color-mix()` primitive with the same inputs, so there is no rounding + * drift to tolerate. A loose tolerance would risk admitting exactly the + * `currentColor`/`transparent` fallback this check exists to catch, so none + * is used. + */ + +interface MigratedSite { + /** Real markup for the site — matches what the actual component renders. */ + html: string; + /** border-[var(--color-warning)]/N opacity, if this site migrated the border. */ + borderPct?: number; + /** bg-[var(--color-warning)]/N opacity, if this site migrated the background. */ + bgPct?: number; +} + +const SITES: Record = { + 'AudienceField:61': { + html: '

x

', + borderPct: 30, + bgPct: 10, + }, + 'EntityRevealDialog:64': { + html: '

x

', + borderPct: 30, + bgPct: 10, + }, + 'HandoutsCard:295': { + html: '

x

', + borderPct: 30, + bgPct: 10, + }, + 'VisibleToPlayersBar:95': { + html: '
x
', + borderPct: 35, + bgPct: 10, + }, + 'VisibleToPlayersBar:113': { + html: '
x
', + borderPct: 35, + bgPct: 10, + }, + 'RunSessionPage:4496': { + html: '
x
', + borderPct: 40, + bgPct: 10, + }, + 'RunSessionPage:4520': { + html: '
x
', + borderPct: 40, + bgPct: 10, + }, + 'RunSessionPage:4551': { + html: '
x
', + borderPct: 40, + bgPct: 10, + }, + 'EncounterWhisperComposer:65': { + html: '
x
', + borderPct: 30, + // No bgPct — this form's background is bg-neutral-900/90, never migrated. + }, + 'AuditLogCard:173': { + html: '
x
', + borderPct: 30, + bgPct: 5, + }, + 'ResetRequestsCard:117': { + html: '
x
', + borderPct: 30, + // No bgPct — this div never had a background utility. + }, + 'SpellbookPanel:463': { + html: '
x
', + borderPct: 50, + // No bgPct — this div's background is bg-neutral-900, never migrated. + }, +}; + +/** Canvas-normalize a CSS color string to a stable, comparable RGBA tuple string. Both + * "real" and "expected" values go through this, so the comparison is apples-to-apples + * regardless of whether the browser's `getComputedStyle` reports the color as `rgb()`, + * `rgba()`, `color(srgb ...)`, or `oklab(...)` — canvas fillStyle resolves all of them + * to the same underlying pixel. */ +async function normalizedColor(page: import('@playwright/test').Page, cssColor: string): Promise { + return page.evaluate((c) => { + const canvas = document.createElement('canvas'); + canvas.width = 1; + canvas.height = 1; + const ctx = canvas.getContext('2d')!; + ctx.fillStyle = c; + ctx.fillRect(0, 0, 1, 1); + return Array.from(ctx.getImageData(0, 0, 1, 1).data).join(','); + }, cssColor); +} + +/** The expected color for an N% `--color-warning` utility, computed independently of + * whether any Tailwind utility class is present — built only from the live + * `--color-warning` custom property and the browser's own `color-mix()`. */ +async function expectedWarningColor(page: import('@playwright/test').Page, pct: number): Promise { + const resolved = await page.evaluate((p) => { + const probe = document.createElement('div'); + document.body.appendChild(probe); + probe.style.backgroundColor = `color-mix(in oklab, var(--color-warning) ${p}%, transparent)`; + const value = getComputedStyle(probe).backgroundColor; + probe.remove(); + return value; + }, pct); + return normalizedColor(page, resolved); +} + +test.describe('warning-token migration: computed cascade (#2161)', () => { + test('every migrated site paints the EXACT --color-warning composite, not just "not the old fallback"', async ({ + page, + }) => { + const allHtml = Object.values(SITES) + .map((s) => s.html) + .join('\n'); + await renderCssFixture(page, `
${allHtml}
`); + + // Cache one expected value per distinct percentage instead of recomputing per site. + const distinctPcts = new Set(); + for (const site of Object.values(SITES)) { + if (site.borderPct !== undefined) distinctPcts.add(site.borderPct); + if (site.bgPct !== undefined) distinctPcts.add(site.bgPct); + } + const expectedByPct = new Map(); + for (const pct of distinctPcts) { + expectedByPct.set(pct, await expectedWarningColor(page, pct)); + } + + for (const [name, site] of Object.entries(SITES)) { + const el = page.locator(`[data-site="${name}"]`); + const { border, bg } = await el.evaluate((node) => { + const cs = getComputedStyle(node); + return { border: cs.borderColor, bg: cs.backgroundColor }; + }); + + if (site.borderPct !== undefined) { + const normBorder = await normalizedColor(page, border); + const expected = expectedByPct.get(site.borderPct)!; + expect( + normBorder, + `${name}: border must equal color-mix(--color-warning ${site.borderPct}%, transparent) exactly — ` + + 'got a different value, meaning this site is not actually painting the warning token ' + + '(currentColor/transparent from a missing utility would also fail here, unlike a "not the old fallback" check)', + ).toBe(expected); + } + if (site.bgPct !== undefined) { + const normBg = await normalizedColor(page, bg); + const expected = expectedByPct.get(site.bgPct)!; + expect( + normBg, + `${name}: background must equal color-mix(--color-warning ${site.bgPct}%, transparent) exactly`, + ).toBe(expected); + } + } + }); +}); diff --git a/apps/web/e2e/tests/warning-token-migration.unit.spec.ts b/apps/web/e2e/tests/warning-token-migration.unit.spec.ts new file mode 100644 index 000000000..46d781b20 --- /dev/null +++ b/apps/web/e2e/tests/warning-token-migration.unit.spec.ts @@ -0,0 +1,154 @@ +/** + * Semantic-warning color token migration (issue #2161). + * + * #1533's PR defined `--color-warning: #d97706` but left every raw `amber-*` + * Tailwind utility that actually renders semantic warning state (a caution + * banner, a "shown once" disclosure, a disabled-feature notice, …) untouched. + * This suite pins the SOURCE at each migrated site so a future edit cannot + * silently drop it back onto a raw `amber-*` class. It is deliberately a + * cheap, fast smoke check, **necessary but not sufficient** — a source string + * can be byte-identical between a working migration and a completely inert + * one whenever the element renders through a component (``, `cf-inset`, + * `.btn`) carrying an unlayered `background`/`border` shorthand, since + * `index.css`/`nocturne.css` are imported unlayered and always beat a layered + * Tailwind utility (including an arbitrary-value one) regardless of + * specificity or source order. `warning-token-cascade.spec.ts` + * (browser-backed, real `getComputedStyle`) is the check that actually proves + * a site paints the right color; run it, don't just read this one, before + * trusting a "migrated" claim on this codebase's design-system classes. + * + * That trap caught 4 of this PR's original 16 candidate sites + * (`CampaignAuditPage.tsx:294` via ``'s `cf-card`, `MembersPage.tsx:483` + * and `InboxPage.tsx:700` via `cf-inset`, `SpellbookPanel.tsx:484` via + * `.btn`'s `background: 0 0` reset) — all four were reverted rather than + * shipped as source that claims `--color-warning` while painting + * `--color-divider`/`--cf-card`/transparent. Filed as a follow-up issue + * (warning-semantic variants for `.cf-card`/`.cf-inset`/`.btn`) rather than + * fixed here with an `!important` escape or a new unlayered modifier class — + * both are real design decisions, not mechanical fixes, and out of scope for + * a color migration. The 12 sites below are confirmed, by that same + * computed-style measurement, to actually paint `--color-warning`. + * + * This spec asserts source presence at each of the 12, with an exact + * PER-FILE occurrence COUNT for files with more than one migrated + * declaration (`VisibleToPlayersBar.tsx`: 2, `RunSessionPage.tsx`: 3) — + * matching only "at least one" would let one of several sites silently + * regress back to raw amber while the others keep the test green. + * + * Scope (see the PR description for the full audit): `--color-warning` is a + * single flat hex, unlike `--color-danger`'s multi-role family + * (`--color-danger`, `--color-danger-solid*`, `--color-danger-border`, + * `--color-danger-focus`, `--color-danger-ghost-*`, `--color-danger-disabled-*`). + * Only the non-text roles (border and background tint) were migrated. + * Readable warning TEXT color, dark "muted surface" tints (`amber-950/*`), and + * decorative/selection uses of amber are deliberately left alone — see the + * PR description for the full excluded population and why. This guard + * therefore only covers the sites actually migrated, not every `amber-*` in + * the app: raw amber remains a legitimate decorative or not-yet-staged + * choice everywhere else. + */ +import { expect, test } from '@playwright/test'; +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; + +const ROOT = resolve(__dirname, '../../src'); +const READ = (relPath: string) => readFileSync(resolve(ROOT, relPath), 'utf8'); + +interface MigratedSite { + file: string; + /** Raw amber-* declarations that must never reappear at this site. */ + bannedPatterns: RegExp[]; + /** + * var(--color-warning) usages that must be present, each with the EXACT number of + * occurrences expected in the file. A plain `toMatch` (at-least-one) check would pass + * for a file with N migrated call sites even if all but one regressed back to raw + * amber — VisibleToPlayersBar.tsx (2 sites) and RunSessionPage.tsx (3 sites) are + * exactly that shape today, and more will be as this migration continues. Counting + * exact occurrences catches a partial regression a presence-only check cannot. + */ + requiredPatterns: Array<{ pattern: RegExp; count: number }>; +} + +const MIGRATED_SITES: MigratedSite[] = [ + { + file: 'features/encounters/SpellbookPanel.tsx', + // Only the modal border (:463) is migrated. The confirm button's bg-amber-600 + // (:484) was reverted (#2203 review) — it renders through `.btn`, whose unlayered + // `background: 0 0` (nocturne.css) made bg-[var(--color-warning)] a no-op there; + // see the file header and the follow-up issue tracking a proper fix. + bannedPatterns: [/border-amber-500\/50/], + requiredPatterns: [{ pattern: /border-\[var\(--color-warning\)\]\/50/g, count: 1 }], + }, + { + file: 'components/AudienceField.tsx', + bannedPatterns: [/border-amber-500\/30 bg-amber-500\/10/], + requiredPatterns: [{ pattern: /border-\[var\(--color-warning\)\]\/30 bg-\[var\(--color-warning\)\]\/10/g, count: 1 }], + }, + { + file: 'components/EntityRevealDialog.tsx', + bannedPatterns: [/border-amber-500\/30 bg-amber-500\/10/], + requiredPatterns: [{ pattern: /border-\[var\(--color-warning\)\]\/30 bg-\[var\(--color-warning\)\]\/10/g, count: 1 }], + }, + { + file: 'features/dashboard/HandoutsCard.tsx', + bannedPatterns: [/border-amber-500\/30 bg-amber-500\/10/], + requiredPatterns: [{ pattern: /border-\[var\(--color-warning\)\]\/30 bg-\[var\(--color-warning\)\]\/10/g, count: 1 }], + }, + { + file: 'components/VisibleToPlayersBar.tsx', + // 2 migrated sites (:95 hidden-from-players, :113 visible-to-players). + bannedPatterns: [/border-amber-500\/35 bg-amber-500\/10/g], + requiredPatterns: [{ pattern: /border-\[var\(--color-warning\)\]\/35 bg-\[var\(--color-warning\)\]\/10/g, count: 2 }], + }, + { + file: 'features/encounters/RunSessionPage.tsx', + // 3 migrated sites (:4496 reconcile banner, :4520/:4551 sync-override prompts). + bannedPatterns: [/border-amber-500\/40 bg-amber-500\/10/g], + requiredPatterns: [{ pattern: /border-\[var\(--color-warning\)\]\/40 bg-\[var\(--color-warning\)\]\/10/g, count: 3 }], + }, + { + file: 'features/encounters/EncounterWhisperComposer.tsx', + // Border only — the form also carries text-amber-300 (title) and + // focus:ring-amber-400 (textarea), deliberately left raw; see PR + // description ("no text-safe --color-warning role"). + bannedPatterns: [/rounded-lg border border-amber-500\/30 bg-neutral-900\/90/], + requiredPatterns: [{ pattern: /rounded-lg border border-\[var\(--color-warning\)\]\/30 bg-neutral-900\/90/g, count: 1 }], + }, + { + file: 'features/admin/AuditLogCard.tsx', + bannedPatterns: [/border-amber-500\/30 bg-amber-500\/5/], + requiredPatterns: [{ pattern: /border-\[var\(--color-warning\)\]\/30 bg-\[var\(--color-warning\)\]\/5/g, count: 1 }], + }, + { + file: 'features/admin/ResetRequestsCard.tsx', + // Border only — the heading directly below stays text-amber-500 (raw); + // same "no text-safe role" reasoning as EncounterWhisperComposer above. + bannedPatterns: [/"border border-amber-500\/30 rounded p-2\.5 space-y-1"/], + requiredPatterns: [{ pattern: /"border border-\[var\(--color-warning\)\]\/30 rounded p-2\.5 space-y-1"/g, count: 1 }], + }, +]; + +test.describe('Semantic-warning token migration (#2161)', () => { + for (const site of MIGRATED_SITES) { + test(`${site.file} uses --color-warning, not raw amber, at its migrated site(s)`, () => { + const text = READ(site.file); + for (const pattern of site.bannedPatterns) { + expect(text, `${site.file} must not reintroduce ${pattern}`).not.toMatch(pattern); + } + for (const { pattern, count } of site.requiredPatterns) { + const matches = text.match(pattern); + const actual = matches ? matches.length : 0; + expect( + actual, + `${site.file} must reference --color-warning via ${pattern} exactly ${count} time(s), found ${actual} — ` + + 'a partial regression (some sites migrated, others reverted to raw amber) must fail here, not pass on "at least one"', + ).toBe(count); + } + }); + } + + test('--color-warning token itself stays defined', () => { + const css = READ('index.css'); + expect(css).toMatch(/--color-warning:\s*#d97706/); + }); +}); diff --git a/apps/web/src/components/AudienceField.tsx b/apps/web/src/components/AudienceField.tsx index 655d0f29e..fe54cd98a 100644 --- a/apps/web/src/components/AudienceField.tsx +++ b/apps/web/src/components/AudienceField.tsx @@ -58,7 +58,7 @@ export function AudienceField({

Players will see this {entityLabel} as soon as you create it — including in lists, search, and shared links. You can hide it again right after if that was a mistake. diff --git a/apps/web/src/components/EntityRevealDialog.tsx b/apps/web/src/components/EntityRevealDialog.tsx index dbcf23407..317176802 100644 --- a/apps/web/src/components/EntityRevealDialog.tsx +++ b/apps/web/src/components/EntityRevealDialog.tsx @@ -61,7 +61,7 @@ export function EntityRevealDialog({ )} -

+

{t('secrecy.revealIrreversible')}

diff --git a/apps/web/src/components/VisibleToPlayersBar.tsx b/apps/web/src/components/VisibleToPlayersBar.tsx index 95a2cf021..b710df524 100644 --- a/apps/web/src/components/VisibleToPlayersBar.tsx +++ b/apps/web/src/components/VisibleToPlayersBar.tsx @@ -92,7 +92,7 @@ export function VisibleToPlayersBar({
Hidden from players @@ -110,7 +110,7 @@ export function VisibleToPlayersBar({
Visible to players diff --git a/apps/web/src/features/admin/AuditLogCard.tsx b/apps/web/src/features/admin/AuditLogCard.tsx index ea5b2af4c..8c6c5c4e4 100644 --- a/apps/web/src/features/admin/AuditLogCard.tsx +++ b/apps/web/src/features/admin/AuditLogCard.tsx @@ -170,7 +170,7 @@ export function AuditLogCard() {
{error &&

{error}

} {retention ? ( -
+

Audit retention policy

diff --git a/apps/web/src/features/admin/ResetRequestsCard.tsx b/apps/web/src/features/admin/ResetRequestsCard.tsx index 89a082f6b..9ad464d72 100644 --- a/apps/web/src/features/admin/ResetRequestsCard.tsx +++ b/apps/web/src/features/admin/ResetRequestsCard.tsx @@ -114,7 +114,7 @@ export function ResetRequestsCard() {

{approval && resetUrl && ( -
+

One-time reset link — shown once, give it to {approval.request.username} now

diff --git a/apps/web/src/features/dashboard/HandoutsCard.tsx b/apps/web/src/features/dashboard/HandoutsCard.tsx index 59534d1e2..b98cd6fee 100644 --- a/apps/web/src/features/dashboard/HandoutsCard.tsx +++ b/apps/web/src/features/dashboard/HandoutsCard.tsx @@ -292,7 +292,7 @@ export function HandoutsCard({ campaignId }: { campaignId: number }) { {pendingReveal.filename}

-

+

Revealing a handout exposes the raw image or PDF to players. Encounter fog, hidden tokens, AoE filtering, and Cast player-safe projection do not protect this file. diff --git a/apps/web/src/features/encounters/EncounterWhisperComposer.tsx b/apps/web/src/features/encounters/EncounterWhisperComposer.tsx index a0484fb54..e297879f0 100644 --- a/apps/web/src/features/encounters/EncounterWhisperComposer.tsx +++ b/apps/web/src/features/encounters/EncounterWhisperComposer.tsx @@ -62,7 +62,7 @@ export function EncounterWhisperComposer({ return (

diff --git a/apps/web/src/features/encounters/RunSessionPage.tsx b/apps/web/src/features/encounters/RunSessionPage.tsx index 11c279493..4b9891626 100644 --- a/apps/web/src/features/encounters/RunSessionPage.tsx +++ b/apps/web/src/features/encounters/RunSessionPage.tsx @@ -4493,7 +4493,7 @@ export default function RunSessionPage() { aria-live="polite" data-testid="mutation-reconcile-banner" data-phase={reconcile.phase} - className="rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-sm" + className="rounded-lg border border-[var(--color-warning)]/40 bg-[var(--color-warning)]/10 px-3 py-2 text-sm" > {reconcile.phase === 'checking' ? t('encounters.reconcile.checking') @@ -4517,7 +4517,7 @@ export default function RunSessionPage() { role="status" aria-live="polite" data-testid="encounter-sync-override-prompt" - className="rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-sm flex items-center gap-2 flex-wrap" + className="rounded-lg border border-[var(--color-warning)]/40 bg-[var(--color-warning)]/10 px-3 py-2 text-sm flex items-center gap-2 flex-wrap" > {t('encounters.sync.overridePrompt')} {t('encounters.sync.ownOverridePrompt')} -
+

🔮 Concentration Warning