mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
The Node oracle runs with the harness's environment, but its cached verdict was keyed only on SCRIPTC_TEST_ENV among the variables. A program whose output reads NODE_ENV or another variable reused a verdict recorded under a different value. The key now covers every inherited variable except the test runner's worker numbers, which differ between workers of one run. Closes #51 Co-authored-by: Patrick Wozniak <4481570+patlux@users.noreply.github.com>
16 lines
759 B
TypeScript
16 lines
759 B
TypeScript
/* The environment part of the differential oracle cache key. The Node
|
|
* oracle runs with the harness's inherited environment, so a program whose
|
|
* output reads a variable (NODE_ENV, SCRIPTC_TEST_ENV, ...) must not reuse a
|
|
* verdict recorded under a different value. The variables that number the
|
|
* test runner's own workers differ between workers of one run and are left
|
|
* out, so every worker shares the cache. */
|
|
const WORKER_VARIABLES = new Set(["VITEST_POOL_ID", "VITEST_WORKER_ID", "TINYPOOL_WORKER_ID"]);
|
|
|
|
export function oracleEnvKey(env: NodeJS.ProcessEnv): string {
|
|
return Object.keys(env)
|
|
.filter((name) => !WORKER_VARIABLES.has(name) && env[name] !== undefined)
|
|
.sort()
|
|
.map((name) => `${name}=${env[name]}\0`)
|
|
.join("");
|
|
}
|