Skip to content

test(runtime): isolate per-repo worktree scan expiry from the shared timer queue - #22575

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-pr22564-worktree-scan
Sep 24, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-pr22564-worktree-scan

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​11
Prod 0 0 0 0

ELI5

A unit test that checks each repo's worktree list expires on its own was sometimes failing in CI because it also counted a scan from a different test.

What Changed

The test still checks that a 30 second cache expires for one repo while its sibling stays cached. It no longer does that by running every pending timer in the process.

Before, moving the clock forward also ran timers left behind by earlier tests in the same file. One of those timers listed a different repo (/tmp/repo) and the assertion saw four scans instead of three. On a machine where that path is a real git repo, the same test could also skip the rescan, because an unchanged admin fingerprint is allowed to extend the cache.

After, the clock is set directly, the fingerprint check is stubbed so it cannot prove the repo unchanged, and the assertion is the exact scan order: repo A, repo B, repo A again.

Why

The cache already stores an expiry per repo. The flake was the test driving that check by flushing the shared timer queue, which is full of unrelated work by the time this case runs. Setting the clock, and stubbing the fingerprint, measures the expiry rule without those side paths. Counting only this case's paths would still pass if the stray scan happened; not running the queue means the stray scan does not happen inside the test.

Linked Issue

No ticket. This is the shard 8 failure on #22564 (expected "vi.fn()" to be called 3 times, but got 4 times).

Visual Proof

N/A. Test-only change; nothing in the app UI changes.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

pnpm exec vitest run src/main/runtime/orca-runtime.test.ts — 1298 passed, 1 skipped. Before the fix, that same file failed this case with an extra /tmp/repo scan at fake time 14s while the clock was being advanced 20s.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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)

…timer queue

The TTL case was advancing every fake timer, so a scan an earlier test
had left scheduled was counted as this repo's rescan.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 1cb251bc-d27b-49ce-b2d3-8c7c374cda94

📥 Commits

Reviewing files that changed from the base of the PR and between 4bab736 and bdc99ef.

📒 Files selected for processing (1)
  • src/main/runtime/orca-runtime-tests/lineage-and-scan-cache-part-03.spec.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The scan-expiration test now stubs readRepoWorktreeAdminFingerprint to return null and uses system-time changes instead of advancing fake timers. It verifies fingerprint reads and checks that scans run for repo A, repo B, then repo A again. The test restores the fingerprint spy during cleanup.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to bdc99

The updated test checks repository scan expiry without a demonstrated merge-blocking issue.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, change, rationale, testing, and UI impact. However, it does not provide the required linked issue. It states "No ticket" even though the template requires an issu… Add the required issue reference, such as Fixes #22564``, and retain the relevant failure details if needed.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the test change and its purpose: isolating per-repository worktree scan expiry from unrelated timers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, change, rationale, testing, and UI impact. However, it does not provide the required linked issue. It states "No ticket" even though the template requires an issue link.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes — one test-only file, the worktree scan cache: expires scans per repo without coupling sibling repos case in lineage-and-scan-cache-part-03.spec.ts.

  • Clock-driven expiry instead of timer flush — swaps vi.advanceTimersByTimeAsync for vi.setSystemTime, so the case no longer flushes the shared fake-timer queue that earlier orca-runtime-tests parts share through orca-runtime.test.ts. Detects the reported /tmp/repo extra scan without running unrelated timers.
  • Fingerprint stub — vi.spyOn(readRepoWorktreeAdminFingerprint).mockResolvedValue(null) (restored in finally) so a real git dir under /tmp/repo-a//tmp/repo-b cannot prove "unchanged" and skip the rescan at the boundary.
  • Stricter assertion — replaces toHaveBeenCalledTimes(3) + nth(3, '/tmp/repo-a') with the exact scan order ['/tmp/repo-a', '/tmp/repo-b', '/tmp/repo-a'].

The change is sound: the cache checks expiresAt > Date.now() at read time (orca-runtime-list-known-resolved-worktrees-for-explicit-target.ts:159), so setting the clock expires the entry without a scheduled timer; the strict order would fail if the per-repo TTL regressed or the TTL moved off 30s in either direction; and vi.useRealTimers() in finally discards any stragglers rather than leaking them. Verified locally via pnpm exec vitest run src/main/runtime/orca-runtime.test.ts -t "expires scans per repo without coupling sibling repos" (passed).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025
brennanb2025 merged commit 7216d5a into main Sep 24, 2026
31 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.

1 participant