fix(cc-config): .claude.json sits BESIDE ~/.claude by default, not inside it
The previous commit routed the read through getClaudeHome(), which appends /.claude when CLAUDE_HOME is unset — pointing the dashboard at ~/.claude/.claude.json, a file the CLI never writes by default. Verified against the real binary: with CLAUDE_CONFIG_DIR unset the CLI writes $HOME/.claude.json; with it set, .claude.json sits flat inside that dir. Branch on CLAUDE_HOME accordingly. The test now drives a fake claude that writes where the real one does and asserts getClaudeJsonPath() names that exact file, under both branches — the previous test only restated the implementation.
This commit is contained in:
@@ -225,26 +225,50 @@ describe("cc-plugin-cli CLAUDE_CONFIG_DIR pinning", () => {
|
||||
}
|
||||
});
|
||||
|
||||
// The two env tests above pin one half each. This pins the pair: the file
|
||||
// the dashboard READS must be the file the CLI WRITES, under both settings.
|
||||
// `.claude.json` was the only read path in cc-discovery not derived from
|
||||
// getClaudeHome(), which is exactly how the two halves drifted apart.
|
||||
it("reads the same .claude.json the CLI writes, with CLAUDE_HOME set or unset", () => {
|
||||
// The two env tests above pin the env var each half of the pair depends
|
||||
// on. This pins the pair itself end to end: the file getClaudeJsonPath()
|
||||
// returns must be the file the CLI actually wrote — under BOTH an unset
|
||||
// and a set CLAUDE_HOME. A fake `claude` that writes `.claude.json`
|
||||
// exactly where the real binary does (verified against it: flat inside
|
||||
// CLAUDE_CONFIG_DIR when set, beside — NOT inside — $HOME when unset)
|
||||
// stands in for the real CLI; no real CLI or real $HOME/CLAUDE_HOME touched.
|
||||
const WRITE_CLAUDE_JSON = 'echo "{}" > "${CLAUDE_CONFIG_DIR:-$HOME}/.claude.json"';
|
||||
|
||||
it("writes .claude.json exactly where getClaudeJsonPath() reads it, with CLAUDE_HOME unset", async () => {
|
||||
const cc = require("../lib/cc-discovery");
|
||||
const originalHome = process.env.CLAUDE_HOME;
|
||||
|
||||
// CLI's write target = <CLAUDE_CONFIG_DIR>/.claude.json, and
|
||||
// CLAUDE_CONFIG_DIR is either CLAUDE_HOME or the CLI's own default,
|
||||
// which is the same directory getClaudeHome() returns.
|
||||
const originalHome = process.env.HOME;
|
||||
const originalClaudeHome = process.env.CLAUDE_HOME;
|
||||
const fakeHome = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-fakehome-"));
|
||||
delete process.env.CLAUDE_HOME;
|
||||
process.env.HOME = fakeHome;
|
||||
const restore = stubClaude(WRITE_CLAUDE_JSON);
|
||||
try {
|
||||
delete process.env.CLAUDE_HOME;
|
||||
assert.equal(cc.getClaudeJsonPath(), path.join(os.homedir(), ".claude", ".claude.json"));
|
||||
|
||||
process.env.CLAUDE_HOME = "/tmp/some-other-claude-home";
|
||||
assert.equal(cc.getClaudeJsonPath(), "/tmp/some-other-claude-home/.claude.json");
|
||||
await cli.marketplaceUpdate({ name: "m" });
|
||||
assert.equal(cc.getClaudeJsonPath(), path.join(fakeHome, ".claude.json"));
|
||||
assert.ok(fs.existsSync(cc.getClaudeJsonPath()), "the CLI's write landed where reads look");
|
||||
} finally {
|
||||
if (originalHome === undefined) delete process.env.CLAUDE_HOME;
|
||||
else process.env.CLAUDE_HOME = originalHome;
|
||||
restore();
|
||||
process.env.HOME = originalHome;
|
||||
if (originalClaudeHome !== undefined) process.env.CLAUDE_HOME = originalClaudeHome;
|
||||
fs.rmSync(fakeHome, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("writes .claude.json exactly where getClaudeJsonPath() reads it, with CLAUDE_HOME set", async () => {
|
||||
const cc = require("../lib/cc-discovery");
|
||||
const originalClaudeHome = process.env.CLAUDE_HOME;
|
||||
const fakeClaudeHome = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-fakeclaudehome-"));
|
||||
process.env.CLAUDE_HOME = fakeClaudeHome;
|
||||
const restore = stubClaude(WRITE_CLAUDE_JSON);
|
||||
try {
|
||||
await cli.marketplaceUpdate({ name: "m" });
|
||||
assert.equal(cc.getClaudeJsonPath(), path.join(fakeClaudeHome, ".claude.json"));
|
||||
assert.ok(fs.existsSync(cc.getClaudeJsonPath()), "the CLI's write landed where reads look");
|
||||
} finally {
|
||||
restore();
|
||||
if (originalClaudeHome === undefined) delete process.env.CLAUDE_HOME;
|
||||
else process.env.CLAUDE_HOME = originalClaudeHome;
|
||||
fs.rmSync(fakeClaudeHome, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user