// tests/helpers/child-env.mjs // The environment a test gives a child process. The lock CLI // (lib/util/test-lock.mjs) writes a session pointer keyed by // CLAUDE_CODE_SESSION_ID; a child that inherits the id of the session running // the tests writes a pointer for that live session (S133). So the id never // reaches a child unless the test sets one itself. Same shape as // lib/util/command-env.mjs. tests/lib/session-id-isolation.test.mjs checks that // no other file under tests/ hands the process environment to a child. /** * A copy of process.env without CLAUDE_CODE_SESSION_ID, with `overrides` * applied last (a test that sets its own id keeps it). * * @param {Record} [overrides] - vars to set or replace * @returns {Record} the child's environment */ export function childEnv(overrides = {}) { const { CLAUDE_CODE_SESSION_ID, ...rest } = process.env; return { ...rest, ...overrides }; }