Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 85 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
package: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.package }}
package_windows: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.package_windows }}
layout_oracle: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.layout_oracle }}
verify_fast_path: ${{ steps.verify_fast_path.outputs.canonical }}
e2e_should_run: ${{ steps.e2e_filter.outputs.should_run }}
test_files: ${{ steps.e2e_filter.outputs.test_files }}
e2e_run_changed: ${{ steps.e2e_filter.outputs.e2e_run_changed }}
Expand Down Expand Up @@ -136,6 +137,33 @@ jobs:
fi
printf '%s\n' "$CHANGED" | node config/scripts/pr-code-change-scope.mjs "${MOBILE_CI_ARGS[@]}" | tee -a "$GITHUB_OUTPUT"

# Actions comparisons ignore case; validate exact routing before allowing a skipped gate.
- name: Validate aggregate routing
id: verify_fast_path
env:
STATIC_ANALYSIS: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.static_analysis }}
TYPECHECK: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.typecheck }}
GIT_COMPATIBILITY: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.git_compatibility }}
CODEX_INDEX_HEAL_CONTRACT: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.codex_index_heal_contract }}
XTERM_PATCH_SYNC: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.xterm_patch_sync }}
SHELL_CONTRACTS: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.shell_contracts }}
TEST: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.test }}
MOBILE_WEB_APP: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.mobile_web_app }}
CROSS_VERSION_WIRE: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.cross-version-wire }}
MANAGED_HOOK_NODE18: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.managed_hook_node18 }}
PACKAGE: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.package }}
PACKAGE_WINDOWS: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.package_windows }}
LAYOUT_ORACLE: ${{ steps.readiness.outputs.reused != 'true' && steps.filter.outputs.layout_oracle }}
run: |
canonical=1
for selected in "$STATIC_ANALYSIS" "$TYPECHECK" "$GIT_COMPATIBILITY" "$CODEX_INDEX_HEAL_CONTRACT" "$XTERM_PATCH_SYNC" "$SHELL_CONTRACTS" "$TEST" "$MOBILE_WEB_APP" "$CROSS_VERSION_WIRE" "$MANAGED_HOOK_NODE18" "$PACKAGE" "$PACKAGE_WINDOWS" "$LAYOUT_ORACLE"; do
case "$selected" in
true|false) ;;
*) canonical=0 ;;
esac
done
echo "canonical=$canonical" >> "$GITHUB_OUTPUT"

# Reuse the path-detector checkout instead of queuing another runner.
- name: Filter changed E2E specs
id: e2e_filter
Expand Down Expand Up @@ -1499,7 +1527,62 @@ jobs:

verify:
name: PR checks passed
if: ${{ !cancelled() }}
# GitHub accepts skipped required jobs; only mismatches need a runner to fail with details.
if: >-
!cancelled() && !(
needs.code_paths.result == 'success' &&
needs.code_paths.outputs.verify_fast_path == '1' &&
(needs.code_paths.outputs.static_analysis == 'true' || needs.code_paths.outputs.static_analysis == 'false') &&
(needs.code_paths.outputs.typecheck == 'true' || needs.code_paths.outputs.typecheck == 'false') &&
(
((needs.code_paths.outputs.static_analysis == 'true' || needs.code_paths.outputs.typecheck == 'true') && needs.preflight.result == 'success') ||
(needs.code_paths.outputs.static_analysis == 'false' && needs.code_paths.outputs.typecheck == 'false' && needs.preflight.result == 'skipped')
) &&
(
(needs.code_paths.outputs.git_compatibility == 'true' && needs.git_compatibility.result == 'success') ||
(needs.code_paths.outputs.git_compatibility == 'false' && needs.git_compatibility.result == 'skipped')
) &&
(
(needs.code_paths.outputs.codex_index_heal_contract == 'true' && needs.codex_index_heal_contract.result == 'success') ||
(needs.code_paths.outputs.codex_index_heal_contract == 'false' && needs.codex_index_heal_contract.result == 'skipped')
) &&
(
(needs.code_paths.outputs.xterm_patch_sync == 'true' && needs.xterm_patch_sync.result == 'success') ||
(needs.code_paths.outputs.xterm_patch_sync == 'false' && needs.xterm_patch_sync.result == 'skipped')
) &&
(
(needs.code_paths.outputs.shell_contracts == 'true' && needs.shell_contracts.result == 'success') ||
(needs.code_paths.outputs.shell_contracts == 'false' && needs.shell_contracts.result == 'skipped')
) &&
(
(needs.code_paths.outputs.test == 'true' && needs.test.result == 'success') ||
(needs.code_paths.outputs.test == 'false' && needs.test.result == 'skipped')
) &&
(
(needs.code_paths.outputs.mobile_web_app == 'true' && needs.mobile_web_app.result == 'success') ||
(needs.code_paths.outputs.mobile_web_app == 'false' && needs.mobile_web_app.result == 'skipped')
) &&
(
(needs.code_paths.outputs['cross-version-wire'] == 'true' && needs['cross-version-wire'].result == 'success') ||
(needs.code_paths.outputs['cross-version-wire'] == 'false' && needs['cross-version-wire'].result == 'skipped')
) &&
(
(needs.code_paths.outputs.managed_hook_node18 == 'true' && needs.managed_hook_node18.result == 'success') ||
(needs.code_paths.outputs.managed_hook_node18 == 'false' && needs.managed_hook_node18.result == 'skipped')
) &&
(
(needs.code_paths.outputs.package == 'true' && needs.package.result == 'success') ||
(needs.code_paths.outputs.package == 'false' && needs.package.result == 'skipped')
) &&
(
(needs.code_paths.outputs.package_windows == 'true' && needs.package_windows.result == 'success') ||
(needs.code_paths.outputs.package_windows == 'false' && needs.package_windows.result == 'skipped')
) &&
(
(needs.code_paths.outputs.layout_oracle == 'true' && needs.layout_oracle.result == 'success') ||
(needs.code_paths.outputs.layout_oracle == 'false' && needs.layout_oracle.result == 'skipped')
)
)
needs:
- code_paths
- preflight
Expand All @@ -1514,7 +1597,7 @@ jobs:
- package
- package_windows
- layout_oracle
# Evaluating job results only needs the lightweight container runner.
# Only failures and noncanonical routing allocate this runner.
runs-on: ubuntu-slim
timeout-minutes: 5

Expand Down
68 changes: 68 additions & 0 deletions config/scripts/pr-aggregate-gate-context.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { readFileSync } from 'node:fs'
import { Evaluator, Lexer, Parser, data } from '@actions/expressions'
import { parse } from 'yaml'
import { PR_CHECK_JOBS } from './pr-code-change-scope.mjs'

export const aggregateWorkflow = parse(readFileSync('.github/workflows/pr.yml', 'utf8'))
export const aggregateJob = aggregateWorkflow.jobs.verify
export const aggregateShell = aggregateJob.steps.find(
(step) => step.name === 'Require successful checks'
)
export const aggregateMarker = aggregateWorkflow.jobs.code_paths.steps.find(
(step) => step.id === 'verify_fast_path'
)
export const aggregateSelectors = PR_CHECK_JOBS.filter((job) => job !== 'orcad_browser')
export const aggregateRequiredJobs = aggregateJob.needs.filter((job) => job !== 'code_paths')
export const aggregateVariable = (job) => job.replaceAll('-', '_').toUpperCase()

export function compileAggregateExpression(expression, contexts = ['needs']) {
const source = expression.replace(/^\$\{\{\s*|\s*\}\}$/g, '')
const functions = [{ name: 'cancelled', minArgs: 0, maxArgs: 0 }]
const ast = new Parser(new Lexer(source).lex().tokens, contexts, functions).parse()
return (context, cancelled = false) =>
new Evaluator(
ast,
JSON.parse(JSON.stringify(context), data.reviver),
new Map([['cancelled', { ...functions[0], call: () => new data.BooleanData(cancelled) }]])
).evaluate()
}

export const aggregateShouldRun = compileAggregateExpression(aggregateJob.if)
const aggregateEnvironmentExpressions = Object.fromEntries(
Object.entries(aggregateShell.env).map(([name, expression]) => [
name,
compileAggregateExpression(expression)
])
)

export function aggregateEnvironment(needs) {
return Object.fromEntries(
Object.entries(aggregateEnvironmentExpressions).map(([name, evaluate]) => [
name,
evaluate({ needs }).coerceString()
])
)
}

export function aggregateNeeds(selected = 'true', overrides = {}) {
const outputs = {
should_run: 'true',
verify_fast_path: '1',
...Object.fromEntries(aggregateSelectors.map((job) => [job, selected])),
...overrides
}
const needs = {
code_paths: { result: 'success', outputs },
...Object.fromEntries(
aggregateRequiredJobs.map((job) => [
job,
{ result: outputs[job] === 'true' ? 'success' : 'skipped' }
])
)
}
needs.preflight.result =
aggregateEnvironmentExpressions.PREFLIGHT_SHOULD_RUN({ needs }).coerceString() === 'true'
? 'success'
: 'skipped'
return needs
}
202 changes: 202 additions & 0 deletions config/scripts/pr-aggregate-gate.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import { describe, expect, it } from 'vitest'
import {
aggregateJob,
aggregateMarker,
aggregateNeeds,
aggregateRequiredJobs,
aggregateSelectors,
aggregateShell,
aggregateShouldRun,
aggregateVariable,
aggregateWorkflow,
compileAggregateExpression
} from './pr-aggregate-gate-context.mjs'

const results = ['success', 'failure', 'cancelled', 'skipped', '', 'unknown', undefined, null]
const malformedSelectors = [
'',
'TRUE',
'True',
'FALSE',
'0',
'1',
'null',
'unknown',
' true',
'true\n',
undefined,
null
]
const admitted = (needs, cancelled = false) =>
aggregateShouldRun({ needs }, cancelled).coerceString() === 'true'

describe('runner-free PR aggregate success', () => {
it('keeps every required dependency and the existing failure reporter', () => {
expect(aggregateJob.name).toBe('PR checks passed')
expect(aggregateJob.needs).toEqual([
'code_paths',
'preflight',
...aggregateSelectors.filter((job) => job !== 'static_analysis' && job !== 'typecheck')
])
for (const job of ['e2e', 'terminal_ime_native', 'windows_wsl', 'unit_selection_evidence']) {
expect(aggregateJob.needs).not.toContain(job)
}
expect(aggregateJob['continue-on-error']).toBeUndefined()
expect(aggregateShell['continue-on-error']).toBeUndefined()
expect(aggregateJob.if).toMatch(/^!cancelled\(\) && !\(/)
expect(aggregateShell.run).toContain('"$CODE_PATHS" != "success"')
const checked = [...aggregateShell.run.matchAll(/^check_job (\S+) /gm)].map((match) => match[1])
expect(checked).toEqual(aggregateRequiredJobs)
})

it('validates the same effective selectors the detector publishes, after readiness and classification', () => {
const detector = aggregateWorkflow.jobs.code_paths
expect(Object.keys(aggregateMarker.env).sort()).toEqual(
aggregateSelectors.map(aggregateVariable).sort()
)
for (const job of aggregateSelectors) {
expect(aggregateMarker.env[aggregateVariable(job)], job).toBe(detector.outputs[job])
}
expect(detector.outputs.verify_fast_path).toBe(
'${{ steps.verify_fast_path.outputs.canonical }}'
)
const position = detector.steps.indexOf(aggregateMarker)
for (const id of ['readiness', 'filter']) {
expect(position).toBeGreaterThan(detector.steps.findIndex((step) => step.id === id))
}
expect(aggregateMarker.if).toBeUndefined()
expect(aggregateMarker['continue-on-error']).toBeUndefined()
})

it('accepts every canonical routing combination without allocating the aggregate runner', () => {
expect(aggregateSelectors).toHaveLength(13)
const failures = []
for (let mask = 0; mask < 2 ** aggregateSelectors.length; mask += 1) {
const selectors = Object.fromEntries(
aggregateSelectors.map((job, index) => [job, mask & (1 << index) ? 'true' : 'false'])
)
if (admitted(aggregateNeeds('false', selectors))) {
failures.push(mask)
}
}
expect(failures).toEqual([])
})

it('requires each job to match its selected or unselected result', () => {
for (const job of aggregateRequiredJobs) {
for (const selected of ['true', 'false']) {
for (const result of results) {
const needs = aggregateNeeds(selected)
needs[job].result = result
const expected = selected === 'true' ? 'success' : 'skipped'
expect(admitted(needs), `${job}/${selected}/${result}`).toBe(result !== expected)
}
}
}
})

it('requires preflight success if either phase is selected', () => {
for (const static_analysis of ['true', 'false']) {
for (const typecheck of ['true', 'false']) {
for (const result of results) {
const needs = aggregateNeeds('false', { static_analysis, typecheck })
needs.preflight.result = result
const selected = static_analysis === 'true' || typecheck === 'true'
const expected = selected ? 'success' : 'skipped'
expect(admitted(needs), `${static_analysis}/${typecheck}/${result}`).toBe(
result !== expected
)
}
}
}
})

it('sends every malformed selector through the unchanged shell', () => {
for (const job of aggregateSelectors) {
for (const selected of malformedSelectors) {
for (const result of results) {
const needs = aggregateNeeds('false', { [job]: selected, verify_fast_path: '0' })
const affected = ['static_analysis', 'typecheck'].includes(job) ? 'preflight' : job
needs[affected].result = result
expect(admitted(needs), `${job}/${selected}/${result}`).toBe(true)
}
}
}
})

it('rejects outputs masked after the canonical-routing marker was emitted', () => {
for (const job of aggregateSelectors) {
for (const selected of ['true', 'false']) {
for (const masked of ['', undefined, null]) {
const needs = aggregateNeeds(selected)
needs.code_paths.outputs[job] = masked
expect(admitted(needs), `${job}/${selected}/${masked}`).toBe(true)
}
}
}
})

it('requires successful detection and a numeric canonical marker', () => {
for (const selected of ['true', 'false']) {
for (const result of results) {
const needs = aggregateNeeds(selected)
needs.code_paths.result = result
expect(admitted(needs), `${selected}/${result}`).toBe(result !== 'success')
}
for (const marker of ['', '0', 'true', 'TRUE', 'unknown', undefined, null]) {
expect(admitted(aggregateNeeds(selected, { verify_fast_path: marker }))).toBe(true)
}
const missing = aggregateNeeds(selected)
delete missing.code_paths.outputs
expect(admitted(missing)).toBe(true)
delete missing.code_paths
expect(admitted(missing)).toBe(true)
}
})

it('preserves workflow cancellation while detecting individually cancelled dependencies', () => {
for (const job of aggregateJob.needs) {
for (const result of results) {
const needs = aggregateNeeds()
needs[job].result = result
expect(admitted(needs, true), `${job}/${result}`).toBe(false)
if (result === 'cancelled') {
expect(admitted(needs, false), job).toBe(true)
}
}
const missing = aggregateNeeds()
delete missing[job]
expect(admitted(missing, false), job).toBe(true)
expect(admitted(missing, true), job).toBe(false)
}
})

it('keeps the informational overall selector independent of the gate', () => {
for (const should_run of ['true', 'false', ...malformedSelectors]) {
for (const selected of ['true', 'false']) {
expect(admitted(aggregateNeeds(selected, { should_run }))).toBe(false)
}
}
})

it('uses Actions case-insensitive equality and preserves readiness output masking', () => {
const compare = compileAggregateExpression("needs.value == 'true'")
expect(compare({ needs: { value: 'TRUE' } }).coerceString()).toBe('true')
for (const job of aggregateSelectors) {
const effective = compileAggregateExpression(aggregateMarker.env[aggregateVariable(job)], [
'steps'
])
for (const reused of ['true', 'TRUE', 'false', '', undefined]) {
for (const selected of ['true', 'false', ...malformedSelectors]) {
const context = {
steps: { readiness: { outputs: { reused } }, filter: { outputs: { [job]: selected } } }
}
const masked = reused?.toLowerCase() === 'true'
expect(effective(context).coerceString(), `${job}/${reused}/${selected}`).toBe(
masked ? 'false' : (selected ?? '')
)
}
}
}
})
})
Loading
Loading