Web version: what the browser lacks is not offered, files dropped on the window, checks, docs
The interface hides what the platform does not have (platform::CAPS): play, new databases, adding to a database, preparation, translation, their shortcuts and the Translation tab. Files dropped on the window open like chosen ones (in a browser; the desktop program takes no drops, as before), with «Release to open» while they are dragged over it. /app/: ?phone=android and ?phone=ios show those variants of the device page. apps/web/check: device.test.mjs (14 devices: computer, iPhone, iPad as a Mac, Android phone and tablet, desktop-site modes, Chromebook, touch laptop) and app.mjs (headless Firefox: the device page in three languages without the program, the program, a PGN opened by Ctrl+O and the file chooser, a dropped PGN, a game of the classics, moves, «Download PGN», e2-e4 on the board, the settings after a reload). All pass. docs/dev/web.md: the architecture, the platform layer, what is not built for a browser, the build and the checks, what comes next; docs/dev/uci.md and desktop.md updated, web/README.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3e69a5d57c
commit
30eac472ff
13 changed files with 501 additions and 32 deletions
160
apps/web/check/app.mjs
Normal file
160
apps/web/check/app.mjs
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
// The web version in headless Firefox: the page for phones, the program, opening a PGN
|
||||
// by its button (Ctrl+O) and by dropping it, a game from the classics, moves, a
|
||||
// download of the PGN. Screenshots go to <out-dir>; what is checked is printed.
|
||||
//
|
||||
// node apps/web/check/app.mjs <app-dir> <out-dir> (app-dir: apps/web/build.sh's)
|
||||
import { spawn } from 'node:child_process';
|
||||
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { launch } from './firefox.mjs';
|
||||
import { sleep, tab } from './bidi.mjs';
|
||||
|
||||
const [appDir, outDir] = process.argv.slice(2).map((p) => resolve(p));
|
||||
const root = fileURLToPath(new URL('../../..', import.meta.url));
|
||||
mkdirSync(outDir, { recursive: true });
|
||||
const port = 18766;
|
||||
const server = spawn('python3', ['-I', join(root, 'apps/web/check/serve.py'), appDir, join(root, 'website/static'), String(port)], { stdio: 'ignore' });
|
||||
const base = `http://127.0.0.1:${port}/app/`;
|
||||
|
||||
let failures = 0;
|
||||
const check = (ok, what) => {
|
||||
console.log(`${ok ? 'ok ' : 'FAIL'} ${what}`);
|
||||
if (!ok) failures++;
|
||||
};
|
||||
const errors = [];
|
||||
const log = (line) => {
|
||||
if (/panicked|RuntimeError|did not start|\[error\]/.test(line)) errors.push(line);
|
||||
};
|
||||
|
||||
const ff = await launch(19223);
|
||||
const shot = async (t, name) => writeFileSync(join(outDir, name), await t.screenshot());
|
||||
const key = (value, mods = []) => {
|
||||
const down = mods.map((m) => ({ type: 'keyDown', value: m }));
|
||||
const up = mods.map((m) => ({ type: 'keyUp', value: m })).reverse();
|
||||
return [...down, { type: 'keyDown', value }, { type: 'keyUp', value }, ...up, { type: 'pause', duration: 80 }];
|
||||
};
|
||||
const CTRL = '';
|
||||
const RIGHT = '';
|
||||
const click = (x, y, count = 1) => {
|
||||
const acts = [{ type: 'pointerMove', x, y }];
|
||||
for (let i = 0; i < count; i++) acts.push({ type: 'pointerDown', button: 0 }, { type: 'pointerUp', button: 0 });
|
||||
return [{ type: 'pointer', id: 'mouse', parameters: { pointerType: 'mouse' }, actions: acts }];
|
||||
};
|
||||
const started = (t) => t.waitFor(`document.getElementById('cp-status').hidden && !document.getElementById('cp-app').hidden`, 30000);
|
||||
|
||||
try {
|
||||
// ----- the page for phones and tablets, without the program ------------------------------
|
||||
{
|
||||
const t = await tab(ff.browser, 390, 844, log);
|
||||
await t.navigate(`${base}?phone=1&lang=ru`);
|
||||
await sleep(800);
|
||||
const text = await t.evaluate(`document.getElementById('cp-device').innerText`);
|
||||
check(/ChessPenguin на телефоне и планшете/.test(text), 'the device page in Russian');
|
||||
check(/Всё равно открыть веб-версию/.test(text), 'with «open the web version anyway»');
|
||||
const wasm = await t.evaluate(`performance.getEntriesByType('resource').some(e => e.name.endsWith('.wasm'))`);
|
||||
check(!wasm, 'the program is not downloaded on it');
|
||||
await shot(t, 'web-phone-ru.png');
|
||||
await t.navigate(`${base}?phone=1&lang=de`);
|
||||
await sleep(500);
|
||||
check(/auf Handy und Tablet/.test(await t.evaluate(`document.getElementById('cp-device').innerText`)), 'the device page in German');
|
||||
await t.navigate(`${base}?phone=android&lang=ru`);
|
||||
await sleep(800);
|
||||
check(/Скачать для Android/.test(await t.evaluate(`document.getElementById('cp-device').innerText`)), 'the Android variant');
|
||||
await shot(t, 'web-phone-android-ru.png');
|
||||
await t.navigate(`${base}?phone=ios&lang=en`);
|
||||
await sleep(800);
|
||||
check(/iPhone and iPad app is coming soon/.test(await t.evaluate(`document.getElementById('cp-device').innerText`)), 'the iPhone and iPad variant');
|
||||
await shot(t, 'web-phone-ios-en.png');
|
||||
}
|
||||
|
||||
// ----- the program -------------------------------------------------------------------------
|
||||
const t = await tab(ff.browser, 1400, 860, log);
|
||||
await t.navigate(`${base}?lang=en`);
|
||||
await started(t);
|
||||
await sleep(2500);
|
||||
check(true, 'the program started (WebGL canvas, no error)');
|
||||
await shot(t, 'web-1-library.png');
|
||||
|
||||
// Open a PGN by the button's shortcut: the browser's file chooser gets the file.
|
||||
const pgn = join(ff.profile, 'Test games.pgn');
|
||||
copyFileSync(join(root, 'examples/alekhine.pgn'), pgn);
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: key('o', [CTRL]) }]);
|
||||
await t.waitFor(`!!document.getElementById('cp-open-files')`, 5000);
|
||||
const input = await ff.browser.send('script.evaluate', {
|
||||
expression: `document.getElementById('cp-open-files')`,
|
||||
target: { context: t.context },
|
||||
awaitPromise: false,
|
||||
});
|
||||
await ff.browser.send('input.setFiles', { context: t.context, element: { sharedId: input.result.sharedId }, files: [pgn] });
|
||||
await sleep(2500);
|
||||
await shot(t, 'web-2-opened.png');
|
||||
|
||||
// Drop a file on the window.
|
||||
const dropped = readFileSync(join(root, 'examples/classics.pgn'), 'utf8');
|
||||
await t.evaluate(`(() => {
|
||||
const dt = new DataTransfer();
|
||||
dt.items.add(new File([${JSON.stringify(dropped)}], 'Dropped classics.pgn', { type: 'application/x-chess-pgn' }));
|
||||
const c = document.getElementById('cp-canvas');
|
||||
for (const type of ['dragenter', 'dragover', 'drop'])
|
||||
c.dispatchEvent(new DragEvent(type, { dataTransfer: dt, bubbles: true, cancelable: true, clientX: 700, clientY: 400 }));
|
||||
return true;
|
||||
})()`);
|
||||
await sleep(2500);
|
||||
await shot(t, 'web-3-dropped.png');
|
||||
|
||||
// The classics: a game opens from the table (double click), its moves on the board.
|
||||
await t.actions(click(Number(process.env.CLASSICS_X || 100), Number(process.env.CLASSICS_Y || 70)));
|
||||
await sleep(1500);
|
||||
await t.actions(click(300, Number(process.env.ROW_Y || 322), 2));
|
||||
await sleep(1500);
|
||||
await shot(t, 'web-4-game.png');
|
||||
const steps = [];
|
||||
for (let i = 0; i < 12; i++) steps.push(...key(RIGHT));
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: steps }]);
|
||||
await sleep(800);
|
||||
await shot(t, 'web-5-moves.png');
|
||||
|
||||
// Download the PGN of the game (the header's button).
|
||||
await t.actions(click(Number(process.env.DOWNLOAD_X || 1180), Number(process.env.DOWNLOAD_Y || 22)));
|
||||
await sleep(2000);
|
||||
const files = existsSync(ff.downloads) ? readdirSync(ff.downloads).filter((f) => f.endsWith('.pgn')) : [];
|
||||
check(files.length === 1, `a PGN downloaded: ${files.join(', ') || 'none'}`);
|
||||
if (files.length) {
|
||||
const text = readFileSync(join(ff.downloads, files[0]), 'utf8');
|
||||
check(/\[White "/.test(text) && /1\. /.test(text), 'the download is the game in PGN');
|
||||
writeFileSync(join(outDir, 'web-download.pgn'), text);
|
||||
}
|
||||
await shot(t, 'web-6-downloaded.png');
|
||||
|
||||
// A move on the board of a new game (Ctrl+N): e2–e4 by two clicks.
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: key('') }]);
|
||||
await sleep(500);
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: key('') }]);
|
||||
await sleep(800);
|
||||
await t.actions([{ type: 'key', id: 'kb', actions: key('n', [CTRL]) }]);
|
||||
await sleep(1200);
|
||||
await shot(t, 'web-7-new-game.png');
|
||||
if (process.env.E2 && process.env.E4) {
|
||||
const [x2, y2] = process.env.E2.split(',').map(Number);
|
||||
const [x4, y4] = process.env.E4.split(',').map(Number);
|
||||
await t.actions(click(x2, y2));
|
||||
await sleep(300);
|
||||
await t.actions(click(x4, y4));
|
||||
await sleep(1000);
|
||||
await shot(t, 'web-8-e4.png');
|
||||
}
|
||||
|
||||
// The settings and the marks survive a reload (the browser's storage).
|
||||
await t.navigate(`${base}?lang=en`);
|
||||
await started(t);
|
||||
await sleep(2500);
|
||||
await shot(t, 'web-9-reloaded.png');
|
||||
} finally {
|
||||
await ff.stop();
|
||||
server.kill();
|
||||
}
|
||||
for (const e of errors) console.log('console:', e);
|
||||
check(errors.length === 0, 'no panic or error in the console');
|
||||
console.log(failures ? `${failures} failed` : 'all ok');
|
||||
process.exit(failures ? 1 : 0);
|
||||
49
apps/web/check/device.test.mjs
Normal file
49
apps/web/check/device.test.mjs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// Which devices get the program and which the page about the apps (page/device.js):
|
||||
//
|
||||
// node apps/web/check/device.test.mjs
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const source = readFileSync(fileURLToPath(new URL('../page/device.js', import.meta.url)), 'utf8');
|
||||
|
||||
// device.js in a window that looks like `d`.
|
||||
function classOf(d) {
|
||||
const media = { '(pointer: coarse)': d.coarse, '(any-pointer: fine)': d.fine };
|
||||
const window = {
|
||||
navigator: { userAgent: d.ua, platform: d.platform || '', maxTouchPoints: d.touch || 0, userAgentData: d.uad },
|
||||
screen: { width: d.screen[0], height: d.screen[1] },
|
||||
matchMedia: (q) => ({ matches: !!media[q] }),
|
||||
};
|
||||
window.window = window;
|
||||
vm.runInNewContext(source, window);
|
||||
return window.CPDevice.deviceClass();
|
||||
}
|
||||
|
||||
const MAC = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15';
|
||||
const cases = [
|
||||
['Windows laptop', { ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Firefox/159.0', screen: [1920, 1080], fine: true }, 'computer'],
|
||||
['Mac', { ua: MAC, platform: 'MacIntel', screen: [1512, 982], fine: true }, 'computer'],
|
||||
['laptop with a touch screen', { ua: 'Mozilla/5.0 (X11; Linux x86_64) Chrome/140.0', screen: [1366, 768], touch: 10, coarse: false, fine: true }, 'computer'],
|
||||
['Chromebook', { ua: 'Mozilla/5.0 (X11; CrOS x86_64 15000.0.0) Chrome/140.0', screen: [1366, 768], touch: 5, coarse: true }, 'computer'],
|
||||
['iPhone', { ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) Mobile/15E148', screen: [390, 844], touch: 5, coarse: true }, 'iphone'],
|
||||
['iPhone asking for the desktop site', { ua: MAC, platform: 'MacIntel', screen: [390, 844], touch: 5, coarse: true }, 'iphone'],
|
||||
['iPad (says it is a Mac)', { ua: MAC, platform: 'MacIntel', screen: [820, 1180], touch: 5, coarse: true }, 'ipad'],
|
||||
['iPad mini', { ua: MAC, platform: 'MacIntel', screen: [744, 1133], touch: 5, coarse: true }, 'ipad'],
|
||||
['Android phone', { ua: 'Mozilla/5.0 (Linux; Android 14; Pixel 8) Chrome/140.0 Mobile', screen: [412, 915], touch: 5, coarse: true }, 'android-phone'],
|
||||
['Android tablet', { ua: 'Mozilla/5.0 (Linux; Android 14; SM-X710) Chrome/140.0', screen: [800, 1280], touch: 10, coarse: true }, 'android-tablet'],
|
||||
['Galaxy Fold folded', { ua: 'Mozilla/5.0 (Linux; Android 14; SM-F946B) Chrome/140.0 Mobile', screen: [344, 882], touch: 5, coarse: true }, 'android-phone'],
|
||||
['tablet asking for the desktop site', { ua: 'Mozilla/5.0 (X11; Linux x86_64) Chrome/140.0', screen: [800, 1280], touch: 10, coarse: true, fine: false }, 'tablet'],
|
||||
['phone asking for the desktop site', { ua: 'Mozilla/5.0 (X11; Linux x86_64) Chrome/140.0', screen: [412, 915], touch: 5, coarse: true, fine: false }, 'phone'],
|
||||
['a mobile Chromium by its client hints', { ua: 'Mozilla/5.0 (X11; Linux x86_64) Chrome/140.0', uad: { mobile: true, platform: 'Linux' }, screen: [412, 915], touch: 5, coarse: true }, 'phone'],
|
||||
];
|
||||
|
||||
let failed = 0;
|
||||
for (const [name, device, want] of cases) {
|
||||
const got = classOf(device);
|
||||
const ok = got === want;
|
||||
if (!ok) failed++;
|
||||
console.log(`${ok ? 'ok ' : 'FAIL'} ${name}: ${got}${ok ? '' : ` (want ${want})`}`);
|
||||
}
|
||||
console.log(failed ? `${failed} of ${cases.length} failed` : `all ${cases.length} ok`);
|
||||
process.exit(failed ? 1 : 0);
|
||||
Loading…
Add table
Add a link
Reference in a new issue