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
2 changes: 2 additions & 0 deletions config/scripts/check-changed.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Data Integrity & Integration · Quick win

Supported by static analysis

Script executed:

sed -n '275,320p' config/scripts/check-changed.mjs
rg -n 'spawn|env:|ORCA_CODE_QUALITY_BASE|ORCA_CHANGED_MERGE_BASE' config/scripts/check-changed.mjs

Repository: stablyai/orca

Length of output: 2131


Support both base variables without changing check:changed precedence.

The standalone command sets ORCA_CHANGED_MERGE_BASE, but the ratchet reads only ORCA_CODE_QUALITY_BASE and otherwise uses origin/main. Add the documented variable after ORCA_CODE_QUALITY_BASE, so an inherited value cannot override check:changed's resolved base.

Suggested fix
-    const requested = process.env.ORCA_CODE_QUALITY_BASE || 'origin/main'
+    const requested =
+      process.env.ORCA_CODE_QUALITY_BASE || process.env.ORCA_CHANGED_MERGE_BASE || 'origin/main'

Keep the fallback test clear of both base variables.

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ORCA_CODE_QUALITY_BASE: mergeBase,
ORCA_CODE_QUALITY_BASE: mergeBase,
ORCA_CHANGED_MERGE_BASE: mergeBase,

...(process.stdout.isTTY ? { FORCE_COLOR: '1' } : {})
}
if (
Expand Down
3 changes: 2 additions & 1 deletion config/scripts/check-flaky-test-pattern-ratchet.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 46 additions & 2 deletions config/scripts/check-flaky-test-pattern-ratchet.test.mjs
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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'
Comment on lines +54 to +56

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Stability & Availability · Quick win

Clear inherited Git repository variables for the fixture.

If a Git hook starts this test with GIT_DIR or related variables set, cwd: fixture does not ensure that Git uses the temporary repository. The fixture commands can target the caller’s repository instead, and the test can fail or alter its index. Clear repository-location variables for both the fixture commands and the listChangedFiles calls, then restore the test environment. Git documents this requirement for commands run against a different repository. (git-scm.com)

Based on learnings, Git subprocesses targeting temporary repositories must clear inherited repository-location variables.

Source: Learnings

}).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'])
})
})
Loading