






















@@ -1,12 +1,14 @@
11import fs from "node:fs/promises";
22import os from "node:os";
33import path from "node:path";
4-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4+import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
55import type { CommandContext } from "../auto-reply/reply/commands-types.js";
66import type { OpenClawConfig } from "../config/types.openclaw.js";
77import { extractCrestodianRescueMessage, runCrestodianRescueMessage } from "./rescue-message.js";
8899const originalStateDir = process.env.OPENCLAW_STATE_DIR;
10+let tempRoot = "";
11+let tempDirId = 0;
10121113type TestConfig = Record<string, unknown>;
1214@@ -101,6 +103,12 @@ vi.mock("../config/model-input.js", () => ({
101103typeof model === "string" ? model : model?.primary,
102104}));
103105106+async function makeStateDir(prefix: string): Promise<string> {
107+const dir = path.join(tempRoot, `${prefix}${tempDirId++}`);
108+await fs.mkdir(dir, { recursive: true });
109+return dir;
110+}
111+104112function commandContext(overrides: Partial<CommandContext> = {}): CommandContext {
105113return {
106114surface: "whatsapp",
@@ -134,6 +142,10 @@ async function runRescue(
134142}
135143136144describe("Crestodian rescue message", () => {
145+beforeAll(async () => {
146+tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-rescue-"));
147+});
148+137149beforeEach(() => {
138150mockConfig.reset();
139151});
@@ -146,6 +158,12 @@ describe("Crestodian rescue message", () => {
146158}
147159});
148160161+afterAll(async () => {
162+if (tempRoot) {
163+await fs.rm(tempRoot, { recursive: true, force: true });
164+}
165+});
166+149167it("recognizes the Crestodian rescue command", () => {
150168expect(extractCrestodianRescueMessage("/crestodian status")).toBe("status");
151169expect(extractCrestodianRescueMessage("/crestodian")).toBe("");
@@ -179,7 +197,7 @@ describe("Crestodian rescue message", () => {
179197});
180198181199it("queues and applies persistent writes through conversational approval", async () => {
182-const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-rescue-"));
200+const tempDir = await makeStateDir("models-");
183201vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
184202185203const cfg: OpenClawConfig = { crestodian: { rescue: { enabled: true } } };
@@ -203,7 +221,7 @@ describe("Crestodian rescue message", () => {
203221});
204222205223it("queues and applies gateway restart through conversational approval", async () => {
206-const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-rescue-gateway-"));
224+const tempDir = await makeStateDir("gateway-");
207225vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
208226const cfg: OpenClawConfig = { crestodian: { rescue: { enabled: true } } };
209227const deps = { runGatewayRestart: vi.fn(async () => {}) };
@@ -229,7 +247,7 @@ describe("Crestodian rescue message", () => {
229247});
230248231249it("queues and applies agent creation through conversational approval", async () => {
232-const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-rescue-agent-"));
250+const tempDir = await makeStateDir("agent-");
233251vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
234252const cfg: OpenClawConfig = { crestodian: { rescue: { enabled: true } } };
235253const deps = { runAgentsAdd: vi.fn(async () => {}) };
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。