Compare commits
3 Commits
v2026.2.15
...
fix/state-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ff9e4830c | ||
|
|
6ffa76ed81 | ||
|
|
c923fb0d5b |
@@ -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
|
||||
|
||||
55
src/canvas-host/server.state-dir.test.ts
Normal file
55
src/canvas-host/server.state-dir.test.ts
Normal 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 });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -4,10 +4,10 @@ import chokidar from "chokidar";
|
||||
import * as fsSync from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
import http, { type IncomingMessage, type Server, type ServerResponse } from "node:http";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { type WebSocket, WebSocketServer } from "ws";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { STATE_DIR } from "../config/paths.js";
|
||||
import { isTruthyEnvValue } from "../infra/env.js";
|
||||
import { SafeOpenError, openFileWithinRoot } from "../infra/fs-safe.js";
|
||||
import { detectMime } from "../media/mime.js";
|
||||
@@ -235,7 +235,7 @@ async function prepareCanvasRoot(rootDir: string) {
|
||||
}
|
||||
|
||||
function resolveDefaultCanvasRoot(): string {
|
||||
const candidates = [path.join(os.homedir(), ".openclaw", "canvas")];
|
||||
const candidates = [path.join(STATE_DIR, "canvas")];
|
||||
const existing = candidates.find((dir) => {
|
||||
try {
|
||||
return fsSync.statSync(dir).isDirectory();
|
||||
|
||||
47
src/infra/device-identity.state-dir.test.ts
Normal file
47
src/infra/device-identity.state-dir.test.ts
Normal 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 });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { STATE_DIR } from "../config/paths.js";
|
||||
|
||||
export type DeviceIdentity = {
|
||||
deviceId: string;
|
||||
@@ -17,7 +17,7 @@ type StoredIdentity = {
|
||||
createdAtMs: number;
|
||||
};
|
||||
|
||||
const DEFAULT_DIR = path.join(os.homedir(), ".openclaw", "identity");
|
||||
const DEFAULT_DIR = path.join(STATE_DIR, "identity");
|
||||
const DEFAULT_FILE = path.join(DEFAULT_DIR, "device.json");
|
||||
|
||||
function ensureDir(filePath: string) {
|
||||
|
||||
Reference in New Issue
Block a user