Files
oh-my-pi/packages/coding-agent/test/eval/agent-bridge.test.ts
T
can1357 24d58033bb refactor(eval): rename agent() params agent_type→agent, return_handle→handle
The eval agent() helper used `agent_type`/`return_handle` (snake_case) in
Python/Ruby/Julia and `agentType`/`returnHandle` (camelCase) in JS, forcing
the prelude docs to repeat every option twice ("JS same but camelcased").
Both are now single lowercase words identical across all four runtimes, and
`agent` matches the `task` tool's existing agent-selection parameter.

- Renamed across py/js/rb/jl preludes (signatures, forwarding, docstrings).
- Renamed the `__agent__` bridge wire protocol + `EvalAgentArgs` (`agentType`
  → `agent`, `returnHandle` → `handle`) so no prelude-side remap is needed.
- Updated prompt docs (workflow-notice.md, tools/eval.md), repo docs
  (docs/tools/eval.md, docs/python-repl.md), and all bridge/prelude tests.
- CHANGELOG: Breaking Changes entry under [Unreleased].
2026-06-22 22:12:24 +02:00

67 lines
2.2 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "bun:test";
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { runEvalAgent } from "@oh-my-pi/pi-coding-agent/eval/agent-bridge";
import type { LocalProtocolOptions } from "@oh-my-pi/pi-coding-agent/internal-urls";
import type { MCPManager } from "@oh-my-pi/pi-coding-agent/mcp";
import * as taskDiscovery from "@oh-my-pi/pi-coding-agent/task/discovery";
import * as taskExecutor from "@oh-my-pi/pi-coding-agent/task/executor";
import type { AgentDefinition, SingleResult } from "@oh-my-pi/pi-coding-agent/task/types";
import type { ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
function createResult(): SingleResult {
return {
index: 0,
id: "0-Task",
agent: "task",
agentSource: "bundled",
task: "do work",
exitCode: 0,
output: "done",
stderr: "",
truncated: false,
durationMs: 1,
tokens: 0,
requests: 0,
};
}
describe("runEvalAgent", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("forwards session-scoped MCP and local protocol options", async () => {
const agent: AgentDefinition = {
name: "task",
description: "Task agent",
systemPrompt: "Handle task",
source: "bundled",
};
vi.spyOn(taskDiscovery, "discoverAgents").mockResolvedValue({ agents: [agent], projectAgentsDir: null });
const runSubprocessSpy = vi.spyOn(taskExecutor, "runSubprocess").mockResolvedValue(createResult());
const mcpManager = { sentinel: "mcp" } as unknown as MCPManager;
const localProtocolOptions: LocalProtocolOptions = {
getArtifactsDir: () => "/tmp/parent-artifacts",
getSessionId: () => "parent-session",
};
const session = {
cwd: "/tmp",
settings: Settings.isolated(),
getSessionSpawns: () => "*",
getSessionFile: () => null,
mcpManager,
localProtocolOptions,
getAgentId: () => "BridgeParent",
} as unknown as ToolSession;
await runEvalAgent({ prompt: "do work", agent: "task" }, { session });
expect(runSubprocessSpy).toHaveBeenCalledTimes(1);
const options = runSubprocessSpy.mock.calls[0]?.[0];
expect(options?.mcpManager).toBe(mcpManager);
expect(options?.localProtocolOptions).toBe(localProtocolOptions);
expect(options?.parentAgentId).toBe("BridgeParent");
});
});