


























@@ -5,6 +5,7 @@ import os from "node:os";
55import path from "node:path";
66import { afterEach, describe, expect, it, vi } from "vitest";
77import type { RuntimeEnv } from "../runtime.js";
8+import { withEnvAsync } from "../test-utils/env.js";
89import { withMockedPlatform } from "../test-utils/vitest-spies.js";
910import {
1011formatControlUiSshHint,
@@ -99,12 +100,6 @@ describe("handleReset", () => {
99100`openclaw-workspace-attestation:v1\n${new Date().toISOString()}\n`,
100101);
101102102-vi.stubEnv("HOME", homeDir);
103-vi.stubEnv("OPENCLAW_HOME", homeDir);
104-vi.stubEnv("OPENCLAW_PROFILE", "work");
105-vi.stubEnv("OPENCLAW_STATE_DIR", profileStateDir);
106-vi.stubEnv("OPENCLAW_CONFIG_PATH", profileConfigPath);
107-108103const runtime = { log: vi.fn() } as unknown as RuntimeEnv;
109104const expectedTrashedPaths = [
110105profileConfigPath,
@@ -116,7 +111,16 @@ describe("handleReset", () => {
116111const expectedDefaultCredentialsDir = expectedTrashSourcePath(defaultCredentialsDir);
117112118113try {
119-await handleReset("full", workspaceDir, runtime);
114+await withEnvAsync(
115+{
116+HOME: homeDir,
117+OPENCLAW_HOME: homeDir,
118+OPENCLAW_PROFILE: "work",
119+OPENCLAW_STATE_DIR: profileStateDir,
120+OPENCLAW_CONFIG_PATH: profileConfigPath,
121+},
122+async () => await handleReset("full", workspaceDir, runtime),
123+);
120124} finally {
121125fs.rmSync(homeDir, { recursive: true, force: true });
122126}
@@ -141,17 +145,20 @@ describe("handleReset", () => {
141145fs.writeFileSync(profileConfigPath, "{}\n");
142146fs.writeFileSync(workspaceAttestationPath, "external data\n");
143147144-vi.stubEnv("HOME", homeDir);
145-vi.stubEnv("OPENCLAW_HOME", homeDir);
146-vi.stubEnv("OPENCLAW_PROFILE", "work");
147-vi.stubEnv("OPENCLAW_STATE_DIR", profileStateDir);
148-vi.stubEnv("OPENCLAW_CONFIG_PATH", profileConfigPath);
149-150148const runtime = { log: vi.fn() } as unknown as RuntimeEnv;
151149const unownedAttestationTrashPath = expectedTrashSourcePath(workspaceAttestationPath);
152150153151try {
154-await handleReset("full", workspaceDir, runtime);
152+await withEnvAsync(
153+{
154+HOME: homeDir,
155+OPENCLAW_HOME: homeDir,
156+OPENCLAW_PROFILE: "work",
157+OPENCLAW_STATE_DIR: profileStateDir,
158+OPENCLAW_CONFIG_PATH: profileConfigPath,
159+},
160+async () => await handleReset("full", workspaceDir, runtime),
161+);
155162} finally {
156163fs.rmSync(homeDir, { recursive: true, force: true });
157164}
@@ -178,17 +185,22 @@ describe("handleReset", () => {
178185fs.writeFileSync(workspaceAttestationPath, "external data\n", { mode: 0o000 });
179186fs.chmodSync(workspaceAttestationPath, 0o000);
180187181-vi.stubEnv("HOME", homeDir);
182-vi.stubEnv("OPENCLAW_HOME", homeDir);
183-vi.stubEnv("OPENCLAW_PROFILE", "work");
184-vi.stubEnv("OPENCLAW_STATE_DIR", profileStateDir);
185-vi.stubEnv("OPENCLAW_CONFIG_PATH", profileConfigPath);
186-187188const runtime = { log: vi.fn() } as unknown as RuntimeEnv;
188189const unreadableAttestationTrashPath = expectedTrashSourcePath(workspaceAttestationPath);
189190190191try {
191-await expect(handleReset("full", workspaceDir, runtime)).resolves.toBeUndefined();
192+await withEnvAsync(
193+{
194+HOME: homeDir,
195+OPENCLAW_HOME: homeDir,
196+OPENCLAW_PROFILE: "work",
197+OPENCLAW_STATE_DIR: profileStateDir,
198+OPENCLAW_CONFIG_PATH: profileConfigPath,
199+},
200+async () => {
201+await expect(handleReset("full", workspaceDir, runtime)).resolves.toBeUndefined();
202+},
203+);
192204} finally {
193205fs.chmodSync(workspaceAttestationPath, 0o600);
194206fs.rmSync(homeDir, { recursive: true, force: true });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。