Repository navigation
[rush] Fix declared environment snapshot hashing - #6203
Yashwanth Reddy Verupaka (yashwanth195) wants to merge 3 commits into
Conversation
David Michon (dmichon-msft)
left a comment
There was a problem hiding this comment.
Case sensitivity vs. insensitivity needs to be globally consistent in Rush so that builds produce the same results on either platform.
| return getStrictHash(input, project, useOperationEnvironment ? environment : undefined); | ||
| } | ||
|
|
||
| it('distinguishes absence, empty values and literal sentinel strings', () => { |
There was a problem hiding this comment.
Why does absent vs. empty string matter?
There was a problem hiding this comment.
An unset value takes the default in process.env.PUBLIC_PATH ?? '/default/', while an empty string overrides it. Those can produce different outputs, so their cache hashes must differ. Added a regression covering that distinction.
| * Selects the compatibility contract for operation inputs. | ||
| * @beta | ||
| */ | ||
| export type InputSnapshotPolicy = 'legacy' | 'strict-v1'; |
There was a problem hiding this comment.
If this is a strict correctness fix, the only backwards compatibility required is to ensure that we don't produce the same hash for different content.
There was a problem hiding this comment.
Removed the legacy/strict policy split. Declared environment inputs now use an unambiguous encoding separated from the old encoding. Operations without declared environment inputs retain their existing hash bytes.
| /** | ||
| * The environment to use for `dependsOnEnvVars`. By default performs a snapshot of process.env upon construction. | ||
| * The environment for `dependsOnEnvVars`. Strict queries capture its values upon construction. | ||
| * Legacy queries retain an explicitly supplied object, or copy process.env by default. |
There was a problem hiding this comment.
The architecture assumes the input object is immutable, and enforcing that is left as an exercise for the caller. In general components were designed to assume callers respect immutability constraints in the interests of performance.
There was a problem hiding this comment.
Removed the defensive copies and duplicate state. The producer captures one EnvironmentMap, and snapshots retain it under the existing caller-owned immutability contract.
| this.#projectMetadataMap = | ||
| (previousSnapshot && | ||
| previousSnapshot.#tryDeriveProjectMetadataMap( | ||
| params, | ||
| environment, | ||
| nodeVersion, | ||
| globalAdditionalHashes, | ||
| operationAdditionalFileCount | ||
| )) ?? | ||
| createProjectMetadataMap(hashes, lookupByPath, projectMap, rootDir); | ||
| (previousSnapshot && areEnvironmentsEqual(environment, previousSnapshot.#environment) | ||
| ? previousSnapshot.#tryDeriveProjectMetadataMap( | ||
| params, | ||
| nodeVersion, | ||
| globalAdditionalHashes, | ||
| operationAdditionalFileCount, | ||
| previousSnapshot.#projectMetadataMap | ||
| ) | ||
| : undefined) ?? createProjectMetadataMap(hashes, lookupByPath, projectMap, rootDir); |
There was a problem hiding this comment.
this.#projectMetadataMap =
previousSnapshot?.#tryDeriveProjectMetadataMap(
params,
environment,
nodeVersion,
globalAdditionalHashes,
operationAdditionalFileCount
) ??
createProjectMetadataMap(hashes, lookupByPath, projectMap, rootDir);There was a problem hiding this comment.
Changed this to #tryDeriveProjectMetadataMap(...) ?? createProjectMetadataMap(...). The helper handles an absent previous snapshot because our parser rejects optional chaining on private members.
| function getOutputLookupPath(rootDir: string, filePath: string): string { | ||
| const relativePath: string = Path.convertToSlashes(path.relative(rootDir, path.resolve(rootDir, filePath))); | ||
| return process.platform === 'win32' ? relativePath.toLowerCase() : relativePath; | ||
| } |
There was a problem hiding this comment.
The filePath inputs are very explicitly constrained in their shape. Any .. or . path components are invalid, so there's no reason to perform path resolution. The provided path is purely a dictionary key into the additionalHashes table.
All delimiters are already normalized to /, so there's no reason to perform delimeter normalization.
Case sensitivity is file system specific, not OS specific.
There was a problem hiding this comment.
If we're going to make the inputs snapshot case insensitive, we need to do so everywhere. We can't have the tooling producing different enforcement results on Windows vs. Linux.
There was a problem hiding this comment.
Removed both. The supplied canonical paths are used directly as dictionary keys, matching the existing behavior.
There was a problem hiding this comment.
Removed the OS-specific file-key folding. File-key handling now matches upstream and remains case-sensitive on every platform.
| return true; | ||
| } | ||
|
|
||
| function areEnvironmentMapsEqual(a: EnvironmentMap, b: EnvironmentMap): boolean { |
There was a problem hiding this comment.
Add this functionality to EnvironmentMap itself, since it seems useful; that will also facilitate optimization like not creating superfluous temporary arrays.
There was a problem hiding this comment.
Added EnvironmentMap.equals() with focused tests and the API report. Both snapshot-reuse checks now use it without allocating temporary arrays.
Summary
Fix Rush cache identity for declared environment inputs: capture supplied values at snapshot creation, distinguish unset from empty, and resolve Windows environment names case-insensitively.
Details
EnvironmentMapfor snapshot capture, explicit per-operation environments, and previous-snapshot comparison. Preserve memoization, undeclared-input exclusion, and non-Windows case sensitivity.How it was tested
Windows, Node 24.22.1, Rush 5.182.0:
node common\scripts\install-run-rush.js build --to @microsoft/rush-lib --parallelism 4libraries\rush-lib:node ..\..\common\scripts\install-run-rushx.js _phase:test --test-path-pattern InputsSnapshot --max-workers 1 --disable-code-coveragenode common\scripts\install-run-rush.js prettiernode common\scripts\install-run-rush.js change --verify --target-branch upstream/main --no-fetchgit diff --cached --checkCoverage includes absent/empty/sentinel values, captured caller mutations, separator collisions, Windows and Linux name semantics, explicit operation environments before/after memoization, and previous-snapshot reuse. Jest reported fixture package-name collision warnings; the suite passed.
Build/tests preceded the final rebase onto
c2acd010079c6c08e63ba25d0b136ed2c1b16ccd. Upstream changed only unrelated Heft plugin selection; all four validated files were verified byte-identical after rebasing. No broad sharding or coverage matrix was run.Impacted documentation
None. The patch changefile documents the intentional cache-key change.