Preserve Claude SDK child environment
This commit is contained in:
@@ -26,12 +26,12 @@ import type {
|
||||
|
||||
/**
|
||||
* Build a child environment: explicit caller entries merge after the scrubbed
|
||||
* parent base, so a deliberately supplied credential or current `DSH_*` fact
|
||||
* wins over the scrub that dropped its ambient namesake.
|
||||
* @param extra - explicit caller entries, merged verbatim after the scrub.
|
||||
* parent base. A string deliberately restores or overrides an entry; an
|
||||
* explicit `undefined` tombstone removes an ordinary ambient entry.
|
||||
* @param extra - explicit caller entries and tombstones, merged after the scrub.
|
||||
* @returns the environment to hand to `spawn` for the child process.
|
||||
*/
|
||||
export function childEnv(extra?: Readonly<Record<string, string>>): NodeJS.ProcessEnv {
|
||||
export function childEnv(extra?: Readonly<NodeJS.ProcessEnv>): NodeJS.ProcessEnv {
|
||||
return { ...scrubbedParentEnv(), ...extra }
|
||||
}
|
||||
|
||||
|
||||
@@ -343,6 +343,19 @@ describe('stdin and extra env (set by in-process plugins)', () => {
|
||||
expect(result.stdout.text).toBe('alpha/beta\n')
|
||||
})
|
||||
|
||||
it('lets an explicit tombstone remove an ordinary ambient env entry', async () => {
|
||||
process.env.SUBPROCESS_TOMBSTONE_PROBE = 'ambient-value'
|
||||
try {
|
||||
const result = await finish(spawnSubprocess(spec(
|
||||
'echo "${SUBPROCESS_TOMBSTONE_PROBE:-absent}"',
|
||||
{ env: { SUBPROCESS_TOMBSTONE_PROBE: undefined } },
|
||||
)))
|
||||
expect(result.stdout.text).toBe('absent\n')
|
||||
} finally {
|
||||
delete process.env.SUBPROCESS_TOMBSTONE_PROBE
|
||||
}
|
||||
})
|
||||
|
||||
it('an explicit extra env entry overrides the credential scrub', async () => {
|
||||
// EXPLICIT_OVERRIDE_PASSWORD matches the credential scrub pattern, yet an explicit
|
||||
// entry is still honored — the scrub only drops AMBIENT process.env creds.
|
||||
|
||||
Reference in New Issue
Block a user