Oregami
Repositories/oxedyne/daimond

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.
16import { open, signInAs, scratch } from './harness.mjs';
17import fs from 'node:fs';
18import os from 'node:os';
19import path from 'node:path';
20
21const FOLDER = path.join(os.homedir(), 'daimond-fsa-test');
22const STAMP = 'written-by-the-agent-' + process.pid + '.md';
23const BODY = 'The agent wrote this through its ordinary file_write tool, into a real folder.';
24
25console.log('\n Opening a browser on your display.');
26console.log(' In the WORKSPACE panel, next to the "🗄 OPFS (sandbox)" chip,');
27console.log(' press "📂 Open a folder…" and pick:\n');
28console.log(' ' + FOLDER + '\n');
29
30const 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});
36const p = s.page;
37await p.waitForTimeout(1500);
38
39// Poll until the folder is open. The gesture is the user's; everything after it is not.
40const t0 = Date.now();
41let mode = 'opfs', folder = '';
42while (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
52if (mode !== 'folder') {
53 console.log(' No folder was picked (timed out). Nothing was written.');
54 await s.close();
55 process.exit(2);
56}
57console.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.
60const 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
69console.log(' Agent wrote: ' + (wrote.w || '').trim());
70console.log(' Agent read: ' + (wrote.r || '').trim().slice(0, 60));
71console.log(' Agent listed: ' + (wrote.l || '').trim().split('\n').join(' | '));
72
73// The claim, checked where it actually matters.
74const onDisk = path.join(FOLDER, STAMP);
75const exists = fs.existsSync(onDisk);
76const disk = exists ? fs.readFileSync(onDisk, 'utf8').trim() : '(absent)';
77const sawExisting = /existing\.md/.test(wrote.l || '');
78
79console.log('\n ── on real disk ──');
80console.log(' ' + onDisk);
81console.log(' exists: ' + exists);
82console.log(' content matches what the agent wrote: ' + (disk === BODY));
83console.log(' the agent could see the file that was already there: ' + sawExisting);
84
85await s.close();
86const pass = exists && disk === BODY && sawExisting;
87console.log('\n ' + (pass ? 'PASS — real-folder mode reaches real disk.' : 'FAIL'));
88process.exit(pass ? 0 : 1);