diff --git a/src/wrapper/cli.test.ts b/src/wrapper/cli.test.ts index 192a0b6..7629520 100644 --- a/src/wrapper/cli.test.ts +++ b/src/wrapper/cli.test.ts @@ -192,6 +192,74 @@ test("wrapper passes --append-system-prompt when the prompt file exists", async 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 () => { const captured = await runWrapperWithFakePi("github-copilot/gpt-4o"); assert.equal(captured.flags.PI_SUBAGENTS_GITHUB_COPILOT_INITIATOR, "agent"); diff --git a/src/wrapper/render.test.ts b/src/wrapper/render.test.ts index d40a382..a860376 100644 --- a/src/wrapper/render.test.ts +++ b/src/wrapper/render.test.ts @@ -17,6 +17,20 @@ test("renderHeader prints generic subagent metadata", () => { 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", () => { const line = renderEventLine({ type: "tool_call",