Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.

fix(baseline): Retry the removal of the tests' scratch directories - #306

Merged
mpaulosky merged 2 commits into
mainfrom
chore/retry-git-scratch-cleanup
Oct 26, 2026
Merged

mpaulosky merged 2 commits into
mainfrom
chore/retry-git-scratch-cleanup

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

Why

dotfiles#304's Template tests run failed once with ENOTEMPTY: directory not empty, rmdir '.git/objects/pack' in checkpoint.test.mts ("lets a branch that leaves the gate script alone through"), and passed on a rerun. The test removes its scratch git repository with a bare rmSync(dir, { recursive: true, force: true }) while git may still be writing into it (background maintenance after a commit). Every assertion in the test had passed; the failure was in the cleanup.

What changed

  • The cleanup: all 39 recursive rmSync calls in the Owned lib/ modules (checkpoint.test.mts, host-safety.test.mts, scan.test.mts, shell.test.mts, review-ledger.test.mts, git-sandbox-fake.mts) now pass maxRetries: 5, retryDelay: 100, which rmSync uses to retry ENOTEMPTY. dotfiles' root copies match.
  • The guard: a dotfiles-only test in template.test.mts fails when a recursive rmSync in those modules lacks maxRetries, and when its scan finds no call at all.
  • The other rmSync uses (review-ledger.mts, one test) delete single files with { force: true } and need no retries.

Verification

  • test.sh passes; check:sandcastle passes (2029 tests, no failures).
  • With one site left bare the new check fails; with the scan broken it fails with "the scan checks nothing".
  • Local /pre-push-review: 2 rounds, one Advisory finding (the guard passing without checking anything), fixed; nothing open.
  • A race can't be reproduced on demand, so the fix is the retry plus the guard that keeps a bare call from coming back.
  • Other repos get the retried cleanup on their next re-Apply.

🤖 Generated with Claude Code

mpaulosky and others added 2 commits October 26, 2026 13:07
A test removes its scratch git repository while git may still be writing into it,
which failed a bare recursive rmSync with ENOTEMPTY ('.git/objects/pack') and
turned a green Template tests run red. Every recursive rmSync in the Owned lib/
modules now passes maxRetries and retryDelay, and a check fails on a bare one.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@mpaulosky mpaulosky added the review:claude Review with Claude label Oct 26, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Review

Overview

This PR adds maxRetries: 5, retryDelay: 100 to every recursive rmSync that removes a scratch directory in the Owned Sandcastle test files and in git-sandbox-fake.mts. It makes the same change in dotfiles' root copies and in the Template's copies, so test.sh's cmp drift check stays green. It also adds a guard test in template.test.mts that scans the Owned lib/*.mts files for any recursive rmSync without maxRetries. I found nothing that should block the merge.

I read the diff and the changed files at the PR's head. The pairs of copies hold identical hunks, and I saw no site where only one copy changed. I did not run the tests. The Advisory items below are the leftovers I'd consider.

Changes

File What changed
.sandcastle/lib/git-sandbox-fake.mts and its Template Owned copy cleanup() removes its scratch root with maxRetries: 5, retryDelay: 100.
.sandcastle/lib/{checkpoint,host-safety,review-ledger,scan,shell}.test.mts and their Template Owned copies Every recursive rmSync in a finally or afterEach now passes maxRetries: 5, retryDelay: 100. The edits are mechanical and the copies match.
.sandcastle/lib/template.test.mts (dotfiles-only) New test that reads each Owned lib/**/*.mts file, matches rmSync(... recursive: true ...) calls, and fails if any lacks maxRetries. It asserts at least one call was found, so it can't pass by checking nothing.

Advisory (not blocking)

  • Guard scope gap: the scan only covers owned/.sandcastle/lib. dotfiles' own template.test.mts still has a bare rmSync(scratch, { recursive: true, force: true }) in its after hook. That directory holds only copied sources and a symlink, and no git runs in it, so the ENOTEMPTY risk is low. The same applies to any other dotfiles-only test file.
  • Async removal not covered: the scan doesn't see fs.rm or fs/promises rm with recursive: true.
  • Regex edge case: /rmSync\([^;]*?recursive: true[^;]*?\)/ stops at the first ) after recursive: true. An option written as retryDelay: delay(), maxRetries: 5 would be reported as a false positive. A bare rmSync(x) with no semicolon before a later recursive: true could also match across the two. This is unlikely in this code.
  • Retry behaviour assumed: I'm relying on Node's rmSync retrying ENOTEMPTY when maxRetries is set. That is documented for fs.rmSync. I haven't confirmed it for the Node version CI uses, in case a newer native rmSync path handles retries differently.
  • Masked test failures: rmSync still runs in finally blocks. If it throws after the retries, that error replaces the test's own assertion failure. This was already the case before the PR.

No findings.

@mpaulosky
mpaulosky merged commit c227f13 into main Oct 26, 2026
5 checks passed
@mpaulosky
mpaulosky deleted the chore/retry-git-scratch-cleanup branch October 26, 2026 20:20
mpaulosky added a commit to mpaulosky/Blazor-Server that referenced this pull request Oct 26, 2026
## Why

Re-Apply the repo-ci-baseline Template so this repo carries the Template
changes from mpaulosky/dotfiles#303, mpaulosky/dotfiles#304,
mpaulosky/dotfiles#305 and mpaulosky/dotfiles#306.

## What changed

- `6af2035` Apply commit, `apply.sh` output alone: brings
mpaulosky/dotfiles#303, mpaulosky/dotfiles#304, mpaulosky/dotfiles#305
and mpaulosky/dotfiles#306.
  - `.github/scripts/post_claude_review.py`
  - `.github/scripts/tests/test_post_claude_review.py`
  - `.github/workflows/claude-review.yml`
  - `.sandcastle/lib/agents.test.mts`
  - `.sandcastle/lib/build.test.mts`
  - `.sandcastle/lib/checkpoint.test.mts`
  - `.sandcastle/lib/git-sandbox-fake.mts`
  - `.sandcastle/lib/host-safety.test.mts`
  - `.sandcastle/lib/plan.test.mts`
  - `.sandcastle/lib/review-ledger.test.mts`
  - `.sandcastle/lib/scan.test.mts`
  - `.sandcastle/lib/shell.test.mts`
  - `.sandcastle/lib/ui-role-fixture.mts` (added)
  - `.sandcastle/lib/ui-role-fixture.test.mts` (added)

## Verification

- The Apply commit is exactly `apply.sh`'s output on a branch up to date
with `main`.
- The pre-push gate (`scripts/gate.sh`) passed on `6af2035`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

review:claude Review with Claude

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant