mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 20:54:30 +00:00
refactor(test): reuse env helper in gateway tool e2e
This commit is contained in:
@@ -2,7 +2,7 @@ import fs from "node:fs/promises";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import { captureEnv } from "../test-utils/env.js";
|
import { withEnvAsync } from "../test-utils/env.js";
|
||||||
import "./test-helpers/fast-core-tools.js";
|
import "./test-helpers/fast-core-tools.js";
|
||||||
import { createOpenClawTools } from "./openclaw-tools.js";
|
import { createOpenClawTools } from "./openclaw-tools.js";
|
||||||
|
|
||||||
@@ -31,12 +31,12 @@ describe("gateway tool", () => {
|
|||||||
it("schedules SIGUSR1 restart", async () => {
|
it("schedules SIGUSR1 restart", async () => {
|
||||||
vi.useFakeTimers();
|
vi.useFakeTimers();
|
||||||
const kill = vi.spyOn(process, "kill").mockImplementation(() => true);
|
const kill = vi.spyOn(process, "kill").mockImplementation(() => true);
|
||||||
const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR", "OPENCLAW_PROFILE"]);
|
|
||||||
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-test-"));
|
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-test-"));
|
||||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
|
||||||
process.env.OPENCLAW_PROFILE = "isolated";
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
await withEnvAsync(
|
||||||
|
{ OPENCLAW_STATE_DIR: stateDir, OPENCLAW_PROFILE: "isolated" },
|
||||||
|
async () => {
|
||||||
const tool = createOpenClawTools({
|
const tool = createOpenClawTools({
|
||||||
config: { commands: { restart: true } },
|
config: { commands: { restart: true } },
|
||||||
}).find((candidate) => candidate.name === "gateway");
|
}).find((candidate) => candidate.name === "gateway");
|
||||||
@@ -69,10 +69,11 @@ describe("gateway tool", () => {
|
|||||||
expect(kill).not.toHaveBeenCalled();
|
expect(kill).not.toHaveBeenCalled();
|
||||||
await vi.runAllTimersAsync();
|
await vi.runAllTimersAsync();
|
||||||
expect(kill).toHaveBeenCalledWith(process.pid, "SIGUSR1");
|
expect(kill).toHaveBeenCalledWith(process.pid, "SIGUSR1");
|
||||||
|
},
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
kill.mockRestore();
|
kill.mockRestore();
|
||||||
vi.useRealTimers();
|
vi.useRealTimers();
|
||||||
envSnapshot.restore();
|
|
||||||
await fs.rm(stateDir, { recursive: true, force: true });
|
await fs.rm(stateDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user