Files
plugins/packages/agy-cli/agy-cli.test.mjs
T
yetoneandklarkxy 738fd501d7 agy-cli 0.1.14: tool schema patterns are turned into RE2 or dropped, so an ECMA-262 pattern no longer aborts the turn (klarkxy #946)
Tool input schemas' `pattern` and `patternProperties` keys are translated
to RE2 (re2-pattern.mjs) before they reach agy; a pattern RE2 can't hold
is dropped with a hint, and `additionalProperties: false` is lifted when
every patternProperties key was dropped. Closes #944.

Reviewed head 99093088 (on c27ba5f7), landed onto main a0b1e491 with the
version moved to 0.1.14.
Run at the reviewed head: WSL2 bun test packages/agy-cli 9 of 9,
check.mjs ok; Windows 8 pass, 1 fail, the same smoke red as main (#973).
A fuzz of 1,033 kept patterns compiled every one with Go's regexp
(go1.26.8), against 222 failures before the `[:` fix. Broken by hand:
the `[:` reject, the sanitizePatternFields call, the propertyNames /
contains / if / then / else / unevaluated* recursion and the
additionalProperties lift each turn re2-pattern-unit.mjs red.
Run at this commit (WSL2 Ubuntu 24.04, Bun 1.4.2, temp HOME): bun test
packages/agy-cli 9 of 9 pass; bun scripts/check.mjs agy-cli ok.
Not tried: macOS (mote refused ssh), a real agy.

Closes #946

Co-authored-by: klarkxy <klarkxy@users.noreply.github.com>
2026-11-11 13:34:04 +08:00

45 lines
1.5 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],
["usage-settlement.mjs", false],
["repeat-batch.mjs", false],
]) {
test(`test/${name}`, () => {
const { code, output } = run(["test", ...(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)