Diagnostic overlays (?probe=1, ?tierlabel=1) only where allowed; footer band test knows the Safari prefix
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled

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 <noreply@anthropic.com>
This commit is contained in:
Void 2026-11-10 14:05:42 +00:00
commit 814fa4b3ab
10 changed files with 123 additions and 18 deletions

View file

@ -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);
});
});

View file

@ -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';

View file

@ -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<SceneOptions, 'tier' | 'patchSource' | 'onCompil
async function create(
config: BackgroundSceneConfig | undefined,
options: StartOptions & { tier: SceneTier },
options: StartOptions & { tier: SceneTier; debug?: boolean },
state: SkyState
): Promise<Scene | null> {
let createScene: (o: SceneOptions) => Scene | null;
@ -82,7 +83,8 @@ export async function startBackgroundScene(
): Promise<Scene | null> {
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);

View file

@ -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;

View file

@ -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<SceneOptions, 'canvas' | 'tier'> & {
/** 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;

View file

@ -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);

View file

@ -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();
});
});

View file

@ -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, {

View file

@ -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 {

View file

@ -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',