mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:00:42 +00:00
fix(cli): scope dev reset to active profile
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import * as fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import {
|
||||
handleReset,
|
||||
normalizeGatewayTokenInput,
|
||||
openUrl,
|
||||
probeGatewayReachable,
|
||||
@@ -45,6 +48,44 @@ afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
describe("handleReset", () => {
|
||||
it("uses active profile paths for destructive reset targets", async () => {
|
||||
const homeDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-reset-profile-"));
|
||||
const profileStateDir = path.join(homeDir, ".openclaw-work");
|
||||
const defaultStateDir = path.join(homeDir, ".openclaw");
|
||||
const profileConfigPath = path.join(profileStateDir, "openclaw.json");
|
||||
const profileCredentialsDir = path.join(profileStateDir, "credentials");
|
||||
const profileSessionsDir = path.join(profileStateDir, "agents", "main", "sessions");
|
||||
const workspaceDir = path.join(profileStateDir, "workspace");
|
||||
const defaultCredentialsDir = path.join(defaultStateDir, "credentials");
|
||||
|
||||
fs.mkdirSync(profileCredentialsDir, { recursive: true });
|
||||
fs.mkdirSync(profileSessionsDir, { recursive: true });
|
||||
fs.mkdirSync(workspaceDir, { recursive: true });
|
||||
fs.mkdirSync(defaultCredentialsDir, { recursive: true });
|
||||
fs.writeFileSync(profileConfigPath, "{}\n");
|
||||
|
||||
vi.stubEnv("HOME", homeDir);
|
||||
vi.stubEnv("OPENCLAW_HOME", homeDir);
|
||||
vi.stubEnv("OPENCLAW_PROFILE", "work");
|
||||
vi.stubEnv("OPENCLAW_STATE_DIR", profileStateDir);
|
||||
vi.stubEnv("OPENCLAW_CONFIG_PATH", profileConfigPath);
|
||||
|
||||
const runtime = { log: vi.fn() } as unknown as RuntimeEnv;
|
||||
|
||||
await handleReset("full", workspaceDir, runtime);
|
||||
|
||||
const trashedPaths = mocks.runCommandWithTimeout.mock.calls.map(([argv]) => argv[1]);
|
||||
expect(trashedPaths).toEqual([
|
||||
profileConfigPath,
|
||||
profileCredentialsDir,
|
||||
profileSessionsDir,
|
||||
workspaceDir,
|
||||
]);
|
||||
expect(trashedPaths).not.toContain(defaultCredentialsDir);
|
||||
});
|
||||
});
|
||||
|
||||
describe("openUrl", () => {
|
||||
it("passes OAuth URLs to Windows FileProtocolHandler without cmd parsing", async () => {
|
||||
vi.stubEnv("VITEST", "");
|
||||
|
||||
@@ -4,7 +4,7 @@ import { inspect } from "node:util";
|
||||
import { cancel, isCancel } from "@clack/prompts";
|
||||
import { DEFAULT_AGENT_WORKSPACE_DIR, ensureAgentWorkspace } from "../agents/workspace.js";
|
||||
import { resolveAgentModelPrimaryValue } from "../config/model-input.js";
|
||||
import { CONFIG_PATH } from "../config/paths.js";
|
||||
import { resolveConfigPath } from "../config/paths.js";
|
||||
import { resolveSessionTranscriptsDirForAgent } from "../config/sessions/paths.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { resolveControlUiLinks } from "../gateway/control-ui-links.js";
|
||||
@@ -21,7 +21,7 @@ import { runCommandWithTimeout } from "../process/exec.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
import { stylePromptTitle } from "../terminal/prompt-style.js";
|
||||
import { CONFIG_DIR, shortenHomeInString, shortenHomePath, sleep } from "../utils.js";
|
||||
import { resolveConfigDir, shortenHomeInString, shortenHomePath, sleep } from "../utils.js";
|
||||
import { VERSION } from "../version.js";
|
||||
import type { NodeManagerChoice, OnboardMode, ResetScope } from "./onboard-types.js";
|
||||
export { randomToken } from "./random-token.js";
|
||||
@@ -205,11 +205,11 @@ export async function moveToTrash(pathname: string, runtime: RuntimeEnv): Promis
|
||||
}
|
||||
|
||||
export async function handleReset(scope: ResetScope, workspaceDir: string, runtime: RuntimeEnv) {
|
||||
await moveToTrash(CONFIG_PATH, runtime);
|
||||
await moveToTrash(resolveConfigPath(), runtime);
|
||||
if (scope === "config") {
|
||||
return;
|
||||
}
|
||||
await moveToTrash(path.join(CONFIG_DIR, "credentials"), runtime);
|
||||
await moveToTrash(path.join(resolveConfigDir(), "credentials"), runtime);
|
||||
await moveToTrash(resolveSessionTranscriptsDirForAgent(), runtime);
|
||||
if (scope === "full") {
|
||||
await moveToTrash(workspaceDir, runtime);
|
||||
|
||||
Reference in New Issue
Block a user