Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/node/services/tools/bash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,25 +1009,22 @@ describe("bash tool", () => {
}
});

it("should block sleep command at start of script", async () => {
it("should allow sleep command at start of script", async () => {
using testEnv = createTestBashTool();
const tool = testEnv.tool;
const args: BashToolArgs = {
script: "sleep 5",
timeout_secs: 10,
script: "sleep 0.1; echo done",
timeout_secs: 5,
run_in_background: false,
display_name: "test",
};

const result = (await tool.execute!(args, mockToolCallOptions)) as BashToolResult;

expect(result.success).toBe(false);
if (!result.success) {
expect(result.error).toContain("do not start commands with sleep");
expect(result.error).toContain("prefer <10s sleeps in busy loops");
expect(result.error).toContain("while ! condition");
expect(result.exitCode).toBe(-1);
expect(result.wall_duration_ms).toBe(0);
expect(result.success).toBe(true);
if (result.success) {
expect(result.output).toBe("done");
expect(result.exitCode).toBe(0);
}
});

Expand Down Expand Up @@ -1096,7 +1093,6 @@ describe("zombie process cleanup", () => {

// Spawn a background sleep process that would become a zombie if not cleaned up
// Use a unique marker to identify our test process
// Note: Start with echo to avoid triggering standalone sleep blocker
const marker = `zombie-test-${Date.now()}`;
const args: BashToolArgs = {
script: `echo "${marker}"; sleep 100 & echo $!`,
Expand Down
11 changes: 0 additions & 11 deletions src/node/services/tools/bash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ function validateScript(script: string, config: ToolConfiguration): BashToolResu
};
}

// Block sleep at the beginning of commands - they waste time waiting
if (/^\s*sleep\s/.test(script)) {
return {
success: false,
error:
"do not start commands with sleep; prefer <10s sleeps in busy loops (e.g., 'while ! condition; do sleep 1; done' or 'until condition; do sleep 1; done').",
exitCode: -1,
wall_duration_ms: 0,
};
}

// Detect redundant cd to working directory
const cdPattern = /^\s*cd\s+['"]?([^'";&|]+)['"]?\s*[;&|]/;
const match = cdPattern.exec(script);
Expand Down
Loading