opencode/packages/widget/test/compiled.test.ts
OpenCode Agent d10749cfce perf(core): widget runners compile each program once; host errors keep the call's position
step, draw and LiveWidget run programs from a bounded cache of compiled programs (Runtime.compile,
the 32 last used). LiveWidget's host functions throw through psychoscript/effect defects, so an
error for posting a function (or an unknown canvas key) reports the call's line and column, as the
interpreter's own argument errors do.
2026-11-22 03:49:09 +00:00

13 lines
623 B
TypeScript

import { expect, test } from "bun:test"
import { compiled } from "../src/compiled.js"
test("a program is compiled once, the cache keeps the 32 last used, and code that doesn't compile stays text", () => {
const first = compiled("return 1")
expect(typeof first).not.toBe("string")
expect(compiled("return 1")).toBe(first)
Array.from({ length: 31 }, (_, index) => compiled(`return ${index + 2}`))
expect(compiled("return 1")).toBe(first)
Array.from({ length: 32 }, (_, index) => compiled(`return ${index + 100}`))
expect(compiled("return 1")).not.toBe(first)
expect(compiled("return (")).toBe("return (")
})