import { describe, expect, it } from "bun:test"; import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings"; import type { ToolSession } from "@oh-my-pi/pi-coding-agent/tools"; import { EvalTool, getEvalToolDescription } from "@oh-my-pi/pi-coding-agent/tools/eval"; function makeSession(opts: { spawns: string | null }): ToolSession { return { cwd: "/tmp/eval-test", hasUI: false, getSessionFile: () => null, getSessionSpawns: () => opts.spawns, settings: Settings.isolated(), } as unknown as ToolSession; } describe("eval tool description", () => { it("advertises agent() when spawns are allowed", () => { const text = getEvalToolDescription({ py: true, js: true, spawns: true }); expect(text).toContain("agent(prompt"); }); it("omits agent() when the session forbids spawning", () => { // Subagents with spawns: undefined (resolved to "") cannot launch tasks. // The prelude doc must not promise a helper that always throws. const text = getEvalToolDescription({ py: true, js: true, spawns: false }); expect(text).not.toContain("agent(prompt"); }); it("EvalTool description reflects spawn policy from the session", () => { const wildcard = new EvalTool(makeSession({ spawns: "*" })).description; const denied = new EvalTool(makeSession({ spawns: "" })).description; expect(wildcard).toContain("agent(prompt"); expect(denied).not.toContain("agent(prompt"); }); });