Files
orca/config/scripts/ci-unit-plan.test.mjs
T
Neil f8f656ca19 perf(ci): spend fewer concurrency slots per pull request (#23810)
A concurrency slot is charged per job, not per core, and the account's cap is
the scarce resource: standard runner minutes are free and unlimited on a public
repository. Two paths spent slots that bought nothing.

The unit matrix ran eight fixed shards averaging 6.5 minutes each, 3384
job-slots a day and 68% of all slot demand, while the arm pool queued 10.5
minutes at p95 — the queue was the oversharding. Five shards run the same work
in ~10.5 minutes each for three fewer slots per run.

Bun profile persistence escalated to all six platforms on `config/`,
`resources/` and `.github/` wholesale, which took 36.5% of the last 1100
commits through the full matrix where a platform-flavoured predicate takes 19%.
A pull request now qualifies one platform unless the change is platform-
flavoured, and the push to main re-qualifies all six, so an unescalated miss
surfaces minutes after merge rather than at the next cron. Missing changed-file
evidence and an unavailable dependency graph still fail closed to all six.
2026-09-29 00:13:33 -07:00

80 lines
2.9 KiB
JavaScript

import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { expect, it } from 'vitest'
import { runProcessSync } from './script-child-process.mjs'
import { FULL_SHARD_COUNT } from './ci-unit-selection.mjs'
it.each([true, false])(
'plans from a real Git diff, with parent evidence available: %s',
(withParent) => {
const root = mkdtempSync(join(tmpdir(), 'orca-unit-plan-'))
const git = (args) => {
const result = runProcessSync({ program: 'git', args, cwd: root })
expect(result.code, result.stderr).toBe(0)
return result.stdout.trim()
}
try {
mkdirSync(join(root, 'src'))
writeFileSync(join(root, 'src/value.ts'), 'export const value = 1')
writeFileSync(join(root, 'src/consumer.test.ts'), "import './value'")
writeFileSync(join(root, 'src/unrelated.test.ts'), 'export const unrelated = true')
git(['init', '--quiet'])
git(['add', 'src'])
const commit = [
'-c',
'user.name=CI Test',
'-c',
'user.email=ci-test@example.invalid',
'-c',
'commit.gpgsign=false',
'commit',
'--quiet',
'-m',
'fixture'
]
git(commit)
if (withParent) {
writeFileSync(join(root, 'src/value.ts'), 'export const value = 2')
git(['add', 'src'])
git(commit)
}
const sourceSha = git(['rev-parse', 'HEAD'])
const eventPath = join(root, 'event.json')
writeFileSync(eventPath, JSON.stringify({ pull_request: { draft: true } }))
const result = runProcessSync({
program: process.execPath,
args: [fileURLToPath(new URL('./ci-unit-plan.mjs', import.meta.url))],
cwd: root,
env: {
...process.env,
ORCA_BACKGROUND_LAUNCH: '1',
ORCA_UNIT_SELECTION_MODE: 'selected',
GITHUB_EVENT_NAME: 'pull_request',
GITHUB_EVENT_PATH: eventPath,
GITHUB_SHA: sourceSha,
ORCA_SHARD_SOURCE_SHA: sourceSha,
GITHUB_OUTPUT: join(root, 'outputs'),
GITHUB_STEP_SUMMARY: join(root, 'summary')
}
})
expect(result.code, result.stderr).toBe(0)
const plan = JSON.parse(readFileSync(join(root, 'ci-shards/unit-selection.json'), 'utf8'))
expect(plan.sourceSha).toBe(sourceSha)
expect(plan.mode).toBe(withParent ? 'selected' : 'shadow')
expect(plan.executionFiles).toEqual(
withParent ? ['src/consumer.test.ts'] : ['src/consumer.test.ts', 'src/unrelated.test.ts']
)
expect(plan.reason).toBe(
withParent
? 'Transitive imports plus indirect-input consumers'
: 'Error: Changed paths unavailable'
)
expect(plan.shards).toHaveLength(withParent ? 1 : FULL_SHARD_COUNT)
} finally {
rmSync(root, { recursive: true, force: true })
}
}
)