diff --git a/config/scripts/check-changed.mjs b/config/scripts/check-changed.mjs index 1cef7a30bd1..ed1c49e3218 100644 --- a/config/scripts/check-changed.mjs +++ b/config/scripts/check-changed.mjs @@ -293,6 +293,8 @@ export async function main(root, argv) { const env = { ...process.env, ORCA_BACKGROUND_LAUNCH: '1', + // Why: spawned gates that read the base themselves (flaky-test ratchet) must use --base too. + ORCA_CODE_QUALITY_BASE: mergeBase, ...(process.stdout.isTTY ? { FORCE_COLOR: '1' } : {}) } if ( diff --git a/config/scripts/check-flaky-test-pattern-ratchet.mjs b/config/scripts/check-flaky-test-pattern-ratchet.mjs index 900d18fa67a..4c3e618f81d 100644 --- a/config/scripts/check-flaky-test-pattern-ratchet.mjs +++ b/config/scripts/check-flaky-test-pattern-ratchet.mjs @@ -54,7 +54,8 @@ export function listChangedFiles(root = process.cwd()) { } let base try { - const mergeBase = git(root, ['merge-base', 'HEAD', 'origin/main']).trim() + const requested = process.env.ORCA_CODE_QUALITY_BASE || 'origin/main' + const mergeBase = git(root, ['merge-base', 'HEAD', requested]).trim() base = resolvePullRequestDiffBase(root, mergeBase) } catch { try { diff --git a/config/scripts/check-flaky-test-pattern-ratchet.test.mjs b/config/scripts/check-flaky-test-pattern-ratchet.test.mjs index 39e54fb7c58..fa033892026 100644 --- a/config/scripts/check-flaky-test-pattern-ratchet.test.mjs +++ b/config/scripts/check-flaky-test-pattern-ratchet.test.mjs @@ -1,6 +1,14 @@ -import { describe, expect, it } from 'vitest' +import { execFileSync } from 'node:child_process' +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { afterEach, describe, expect, it, vi } from 'vitest' -import { changedFileScope, countFindings } from './check-flaky-test-pattern-ratchet.mjs' +import { + changedFileScope, + countFindings, + listChangedFiles +} from './check-flaky-test-pattern-ratchet.mjs' describe('countFindings', () => { it('counts each rule per file, folding TSX twins and Windows separators', () => { @@ -32,3 +40,39 @@ describe('changedFileScope', () => { expect(changedFileScope(null)).toBeUndefined() }) }) + +describe('listChangedFiles', () => { + let fixture + afterEach(() => { + vi.unstubAllEnvs() + rmSync(fixture, { recursive: true, force: true }) + }) + + it('scopes to the base check:changed forwards instead of a stale origin/main', () => { + fixture = mkdtempSync(join(tmpdir(), 'flaky-ratchet-base-')) + const git = (...args) => + execFileSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@example.com', ...args], { + cwd: fixture, + encoding: 'utf8' + }).trim() + const commit = (file) => { + writeFileSync(join(fixture, file), file) + git('add', file) + git('-c', 'commit.gpgsign=false', 'commit', '-qm', file) + return git('rev-parse', 'HEAD') + } + git('init', '-q') + git('update-ref', 'refs/remotes/origin/main', commit('fork-base.txt')) + const upstream = commit('upstream-drift.txt') + commit('contribution.txt') + vi.stubEnv('ORCA_FLAKY_TEST_RATCHET_ALL', '') + vi.stubEnv('ORCA_CODE_QUALITY_BASE', '') + + expect([...listChangedFiles(fixture)].sort()).toEqual([ + 'contribution.txt', + 'upstream-drift.txt' + ]) + vi.stubEnv('ORCA_CODE_QUALITY_BASE', upstream) + expect([...listChangedFiles(fixture)]).toEqual(['contribution.txt']) + }) +})