refactor(codex): give the CODEX_HOME lookup its own module
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @file Tests for codex-home.js: CODEX_HOME resolution and related path
|
||||
* resolutions for Codex project and surface directories.
|
||||
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
||||
*/
|
||||
|
||||
const path = require("node:path");
|
||||
const os = require("node:os");
|
||||
|
||||
const { describe, it, beforeEach } = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
describe("codex-home", () => {
|
||||
beforeEach(() => {
|
||||
// Clear the require cache so getCodexHome() reads the fresh env var
|
||||
delete require.cache[require.resolve("../lib/codex-home")];
|
||||
});
|
||||
|
||||
it("honours CODEX_HOME over the home directory", () => {
|
||||
process.env.CODEX_HOME = "/tmp/injected-codex";
|
||||
delete require.cache[require.resolve("../lib/codex-home")];
|
||||
assert.equal(require("../lib/codex-home").getCodexHome(), "/tmp/injected-codex");
|
||||
});
|
||||
|
||||
it("puts the project surfaces under <cwd>/.codex", () => {
|
||||
const { getProjectCodexDir } = require("../lib/codex-home");
|
||||
assert.equal(getProjectCodexDir("/repo"), path.join("/repo", ".codex"));
|
||||
});
|
||||
|
||||
it("returns the cwd as the project root", () => {
|
||||
const { getProjectRoot } = require("../lib/codex-home");
|
||||
assert.equal(getProjectRoot("/repo"), "/repo");
|
||||
});
|
||||
|
||||
it("defaults to ~/.codex when CODEX_HOME is not set", () => {
|
||||
delete process.env.CODEX_HOME;
|
||||
delete require.cache[require.resolve("../lib/codex-home")];
|
||||
const { getCodexHome } = require("../lib/codex-home");
|
||||
assert.equal(getCodexHome(), path.join(os.homedir(), ".codex"));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user