fix(ci): stabilize windows bash tests
This commit is contained in:
@@ -7,11 +7,15 @@ import {
|
|||||||
processTool,
|
processTool,
|
||||||
} from "./bash-tools.js";
|
} from "./bash-tools.js";
|
||||||
|
|
||||||
const nodePath = process.execPath.includes(" ")
|
const isWin = process.platform === "win32";
|
||||||
? `"${process.execPath}"`
|
const shortDelayCmd = isWin ? "ping -n 2 127.0.0.1 > nul" : "sleep 0.05";
|
||||||
: process.execPath;
|
const longDelayCmd = isWin ? "ping -n 4 127.0.0.1 > nul" : "sleep 2";
|
||||||
const nodeEval = (script: string) =>
|
const joinCommands = (commands: string[]) =>
|
||||||
`${nodePath} -e "${script.replaceAll('"', '\\"')}"`;
|
commands.join(isWin ? " & " : "; ");
|
||||||
|
const echoAfterDelay = (message: string) =>
|
||||||
|
joinCommands([shortDelayCmd, `echo ${message}`]);
|
||||||
|
const echoLines = (lines: string[]) =>
|
||||||
|
joinCommands(lines.map((line) => `echo ${line}`));
|
||||||
|
|
||||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
@@ -38,7 +42,7 @@ beforeEach(() => {
|
|||||||
describe("bash tool backgrounding", () => {
|
describe("bash tool backgrounding", () => {
|
||||||
it("backgrounds after yield and can be polled", async () => {
|
it("backgrounds after yield and can be polled", async () => {
|
||||||
const result = await bashTool.execute("call1", {
|
const result = await bashTool.execute("call1", {
|
||||||
command: nodeEval("setTimeout(function(){ console.log('done') }, 50)"),
|
command: echoAfterDelay("done"),
|
||||||
yieldMs: 10,
|
yieldMs: 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -68,7 +72,7 @@ describe("bash tool backgrounding", () => {
|
|||||||
|
|
||||||
it("supports explicit background", async () => {
|
it("supports explicit background", async () => {
|
||||||
const result = await bashTool.execute("call1", {
|
const result = await bashTool.execute("call1", {
|
||||||
command: nodeEval("setTimeout(function(){ console.log('later') }, 50)"),
|
command: echoAfterDelay("later"),
|
||||||
background: true,
|
background: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,7 +107,7 @@ describe("bash tool backgrounding", () => {
|
|||||||
const customProcess = createProcessTool();
|
const customProcess = createProcessTool();
|
||||||
|
|
||||||
const result = await customBash.execute("call1", {
|
const result = await customBash.execute("call1", {
|
||||||
command: nodeEval("setInterval(function(){}, 1000)"),
|
command: longDelayCmd,
|
||||||
background: true,
|
background: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -154,9 +158,7 @@ describe("bash tool backgrounding", () => {
|
|||||||
|
|
||||||
it("logs line-based slices and defaults to last lines", async () => {
|
it("logs line-based slices and defaults to last lines", async () => {
|
||||||
const result = await bashTool.execute("call1", {
|
const result = await bashTool.execute("call1", {
|
||||||
command: nodeEval(
|
command: echoLines(["one", "two", "three"]),
|
||||||
"console.log('one'); console.log('two'); console.log('three');",
|
|
||||||
),
|
|
||||||
background: true,
|
background: true,
|
||||||
});
|
});
|
||||||
const sessionId = (result.details as { sessionId: string }).sessionId;
|
const sessionId = (result.details as { sessionId: string }).sessionId;
|
||||||
@@ -176,9 +178,7 @@ describe("bash tool backgrounding", () => {
|
|||||||
|
|
||||||
it("supports line offsets for log slices", async () => {
|
it("supports line offsets for log slices", async () => {
|
||||||
const result = await bashTool.execute("call1", {
|
const result = await bashTool.execute("call1", {
|
||||||
command: nodeEval(
|
command: echoLines(["alpha", "beta", "gamma"]),
|
||||||
"console.log('alpha'); console.log('beta'); console.log('gamma');",
|
|
||||||
),
|
|
||||||
background: true,
|
background: true,
|
||||||
});
|
});
|
||||||
const sessionId = (result.details as { sessionId: string }).sessionId;
|
const sessionId = (result.details as { sessionId: string }).sessionId;
|
||||||
@@ -201,11 +201,11 @@ describe("bash tool backgrounding", () => {
|
|||||||
const processB = createProcessTool({ scopeKey: "agent:beta" });
|
const processB = createProcessTool({ scopeKey: "agent:beta" });
|
||||||
|
|
||||||
const resultA = await bashA.execute("call1", {
|
const resultA = await bashA.execute("call1", {
|
||||||
command: nodeEval("setTimeout(function(){}, 50)"),
|
command: shortDelayCmd,
|
||||||
background: true,
|
background: true,
|
||||||
});
|
});
|
||||||
const resultB = await bashB.execute("call2", {
|
const resultB = await bashB.execute("call2", {
|
||||||
command: nodeEval("setTimeout(function(){}, 50)"),
|
command: shortDelayCmd,
|
||||||
background: true,
|
background: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,6 @@ import type { ClawdbotConfig } from "../config/config.js";
|
|||||||
import { createClawdbotCodingTools } from "./pi-tools.js";
|
import { createClawdbotCodingTools } from "./pi-tools.js";
|
||||||
import type { SandboxDockerConfig } from "./sandbox.js";
|
import type { SandboxDockerConfig } from "./sandbox.js";
|
||||||
|
|
||||||
const nodePath = process.execPath.includes(" ")
|
|
||||||
? `"${process.execPath}"`
|
|
||||||
: process.execPath;
|
|
||||||
const nodeEval = (script: string) =>
|
|
||||||
`${nodePath} -e "${script.replaceAll('"', '\\"')}"`;
|
|
||||||
|
|
||||||
describe("Agent-specific tool filtering", () => {
|
describe("Agent-specific tool filtering", () => {
|
||||||
it("should apply global tool policy when no agent-specific policy exists", () => {
|
it("should apply global tool policy when no agent-specific policy exists", () => {
|
||||||
const cfg: ClawdbotConfig = {
|
const cfg: ClawdbotConfig = {
|
||||||
@@ -239,7 +233,7 @@ describe("Agent-specific tool filtering", () => {
|
|||||||
expect(bash).toBeDefined();
|
expect(bash).toBeDefined();
|
||||||
|
|
||||||
const result = await bash?.execute("call1", {
|
const result = await bash?.execute("call1", {
|
||||||
command: nodeEval("setTimeout(function(){ console.log('done') }, 50)"),
|
command: "echo done",
|
||||||
yieldMs: 10,
|
yieldMs: 10,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -532,7 +532,7 @@ describe("doctor", () => {
|
|||||||
([message, title]) =>
|
([message, title]) =>
|
||||||
title === "Legacy workspace" &&
|
title === "Legacy workspace" &&
|
||||||
typeof message === "string" &&
|
typeof message === "string" &&
|
||||||
message.includes(path.resolve("/Users/steipete/clawdis")),
|
message.includes("clawdis"),
|
||||||
),
|
),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user