From 814fa4b3ab0f6848d6902a637b70a9d7907a67b7 Mon Sep 17 00:00:00 2001 From: Void Date: Tue, 10 Nov 2026 14:05:42 +0000 Subject: [PATCH] Diagnostic overlays (?probe=1, ?tierlabel=1) only where allowed; footer band test knows the Safari prefix debugOverlaysAllowed: a dev build, a VITE_PREVIEW_DEMO build, or backgroundScene.debugOverlays in the client config. A production visitor adding the query string gets neither the frame readout nor the tier label. footerBand.test pins -webkit-backdrop-filter (live commit 0fe41efb) and that it blurs as the standard one. Co-Authored-By: Claude Sonnet 5.5 --- src/app/features/scene/debugOverlays.test.ts | 49 +++++++++++++++++++ src/app/features/scene/debugOverlays.ts | 15 ++++++ src/app/features/scene/index.ts | 6 ++- src/app/features/scene/ridge/Ridge.test.ts | 13 ++++- src/app/features/scene/ridge/Ridge.ts | 7 ++- src/app/features/scene/terrain/Terrain.ts | 9 ++-- .../features/scene/terrain/tierLabel.test.ts | 12 +++-- src/app/features/scene/terrain/tierLabel.ts | 18 ++++--- src/app/features/scene/tier.ts | 2 + src/app/pages/auth/footerBand.test.ts | 10 +++- 10 files changed, 123 insertions(+), 18 deletions(-) create mode 100644 src/app/features/scene/debugOverlays.test.ts create mode 100644 src/app/features/scene/debugOverlays.ts diff --git a/src/app/features/scene/debugOverlays.test.ts b/src/app/features/scene/debugOverlays.test.ts new file mode 100644 index 00000000..e1a4e61e --- /dev/null +++ b/src/app/features/scene/debugOverlays.test.ts @@ -0,0 +1,49 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { debugOverlaysAllowed, overlayRequested } from './debugOverlays'; + +let search = ''; +beforeEach(() => { + search = ''; + vi.stubGlobal('window', { + get location() { + return { search }; + }, + }); +}); +afterEach(() => { + vi.unstubAllGlobals(); + vi.unstubAllEnvs(); +}); + +describe('debugOverlaysAllowed', () => { + it('a production build allows nothing by default', () => { + vi.stubEnv('DEV', false); + vi.stubEnv('VITE_PREVIEW_DEMO', ''); + expect(debugOverlaysAllowed(undefined)).toBe(false); + expect(debugOverlaysAllowed({ tier: 'full' })).toBe(false); + expect(debugOverlaysAllowed({ tier: 'full', debugOverlays: false })).toBe(false); + }); + + it('a dev build, a demo preview build or an explicit config flag allows them', () => { + vi.stubEnv('DEV', true); + expect(debugOverlaysAllowed(undefined)).toBe(true); + vi.stubEnv('DEV', false); + vi.stubEnv('VITE_PREVIEW_DEMO', '1'); + expect(debugOverlaysAllowed(undefined)).toBe(true); + vi.stubEnv('VITE_PREVIEW_DEMO', ''); + expect(debugOverlaysAllowed({ debugOverlays: true })).toBe(true); + }); +}); + +describe('overlayRequested', () => { + it('needs both the query and the permission', () => { + search = '?probe=1'; + expect(overlayRequested('probe', true)).toBe(true); + expect(overlayRequested('probe', false)).toBe(false); + expect(overlayRequested('tierlabel', true)).toBe(false); + search = '?tierlabel=1'; + expect(overlayRequested('tierlabel', true)).toBe(true); + search = ''; + expect(overlayRequested('probe', true)).toBe(false); + }); +}); diff --git a/src/app/features/scene/debugOverlays.ts b/src/app/features/scene/debugOverlays.ts new file mode 100644 index 00000000..a02d9e92 --- /dev/null +++ b/src/app/features/scene/debugOverlays.ts @@ -0,0 +1,15 @@ +import type { BackgroundSceneConfig } from './tier'; + +/** + * Whether the page URL may switch on the scene's diagnostic overlays (`?probe=1` frame readout, `?tierlabel=1` path + * label). Only a dev build, a demo preview build (VITE_PREVIEW_DEMO=1), or a config that says `debugOverlays: true` + * allows it; a production visitor adding a query string gets nothing. + */ +export const debugOverlaysAllowed = (config: BackgroundSceneConfig | undefined): boolean => + import.meta.env?.DEV === true || + import.meta.env?.VITE_PREVIEW_DEMO === '1' || + config?.debugOverlays === true; + +/** The page URL asks for this overlay (`?name=1`), and the overlays are allowed. */ +export const overlayRequested = (name: 'probe' | 'tierlabel', allowed: boolean): boolean => + allowed && new URLSearchParams(window.location.search).get(name) === '1'; diff --git a/src/app/features/scene/index.ts b/src/app/features/scene/index.ts index 73377440..bc041672 100644 --- a/src/app/features/scene/index.ts +++ b/src/app/features/scene/index.ts @@ -1,5 +1,6 @@ import type { Scene, SceneOptions } from './Scene'; import { BackgroundSceneConfig, Capabilities, SceneTier, resolveTier } from './tier'; +import { debugOverlaysAllowed } from './debugOverlays'; import { getSkyState, subscribe } from './skyState'; import type { SkyState } from './skyState'; @@ -17,7 +18,7 @@ export type StartOptions = Omit { let createScene: (o: SceneOptions) => Scene | null; @@ -82,7 +83,8 @@ export async function startBackgroundScene( ): Promise { const tier = resolveTier(config, capabilities); if (tier === 'off') return null; - const build = (state: SkyState) => create(config, { ...options, tier }, state); + const debug = debugOverlaysAllowed(config); + const build = (state: SkyState) => create(config, { ...options, tier, debug }, state); const state = getSkyState(); const key0 = config?.style === 'raymarch' ? null : await skyKey(config, state); const first = await build(state); diff --git a/src/app/features/scene/ridge/Ridge.test.ts b/src/app/features/scene/ridge/Ridge.test.ts index 711054f6..adee2717 100644 --- a/src/app/features/scene/ridge/Ridge.test.ts +++ b/src/app/features/scene/ridge/Ridge.test.ts @@ -428,7 +428,7 @@ describe('createRidgeScene', () => { it('?probe=1 keeps the rAF loop alive and shows median and p95', () => { search = '?probe=1'; const { parent, canvas } = host(); - const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!; + const s = createRidgeScene({ canvas, tier: 'full', sky: DAY, debug: true })!; const readout = parent.children[parent.children.length - 1]; runFrames(16.7, 300); expect(rafQueue.length).toBe(1); // still sampling @@ -437,6 +437,17 @@ describe('createRidgeScene', () => { expect(parent.children.some((c: any) => c === readout)).toBe(false); }); + it('?probe=1 does nothing where the overlays are not allowed: no readout, the loop ends', () => { + search = '?probe=1'; + const { parent, canvas } = host(); + const before = parent.children.length; + const s = createRidgeScene({ canvas, tier: 'full', sky: DAY })!; + expect(parent.children.length).toBe(before + LAYERS.length); + runFrames(16.7, 300); + expect(rafQueue.length).toBe(0); + s.dispose(); + }); + it('a scene started at zero size paints nothing, then builds on the first non-zero resize', async () => { const { parent, canvas } = host(); canvas.clientWidth = 0; diff --git a/src/app/features/scene/ridge/Ridge.ts b/src/app/features/scene/ridge/Ridge.ts index 69a88864..fd40a967 100644 --- a/src/app/features/scene/ridge/Ridge.ts +++ b/src/app/features/scene/ridge/Ridge.ts @@ -1,4 +1,5 @@ import type { Scene, SceneOptions } from '../Scene'; +import { overlayRequested } from '../debugOverlays'; import { FrameSampler, FrameStats } from './probe'; import { skyColours, SkyColours, Srgb } from './skyColour'; import { activeAt, drawStars, drawTwinkle as paintTwinkle, makeStars, Star } from './stars'; @@ -14,8 +15,10 @@ import { } from './ridgeWorld'; export type RidgeOptions = Pick & { - /** Show the rAF median/p95 readout. Default: the page URL has `?probe=1`. */ + /** Show the rAF median/p95 readout. Default: the page URL has `?probe=1`, where `debug` allows it. */ probe?: boolean; + /** The diagnostic overlays may be asked for by URL (debugOverlays.ts). Default: no. */ + debug?: boolean; /** Each time the readout would update, and once with `still` when the fallback fires. */ onProbe?: (s: FrameStats & { still: boolean }) => void; /** The sky's colours; default `skyColours()`, the one function to replace with Void's sun.js. */ @@ -151,7 +154,7 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null { const parent = canvas.parentElement; if (!parent) return null; const sky = opts.sky ?? skyColours(); - const probe = opts.probe ?? new URLSearchParams(window.location.search).get('probe') === '1'; + const probe = opts.probe ?? overlayRequested('probe', opts.debug === true); const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)'); let built: Built | undefined; diff --git a/src/app/features/scene/terrain/Terrain.ts b/src/app/features/scene/terrain/Terrain.ts index b697927b..a1807305 100644 --- a/src/app/features/scene/terrain/Terrain.ts +++ b/src/app/features/scene/terrain/Terrain.ts @@ -22,6 +22,7 @@ import { SKY_FRAG, } from './terrainShaders'; import { createTerrainStars } from './terrainStars'; +import { overlayRequested } from '../debugOverlays'; import { showTierLabel } from './tierLabel'; export type TerrainOptions = Pick< @@ -36,8 +37,10 @@ export type TerrainOptions = Pick< band?: SkyBand; /** Terrain seed: the height map is sampled at an offset taken from it. Default 0. */ seed?: number; - /** Show the rAF median/p95 readout (plus triangle count). Default: the page URL has `?probe=1`. */ + /** Show the rAF median/p95 readout (plus triangle count). Default: the page URL has `?probe=1`, where `debug` allows it. */ probe?: boolean; + /** The diagnostic overlays (readout, tier label) may be asked for by URL (debugOverlays.ts). Default: no. */ + debug?: boolean; onProbe?: (s: FrameStats & { still: boolean; triangles: number }) => void; }; @@ -89,7 +92,7 @@ export function createTerrainScene(opts: TerrainOptions): Scene | null { const tier = opts.tier ?? 'full'; if (tier === 'off') return null; const { canvas } = opts; - const probe = opts.probe ?? new URLSearchParams(window.location.search).get('probe') === '1'; + const probe = opts.probe ?? overlayRequested('probe', opts.debug === true); const gl = canvas.getContext('webgl2', { antialias: false, alpha: false, @@ -395,7 +398,7 @@ export function createTerrainScene(opts: TerrainOptions): Scene | null { }); canvas.parentElement.appendChild(readout); } - const removeLabel = showTierLabel(canvas, tier); + const removeLabel = showTierLabel(canvas, tier, opts.debug === true); if (still) settleToStill(); else wake(); if (!still && !moving()) draw(0); diff --git a/src/app/features/scene/terrain/tierLabel.test.ts b/src/app/features/scene/terrain/tierLabel.test.ts index 3e9f3a48..e3f18871 100644 --- a/src/app/features/scene/terrain/tierLabel.test.ts +++ b/src/app/features/scene/terrain/tierLabel.test.ts @@ -29,21 +29,27 @@ afterEach(() => vi.unstubAllGlobals()); describe('showTierLabel', () => { it('adds nothing in a normal build', () => { - expect(showTierLabel(canvas(true), 'full')).toBeNull(); + expect(showTierLabel(canvas(true), 'full', true)).toBeNull(); expect(appended).toHaveLength(0); }); it('names the path on screen when asked with ?tierlabel=1, and removes itself', () => { search = '?tierlabel=1'; - const remove = showTierLabel(canvas(true), 'sky-only'); + const remove = showTierLabel(canvas(true), 'sky-only', true); expect(appended).toHaveLength(1); expect(appended[0].textContent).toBe('terrain · sky-only'); remove!(); expect(appended[0].remove).toHaveBeenCalled(); }); + it('ignores ?tierlabel=1 where the overlays are not allowed (a production page)', () => { + search = '?tierlabel=1'; + expect(showTierLabel(canvas(true), 'full', false)).toBeNull(); + expect(appended).toHaveLength(0); + }); + it('has nowhere to go without a parent', () => { search = '?tierlabel=1'; - expect(showTierLabel(canvas(false), 'full')).toBeNull(); + expect(showTierLabel(canvas(false), 'full', true)).toBeNull(); }); }); diff --git a/src/app/features/scene/terrain/tierLabel.ts b/src/app/features/scene/terrain/tierLabel.ts index 0b2c79ec..4afc8a69 100644 --- a/src/app/features/scene/terrain/tierLabel.ts +++ b/src/app/features/scene/terrain/tierLabel.ts @@ -1,13 +1,19 @@ +import { overlayRequested } from '../debugOverlays'; + // A tiny label naming which terrain path is on screen ('full', 'low', 'still', or 'sky-only' where WebGL2 is missing), -// so a screenshot of a preview says what it shows. Built into preview builds only (VITE_PREVIEW_DEMO=1), or by `?tierlabel=1`. -const wanted = (): boolean => - import.meta.env?.VITE_PREVIEW_DEMO === '1' || - new URLSearchParams(window.location.search).get('tierlabel') === '1'; +// so a screenshot of a preview says what it shows. Built into preview builds (VITE_PREVIEW_DEMO=1), or by `?tierlabel=1` +// where the diagnostic overlays are allowed (debugOverlays.ts). +const wanted = (allowed: boolean): boolean => + import.meta.env?.VITE_PREVIEW_DEMO === '1' || overlayRequested('tierlabel', allowed); /** Adds the label to the canvas's parent; returns its remover, or null when no label is wanted. */ -export function showTierLabel(canvas: HTMLCanvasElement, text: string): (() => void) | null { +export function showTierLabel( + canvas: HTMLCanvasElement, + text: string, + allowed: boolean +): (() => void) | null { const parent = canvas.parentElement; - if (!parent || !wanted()) return null; + if (!parent || !wanted(allowed)) return null; const el = document.createElement('div'); el.textContent = `terrain · ${text}`; Object.assign(el.style, { diff --git a/src/app/features/scene/tier.ts b/src/app/features/scene/tier.ts index 4a976081..ba338f37 100644 --- a/src/app/features/scene/tier.ts +++ b/src/app/features/scene/tier.ts @@ -24,6 +24,8 @@ export type SceneStyle = 'ridge' | 'raymarch' | 'terrain'; export interface BackgroundSceneConfig { tier?: SceneTier; style?: SceneStyle; + /** Let the page URL switch on the diagnostic overlays (`?probe=1`, `?tierlabel=1`) in a production build. Default: no. */ + debugOverlays?: boolean; } export function readCapabilities(nav: Navigator): Capabilities { diff --git a/src/app/pages/auth/footerBand.test.ts b/src/app/pages/auth/footerBand.test.ts index 9d196200..97febbbb 100644 --- a/src/app/pages/auth/footerBand.test.ts +++ b/src/app/pages/auth/footerBand.test.ts @@ -43,9 +43,17 @@ describe('the sign-in footer band, as emitted', () => { ]); }); - it('declares exactly these properties, so nothing else (a shadow, a prefixed override) rides along', async () => { + it('declares exactly these properties, so nothing else (a shadow, a stray override) rides along', async () => { const [rule] = declarations(await emitted(), over); + // -webkit-backdrop-filter is the one prefixed property, for Safari 14; it must blur exactly as the standard one does. + const blur = (prop: string) => + rule + .find((d) => d.startsWith(`${prop}:`)) + ?.split(':')[1] + .trim(); + expect(blur('-webkit-backdrop-filter')).toBe(blur('backdrop-filter')); expect(rule.map((d) => d.slice(0, d.indexOf(':'))).sort()).toEqual([ + '-webkit-backdrop-filter', 'backdrop-filter', 'background-color', 'background-color',