Files
clawdbot/src/agents/agents.test.ts
2025-12-05 17:50:02 +00:00

61 lines
2.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { piSpec } from "./pi.js";
describe("pi agent helpers", () => {
it("buildArgs injects print/format flags and identity once", () => {
const argv = ["pi", "hi"];
const built = piSpec.buildArgs({
argv,
bodyIndex: 1,
isNewSession: true,
sessionId: "sess",
sendSystemOnce: false,
systemSent: false,
identityPrefix: "IDENT",
format: "json",
});
expect(built).toContain("-p");
expect(built).toContain("--mode");
expect(built).toContain("json");
expect(built.at(-1)).toContain("IDENT");
const builtNoIdentity = piSpec.buildArgs({
argv,
bodyIndex: 1,
isNewSession: false,
sessionId: "sess",
sendSystemOnce: true,
systemSent: true,
identityPrefix: "IDENT",
format: "json",
});
expect(builtNoIdentity.at(-1)).toBe("hi");
});
it("parses final assistant message and preserves usage meta", () => {
const stdout = [
'{"type":"message_start","message":{"role":"assistant"}}',
'{"type":"message_end","message":{"role":"assistant","content":[{"type":"text","text":"hello world"}],"usage":{"input":10,"output":5},"model":"pi-1","provider":"inflection","stopReason":"end"}}',
].join("\n");
const parsed = piSpec.parseOutput(stdout);
expect(parsed.texts?.[0]).toBe("hello world");
expect(parsed.meta?.provider).toBe("inflection");
expect((parsed.meta?.usage as { output?: number })?.output).toBe(5);
});
it("piSpec carries tool names when present", () => {
const stdout =
'{"type":"message_end","message":{"role":"tool_result","name":"bash","details":{"command":"ls -la"},"content":[{"type":"text","text":"ls output"}]}}';
const parsed = piSpec.parseOutput(stdout);
const tool = parsed.toolResults?.[0] as {
text?: string;
toolName?: string;
meta?: string;
};
expect(tool?.text).toBe("ls output");
expect(tool?.toolName).toBe("bash");
expect(tool?.meta).toBe("ls -la");
});
});