The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(build): refuse a completed-install receipt whose packages lost their manifests
liuhao10241d6b2786e2b2
diff --git a/scripts/build/node-deps.mjs b/scripts/build/node-deps.mjsindex edab59ec067..df2bbd9adec 100644--- a/scripts/build/node-deps.mjs+++ b/scripts/build/node-deps.mjs@@ -56,8 +56,13 @@ function completedInstallMatches({ source, receipt, hiddenLock, key, nativeKey }const nativeReceipt = `${receipt}.native-toolchain`if (!existsSync(nativeReceipt) || readFileSync(nativeReceipt, 'utf8') !== `${expected}${nativeKey}\n`) return false}+ // Probe each locked entry's manifest, not its directory: a partial cleanup or+ // snapshot restore can leave gutted directories behind, and product builders+ // resolve tools through these manifests (#128935). npm itself never repairs+ // such an entry — it trusts the hidden lockfile's claim that the package is+ // installed — so only rejecting the receipt here routes the update to npm ci.return readFileSync(receipt, 'utf8') === expected && Object.keys(JSON.parse(installed).packages)- .every(path => existsSync(join(source, path)))+ .every(path => existsSync(join(source, path, 'package.json')))}// An interrupted Windows update can leave a nested .bin that npm ci's own rmdirdiff --git a/tests-js/node-deps.test.mjs b/tests-js/node-deps.test.mjsindex b80cb59a1ae..f4e8ff77b0e 100644--- a/tests-js/node-deps.test.mjs+++ b/tests-js/node-deps.test.mjs@@ -66,6 +66,23 @@ test('read-only dependency preparation reuses complete receipts but refuses missexpect(readFileSync(join(source, 'node_modules/.hermes-node-deps'))).toEqual(receipt)}, 30000)+test('reuse refuses a gutted package directory and repairs it with npm ci', async () => {+ const { prepareNodeDependencies } = await import('../scripts/build/node-deps.mjs')+ const source = fixture()+ const options = { source, workspaces: ['web'], reuse: true,+ env: { ...process.env, npm_config_offline: 'true', npm_config_cache: join(source, '.npm-cache') } }+ prepareNodeDependencies(options)+ // #128935: an external cleanup or snapshot restore can leave the directory+ // while stripping its contents. npm trusts the hidden lockfile and would+ // only "repair" entries it does not list, so the receipt must reject first.+ rmSync(join(source, 'node_modules/web-only'), { recursive: true })+ mkdirSync(join(source, 'node_modules/web-only'))+ expect(existsSync(join(source, 'node_modules/web-only/package.json'))).toBe(false)+ expect(() => prepareNodeDependencies({ ...options, install: false })).toThrow(/disabled/)+ prepareNodeDependencies(options)+ expect(createRequire(join(source, 'web/package.json'))('web-only')).toBe('web-only')+}, 30000)+test('native toolchain admission rejects a changed compiler without breaking ordinary builders', async () => {const { prepareNodeDependencies } = await import('../scripts/build/node-deps.mjs')const source = fixture()