mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
test: scope utility home env
This commit is contained in:
+9
-24
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { MAX_TIMER_TIMEOUT_MS } from "./shared/number-coercion.js";
|
||||
import { withTempDir } from "./test-helpers/temp-dir.js";
|
||||
import { withEnv } from "./test-utils/env.js";
|
||||
import {
|
||||
ensureDir,
|
||||
resolveConfigDir,
|
||||
@@ -84,43 +85,31 @@ describe("resolveConfigDir", () => {
|
||||
|
||||
describe("resolveHomeDir", () => {
|
||||
it("prefers OPENCLAW_HOME over HOME", () => {
|
||||
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home");
|
||||
vi.stubEnv("HOME", "/home/other");
|
||||
try {
|
||||
withEnv({ OPENCLAW_HOME: "/srv/openclaw-home", HOME: "/home/other" }, () => {
|
||||
expect(resolveHomeDir()).toBe(path.resolve("/srv/openclaw-home"));
|
||||
} finally {
|
||||
vi.unstubAllEnvs();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("shortenHomePath", () => {
|
||||
it("uses $OPENCLAW_HOME prefix when OPENCLAW_HOME is set", () => {
|
||||
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home");
|
||||
vi.stubEnv("HOME", "/home/other");
|
||||
try {
|
||||
withEnv({ OPENCLAW_HOME: "/srv/openclaw-home", HOME: "/home/other" }, () => {
|
||||
expect(shortenHomePath(`${path.resolve("/srv/openclaw-home")}/.openclaw/openclaw.json`)).toBe(
|
||||
"$OPENCLAW_HOME/.openclaw/openclaw.json",
|
||||
);
|
||||
} finally {
|
||||
vi.unstubAllEnvs();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("shortenHomeInString", () => {
|
||||
it("uses $OPENCLAW_HOME replacement when OPENCLAW_HOME is set", () => {
|
||||
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home");
|
||||
vi.stubEnv("HOME", "/home/other");
|
||||
try {
|
||||
withEnv({ OPENCLAW_HOME: "/srv/openclaw-home", HOME: "/home/other" }, () => {
|
||||
expect(
|
||||
shortenHomeInString(
|
||||
`config: ${path.resolve("/srv/openclaw-home")}/.openclaw/openclaw.json`,
|
||||
),
|
||||
).toBe("config: $OPENCLAW_HOME/.openclaw/openclaw.json");
|
||||
} finally {
|
||||
vi.unstubAllEnvs();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -140,13 +129,9 @@ describe("resolveUserPath", () => {
|
||||
});
|
||||
|
||||
it("prefers OPENCLAW_HOME for tilde expansion", () => {
|
||||
vi.stubEnv("OPENCLAW_HOME", "/srv/openclaw-home");
|
||||
vi.stubEnv("HOME", "/home/other");
|
||||
try {
|
||||
withEnv({ OPENCLAW_HOME: "/srv/openclaw-home", HOME: "/home/other" }, () => {
|
||||
expect(resolveUserPath("~/openclaw")).toBe(path.resolve("/srv/openclaw-home", "openclaw"));
|
||||
} finally {
|
||||
vi.unstubAllEnvs();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the provided env for tilde expansion", () => {
|
||||
|
||||
Reference in New Issue
Block a user