Files
oh-my-pi/packages/coding-agent/test/task/task-schema.test.ts
T
can1357 a050474af7 feat: migrated validation schemas and tool definitions from Zod to ArkType
- Migrated all wire protocol, schema definitions, and tools validation from Zod to ArkType across multiple packages.
- Updated extension runtimes, custom tools loader, and TypeBox compatibility shim to expose and use ArkType instances.
- Added a comprehensive ArkType migration guide, validation parity tests, and helper utilities.
- Removed redundant PDF asset routing and parsing implementations from the read tool.
2026-06-18 00:59:53 +02:00

81 lines
2.9 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "bun:test";
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { TaskTool, taskSchema } from "@oh-my-pi/pi-coding-agent/task";
import * as discoveryModule from "@oh-my-pi/pi-coding-agent/task/discovery";
import type { ToolSession } from "@oh-my-pi/pi-coding-agent/tools";
import { type } from "arktype";
// Contract: the single-spawn schema (`task.batch: false`; the exported
// `taskSchema` instance) carries no batch fields. The batch shape (`tasks[]` +
// shared `context`) is gated by the `task.batch` setting (default on, covered
// by test/task/task-batch.test.ts), and a per-call `schema` input no longer
// exists at all; follow-ups go through `irc` messaging.
describe("task schema (single-spawn)", () => {
it("accepts {agent, assignment}", () => {
const parsed = taskSchema({ agent: "explore", assignment: "Map the auth module." });
expect(parsed instanceof type.errors).toBe(false);
});
it("requires agent", () => {
const parsed = taskSchema({ assignment: "Map the auth module." });
expect(parsed instanceof type.errors).toBe(true);
});
it("requires assignment", () => {
const parsed = taskSchema({ agent: "explore" });
expect(parsed instanceof type.errors).toBe(true);
});
it("strips tasks/context/schema from the single-spawn schema", () => {
const parsed = taskSchema({
agent: "explore",
assignment: "Map the auth module.",
context: "shared background",
tasks: [{ id: "A", assignment: "..." }],
schema: '{"properties":{}}',
});
expect(parsed instanceof type.errors).toBe(false);
if (!(parsed instanceof type.errors)) {
// Unknown keys are stripped: batch/context exist only on the batch
// schema and the per-call schema input was removed outright.
expect("tasks" in parsed).toBe(false);
expect("context" in parsed).toBe(false);
expect("schema" in parsed).toBe(false);
}
});
});
describe("task spawn validation", () => {
afterEach(() => {
vi.restoreAllMocks();
});
function createSession(): ToolSession {
return {
cwd: "/tmp",
hasUI: false,
settings: Settings.isolated({ "task.isolation.mode": "none", "task.batch": false }),
getSessionFile: () => null,
getSessionSpawns: () => "*",
} as unknown as ToolSession;
}
async function executeText(params: unknown): Promise<string> {
vi.spyOn(discoveryModule, "discoverAgents").mockResolvedValue({ agents: [], projectAgentsDir: null });
const tool = await TaskTool.create(createSession());
const result = await tool.execute("tool-call", params);
return result.content.find(part => part.type === "text")?.text ?? "";
}
it("rejects a missing agent", async () => {
const text = await executeText({ assignment: "..." });
expect(text).toContain("Missing `agent`");
});
it("rejects a missing assignment", async () => {
const text = await executeText({ agent: "explore" });
expect(text).toContain("Missing `assignment`");
});
});