fix: scope state-dir patch + add regression tests (#4824) (thanks @kossoy)

This commit is contained in:
Gustavo Madeira Santana
2026-02-07 21:59:06 -05:00
parent 6ffa76ed81
commit 6ff9e4830c
4 changed files with 104 additions and 6 deletions

View File

@@ -15,6 +15,7 @@ Docs: https://docs.openclaw.ai
- Memory: set Voyage embeddings `input_type` for improved retrieval. (#10818) Thanks @mcinteerj.
- Memory/QMD: run boot refresh in background by default, add configurable QMD maintenance timeouts, and retry QMD after fallback failures. (#9690, #9705)
- Media understanding: recognize `.caf` audio attachments for transcription. (#10982) Thanks @succ985.
- State dir: honor `OPENCLAW_STATE_DIR` for default device identity and canvas storage paths. (#4824) Thanks @kossoy.
- Tests: harden flaky hotspots by removing timer sleeps, consolidating onboarding provider-auth coverage, and improving memory test realism. (#11598) Thanks @gumadeiras.
## 2026.2.6

View File

@@ -0,0 +1,55 @@
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 { defaultRuntime } from "../runtime.js";
describe("canvas host state dir defaults", () => {
let previousStateDir: string | undefined;
let previousLegacyStateDir: string | undefined;
beforeEach(() => {
previousStateDir = process.env.OPENCLAW_STATE_DIR;
previousLegacyStateDir = process.env.CLAWDBOT_STATE_DIR;
});
afterEach(() => {
vi.resetModules();
if (previousStateDir === undefined) {
delete process.env.OPENCLAW_STATE_DIR;
} else {
process.env.OPENCLAW_STATE_DIR = previousStateDir;
}
if (previousLegacyStateDir === undefined) {
delete process.env.CLAWDBOT_STATE_DIR;
} else {
process.env.CLAWDBOT_STATE_DIR = previousLegacyStateDir;
}
});
it("uses OPENCLAW_STATE_DIR for the default canvas root", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-canvas-state-"));
const stateDir = path.join(tempRoot, "state");
process.env.OPENCLAW_STATE_DIR = stateDir;
delete process.env.CLAWDBOT_STATE_DIR;
vi.resetModules();
const { createCanvasHostHandler } = await import("./server.js");
const handler = await createCanvasHostHandler({
runtime: defaultRuntime,
allowInTests: true,
});
try {
const expectedRoot = await fs.realpath(path.join(stateDir, "canvas"));
const actualRoot = await fs.realpath(handler.rootDir);
expect(actualRoot).toBe(expectedRoot);
const indexPath = path.join(expectedRoot, "index.html");
const indexContents = await fs.readFile(indexPath, "utf8");
expect(indexContents).toContain("OpenClaw Canvas");
} finally {
await handler.close();
await fs.rm(tempRoot, { recursive: true, force: true });
}
});
});

View File

@@ -687,12 +687,7 @@ function printResult(result: UpdateRunResult, opts: PrintResultOptions) {
}
export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
Object.defineProperty(process, "noDeprecation", {
value: true,
writable: true,
enumerable: true,
configurable: true,
});
process.noDeprecation = true;
process.env.NODE_NO_WARNINGS = "1";
const timeoutMs = opts.timeout ? Number.parseInt(opts.timeout, 10) * 1000 : undefined;
const shouldRestart = opts.restart !== false;

View File

@@ -0,0 +1,47 @@
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";
describe("device identity state dir defaults", () => {
let previousStateDir: string | undefined;
let previousLegacyStateDir: string | undefined;
beforeEach(() => {
previousStateDir = process.env.OPENCLAW_STATE_DIR;
previousLegacyStateDir = process.env.CLAWDBOT_STATE_DIR;
});
afterEach(() => {
vi.resetModules();
if (previousStateDir === undefined) {
delete process.env.OPENCLAW_STATE_DIR;
} else {
process.env.OPENCLAW_STATE_DIR = previousStateDir;
}
if (previousLegacyStateDir === undefined) {
delete process.env.CLAWDBOT_STATE_DIR;
} else {
process.env.CLAWDBOT_STATE_DIR = previousLegacyStateDir;
}
});
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");
process.env.OPENCLAW_STATE_DIR = stateDir;
delete process.env.CLAWDBOT_STATE_DIR;
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 });
}
});
});