Files
oh-my-pi/packages/coding-agent/test/tools/task-repair-args.test.ts
T
can1357 9d99ae1af0 feat(coding-agent): rewrote the task tool to spawn one persistent subagent per call
The task tool now takes a single { agent, assignment, description, ... } and always runs the subagent in the background — the batch tasks[] array and shared context parameter are gone. Fan-out is parallel task calls; shared background flows through a '/Users/can/.omp/agent/sessions/-Projects-.tree-pi-commit/2026-06-10T15-36-32-782Z_019eb22d-970e-7000-8964-72c98becf3e8/local' file referenced in each assignment.\n\nIntroduces a persistent subagent lifecycle: finished subagents stay live as idle, the lifecycle manager parks them to disk after task.agentIdleTtlMs (default 7 minutes; 0 keeps them live until exit), and they revive automatically when prompted from the Agent Hub, messaged on IRC, or resumed via task. New task(resume: "<id>") revives an idle or parked subagent and runs a follow-up assignment in its existing session.\n\nAdds soft request budgets (explore/quick_task 40, others 90, configurable via task.softRequestBudget, 0 disables): crossing the budget injects a one-time wrap-up steer into the child; crossing 1.5× aborts the run gracefully. Cancelled/aborted subagent salvage replaces the old (no output) with the child's last activity snippet plus request/token stats; SingleResult tracks a per-child requests counter (assistant message_end events) used to sort agent lists in runtime-ascending order in both the live progress view (finished agents above pending/running) and the finalized result view, so rows no longer reshuffle on finalize. Adds a task gallery fixture variant for the resume path (renderer key separated from fixture key).\n\nAll task tests are reshaped around the single-call contract; tests for the discarded shared-context flow are removed, and new task-guards/task-resume/task-schema tests pin the new contract surface.
2026-06-10 17:54:47 +02:00

72 lines
2.9 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { repairDoubleEncodedJsonString, repairTaskParams } from "@oh-my-pi/pi-coding-agent/task/repair-args";
import type { TaskParams } from "@oh-my-pi/pi-coding-agent/task/types";
describe("repairDoubleEncodedJsonString", () => {
it("decodes a uniformly double-encoded prose value", () => {
// One JSON decode already applied by the provider; the value still
// carries literal `\n`, `\"`, and `\u2014` because the model escaped twice.
const doubled = '# Role\\nYou are a judge \\"describe this\\" return \\u2014';
expect(repairDoubleEncodedJsonString(doubled)).toBe('# Role\nYou are a judge "describe this" return —');
});
it("decodes a double-encoded multi-line plain-text value", () => {
expect(repairDoubleEncodedJsonString("line one\\nline two\\nline three")).toBe("line one\nline two\nline three");
});
it("preserves a Windows path (bare backslashes are not valid escapes)", () => {
expect(repairDoubleEncodedJsonString("C:\\Users\\me")).toBe("C:\\Users\\me");
});
it("preserves a regex with a backslash class", () => {
expect(repairDoubleEncodedJsonString("match \\d+ digits")).toBe("match \\d+ digits");
});
it("preserves text containing a bare double quote", () => {
expect(repairDoubleEncodedJsonString('she said "hi" loudly')).toBe('she said "hi" loudly');
});
it("leaves a lone literal \\n mention alone (no double-encode signature)", () => {
expect(repairDoubleEncodedJsonString("split lines on \\n then count")).toBe("split lines on \\n then count");
});
it("is a no-op for plain text without escapes", () => {
const plain = "just some normal instructions";
expect(repairDoubleEncodedJsonString(plain)).toBe(plain);
});
it("leaves a partially-decoded value (real newline mixed with literal escape) untouched", () => {
// A real newline cannot appear inside a JSON string literal unescaped, so
// the round-trip parse throws and the value is preserved as-is.
const mixed = "real\nnewline with \\t tab";
expect(repairDoubleEncodedJsonString(mixed)).toBe(mixed);
});
});
describe("repairTaskParams", () => {
it("repairs assignment and description, leaving agent/id intact", () => {
const params = {
agent: "task",
id: "FirstTask",
description: 'judge \\"sketch\\" accuracy',
assignment: "Score 0-100.\\nUse the full range.\\nNo bunching.",
} as unknown as TaskParams;
const repaired = repairTaskParams(params);
expect(repaired.agent).toBe("task");
expect(repaired.id).toBe("FirstTask");
expect(repaired.description).toBe('judge "sketch" accuracy');
expect(repaired.assignment).toBe("Score 0-100.\nUse the full range.\nNo bunching.");
});
it("returns the same reference when nothing needs repair", () => {
const params = {
agent: "task",
id: "A",
description: "label",
assignment: "do work",
} as unknown as TaskParams;
expect(repairTaskParams(params)).toBe(params);
});
});