





















@@ -1,7 +1,10 @@
1+import * as fs from "node:fs";
12import os from "node:os";
23import path from "node:path";
34import { afterEach, describe, expect, it, vi } from "vitest";
5+import type { RuntimeEnv } from "../runtime.js";
46import {
7+handleReset,
58normalizeGatewayTokenInput,
69openUrl,
710probeGatewayReachable,
@@ -45,6 +48,44 @@ afterEach(() => {
4548vi.unstubAllEnvs();
4649});
475051+describe("handleReset", () => {
52+it("uses active profile paths for destructive reset targets", async () => {
53+const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-reset-profile-"));
54+const profileStateDir = path.join(homeDir, ".openclaw-work");
55+const defaultStateDir = path.join(homeDir, ".openclaw");
56+const profileConfigPath = path.join(profileStateDir, "openclaw.json");
57+const profileCredentialsDir = path.join(profileStateDir, "credentials");
58+const profileSessionsDir = path.join(profileStateDir, "agents", "main", "sessions");
59+const workspaceDir = path.join(profileStateDir, "workspace");
60+const defaultCredentialsDir = path.join(defaultStateDir, "credentials");
61+62+fs.mkdirSync(profileCredentialsDir, { recursive: true });
63+fs.mkdirSync(profileSessionsDir, { recursive: true });
64+fs.mkdirSync(workspaceDir, { recursive: true });
65+fs.mkdirSync(defaultCredentialsDir, { recursive: true });
66+fs.writeFileSync(profileConfigPath, "{}\n");
67+68+vi.stubEnv("HOME", homeDir);
69+vi.stubEnv("OPENCLAW_HOME", homeDir);
70+vi.stubEnv("OPENCLAW_PROFILE", "work");
71+vi.stubEnv("OPENCLAW_STATE_DIR", profileStateDir);
72+vi.stubEnv("OPENCLAW_CONFIG_PATH", profileConfigPath);
73+74+const runtime = { log: vi.fn() } as unknown as RuntimeEnv;
75+76+await handleReset("full", workspaceDir, runtime);
77+78+const trashedPaths = mocks.runCommandWithTimeout.mock.calls.map(([argv]) => argv[1]);
79+expect(trashedPaths).toEqual([
80+profileConfigPath,
81+profileCredentialsDir,
82+profileSessionsDir,
83+workspaceDir,
84+]);
85+expect(trashedPaths).not.toContain(defaultCredentialsDir);
86+});
87+});
88+4889describe("openUrl", () => {
4990it("passes OAuth URLs to Windows FileProtocolHandler without cmd parsing", async () => {
5091vi.stubEnv("VITEST", "");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。