interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / scripts / test-home-floor-client.cjs

65 lines · 3282 bytes Raw Blame History
1#!/usr/bin/env node
2// Independent, verification-only schedule oracle for the Omega-emitted client.
3const assert = require('node:assert/strict');
4const fs = require('node:fs');
5const vm = require('node:vm');
6const entire = fs.readFileSync(process.argv[2] || 'dist/js/site.js', 'utf8');
7const marker = '/* Home floor after paint. Generated by om/site/floor.om. */';
8assert.equal(entire.split(marker).length, 2, 'one floor controller in the emitted client');
9const code = entire.slice(entire.indexOf(marker));
10function fixture(options = {}) {
11 const callbacks = [], writes = [];
12 const attrs = new Map(options.shell === false ? [] : [['data-floor-srcdoc', '<html data-mode="public">public shell</html>']]);
13 if (options.preinitialized) attrs.set('srcdoc', 'existing');
14 const frame = {
15 hidden: true, isConnected: true, dataset: {},
16 getAttribute: k => attrs.get(k) ?? null,
17 hasAttribute: k => attrs.has(k),
18 removeAttribute: k => attrs.delete(k),
19 set srcdoc(value) { writes.push(value); attrs.set('srcdoc', value); },
20 };
21 const waiting = { hidden: false, isConnected: true };
22 const context = vm.createContext({
23 document: { getElementById: id => options.absent ? null : id === 'factory-floor-frame' ? frame : waiting },
24 requestAnimationFrame: fn => callbacks.push(fn),
25 });
26 return { callbacks, writes, frame, waiting, context, attrs };
27}
28function proveSchedule(source) {
29 const f = fixture();
30 vm.runInContext(source, f.context);
31 assert.equal(f.writes.length, 0, 'must not start during deferred script execution');
32 assert.equal(f.waiting.hidden, false, 'first-paint overview remains visible');
33 assert.equal(f.callbacks.length, 1);
34 f.callbacks.shift()();
35 assert.equal(f.writes.length, 0, 'must not start before the first paint opportunity');
36 assert.equal(f.callbacks.length, 1);
37 f.callbacks.shift()();
38 assert.equal(f.writes.length, 1, 'starts in the following frame');
39 assert.equal(f.frame.hidden, false);
40 assert.equal(f.waiting.hidden, true);
41 assert.equal(f.attrs.has('data-floor-srcdoc'), false);
42 vm.runInContext(source, f.context);
43 assert.equal(f.callbacks.length, 0, 'never reload a running floor');
44}
45proveSchedule(code);
46for (const options of [{ absent: true }, { shell: false }, { preinitialized: true }]) {
47 const f = fixture(options);
48 vm.runInContext(code, f.context);
49 assert.equal(f.callbacks.length, 0, 'refuses incomplete or already-active markup');
50 assert.equal(f.writes.length, 0);
51}
52const removed = fixture();
53vm.runInContext(code, removed.context);
54removed.callbacks.shift()();
55removed.frame.isConnected = false;
56removed.callbacks.shift()();
57assert.equal(removed.writes.length, 0, 'must not activate a removed frame');
58const duplicate = fixture();
59vm.runInContext(code, duplicate.context);
60vm.runInContext(code, duplicate.context);
61assert.equal(duplicate.callbacks.length, 1, 'one pending activation');
62const early = code.replace('requestAnimationFrame(() => {', '(callback => callback())(() => {');
63assert.notEqual(early, code, 'negative-control target exists');
64assert.throws(() => proveSchedule(early), 'oracle must reject activation one frame too early');
65console.log('HOME-FLOOR-CLIENT PASS: after-paint schedule, static overview, refusals, single activation, early-start negative control');