63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "bun:test";
|
|
import { Settings } from "../../src/config/settings";
|
|
import * as taskDiscovery from "../../src/task/discovery";
|
|
import { TaskTool } from "../../src/task/index";
|
|
import type { AgentDefinition } from "../../src/task/types";
|
|
import { getTaskSchema } from "../../src/task/types";
|
|
import type { ToolSession } from "../../src/tools";
|
|
|
|
const factFinderAgent = {
|
|
name: "fact-finder",
|
|
description: "Find facts.",
|
|
systemPrompt: "Find facts.",
|
|
source: "project",
|
|
} satisfies AgentDefinition;
|
|
|
|
const oracleAgent = {
|
|
name: "oracle",
|
|
description: "Answer hard questions.",
|
|
systemPrompt: "Answer hard questions.",
|
|
source: "bundled",
|
|
} satisfies AgentDefinition;
|
|
|
|
function makeSession(spawns: string): ToolSession {
|
|
const settings = Settings.isolated({
|
|
"async.enabled": false,
|
|
"task.batch": true,
|
|
"task.isolation.mode": "none",
|
|
});
|
|
return {
|
|
cwd: process.cwd(),
|
|
hasUI: false,
|
|
settings,
|
|
getSessionFile: () => null,
|
|
getSessionSpawns: () => spawns,
|
|
};
|
|
}
|
|
|
|
describe("task spawn policy surfaces", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("uses the first allowed spawn as the schema default", () => {
|
|
const schema = getTaskSchema({ isolationEnabled: false, batchEnabled: false, defaultAgent: "fact-finder" });
|
|
const parsed = schema({ task: "check" });
|
|
|
|
expect(parsed).toEqual({ agent: "fact-finder", task: "check" });
|
|
});
|
|
|
|
it("filters the agent list to the restricted spawn policy in the description", async () => {
|
|
vi.spyOn(taskDiscovery, "discoverAgents").mockResolvedValue({
|
|
agents: [factFinderAgent, oracleAgent],
|
|
projectAgentsDir: null,
|
|
});
|
|
|
|
const tool = await TaskTool.create(makeSession("fact-finder"));
|
|
const description = tool.description;
|
|
|
|
expect(description).toContain("### fact-finder");
|
|
expect(description).not.toContain("### oracle");
|
|
});
|
|
});
|