Files
orca/config/scripts/ci/sharding/ci-unit-sequencer.mjs
T
Neil 9bd6272fdf refactor(tooling): organize build, CI, and test owners (#38130)
* refactor(tooling): organize test runtime and maintenance owners

* test(tooling): preserve relocated runtime fixture dependency edges

* refactor(tooling): preserve xterm routing owner checks

* ci(tooling): include routing owner in sparse checkout

* test(tooling): preserve copied workflow dependency closures

* fix(tooling): normalize hashed JSON assets in release parity

* fix(tooling): distinguish asset aliases from literal references

* fix(tooling): frame normalized asset reference payloads

* fix(tooling): normalize decoded JSON asset references

* refactor(tooling): organize build, CI and release owners

* fix(tooling): align moved generator and workflow path contracts

* fix(tooling): update generated plugin bundle owner banners

* test(tooling): create relocated mobile verifier fixture directories

* test(tooling): copy headless detector dependency closure

* test(tooling): align native batch policy fixtures with owner path

* fix(tooling): link moved reliability command to historical evidence

* fix(tooling): preserve nested sandbox owners and canonical guide source

* fix(tooling): target release version owners in checkout fixture
2026-11-04 21:08:19 -08:00

56 lines
2.1 KiB
JavaScript

import { relative } from 'node:path'
import { readFileSync } from 'node:fs'
import RuntimeSequencer from '../../test-runtime/execution-policy/vitest-runtime-sequencer.mjs'
import { balanceFiles, readTimingBaseline, writeAssignment } from './ci-shard-assignment.mjs'
export default class TimingSequencer extends RuntimeSequencer {
async shard(specs) {
const { index, count } = this.ctx.config.shard
const key = (spec) => relative(this.ctx.config.root, spec.moduleId).replaceAll('\\', '/')
let execution = specs
let selectionReason = 'Full suite: no verified selection plan'
try {
const plan = JSON.parse(
readFileSync(
process.env.ORCA_UNIT_SELECTION_PLAN ?? 'ci-shards/unit-selection.json',
'utf8'
)
)
const discovered = new Set(plan.files)
if (
plan.version !== 1 ||
!plan.sourceSha ||
plan.sourceSha !== process.env.ORCA_SHARD_SOURCE_SHA ||
JSON.stringify([...plan.files].sort()) !== JSON.stringify(specs.map(key).sort()) ||
!Array.isArray(plan.executionFiles) ||
plan.executionFiles.some((file) => !discovered.has(file))
) {
throw new Error('Selection provenance or discovery differs')
}
const allowed = new Set(plan.executionFiles)
if (allowed.size === 0) {
throw new Error('Empty execution selection')
}
execution = specs.filter((spec) => allowed.has(key(spec)))
selectionReason = plan.reason
} catch (error) {
console.log(`Running every discovered unit test: ${error.message}`)
}
const baseline = readTimingBaseline('unit')
const assignment = balanceFiles(
execution.map(key),
count,
baseline.timings,
baseline.overheadMs
)
writeAssignment(process.env.ORCA_SHARD_MANIFEST ?? 'ci-shards/unit-assignment.json', {
...assignment,
baselineSha256: baseline.baselineSha256,
selectedShard: index,
selectionReason
})
const selected = new Set(assignment.shards[index - 1].files)
return specs.filter((spec) => selected.has(key(spec)))
}
}