Repository navigation
perf(ci): Reuse integration dependency installs within test workers #26720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicohrubec
merged 17 commits into
develop
from
feat/benchmark-integration-install-timings
Nov 23, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
17b71d5
test(ci): Measure integration fixture dependency installs
nicohrubec f598ba7
test(ci): Benchmark keyed fixture dependency reuse
nicohrubec e83a45f
test(ci): Benchmark native fixture dependency copies
nicohrubec af2b668
test(ci): Diagnose copy failures and install fresh on cache misses
nicohrubec 6961831
test(ci): Seed persistent integration dependency caches
nicohrubec 40b3344
test(ci): Normalize Deno version in fixture cache keys
nicohrubec 925cae9
test(ci): Benchmark warm integration dependency caches
nicohrubec 3d3a631
ci: Clean up previous days' integration dependency caches
nicohrubec 21f62d4
perf(ci): Finalize integration dependency caching
nicohrubec 21af599
ci: Simplify integration cache environment checks
nicohrubec 6109e33
ci: Extract integration cache composite actions
nicohrubec 126b2d0
ci: Make integration cache action calls explicit
nicohrubec 5f12f66
ci: Ignore already deleted caches during cleanup
nicohrubec e8afae0
refactor(ci): Keep integration dependency reuse within each worker
nicohrubec 75a3fab
test(ci): Benchmark fresh integration dependency installs
nicohrubec c307fe2
test(ci): Measure in-runner integration dependency reuse
nicohrubec 452da77
refactor(ci): Explain fixture reuse and clarify install names
nicohrubec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
dev-packages/node-integration-tests/utils/runner/installFixtureDependencies.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| import { execFile } from 'child_process'; | ||
| import { rmSync } from 'fs'; | ||
| import { cp, mkdtemp, rm, writeFile } from 'fs/promises'; | ||
| import { join } from 'path'; | ||
| import { promisify } from 'util'; | ||
| import { PACKAGE_ROOT } from './createRunner'; | ||
|
|
||
| const execFilePromise = promisify(execFile); | ||
|
|
||
| const dependencyInstalls = new Map<string, Promise<string>>(); | ||
| const dependencyDirectories = new Set<string>(); | ||
|
|
||
| process.once('exit', () => { | ||
| for (const directory of dependencyDirectories) { | ||
| rmSync(directory, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| // Install each dependency set once per worker, then copy it into each scenario's directory. | ||
| // Sharing the promise also deduplicates concurrent requests. Scenarios can modify or delete | ||
| // their copies independently; the original installs are kept until the worker exits. | ||
| export async function installFixtureDependencies( | ||
| directory: string, | ||
| dependencies: Record<string, string>, | ||
| reuseAllowed: boolean, | ||
| ): Promise<void> { | ||
| const dependencySpecs = Object.entries(dependencies).map(([name, range]) => { | ||
| if (!range || typeof range !== 'string') { | ||
| throw new Error(`Invalid version range for "${name}": ${String(range)}`); | ||
| } | ||
| return `${name}@${range}`; | ||
| }); | ||
| // Custom installs may depend on copied fixture files; the fast-copy path also requires GNU cp. | ||
| if (!process.env.CI || process.platform !== 'linux' || !reuseAllowed) { | ||
| await npmInstallWithRetry(directory, dependencySpecs); | ||
| return; | ||
| } | ||
|
|
||
| const key = JSON.stringify(Object.entries(dependencies).sort(([a], [b]) => a.localeCompare(b))); | ||
| const installPromise = getOrCreateDependencyInstall(key, dependencies, dependencySpecs); | ||
| const sourceDirectory = await installPromise; | ||
| try { | ||
| await copyDependencyInstall(sourceDirectory, directory); | ||
| } catch (error) { | ||
| // oxlint-disable-next-line no-console | ||
| console.warn('Dependency copy failed; installing fresh:', error); | ||
| if (dependencyInstalls.get(key) === installPromise) { | ||
| dependencyInstalls.delete(key); | ||
| } | ||
| await rm(join(directory, 'node_modules'), { recursive: true, force: true }); | ||
| await rm(join(directory, 'package-lock.json'), { force: true }); | ||
| await npmInstallWithRetry(directory, dependencySpecs); | ||
| } | ||
| } | ||
|
|
||
| async function copyDependencyInstall(source: string, destination: string): Promise<void> { | ||
| // Native copying avoids the per-file overhead of fs.cp for large dependency trees. | ||
| await execFilePromise('cp', [ | ||
| '-a', | ||
| '--reflink=auto', | ||
| join(source, 'node_modules'), | ||
| join(destination, 'node_modules'), | ||
| ]); | ||
| await cp(join(source, 'package-lock.json'), join(destination, 'package-lock.json')); | ||
| } | ||
|
|
||
| function getOrCreateDependencyInstall( | ||
| key: string, | ||
| dependencies: Record<string, string>, | ||
| dependencySpecs: string[], | ||
| ): Promise<string> { | ||
| const existing = dependencyInstalls.get(key); | ||
| if (existing) return existing; | ||
|
|
||
| const installPromise = (async () => { | ||
| const directory = await mkdtemp(join(PACKAGE_ROOT, 'tmp_dependencies_')); | ||
| dependencyDirectories.add(directory); | ||
| await writeFile( | ||
| join(directory, 'package.json'), | ||
| JSON.stringify({ name: 'tmp-integration-test', private: true, version: '0.0.0', dependencies }), | ||
| ); | ||
| await npmInstallWithRetry(directory, dependencySpecs); | ||
| return directory; | ||
| })(); | ||
|
|
||
| dependencyInstalls.set(key, installPromise); | ||
| void installPromise.catch(() => { | ||
| if (dependencyInstalls.get(key) === installPromise) { | ||
| dependencyInstalls.delete(key); | ||
| } | ||
| }); | ||
| return installPromise; | ||
| } | ||
|
|
||
| const NPM_INSTALL_MAX_RETRIES = 3; | ||
| const NPM_INSTALL_RETRY_DELAY_MS = 2_000; | ||
| // npm install can stall on CI without ever failing, which would otherwise use up the whole setup hook timeout | ||
| // before a retry gets a chance to run. | ||
| const NPM_INSTALL_TIMEOUT_MS = 60_000; | ||
|
|
||
| async function npmInstallWithRetry(cwd: string, deps: string[]): Promise<void> { | ||
| for (let attempt = 1; attempt <= NPM_INSTALL_MAX_RETRIES; attempt++) { | ||
| try { | ||
| // Run npm without a shell, so the timeout kills npm itself rather than leaving it running next to the retry | ||
| const { stdout, stderr } = await execFilePromise( | ||
| 'npm', | ||
| // We only use --prefer-offline on the first attempt to try to read from cache | ||
| // in follow ups we just try to install in any way | ||
| ['install', ...(attempt === 1 ? ['--prefer-offline'] : []), '--no-audit', '--no-fund'], | ||
| { | ||
| cwd, | ||
| encoding: 'utf8', | ||
| timeout: NPM_INSTALL_TIMEOUT_MS, | ||
| }, | ||
| ); | ||
|
|
||
| if (process.env.DEBUG) { | ||
| // eslint-disable-next-line no-console | ||
| console.log('[additionalDependencies via npm]', deps.join(' ')); | ||
| // eslint-disable-next-line no-console | ||
| console.log('[npm stdout]', stdout); | ||
| // eslint-disable-next-line no-console | ||
| console.log('[npm stderr]', stderr); | ||
| } | ||
| return; | ||
| } catch (error) { | ||
| if (attempt < NPM_INSTALL_MAX_RETRIES) { | ||
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| `npm install attempt ${attempt}/${NPM_INSTALL_MAX_RETRIES} failed, retrying in ${NPM_INSTALL_RETRY_DELAY_MS}ms...`, | ||
| ); | ||
| await new Promise(resolve => setTimeout(resolve, NPM_INSTALL_RETRY_DELAY_MS)); | ||
| // A killed attempt leaves a partial install behind, which the next attempt would treat as complete | ||
| await rm(join(cwd, 'node_modules'), { recursive: true, force: true }); | ||
| await rm(join(cwd, 'package-lock.json'), { force: true }); | ||
| } else { | ||
| // oxlint-disable-next-line no-console | ||
| console.error(error); | ||
| throw new Error( | ||
| `Failed to install additionalDependencies in tmp dir ${cwd} after ${NPM_INSTALL_MAX_RETRIES} attempts`, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from here on downwards this was just moved to this file as is