From e452ce7785e5e47ec01a409d6da1f59564f8f365 Mon Sep 17 00:00:00 2001 From: Hermes SysOp Date: Thu, 12 Nov 2026 17:02:47 +0100 Subject: fix(newos4): stop reporting network and VFS size as facts we do not have (v4.6.161) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. The last two `navigator.onLine`-as-fact payloads - module-aiassist.js: the debug/health payload carried `online: navigator.onLine`, consumed by downloads/dashboard.html, which rendered "๐Ÿ”ด Offline" โ€” on an Android WebView (reports false while fully connected) that told working users they were offline. The key is gone; the payload carries `network:'unknown'`, `networkKnown:false` and `networkHint`. - module-world-model.js: the snapshot had the same field, and it is also handed to the LLM through `_modelDigest()`/`ask()`, so the model was told the user was offline. Now `network:'unknown'` + `networkKnown:false`. - `_loadFromVFS()` scrubs `system.online` from a model persisted by an older build โ€” otherwise the stale boolean would survive inside the digest for the life of the VFS. - downloads/dashboard.html: `networkText()` renders reachable/unreachable/http-* only when doctor produced them ("(doctor)"), `unprobed` as "โ€” not probed", and everything else as "โ€” unknown (run doctor for a live probe)". A legacy payload's `online:false` lands in "unknown", never "Offline". The row label is "Network", not "Online". - Neither payload invents a probe: SystemModule stores no last-doctor verdict, so 'unknown' is the honest value until one exists. 2. `vfsSize` in both payloads was a different unit again - aiassist: `JSON.stringify(fs.root).length / 1024`; world-model: `JSON.stringify(fs.root).length`. Same lie v4.6.160 fixed in `vfs-size` โ€” UTF-16 code units plus serialisation structure. Both now sum UTF-8 bytes of file content (`_utf8Len`/`_measureVfs`, Blob โ†’ TextEncoder โ†’ code-point fallback, depth/node capped) and carry `sizeBytes` beside the human string so the rows reconcile. - world-model's `_gatherFileInfo().size` used a THIRD unit on an adjacent line (`JSON.stringify(fs.root).length/1024`); now the same measurement, plus `sizeBytes`. - `showModel()` renders exact bytes and tolerates a pre-fix persisted string. 3. Predictor made a guaranteed-401 request on every boot (UI-plan finding F6) - `_wdConfig()` returns `user:''`/`pass:''` when the saved WebDAV config has a URL but no credentials, and `_pullFromServer`/`_pushToServer` fetched the auth-gated `/spaces//_data/predictor.json` anyway โ€” 107 ร— 401 in one day, logged by the browser as console errors. Both now refuse without credentials (`cache-only (no credentials)`). Verified: 42/42 node tests, 2 new files (38 payload/honesty assertions, 8 predictor-store assertions); the predictor suite is 4/8 against the pre-fix source, and the payload suite fails 14 assertions against HEAD (`online:false` present, vfsSize === JSON.stringify length). Live Chromium on v4.6.161, on the served dashboard: a legacy payload with `online:false` renders "Network โ€” unknown (run doctor for a live probe)", the current payload renders "85.8 KB (87880 B)" and the same unknown, and a doctor-produced `unreachable` renders "โš ๏ธ unreachable (doctor)". Served bytes identical for core-bundle.js, main.html and downloads/dashboard.html. `maintain.py --fix` all PASS. --- modules/test/test-network-payload-honesty.js | 298 +++++++++++++++++++++++++++ modules/test/test-predictor-store-auth.js | 80 +++++++ 2 files changed, 378 insertions(+) create mode 100644 modules/test/test-network-payload-honesty.js create mode 100644 modules/test/test-predictor-store-auth.js (limited to 'modules/test') diff --git a/modules/test/test-network-payload-honesty.js b/modules/test/test-network-payload-honesty.js new file mode 100644 index 0000000..1f18725 --- /dev/null +++ b/modules/test/test-network-payload-honesty.js @@ -0,0 +1,298 @@ +// node modules/test/test-network-payload-honesty.js +// Payload honesty: no payload may turn `navigator.onLine` into a network verdict, and the +// world-model VFS size must be STORED UTF-8 BYTES. +// +// Why: an Android WebView reports navigator.onLine === false while the page is fully connected. +// v4.6.159/160 removed that boolean from `status`, `doctor`, the status bar and the net test; +// these are the two payloads that were left, plus every reader that printed "Offline" from them. +// +// Asserts (all on OUTPUT, never on a regex over source): +// ยท navigator.onLine === false must not produce `online: false` in the aiassist health payload, +// nor any online/offline claim in the world-model snapshot or its LLM digest; +// ยท world-model `vfsSize` == UTF-8 byte sum ('รฉ' 2 + 'โ˜ƒ' 3 + 1000 ASCII + 'abc' 3 = 1008), +// and != JSON.stringify(root).length (UTF-16 units + serialisation structure); +// ยท the consumer renders 'unknown': the real dashboard script is executed against a stub DOM +// and the actual health panel HTML is inspected; world-model's showModel output is captured; +// ยท a missing `navigator` does not throw. +// +// N4_CORE / N4_DASH point the same assertions at another build (mutation check). +const fsMod = require('fs'), path = require('path'); + +const CORE = process.env.N4_CORE || path.join(__dirname, '..', 'core'); +const DASH = process.env.N4_DASH || path.join(__dirname, '..', '..', 'downloads', 'dashboard.html'); + +// โ”€โ”€ browser globals the modules reach for โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +const store = {}; +global.window = global; +global.localStorage = { + getItem: k => (k in store ? store[k] : null), + setItem: (k, v) => { store[k] = String(v); }, + removeItem: k => { delete store[k]; }, +}; +global.indexedDB = { open() { throw new Error('no idb'); }, deleteDatabase() { throw new Error('no idb'); } }; +global.NEWOS4_VERSION = 'v4.6.160-test'; + +function setNavigator(onLine) { + if (onLine === 'missing') { + try { delete globalThis.navigator; } catch (e) { /* older node: shadow below */ } + try { Object.defineProperty(globalThis, 'navigator', { configurable: true, value: undefined }); } catch (e) {} + return; + } + Object.defineProperty(globalThis, 'navigator', { + configurable: true, + value: { onLine: onLine, userAgent: 'test-agent', storage: undefined }, + }); +} + +// โ”€โ”€ classes, loaded from source exactly as the bundle does โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +const WorldModelModule = new Function( + fsMod.readFileSync(path.join(CORE, 'module-world-model.js'), 'utf8') + '\nreturn WorldModelModule;')(); +const AI = new Function( + fsMod.readFileSync(path.join(CORE, 'module-aiassist.js'), 'utf8') + '\nreturn WebX11AIAssistantModule;')(); + +let fails = 0, passes = 0; +function ok(name, cond, detail) { + if (cond) { passes++; return; } + fails++; + console.log('FAIL ' + name + (detail ? ' โ€” ' + detail : '')); +} + +// โ”€โ”€ the honest tree: 'รฉ' = 2 B, 'โ˜ƒ' = 3 B, 1000 ASCII, nested 'abc' = 3 B โ”€โ”€ +const EXPECTED_BYTES = 2 + 3 + 1000 + 3; // 1008 stored bytes +function makeTree() { + return { + type: 'dir', + content: { + 'e.txt': { type: 'file', content: 'รฉ' }, + 's.txt': { type: 'file', content: 'โ˜ƒ' }, + 'ascii.txt': { type: 'file', content: 'x'.repeat(1000) }, + 'sub': { type: 'dir', content: { 'n.txt': { type: 'file', content: 'abc' } } }, + }, + }; +} + +// โ”€โ”€ an in-memory VFS with only the methods these modules call โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ +function mkFs(root) { + const writes = new Map(), json = new Map(); + const resolve = (p) => { + if (!p || p === '/') return root; + const parts = String(p).replace(/^\/+|\/+$/g, '').split('/').filter(Boolean); + let node = root; + for (const part of parts) { + node = node && node.content && node.content[part]; + if (!node) return null; + } + return node || null; + }; + const fs = { + root, + currentPath: [], + writes, + ls(p) { + const node = resolve(p || '/'); + if (!node || !node.content) return []; + return Object.keys(node.content).map(name => ({ + name, type: node.content[name].type, _virtual: false, + })); + }, + readDir(p) { return fs.ls(p); }, + readFile(p) { + if (writes.has(p)) return writes.get(p); + const n = resolve(p); + return n && n.type === 'file' ? (n.content || '') : null; + }, + writeFile(p, c) { writes.set(p, String(c)); return true; }, + deleteFile(p) { writes.delete(p); return true; }, + mkdir() { return true; }, + fsWriteJSON(p, obj) { json.set(p, obj); writes.set(p, JSON.stringify(obj)); return true; }, + fsReadJSON(p) { + if (json.has(p)) return json.get(p); + if (writes.has(p)) { try { return JSON.parse(writes.get(p)); } catch (e) { return null; } } + const n = resolve(p); + if (n && n.type === 'file') { try { return JSON.parse(n.content); } catch (e) { return null; } } + return null; + }, + }; + return fs; +} + +function mkTerminal(fs, wm) { + const out = []; + return { + out, + text: () => out.map(l => l.msg).join('\n'), + fs, + ollamaManager: { connected: false, currentModel: null, currentProvider: null }, + moduleManager: { + modules: wm ? { WorldModelModule: wm } : {}, + moduleRegistry: [{ name: 'A' }, { name: 'B' }], + getAllCommands: () => ({}), + }, + countErrors: () => ({ total: 0, debug: 0, latency: 0, log: 0 }), + print: (msg, cls) => out.push({ msg: String(msg), cls: cls || '' }), + }; +} + +function newWorldModel() { + const wm = new WorldModelModule(); + wm.terminal = mkTerminal(mkFs(makeTree())); + wm._synthesize(); + return wm; +} + +async function aiassistPayload(wm) { + const ai = Object.create(AI.prototype); + ai.terminal = mkTerminal(mkFs(makeTree()), wm); + return await ai._collectDashboardData(); +} + +// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• +// A/B. navigator.onLine === false must not become a payload fact +// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• +(async function main() { + setNavigator(false); + const wm = newWorldModel(); + const data = await aiassistPayload(wm); + + // โ”€โ”€ A. aiassist health payload (debug panel / dashboard source) โ”€โ”€ + const health = (data && data.health) || {}; + ok('A1 health payload has no `online` key', + !Object.prototype.hasOwnProperty.call(health, 'online'), JSON.stringify(health)); + ok('A2 serialised health carries no "online"', + JSON.stringify(health).indexOf('"online"') === -1, JSON.stringify(health)); + ok('A3 health.network is "unknown"', health.network === 'unknown', String(health.network)); + ok('A4 health.networkKnown is false', health.networkKnown === false, String(health.networkKnown)); + ok('A5 health.vfsSizeBytes is the UTF-8 sum', + health.vfsSizeBytes === EXPECTED_BYTES, String(health.vfsSizeBytes)); + ok('A6 health.vfsSize is a byte figure, not JSON length', + typeof health.vfsSize === 'string' && /B$/.test(health.vfsSize.trim()), String(health.vfsSize)); + ok('A7 whole payload contains no "online":false', + JSON.stringify(data).indexOf('"online":false') === -1); + ok('A8 aiassist vfs bytes differ from JSON.stringify(root).length', + health.vfsSizeBytes !== JSON.stringify(makeTree()).length, + health.vfsSizeBytes + ' vs ' + JSON.stringify(makeTree()).length); + + // โ”€โ”€ B. world-model snapshot + LLM digest โ”€โ”€ + const sys = (wm._model && wm._model.system) || {}; + ok('B1 world-model system has no `online` key', + !Object.prototype.hasOwnProperty.call(sys, 'online'), JSON.stringify(sys)); + ok('B2 world-model network is "unknown"', sys.network === 'unknown', String(sys.network)); + ok('B3 world-model networkKnown is false', sys.networkKnown === false, String(sys.networkKnown)); + const snap = JSON.stringify(wm._modelSnapshot()); + ok('B4 snapshot has no "online" field', snap.indexOf('"online"') === -1); + ok('B5 snapshot states network unknown', /"network":"unknown"/.test(snap)); + const digest = wm._modelDigest(); + ok('B6 digest makes no Online/Offline claim', + !/\b(Online|Offline)\b/.test(digest), digest.slice(0, 200)); + ok('B7 world-model vfsSize is the UTF-8 sum', + sys.vfsSize === EXPECTED_BYTES, String(sys.vfsSize)); + ok('B8 vfsSize differs from JSON.stringify(root).length', + sys.vfsSize !== JSON.stringify(makeTree()).length, + sys.vfsSize + ' vs ' + JSON.stringify(makeTree()).length); + ok('B9 files.sizeBytes reconciles with system.vfsSize', + wm._model.files.sizeBytes === sys.vfsSize, wm._model.files.sizeBytes + ' vs ' + sys.vfsSize); + + // โ”€โ”€ C. the UTF-8 unit itself, one file at a time (no averaging) โ”€โ”€ + // Guarded so a missing helper FAILS an assertion instead of aborting the run. + const u8len = (s) => (typeof wm._utf8Len === 'function' ? wm._utf8Len(s) : NaN); + const measure = (n) => (typeof wm._measureVfs === 'function' ? wm._measureVfs(n) : { bytes: NaN, files: NaN }); + ok('C1 รฉ counts as 2 bytes', u8len('รฉ') === 2, String(u8len('รฉ'))); + ok('C2 โ˜ƒ counts as 3 bytes', u8len('โ˜ƒ') === 3, String(u8len('โ˜ƒ'))); + ok('C3 a nested dir adds only its own file content', + measure(makeTree().content['sub']).bytes === 3, String(measure(makeTree().content['sub']).bytes)); + ok('C4 measure counts files, not directories', + measure(makeTree()).files === 4, String(measure(makeTree()).files)); + + // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• + // D. the consumer renders 'unknown' โ€” real dashboard script, stub DOM + // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• + const dashHtml = fsMod.readFileSync(DASH, 'utf8'); + let dashScript = null; + for (const m of dashHtml.matchAll(/