






















@@ -4,6 +4,7 @@ import os from "node:os";
44import path from "node:path";
55import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
66import type { RuntimeEnv } from "../runtime.js";
7+import { captureEnv, setTestEnvValue } from "../test-utils/env.js";
78import { createCrestodianTestRuntime } from "./crestodian.test-helpers.js";
89import { executeCrestodianOperation, parseCrestodianOperation } from "./operations.js";
910@@ -192,12 +193,16 @@ vi.mock("../config/model-input.js", () => ({
192193}));
193194194195describe("parseCrestodianOperation", () => {
196+let stateDirSnapshot: ReturnType<typeof captureEnv> | undefined;
197+195198beforeEach(() => {
196199mockConfig.reset();
200+stateDirSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
197201vi.stubEnv("OPENCLAW_TEST_FAST", "1");
198202});
199203200204afterEach(() => {
205+stateDirSnapshot?.restore();
201206vi.unstubAllEnvs();
202207});
203208@@ -321,7 +326,7 @@ describe("parseCrestodianOperation", () => {
321326322327it("applies config set through typed deps and writes an audit entry", async () => {
323328const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-config-set-"));
324-vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
329+setTestEnvValue("OPENCLAW_STATE_DIR", tempDir);
325330const { runtime, lines } = createCrestodianTestRuntime();
326331const runConfigSet = vi.fn(async () => {});
327332@@ -357,7 +362,7 @@ describe("parseCrestodianOperation", () => {
357362358363it("applies SecretRef config set through typed deps and writes an audit entry", async () => {
359364const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-config-ref-"));
360-vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
365+setTestEnvValue("OPENCLAW_STATE_DIR", tempDir);
361366const { runtime, lines } = createCrestodianTestRuntime();
362367const runConfigSet = vi.fn(async () => {});
363368@@ -435,7 +440,7 @@ describe("parseCrestodianOperation", () => {
435440436441it("installs plugins only after approval and audits the write", async () => {
437442const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-plugin-install-"));
438-vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
443+setTestEnvValue("OPENCLAW_STATE_DIR", tempDir);
439444const { runtime, lines } = createCrestodianTestRuntime();
440445const runPluginInstall = vi.fn(async (spec: string, pluginRuntime: RuntimeEnv) => {
441446pluginRuntime.log(`installed ${spec}`);
@@ -481,7 +486,7 @@ describe("parseCrestodianOperation", () => {
481486482487it("uninstalls plugins only after approval and audits the write", async () => {
483488const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-plugin-uninstall-"));
484-vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
489+setTestEnvValue("OPENCLAW_STATE_DIR", tempDir);
485490const { runtime, lines } = createCrestodianTestRuntime();
486491const runPluginUninstall = vi.fn(async (pluginId: string, pluginRuntime: RuntimeEnv) => {
487492pluginRuntime.log(`uninstalled ${pluginId}`);
@@ -527,7 +532,7 @@ describe("parseCrestodianOperation", () => {
527532528533it("runs setup bootstrap only after approval and audits it", async () => {
529534const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-setup-"));
530-vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
535+setTestEnvValue("OPENCLAW_STATE_DIR", tempDir);
531536vi.stubEnv("OPENAI_API_KEY", "test-key");
532537const { runtime, lines } = createCrestodianTestRuntime();
533538@@ -576,7 +581,7 @@ describe("parseCrestodianOperation", () => {
576581577582it("runs doctor repairs only after approval and audits them", async () => {
578583const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "crestodian-doctor-fix-"));
579-vi.stubEnv("OPENCLAW_STATE_DIR", tempDir);
584+setTestEnvValue("OPENCLAW_STATE_DIR", tempDir);
580585const { runtime, lines } = createCrestodianTestRuntime();
581586const runDoctor = vi.fn(async () => {});
582587此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。