Files
deepseek-harness/scripts/verify-npm-install-layout.spec.ts
T
Chinesezjc f45693fbe5 fix(ci): decide the dual-release install layout by graph scale
The Dependency layout lane failed whenever the npm child process exceeded
a hardcoded 300 s deadline. That deadline measured the runner rather than
the graph: the same layout resolves in 137-205 s on an idle developer host
and exceeded 300 s on CI while the placement assertion reported no error,
so the failure carried no information about what had grown.

The gate now bounds the verified graph by resolution work units,
dshPackagesPerVersion * checkedDshEdges against MAX_RESOLUTION_WORK_UNITS,
and keeps the wall clock only as a hang guard derived from that budget.
Growth fails with the graph's own measured counts on any runner.

The resolution cost itself is unchanged. Measurement attributed 99.3% of
it to npm's peer-conflict placement, and cache reuse, graph splitting and
the placement flags were measured and rejected.
2026-09-28 16:04:06 +08:00

145 lines
5.7 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import type { NpmPackageLock, RegistryIndex } from './benchmark-npm-resolution.ts'
import {
assertDualDshInstallLayout,
assertResolutionWorkBudget,
buildDualDshRegistry,
MAX_RESOLUTION_WORK_UNITS,
} from './verify-npm-install-layout.ts'
function validLayout(): NpmPackageLock {
return {
lockfileVersion: 3,
packages: {
'': { dependencies: { '@deepseek-ai/dsh': '0.2.0', 'dsh-previous': 'npm:@deepseek-ai/[email protected]' } },
'node_modules/@deepseek-ai/cordis': { version: '4.0.1' },
'node_modules/@deepseek-ai/dsh': {
version: '0.2.0',
dependencies: { '@deepseek-ai/dsh-child': '^0.2.0' },
peerDependencies: { '@deepseek-ai/cordis': '^4.0.1' },
},
'node_modules/@deepseek-ai/dsh-child': {
version: '0.2.0',
dependencies: { '@deepseek-ai/dsh-leaf': '^0.2.0' },
},
'node_modules/@deepseek-ai/dsh-leaf': { version: '0.2.0' },
'node_modules/dsh-previous': {
name: '@deepseek-ai/dsh',
version: '0.1.0',
dependencies: { '@deepseek-ai/dsh-child': '^0.1.0' },
peerDependencies: { '@deepseek-ai/cordis': '^4.0.1' },
},
'node_modules/dsh-previous/node_modules/@deepseek-ai/dsh-child': {
version: '0.1.0',
dependencies: { '@deepseek-ai/dsh-leaf': '^0.1.0' },
},
'node_modules/dsh-previous/node_modules/@deepseek-ai/dsh-leaf': { version: '0.1.0' },
},
}
}
describe('npm install layout verifier', () => {
it('creates two incompatible versions of every DSH package', () => {
const index: RegistryIndex = new Map([
['@deepseek-ai/dsh', new Map([['0.1.1-rc.2', {
name: '@deepseek-ai/dsh',
version: '0.1.1-rc.2',
dependencies: { '@deepseek-ai/dsh-child': '^0.1.1-rc.2' },
peerDependencies: { '@deepseek-ai/cordis': '^4.0.1' },
}]])],
['@deepseek-ai/dsh-child', new Map([['0.1.1-rc.2', {
name: '@deepseek-ai/dsh-child',
version: '0.1.1-rc.2',
}]])],
['@deepseek-ai/cordis', new Map([['4.0.1', {
name: '@deepseek-ai/cordis',
version: '4.0.1',
}]])],
])
const dual = buildDualDshRegistry(index, '0.1.1-rc.2')
expect([...dual.get('@deepseek-ai/dsh')?.keys() ?? []]).toEqual(['0.1.0', '0.2.0'])
expect(dual.get('@deepseek-ai/dsh')?.get('0.1.0')).toMatchObject({
version: '0.1.0',
dependencies: { '@deepseek-ai/dsh-child': '^0.1.0' },
peerDependencies: { '@deepseek-ai/cordis': '^4.0.1' },
})
expect(dual.get('@deepseek-ai/dsh')?.get('0.2.0')).toMatchObject({
version: '0.2.0',
dependencies: { '@deepseek-ai/dsh-child': '^0.2.0' },
})
expect(dual.get('@deepseek-ai/cordis')).toBe(index.get('@deepseek-ai/cordis'))
})
it('accepts isolated DSH releases with one shared Cordis installation', () => {
expect(assertDualDshInstallLayout(validLayout())).toEqual({
dshPackagesPerVersion: 3,
checkedDshEdges: 4,
})
})
it.each([
['react', 'node_modules/react'],
['react-dom', 'node_modules/react-dom'],
['react', 'node_modules/dsh-previous/node_modules/react'],
['react-dom', 'node_modules/dsh-previous/node_modules/react-dom'],
])('rejects browser runtime %s installed at %s in the DSH-only consumer', (name, path) => {
const layout = validLayout()
const packages = { ...layout.packages, [path]: { version: '18.3.1' } }
expect(() => assertDualDshInstallLayout({ ...layout, packages })).toThrow(
`${path}: ${name} is a browser build input`,
)
})
it('rejects an internal edge that crosses release versions', () => {
const layout = validLayout()
const packages = { ...layout.packages }
Reflect.deleteProperty(packages, 'node_modules/dsh-previous/node_modules/@deepseek-ai/dsh-leaf')
expect(() => assertDualDshInstallLayout({ ...layout, packages })).toThrow(
'node_modules/dsh-previous/node_modules/@deepseek-ai/dsh-child: dependencies '
+ '@deepseek-ai/dsh-leaf resolves to node_modules/@deepseek-ai/[email protected], expected 0.1.0',
)
})
it('rejects a second Cordis installation', () => {
const layout = validLayout()
const packages = {
...layout.packages,
'node_modules/dsh-previous/node_modules/@deepseek-ai/cordis': { version: '4.0.1' },
}
expect(() => assertDualDshInstallLayout({ ...layout, packages })).toThrow(
'expected one shared @deepseek-ai/cordis',
)
})
})
describe('resolution work budget', () => {
it('accepts the measured dual-release graph', () => {
expect(assertResolutionWorkBudget({ dshPackagesPerVersion: 277, checkedDshEdges: 2524 }))
.toBe(699_148)
})
it('accepts a graph exactly at the budget and rejects one internal edge above it', () => {
const packages = 350
const edgesAtBudget = Math.floor(MAX_RESOLUTION_WORK_UNITS / packages)
expect(packages * edgesAtBudget).toBe(MAX_RESOLUTION_WORK_UNITS)
expect(assertResolutionWorkBudget({ dshPackagesPerVersion: packages, checkedDshEdges: edgesAtBudget }))
.toBe(MAX_RESOLUTION_WORK_UNITS)
expect(() => assertResolutionWorkBudget({
dshPackagesPerVersion: packages,
checkedDshEdges: edgesAtBudget + 1,
})).toThrow(`= ${String(MAX_RESOLUTION_WORK_UNITS + packages)} unit(s), budget ${String(MAX_RESOLUTION_WORK_UNITS)} unit(s)`)
})
it('accepts the headroom and rejects a runaway graph with its own measured counts', () => {
expect(assertResolutionWorkBudget({ dshPackagesPerVersion: 300, checkedDshEdges: 2800 }))
.toBe(840_000)
expect(() => assertResolutionWorkBudget({ dshPackagesPerVersion: 400, checkedDshEdges: 3000 }))
.toThrow('400 package(s) per release x 3000 internal edge(s) = 1200000 unit(s), budget 875000 unit(s)')
})
})