Oregami
Repositories/oxedyne/daimond

oxedyne/daimond/dev/probe_droots.mjs

2.2 KiB, 1 run

created by r2519314175:45, 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// probe_droots.mjs — where does a Diamond's directory live when a folder is open?
2//
3// Throwaway probe, run BEFORE the fix, to see the split for real rather than
4// from reading. It stands a folder in with an OPFS subdirectory, exactly as
5// dev/verify_fsa.mjs does.
6import { open, signInAs } from './harness.mjs';
7
8const s = await open({ name: 'droots-probe', connect: false });
9const p = s.page;
10await p.waitForTimeout(1500);
11
12const out = await p.evaluate(async () => {
13 const mod = await import('../pkg/oxedyne_daimond.js');
14 const root = await navigator.storage.getDirectory();
15 const dir = await root.getDirectoryHandle('probefolder', { create: true });
16 const app = new mod.DaimondApp('http://127.0.0.1/v1/chat/completions', '', 'none', 256, '', true);
17
18 const id = await app.create_diamond('Probe');
19 await app.write_crystal_data(id, JSON.stringify({ title: 'the crystal' }));
20
21 const listBrowser = await app.run_tool('file_list', JSON.stringify({ path: 'diamonds/' + id }));
22 const readBrowser = await app.run_tool('file_read', JSON.stringify({ path: 'diamonds/' + id + '/crystal.json' }));
23
24 mod.set_workspace_dir(dir);
25 const listMachine = await app.run_tool('file_list', JSON.stringify({ path: 'diamonds/' + id }));
26 const readMachine = await app.run_tool('file_read', JSON.stringify({ path: 'diamonds/' + id + '/crystal.json' }));
27 const wroteMachine = await app.run_tool('file_write',
28 JSON.stringify({ path: 'diamonds/' + id + '/worker.md', content: 'a worker wrote this' }));
29
30 // Where did the worker's file land?
31 const at = async (d, ...parts) => {
32 let cur = d;
33 try {
34 for (let i = 0; i < parts.length - 1; i++) cur = await cur.getDirectoryHandle(parts[i]);
35 await cur.getFileHandle(parts[parts.length - 1]);
36 return true;
37 } catch (e) { return false; }
38 };
39 const inFolder = await at(dir, 'diamonds', id, 'worker.md');
40 const inOpfs = await at(root, 'diamonds', id, 'worker.md');
41
42 // And can the store see it?
43 const exported = await app.export_diamond(id);
44
45 mod.use_opfs_workspace();
46 return {
47 id, listBrowser, readBrowser, listMachine, readMachine, wroteMachine,
48 inFolder, inOpfs, inExport: exported.includes('worker.md'),
49 };
50});
51
52console.log(JSON.stringify(out, null, 2));
53await s.close();