69 lines
3.6 KiB
JavaScript
69 lines
3.6 KiB
JavaScript
// Build: flutter build web -t tool/server_editor_save_probe.dart -o build/server_editor_save_probe_web
|
|
// Run: node tool/server_editor_save_probe.mjs [evidence directory]
|
|
import assert from 'node:assert/strict';
|
|
import { once } from 'node:events';
|
|
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join, resolve } from 'node:path';
|
|
import { startServer, launchChrome, waitForPort, waitForPage, connect, sleep } from './pipelines_probe_cdp_lib.mjs';
|
|
import { axNodes, enableSemantics, waitFor, capture, assertName, click, clickAt } from './pipelines_probe_cdp_input.mjs';
|
|
|
|
const output = resolve(process.argv[2] ?? 'build/server-editor-save-evidence');
|
|
await mkdir(output, { recursive: true });
|
|
const fixture = await startServer(resolve('build/server_editor_save_probe_web'));
|
|
const profile = await mkdtemp(join(tmpdir(), 'server-editor-save-'));
|
|
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank');
|
|
const log = { checks: [], captures: [] };
|
|
let c;
|
|
try {
|
|
c = await connect((await waitForPage(await waitForPort(join(profile, 'DevToolsActivePort')))).webSocketDebuggerUrl);
|
|
await c.send('Page.enable');
|
|
await c.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true });
|
|
for (const host of ['material', 'cupertino']) {
|
|
await c.send('Page.navigate', { url: `${fixture.url}?host=${host}` });
|
|
assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 12000));
|
|
await enableSemantics(c);
|
|
await click(c, 'Add server');
|
|
const type = async (index, text) => {
|
|
const field = (await axNodes(c)).filter(node => node.role?.value === 'textbox')[index];
|
|
assert.ok(field, `field ${index}`);
|
|
const { model } = await c.send('DOM.getBoxModel', { backendNodeId: field.backendDOMNodeId });
|
|
const [x1, y1, , , x3, y3] = model.content;
|
|
await clickAt(c, (x1 + x3) / 2, (y1 + y3) / 2);
|
|
await c.send('Input.insertText', { text });
|
|
await sleep(200);
|
|
};
|
|
await type(0, 'Home draft');
|
|
await type(1, 'wss://home.test/connect');
|
|
await click(c, 'Save server');
|
|
await assertName(c, 'Saving server…', `${host}: pending state visible`, log);
|
|
await click(c, 'Saving server…');
|
|
assert.equal(await c.evaluate('globalThis.serverEditorSaveAttempts'), 1);
|
|
log.checks.push(`${host}: repeat click does not submit again`);
|
|
await capture(c, output, log, `${host}-saving`);
|
|
await assertName(c, 'could not be saved', `${host}: save refusal shown in editor`, log);
|
|
await assertName(c, 'Home draft', `${host}: name draft retained`, log);
|
|
await assertName(c, 'wss://home.test/connect', `${host}: address draft retained`, log);
|
|
await capture(c, output, log, `${host}-failure-draft`);
|
|
await click(c, 'Save server');
|
|
await assertName(c, 'Selected server', `${host}: retry succeeds`, log);
|
|
assert.equal(await c.evaluate('globalThis.serverEditorSaveAttempts'), 2);
|
|
assert.ok(!(await axNodes(c)).some(node => node.role?.value === 'textbox'));
|
|
await capture(c, output, log, `${host}-retry-saved`);
|
|
}
|
|
console.log(JSON.stringify(log, null, 2));
|
|
} catch (error) {
|
|
if (c) {
|
|
await capture(c, output, log, 'failure');
|
|
await writeFile(join(output, 'failure-ax.json'), JSON.stringify(await axNodes(c), null, 2));
|
|
}
|
|
throw error;
|
|
} finally {
|
|
await writeFile(join(output, 'result.json'), JSON.stringify(log, null, 2));
|
|
c?.close();
|
|
const exited = once(chrome, 'exit');
|
|
chrome.kill();
|
|
await exited;
|
|
await new Promise(done => fixture.server.close(done));
|
|
}
|