Files
oh-my-pi/packages/coding-agent/src/eval/py/__tests__/prelude.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

33 lines
1.6 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { PYTHON_PRELUDE } from "../prelude";
describe("python prelude", () => {
it("exposes read(path, offset?, limit?) with positional optional args", () => {
// The eval docs advertise `read(path, offset?=1, limit?=None)`. A
// keyword-only signature (`def read(path, *, offset=1, limit=None)`)
// makes `read("file", 10)` raise `TypeError: read() takes 1 positional
// argument but 2 were given`, which agents in the wild repeatedly hit.
// Lock the contract so the helper accepts both positional and keyword
// forms.
const match = PYTHON_PRELUDE.match(/def\s+read\(([^)]+)\)/);
expect(match).not.toBeNull();
const signature = match?.[1] ?? "";
expect(signature).not.toContain("*,");
expect(signature).toContain("offset");
expect(signature).toContain("limit");
});
it("exposes isolation artifacts on the agent() handle node", () => {
// agent(..., handle=True) is the only escape hatch for
// recovering apply=False patch/branch/nested artifacts (the bare
// schema return is just the parsed object), so the helper MUST
// translate the bridge's camelCase details onto the node — otherwise
// an isolated apply=False workflow loses captured nested patches.
expect(PYTHON_PRELUDE).toContain('("patchPath", "patch_path")');
expect(PYTHON_PRELUDE).toContain('("branchName", "branch_name")');
expect(PYTHON_PRELUDE).toContain('("nestedPatches", "nested_patches")');
expect(PYTHON_PRELUDE).toContain('("changesApplied", "changes_applied")');
expect(PYTHON_PRELUDE).toContain('("isolationSummary", "isolation_summary")');
});
});