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). |
| 5 | import { open, shot } from './harness.mjs'; |
| 6 | |
| 7 | const s = await open({ name: 'livecost-shot', signIn: true, connect: true }); |
| 8 | const { page } = s; |
| 9 | const pause = (ms) => page.waitForTimeout(ms); |
| 10 | |
| 11 | await page.click('#new-diamond-btn', { force: true }); |
| 12 | await page.waitForSelector('.dlg-input', { timeout: 8000 }); |
| 13 | await page.fill('.dlg-input', 'Cost test'); |
| 14 | await page.click('.dlg-ok'); |
| 15 | await page.waitForSelector('#steer-input', { timeout: 10000 }); |
| 16 | await pause(300); |
| 17 | |
| 18 | // One worker: a tool call (books usage), then a slow stream. |
| 19 | await page.fill('#steer-input', '@tools spawn_agent {"name":"coster","task":"@toolslow"}'); |
| 20 | await page.click('#steer-send'); |
| 21 | await pause(500); |
| 22 | const okBtn = await page.$('.dlg-ok'); |
| 23 | if (okBtn) { await okBtn.click(); await pause(300); } |
| 24 | |
| 25 | // Wait for round one to book usage and round two to be streaming. |
| 26 | await pause(2600); |
| 27 | const 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 | }); |
| 36 | console.log('LIVE (running):', JSON.stringify(live)); |
| 37 | await shot(s, 'livecost-running'); |
| 38 | |
| 39 | const realErrs = s.errs.filter(e => !/502|Bad Gateway|\/api\b/.test(e)); |
| 40 | const 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; |
| 45 | console.log(ok ? '\n✅ PASS — a running worker shows its cost live on the tile' : '\n❌ FAIL — see above'); |
| 46 | if (realErrs.length) console.log('PAGE ERRORS:', realErrs); |
| 47 | await s.close(); |
| 48 | process.exit(ok ? 0 : 1); |