Files
oh-my-pi/packages/coding-agent/test/job-renderer-preview.test.ts
T
can1357 cfeaee0105 feat(coding-agent): add shimmer to running jobs and refine ID display
- Running job labels now shimmer in the TUI to provide a dynamic visual indicator of activity.
- Adjusted cache key to account for shimmer animation, ensuring it updates at 30fps instead of the 12.5fps spinner cadence.
- Suppressed job ID display when the job label is identical to its ID, avoiding redundant information.
2026-06-12 04:01:10 +02:00

114 lines
3.7 KiB
TypeScript

/**
* The job tool's TUI preview must not leak the model-facing `<task-result>`
* envelope (prompts/tools/task-summary.md): a settled task job previews the
* inner <output>/<preview> body, while non-envelope result text (bash jobs)
* passes through unchanged.
*/
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
import { resetSettingsForTest, Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { initTheme, theme } from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
import { jobToolRenderer } from "@oh-my-pi/pi-coding-agent/tools/job";
import { prompt } from "@oh-my-pi/pi-utils";
import taskSummaryTemplate from "../src/prompts/tools/task-summary.md" with { type: "text" };
function renderLines(resultText: string): string {
const result = {
content: [{ type: "text", text: "" }],
details: {
jobs: [
{
id: "SpawnProbe",
type: "task" as const,
status: "completed" as const,
label: "SpawnProbe",
durationMs: 8_700,
resultText,
},
],
},
};
const component = jobToolRenderer.renderResult(
result,
{ expanded: true } as Parameters<typeof jobToolRenderer.renderResult>[1],
theme,
);
return (component.render(120) as readonly string[]).join("\n");
}
describe("job renderer task-result preview", () => {
beforeAll(async () => {
resetSettingsForTest();
await Settings.init({ inMemory: true });
await initTheme();
});
afterAll(() => {
resetSettingsForTest();
});
it("previews the envelope body, not the wrapper markup", () => {
const summary = prompt.render(taskSummaryTemplate, {
agentName: "quick_task",
id: "SpawnProbe",
status: "completed",
duration: "8.7s",
preview: "Probe finished: spawned worker, ping ok.",
truncated: false,
meta: { lineCount: 3, charSize: "120 B" },
mergeSummary: "",
});
const deliveryText = `${summary}\n\nSpawnProbe is now idle — message it via \`irc\` to follow up; transcript at history://SpawnProbe`;
const output = renderLines(deliveryText);
expect(output).toContain("Probe finished: spawned worker, ping ok.");
expect(output).not.toContain("<task-result");
expect(output).not.toContain("<output>");
});
it("previews the truncated <preview> body the same way", () => {
const summary = prompt.render(taskSummaryTemplate, {
agentName: "task",
id: "BigOne",
status: "completed",
duration: "2m",
preview: "first line of long output",
truncated: true,
mergeSummary: "",
});
const output = renderLines(summary);
expect(output).toContain("first line of long output");
expect(output).not.toContain("<task-result");
});
it("flattens a pretty-printed JSON body instead of previewing a lone brace", () => {
const summary = prompt.render(taskSummaryTemplate, {
agentName: "quick_task",
id: "EchoAlpha",
status: "completed",
duration: "11.6s",
preview: '{\n "echo": "alpha",\n "ok": true\n}',
truncated: false,
mergeSummary: "",
});
const output = Bun.stripANSI(renderLines(summary));
expect(output).toContain('{ "echo": "alpha", "ok": true }');
expect(output.split("\n").some(line => line.trim() === "{")).toBe(false);
});
it("passes non-envelope result text through unchanged", () => {
const output = renderLines("42 pass, 0 fail (18.4s)");
expect(output).toContain("42 pass, 0 fail (18.4s)");
});
it("drops the id column when the label repeats it", () => {
// Task jobs label themselves with their agent id; rendering both columns
// stutters ("SpawnProbe ⟨task⟩ SpawnProbe").
const output = Bun.stripANSI(renderLines("done"));
const header = output.split("\n").find(line => line.includes("SpawnProbe"));
expect(header).toBeDefined();
expect(header!.match(/SpawnProbe/g)).toHaveLength(1);
});
});