mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:21:23 +00:00
fix(paths): respect OPENCLAW_HOME for all internal path resolution (#12091)
* 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)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { loadCronStore } from "./store.js";
|
||||
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-"));
|
||||
@@ -15,6 +15,20 @@ async function makeStorePath() {
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import JSON5 from "json5";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type { CronStoreFile } from "./types.js";
|
||||
import { expandHomePrefix } from "../infra/home-dir.js";
|
||||
import { CONFIG_DIR } from "../utils.js";
|
||||
|
||||
export const DEFAULT_CRON_DIR = path.join(CONFIG_DIR, "cron");
|
||||
@@ -12,7 +12,7 @@ export function resolveCronStorePath(storePath?: string) {
|
||||
if (storePath?.trim()) {
|
||||
const raw = storePath.trim();
|
||||
if (raw.startsWith("~")) {
|
||||
return path.resolve(raw.replace("~", os.homedir()));
|
||||
return path.resolve(expandHomePrefix(raw));
|
||||
}
|
||||
return path.resolve(raw);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user