/** * @file Tests that the server drops the variables describing the Claude Code * session that started it (always the case on macOS, where there is no * systemd unit to give it a clean env) — tmux and every lane pane inherit the * server's env, so a leaked CLAUDECODE made each pane look like a nested * session. User configuration (CLAUDE_CONFIG_DIR, ANTHROPIC_*, …) must survive. * @author Nguyễn Ngọc Trí Vĩ */ const { it, after } = require("node:test"); const assert = require("node:assert/strict"); const fs = require("fs"); const os = require("os"); const path = require("path"); const TMP = fs.mkdtempSync(path.join(os.tmpdir(), "agenthub-envscrub-")); process.env.DASHBOARD_DB_PATH = path.join(TMP, "dashboard.db"); process.env.CLAUDE_HOME = path.join(TMP, "home"); process.env.DASHBOARD_DATA_DIR = path.join(TMP, "data"); process.env.CLAUDECODE = "1"; process.env.CLAUDE_CODE_ENTRYPOINT = "cli"; process.env.CLAUDE_CODE_SESSION_ID = "abc"; process.env.CLAUDE_CODE_MESSAGING_SOCKET = "/tmp/x.sock"; process.env.CLAUDE_PLUGIN_ROOT = "/some/cache/dir"; process.env.CLAUDE_CONFIG_DIR = "/Users/x/.claude-work"; process.env.CLAUDE_CODE_USE_BEDROCK = "1"; process.env.ANTHROPIC_BASE_URL = "https://example.invalid"; require("../index"); const { db } = require("../db"); after(() => { db.close(); fs.rmSync(TMP, { recursive: true, force: true }); }); it("strips the parent session's variables and keeps user configuration", () => { for (const k of [ "CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT", "CLAUDE_CODE_SESSION_ID", "CLAUDE_CODE_MESSAGING_SOCKET", "CLAUDE_PLUGIN_ROOT", ]) { assert.equal(process.env[k], undefined, k); } assert.equal(process.env.CLAUDE_CONFIG_DIR, "/Users/x/.claude-work"); assert.equal(process.env.CLAUDE_CODE_USE_BEDROCK, "1"); assert.equal(process.env.ANTHROPIC_BASE_URL, "https://example.invalid"); });