Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/browser-smoke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Real browser playability smoke
on:
pull_request:
branches: [main]
paths:
- 'experiments/**'
- '.github/workflows/browser-smoke.yml'
push:
branches: [main]
paths:
- 'experiments/**'
- '.github/workflows/browser-smoke.yml'
permissions:
contents: read
jobs:
chromium-smoke:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install browser test dependency
run: npm install --no-save --no-package-lock [email protected]
- name: Install headless Chromium
run: npx playwright install --with-deps chromium
- name: Launch and exercise both games on desktop and mobile
run: node experiments/tests/browser-smoke.mjs
- name: Upload screenshots for debugging
if: always()
uses: actions/upload-artifact@v4
with:
name: game-browser-screenshots
path: experiments/browser-artifacts/
if-no-files-found: warn
retention-days: 3
108 changes: 108 additions & 0 deletions experiments/tests/browser-smoke.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Actual Chromium runtime smoke tests, separate from Node syntax checks.
// Run with: npm install --no-save playwright && npx playwright install chromium && node experiments/tests/browser-smoke.mjs
import { chromium } from 'playwright';
import { createServer } from 'node:http';
import { readFile, mkdir } from 'node:fs/promises';
import { extname, resolve, relative, sep, join } from 'node:path';
import { once } from 'node:events';

const root = resolve('.');
const screenshots = resolve('experiments', 'browser-artifacts');
await mkdir(screenshots, { recursive: true });
const types = { '.html': 'text/html; charset=utf-8', '.css': 'text/css; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.mjs': 'text/javascript; charset=utf-8', '.json': 'application/json' };
const server = createServer(async (req, res) => {
try {
const url = new URL(req.url || '/', 'http://localhost');
const pathname = decodeURIComponent(url.pathname);
if (pathname === '/favicon.ico') { res.writeHead(204).end(); return; }
const path = resolve(root, '.' + pathname, pathname.endsWith('/') ? 'index.html' : '');
const rel = relative(root, path);
if (rel === '..' || rel.startsWith('..' + sep) || path === root) { res.writeHead(403).end('Forbidden'); return; }
const bytes = await readFile(path);
res.writeHead(200, { 'content-type': types[extname(path)] || 'application/octet-stream', 'cache-control': 'no-store' }).end(bytes);
} catch (e) { res.writeHead(404).end('Not found'); }
});
server.listen(0, '127.0.0.1');
await once(server, 'listening');
const origin = 'http://127.0.0.1:' + server.address().port;
let browser;
const results = [];
try {
browser = await chromium.launch({
headless: true,
args: ['--enable-webgl', '--use-gl=angle', '--use-angle=swiftshader', '--ignore-gpu-blocklist', '--disable-dev-shm-usage']
});
for (const game of ['voxel-frontier', 'neon-streets']) {
for (const mode of ['desktop', 'mobile']) {
const mobile = mode === 'mobile';
const context = await browser.newContext({
viewport: mobile ? { width: 390, height: 844 } : { width: 1280, height: 800 },
isMobile: mobile,
hasTouch: mobile,
deviceScaleFactor: 1
});
const page = await context.newPage();
const errors = [];
page.on('pageerror', e => errors.push('Uncaught: ' + e.message));
page.on('console', m => { if (m.type() === 'error') errors.push('Console: ' + m.text()); });
page.on('requestfailed', req => errors.push('Network: ' + req.url() + ' ' + (req.failure()?.errorText || 'failed')));
try {
const response = await page.goto(origin + '/experiments/' + game + '/', { waitUntil: 'domcontentloaded', timeout: 30000 });
if (!response?.ok()) throw new Error('Entrypoint returned ' + response?.status());
const canvas = page.locator(game === 'voxel-frontier' ? '#game canvas' : '#canvas');
await canvas.waitFor({ state: 'visible', timeout: 30000 });
await page.waitForTimeout(game === 'voxel-frontier' ? 1800 : 350);
const state = await canvas.evaluate(c => {
const rect = c.getBoundingClientRect();
const isVoxel = Boolean(c.closest('#game'));
const gl = isVoxel ? c.getContext('webgl2') : null;
const ctx = isVoxel ? null : c.getContext('2d');
return { width: rect.width, height: rect.height, backingWidth: c.width, backingHeight: c.height,
webgl: Boolean(gl && !gl.isContextLost()), canvas2d: Boolean(ctx),
pixel: ctx ? Array.from(ctx.getImageData(Math.floor(c.width / 2), Math.floor(c.height / 2), 1, 1).data) : null };
});
if (state.width < 200 || state.height < 200 || state.backingWidth < 200 || state.backingHeight < 200) {
throw new Error('Canvas missing or incorrectly sized: ' + JSON.stringify(state));
}
if (game === 'voxel-frontier' && !state.webgl) throw new Error('Three.js did not establish a live WebGL2 context');
if (game === 'neon-streets' && (!state.canvas2d || !state.pixel || state.pixel[3] === 0)) throw new Error('Canvas 2D did not draw');
if (mobile) await page.locator('#play').tap();
else await page.locator('#play').click();
await page.waitForFunction(() => document.querySelector('#start')?.classList.contains('hidden'), null, { timeout: 5000 });
if (game === 'neon-streets') {
if (mobile) {
const button = page.locator('[data-key="ArrowUp"]');
await button.dispatchEvent('pointerdown', { pointerId: 1, bubbles: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use a real active pointer for the mobile throttle

In the mobile Neon Streets run, dispatchEvent creates a synthetic DOM event but does not register pointerId: 1 as an active browser pointer. The game's pointerdown handler consequently throws NotFoundError when it calls setPointerCapture(1); the pageerror listener records that exception and the check at the end marks every mobile run as failed even if acceleration succeeds. Drive this with a real Playwright pointer/touch action, or otherwise avoid triggering pointer capture with an inactive synthetic pointer.

Useful? React with 👍 / 👎.

await page.waitForTimeout(700);
await button.dispatchEvent('pointerup', { pointerId: 1, bubbles: true });
} else {
await page.keyboard.down('ArrowUp');
await page.waitForTimeout(700);
await page.keyboard.up('ArrowUp');
}
const speed = Number((await page.locator('#speed').innerText()).match(/\d+/)?.[0] || 0);
if (speed < 1) throw new Error('Throttle input did not accelerate vehicle');
} else if (!mobile) {
await page.keyboard.press('Digit2');
const selected = await page.locator('#hotbar button.active').getAttribute('data-block');
if (selected !== 'stone') throw new Error('Hotbar selection did not respond to keyboard');
}
await page.waitForTimeout(300);
await page.screenshot({ path: join(screenshots, game + '-' + mode + '.png') });
if (errors.length) throw new Error(errors.join('\n').slice(0, 2000));
results.push({ game, mode, status: 'PASS', ...state });
} catch (e) {
try { await page.screenshot({ path: join(screenshots, game + '-' + mode + '-FAILED.png') }); } catch {}
results.push({ game, mode, status: 'FAIL', error: String(e) });
process.exitCode = 1;
} finally {
await context.close();
}
}
}
} finally {
await browser?.close();
await new Promise(resolve => server.close(resolve));
}
for (const result of results) console.log(JSON.stringify(result));
if (process.exitCode) console.error('Browser smoke FAILED: see screenshots and errors above.');
22 changes: 22 additions & 0 deletions experiments/tests/script-loading.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { existsSync, readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
for (const game of ['voxel-frontier', 'neon-streets']) {
test(game + ': HTML script mode matches JavaScript import syntax', () => {
const dir = resolve(root, game);
const html = readFileSync(resolve(dir, 'index.html'), 'utf8');
const js = readFileSync(resolve(dir, 'game.js'), 'utf8');
const script = [...html.matchAll(/<script\b([^>]*)><\/script>/g)].find(match => /\bsrc=["']\.\/game\.js["']/.test(match[1]));
assert.ok(script, 'game.js must be loaded by a script tag');
const moduleScript = /\btype=["']module["']/.test(script[1]);
const staticImports = /^\s*import\s+(?:[\s\S]*?\s+from\s+)?['"][^'"]+['"]\s*;?/m.test(js);
assert.ok(!staticImports || moduleScript, 'game.js has static imports but index.html uses a classic script: browser SyntaxError');
for (const match of js.matchAll(/(?:from\s*|import\s*\(\s*)['"](\.[^'"]+)['"]/g)) {
assert.ok(existsSync(resolve(dir, match[1])), 'Missing local import: ' + match[1]);
}
});
}
Loading