mirror of https://github.com/openclaw/openclaw.git
test: add home relative path coverage
This commit is contained in:
parent
285b50c549
commit
56798bd811
|
|
@ -1,6 +1,11 @@
|
|||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { expandHomePrefix, resolveEffectiveHomeDir, resolveRequiredHomeDir } from "./home-dir.js";
|
||||
import {
|
||||
expandHomePrefix,
|
||||
resolveEffectiveHomeDir,
|
||||
resolveHomeRelativePath,
|
||||
resolveRequiredHomeDir,
|
||||
} from "./home-dir.js";
|
||||
|
||||
describe("resolveEffectiveHomeDir", () => {
|
||||
it.each([
|
||||
|
|
@ -123,3 +128,33 @@ describe("expandHomePrefix", () => {
|
|||
expect(expandHomePrefix(input, opts)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveHomeRelativePath", () => {
|
||||
it("returns blank input unchanged", () => {
|
||||
expect(resolveHomeRelativePath(" ")).toBe("");
|
||||
});
|
||||
|
||||
it("resolves trimmed relative and absolute paths", () => {
|
||||
expect(resolveHomeRelativePath(" ./tmp/file.txt ")).toBe(path.resolve("./tmp/file.txt"));
|
||||
expect(resolveHomeRelativePath(" /tmp/file.txt ")).toBe(path.resolve("/tmp/file.txt"));
|
||||
});
|
||||
|
||||
it("expands tilde paths using the resolved home directory", () => {
|
||||
expect(
|
||||
resolveHomeRelativePath("~/docs", {
|
||||
env: { OPENCLAW_HOME: "/srv/openclaw-home" } as NodeJS.ProcessEnv,
|
||||
}),
|
||||
).toBe(path.resolve("/srv/openclaw-home/docs"));
|
||||
});
|
||||
|
||||
it("falls back to cwd when tilde paths have no home source", () => {
|
||||
expect(
|
||||
resolveHomeRelativePath("~", {
|
||||
env: {} as NodeJS.ProcessEnv,
|
||||
homedir: () => {
|
||||
throw new Error("no home");
|
||||
},
|
||||
}),
|
||||
).toBe(path.resolve(process.cwd()));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue