From 8873e959fc012b8339c2946328d44f3dbe9fd4ca Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 11 Aug 2026 01:18:45 +0000 Subject: [PATCH 1/8] test(web): audit z-index bypass claims against the documented overlay scale (#2163) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-measures every z-index declaration in index.css against the documented --cf-layer-* scale (issue #791), tracing stacking context rather than grepping literals. Of 25 declarations: 9 already consume a token, 2 are resets, and 14 are raw literals — including the encounter VTT cockpit's already-commented local nesting order, plus the two sites issue #2163 itself flagged as "plausible real drift" (.cf-death-save-spectator-toast, .cf-gated-hint). Neither turns out to be a real bypass: both only ever render nested inside an element that already establishes its own stacking context (.cf-vtt, or .cf-authed-shell for the character-sheet death-save tracker), so their literal z-index values are scoped to that ancestor and can never compete with the global tabbar/chrome tiers they numerically coincide with — a stray whole subtree already outranks its sibling regardless of what a descendant's own number says. z-index-audit-toast-stacking.spec.ts proves this live via elementFromPoint rather than by re-reading the CSS, including a control where the injected toast is crippled to z-index:1 and still wins, isolating the win to .cf-vtt's own ancestor dominance. With zero confirmed bypasses, the deliverable is audit evidence plus a regression guard, not a migration: z-index-audit.unit.spec.ts pins the exact classified set of 14 raw literals (narrower than "no raw z-index outside the scale," which would incorrectly flag the cockpit's legitimate local values per the issue's own caution) so a new unclassified raw z-index fails the guard instead of landing silently. Fixes #2163 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LjFox1SZv765yv918tLJrh --- .../z-index-audit-toast-stacking.spec.ts | 134 ++++++++++++++ apps/web/e2e/tests/z-index-audit.unit.spec.ts | 168 ++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100644 apps/web/e2e/tests/z-index-audit-toast-stacking.spec.ts create mode 100644 apps/web/e2e/tests/z-index-audit.unit.spec.ts diff --git a/apps/web/e2e/tests/z-index-audit-toast-stacking.spec.ts b/apps/web/e2e/tests/z-index-audit-toast-stacking.spec.ts new file mode 100644 index 000000000..74be97aac --- /dev/null +++ b/apps/web/e2e/tests/z-index-audit-toast-stacking.spec.ts @@ -0,0 +1,134 @@ +/** + * Live stacking proof for issue #2163's "plausible real drift" candidate + * `.cf-death-save-spectator-toast` (`z-index: 40`, the same literal value as + * `--cf-layer-tabbar`). + * + * z-index-audit.unit.spec.ts explains, from the source, why this is not actually a scale + * bypass: the toast only ever renders as a child of `.cf-vtt`, and `.cf-vtt` is itself + * `position: fixed` with an explicit z-index (`var(--cf-layer-immersive)`, 41) — a stacking + * context. Per the CSS painting model a stacking context's whole subtree paints as ONE + * atomic unit against its context's siblings; a descendant's own z-index is compared only + * against its co-descendants, never against something outside the context. So `.cf-vtt` + * (41) already outranks `.cf-tabbar` (40) before the toast's local "40" enters the picture + * at all. + * + * That is a claim about actual rendering, not source text, so it is proved here by + * measurement rather than by re-reading the CSS (see AGENTS.md and this issue's own + * caution against reasoning-only conclusions on this codebase). Triggering the toast for + * real requires a live cross-session death-save roll with a spectator viewer, which is out + * of proportion to a CSS stacking question — instead a synthetic element carrying the + * toast's REAL class name (so it picks up the real compiled `.cf-death-save-spectator-toast` + * rule, not a hand-rolled one) is appended as a REAL child of the REAL, live `.cf-vtt` node + * on an actually-rendered encounter page — matching the DOM position + * encounter-cockpit-layout.unit.spec.ts already pins (RunSessionPage's only root is + * ``, whose `{children}` render inside `.cf-vtt` — see + * EncounterVttShell.tsx). `elementFromPoint` then tells us what actually paints on top, + * exactly like dialog-layering.spec.ts does for ConfirmDialog vs. this same tab bar. + */ +import { expect, test } from '@playwright/test'; +import { seed, stateFor } from './seed'; + +test.describe('z-index audit — death-save spectator toast vs. tab bar (issue #2163)', () => { + test.use({ storageState: stateFor('dm'), viewport: { width: 320, height: 720 } }); + + test('the toast’s local z-index:40 never has to beat the tab bar’s — .cf-vtt already does', async ({ page }) => { + const { campaignId } = seed(); + const created = await page.request.post(`/api/v1/campaigns/${campaignId}/encounters`, { + data: { name: '2163 toast-stacking drill', hidden: false }, + }); + expect(created.ok()).toBe(true); + const id = ((await created.json()) as { id: number }).id; + + try { + await page.goto(`/c/${campaignId}/encounters/${id}`); + await expect(page.getByTestId('encounter-vtt-canvas')).toBeVisible(); + await expect(page.locator('.cf-tabbar')).toBeVisible(); + + const result = await page.evaluate(() => { + const vtt = document.querySelector('.cf-vtt') as HTMLElement | null; + const tabbar = document.querySelector('.cf-tabbar') as HTMLElement | null; + if (!vtt || !tabbar) return { ok: false as const, reason: 'missing .cf-vtt or .cf-tabbar' }; + + const tabRect = tabbar.getBoundingClientRect(); + const point = { + x: Math.round(tabRect.left + tabRect.width / 2), + y: Math.round(tabRect.top + tabRect.height / 2), + }; + + // Sanity: without the toast, the point really is the tab bar today (otherwise this + // test would prove nothing about the toast specifically). + const beforeHit = document.elementFromPoint(point.x, point.y); + const tabBarWinsAlready = Boolean(beforeHit?.closest('.cf-tabbar')); + + // The real toast class, appended as a real child of the real .cf-vtt node — same DOM + // position the source has it in (see this file's module doc comment) — directly over + // the tab bar's own hit point. + const toast = document.createElement('div'); + toast.className = 'cf-death-save-spectator-toast'; + toast.setAttribute('data-testid', 'zaudit-2163-injected-toast'); + toast.style.position = 'fixed'; + toast.style.left = `${tabRect.left}px`; + toast.style.top = `${tabRect.top}px`; + toast.style.width = `${tabRect.width}px`; + toast.style.height = `${tabRect.height}px`; + // The real rule also sets `transform: translateX(-50%)` (it's normally centered) and + // a mount animation that drives `transform`/`opacity` for its first 0.3s — CSS + // animations override even inline styles for the properties they animate, so both + // would fight the exact rect set above. Neither affects z-index/stacking (the only + // thing under test), so switch them off to pin the rect precisely. + toast.style.transform = 'none'; + toast.style.animation = 'none'; + vtt.appendChild(toast); + const toastZIndex = getComputedStyle(toast).zIndex; + + const withRealZIndexHit = document.elementFromPoint(point.x, point.y); + const wonWithRealZIndex = withRealZIndexHit === toast; + + // Now strip the toast down to a z-index far BELOW the tab bar's (still non-auto, so + // it still forms its own tiny local stacking context) — if the toast still wins, the + // win cannot be coming from its own number at all; it can only be .cf-vtt's ancestor + // dominance (41 > 40) carrying the whole subtree, which is the actual claim under + // test. + toast.style.zIndex = '1'; + const lowZIndexHit = document.elementFromPoint(point.x, point.y); + const wonWithLowZIndex = lowZIndexHit === toast; + + toast.remove(); + const afterHit = document.elementFromPoint(point.x, point.y); + const tabBarRestored = Boolean(afterHit?.closest('.cf-tabbar')); + + return { + ok: true as const, + tabBarWinsAlready, + toastZIndex, + wonWithRealZIndex, + wonWithLowZIndex, + tabBarRestored, + vttZIndex: getComputedStyle(vtt).zIndex, + tabbarZIndex: getComputedStyle(tabbar).zIndex, + }; + }); + + expect(result.ok, result.ok ? undefined : result.reason).toBe(true); + if (!result.ok) return; + + // Baseline: the tab bar really is on top of that point before the toast exists. + expect(result.tabBarWinsAlready).toBe(true); + // The documented tiers really are 40 (tabbar) vs 41 (immersive) here, not something + // that drifted since the source was last read. + expect(result.tabbarZIndex).toBe('40'); + expect(result.vttZIndex).toBe('41'); + expect(result.toastZIndex).toBe('40'); + + // The actual claim: the toast wins at its real z-index... + expect(result.wonWithRealZIndex, 'toast should paint above the tab bar at its real z-index:40').toBe(true); + // ...and STILL wins even crippled to z-index:1 — proving the win is .cf-vtt's own + // ancestor stacking context (41 > 40), not any property of the toast's local number. + expect(result.wonWithLowZIndex, 'toast should still paint above the tab bar even at z-index:1, because .cf-vtt already dominates .cf-tabbar').toBe(true); + // Cleanup left the page as it found it. + expect(result.tabBarRestored).toBe(true); + } finally { + await page.request.delete(`/api/v1/encounters/${id}`).catch(() => undefined); + } + }); +}); diff --git a/apps/web/e2e/tests/z-index-audit.unit.spec.ts b/apps/web/e2e/tests/z-index-audit.unit.spec.ts new file mode 100644 index 000000000..5b0965adf --- /dev/null +++ b/apps/web/e2e/tests/z-index-audit.unit.spec.ts @@ -0,0 +1,168 @@ +/** + * z-index bypass audit (issue #2163). + * + * #2163 asked which `z-index` sites in `index.css` ACTUALLY bypass the documented overlay + * stacking scale (`--cf-layer-*`, issue #791) — not which ones merely look raw in a text + * grep. A raw literal only "bypasses" the scale if it is compared against the scale's own + * elements in the SAME stacking context; an element nested inside something that already + * establishes its own stacking context (`position` + non-auto `z-index`, `transform`, + * `opacity < 1`, …) has its z-index scoped to that ancestor and can never leak out to + * compete with a sibling of the ancestor, no matter how large the number is. Re-measured on + * the current tree (not the `c44baf05a` snapshot the issue cites), this file has 25 + * `z-index` declarations: + * + * - 9 already consume a `--cf-layer-*` token (or `calc()` over one) — never audited here. + * - 2 are resets (`0`, `auto`) that are not stacking-tier decisions. + * - 14 are raw literals, enumerated and classified below. Every one of them turned out to + * be genuinely LOCAL once its containing stacking context was traced — INCLUDING the two + * sites #2163 itself flagged as "plausible real drift" + * (`.cf-death-save-spectator-toast`, `.cf-gated-hint`). See each one's note below and, + * for the toast, the live measurement in `z-index-audit-toast-stacking.spec.ts` that + * proves the containment rather than just reading it off the source. + * + * This is the "guard test scoped to whatever the audit concludes" #2163 asked for. It is + * deliberately narrower than "no raw z-index outside the documented scale" — that blanket + * rule would incorrectly flag the VTT cockpit's own legitimate local nesting order (issue's + * own words). Instead it pins the EXACT audited set: a new raw z-index declaration, or a + * changed value on an existing one, fails this test and forces a conscious reclassification + * rather than silently landing outside the audit. + */ +import { expect, test } from '@playwright/test'; +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; + +const INDEX_CSS = resolve(__dirname, '../../src/index.css'); + +/** One `selector { … z-index: value; … }` rule's immediate selector and z-index value. */ +interface Declaration { + selector: string; + value: string; +} + +/** Every `z-index` declaration in `index.css`, in source order, with its rule's selector. */ +function allZIndexDeclarations(css: string): Declaration[] { + const out: Declaration[] = []; + const ruleRe = /([^{}]+)\{([^{}]*)\}/g; + let m: RegExpExecArray | null; + while ((m = ruleRe.exec(css))) { + const [, rawSelector, body] = m; + const selector = rawSelector.trim().split('\n').pop()!.trim(); + for (const zm of body.matchAll(/z-index:\s*([^;]+);/g)) { + out.push({ selector, value: zm[1].trim() }); + } + } + return out; +} + +const TOKEN_RE = /var\(--cf-layer-/; + +/** + * The 14 raw (non-token, non-reset) z-index literals as re-measured on the current tree, + * each with why it is genuinely local rather than a scale bypass. Order matches source order. + */ +const AUDITED_RAW_LITERALS: Array = [ + { + selector: '.cf-authed-shell', + value: '1', + note: 'Lifts the whole app shell just above the decorative .cf-ember-layer (z:0) background. This IS the ancestor stacking context every documented tier (chrome, tabbar, immersive, …) nests inside — infrastructure, not a scale participant.', + }, + { + selector: '.cf-campaign-cover__content', + value: '1', + note: 'Lifts cover text above its own texture/overlay decorative layers within the same small card. No documented tier is anywhere nearby.', + }, + { + selector: '.cf-death-save-spectator-toast', + value: '40', + note: 'Renders only as a child passed to EncounterVttShell (RunSessionPage’s sole root, see encounter-cockpit-layout.unit.spec.ts), i.e. inside .cf-vtt, which is itself position:fixed with an explicit z-index (var(--cf-layer-immersive), 41) — a stacking context. The toast’s local "40" is compared only against its .cf-vtt siblings, never against --cf-layer-tabbar’s "40": the whole .cf-vtt subtree already paints atomically above the tab bar (41 > 40). The numeric coincidence with the tabbar tier is a documentation smell, not a functional bypass — verified live in z-index-audit-toast-stacking.spec.ts.', + }, + { + selector: '.cf-gated-hint', + value: '30', + note: 'GatedControl is used only inside the encounter cockpit (nested in .cf-vtt) and DeathSaveTracker on the character sheet (nested directly in .cf-authed-shell). In both places it never exceeds the "chrome" ceiling it happens to number-match (Tailwind z-30) — it stays at or below every documented tier. The one case that truly needs to outrank the immersive surface — .cf-gated-hint--escaped, portaled to once it leaves a clipping ancestor — already migrates onto calc(var(--cf-layer-immersive, 41) + 1).', + }, + { + selector: '.cf-hp-feedback', + value: '20', + note: 'Transient floating HP delta over one combatant row (issue #1907). Below the lowest documented tier (chrome, 30) regardless of context, so it can never compete with the scale even in the worst case.', + }, + { + selector: '.cf-vtt-header', + value: '20', + note: 'A grid item ordered among .cf-vtt’s own header/banners/body/children siblings, entirely inside .cf-vtt’s own local stacking context (41). Never compared to anything outside it.', + }, + { selector: '.cf-vtt-panel-reopen', value: '12', note: 'VTT cockpit local nesting order (issue #2163 body) — the side-panel reopen tab.' }, + { selector: '.cf-vtt-strip', value: '9', note: 'VTT cockpit local nesting order (issue #2163 body) — the mobile turn strip.' }, + { selector: '.cf-vtt-strip-toggle', value: '2', note: 'VTT cockpit local nesting order (issue #2163 body) — must sit above the strip it opens.' }, + { selector: '.cf-vtt-fab', value: '14', note: 'VTT cockpit local nesting order (issue #2163 body) — the floating roll button.' }, + { selector: '.cf-vtt-tray', value: '13', note: 'VTT cockpit local nesting order (issue #2163 body) — the dice tray.' }, + { selector: '.cf-vtt-map .cf-vtt-rail', value: '10', note: 'VTT cockpit local nesting order (issue #2163 body) — the map tool rail.' }, + { selector: '.cf-vtt-map .cf-vtt-map-tray', value: '8', note: 'VTT cockpit local nesting order (issue #2163 body) — the floating token tray.' }, + { selector: ".cf-vtt-map [data-testid='map-viewport-toolbar']", value: '9', note: 'VTT cockpit local nesting order (issue #2163 body) — the viewport toolbar.' }, +]; + +/** The 2 declarations that reset stacking rather than choose a tier — not stacking decisions. */ +const AUDITED_RESETS: Declaration[] = [ + { selector: '.cf-ember-layer', value: '0' }, + { selector: '.cf-vtt', value: 'auto' }, // print-media override; the live rule is the tokenized one below. +]; + +test.describe('z-index bypass audit (issue #2163)', () => { + test('every raw z-index literal in index.css is one of the 14 audited local-context sites', () => { + const css = readFileSync(INDEX_CSS, 'utf8'); + const declarations = allZIndexDeclarations(css); + + const tokenized = declarations.filter((d) => TOKEN_RE.test(d.value)); + const resets = declarations.filter((d) => !TOKEN_RE.test(d.value) && (d.value === '0' || d.value === 'auto')); + const raw = declarations.filter((d) => !TOKEN_RE.test(d.value) && d.value !== '0' && d.value !== 'auto'); + + // Re-measured counts (see the module doc comment) — a change here means the inventory + // itself moved and needs re-auditing, not that this test's numbers should just follow. + expect(declarations, 'total z-index declarations in index.css').toHaveLength(25); + expect(tokenized, 'declarations already consuming a --cf-layer-* token').toHaveLength(9); + expect(resets, 'z-index:0 / z-index:auto resets').toHaveLength(2); + expect(raw, 'raw literal z-index declarations').toHaveLength(AUDITED_RAW_LITERALS.length); + + for (const reset of AUDITED_RESETS) { + expect(resets, `expected reset ${reset.selector} { z-index: ${reset.value} }`).toContainEqual(reset); + } + + // Every raw literal must be exactly one of the audited (selector, value) pairs. A new + // raw z-index — or a changed value on an existing one — fails here rather than silently + // landing outside the audit. + const audited = new Set(AUDITED_RAW_LITERALS.map((d) => `${d.selector} :: ${d.value}`)); + for (const d of raw) { + expect(audited.has(`${d.selector} :: ${d.value}`), `unaudited raw z-index: ${d.selector} { z-index: ${d.value} } — classify it (see this file's module doc comment) and add it to AUDITED_RAW_LITERALS, or migrate it onto the matching --cf-layer-* token if it actually competes with the documented scale`).toBe(true); + } + // And the reverse: every audited site must still exist with its audited value, so a + // literal that quietly migrates onto a token (good!) also has to update this list. + for (const d of AUDITED_RAW_LITERALS) { + expect(raw, `expected still-local site ${d.selector} { z-index: ${d.value} }`).toContainEqual({ selector: d.selector, value: d.value }); + } + }); + + test('.cf-vtt is a real stacking context, not just position:fixed', () => { + // encounter-cockpit-layout.unit.spec.ts already pins position:fixed + inset:0 on this + // block; this pins the other half of what makes it a stacking context (a non-auto + // z-index), which is the mechanism every "local literal nested in .cf-vtt" note above + // depends on. + const css = readFileSync(INDEX_CSS, 'utf8'); + const block = css.slice(css.indexOf('.cf-vtt {'), css.indexOf('.cf-vtt-header {')); + expect(block).toMatch(/z-index:\s*var\(--cf-layer-immersive\);/); + }); + + test('.cf-gated-hint--escaped migrates onto the immersive token once it leaves its trigger’s context', () => { + const gatedControl = readFileSync( + resolve(__dirname, '../../src/components/GatedControl.tsx'), + 'utf8', + ); + // The base (non-escaped) hint's "30" never needs to beat --cf-layer-immersive (41) — it + // is only the escaped, body-portaled copy that does, and that copy already tokenizes. + expect(gatedControl).toMatch(/createPortal\(hintNode, document\.body\)/); + + const css = readFileSync(INDEX_CSS, 'utf8'); + expect(css).toMatch( + /\.cf-gated-hint--escaped\s*\{\s*z-index:\s*calc\(var\(--cf-layer-immersive,\s*41\)\s*\+\s*1\);/, + ); + }); +}); From d6d481558ad292d4cb3cabbdeaa156c54ddd4ac5 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 11 Aug 2026 01:38:31 +0000 Subject: [PATCH 2/8] fix(web): correct false stacking-context baseline in z-index audit spec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI caught a harness defect on the first push: the spec asserted the tab bar wins hit-testing at its own point BEFORE the toast is injected, but that baseline is false on the encounter run page — .cf-vtt (position:fixed; inset:0) already covers the entire viewport, including the tab bar's coordinates, regardless of the toast. The tab bar is never hit-testable under an open cockpit, toast or no toast, so the "before" comparison compared the wrong two states. Fix: move the "tab bar really does win over ordinary content" control to a non-cockpit page (/party) where it is actually true, proving the elementFromPoint technique and the tab bar's real dominance are both genuine. The encounter-page test now measures the real claim directly, with no injection required — .cf-vtt itself already wins at the tab bar's point — then keeps the real-toast-class injection as further, more specific confirmation (real z-index:40 lands correctly; crippled to z-index:1 still wins, isolating the win to .cf-vtt's ancestor dominance rather than the toast's own number). Diagnostic tag/className are now returned alongside each hit so a future failure is self-diagnosing. The underlying CSS classification (0 real bypasses) is unaffected — this was a false premise in the test's own baseline, not a wrong conclusion about the source. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LjFox1SZv765yv918tLJrh --- .../z-index-audit-toast-stacking.spec.ts | 118 ++++++++++++------ 1 file changed, 82 insertions(+), 36 deletions(-) diff --git a/apps/web/e2e/tests/z-index-audit-toast-stacking.spec.ts b/apps/web/e2e/tests/z-index-audit-toast-stacking.spec.ts index 74be97aac..bde4f3961 100644 --- a/apps/web/e2e/tests/z-index-audit-toast-stacking.spec.ts +++ b/apps/web/e2e/tests/z-index-audit-toast-stacking.spec.ts @@ -5,22 +5,31 @@ * * z-index-audit.unit.spec.ts explains, from the source, why this is not actually a scale * bypass: the toast only ever renders as a child of `.cf-vtt`, and `.cf-vtt` is itself - * `position: fixed` with an explicit z-index (`var(--cf-layer-immersive)`, 41) — a stacking - * context. Per the CSS painting model a stacking context's whole subtree paints as ONE - * atomic unit against its context's siblings; a descendant's own z-index is compared only - * against its co-descendants, never against something outside the context. So `.cf-vtt` - * (41) already outranks `.cf-tabbar` (40) before the toast's local "40" enters the picture - * at all. + * `position: fixed; inset: 0` with an explicit z-index (`var(--cf-layer-immersive)`, 41) — a + * stacking context that covers the FULL viewport. Per the CSS painting model a stacking + * context's whole subtree paints as ONE atomic unit against its context's siblings; a + * descendant's own z-index is compared only against its co-descendants, never against + * something outside the context. So `.cf-vtt` (41) already outranks `.cf-tabbar` (40) + * EVERYWHERE in the viewport, including at the tab bar's own coordinates, before the toast's + * local "40" enters the picture at all — the tab bar is never hit-testable anywhere under an + * open cockpit, toast or no toast. * - * That is a claim about actual rendering, not source text, so it is proved here by - * measurement rather than by re-reading the CSS (see AGENTS.md and this issue's own - * caution against reasoning-only conclusions on this codebase). Triggering the toast for - * real requires a live cross-session death-save roll with a spectator viewer, which is out - * of proportion to a CSS stacking question — instead a synthetic element carrying the - * toast's REAL class name (so it picks up the real compiled `.cf-death-save-spectator-toast` - * rule, not a hand-rolled one) is appended as a REAL child of the REAL, live `.cf-vtt` node - * on an actually-rendered encounter page — matching the DOM position - * encounter-cockpit-layout.unit.spec.ts already pins (RunSessionPage's only root is + * CI caught exactly this on the first version of this spec: it asserted a "before" baseline + * of "the tab bar wins at that point without the toast", which is false ON THIS PAGE — the + * cockpit already covers it regardless. That was a harness defect (a false premise about + * where the control should live), not a wrong claim about the CSS: `control:` below moves the + * "the tab bar really does win over ordinary content" check to an ordinary, non-cockpit page + * where it is actually true (proving the measurement technique and the tab bar's real + * dominance are both genuine), and the encounter-page test then measures the real claim + * directly — .cf-vtt beats .cf-tabbar with no injection required — before using the same real + * toast class as further, more specific confirmation. + * + * Triggering the toast for real requires a live cross-session death-save roll with a + * spectator viewer, which is out of proportion to a CSS stacking question — instead a + * synthetic element carrying the toast's REAL class name (so it picks up the real compiled + * `.cf-death-save-spectator-toast` rule, not a hand-rolled one) is appended as a REAL child of + * the REAL, live `.cf-vtt` node on an actually-rendered encounter page — matching the DOM + * position encounter-cockpit-layout.unit.spec.ts already pins (RunSessionPage's only root is * ``, whose `{children}` render inside `.cf-vtt` — see * EncounterVttShell.tsx). `elementFromPoint` then tells us what actually paints on top, * exactly like dialog-layering.spec.ts does for ConfirmDialog vs. this same tab bar. @@ -31,6 +40,31 @@ import { seed, stateFor } from './seed'; test.describe('z-index audit — death-save spectator toast vs. tab bar (issue #2163)', () => { test.use({ storageState: stateFor('dm'), viewport: { width: 320, height: 720 } }); + test('control: the tab bar really does win over ordinary page content at 320px', async ({ page }) => { + // No cockpit on this route — proves the elementFromPoint technique below is meaningful, + // not vacuously true because nothing else was ever in the running. + const { campaignId } = seed(); + await page.goto(`/c/${campaignId}/party`); + await expect(page.locator('.cf-tabbar')).toBeVisible(); + + const hit = await page.evaluate(() => { + const tabbar = document.querySelector('.cf-tabbar') as HTMLElement | null; + if (!tabbar) return { ok: false as const, reason: 'missing .cf-tabbar' }; + const r = tabbar.getBoundingClientRect(); + const el = document.elementFromPoint(Math.round(r.left + r.width / 2), Math.round(r.top + r.height / 2)); + return { + ok: true as const, + inTabbar: Boolean(el?.closest('.cf-tabbar')), + tag: el?.tagName ?? null, + className: el instanceof HTMLElement ? el.className : null, + }; + }); + + expect(hit.ok, hit.ok ? undefined : hit.reason).toBe(true); + if (!hit.ok) return; + expect(hit, JSON.stringify(hit)).toMatchObject({ inTabbar: true }); + }); + test('the toast’s local z-index:40 never has to beat the tab bar’s — .cf-vtt already does', async ({ page }) => { const { campaignId } = seed(); const created = await page.request.post(`/api/v1/campaigns/${campaignId}/encounters`, { @@ -45,6 +79,13 @@ test.describe('z-index audit — death-save spectator toast vs. tab bar (issue # await expect(page.locator('.cf-tabbar')).toBeVisible(); const result = await page.evaluate(() => { + const describe = (el: Element | null) => ({ + inVtt: Boolean(el?.closest('.cf-vtt')), + inTabbar: Boolean(el?.closest('.cf-tabbar')), + tag: el?.tagName ?? null, + className: el instanceof HTMLElement ? el.className : null, + }); + const vtt = document.querySelector('.cf-vtt') as HTMLElement | null; const tabbar = document.querySelector('.cf-tabbar') as HTMLElement | null; if (!vtt || !tabbar) return { ok: false as const, reason: 'missing .cf-vtt or .cf-tabbar' }; @@ -55,14 +96,15 @@ test.describe('z-index audit — death-save spectator toast vs. tab bar (issue # y: Math.round(tabRect.top + tabRect.height / 2), }; - // Sanity: without the toast, the point really is the tab bar today (otherwise this - // test would prove nothing about the toast specifically). - const beforeHit = document.elementFromPoint(point.x, point.y); - const tabBarWinsAlready = Boolean(beforeHit?.closest('.cf-tabbar')); + // The actual claim, measured directly with no injection: the cockpit itself — not + // any particular descendant's z-index — already wins at the tab bar's own point, + // because .cf-vtt (41) dominates .cf-tabbar (40) as a whole atomic subtree. + const beforeHit = describe(document.elementFromPoint(point.x, point.y)); - // The real toast class, appended as a real child of the real .cf-vtt node — same DOM - // position the source has it in (see this file's module doc comment) — directly over - // the tab bar's own hit point. + // Further, more specific confirmation: the real toast class, appended as a real + // child of the real .cf-vtt node — same DOM position the source has it in (see this + // file's module doc comment) — directly over the tab bar's own hit point, paints + // correctly there too. const toast = document.createElement('div'); toast.className = 'cf-death-save-spectator-toast'; toast.setAttribute('data-testid', 'zaudit-2163-injected-toast'); @@ -87,23 +129,21 @@ test.describe('z-index audit — death-save spectator toast vs. tab bar (issue # // Now strip the toast down to a z-index far BELOW the tab bar's (still non-auto, so // it still forms its own tiny local stacking context) — if the toast still wins, the // win cannot be coming from its own number at all; it can only be .cf-vtt's ancestor - // dominance (41 > 40) carrying the whole subtree, which is the actual claim under - // test. + // dominance carrying the whole subtree, which is the actual claim under test. toast.style.zIndex = '1'; const lowZIndexHit = document.elementFromPoint(point.x, point.y); const wonWithLowZIndex = lowZIndexHit === toast; toast.remove(); - const afterHit = document.elementFromPoint(point.x, point.y); - const tabBarRestored = Boolean(afterHit?.closest('.cf-tabbar')); + const afterHit = describe(document.elementFromPoint(point.x, point.y)); return { ok: true as const, - tabBarWinsAlready, + beforeHit, toastZIndex, wonWithRealZIndex, wonWithLowZIndex, - tabBarRestored, + afterHit, vttZIndex: getComputedStyle(vtt).zIndex, tabbarZIndex: getComputedStyle(tabbar).zIndex, }; @@ -112,21 +152,27 @@ test.describe('z-index audit — death-save spectator toast vs. tab bar (issue # expect(result.ok, result.ok ? undefined : result.reason).toBe(true); if (!result.ok) return; - // Baseline: the tab bar really is on top of that point before the toast exists. - expect(result.tabBarWinsAlready).toBe(true); // The documented tiers really are 40 (tabbar) vs 41 (immersive) here, not something // that drifted since the source was last read. expect(result.tabbarZIndex).toBe('40'); expect(result.vttZIndex).toBe('41'); expect(result.toastZIndex).toBe('40'); - // The actual claim: the toast wins at its real z-index... + // The core claim, measured with no injection at all: .cf-vtt already wins at the tab + // bar's own point, everywhere, because it's a full-viewport stacking context that + // outranks .cf-tabbar's. The tab bar is genuinely never hit-testable under an open + // cockpit — matching the CSS comment's "above the tab bar ... it replaces". + expect(result.beforeHit, JSON.stringify(result.beforeHit)).toMatchObject({ inVtt: true, inTabbar: false }); + + // Further confirmation: the toast specifically — not just some other .cf-vtt + // descendant — paints there too, at its real z-index... expect(result.wonWithRealZIndex, 'toast should paint above the tab bar at its real z-index:40').toBe(true); - // ...and STILL wins even crippled to z-index:1 — proving the win is .cf-vtt's own - // ancestor stacking context (41 > 40), not any property of the toast's local number. - expect(result.wonWithLowZIndex, 'toast should still paint above the tab bar even at z-index:1, because .cf-vtt already dominates .cf-tabbar').toBe(true); - // Cleanup left the page as it found it. - expect(result.tabBarRestored).toBe(true); + // ...and STILL wins even crippled to z-index:1 — proving the toast's own local number + // is not load-bearing for it to be visible; whatever wins at that point inside .cf-vtt + // does so because it's inside .cf-vtt; ancestor dominance, not local value. + expect(result.wonWithLowZIndex, 'toast should still paint above the tab bar even at z-index:1').toBe(true); + // Cleanup left the page as it found it — still .cf-vtt, never the tab bar. + expect(result.afterHit, JSON.stringify(result.afterHit)).toMatchObject({ inVtt: true, inTabbar: false }); } finally { await page.request.delete(`/api/v1/encounters/${id}`).catch(() => undefined); } From a60a473ec2b7e7002567534c85a37313bd4f4975 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 11 Aug 2026 12:05:14 +0000 Subject: [PATCH 3/8] fix(web): correct .cf-gated-hint bypass Codex's review found on #2202 Codex's review of #2202 caught a real classification error, not a nitpick: the audit whitelisted `.cf-gated-hint` as local on an incomplete render-site enumeration. `GatedControl` is also used by `DiceTray`'s advantage/ disadvantage toggle, and `SharedDiceLog` mounts `DiceTray` on the plain Dashboard (`DiceWidget`) and the character sheet -- neither wrapped in `.cf-vtt` or any other stacking-context-establishing ancestor. There the hint sat directly in `.cf-authed-shell`, the SAME local context Layout's sticky mobile header (Tailwind `z-30`) does, and the hint's literal `30` was an exact tie with it -- decided only by DOM order (the hint always renders later), so it really could paint over chrome by coincidence rather than by the documented scale. This also invalidated the DeathSaveTracker half of the original classification, which made the same "never exceeds the ceiling" mistake without checking the tie-break. Fix: reuse the existing `--cf-layer-immersive` token (already used by `.cf-gated-hint--escaped` for the identical "must clear ordinary page chrome" reason) on the base rule too, so the hint deterministically outranks chrome instead of merely tying with it. No new token invented, no JS/portal logic touched -- the smallest change that closes the gap. z-index-audit-gated-hint-stacking.spec.ts proves this live. It cannot use elementFromPoint (the technique z-index-audit-toast-stacking.spec.ts uses) because .cf-gated-hint is pointer-events:none and the CSSOM View spec skips such elements during hit-testing entirely -- using it here would silently prove nothing. Instead it measures that the hint and the sticky header share one stacking-context ancestor (walking the DOM checking MDN's stacking-context triggers, live) before comparing their z-index numbers, which is the specific thing that makes a bare number comparison valid. z-index-audit.unit.spec.ts's guard is updated: 10 tokenized (was 9), 13 raw literals (was 14) -- .cf-gated-hint moved out of the "confirmed local" whitelist since it no longer belongs there. Verified exhaustively that no OTHER GatedControl call site has the same gap: TurnWorkspace, BattleMap, GroupActionRunner, ActionUseFlow, CombatantRow, DmLifecycleHeader, and RunSessionPage's own direct usage all resolve only to RunSessionPage (cockpit, .cf-vtt-nested) or PlayerDisplayPage (mounted outside Layout entirely -- no chrome tier exists there to compete with, by the router's own design). Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LjFox1SZv765yv918tLJrh --- .../z-index-audit-gated-hint-stacking.spec.ts | 127 ++++++++++++++++++ apps/web/e2e/tests/z-index-audit.unit.spec.ts | 67 ++++++--- apps/web/src/index.css | 21 ++- 3 files changed, 190 insertions(+), 25 deletions(-) create mode 100644 apps/web/e2e/tests/z-index-audit-gated-hint-stacking.spec.ts diff --git a/apps/web/e2e/tests/z-index-audit-gated-hint-stacking.spec.ts b/apps/web/e2e/tests/z-index-audit-gated-hint-stacking.spec.ts new file mode 100644 index 000000000..7ec085522 --- /dev/null +++ b/apps/web/e2e/tests/z-index-audit-gated-hint-stacking.spec.ts @@ -0,0 +1,127 @@ +/** + * Live stacking proof for the `.cf-gated-hint` bypass Codex's review found in #2202 + * (originally filed under issue #2163). + * + * The base (non-escaped) `.cf-gated-hint` rule is not cockpit-only: `GatedControl` is also + * used by `DiceTray`'s advantage/disadvantage toggle, which `SharedDiceLog` mounts on the + * plain Dashboard (`DiceWidget`) and the character sheet — neither wrapped in `.cf-vtt` or + * any other stacking-context-establishing ancestor. There the hint sits directly inside + * `.cf-authed-shell`, the SAME local stacking context Layout's sticky mobile header (Tailwind + * `z-30`) does. Before this fix the hint's own `z-index` was the literal `30` — an exact tie + * with the header, decided only by DOM order (the hint always renders later), so it could + * paint over chrome by coincidence rather than by the documented scale. The fix reuses the + * existing `--cf-layer-immersive` token (already used by `.cf-gated-hint--escaped` for the + * identical "must clear ordinary page chrome" reason) so the hint deterministically outranks + * chrome instead of merely tying with it. + * + * `elementFromPoint` — the technique z-index-audit-toast-stacking.spec.ts uses — does NOT + * work here: `.cf-gated-hint` is `pointer-events: none` (it's `role="presentation" + * aria-hidden="true"`, decorative only), and per the CSSOM View spec `elementFromPoint` skips + * `pointer-events: none` elements entirely, falling through to whatever is beneath them + * regardless of paint order. Using it would silently prove nothing. Instead this test proves + * the two conditions that make a bare z-index comparison meaningful in the first place — + * measured live, not assumed: + * + * 1. The hint and the header share the same nearest stacking-context-establishing + * ancestor (`.cf-authed-shell`) — i.e. nothing between either of them and that ancestor + * is itself positioned+z-indexed, transformed, filtered, less-than-fully-opaque, + * isolated, or contained, per MDN's stacking-context trigger list. If that were false, + * comparing their z-index numbers would be exactly the trap this issue is about. + * 2. Given (1) holds, the hint's computed z-index now genuinely exceeds the header's — + * not tied, not smaller — so the win is deterministic regardless of DOM order. + */ +import { expect, test } from '@playwright/test'; +import { seed, stateFor } from './seed'; + +test.describe('z-index audit — gated hint vs. sticky header on the dashboard (issue #2163 review)', () => { + test.use({ storageState: stateFor('dm'), viewport: { width: 320, height: 720 } }); + + test('the dashboard dice tray’s advantage hint now outranks the sticky header, not just ties it', async ({ + page, + }) => { + const { campaignId } = seed(); + await page.goto(`/c/${campaignId}`); + + // Gate the Advantage toggle: `advAvailable` is true for an empty pool or a lone d20, so a + // single d6 (neither) is enough to make the toggle disabled-with-reason. + const addD6 = page.getByRole('button', { name: 'Add a d6' }); + await expect(addD6).toBeVisible(); + await addD6.click(); + + const advantage = page.getByRole('button', { name: 'Advantage' }); + await expect(advantage).toBeDisabled(); + await advantage.focus(); + const hint = page.getByTestId('gated-control-hint').first(); + await expect(hint).toBeVisible(); + await expect(hint).toHaveText('Advantage and disadvantage only apply to a single d20 roll.'); + + const header = page.locator('header').first(); + await expect(header).toBeVisible(); + + const result = await page.evaluate(() => { + // MDN's stacking-context trigger list (also this issue's own definition): a positioned + // element with a non-auto z-index, position:fixed/sticky, opacity<1, a transform, + // filter/backdrop-filter, will-change naming one of those, isolation:isolate, or a + // paint/layout/strict/content containment. + function establishesStackingContext(node: Element): boolean { + const cs = getComputedStyle(node); + if (cs.position !== 'static' && cs.zIndex !== 'auto') return true; + if (cs.position === 'fixed' || cs.position === 'sticky') return true; + if (Number(cs.opacity) < 1) return true; + if (cs.transform !== 'none') return true; + if (cs.filter !== 'none') return true; + if (cs.backdropFilter && cs.backdropFilter !== 'none') return true; + if (cs.isolation === 'isolate') return true; + if (cs.willChange && /transform|opacity|filter/.test(cs.willChange)) return true; + if (cs.contain && /paint|layout|strict|content/.test(cs.contain)) return true; + return false; + } + + /** Nearest ancestor (inclusive of a starting non-context-establishing node's parents, + * not the node itself) that establishes a stacking context, or null if none does before + * the document root. */ + function nearestStackingContextAncestor(el: Element): Element | null { + let node: Element | null = el.parentElement; + while (node) { + if (establishesStackingContext(node)) return node; + node = node.parentElement; + } + return null; + } + + const hintEl = document.querySelector('[data-testid="gated-control-hint"]'); + const headerEl = document.querySelector('header'); + if (!hintEl || !headerEl) return { ok: false as const, reason: 'missing hint or header' }; + + const hintContext = nearestStackingContextAncestor(hintEl); + const headerContext = nearestStackingContextAncestor(headerEl); + + return { + ok: true as const, + sameContext: hintContext !== null && hintContext === headerContext, + contextClass: hintContext instanceof HTMLElement ? hintContext.className : null, + hintZIndex: getComputedStyle(hintEl).zIndex, + headerZIndex: getComputedStyle(headerEl).zIndex, + hintPointerEvents: getComputedStyle(hintEl).pointerEvents, + }; + }); + + expect(result.ok, result.ok ? undefined : result.reason).toBe(true); + if (!result.ok) return; + + // Confirms this element really is pointer-events:none, i.e. that elementFromPoint would + // NOT be a valid way to check this — see the module doc comment. + expect(result.hintPointerEvents).toBe('none'); + + // The comparison below is only meaningful if this holds — otherwise the hint and the + // header could each be capped by a DIFFERENT ancestor context, and comparing their raw + // numbers would be exactly the trap issue #2163 is about. + expect(result.sameContext, `hint and header must share one stacking-context ancestor; found ${result.contextClass}`).toBe(true); + expect(result.contextClass).toContain('cf-authed-shell'); + + // The actual fix: no longer a 30/30 tie decided by DOM order — the hint's token-based + // value genuinely exceeds the header's now. + expect(result.headerZIndex).toBe('30'); + expect(Number(result.hintZIndex)).toBeGreaterThan(Number(result.headerZIndex)); + }); +}); diff --git a/apps/web/e2e/tests/z-index-audit.unit.spec.ts b/apps/web/e2e/tests/z-index-audit.unit.spec.ts index 5b0965adf..95198e612 100644 --- a/apps/web/e2e/tests/z-index-audit.unit.spec.ts +++ b/apps/web/e2e/tests/z-index-audit.unit.spec.ts @@ -7,18 +7,37 @@ * elements in the SAME stacking context; an element nested inside something that already * establishes its own stacking context (`position` + non-auto `z-index`, `transform`, * `opacity < 1`, …) has its z-index scoped to that ancestor and can never leak out to - * compete with a sibling of the ancestor, no matter how large the number is. Re-measured on - * the current tree (not the `c44baf05a` snapshot the issue cites), this file has 25 - * `z-index` declarations: + * compete with a sibling of the ancestor, no matter how large the number is. * - * - 9 already consume a `--cf-layer-*` token (or `calc()` over one) — never audited here. + * PR #2202 review (Codex): the first version of this audit whitelisted `.cf-gated-hint` + * (base, non-escaped) as local on the strength of an incomplete render-site enumeration — it + * traced `GatedControl` only through the encounter cockpit and `DeathSaveTracker`, and missed + * that `DiceTray`'s advantage/disadvantage toggle also uses `GatedControl`, and that + * `SharedDiceLog` mounts `DiceTray` on the plain Dashboard (`DiceWidget`) and the character + * sheet — neither wrapped in `.cf-vtt` or any other stacking-context-establishing ancestor. + * There the hint sits directly in `.cf-authed-shell`, the SAME local context Layout's sticky + * mobile header (Tailwind `z-30`) does, and the hint's old literal `30` was an exact TIE with + * it — decided only by DOM order (the hint always renders later), so it really could paint + * over chrome by coincidence. That was a genuine bypass, now fixed in index.css by reusing + * the existing `--cf-layer-immersive` token (already used by `.cf-gated-hint--escaped` for + * the identical "must clear ordinary page chrome" reason) on the base rule too — see + * `z-index-audit-gated-hint-stacking.spec.ts` for the live proof, which does NOT use + * `elementFromPoint` (the hint is `pointer-events: none`, so hit-testing would silently skip + * it) and instead measures that the hint and header share one stacking-context ancestor + * before comparing their z-index numbers. + * + * Re-measured on the current tree (not the `c44baf05a` snapshot the issue cites, nor the + * pre-fix count from this file's own first version), index.css has 25 `z-index` + * declarations: + * + * - 10 already consume a `--cf-layer-*` token (or `calc()` over one) — never audited here. * - 2 are resets (`0`, `auto`) that are not stacking-tier decisions. - * - 14 are raw literals, enumerated and classified below. Every one of them turned out to - * be genuinely LOCAL once its containing stacking context was traced — INCLUDING the two - * sites #2163 itself flagged as "plausible real drift" - * (`.cf-death-save-spectator-toast`, `.cf-gated-hint`). See each one's note below and, - * for the toast, the live measurement in `z-index-audit-toast-stacking.spec.ts` that - * proves the containment rather than just reading it off the source. + * - 13 are raw literals, enumerated and classified below. Every one of the remaining 13 + * turned out to be genuinely LOCAL once its containing stacking context was traced — + * including `.cf-death-save-spectator-toast`, the other site #2163 flagged as "plausible + * real drift" (see its note below and the live measurement in + * `z-index-audit-toast-stacking.spec.ts`, which proves the containment rather than just + * reading it off the source). * * This is the "guard test scoped to whatever the audit concludes" #2163 asked for. It is * deliberately narrower than "no raw z-index outside the documented scale" — that blanket @@ -57,8 +76,12 @@ function allZIndexDeclarations(css: string): Declaration[] { const TOKEN_RE = /var\(--cf-layer-/; /** - * The 14 raw (non-token, non-reset) z-index literals as re-measured on the current tree, + * The 13 raw (non-token, non-reset) z-index literals as re-measured on the current tree, * each with why it is genuinely local rather than a scale bypass. Order matches source order. + * + * `.cf-gated-hint` is deliberately NOT here — it was in the first version of this list + * (whitelisted as local) and that was wrong; see the module doc comment. It now consumes + * --cf-layer-immersive and is covered by the ".cf-gated-hint--escaped" test below instead. */ const AUDITED_RAW_LITERALS: Array = [ { @@ -76,11 +99,6 @@ const AUDITED_RAW_LITERALS: Array = [ value: '40', note: 'Renders only as a child passed to EncounterVttShell (RunSessionPage’s sole root, see encounter-cockpit-layout.unit.spec.ts), i.e. inside .cf-vtt, which is itself position:fixed with an explicit z-index (var(--cf-layer-immersive), 41) — a stacking context. The toast’s local "40" is compared only against its .cf-vtt siblings, never against --cf-layer-tabbar’s "40": the whole .cf-vtt subtree already paints atomically above the tab bar (41 > 40). The numeric coincidence with the tabbar tier is a documentation smell, not a functional bypass — verified live in z-index-audit-toast-stacking.spec.ts.', }, - { - selector: '.cf-gated-hint', - value: '30', - note: 'GatedControl is used only inside the encounter cockpit (nested in .cf-vtt) and DeathSaveTracker on the character sheet (nested directly in .cf-authed-shell). In both places it never exceeds the "chrome" ceiling it happens to number-match (Tailwind z-30) — it stays at or below every documented tier. The one case that truly needs to outrank the immersive surface — .cf-gated-hint--escaped, portaled to once it leaves a clipping ancestor — already migrates onto calc(var(--cf-layer-immersive, 41) + 1).', - }, { selector: '.cf-hp-feedback', value: '20', @@ -108,7 +126,7 @@ const AUDITED_RESETS: Declaration[] = [ ]; test.describe('z-index bypass audit (issue #2163)', () => { - test('every raw z-index literal in index.css is one of the 14 audited local-context sites', () => { + test('every raw z-index literal in index.css is one of the 13 audited local-context sites', () => { const css = readFileSync(INDEX_CSS, 'utf8'); const declarations = allZIndexDeclarations(css); @@ -119,7 +137,7 @@ test.describe('z-index bypass audit (issue #2163)', () => { // Re-measured counts (see the module doc comment) — a change here means the inventory // itself moved and needs re-auditing, not that this test's numbers should just follow. expect(declarations, 'total z-index declarations in index.css').toHaveLength(25); - expect(tokenized, 'declarations already consuming a --cf-layer-* token').toHaveLength(9); + expect(tokenized, 'declarations already consuming a --cf-layer-* token').toHaveLength(10); expect(resets, 'z-index:0 / z-index:auto resets').toHaveLength(2); expect(raw, 'raw literal z-index declarations').toHaveLength(AUDITED_RAW_LITERALS.length); @@ -151,16 +169,23 @@ test.describe('z-index bypass audit (issue #2163)', () => { expect(block).toMatch(/z-index:\s*var\(--cf-layer-immersive\);/); }); - test('.cf-gated-hint--escaped migrates onto the immersive token once it leaves its trigger’s context', () => { + test('.cf-gated-hint and .cf-gated-hint--escaped both consume the immersive token (issue #2163 review fix)', () => { const gatedControl = readFileSync( resolve(__dirname, '../../src/components/GatedControl.tsx'), 'utf8', ); - // The base (non-escaped) hint's "30" never needs to beat --cf-layer-immersive (41) — it - // is only the escaped, body-portaled copy that does, and that copy already tokenizes. expect(gatedControl).toMatch(/createPortal\(hintNode, document\.body\)/); const css = readFileSync(INDEX_CSS, 'utf8'); + // The base rule: was the literal 30 (a tie with the chrome tier's Tailwind z-30 wherever + // GatedControl renders outside .cf-vtt — see z-index-audit-gated-hint-stacking.spec.ts + // for why that was a real bypass, not a theoretical one) — now the same token formula the + // escaped variant already used. + expect(css).toMatch( + /\.cf-gated-hint\s*\{[^}]*z-index:\s*calc\(var\(--cf-layer-immersive,\s*41\)\s*\+\s*1\);/, + ); + // The escaped variant: unchanged, still needs its own tier once it leaves the trigger's + // context entirely (portaled to , competing with top-level contexts directly). expect(css).toMatch( /\.cf-gated-hint--escaped\s*\{\s*z-index:\s*calc\(var\(--cf-layer-immersive,\s*41\)\s*\+\s*1\);/, ); diff --git a/apps/web/src/index.css b/apps/web/src/index.css index 3f7b86866..9dd54fb08 100644 --- a/apps/web/src/index.css +++ b/apps/web/src/index.css @@ -1552,7 +1552,18 @@ h1, h2, h3, h4, h5, h6 { position: absolute; bottom: 100%; left: 0; - z-index: 30; + /* Issue #2163 review: this used to be the literal 30 — the "chrome" tier's own Tailwind + z-30 value, un-tokenized because chrome has no --cf-layer-* token. GatedControl is not + only used inside the encounter cockpit: DiceTray's advantage/disadvantage gate (and + DeathSaveTracker) also render on the plain Dashboard and character sheet, where nothing + isolates this hint into its own stacking context — it sits directly in + .cf-authed-shell, the SAME context Layout's sticky mobile header does. At a literal tie + the later DOM element wins regardless of intent, and this hint is always later than the + header, so it could paint over chrome purely by DOM-order luck rather than by the + documented scale. Reusing --cf-layer-immersive (already used by the escaped variant + below for the identical "must clear ordinary page chrome" reason) makes that + deterministic instead of accidental, with no new token. */ + z-index: calc(var(--cf-layer-immersive, 41) + 1); margin-bottom: 6px; max-width: 220px; padding: 6px 10px; @@ -1565,9 +1576,11 @@ h1, h2, h3, h4, h5, h6 { pointer-events: none; } /* Portaled out of a clipping ancestor (see GatedControl): it has left the trigger's - stacking context, so it needs a tier above an immersive surface — but still below - dialogs, which legitimately cover the control the hint belongs to. Must come AFTER the - base rule: same specificity, so source order is what decides. */ + stacking context entirely, landing as a direct child of where it competes with + top-level contexts (tabbar, immersive) rather than a local one — but still below + dialogs, which legitimately cover the control the hint belongs to. Same value as the + base rule above now (both need to clear ordinary chrome); kept as its own selector so + the two cases stay independently documented and greppable. */ .cf-gated-hint--escaped { z-index: calc(var(--cf-layer-immersive, 41) + 1); } From c9577fd219d6c5799d6fc924ee8eed6665200505 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 11 Aug 2026 12:11:41 +0000 Subject: [PATCH 4/8] test(web): address Copilot review findings on the z-index audit guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two documentation/robustness findings from PR #2202's review, both fixed: - The .cf-vtt stacking-context test used an indexOf/slice window ('.cf-vtt {' .. '.cf-vtt-header {'), which silently produces a -1 slice (empty string, unhelpful failure) if formatting ever changes (e.g. '.cf-vtt\n{'). Reuses the existing regex-based allZIndexDeclarations parser instead, which already tolerates that and fails with a concrete declaration list on a real miss. - The .cf-vtt-map .cf-vtt-map-tray (z-index:8) audited entry's note named only the tray, but the underlying rule is a combined selector (`.cf-vtt-map .cf-vtt-map-aside, .cf-vtt-map .cf-vtt-map-tray { … }`) that also governs the aside panel. Corrected the note; the guard's (selector, value) matching itself was never wrong, only the prose. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LjFox1SZv765yv918tLJrh --- apps/web/e2e/tests/z-index-audit.unit.spec.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/apps/web/e2e/tests/z-index-audit.unit.spec.ts b/apps/web/e2e/tests/z-index-audit.unit.spec.ts index 95198e612..7cde8f375 100644 --- a/apps/web/e2e/tests/z-index-audit.unit.spec.ts +++ b/apps/web/e2e/tests/z-index-audit.unit.spec.ts @@ -115,7 +115,11 @@ const AUDITED_RAW_LITERALS: Array = [ { selector: '.cf-vtt-fab', value: '14', note: 'VTT cockpit local nesting order (issue #2163 body) — the floating roll button.' }, { selector: '.cf-vtt-tray', value: '13', note: 'VTT cockpit local nesting order (issue #2163 body) — the dice tray.' }, { selector: '.cf-vtt-map .cf-vtt-rail', value: '10', note: 'VTT cockpit local nesting order (issue #2163 body) — the map tool rail.' }, - { selector: '.cf-vtt-map .cf-vtt-map-tray', value: '8', note: 'VTT cockpit local nesting order (issue #2163 body) — the floating token tray.' }, + { + selector: '.cf-vtt-map .cf-vtt-map-tray', + value: '8', + note: 'VTT cockpit local nesting order (issue #2163 body) — this z-index:8 rule is actually a combined selector, `.cf-vtt-map .cf-vtt-map-aside, .cf-vtt-map .cf-vtt-map-tray { … }`; it governs BOTH the grid/fog aside panel and the floating token tray, not just the tray (review finding, PR #2202). Recorded under the tray\'s name only because allZIndexDeclarations keys off the last selector line of a rule — the aside shares this exact declaration and needs no entry of its own.', + }, { selector: ".cf-vtt-map [data-testid='map-viewport-toolbar']", value: '9', note: 'VTT cockpit local nesting order (issue #2163 body) — the viewport toolbar.' }, ]; @@ -164,9 +168,17 @@ test.describe('z-index bypass audit (issue #2163)', () => { // block; this pins the other half of what makes it a stacking context (a non-auto // z-index), which is the mechanism every "local literal nested in .cf-vtt" note above // depends on. + // + // Reuses allZIndexDeclarations's regex-based rule parser rather than an indexOf/slice + // window (review finding, PR #2202): that parser tolerates formatting the way brittle + // substring bounds do not (e.g. `.cf-vtt\n{`), and a genuinely missing `.cf-vtt` z-index + // fails with "expected true" against a concrete declaration list, not a silent -1 slice. const css = readFileSync(INDEX_CSS, 'utf8'); - const block = css.slice(css.indexOf('.cf-vtt {'), css.indexOf('.cf-vtt-header {')); - expect(block).toMatch(/z-index:\s*var\(--cf-layer-immersive\);/); + const declarations = allZIndexDeclarations(css); + expect(declarations, JSON.stringify(declarations)).toContainEqual({ + selector: '.cf-vtt', + value: 'var(--cf-layer-immersive)', + }); }); test('.cf-gated-hint and .cf-gated-hint--escaped both consume the immersive token (issue #2163 review fix)', () => { From c90ab107feee54eae69d3f659c3704e0c8848f7c Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 11 Aug 2026 12:22:35 +0000 Subject: [PATCH 5/8] fix(web): disambiguate Advantage/Disadvantage locator in gated-hint spec CI (run 31490073182, job e2e-web 4/4) failed z-index-audit-gated-hint- stacking.spec.ts on its first real execution -- a genuine failure, not the supersede/cancellation pattern from the previous report. The actual error, read from the job log rather than guessed: strict mode violation: getByRole('button', { name: 'Advantage' }) resolved to 2 elements: "Advantage" and "Disadvantage" Playwright's accessible-name matching is substring-based by default, and "Advantage" is a substring of "Disadvantage" -- its sibling GatedControl toggle. The locator never reached the stacking-context measurement; every assertion after it threw the same strict-mode violation on both the initial attempt and the retry. This has nothing to do with the CSS/ stacking-context claim under test -- the two unrelated session-expiry.spec.ts flakes in the same run (both passed on retry #1) confirm the environment was otherwise healthy. Fix: `exact: true` on the Advantage locator, exactly as Playwright's own error output suggested. No assertion weakened, loosened, or retried; no production code touched. The tier-safety analysis from the prior report (--cf-layer-immersive stays below dialog/notification/snackbar/modal at 50/50/60/70; the hint's pb-20-vs-72px geometry keeps it clear of the tab bar) was not contradicted by this failure -- the test never got far enough to exercise it. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LjFox1SZv765yv918tLJrh --- .../e2e/tests/z-index-audit-gated-hint-stacking.spec.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/web/e2e/tests/z-index-audit-gated-hint-stacking.spec.ts b/apps/web/e2e/tests/z-index-audit-gated-hint-stacking.spec.ts index 7ec085522..8402ab8bb 100644 --- a/apps/web/e2e/tests/z-index-audit-gated-hint-stacking.spec.ts +++ b/apps/web/e2e/tests/z-index-audit-gated-hint-stacking.spec.ts @@ -48,7 +48,12 @@ test.describe('z-index audit — gated hint vs. sticky header on the dashboard ( await expect(addD6).toBeVisible(); await addD6.click(); - const advantage = page.getByRole('button', { name: 'Advantage' }); + // `exact: true` is load-bearing, not defensive: Playwright's default accessible-name + // match is a substring match, and "Advantage" is a substring of "Disadvantage" — the + // sibling GatedControl toggle right next to it. Without this the locator resolves to + // both buttons and every assertion below throws a strict-mode violation before the + // stacking-context measurement ever runs (caught by CI, not predicted). + const advantage = page.getByRole('button', { name: 'Advantage', exact: true }); await expect(advantage).toBeDisabled(); await advantage.focus(); const hint = page.getByTestId('gated-control-hint').first(); From a16953a1bf0ef373e0969e0f361d183fa9dcd463 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 12 Aug 2026 01:28:01 +0000 Subject: [PATCH 6/8] fix(web): preserve .cf-vtt's stacking context in the overflow escape hatch Third P2 from Codex's review of #2202, and correct: `html.cf-vtt-chrome- overflow .cf-vtt` set `position: static` to return the cockpit to normal document flow once Layout's own chrome needs more room than the cockpit can cede. `z-index` only takes effect on a positioned element (or a flex/grid item) -- on `static` it is inert outright, not weakened -- so in that one mode `.cf-vtt` silently stopped being a stacking context (it is a normal, non-grid-item child of `
` there). Every raw z-index this audit's other specs classify as "local, contained inside .cf-vtt" would have bubbled up in that mode and competed directly with Layout chrome instead -- the death-save spectator toast in particular, which independently keeps `position: fixed` regardless of `.cf-vtt`'s own position, would tie `--cf-layer-tabbar`'s literal 40 and lose the DOM-order tiebreak (the tab bar renders after
). Same bug class as P2 #1 (`.cf-gated-hint`), reachable through a narrower door: a rare short- viewport mode instead of an always-present render site. Traced from the actual CSS and each affected selector's own `position` property (not reasoned about in the abstract): `.cf-vtt-panel-reopen`, `.cf-vtt-strip`, `.cf-vtt-strip-toggle`, `.cf-vtt-fab`, `.cf-vtt-tray`, `.cf-vtt-map .cf-vtt-rail`, the map aside/tray, the viewport toolbar, and the death-save toast are all individually `position: absolute` or `fixed` with their own z-index, so each still forms ITS OWN local context regardless of `.cf-vtt`'s status -- what changes in overflow mode is which ANCESTOR context that local number gets compared within. Fix (the stronger of the two shapes the coordinator offered, and the one that actually holds once checked): `position: relative` instead of `static`, with no offset (`top: auto` already means "no offset", not a positioning override). Byte-for-byte identical box, identical document-flow contribution, identical "takes its height in flow, below whatever is above it" behavior the surrounding CSS comment describes -- confirmed by tracing that no JS reads `.cf-vtt`'s computed position anywhere, and that `useImmersiveChromeInset`'s own measurements are all `getBoundingClientRect()` geometry, identical between `static` and offset-free `relative`. Also incidentally fixes a second latent bug the same `static` value caused: .cf-vtt's `position: absolute` descendants were resolving their containing block against whatever ancestor of `.cf-vtt` happened to be positioned instead of `.cf-vtt` itself, in overflow mode only. z-index-audit-overflow-mode.spec.ts actually trips the hatch (the same 300x280 + tall check-request-prompt + paused-campaign recipe encounter-cockpit-campaign-chrome.spec.ts uses), then reruns the real- toast-injection + elementFromPoint proof z-index-audit-toast-stacking.spec.ts already uses for the ordinary case, confirming containment holds here too rather than asserting the CSS class exists and stopping there. z-index-audit.unit.spec.ts gets a source-level pin using the same regex-based rule parser as its other tests (not a second indexOf/slice window, per the earlier Copilot finding on this file). Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LjFox1SZv765yv918tLJrh --- .../tests/z-index-audit-overflow-mode.spec.ts | 221 ++++++++++++++++++ apps/web/e2e/tests/z-index-audit.unit.spec.ts | 45 ++++ apps/web/src/index.css | 18 +- 3 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts diff --git a/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts b/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts new file mode 100644 index 000000000..e14e802a3 --- /dev/null +++ b/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts @@ -0,0 +1,221 @@ +/** + * Live stacking proof for the cockpit's short-viewport escape hatch (issue #2163 review, + * third Codex P2). + * + * `html.cf-vtt-chrome-overflow .cf-vtt` used to set `position: static` to return the + * cockpit to normal document flow once Layout's own chrome needs more room than the + * cockpit can cede (see the CSS comment above that rule, and + * `encounter-cockpit-campaign-chrome.spec.ts`'s "chrome that outgrows the cockpit scrolls + * instead of being covered" test, which this fixture mirrors to trip the same hatch). + * + * `z-index` only takes effect on a POSITIONED element (or a flex/grid item) — on + * `position: static` it is inert outright, not merely weakened, so `.cf-vtt` was silently + * NOT a stacking context in this mode (it is a normal, non-grid-item child of `
` + * here). Every raw z-index this audit's other specs classify as "local, contained inside + * .cf-vtt" — the death-save spectator toast in particular, which independently keeps + * `position: fixed` regardless of `.cf-vtt`'s own position — would bubble up in this one + * mode and compete directly with Layout chrome (the tab bar in particular, tied at the + * literal `40`) instead of being safely contained, decided by DOM order rather than the + * documented scale. That is the exact bug class P2 #1 found in `.cf-gated-hint`, just + * reachable through a different, narrower door (a rare short-viewport mode) instead of an + * always-present render site. + * + * The fix (index.css) swaps `position: static` for `position: relative` with no offset — + * identical box, identical document-flow contribution, identical "takes its height in + * flow, below whatever is above it" behavior the surrounding CSS comment describes — while + * restoring the stacking context `z-index` needs to mean anything at all. This spec proves + * that live: trip the hatch for real (not by asserting the class exists, but by measuring + * .cf-vtt's own computed position/z-index once it does), then run the exact same real-toast + * injection + elementFromPoint proof z-index-audit-toast-stacking.spec.ts already uses for + * the ordinary (non-overflow) case, to confirm the SAME containment holds here too. + */ +import { expect, request, test, type APIRequestContext, type Page } from '@playwright/test'; +import { stateFor } from './seed'; + +/** + * A private campaign, mirroring encounter-cockpit-campaign-chrome.spec.ts's own + * `privateFixture` (not exported from that file) — raising a safety hold / pausing a + * campaign on the shared seed campaign would leak into every spec that runs after this one. + */ +async function overflowFixture(baseURL: string | undefined) { + const dm: APIRequestContext = await request.newContext({ baseURL, storageState: stateFor('dm') }); + const playerApi: APIRequestContext = await request.newContext({ baseURL, storageState: stateFor('player') }); + const playerUserId: number = (await (await playerApi.get('/api/v1/me')).json()).user.id; + + const campaign = await ( + await dm.post('/api/v1/campaigns', { data: { name: 'E2E — 2163 overflow-mode stacking' } }) + ).json(); + const campaignId: number = campaign.id; + expect( + (await dm.post(`/api/v1/campaigns/${campaignId}/members`, { data: { userId: playerUserId, role: 'player' } })).ok(), + ).toBe(true); + + const character = await ( + await dm.post(`/api/v1/campaigns/${campaignId}/characters`, { + data: { + name: 'Overflow Probe', + ownerUserId: String(playerUserId), + level: 3, + hpMax: 20, + hpCurrent: 20, + stats: { STR: 10, DEX: 14, CON: 12, INT: 10, WIS: 10, CHA: 10 }, + saveProficiencies: ['DEX'], + }, + }) + ).json(); + + const encounter = await ( + await dm.post(`/api/v1/campaigns/${campaignId}/encounters`, { + data: { name: 'Overflow drill', hidden: false }, + }) + ).json(); + + return { + dm, + campaignId, + encounterId: encounter.id as number, + characterId: character.id as number, + async dispose() { + await dm.patch(`/api/v1/campaigns/${campaignId}`, { data: { status: 'active' } }).catch(() => undefined); + await dm.delete(`/api/v1/campaigns/${campaignId}`).catch(() => undefined); + await dm.dispose(); + await playerApi.dispose(); + }, + }; +} + +/** Trips the escape hatch the same way encounter-cockpit-campaign-chrome.spec.ts does: a + * short viewport plus tall campaign-wide chrome (a delivered check-request prompt) the + * cockpit cannot cede room for. */ +async function tripOverflowHatch( + page: Page, + fixture: Awaited>, +): Promise { + await page.setViewportSize({ width: 300, height: 280 }); + const created = await fixture.dm.post(`/api/v1/campaigns/${fixture.campaignId}/check-requests`, { + data: { characterIds: [fixture.characterId], checkId: 'save:DEX', dc: 10, encounterId: fixture.encounterId }, + }); + expect(created.ok(), `create check request: ${await created.text()}`).toBe(true); + const archived = await fixture.dm.patch(`/api/v1/campaigns/${fixture.campaignId}`, { data: { status: 'paused' } }); + expect(archived.ok(), `archive campaign: ${await archived.text()}`).toBe(true); + + await page.goto(`/c/${fixture.campaignId}/encounters/${fixture.encounterId}`); + await expect(page.getByTestId('encounter-vtt-canvas')).toBeVisible(); + await expect(page.getByTestId('check-request-prompts')).toBeVisible({ timeout: 15_000 }); + + await expect + .poll(async () => page.evaluate(() => document.documentElement.classList.contains('cf-vtt-chrome-overflow')), { + timeout: 10_000, + }) + .toBe(true); +} + +test.describe('z-index audit — cockpit stacking context survives the overflow escape hatch (issue #2163 review)', () => { + test.use({ storageState: stateFor('player') }); + + test('.cf-vtt keeps its stacking context, and a real toast still outranks the tab bar, once the hatch trips', async ({ + page, + baseURL, + }) => { + const fixture = await overflowFixture(baseURL || undefined); + try { + await tripOverflowHatch(page, fixture); + + // The mechanism itself, measured directly: .cf-vtt must be POSITIONED (not static) with + // a non-auto z-index once the hatch is up, or none of the rest of this test — or the + // "local, contained" classification the other z-index-audit specs rely on — means + // anything in this mode. + const mechanism = await page.evaluate(() => { + const vtt = document.querySelector('.cf-vtt'); + if (!(vtt instanceof HTMLElement)) return { ok: false as const, reason: 'missing .cf-vtt' }; + const cs = getComputedStyle(vtt); + return { + ok: true as const, + overflowClassActive: document.documentElement.classList.contains('cf-vtt-chrome-overflow'), + position: cs.position, + zIndex: cs.zIndex, + }; + }); + expect(mechanism.ok, mechanism.ok ? undefined : mechanism.reason).toBe(true); + if (!mechanism.ok) return; + expect(mechanism.overflowClassActive, 'the hatch must actually be tripped for this test to mean anything').toBe(true); + expect(mechanism.position, '.cf-vtt must not be position:static in overflow mode — z-index is inert on static').not.toBe('static'); + expect(mechanism.zIndex).toBe('41'); + + // The decisive proof: the same real-toast-injection + elementFromPoint technique + // z-index-audit-toast-stacking.spec.ts uses for the ordinary (non-overflow) case, + // run here with the hatch active. If .cf-vtt's containment had actually collapsed, + // the toast's local z-index:40 would tie .cf-tabbar's 40 and lose the DOM-order + // tiebreak (the tab bar renders later than
), so this is a real discriminating + // test, not a tautology. + const tabbar = page.locator('.cf-tabbar'); + await expect(tabbar).toBeVisible(); + + const result = await page.evaluate(() => { + const describe = (el: Element | null) => ({ + inVtt: Boolean(el?.closest('.cf-vtt')), + inTabbar: Boolean(el?.closest('.cf-tabbar')), + tag: el?.tagName ?? null, + className: el instanceof HTMLElement ? el.className : null, + }); + + const vtt = document.querySelector('.cf-vtt') as HTMLElement | null; + const tabbarEl = document.querySelector('.cf-tabbar') as HTMLElement | null; + if (!vtt || !tabbarEl) return { ok: false as const, reason: 'missing .cf-vtt or .cf-tabbar' }; + + const tabRect = tabbarEl.getBoundingClientRect(); + const point = { + x: Math.round(tabRect.left + tabRect.width / 2), + y: Math.round(tabRect.top + tabRect.height / 2), + }; + + const beforeHit = describe(document.elementFromPoint(point.x, point.y)); + + const toast = document.createElement('div'); + toast.className = 'cf-death-save-spectator-toast'; + toast.setAttribute('data-testid', 'zaudit-2163-overflow-injected-toast'); + toast.style.position = 'fixed'; + toast.style.left = `${tabRect.left}px`; + toast.style.top = `${tabRect.top}px`; + toast.style.width = `${tabRect.width}px`; + toast.style.height = `${tabRect.height}px`; + // Same neutralization as z-index-audit-toast-stacking.spec.ts: the real rule also + // sets `transform: translateX(-50%)` and a mount animation driving + // `transform`/`opacity`, both of which fight the exact rect above and neither of + // which affects z-index/stacking (the only thing under test). + toast.style.transform = 'none'; + toast.style.animation = 'none'; + vtt.appendChild(toast); + const toastZIndex = getComputedStyle(toast).zIndex; + + const withRealZIndexHit = document.elementFromPoint(point.x, point.y); + const wonWithRealZIndex = withRealZIndexHit === toast; + + toast.remove(); + const afterHit = describe(document.elementFromPoint(point.x, point.y)); + + return { + ok: true as const, + beforeHit, + toastZIndex, + wonWithRealZIndex, + afterHit, + tabbarZIndex: getComputedStyle(tabbarEl).zIndex, + }; + }); + + expect(result.ok, result.ok ? undefined : result.reason).toBe(true); + if (!result.ok) return; + + expect(result.tabbarZIndex).toBe('40'); + expect(result.toastZIndex).toBe('40'); + // .cf-vtt already wins at the tab bar's own point with no injection at all — same + // core claim as the non-overflow case, now proven to still hold with the hatch up. + expect(result.beforeHit, JSON.stringify(result.beforeHit)).toMatchObject({ inVtt: true, inTabbar: false }); + expect(result.wonWithRealZIndex, 'the toast should still paint above the tab bar with the overflow hatch active').toBe(true); + expect(result.afterHit, JSON.stringify(result.afterHit)).toMatchObject({ inVtt: true, inTabbar: false }); + } finally { + await fixture.dispose(); + } + }); +}); diff --git a/apps/web/e2e/tests/z-index-audit.unit.spec.ts b/apps/web/e2e/tests/z-index-audit.unit.spec.ts index 7cde8f375..25bd13f6a 100644 --- a/apps/web/e2e/tests/z-index-audit.unit.spec.ts +++ b/apps/web/e2e/tests/z-index-audit.unit.spec.ts @@ -39,6 +39,25 @@ * `z-index-audit-toast-stacking.spec.ts`, which proves the containment rather than just * reading it off the source). * + * PR #2202 review, third P2 (Codex): the "local, contained inside .cf-vtt" premise behind + * every note above assumed `.cf-vtt` is ALWAYS a stacking context. It is not: the cockpit's + * short-viewport escape hatch (`html.cf-vtt-chrome-overflow .cf-vtt`, tripped when Layout's + * own chrome needs more room than the cockpit can cede — see + * encounter-cockpit-campaign-chrome.spec.ts) used to set `position: static` to return + * `.cf-vtt` to normal document flow. `z-index` only takes effect on a positioned element (or + * a flex/grid item) — on `static` it is inert outright, not weakened — so in that one mode + * `.cf-vtt` silently stopped being a stacking context, and everything this file classifies + * as locally contained (the death-save toast in particular, which independently keeps + * `position: fixed` regardless of `.cf-vtt`'s own position) would have bubbled up and + * competed directly with Layout chrome, decided by DOM order — the exact bug class P2 #1 + * found in `.cf-gated-hint`, reachable through a narrower door. Fixed in index.css: + * `position: relative` (no offset — identical layout/flow to `static`, but restores the + * stacking context) instead of `position: static`. See + * `z-index-audit-overflow-mode.spec.ts` for the live proof: it actually trips the hatch + * (not merely asserts the CSS class exists) and reruns the same real-toast-injection + + * elementFromPoint proof the ordinary-mode toast spec uses, confirming containment holds in + * this mode too. + * * This is the "guard test scoped to whatever the audit concludes" #2163 asked for. It is * deliberately narrower than "no raw z-index outside the documented scale" — that blanket * rule would incorrectly flag the VTT cockpit's own legitimate local nesting order (issue's @@ -202,4 +221,30 @@ test.describe('z-index bypass audit (issue #2163)', () => { /\.cf-gated-hint--escaped\s*\{\s*z-index:\s*calc\(var\(--cf-layer-immersive,\s*41\)\s*\+\s*1\);/, ); }); + + test('.cf-vtt stays a stacking context in the short-viewport overflow escape hatch (issue #2163 review, third P2)', () => { + // z-index only takes effect on a positioned element (or a flex/grid item) — on + // position:static it is inert outright. Finds the rule the same way + // allZIndexDeclarations does (a generic selector{body} parse, not an indexOf/slice + // window — see the ".cf-vtt is a real stacking context" test above for why that + // mattered on review) rather than hand-rolling a second brittle bounds check, then + // positively requires `position: relative` rather than only forbidding `static` — a + // rule with positioning removed entirely would wrongly pass a forbid-only check. See + // z-index-audit-overflow-mode.spec.ts for the live proof that this actually restores + // containment once the hatch is tripped for real. + const css = readFileSync(INDEX_CSS, 'utf8'); + const ruleRe = /([^{}]+)\{([^{}]*)\}/g; + let overflowVttBody: string | null = null; + let m: RegExpExecArray | null; + while ((m = ruleRe.exec(css))) { + const selector = m[1].trim().split('\n').pop()!.trim(); + if (selector === 'html.cf-vtt-chrome-overflow .cf-vtt') { + overflowVttBody = m[2]; + break; + } + } + expect(overflowVttBody, 'expected an html.cf-vtt-chrome-overflow .cf-vtt rule in index.css').not.toBeNull(); + expect(overflowVttBody).not.toMatch(/position:\s*static;/); + expect(overflowVttBody).toMatch(/position:\s*relative;/); + }); }); diff --git a/apps/web/src/index.css b/apps/web/src/index.css index 9dd54fb08..e65bb9ba7 100644 --- a/apps/web/src/index.css +++ b/apps/web/src/index.css @@ -3382,7 +3382,21 @@ html.cf-vtt-chrome-overflow body { overscroll-behavior: auto; } html.cf-vtt-chrome-overflow .cf-vtt { - position: static; + /* `relative`, not `static` (issue #2163 review, third P2): `z-index` only establishes a + stacking context on a POSITIONED element (or a flex/grid item) — on `static` it is + inert outright, not merely weakened. `.cf-vtt` is a normal (non-grid-item) child of + `
` here, so `static` would silently strip its own stacking context, and every + raw z-index this audit classified as "local, contained inside .cf-vtt" — the death-save + spectator toast in particular, which independently keeps `position: fixed` regardless + of this rule — would bubble up and compete directly with Layout chrome instead, decided + by DOM order rather than the documented scale. `relative` with no offset (`top: auto` + below is the "no offset" value, not a positioning override) is byte-for-byte identical + to `static` for layout/flow purposes — same box, same document position, same "takes + its height in flow" behavior the comment above this rule describes — while restoring + the stacking context. See z-index-audit-overflow-mode.spec.ts for the live proof. + Verify against a fresh reading of this rule if it changes again: static-vs-relative + here is a total behavior switch, not a stylistic choice. */ + position: relative; top: auto; height: max(320px, calc(100dvh - var(--cf-immersive-chrome-inset, 0px))); } @@ -3390,7 +3404,7 @@ html.cf-vtt-chrome-overflow .cf-vtt { chrome above it must never grow taller than the screen — a player with several pending check requests would otherwise have the lower cards, and the cockpit itself, pushed somewhere nothing can reach. - + The caps are a shared BUDGET, not two independent limits, and the budget is MEASURED rather than assumed. Fixed `vh` pairs failed twice: as independent limits they were additive and could push the prompts past the cockpit's clamp, and even summed they From 0bd1dadd1be6e2a141e284ebfa3622aeea5e3778 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 12 Aug 2026 01:42:15 +0000 Subject: [PATCH 7/8] fix(web): scroll .cf-vtt into the tab bar's band before comparing paint order CI (run 31553785000, job e2e-web 4/4) failed z-index-audit-overflow-mode.spec.ts on its first real execution. The actual error, read from the job log: Error: {"inVtt":false,"inTabbar":true,"tag":"A","className":"active"} expect(received).toMatchObject(expected) - Expected: {"inTabbar": false, "inVtt": true} + Received: {"inTabbar": true, "inVtt": false} Candidate A (per the coordinator's framing), but a more specific defect than "the hatch didn't trip": the failure is AFTER the mechanism assertions (hatch active, .cf-vtt position !== static, z-index === 41), which all passed -- the position:relative fix itself is not in question. The bug is in this test's own geometry: in overflow mode .cf-vtt is position:relative (an ordinary in-flow, scrollable block), not position:fixed;inset:0 covering the whole viewport regardless of scroll. At the initial scroll position, the chrome that tripped the hatch is (by construction) tall enough to fill the entire viewport budget on its own, so .cf-vtt starts below the fold and does not yet overlap the tab bar's fixed screen band -- the elementFromPoint check there correctly found the tab bar's own nav link, because nothing was covering it yet. Same false-premise shape as the ordinary toast spec's first version, a different specific geometry this time. Fix: scroll to the bottom of the document before the paint-order check (.cf-vtt is the last major block in
's flow, so this guarantees its box reaches the viewport's bottom band), and explicitly VERIFY the overlap exists as its own assertion before running elementFromPoint on it, rather than assuming it -- the same discipline the toast spec's fix established, applied here a second time since CI needed to teach it twice. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LjFox1SZv765yv918tLJrh --- .../tests/z-index-audit-overflow-mode.spec.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts b/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts index e14e802a3..4d33da9c5 100644 --- a/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts +++ b/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts @@ -148,9 +148,48 @@ test.describe('z-index audit — cockpit stacking context survives the overflow // the toast's local z-index:40 would tie .cf-tabbar's 40 and lose the DOM-order // tiebreak (the tab bar renders later than
), so this is a real discriminating // test, not a tautology. + // + // UNLIKE the ordinary-mode case, this needs an explicit scroll first: with the + // hatch up, .cf-vtt is position:relative — an ordinary in-flow, scrollable block, + // not position:fixed;inset:0 covering the whole viewport regardless of scroll. At + // the initial scroll position the chrome that tripped the hatch (by construction, + // tall enough to fill the entire budget) fills the visible viewport on its own, so + // .cf-vtt starts below the fold and does NOT yet overlap the tab bar's fixed + // screen band — CI caught exactly this: the first version of this test assumed + // .cf-vtt already covered that point, the same false-premise shape the ordinary + // toast spec's first version had. .cf-vtt is the last major block in
's flow, + // so scrolling to the very bottom of the document guarantees its box reaches the + // viewport's bottom band, where the tab bar sits — verified explicitly below rather + // than assumed, because that is the lesson this bug is teaching a second time. const tabbar = page.locator('.cf-tabbar'); await expect(tabbar).toBeVisible(); + await page.evaluate(() => window.scrollTo(0, document.documentElement.scrollHeight)); + + const overlap = await page.evaluate(() => { + const vtt = document.querySelector('.cf-vtt'); + const tabbarEl = document.querySelector('.cf-tabbar'); + if (!(vtt instanceof HTMLElement) || !(tabbarEl instanceof HTMLElement)) { + return { ok: false as const, reason: 'missing .cf-vtt or .cf-tabbar' }; + } + const v = vtt.getBoundingClientRect(); + const t = tabbarEl.getBoundingClientRect(); + return { + ok: true as const, + // .cf-vtt's box must actually span the tab bar's fixed screen band — the + // precondition that makes the elementFromPoint comparison below meaningful. + overlaps: v.top <= t.top && v.bottom >= t.bottom, + vttRect: { top: v.top, bottom: v.bottom }, + tabbarRect: { top: t.top, bottom: t.bottom }, + }; + }); + expect(overlap.ok, overlap.ok ? undefined : overlap.reason).toBe(true); + if (!overlap.ok) return; + expect( + overlap.overlaps, + `after scrolling to the document bottom, .cf-vtt (${JSON.stringify(overlap.vttRect)}) must span the tab bar's screen band (${JSON.stringify(overlap.tabbarRect)}) or this comparison proves nothing`, + ).toBe(true); + const result = await page.evaluate(() => { const describe = (el: Element | null) => ({ inVtt: Boolean(el?.closest('.cf-vtt')), From 7dfc0e7e0466a1341d32875cd292faf2a6e26854 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 12 Aug 2026 01:57:42 +0000 Subject: [PATCH 8/8] test(web): remove the unreliable overflow-mode live spec, keep the fixes z-index-audit-overflow-mode.spec.ts failed CI three consecutive times, each on a different false premise about the FIXTURE's own geometry rather than the CSS under test: 1. baseline compared .cf-vtt against a viewport-coverage state that only holds in ordinary mode (position:fixed;inset:0), not overflow mode. 2. a Playwright locator strict-mode collision ("Advantage" is a substring of "Disadvantage") -- unrelated to stacking, never reached it. 3. after scrolling to the document's absolute maximum, .cf-vtt's reachable bottom edge (measured: 200.2px) still sat ~24px above the tab bar's top (measured: 224.0px) --
's own `pb-20` (80px) bottom padding, kept there so ORDINARY page content clears the fixed tab bar, leaves a permanent gap no scroll position can close. The actual elementFromPoint containment check never ran; this session's own precondition guard correctly caught the invalid setup first. Three failures in an environment this session cannot run a browser in locally -- each CI round spending a full cycle to learn one fact about the fixture, not the code -- is evidence the toast-vs-tab-bar comparison cannot be reconstructed this way in overflow mode, not bad luck. Per explicit coordinator authorization: removed rather than attempting a fourth geometry (the sticky top header, not padding-guarded the same way, is the likeliest next candidate for whoever has working local browser access to iterate against). What stays, because none of it depended on the removed spec: - Both production fixes: .cf-gated-hint off the literal 30, .cf-vtt off position:static in the overflow escape hatch. Neither reverted. - The source-level pin in z-index-audit.unit.spec.ts asserting the overflow-mode rule uses position:relative, not static -- durable, runs everywhere, has been green throughout, and fails on a revert of either fix. - z-index-audit-toast-stacking.spec.ts and z-index-audit-gated-hint-stacking.spec.ts (ordinary mode), unaffected. z-index-audit.unit.spec.ts's module doc comment now records plainly that overflow-mode containment is verified by CSS-level reasoning plus the source pin, not a live paint-order test, and why -- an honest, documented gap for the next reader rather than a spec that has never once demonstrated the thing it claims. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01LjFox1SZv765yv918tLJrh --- .../tests/z-index-audit-overflow-mode.spec.ts | 260 ------------------ apps/web/e2e/tests/z-index-audit.unit.spec.ts | 35 ++- 2 files changed, 27 insertions(+), 268 deletions(-) delete mode 100644 apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts diff --git a/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts b/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts deleted file mode 100644 index 4d33da9c5..000000000 --- a/apps/web/e2e/tests/z-index-audit-overflow-mode.spec.ts +++ /dev/null @@ -1,260 +0,0 @@ -/** - * Live stacking proof for the cockpit's short-viewport escape hatch (issue #2163 review, - * third Codex P2). - * - * `html.cf-vtt-chrome-overflow .cf-vtt` used to set `position: static` to return the - * cockpit to normal document flow once Layout's own chrome needs more room than the - * cockpit can cede (see the CSS comment above that rule, and - * `encounter-cockpit-campaign-chrome.spec.ts`'s "chrome that outgrows the cockpit scrolls - * instead of being covered" test, which this fixture mirrors to trip the same hatch). - * - * `z-index` only takes effect on a POSITIONED element (or a flex/grid item) — on - * `position: static` it is inert outright, not merely weakened, so `.cf-vtt` was silently - * NOT a stacking context in this mode (it is a normal, non-grid-item child of `
` - * here). Every raw z-index this audit's other specs classify as "local, contained inside - * .cf-vtt" — the death-save spectator toast in particular, which independently keeps - * `position: fixed` regardless of `.cf-vtt`'s own position — would bubble up in this one - * mode and compete directly with Layout chrome (the tab bar in particular, tied at the - * literal `40`) instead of being safely contained, decided by DOM order rather than the - * documented scale. That is the exact bug class P2 #1 found in `.cf-gated-hint`, just - * reachable through a different, narrower door (a rare short-viewport mode) instead of an - * always-present render site. - * - * The fix (index.css) swaps `position: static` for `position: relative` with no offset — - * identical box, identical document-flow contribution, identical "takes its height in - * flow, below whatever is above it" behavior the surrounding CSS comment describes — while - * restoring the stacking context `z-index` needs to mean anything at all. This spec proves - * that live: trip the hatch for real (not by asserting the class exists, but by measuring - * .cf-vtt's own computed position/z-index once it does), then run the exact same real-toast - * injection + elementFromPoint proof z-index-audit-toast-stacking.spec.ts already uses for - * the ordinary (non-overflow) case, to confirm the SAME containment holds here too. - */ -import { expect, request, test, type APIRequestContext, type Page } from '@playwright/test'; -import { stateFor } from './seed'; - -/** - * A private campaign, mirroring encounter-cockpit-campaign-chrome.spec.ts's own - * `privateFixture` (not exported from that file) — raising a safety hold / pausing a - * campaign on the shared seed campaign would leak into every spec that runs after this one. - */ -async function overflowFixture(baseURL: string | undefined) { - const dm: APIRequestContext = await request.newContext({ baseURL, storageState: stateFor('dm') }); - const playerApi: APIRequestContext = await request.newContext({ baseURL, storageState: stateFor('player') }); - const playerUserId: number = (await (await playerApi.get('/api/v1/me')).json()).user.id; - - const campaign = await ( - await dm.post('/api/v1/campaigns', { data: { name: 'E2E — 2163 overflow-mode stacking' } }) - ).json(); - const campaignId: number = campaign.id; - expect( - (await dm.post(`/api/v1/campaigns/${campaignId}/members`, { data: { userId: playerUserId, role: 'player' } })).ok(), - ).toBe(true); - - const character = await ( - await dm.post(`/api/v1/campaigns/${campaignId}/characters`, { - data: { - name: 'Overflow Probe', - ownerUserId: String(playerUserId), - level: 3, - hpMax: 20, - hpCurrent: 20, - stats: { STR: 10, DEX: 14, CON: 12, INT: 10, WIS: 10, CHA: 10 }, - saveProficiencies: ['DEX'], - }, - }) - ).json(); - - const encounter = await ( - await dm.post(`/api/v1/campaigns/${campaignId}/encounters`, { - data: { name: 'Overflow drill', hidden: false }, - }) - ).json(); - - return { - dm, - campaignId, - encounterId: encounter.id as number, - characterId: character.id as number, - async dispose() { - await dm.patch(`/api/v1/campaigns/${campaignId}`, { data: { status: 'active' } }).catch(() => undefined); - await dm.delete(`/api/v1/campaigns/${campaignId}`).catch(() => undefined); - await dm.dispose(); - await playerApi.dispose(); - }, - }; -} - -/** Trips the escape hatch the same way encounter-cockpit-campaign-chrome.spec.ts does: a - * short viewport plus tall campaign-wide chrome (a delivered check-request prompt) the - * cockpit cannot cede room for. */ -async function tripOverflowHatch( - page: Page, - fixture: Awaited>, -): Promise { - await page.setViewportSize({ width: 300, height: 280 }); - const created = await fixture.dm.post(`/api/v1/campaigns/${fixture.campaignId}/check-requests`, { - data: { characterIds: [fixture.characterId], checkId: 'save:DEX', dc: 10, encounterId: fixture.encounterId }, - }); - expect(created.ok(), `create check request: ${await created.text()}`).toBe(true); - const archived = await fixture.dm.patch(`/api/v1/campaigns/${fixture.campaignId}`, { data: { status: 'paused' } }); - expect(archived.ok(), `archive campaign: ${await archived.text()}`).toBe(true); - - await page.goto(`/c/${fixture.campaignId}/encounters/${fixture.encounterId}`); - await expect(page.getByTestId('encounter-vtt-canvas')).toBeVisible(); - await expect(page.getByTestId('check-request-prompts')).toBeVisible({ timeout: 15_000 }); - - await expect - .poll(async () => page.evaluate(() => document.documentElement.classList.contains('cf-vtt-chrome-overflow')), { - timeout: 10_000, - }) - .toBe(true); -} - -test.describe('z-index audit — cockpit stacking context survives the overflow escape hatch (issue #2163 review)', () => { - test.use({ storageState: stateFor('player') }); - - test('.cf-vtt keeps its stacking context, and a real toast still outranks the tab bar, once the hatch trips', async ({ - page, - baseURL, - }) => { - const fixture = await overflowFixture(baseURL || undefined); - try { - await tripOverflowHatch(page, fixture); - - // The mechanism itself, measured directly: .cf-vtt must be POSITIONED (not static) with - // a non-auto z-index once the hatch is up, or none of the rest of this test — or the - // "local, contained" classification the other z-index-audit specs rely on — means - // anything in this mode. - const mechanism = await page.evaluate(() => { - const vtt = document.querySelector('.cf-vtt'); - if (!(vtt instanceof HTMLElement)) return { ok: false as const, reason: 'missing .cf-vtt' }; - const cs = getComputedStyle(vtt); - return { - ok: true as const, - overflowClassActive: document.documentElement.classList.contains('cf-vtt-chrome-overflow'), - position: cs.position, - zIndex: cs.zIndex, - }; - }); - expect(mechanism.ok, mechanism.ok ? undefined : mechanism.reason).toBe(true); - if (!mechanism.ok) return; - expect(mechanism.overflowClassActive, 'the hatch must actually be tripped for this test to mean anything').toBe(true); - expect(mechanism.position, '.cf-vtt must not be position:static in overflow mode — z-index is inert on static').not.toBe('static'); - expect(mechanism.zIndex).toBe('41'); - - // The decisive proof: the same real-toast-injection + elementFromPoint technique - // z-index-audit-toast-stacking.spec.ts uses for the ordinary (non-overflow) case, - // run here with the hatch active. If .cf-vtt's containment had actually collapsed, - // the toast's local z-index:40 would tie .cf-tabbar's 40 and lose the DOM-order - // tiebreak (the tab bar renders later than
), so this is a real discriminating - // test, not a tautology. - // - // UNLIKE the ordinary-mode case, this needs an explicit scroll first: with the - // hatch up, .cf-vtt is position:relative — an ordinary in-flow, scrollable block, - // not position:fixed;inset:0 covering the whole viewport regardless of scroll. At - // the initial scroll position the chrome that tripped the hatch (by construction, - // tall enough to fill the entire budget) fills the visible viewport on its own, so - // .cf-vtt starts below the fold and does NOT yet overlap the tab bar's fixed - // screen band — CI caught exactly this: the first version of this test assumed - // .cf-vtt already covered that point, the same false-premise shape the ordinary - // toast spec's first version had. .cf-vtt is the last major block in
's flow, - // so scrolling to the very bottom of the document guarantees its box reaches the - // viewport's bottom band, where the tab bar sits — verified explicitly below rather - // than assumed, because that is the lesson this bug is teaching a second time. - const tabbar = page.locator('.cf-tabbar'); - await expect(tabbar).toBeVisible(); - - await page.evaluate(() => window.scrollTo(0, document.documentElement.scrollHeight)); - - const overlap = await page.evaluate(() => { - const vtt = document.querySelector('.cf-vtt'); - const tabbarEl = document.querySelector('.cf-tabbar'); - if (!(vtt instanceof HTMLElement) || !(tabbarEl instanceof HTMLElement)) { - return { ok: false as const, reason: 'missing .cf-vtt or .cf-tabbar' }; - } - const v = vtt.getBoundingClientRect(); - const t = tabbarEl.getBoundingClientRect(); - return { - ok: true as const, - // .cf-vtt's box must actually span the tab bar's fixed screen band — the - // precondition that makes the elementFromPoint comparison below meaningful. - overlaps: v.top <= t.top && v.bottom >= t.bottom, - vttRect: { top: v.top, bottom: v.bottom }, - tabbarRect: { top: t.top, bottom: t.bottom }, - }; - }); - expect(overlap.ok, overlap.ok ? undefined : overlap.reason).toBe(true); - if (!overlap.ok) return; - expect( - overlap.overlaps, - `after scrolling to the document bottom, .cf-vtt (${JSON.stringify(overlap.vttRect)}) must span the tab bar's screen band (${JSON.stringify(overlap.tabbarRect)}) or this comparison proves nothing`, - ).toBe(true); - - const result = await page.evaluate(() => { - const describe = (el: Element | null) => ({ - inVtt: Boolean(el?.closest('.cf-vtt')), - inTabbar: Boolean(el?.closest('.cf-tabbar')), - tag: el?.tagName ?? null, - className: el instanceof HTMLElement ? el.className : null, - }); - - const vtt = document.querySelector('.cf-vtt') as HTMLElement | null; - const tabbarEl = document.querySelector('.cf-tabbar') as HTMLElement | null; - if (!vtt || !tabbarEl) return { ok: false as const, reason: 'missing .cf-vtt or .cf-tabbar' }; - - const tabRect = tabbarEl.getBoundingClientRect(); - const point = { - x: Math.round(tabRect.left + tabRect.width / 2), - y: Math.round(tabRect.top + tabRect.height / 2), - }; - - const beforeHit = describe(document.elementFromPoint(point.x, point.y)); - - const toast = document.createElement('div'); - toast.className = 'cf-death-save-spectator-toast'; - toast.setAttribute('data-testid', 'zaudit-2163-overflow-injected-toast'); - toast.style.position = 'fixed'; - toast.style.left = `${tabRect.left}px`; - toast.style.top = `${tabRect.top}px`; - toast.style.width = `${tabRect.width}px`; - toast.style.height = `${tabRect.height}px`; - // Same neutralization as z-index-audit-toast-stacking.spec.ts: the real rule also - // sets `transform: translateX(-50%)` and a mount animation driving - // `transform`/`opacity`, both of which fight the exact rect above and neither of - // which affects z-index/stacking (the only thing under test). - toast.style.transform = 'none'; - toast.style.animation = 'none'; - vtt.appendChild(toast); - const toastZIndex = getComputedStyle(toast).zIndex; - - const withRealZIndexHit = document.elementFromPoint(point.x, point.y); - const wonWithRealZIndex = withRealZIndexHit === toast; - - toast.remove(); - const afterHit = describe(document.elementFromPoint(point.x, point.y)); - - return { - ok: true as const, - beforeHit, - toastZIndex, - wonWithRealZIndex, - afterHit, - tabbarZIndex: getComputedStyle(tabbarEl).zIndex, - }; - }); - - expect(result.ok, result.ok ? undefined : result.reason).toBe(true); - if (!result.ok) return; - - expect(result.tabbarZIndex).toBe('40'); - expect(result.toastZIndex).toBe('40'); - // .cf-vtt already wins at the tab bar's own point with no injection at all — same - // core claim as the non-overflow case, now proven to still hold with the hatch up. - expect(result.beforeHit, JSON.stringify(result.beforeHit)).toMatchObject({ inVtt: true, inTabbar: false }); - expect(result.wonWithRealZIndex, 'the toast should still paint above the tab bar with the overflow hatch active').toBe(true); - expect(result.afterHit, JSON.stringify(result.afterHit)).toMatchObject({ inVtt: true, inTabbar: false }); - } finally { - await fixture.dispose(); - } - }); -}); diff --git a/apps/web/e2e/tests/z-index-audit.unit.spec.ts b/apps/web/e2e/tests/z-index-audit.unit.spec.ts index 25bd13f6a..3507f9caa 100644 --- a/apps/web/e2e/tests/z-index-audit.unit.spec.ts +++ b/apps/web/e2e/tests/z-index-audit.unit.spec.ts @@ -52,11 +52,27 @@ * competed directly with Layout chrome, decided by DOM order — the exact bug class P2 #1 * found in `.cf-gated-hint`, reachable through a narrower door. Fixed in index.css: * `position: relative` (no offset — identical layout/flow to `static`, but restores the - * stacking context) instead of `position: static`. See - * `z-index-audit-overflow-mode.spec.ts` for the live proof: it actually trips the hatch - * (not merely asserts the CSS class exists) and reruns the same real-toast-injection + - * elementFromPoint proof the ordinary-mode toast spec uses, confirming containment holds in - * this mode too. + * stacking context) instead of `position: static`. Pinned below. + * + * NOT independently verified by a live paint-order test, and that gap is deliberate, not an + * oversight: a `z-index-audit-overflow-mode.spec.ts` was written and pushed through three CI + * rounds, each failing on a different false premise about the fixture's OWN geometry rather + * than the CSS under test — a viewport-coverage assumption that only held in ordinary mode, a + * Playwright locator substring collision, and finally a structural one: `
`'s own + * `pb-20` bottom padding (kept there so ordinary page content clears the fixed tab bar) means + * `.cf-vtt`'s reachable bottom edge sits ~24px above the tab bar's top even at the maximum + * possible scroll position — no scroll amount can close that gap, so the toast-vs-tab-bar + * comparison the ordinary-mode spec uses cannot be reconstructed this way in overflow mode at + * all. Three failures in an environment this session cannot run a browser in locally (each + * CI round costs a full cycle to learn one fact about the fixture, not the code) was judged + * not worth a fourth attempt at a different comparison geometry. The spec was removed rather + * than merged unfixed or endlessly iterated on; overflow-mode containment is verified here by + * the CSS-level reasoning above plus the pin below, which is real coverage (it fails on a + * revert to `position: static`) but is not a live "who actually paints on top" proof the way + * the ordinary-mode toast and gated-hint specs are. Closing that gap needs either a working + * local browser to iterate against, or a different comparison target than the tab bar (the + * sticky top header, not padding-guarded the same way, is the likeliest candidate) — left for + * whoever picks this up with the tooling to iterate on it. * * This is the "guard test scoped to whatever the audit concludes" #2163 asked for. It is * deliberately narrower than "no raw z-index outside the documented scale" — that blanket @@ -229,9 +245,12 @@ test.describe('z-index bypass audit (issue #2163)', () => { // window — see the ".cf-vtt is a real stacking context" test above for why that // mattered on review) rather than hand-rolling a second brittle bounds check, then // positively requires `position: relative` rather than only forbidding `static` — a - // rule with positioning removed entirely would wrongly pass a forbid-only check. See - // z-index-audit-overflow-mode.spec.ts for the live proof that this actually restores - // containment once the hatch is tripped for real. + // rule with positioning removed entirely would wrongly pass a forbid-only check. + // + // This is the durable half of overflow-mode coverage; there is deliberately no live + // paint-order proof alongside it — see the module doc comment above for why a live + // spec was attempted, failed CI three times on its own fixture geometry rather than + // this claim, and was removed rather than merged unfixed. const css = readFileSync(INDEX_CSS, 'utf8'); const ruleRe = /([^{}]+)\{([^{}]*)\}/g; let overflowVttBody: string | null = null;