On this page
The Node env floor: a throwaway HOME and the four XDG dirs, an emptied git config with a throwaway identity, transport lockdown, credential stripping.
#typescript/src/env
#typescript/src/env
The environment floor: a throwaway home, an isolated git configuration and identity, transport lockdown, and credential stripping.
#IDENTITY_NAME
export const IDENTITY_NAME = "stricttest"The throwaway commit identity. The address is intentionally invalid: a commit made under it can never be mistaken for one of the developer's own, and mail to it goes nowhere.
#IDENTITY_EMAIL
export const IDENTITY_EMAIL = "[email protected]"#CREDENTIAL_VARS
export const CREDENTIAL_VARS: readonly string[] = [The closed list of ambient credential vectors that {@link stripCredentials} removes from the environment. A test that genuinely needs one sets a FAKE value itself.
The list is identical to the Go module's CredentialVars, and identical to the Python plugin's CREDENTIAL_VARS plus GIT_ASKPASS. That one variable is the floors' single deliberate divergence: the Python floor pins it to /bin/false, while this package and the Go module remove it. Both close the same door -- git cannot obtain a credential either way -- and a cross-language test in the Python suite holds the three lists in lockstep.
#throwawayHome
export function throwawayHome(registry: CleanupRegistry): stringRepoint HOME, USERPROFILE and the four XDG base directories (XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_CACHE_HOME, XDG_STATE_HOME) at a fresh temporary directory owned by this test, and return that directory. Every variable is restored and the directory is removed when the test finishes.
The XDG directories are repointed as well as HOME because a great many tools read them FIRST: a suite that moved only HOME would still let a tool read the developer's real ~/.config (gh's hosts.yml lives there) and write into their real caches.
The call is memoized per test: asking twice within the same test returns the same directory rather than moving HOME again. Each subtest gets its own context and therefore its own home.
#isolateGitConfig
export function isolateGitConfig(registry: CleanupRegistry): voidCut git off from the developer's configuration and identity: GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM point at empty files inside the throwaway home (allocated through {@link throwawayHome} if this test has not already), the author and committer identity become a throwaway one, and GIT_TERMINAL_PROMPT is 0 so no git invocation can block a test on a password prompt.
The config files are empty rather than carrying the identity, because the GIT_AUTHOR_ / GIT_COMMITTER_ variables below already supply it and outrank any config file -- a git invocation that ignores the config path entirely still cannot commit as the developer.
core.hooksPath is deliberately NOT set. It overrides repo-local hooks too, which would silently disable a suite's own pre-push-hook tests; an empty global config already prevents the developer's hooks from firing.
#lockdownTransports
export function lockdownTransports(registry: CleanupRegistry): voidRestrict git to the local file transport for the duration of this test. Any ssh://, https:// or git:// URL a test reaches for -- a real remote, a real fetch, a real push -- fails at the protocol check instead of touching the network.
GIT_SSH_COMMAND and GIT_PROXY_COMMAND are pinned to /bin/false as a second, independent layer. The protocol list is the first line and would be enough on its own, but a test (or a tool under test) that sets GIT_ALLOW_PROTOCOL itself would lift it -- and then the developer's real ssh, with their real key and their real proxy, is what git would run. Pinning both helpers means that path dies at an executable that only ever fails.
#stripCredentials
export function stripCredentials(registry: CleanupRegistry): voidRemove every variable in {@link CREDENTIAL_VARS} from the environment for the duration of this test. The original values are restored when it finishes.
#chdir
export function chdir(registry: CleanupRegistry, dir: string): voidMove the process working directory to dir for the duration of this test and restore the previous one when it finishes.
A failed restore FAILS the test rather than being logged and swallowed: the process is then sitting in the wrong directory, and every later test in the file would run against it. A test that reports the damage is the only honest outcome.
PWD is updated alongside the real working directory so that child processes inheriting the environment agree with the parent about where they are.