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
4 changes: 4 additions & 0 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
# Safari on iPhone runs WebKit; the Chrome acceptance above does not see its layout.
# Uses the build from test:browser.
- run: npx playwright install --with-deps webkit
- run: node scripts/quality.acceptance.mjs
- run: node scripts/webkit-layout.mjs
# The reference views (web/DESIGN.md, "Rebuild") for review on every PR.
- uses: actions/upload-artifact@v7.0.2
Expand Down Expand Up @@ -89,3 +90,6 @@ jobs:
env:
BASE_URL: https://proofofwork.fyi
EXPECT_POSTHOG: '1'
- run: node scripts/quality.acceptance.mjs
env:
BASE_URL: https://proofofwork.fyi
13 changes: 13 additions & 0 deletions web/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ decision, 2026-10-27):
"Mining" between races, "Re-mine block #K" during a repair. Nothing else: not "Start demo",
not during a race or a repeating run, not while typing, with Cmd/Ctrl/Alt, on key repeat or
under an open dialog.
Settings lets the learner disable this single-letter shortcut, including its
announcement, for speech input or assistive technology. The choice stays in this
browser; the mining button remains available.
- **Miner details** (Mirko, 2026-11-03, replaces the miner editor): a click on a miner's name
opens a **popover** under its lane, between races and during one: its **share** of the racing
miners' hashpower as a slider from 5 to 90 %, which is its chance to find the next block; the
Expand Down Expand Up @@ -597,6 +600,16 @@ Rules for every workbench component (`src/components/workbench/`):

## Guards

- Labs and the leaderboard view load on demand; the workbench starts without their
code or styles. `check:bundle` follows the build manifest's static imports and caps
initial gzip transfer at 255 KiB JavaScript and 25 KiB CSS.
- `test:quality` checks WCAG A/AA axe rules in both themes at 360 px and desktop,
plus the skip link, dialog focus return and shortcut preference. The skip link
focuses the current view without changing experiments. Explaining bubbles remain
hoverable; Escape dismisses chain explanations while preserving keyboard position.
- Accent labels use dark ink on the brighter dark-theme blue; muted text remains
readable on all panel surfaces. The light theme uses white labels on darker blue.

- `src/__tests__/designTokens.test.js` fails on any color literal (hex,
`rgb()`, `hsl()`) outside `src/styles/tokens.css`.
- The browser acceptance (`npm run test:browser`) writes the reference views
Expand Down
11 changes: 11 additions & 0 deletions web/package-lock.json

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

5 changes: 4 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"lint": "eslint .",
"preview": "vite preview",
"test": "vitest run",
"check": "npm run lint && npm test && npm run build",
"check": "npm run lint && npm test && npm run build && npm run check:bundle",
"check:bundle": "node scripts/check-bundle.mjs",
"test:quality": "npm run build && node scripts/quality.acceptance.mjs",
"deploy:check": "npm run build && wrangler deploy --env production --dry-run",
"deploy": "npm run build && wrangler deploy --env \"\"",
"deploy:production": "npm run build && wrangler deploy --env production",
Expand All @@ -31,6 +33,7 @@
"@types/react": "^19.2.5",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1",
"axe-core": "4.14.0",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
Expand Down
32 changes: 32 additions & 0 deletions web/scripts/check-bundle.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { gzipSync } from 'node:zlib';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

const dist = resolve(process.argv[2] || fileURLToPath(new URL('../dist', import.meta.url)));
const manifest = JSON.parse(await readFile(`${dist}/.vite/manifest.json`, 'utf8'));
const entries = Object.keys(manifest).filter(key => manifest[key].isEntry);
assert.ok(entries.length, 'Build manifest has no entry');
const files = new Set();
const visited = new Set();
function collect(key) {
if (visited.has(key)) return;
visited.add(key);
const chunk = manifest[key];
assert.ok(chunk, `Missing static dependency ${key}`);
files.add(chunk.file);
for (const css of chunk.css || []) files.add(css);
for (const dependency of chunk.imports || []) collect(dependency);
}
entries.forEach(collect);
const sizes = { js: 0, css: 0 };
for (const file of files) {
const kind = file.endsWith('.js') ? 'js' : file.endsWith('.css') ? 'css' : null;
if (kind) sizes[kind] += gzipSync(await readFile(resolve(dist, file))).length;
}
// e009022 eagerly shipped 265,995 bytes JS and 26,504 bytes CSS (gzip).
// Keep room above the split build while preventing a return to that payload.
assert.ok(sizes.js <= 255 * 1024, `Initial JavaScript ${sizes.js} exceeds 255 KiB gzip`);
assert.ok(sizes.css <= 25 * 1024, `Initial CSS ${sizes.css} exceeds 25 KiB gzip`);
console.log(JSON.stringify({ initialGzipBytes: sizes, files: [...files] }));
96 changes: 96 additions & 0 deletions web/scripts/quality.acceptance.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import assert from 'node:assert/strict';
import { chromium } from 'playwright';
import { createRequire } from 'node:module';
import { spawn } from 'node:child_process';
import { stripVTControlCharacters } from 'node:util';
import { fileURLToPath } from 'node:url';

const require = createRequire(import.meta.url);
const base = process.env.BASE_URL || 'http://127.0.0.1:4187';
const root = fileURLToPath(new URL('..', import.meta.url));
let server, browser;
try {
if (!process.env.BASE_URL) {
server = spawn(process.execPath, [fileURLToPath(new URL('../node_modules/vite/bin/vite.js', import.meta.url)), 'preview', '--host', '127.0.0.1', '--port', '4187', '--strictPort'], { cwd: root, stdio: ['ignore', 'pipe', 'pipe'] });
let log = '';
server.stdout.on('data', data => { log += data; });
server.stderr.on('data', data => { log += data; });
let ready = false;
for (let i = 0; i < 100; i++) {
if (server.exitCode !== null) throw new Error(`Preview exited: ${log}`);
try { if (stripVTControlCharacters(log).includes(base) && (await fetch(base)).ok) { ready = true; break; } } catch { /* Startup only. */ }
await new Promise(resolve => setTimeout(resolve, 100));
}
assert.ok(ready, `Preview did not start: ${log}`);
}
browser = await chromium.launch({ channel: 'chrome', headless: true });
for (const width of [360, 1512]) {
const context = await browser.newContext({ viewport: { width, height: 860 }, reducedMotion: 'reduce' });
await context.route(/^https:\/\/(eu\.i\.posthog\.com|api\.proofofwork\.fyi)\//, route => route.abort('connectionrefused'));
const page = await context.newPage();
const errors = [];
page.on('pageerror', error => errors.push(error.message));
const audit = async label => {
await page.addScriptTag({ path: require.resolve('axe-core/axe.min.js') });
const violations = await page.evaluate(async () => (await globalThis.axe.run(document, {
runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21aa', 'wcag22aa'] }
})).violations.map(v => ({ id: v.id, targets: v.nodes.map(node => node.target) })));
assert.deepEqual(violations, [], `${label} ${width}px`);
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), `${label}: horizontal overflow`);
};
for (const route of ['', '#/hash-lab', '#/chain-lab']) {
await page.goto(`${base}/${route}`);
await page.getByRole('main').waitFor();
if (route) await page.getByRole('button', { name: 'Back to simulator', exact: true }).waitFor();
const view = await page.getByRole('main').getAttribute('aria-label');
await page.getByRole('link', { name: 'Skip to content', exact: true }).focus();
await page.keyboard.press('Enter');
assert.equal(await page.evaluate(() => document.activeElement.id), 'workbench');
assert.equal(await page.getByRole('main').getAttribute('aria-label'), view);
for (const theme of ['dark', 'light']) {
await page.evaluate(theme => document.documentElement.setAttribute('data-theme', theme), theme);
await audit(`${route || 'workbench'} ${theme}`);
}
if (!route) {
const newTransaction = page.getByRole('button', { name: 'New transaction', exact: true });
await newTransaction.click();
await page.getByRole('button', { name: 'Cancel', exact: true }).focus();
await page.keyboard.press('Enter');
assert.equal(await newTransaction.evaluate(element => element === document.activeElement), true);
const miner = page.getByRole('button', { name: 'Hal: hashpower, attempts and name', exact: true });
await miner.click();
await page.getByRole('group', { name: 'Miner Hal', exact: true }).getByRole('button', { name: 'Done', exact: true }).click();
assert.equal(await miner.evaluate(element => element === document.activeElement), true);
if (width >= 1024) {
const face = page.locator('.chain-band-tile-face').first();
await page.keyboard.press('Tab');
await face.focus();
const explanation = page.getByRole('group', { name: 'Full hash of block 0', exact: true });
assert.equal(await explanation.isVisible(), true);
await page.keyboard.press('Escape');
assert.equal(await explanation.isVisible(), false);
assert.equal(await face.evaluate(element => element === document.activeElement), true);
}
}
}
await page.goto(`${base}/`);
await page.getByRole('button', { name: width < 768 ? 'Menu' : 'More', exact: true }).click();
await page.getByRole('button', { name: 'Reset', exact: true }).hover();
await page.getByRole('tooltip').waitFor();
await page.getByRole('button', { name: 'Settings', exact: true }).click();
await page.getByRole('dialog', { name: 'Settings', exact: true }).waitFor();
for (const theme of ['dark', 'light']) {
await page.evaluate(theme => document.documentElement.setAttribute('data-theme', theme), theme);
await audit(`Settings ${theme}`);
}
const shortcut = page.getByRole('checkbox', { name: 'Enable M to mine or re-mine a block', exact: true });
await shortcut.uncheck();
await page.keyboard.press('Escape');
assert.equal(await page.evaluate(() => document.activeElement.getAttribute('aria-label')), width < 768 ? 'Menu' : 'More');
await page.reload();
assert.equal(await page.evaluate(() => localStorage.getItem('proofofwork-mining-shortcut')), '0');
assert.deepEqual(errors, []);
await context.close();
}
console.log('Quality: WCAG A/AA axe checks in both themes, 360px/desktop, skip link, dialog focus return and shortcut preference passed');
} finally { await browser?.close(); server?.kill(); }
16 changes: 10 additions & 6 deletions web/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';
import { lazy, Suspense, useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';
import { useBlockchain } from './hooks/useBlockchain';
import { useMinerIdentity } from './hooks/useMinerIdentity';
import { playMiningSuccessSound, playRecordSound, unlockMiningAudio } from './lib/sound';
Expand All @@ -15,9 +15,6 @@ import { LowerDifficultyDialog } from './components/workbench/LowerDifficultyDia
import { Workbench } from './components/workbench/Workbench';
import { MissionRail } from './components/workbench/MissionRail';
import { MissionIntro } from './components/workbench/MissionIntro';
import { HashLab } from './components/HashLab';
import { ChainLab } from './components/ChainLab';
import { PoolPanel } from './components/PoolPanel';
import { minerProfileHash, POOL_HASH } from './lib/poolApi';
import { BlockDetailsModal } from './components/BlockDetailsModal';
import { ParticipantDetailsModal } from './components/ParticipantDetailsModal';
Expand All @@ -29,6 +26,11 @@ import './index.css';
import { adjustedDifficulty, averagePace, checkWindowStart, isCheckHeight } from './lib/difficulty';
import { DEFAULT_FEE_RATE } from './lib/blockchain';

// Free play starts on the workbench; other experiments load when opened.
const HashLab = lazy(() => import('./components/HashLab').then(module => ({ default: module.HashLab })));
const ChainLab = lazy(() => import('./components/ChainLab').then(module => ({ default: module.ChainLab })));
const PoolPanel = lazy(() => import('./components/PoolPanel').then(module => ({ default: module.PoolPanel })));

const INITIAL_CONFIG = {
name: 'powfyicoin', miningDifficulty: 4, blockReward: 3.125, halvingEvent: 21,
participants: ['Alice', 'Bob', 'Chris', 'Hal', 'Dorian', 'Laszlo'], miners: ['Hal', 'Dorian', 'Laszlo']
Expand Down Expand Up @@ -447,7 +449,7 @@ function App() {
return (
<div className={`app-shell${view === 'workbench' ? ' is-workbench' : ''}${view === 'workbench' && drawerMiner ? ' has-miner-drawer' : ''}${railCollapsed ? ' is-rail-collapsed' : ' is-rail-expanded'}`}
onClickCapture={prepareSound} onKeyDownCapture={prepareSound}>
<a className="skip-link" href="#workbench">Skip to workbench</a>
<a className="skip-link" href="#workbench" onClick={event => { event.preventDefault(); document.getElementById('workbench')?.focus(); }}>Skip to content</a>
<HintLayer />
<TopBar view={view} onNavigate={navigate} coinName={coinName} theme={theme} onTheme={changeTheme}
muted={muted} onMuted={changeMuted} onReset={reset} onOpenSettings={() => setShowSettings(true)} compact={compact} saveState={sim.saveState} />
Expand All @@ -457,7 +459,7 @@ function App() {
<div className="wb-rail">
<MissionRail progress={progress} collapsed={railCollapsed} onToggle={toggleRail} onShowMe={showMe} highlight={showIntro} />
</div>
<main id="workbench" className="wb-main" aria-label={VIEW_LABELS[view]}>
<main id="workbench" tabIndex={-1} className="wb-main" aria-label={VIEW_LABELS[view]}>
<div className="wb-mbar"><MissionRail progress={progress} variant="bar" collapsed={railCollapsed}
onToggle={toggleRail} onShowMe={showMe} highlight={showIntro} /></div>
{showIntro && <MissionIntro onStart={startMissions} onDismiss={dismissIntro} />}
Expand All @@ -471,6 +473,7 @@ function App() {
onDifficulty={onDifficulty} onBack={onBack} onCreateTransaction={onCreateTransaction} onCreateWallet={createWallet} onCreateMiner={createMiner}
onRenameMiner={onRenameMiner} onShare={setMinerShare} onOpenMiner={openMiner} onSlowMotion={setSlowMotion}
onOpenWallet={setWalletDetails} onOpenDetails={setDetails} onOpenTransaction={setPendingTx} onOpenBlockTx={(transaction, blockIndex) => setBlockTx({ transaction, blockIndex })} onOpenChainLab={() => navigate('chain-lab')} error={error} />}
<Suspense fallback={<p role="status">Loading {VIEW_LABELS[view]}…</p>}>
{view === 'hash-lab' && <div className="wb-view">
<HashLab key={hashLesson ?? 'free'} lesson={hashLesson} onLessonEvent={hashLesson ? report : undefined}
coach={hashLesson ? coach : null} onClose={() => navigate('workbench')}
Expand All @@ -483,6 +486,7 @@ function App() {
{view === 'pool' && <div className="wb-view"><PoolPanel name={identity.name} onNameChange={identity.setName} refreshKey={boardKey}
onAccepted={onBlockAccepted} onClose={() => navigate('workbench')}
profile={profile} onOpenProfile={openProfile} onCloseProfile={closeProfile} /></div>}
</Suspense>
</main>
</div>
{winner && <div key={winner.id} className="wb-announce" role="status"><span className="wb-found-cube" aria-hidden="true" /><span>{winner.name} mined a block</span></div>}
Expand Down
4 changes: 2 additions & 2 deletions web/src/__tests__/AppMissions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ describe('optional missions in App', () => {
expect(collapsed()).toBe(true);
});

it('remembers dismissal, while the page and free labs stay usable', () => {
it('remembers dismissal, while the page and free labs stay usable', async () => {
render(<App />);
fireEvent.click(screen.getByRole('button', { name: "Don't show again" }));
expect(intro()).toBeNull();
fireEvent.click(screen.getByRole('button', { name: 'Hash lab', exact: true }));
expect(screen.getByText('Free hash lab')).toBeTruthy();
expect(await screen.findByText('Free hash lab')).toBeTruthy();
expect(screen.getByText('No coach')).toBeTruthy();
fireEvent.click(screen.getByRole('button', { name: 'Complete manual proof' }));
expect(JSON.parse(localStorage.getItem(STORAGE_KEY)).completed).toEqual([]);
Expand Down
Loading
Loading