oxedyne/daimond/dev/fsa_disk_check.mjs
4.1 KiB, 1 run
created by r2519314175:19, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | // fsa_disk_check.mjs — the one thing an OPFS stand-in cannot prove: the bytes are on real disk. |
| 2 | // |
| 3 | // `verify_fsa.mjs` drives all of real-folder mode headlessly by standing an OPFS subdirectory |
| 4 | // handle in for a picked folder — the types are identical, so every line of the code is exercised. |
| 5 | // What it cannot show is that a *picked* folder is a real directory on the user's disk, because |
| 6 | // showDirectoryPicker opens a native dialog that automation cannot answer. |
| 7 | // |
| 8 | // So this asks for exactly one human gesture, and then does the rest: it opens a real browser, |
| 9 | // waits for the folder to be picked, has the AGENT write a file through its ordinary file tool, |
| 10 | // and reads it back. The proof is not in this script — it is in the shell afterwards, where the |
| 11 | // file either is on disk or is not. |
| 12 | // |
| 13 | // node dev/fsa_disk_check.mjs (then pick ~/daimond-fsa-test in the dialog) |
| 14 | // |
| 15 | // The browser profile is kept, so the grant persists and a later run reconnects with no gesture. |
| 16 | import { open, signInAs, scratch } from './harness.mjs'; |
| 17 | import fs from 'node:fs'; |
| 18 | import os from 'node:os'; |
| 19 | import path from 'node:path'; |
| 20 | |
| 21 | const FOLDER = path.join(os.homedir(), 'daimond-fsa-test'); |
| 22 | const STAMP = 'written-by-the-agent-' + process.pid + '.md'; |
| 23 | const BODY = 'The agent wrote this through its ordinary file_write tool, into a real folder.'; |
| 24 | |
| 25 | console.log('\n Opening a browser on your display.'); |
| 26 | console.log(' In the WORKSPACE panel, next to the "🗄 OPFS (sandbox)" chip,'); |
| 27 | console.log(' press "📂 Open a folder…" and pick:\n'); |
| 28 | console.log(' ' + FOLDER + '\n'); |
| 29 | |
| 30 | const s = await open({ |
| 31 | name: 'fsa-real', |
| 32 | headed: true, // a native dialog needs a real window |
| 33 | connect: false, |
| 34 | profile: scratch('fsa-real'), // keep the grant, so the next run needs no gesture |
| 35 | }); |
| 36 | const p = s.page; |
| 37 | await p.waitForTimeout(1500); |
| 38 | |
| 39 | // Poll until the folder is open. The gesture is the user's; everything after it is not. |
| 40 | const t0 = Date.now(); |
| 41 | let mode = 'opfs', folder = ''; |
| 42 | while (Date.now() - t0 < 240000) { |
| 43 | const st = await p.evaluate(async () => { |
| 44 | const mod = await import('../pkg/oxedyne_daimond.js'); |
| 45 | const chip = document.querySelector('.files-mode-chip'); |
| 46 | return { mode: mod.workspace_mode(), chip: chip ? chip.textContent.trim() : '' }; |
| 47 | }).catch(() => ({ mode: 'opfs', chip: '' })); |
| 48 | if (st.mode === 'folder') { mode = st.mode; folder = st.chip; break; } |
| 49 | await p.waitForTimeout(1000); |
| 50 | } |
| 51 | |
| 52 | if (mode !== 'folder') { |
| 53 | console.log(' No folder was picked (timed out). Nothing was written.'); |
| 54 | await s.close(); |
| 55 | process.exit(2); |
| 56 | } |
| 57 | console.log(' Folder is open: ' + folder); |
| 58 | |
| 59 | // The agent's own tool, not a test back door: this is the path a real turn takes. |
| 60 | const wrote = await p.evaluate(async ({ stamp, body }) => { |
| 61 | const mod = await import('../pkg/oxedyne_daimond.js'); |
| 62 | const app = new mod.DaimondApp('http://127.0.0.1/v1/chat/completions', '', 'none', 256, '', true); |
| 63 | const w = await app.run_tool('file_write', JSON.stringify({ path: stamp, content: body })); |
| 64 | const r = await app.run_tool('file_read', JSON.stringify({ path: stamp })); |
| 65 | const l = await app.run_tool('file_list', JSON.stringify({ path: '.' })); |
| 66 | return { w, r, l }; |
| 67 | }, { stamp: STAMP, body: BODY }); |
| 68 | |
| 69 | console.log(' Agent wrote: ' + (wrote.w || '').trim()); |
| 70 | console.log(' Agent read: ' + (wrote.r || '').trim().slice(0, 60)); |
| 71 | console.log(' Agent listed: ' + (wrote.l || '').trim().split('\n').join(' | ')); |
| 72 | |
| 73 | // The claim, checked where it actually matters. |
| 74 | const onDisk = path.join(FOLDER, STAMP); |
| 75 | const exists = fs.existsSync(onDisk); |
| 76 | const disk = exists ? fs.readFileSync(onDisk, 'utf8').trim() : '(absent)'; |
| 77 | const sawExisting = /existing\.md/.test(wrote.l || ''); |
| 78 | |
| 79 | console.log('\n ── on real disk ──'); |
| 80 | console.log(' ' + onDisk); |
| 81 | console.log(' exists: ' + exists); |
| 82 | console.log(' content matches what the agent wrote: ' + (disk === BODY)); |
| 83 | console.log(' the agent could see the file that was already there: ' + sawExisting); |
| 84 | |
| 85 | await s.close(); |
| 86 | const pass = exists && disk === BODY && sawExisting; |
| 87 | console.log('\n ' + (pass ? 'PASS — real-folder mode reaches real disk.' : 'FAIL')); |
| 88 | process.exit(pass ? 0 : 1); |