mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 01:38:26 +00:00
refactor(test): snapshot shell/path env in bash tools e2e
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||||
import { peekSystemEvents, resetSystemEventsForTest } from "../infra/system-events.js";
|
import { peekSystemEvents, resetSystemEventsForTest } from "../infra/system-events.js";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
import { getFinishedSession, resetProcessRegistryForTests } from "./bash-process-registry.js";
|
import { getFinishedSession, resetProcessRegistryForTests } from "./bash-process-registry.js";
|
||||||
import { createExecTool, createProcessTool, execTool, processTool } from "./bash-tools.js";
|
import { createExecTool, createProcessTool, execTool, processTool } from "./bash-tools.js";
|
||||||
import { buildDockerExecArgs } from "./bash-tools.shared.js";
|
import { buildDockerExecArgs } from "./bash-tools.shared.js";
|
||||||
@@ -61,18 +62,17 @@ beforeEach(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("exec tool backgrounding", () => {
|
describe("exec tool backgrounding", () => {
|
||||||
const originalShell = process.env.SHELL;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
envSnapshot = captureEnv(["SHELL"]);
|
||||||
if (!isWin && defaultShell) {
|
if (!isWin && defaultShell) {
|
||||||
process.env.SHELL = defaultShell;
|
process.env.SHELL = defaultShell;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (!isWin) {
|
envSnapshot.restore();
|
||||||
process.env.SHELL = originalShell;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it(
|
it(
|
||||||
@@ -301,18 +301,17 @@ describe("exec tool backgrounding", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("exec exit codes", () => {
|
describe("exec exit codes", () => {
|
||||||
const originalShell = process.env.SHELL;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
envSnapshot = captureEnv(["SHELL"]);
|
||||||
if (!isWin && defaultShell) {
|
if (!isWin && defaultShell) {
|
||||||
process.env.SHELL = defaultShell;
|
process.env.SHELL = defaultShell;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (!isWin) {
|
envSnapshot.restore();
|
||||||
process.env.SHELL = originalShell;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("treats non-zero exits as completed and appends exit code", async () => {
|
it("treats non-zero exits as completed and appends exit code", async () => {
|
||||||
@@ -416,20 +415,17 @@ describe("exec notifyOnExit", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("exec PATH handling", () => {
|
describe("exec PATH handling", () => {
|
||||||
const originalPath = process.env.PATH;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
const originalShell = process.env.SHELL;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
envSnapshot = captureEnv(["PATH", "SHELL"]);
|
||||||
if (!isWin && defaultShell) {
|
if (!isWin && defaultShell) {
|
||||||
process.env.SHELL = defaultShell;
|
process.env.SHELL = defaultShell;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
process.env.PATH = originalPath;
|
envSnapshot.restore();
|
||||||
if (!isWin) {
|
|
||||||
process.env.SHELL = originalShell;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("prepends configured path entries", async () => {
|
it("prepends configured path entries", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user