Files
oh-my-pi/packages/coding-agent/test/task/task-schema.test.ts
T
can1357 6ac73655c8 feat(coding-agent): removed resume support and switched task execution to spawn-only
- Removed `resume` from task params and schema, requiring agent and assignment inputs.
- Dropped resume continuation paths in task execution and call rendering, always spawning a new agent.
- Removed the `irc.enabled` setting and computed IRC availability by task-depth rules.
- Updated task follow-up guidance to use IRC messaging/history links instead of `task(resume:)`.
2026-06-10 23:00:03 +02:00

74 lines
2.5 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";
// Contract (rework-contracts.md §3): the task tool spawns ONE agent per call.
// `tasks[]` and `context` are gone; follow-ups go through `irc` messaging.
describe("task schema (single-spawn)", () => {
it("accepts {agent, assignment}", () => {
const parsed = taskSchema.safeParse({ agent: "explore", assignment: "Map the auth module." });
expect(parsed.success).toBe(true);
});
it("requires agent", () => {
const parsed = taskSchema.safeParse({ assignment: "Map the auth module." });
expect(parsed.success).toBe(false);
});
it("requires assignment", () => {
const parsed = taskSchema.safeParse({ agent: "explore" });
expect(parsed.success).toBe(false);
});
it("carries no tasks/context fields", () => {
const parsed = taskSchema.safeParse({
agent: "explore",
assignment: "Map the auth module.",
context: "shared background",
tasks: [{ id: "A", assignment: "..." }],
});
expect(parsed.success).toBe(true);
if (parsed.success) {
// Unknown keys are stripped: the batch/context shape no longer exists.
expect("tasks" in parsed.data).toBe(false);
expect("context" in parsed.data).toBe(false);
}
});
});
describe("task spawn validation", () => {
afterEach(() => {
vi.restoreAllMocks();
});
function createSession(): ToolSession {
return {
cwd: "/tmp",
hasUI: false,
settings: Settings.isolated({ "task.isolation.mode": "none" }),
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`");
});
});