Oregami
Repositories/oxedyne/daimond

oxedyne/daimond/dev/shot_livecost.mjs

2.0 KiB, 1 run

created by r2519314175:161, 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// shot_livecost.mjs — a worker's cost must show on its tile while it is still
2// running, not only once it finishes. Drives a @toolslow worker: round one books
3// token usage (the meter), round two streams slowly, so the tile is caught mid-run
4// with a non-zero cost. Needs dev/serve.mjs + dev/mockllm.mjs (with @toolslow).
5import { open, shot } from './harness.mjs';
6
7const s = await open({ name: 'livecost-shot', signIn: true, connect: true });
8const { page } = s;
9const pause = (ms) => page.waitForTimeout(ms);
10
11await page.click('#new-diamond-btn', { force: true });
12await page.waitForSelector('.dlg-input', { timeout: 8000 });
13await page.fill('.dlg-input', 'Cost test');
14await page.click('.dlg-ok');
15await page.waitForSelector('#steer-input', { timeout: 10000 });
16await pause(300);
17
18// One worker: a tool call (books usage), then a slow stream.
19await page.fill('#steer-input', '@tools spawn_agent {"name":"coster","task":"@toolslow"}');
20await page.click('#steer-send');
21await pause(500);
22const okBtn = await page.$('.dlg-ok');
23if (okBtn) { await okBtn.click(); await pause(300); }
24
25// Wait for round one to book usage and round two to be streaming.
26await pause(2600);
27const live = await page.evaluate(() => {
28 const c = document.querySelector('#agents-list .acard.running');
29 if (!c) return { running: false };
30 const arow = c.querySelector('.arow');
31 return {
32 running: true,
33 rowText: arow ? arow.textContent.trim() : '',
34 };
35});
36console.log('LIVE (running):', JSON.stringify(live));
37await shot(s, 'livecost-running');
38
39const realErrs = s.errs.filter(e => !/502|Bad Gateway|\/api\b/.test(e));
40const ok =
41 live.running === true
42 && /tok/.test(live.rowText) // tokens shown while running
43 && /\$\d/.test(live.rowText) // a dollar cost shown while running
44 && realErrs.length === 0;
45console.log(ok ? '\n✅ PASS — a running worker shows its cost live on the tile' : '\n❌ FAIL — see above');
46if (realErrs.length) console.log('PAGE ERRORS:', realErrs);
47await s.close();
48process.exit(ok ? 0 : 1);