返回 DeepSeek-Reasonix
home.test.ts
根目录 / desktop / electron / src / main / home.test.ts
1 import assert from "node:assert/strict";
2 import { sep } from "node:path";
3 import { test } from "node:test";
4 import { reasonixHome } from "./home.js";
5
6 const unix = (env: NodeJS.ProcessEnv, platform: NodeJS.Platform = "darwin") =>
7 reasonixHome({ env, platform, homedir: () => "/home/fallback", cwd: () => "/work" });
8
9 test("REASONIX_HOME wins, with ~ and ${VAR} expansion and relative paths made absolute", () => {
10 assert.equal(unix({ REASONIX_HOME: "/data/rx", HOME: "/home/u" }), "/data/rx");
11 assert.equal(unix({ REASONIX_HOME: " /data/rx/ ", HOME: "/home/u" }), "/data/rx");
12 assert.equal(unix({ REASONIX_HOME: "~/rx", HOME: "/home/u" }), "/home/u/rx");
13 assert.equal(unix({ REASONIX_HOME: "~", HOME: "/home/u" }), "/home/u");
14 assert.equal(unix({ REASONIX_HOME: "${BASE}/rx", BASE: "/srv", HOME: "/home/u" }), "/srv/rx");
15 assert.equal(unix({ REASONIX_HOME: "${MISSING:-/opt}/rx", HOME: "/home/u" }), "/opt/rx");
16 assert.equal(unix({ REASONIX_HOME: "rel/rx", HOME: "/home/u" }), "/work/rel/rx");
17 });
18
19 test("macOS and Linux default to ~/.reasonix from $HOME, then the passwd home", () => {
20 assert.equal(unix({ HOME: "/home/u" }), "/home/u/.reasonix");
21 assert.equal(unix({ HOME: "/home/u" }, "linux"), "/home/u/.reasonix");
22 assert.equal(unix({}), "/home/fallback/.reasonix");
23 });
24
25 test("Windows uses %APPDATA%\\reasonix with the Roaming fallback", () => {
26 const win = (env: NodeJS.ProcessEnv) => reasonixHome({ env, platform: "win32", homedir: () => "", cwd: () => "C:\\work" });
27 assert.equal(win({ APPDATA: "C:\\Users\\u\\AppData\\Roaming" }), ["C:\\Users\\u\\AppData\\Roaming", "reasonix"].join(sep));
28 assert.equal(win({ USERPROFILE: "C:\\Users\\u" }), ["C:\\Users\\u", "AppData", "Roaming", "reasonix"].join(sep));
29 });
30
30 lines TYPESCRIPT