agy 1.5.1+ reports ACP `inputTokens` as uncached prompt tokens only; `promptUsage()` tells the exclusive shape from the inclusive one by `totalTokens`, so cache reads are no longer clipped and the learned cache ratio no longer pins to 1.0. Each HTTP step of a multi-step tool loop is settled from agy's own per-call rows in `conversations/<id>.db` (`gen_metadata` on 1.5.1+, `steps` type 15 on 1.4.x-1.5.0) when they reconcile with ACP's total; same-generation tool continuations settle at 0, a cancelled or fallen-back turn stops trusting the store, and a clipped cold-start replay bounds its fallback estimate. The reader (`step-usage.mjs`) never opens a store read-write. Under Bun it opens with `SQLITE_OPEN_READONLY | SQLITE_OPEN_URI` (Bun's SQLite on Linux and Windows parses `file:` URIs only with that flag), finalizes statements and waits on no busy timeout. A checkpointed WAL store with no `-wal`/`-shm` is read through `?immutable=1` and gains no side files; if `-wal` appears during that read it is read again live. Store paths are resolved to absolute first, and Windows `\\?\` and UNC paths get their own `file:` form. On an uncheckpointed store the only file a reader touches is SQLite's `-shm` WAL index. Reviewed head 9054f47295d51d6f83f8585dd550312ebff8448a (base dba24067; merges cleanly onto main7c44d027). What ran at that head, Bun 1.4.2 everywhere, fresh temp HOME (and USERPROFILE on Windows): - macOS (mote): `bun test packages/agy-cli` 14/14; step-usage 10/10, usage-settlement 33/33; `node --test test/step-usage.mjs` (Node 22.22) 10/10; `bun scripts/check.mjs` ok. - Linux (WSL Ubuntu 24.04): `bun test packages/agy-cli` 14/14; step-usage 10/10, usage-settlement 33/33; Node 22.23 10/10; check.mjs ok. - Windows 11: step-usage 10/10 (the loopback UNC share was reachable, so its branch ran), usage-settlement 33/33, Node 10/10, check.mjs ok. `bun test packages/agy-cli` 13/14: smoke's one red is "no call to the loaded tool reaches agy's validator in the old prompt", the known #973 (1 of 334 checks), not touched here. - Root `bun test` on mica, merged onto origin/main7c44d027, under suite.lock: 8407 pass, 20 skip, 0 fail across 593 files (fresh temp HOME). Broken by hand (restored after each): - Linux: SQLITE_OPEN_URI dropped -> step-usage 3 red, usage-settlement 2 red; `path.resolve` dropped -> the URI/relative-path test red (Bun and Node); the "no -wal after a failed immutable read returns null" guard dropped -> the mid-read test red (Bun and Node). - macOS: the re-read after `-wal` appears removed, and the failed-immutable-read path returning null outright -> the mid-read test red under Bun and Node (at 262145f4; the code is unchanged since). - Windows: the `\\` branch of `immutableUri` disabled -> the URI/UNC test red. Not tried: a real agy session or account (fake agy and fixture stores only); Bun versions other than 1.4.2; a remote (non-loopback) UNC share. Co-authored-by: tungloong <19512489+tungloong@users.noreply.github.com>
55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
// Runs the suites in test/ (brought over from gitxm/yce-magpie-agy, MIT), each
|
|
// in a bun process of its own: they mock node:child_process, move the clock and
|
|
// set the bridge's environment, and smoke.mjs ends with process.exit.
|
|
import { expect, test } from "bun:test"
|
|
import path from "node:path"
|
|
|
|
const dir = path.join(import.meta.dir, "test")
|
|
const hook = path.join(dir, "cp-hook.mjs")
|
|
|
|
function run(args, timeout) {
|
|
const result = Bun.spawnSync({ cmd: [process.execPath, ...args], cwd: dir, env: { ...process.env }, stdout: "pipe", stderr: "pipe", timeout })
|
|
const output = result.stdout.toString() + result.stderr.toString()
|
|
if (result.exitCode !== 0) console.error(output)
|
|
return { code: result.exitCode, output }
|
|
}
|
|
|
|
for (const [name, mocks] of [
|
|
["platform.mjs", true],
|
|
["compat.mjs", true],
|
|
["prefill.mjs", false],
|
|
["usage.mjs", true],
|
|
["catalog.mjs", false],
|
|
["step-usage.mjs", false],
|
|
["usage-settlement.mjs", false],
|
|
["repeat-batch.mjs", false],
|
|
["conversation-key.mjs", false],
|
|
]) {
|
|
test(`test/${name}`, () => {
|
|
// bun's 5s default per test is a fixed wait these process-spawning tests
|
|
// overrun on a loaded machine; the 240s run bounds a real hang.
|
|
const { code, output } = run(["test", "--timeout", "120000", ...(mocks ? ["--preload", hook] : []), `./${name}`], 240_000)
|
|
expect(output).toMatch(/\b[1-9]\d* pass\b/)
|
|
expect(code).toBe(0)
|
|
}, 250_000)
|
|
}
|
|
|
|
|
|
test("test/re2-pattern-unit.mjs", () => {
|
|
const { code, output } = run([path.join(dir, "re2-pattern-unit.mjs")], 60_000)
|
|
expect(output).toMatch(/ALL OK/)
|
|
expect(code).toBe(0)
|
|
}, 70_000)
|
|
|
|
test("test/smoke.mjs against a fake agy", () => {
|
|
const { code, output } = run([path.join(dir, "smoke.mjs")], 240_000)
|
|
expect(output).toMatch(/ALL OK \(\d+ checks\)/)
|
|
expect(code).toBe(0)
|
|
}, 250_000)
|
|
|
|
test("test/array-items-unit.mjs", () => {
|
|
const { code, output } = run([path.join(dir, "array-items-unit.mjs")], 60_000)
|
|
expect(output).toMatch(/ALL OK/)
|
|
expect(code).toBe(0)
|
|
}, 70_000)
|