test(wrapper): cover preset header and empty metadata

This commit is contained in:
pi
2026-04-12 13:41:07 +01:00
parent 4826c103a2
commit afab606237
2 changed files with 82 additions and 0 deletions

View File

@@ -192,6 +192,74 @@ test("wrapper passes --append-system-prompt when the prompt file exists", async
assert.equal(argv[idx + 1], promptPath); assert.equal(argv[idx + 1], promptPath);
}); });
test("wrapper omits tools and system prompt flags when metadata is absent or empty", async () => {
const dir = await mkdtemp(join(tmpdir(), "pi-subagents-wrapper-"));
const metaPath = join(dir, "meta.json");
const resultPath = join(dir, "result.json");
const capturePath = join(dir, "capture.json");
const piPath = join(dir, "pi");
await writeFile(
piPath,
[
`#!${process.execPath}`,
"const fs = require('fs');",
`const capturePath = ${JSON.stringify(capturePath)};`,
"const obj = {",
" PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR: process.env.PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR || '',",
" PI_SUBAGENTS_CHILD: process.env.PI_SUBAGENTS_CHILD || '',",
" argv: process.argv.slice(2)",
"};",
"fs.writeFileSync(capturePath, JSON.stringify(obj), 'utf8');",
"console.log(JSON.stringify({type:'message_end',message:{role:'assistant',content:[{type:'text',text:'done'}],model:'github-copilot/gpt-4o',stopReason:'stop'}}));",
].join("\n"),
"utf8",
);
await chmod(piPath, 0o755);
await writeFile(
metaPath,
JSON.stringify(
{
runId: "run-1",
mode: "single",
task: "inspect auth",
cwd: dir,
requestedModel: "anthropic/claude-sonnet-4-5",
resolvedModel: "anthropic/claude-sonnet-4-5",
startedAt: "2026-04-09T00:00:00.000Z",
sessionPath: join(dir, "child-session.jsonl"),
eventsPath: join(dir, "events.jsonl"),
resultPath,
stdoutPath: join(dir, "stdout.log"),
stderrPath: join(dir, "stderr.log"),
transcriptPath: join(dir, "transcript.log"),
tools: [],
},
null,
2,
),
"utf8",
);
const wrapperPath = join(dirname(fileURLToPath(import.meta.url)), "cli.mjs");
const child = spawn(process.execPath, [wrapperPath, metaPath], {
env: {
...process.env,
PATH: dir,
},
stdio: ["ignore", "pipe", "pipe"],
});
const exitCode = await waitForExit(child);
assert.equal(exitCode, 0);
const captureJson = JSON.parse(await readFile(capturePath, "utf8"));
const argv = captureJson.argv;
assert.equal(argv.includes("--tools"), false);
assert.equal(argv.includes("--append-system-prompt"), false);
});
test("wrapper marks github-copilot child runs as agent-initiated", async () => { test("wrapper marks github-copilot child runs as agent-initiated", async () => {
const captured = await runWrapperWithFakePi("github-copilot/gpt-4o"); const captured = await runWrapperWithFakePi("github-copilot/gpt-4o");
assert.equal(captured.flags.PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR, "agent"); assert.equal(captured.flags.PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR, "agent");

View File

@@ -17,6 +17,20 @@ test("renderHeader prints generic subagent metadata", () => {
assert.match(header, /Session: \/repo\/\.pi\/subagents\/runs\/run-1\/child-session\.jsonl/); assert.match(header, /Session: \/repo\/\.pi\/subagents\/runs\/run-1\/child-session\.jsonl/);
}); });
test("renderHeader includes preset when present", () => {
const header = renderHeader({
preset: "auth-inspector",
task: "Inspect authentication code",
cwd: "/repo",
requestedModel: "anthropic/claude-sonnet-4-5",
resolvedModel: "anthropic/claude-sonnet-4-5",
sessionPath: "/repo/.pi/subagents/runs/run-1/child-session.jsonl",
});
assert.match(header, /Preset: auth-inspector/);
assert.doesNotMatch(header, /Agent:/);
});
test("renderEventLine keeps bash commands readable for subagent transcript output", () => { test("renderEventLine keeps bash commands readable for subagent transcript output", () => {
const line = renderEventLine({ const line = renderEventLine({
type: "tool_call", type: "tool_call",