Skip to content

Commit b671c1b

Browse files
authored
test: consolidate Bash tools suites (#117856)
* test: consolidate bash tools suites * test: satisfy consolidated suite checks
1 parent 72d9019 commit b671c1b

16 files changed

Lines changed: 773 additions & 1261 deletions

‎src/agents/bash-tools.build-docker-exec-args.test.ts‎

Lines changed: 0 additions & 98 deletions
This file was deleted.

‎src/agents/bash-tools.exec-approval-continuation.integration.test.ts‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

‎src/agents/bash-tools.exec-approval-output.test.ts‎

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { describe, expect, it } from "vitest";
1+
import { afterEach, describe, expect, it } from "vitest";
2+
import { resetProcessRegistryForTests } from "./bash-process-registry.test-support.js";
23
import {
34
buildExecApprovalContinuationFallbackPrompt,
45
buildExecApprovalContinuationPrompt,
56
formatExecApprovalContinuationSourceOutput,
67
resizeExecApprovalContinuationPrompt,
78
} from "./bash-tools.exec-approval-output.js";
9+
import {
10+
appendExecTimeoutRetryGuidance,
11+
renderExecOutputText,
12+
renderExecUpdateText,
13+
} from "./bash-tools.exec-output.js";
14+
import { runExecProcess } from "./bash-tools.exec-runtime.js";
815

916
const MAX_SOURCE_UTF16_UNITS = 256_000;
1017
const MARKER =
@@ -186,3 +193,98 @@ describe("resizeExecApprovalContinuationPrompt", () => {
186193
expect(resized.split(OUTPUT_END)).toHaveLength(2);
187194
});
188195
});
196+
197+
describe("exec output rendering", () => {
198+
it.each(["overall-timeout", "no-output-timeout"] as const)(
199+
"warns that %s may already have produced side effects",
200+
(exitReason) => {
201+
const text = appendExecTimeoutRetryGuidance("Command timed out.", exitReason);
202+
203+
expect(text).toContain("external side effects may already have completed");
204+
expect(text).toContain("Verify the resulting state before retrying");
205+
expect(text).toContain("Do not automatically rerun non-idempotent commands");
206+
expect(text).toContain("known to be safe to retry");
207+
},
208+
);
209+
210+
it("leaves non-timeout exits unchanged", () => {
211+
expect(appendExecTimeoutRetryGuidance("Command failed.", "signal")).toBe("Command failed.");
212+
});
213+
214+
it.each([
215+
{ name: "undefined input", input: undefined, expected: "(no output)" },
216+
{ name: "empty input", input: "", expected: "(no output)" },
217+
{ name: "non-empty input", input: "hello", expected: "hello" },
218+
{ name: "whitespace-only input", input: " ", expected: " " },
219+
{ name: "multiline input", input: "line1\nline2", expected: "line1\nline2" },
220+
])("renders $name", ({ input, expected }) => {
221+
expect(renderExecOutputText(input)).toBe(expected);
222+
});
223+
224+
it.each([
225+
{ name: "no output", input: { warnings: [] }, expected: "(no output)" },
226+
{ name: "tail output", input: { tailText: "hello", warnings: [] }, expected: "hello" },
227+
{
228+
name: "warning without output",
229+
input: { warnings: ["warning1"] },
230+
expected: "warning1\n\n(no output)",
231+
},
232+
{
233+
name: "warning and output",
234+
input: { tailText: "hello", warnings: ["warning1"] },
235+
expected: "warning1\n\nhello",
236+
},
237+
{
238+
name: "multiple warnings",
239+
input: { tailText: "hello", warnings: ["warning1", "warning2"] },
240+
expected: "warning1\nwarning2\n\nhello",
241+
},
242+
{
243+
name: "explicit empty warnings",
244+
input: { tailText: "hello", warnings: [] },
245+
expected: "hello",
246+
},
247+
{
248+
name: "undefined tail with warnings",
249+
input: { tailText: undefined, warnings: ["warning1"] },
250+
expected: "warning1\n\n(no output)",
251+
},
252+
])("renders updates with $name", ({ input, expected }) => {
253+
expect(renderExecUpdateText(input)).toBe(expected);
254+
});
255+
});
256+
257+
describe("approved exec continuation producer", () => {
258+
afterEach(() => {
259+
resetProcessRegistryForTests();
260+
});
261+
262+
it.runIf(process.platform !== "win32")(
263+
"preserves real multiline output beyond the legacy 16k boundary",
264+
async () => {
265+
const handle = await runExecProcess({
266+
command: "/usr/bin/printf 'first line\\n\\tindented\\n\\n'; /usr/bin/printf '%017000d' 0",
267+
workdir: process.cwd(),
268+
env: {
269+
HOME: process.env.HOME ?? "/tmp",
270+
PATH: process.env.PATH ?? "/usr/bin:/bin",
271+
},
272+
usePty: false,
273+
warnings: [],
274+
maxOutput: 200_000,
275+
pendingMaxOutput: 200_000,
276+
notifyOnExit: false,
277+
timeoutSec: 10,
278+
});
279+
280+
const outcome = await handle.promise;
281+
expect(outcome.status).toBe("completed");
282+
const source = formatExecApprovalContinuationSourceOutput([
283+
{ label: "output", value: outcome.aggregated },
284+
]);
285+
expect(source).toContain("first line\n\tindented\n\n");
286+
expect(source.length).toBeGreaterThan(16_000);
287+
expect(source).toBe(outcome.aggregated);
288+
},
289+
);
290+
});

‎src/agents/bash-tools.exec-approval-request.test.ts‎

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,16 @@ describe("exec approval requests", () => {
225225
expect(payload?.approvalReviewerDeviceIds).toEqual(["device-ios-reviewer"]);
226226
});
227227

228-
it("does not generate command spans by default", async () => {
228+
it.each([
229+
{ name: "by default", commandHighlighting: undefined },
230+
{ name: "when command highlighting is disabled", commandHighlighting: false },
231+
])("does not generate command spans $name", async ({ commandHighlighting }) => {
229232
vi.mocked(callGatewayTool).mockResolvedValue({ id: "approval-id", expiresAtMs: 1234 });
230233

231234
await registerExecApprovalRequestForHostOrThrow({
232235
approvalId: "approval-id",
233236
command: 'ls | grep "stuff" | python -c \'print("hi")\'',
237+
...(commandHighlighting === undefined ? {} : { commandHighlighting }),
234238
workdir: "/tmp/project",
235239
host: "node",
236240
security: "allowlist",
@@ -239,27 +243,7 @@ describe("exec approval requests", () => {
239243

240244
expect(commandExplainerMock.explainShellCommand).not.toHaveBeenCalled();
241245
expect(commandExplainerMock.formatCommandSpans).not.toHaveBeenCalled();
242-
const payload = requireApprovalRequestPayload(0);
243-
expect(payload?.commandSpans).toBeUndefined();
244-
});
245-
246-
it("does not generate command spans when command highlighting is disabled", async () => {
247-
vi.mocked(callGatewayTool).mockResolvedValue({ id: "approval-id", expiresAtMs: 1234 });
248-
249-
await registerExecApprovalRequestForHostOrThrow({
250-
approvalId: "approval-id",
251-
command: 'ls | grep "stuff" | python -c \'print("hi")\'',
252-
commandHighlighting: false,
253-
workdir: "/tmp/project",
254-
host: "node",
255-
security: "allowlist",
256-
ask: "always",
257-
});
258-
259-
expect(commandExplainerMock.explainShellCommand).not.toHaveBeenCalled();
260-
expect(commandExplainerMock.formatCommandSpans).not.toHaveBeenCalled();
261-
const payload = requireApprovalRequestPayload(0);
262-
expect(payload?.commandSpans).toBeUndefined();
246+
expect(requireApprovalRequestPayload(0).commandSpans).toBeUndefined();
263247
});
264248

265249
it("uses system run plan command text for host approval explanations", async () => {

0 commit comments

Comments
 (0)