mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:38:28 +00:00
fix: use STATE_DIR instead of hardcoded ~/.openclaw for identity and canvas (#4824)
* fix: use STATE_DIR instead of hardcoded ~/.openclaw for identity and canvas device-identity.ts and canvas-host/server.ts used hardcoded path.join(os.homedir(), '.openclaw', ...) ignoring OPENCLAW_STATE_DIR env var and the resolveStateDir() logic from config/paths.ts. This caused ~/.openclaw/identity and ~/.openclaw/canvas directories to be created even when state dir was overridden or resided elsewhere. * fix: format and remove duplicate imports * fix: scope state-dir patch + add regression tests (#4824) (thanks @kossoy) * fix: align state-dir fallbacks in hooks and agent paths (#4824) (thanks @kossoy) --------- Co-authored-by: Gustavo Madeira Santana <gumadeiras@gmail.com>
This commit is contained in:
40
src/infra/device-identity.state-dir.test.ts
Normal file
40
src/infra/device-identity.state-dir.test.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
restoreStateDirEnv,
|
||||
setStateDirEnv,
|
||||
snapshotStateDirEnv,
|
||||
} from "../test-helpers/state-dir-env.js";
|
||||
|
||||
describe("device identity state dir defaults", () => {
|
||||
let envSnapshot: ReturnType<typeof snapshotStateDirEnv>;
|
||||
|
||||
beforeEach(() => {
|
||||
envSnapshot = snapshotStateDirEnv();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.resetModules();
|
||||
restoreStateDirEnv(envSnapshot);
|
||||
});
|
||||
|
||||
it("writes the default identity file under OPENCLAW_STATE_DIR", async () => {
|
||||
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-identity-state-"));
|
||||
const stateDir = path.join(tempRoot, "state");
|
||||
setStateDirEnv(stateDir);
|
||||
vi.resetModules();
|
||||
|
||||
const { loadOrCreateDeviceIdentity } = await import("./device-identity.js");
|
||||
const identity = loadOrCreateDeviceIdentity();
|
||||
|
||||
try {
|
||||
const identityPath = path.join(stateDir, "identity", "device.json");
|
||||
const raw = JSON.parse(await fs.readFile(identityPath, "utf8")) as { deviceId?: string };
|
||||
expect(raw.deviceId).toBe(identity.deviceId);
|
||||
} finally {
|
||||
await fs.rm(tempRoot, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user