Files
orca/config/scripts/pinned-node-downloads.test.mjs
T
Neil 3a7ec7dff1 perf: reuse verified Node and run the layout check with Bun (#28218)
* perf: overlap preflight daemon smoke and reuse verified Node executable

* Keep measured Node reuse and Bun layout wins; drop smoke scheduling experiments
2026-10-13 02:58:56 -07:00

62 lines
2.1 KiB
JavaScript

import { createHash } from 'node:crypto'
import {
existsSync,
mkdirSync,
mkdtempSync,
readFileSync,
rmSync,
statSync,
writeFileSync
} from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, expect, it } from 'vitest'
import { copyPinnedNodeExecutable } from './pinned-node-downloads.mjs'
const directories = []
afterEach(() => {
for (const directory of directories.splice(0)) {
rmSync(directory, { recursive: true, force: true })
}
})
function fixture() {
const directory = mkdtempSync(join(tmpdir(), 'pinned-node-copy-'))
directories.push(directory)
const source = join(directory, 'host-node')
const destination = join(directory, 'cache', 'bin', 'node')
const bytes = Buffer.from('pinned executable bytes')
writeFileSync(source, bytes, { mode: 0o600 })
return { source, destination, bytes, hash: createHash('sha256').update(bytes).digest('hex') }
}
it('copies only the exact pinned executable and makes the cached copy runnable on POSIX', async () => {
const { source, destination, bytes, hash } = fixture()
expect(await copyPinnedNodeExecutable(source, destination, hash)).toBe(true)
expect(readFileSync(destination)).toEqual(bytes)
if (process.platform !== 'win32') {
expect(statSync(destination).mode & 0o777).toBe(0o755)
}
})
it('falls back when the host executable differs from the pin without staging it', async () => {
const { source, destination } = fixture()
expect(await copyPinnedNodeExecutable(source, destination, '0'.repeat(64))).toBe(false)
expect(existsSync(destination)).toBe(false)
})
it('falls back when the candidate executable is unavailable', async () => {
const { source, destination, hash } = fixture()
rmSync(source)
expect(await copyPinnedNodeExecutable(source, destination, hash)).toBe(false)
expect(existsSync(destination)).toBe(false)
})
it('falls back when the candidate cannot be read as an executable file', async () => {
const { source, destination, hash } = fixture()
rmSync(source)
mkdirSync(source)
expect(await copyPinnedNodeExecutable(source, destination, hash)).toBe(false)
expect(existsSync(destination)).toBe(false)
})