mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-19 22:10:51 +00:00
* fix(paths): respect OPENCLAW_HOME for all internal path resolution (#11995) Add home-dir module (src/infra/home-dir.ts) that centralizes home directory resolution with precedence: OPENCLAW_HOME > HOME > USERPROFILE > os.homedir(). Migrate all path-sensitive callsites: config IO, agent dirs, session transcripts, pairing store, cron store, doctor, CLI profiles. Add envHomedir() helper in config/paths.ts to reduce lambda noise. Document OPENCLAW_HOME in docs/help/environment.md. * fix(paths): handle OPENCLAW_HOME '~' fallback (#12091) (thanks @sebslight) * docs: mention OPENCLAW_HOME in install and getting started (#12091) (thanks @sebslight) * fix(status): show OPENCLAW_HOME in shortened paths (#12091) (thanks @sebslight) * docs(changelog): clarify OPENCLAW_HOME and HOME precedence (#12091) (thanks @sebslight)
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { loadCronStore, resolveCronStorePath } from "./store.js";
|
|
|
|
async function makeStorePath() {
|
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-cron-store-"));
|
|
return {
|
|
dir,
|
|
storePath: path.join(dir, "jobs.json"),
|
|
cleanup: async () => {
|
|
await fs.rm(dir, { recursive: true, force: true });
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("resolveCronStorePath", () => {
|
|
afterEach(() => {
|
|
vi.unstubAllEnvs();
|
|
});
|
|
|
|
it("uses OPENCLAW_HOME for tilde expansion", () => {
|
|
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home");
|
|
vi.stubEnv("HOME", "/home/other");
|
|
|
|
const result = resolveCronStorePath("~/cron/jobs.json");
|
|
expect(result).toBe(path.resolve("/srv/openclaw-home", "cron", "jobs.json"));
|
|
});
|
|
});
|
|
|
|
describe("cron store", () => {
|
|
it("returns empty store when file does not exist", async () => {
|
|
const store = await makeStorePath();
|
|
const loaded = await loadCronStore(store.storePath);
|
|
expect(loaded).toEqual({ version: 1, jobs: [] });
|
|
await store.cleanup();
|
|
});
|
|
|
|
it("throws when store contains invalid JSON", async () => {
|
|
const store = await makeStorePath();
|
|
await fs.writeFile(store.storePath, "{ not json", "utf-8");
|
|
await expect(loadCronStore(store.storePath)).rejects.toThrow(/Failed to parse cron store/i);
|
|
await store.cleanup();
|
|
});
|
|
});
|