Skip to content

fix(scripts): scope the flaky-test ratchet to check:changed's --base merge base - #33782

Merged
nwparker merged 1 commit into
stablyai:mainfrom
eatmoreduck:fix/33763-changed-base-ratchet
Oct 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
eatmoreduck:fix/33763-changed-base-ratchet

Conversation

@eatmoreduck

@eatmoreduck eatmoreduck commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

pnpm check:changed --base=upstream/main is supposed to check only your changes against the branch you named. One of its sub-checks, the flaky-test ratchet, ignored that and compared against origin/main anyway. If your origin is an older fork, that pulled in a pile of files you never touched, and the run could fail on them. Now the ratchet compares against the same base as everything else.

What Changed

  • Before: check-changed.mjs turned --base=<ref> into a merge base and used it for the gates it runs itself. The ratchets run as separate pnpm run check:<name> subprocesses, though, and listChangedFiles() in check-flaky-test-pattern-ratchet.mjs ran its own git merge-base HEAD origin/main. On a fork checkout with an old origin/main, its scope included unrelated upstream files.
  • After: check:changed puts its resolved merge base in ORCA_CODE_QUALITY_BASE in the env it passes to every subprocess. That variable is already the base override that check-changed-code-quality.mjs and check-react-doctor-changed.mjs read. The ratchet's listChangedFiles() now takes its merge base from ORCA_CODE_QUALITY_BASE and falls back to origin/main when it isn't set. Run on its own (for example from pnpm lint), the ratchet behaves as before.

Why

This reuses the base-override env var the other changed-code gates already honor, so we don't add a second one (ORCA_CHANGED_MERGE_BASE, as the original version did). Passing --base as a CLI argument wouldn't fit: the ratchet's only positional argument is already update, and the ratchets are spawned generically from plan.checks. Guessing other refs (such as upstream/main) was ruled out too. Using a ref nobody asked for is the same kind of surprise this bug is about.

Linked Issue

Fixes #33763

Visual Proof

N/A. This only changes developer tooling scripts, so there's no UI or visible app behavior. The regression test below covers the behavior change directly.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New regression test in check-flaky-test-pattern-ratchet.test.mjs. It builds a throwaway git repo whose origin/main sits behind an upstream commit. With no override, the scope includes both the upstream-drift file and the contribution. With ORCA_CODE_QUALITY_BASE set to the upstream commit, the scope is only the contribution.

  • pnpm test config/scripts/check-flaky-test-pattern-ratchet.test.mjs config/scripts/check-changed*: 4 files and 49 tests pass.

  • Static gates on the touched files are clean: anti-slop oxlint, native code-quality oxlint, ast-grep, check-changed-code-quality.mjs, and oxfmt.

  • Platforms: macOS arm64. The change is plain Node and git plumbing with no platform-specific paths.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: the env var is only read inside the process tree that check:changed spawns. No new external input.
  • Cross-platform: pure Node script change.
  • Remote/SSH/mobile: not affected, since this is local dev tooling only.
  • Backwards compatibility: without the env var, the ratchet's standalone behavior is unchanged.
  • Performance: no extra git calls.

Original fix by @eatmoreduck in #33782. Maintainer follow-up switched to the existing ORCA_CODE_QUALITY_BASE override and made the test hermetic.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The changed-file check now passes its resolved merge base to subprocesses through ORCA_CODE_QUALITY_BASE. The flaky-test ratchet uses that value when set and otherwise uses origin/main. A new test checks both cases using a Git fixture with a stale origin/main reference.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Low · up to 156bb

The reported standalone ratchet command can check the wrong files, and the test fixture may fail or touch another repository when Git location variables are inherited. The main check:changed path remains functional; these bounded issues should be fixed or explicitly accepted before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: aligning the flaky-test ratchet with check:changed's resolved base.
Description check Passed The description covers the required sections, linked issue, behavior before and after, rationale, testing, platform considerations, and checklist status. It is sufficiently complete despite the full r…
Linked Issues check Passed Issue #33763 requires the flaky-test ratchet to use the base selected by check:changed --base=<ref>. The PR sets ORCA_CODE_QUALITY_BASE to the resolved merge base for spawned checks. `listChangedF…
Out of Scope Changes check Passed The changes are limited to base forwarding, ratchet base selection, and focused regression coverage. Each change supports issue #33763. No unrelated change is established.
Full details: Description check

Explanation

The description covers the required sections, linked issue, behavior before and after, rationale, testing, platform considerations, and checklist status. It is sufficiently complete despite the full repository command checklist remaining unchecked because CI may cover it.

Full details: Linked Issues check

Explanation

Issue #33763 requires the flaky-test ratchet to use the base selected by check:changed --base=&lt;ref&gt;. The PR sets ORCA_CODE_QUALITY_BASE to the resolved merge base for spawned checks. listChangedFiles() reads that variable and retains origin/main as the standalone fallback. The regression test verifies that a stale origin/main includes upstream drift, while the forwarded base includes only the contribution.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments: 1
config/scripts/check-flaky-test-pattern-ratchet.test.mjs: 1

56-56: Trivial · Maintainability & Code Quality · Heavy lift

Make the base-selection tests deterministic.

The first test distinguishes the bases in this checkout, but it relies on the live repository state. It does not guarantee different file sets in every test checkout. The second test does not clear ORCA_FLAKY_TEST_RATCHET_ALL and accepts null; an inherited override can therefore bypass base selection.

Use a controlled Git fixture with different expected file sets for HEAD and the fallback base. Clear ORCA_FLAKY_TEST_RATCHET_ALL in the fallback test. The first test already clears it.


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 10788bb6-b6c7-4260-a3bc-2fd4142250f6
Commits

Reviewing files that changed from the base of the PR and between 44ac5e2 and e48a08b.

Files selected for processing: 3
  • config/scripts/check-changed.mjs
  • config/scripts/check-flaky-test-pattern-ratchet.mjs
  • config/scripts/check-flaky-test-pattern-ratchet.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@eatmoreduck

Copy link
Copy Markdown
Contributor Author

Addressed the fallback-test gap in cfb9f74 — it now clears ORCA_FLAKY_TEST_RATCHET_ALL alongside the base var, so an inherited override can no longer bypass base selection and pass vacuously.

On determinism for the first test: it compares the ratchet's scope against an independently recomputed git diff over the same base, so it cannot false-pass through checkout drift — and the two paths genuinely diverge in both live states (an empty working tree makes the env path return an empty set while the origin/main path returns the full fork delta; a dirty tree recomputes both sides from the same state). A dedicated git fixture would pin the states further, but for these two properties the live-repo assertion is already discriminating in either checkout shape, so I kept it light rather than adding fixture scaffolding to the scripts test suite.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c775bde5-7a58-4ce1-a5ab-df74adc4ad79
Commits

Reviewing files that changed from the base of the PR and between e48a08b and cfb9f74.

Files selected for processing: 1
  • config/scripts/check-flaky-test-pattern-ratchet.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

…d base

check:changed --base=<ref> resolved a merge base for the gates it drives
directly, but the flaky-test ratchet subprocess re-derived its scope from
origin/main. On a checkout whose origin is a stale fork that pulled in
unrelated files and could fail the run. check:changed now forwards its
merge base via ORCA_CODE_QUALITY_BASE (the env the other changed-code
gates already honor), and the ratchet uses it before falling back to
origin/main.

Fixes stablyai#33763

Co-authored-by: yu.xia <yuxianice@163.com>
@nwparker
nwparker force-pushed the fix/33763-changed-base-ratchet branch from 5f57251 to 156bbcd Compare October 27, 2026 08:52
@nwparker nwparker changed the title fix(scripts): scope the flaky-test ratchet to check:changed's resolved base fix(scripts): scope the flaky-test ratchet to check:changed's --base merge base Oct 27, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9af9de5b-f3bd-407a-9ed4-ec7cb9e2e798
Commits

Reviewing files that changed from the base of the PR and between 5f57251 and 156bbcd.

Files selected for processing: 3
  • config/scripts/check-changed.mjs
  • config/scripts/check-flaky-test-pattern-ratchet.mjs
  • config/scripts/check-flaky-test-pattern-ratchet.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

...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,

Comment on lines +54 to +56
execFileSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@example.com', ...args], {
cwd: fixture,
encoding: 'utf8'

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

@nwparker
nwparker merged commit b13bc4f into stablyai:main Oct 27, 2026
56 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: check:changed --base is not passed to the flaky-test ratchet

2 participants