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
28 changes: 19 additions & 9 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ jobs:

- run: npm ci --no-audit --no-fund
- run: npm run typecheck
- run: npm test
- name: Install browser for production audio cache check
run: npx playwright install --with-deps chromium
- name: Run unit tests and install Chromium
run: |
# Vitest needs no browser. Overlap it with Playwright's package and browser downloads.
npx playwright install --with-deps chromium &
browser_install_pid=$!
status=0
npm test || status=$?
wait "$browser_install_pid" || status=$?
exit "$status"
- name: Verify lazy audio caching in the production build
run: npm run test:audio-cache
- name: Verify editor ownership across game sessions
- name: Verify production browser sessions and room rendering
env:
PLAYWRIGHT_BASE_URL: http://127.0.0.1:5183
run: |
Expand All @@ -62,11 +68,15 @@ jobs:
fi
sleep 1
done
node node_modules/@playwright/test/cli.js test tests/browser/editor-ownership.spec.ts tests/browser/room-semantics.spec.ts tests/browser/room-exposure.spec.ts tests/browser/room-bounce-level.spec.ts --workers=1 --reporter=line
- name: Verify browser session ownership and visitor privacy in the production build
run: |
node scripts/check-browser-sessions.mjs
node scripts/check-client-recovery.mjs
node node_modules/@playwright/test/cli.js test tests/browser/editor-ownership.spec.ts tests/browser/room-semantics.spec.ts tests/browser/room-exposure.spec.ts --workers=1 --reporter=line

# The lighting test uses its own browser and can bake while the session checks run.
node node_modules/@playwright/test/cli.js test tests/browser/room-bounce-level.spec.ts --workers=1 --reporter=line --output "$RUNNER_TEMP/room-bounce-test-results" &
room_bounce_pid=$!
status=0
(node scripts/check-browser-sessions.mjs && node scripts/check-client-recovery.mjs) || status=$?
wait "$room_bounce_pid" || status=$?
exit "$status"
- name: Verify keyboard accessibility in the production build
run: npm run test:a11y

Expand Down
31 changes: 31 additions & 0 deletions agent-notes/perf-ci-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# CI and build performance

## Goal

Reduce React Client CI and build times while preserving checks, build behavior, and deployment behavior. Work in the separate `perf/ci-build` worktree.

## State

Implemented in `C:/Users/Q/code/react-client-ci-build` on `perf/ci-build`, based on `origin/master`. CI overlaps Chromium provisioning with Vitest and the existing Living Room lighting test with the browser-session and recovery checks. Both groups wait for the background command and fail if either foreground or background work fails. The recovery journey advances the browser clock through the real 15-second timeout and still requires one reconnect, owner restoration and a successful follow-up ping. The normal minified build uses a token-boundary map for commit comments. Development, explicit sourcemaps and unminified builds use the original transform.

Local verification used the hosted Node and npm versions. Actionlint, zizmor, Bash failure-path checks, the recovery journey and the real Chromium lighting check passed. Recovery went from 29.2 to 12.9 seconds. Lighting and recovery passed together in 51.4 seconds. Two interleaved pairs comparing the final Vite transform against the original averaged 18.9 to 16.8 seconds wall time. All 96 files in `dist` matched byte for byte in all four builds and in the final `npm run build`. The two existing Rollup diagnostics retained their original line and column.

## Decisions and why

Preserve every check and its assertions, separate browser contexts, the Playwright version and Chromium modes, the production build and service worker behavior, workflow triggers, and deployment of the exact checked artifact. The manual Safari decode probe is a separate experiment from the PR and master build path.

The latest 30 runs contain 16 successful PR runs (177–373 seconds, median 245) and 11 successful master runs (224–307 seconds, median 242, including deploy). In 14 sampled job logs, step ranges were 52–102 seconds for Vitest, 17–40 for Chromium setup, 30–33 for session ownership and recovery, 18–25 for accessibility, 7–18 for npm install, 5–10 for typechecking, and 10–22 for workflow audits.

Baseline examples: [latest master run](https://github.com/MongooseMoo/react-client/actions/runs/46225083695/job/141228206105), [matching PR](https://github.com/MongooseMoo/react-client/actions/runs/46224645488/job/141226841658), and [earlier PR before the bounce regression joined CI](https://github.com/MongooseMoo/react-client/actions/runs/46190423710/job/141119703654).

The [current master baseline](https://github.com/MongooseMoo/react-client/actions/runs/46228999253) ran 230 Vitest files and 3,586 tests. The lighting regression occupied 52 seconds, the recovery journey 27 seconds, and the main Vite build 8.91 seconds. Keeping the existing runner and Chromium provisioning avoids adding an image download, another runner, or a cache. Both concurrent commands must succeed before the first browser check.

## Surprises

The latest master log shows 60 seconds between starting the Living Room light-bounce test and starting the next test. `src/map/roomBounce.ts` spreads the bake over animation frames for interactive use. The regression checks the final rendered illuminance. The latest master also spent 26 seconds installing Linux browser dependencies before the first browser download. The PR and master samples measured about 10.3 and 8.7 seconds respectively for the main Vite build, plus about 0.2 seconds each for the separate service worker build. Production builds already run once per workflow, and Pages publishes the checked artifact. In the latest master run, Vitest reported 229 files and 3,585 tests.

The Vite CPU profile showed that `vite-plugin-commit-hash` generates per-character maps for JS and CSS just to prepend a comment. Omitting the comment changed generated JavaScript filenames and the precache manifest. Keeping the comment without a map shifted diagnostic lines. The final transform keeps the plugin's exact prefix and maps token boundaries with the existing locked MagicString version. A faster test-only lighting scheduler saved under two seconds in one local comparison. The final workflow retains the existing lighting scheduler and overlaps the original check with independent browser work.

## Next step

Verify the pull request on GitHub Actions and compare individual stages to the master baseline before merging. Keep the full Vitest suite and current browser runtime settings unless hosted measurements justify tuning.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"fake-indexeddb": "^6.2.5",
"husky": "^9.1.7",
"jsdom": "^26.1.0",
"magic-string": "^0.30.21",
"tsx": "^4.23.15",
"typescript": "^5.9.3",
"vite": "^6.4.2",
Expand Down
9 changes: 9 additions & 0 deletions scripts/check-client-recovery.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ try {
}, 100);
});
const page = await context.newPage();
await page.clock.install();
await page.goto(origin);
await expect.poll(() => page.evaluate(() => window.mudClient?.gmcp.require('Auth.Autologin').currentGrant?.playerUuid)).toBe(owner.uuid);
// A reconnect must retain the in-memory log even when its debounced save fails.
Expand Down Expand Up @@ -179,10 +180,18 @@ try {
await page.getByRole('button', { name: 'Resume owner', exact: true }).click();
await expect(command).toBeVisible();
await expect(page.getByText('Saved data is restored. Notifications remain paused; enable browser notifications when you want them.')).toBeVisible();
// Drive the production ping timeout without waiting 15 wall-clock seconds.
await page.clock.pauseAt(Date.now() + 1000);
const oldConnections = sockets.length;
dropNextPing = true;
await page.evaluate(() => window.mudClient.latency.probe());
await expect.poll(() => dropNextPing).toBe(false);
await page.clock.runFor(14_999);
assert.equal(sockets.length, oldConnections);
assert.equal(await page.evaluate(() => window.mudClient.connected), true);
await page.clock.runFor(1);
await expect.poll(() => sockets.length, { timeout: 22000 }).toBe(oldConnections + 1);
await page.clock.resume();
await expect(page.locator('.status-latency')).toContainText(/Ping: \d+ ms/);
await expect.poll(() => page.evaluate(() => window.mudClient.gmcp.require('Auth.Autologin').currentGrant?.playerUuid)).toBe(owner.uuid);
assert.equal(sockets.length, oldConnections + 1);
Expand Down
19 changes: 17 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import preact from '@preact/preset-vite';
import { defineConfig, loadEnv } from 'vite';
import MagicString from 'magic-string';
import { defineConfig, loadEnv, type Plugin } from 'vite';
import { CommitHashPlugin } from 'vite-plugin-commit-hash';
import { VitePWA } from 'vite-plugin-pwa';
import { lazyPackagesAtStartup, optionalChunks } from './src/build/optionalChunks';
Expand All @@ -9,10 +10,24 @@ let deferredChunks = new Set<string>();

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), 'VITE_');
const upstreamCommitHash = CommitHashPlugin();
const commitHash: Plugin = upstreamCommitHash;
const prependCommitComment = upstreamCommitHash.transform;
commitHash.configResolved = ({ command, build }) => {
if (command === 'build' && build.minify === 'esbuild' && build.cssMinify && !build.sourcemap) {
// Keep the commit comment and diagnostic locations without mapping every character.
commitHash.transform = (code, id) => {
const comment = prependCommitComment('', id);
if (!comment) return null;
const source = new MagicString(code).prepend(comment.code);
return { code: source.toString(), map: source.generateMap({ source: id, hires: 'boundary' }) };
};
}
};
return {
plugins: [
preact(),
CommitHashPlugin(),
commitHash,
{
name: 'optional-feature-precache',
apply: 'build',
Expand Down