Skip to content

Fix code-review findings: safer deletes, plus smaller bugs - #3

Merged
devloop01 merged 2 commits into
mainfrom
claude/kind-newton-7v2sgz
Nov 13, 2026
Merged

devloop01 merged 2 commits into
mainfrom
claude/kind-newton-7v2sgz

Conversation

@devloop01

Copy link
Copy Markdown
Owner

Fixes from a code review of the last commit and then of the whole codebase.

Could delete the wrong thing

  • Forgeable candidates. The exported sweep.At let any caller build a Candidate that Remove accepts without Scan's checks. It is now a test-only helper (at), and a new test checks that a candidate not from Scan is refused even when its path passes Vet.
  • Empty DIR. sweep -y "$UNSET" was read as the current folder. Resolve now refuses an empty path.
  • Inherited git environment. With GIT_DIR / GIT_WORK_TREE / GIT_INDEX_FILE set (hooks, rebase --exec, a dotfiles shell), git answered for another repo, so a folder with tracked files looked disposable. git now runs without the repo-local variables (the list from git rev-parse --local-env-vars).
  • Nested checkouts. A target with its own .git (a nested clone, a worktree) inside an ignored build/, out/ or dist/ was treated as build output. Any target with its own .git entry is now kept.
  • Volume mounted after the scan. Scan drops targets with another volume mounted inside, but Remove didn't re-check. It now does, right before deleting.

Smaller bugs

  • /dev/null counted as a terminal, so sweep > /dev/null opened the interactive screen. isTerminal now asks for terminal settings, like isatty.
  • A build whose version is a bare commit hash (make build in a clone without tags) was told to upgrade on every run, and sweep upgrade replaced it. Versions without vX.Y.Z numbers are now treated like dev.
  • A target that vanished between being found and measured was listed as a 0.0 KB row that could never be deleted. It is no longer listed.
  • The scan status line could be cut inside the … at 10–11 columns.

Speed

Targets in one folder are put to git together, so a project's node_modules, .next and dist cost two git runs instead of five. The questions asked of git are unchanged, and keep goes through the same code as the batch. The re-check before each delete still asks per folder, on purpose. This is not full per-repo batching.

Not changed

The review also flagged that q / ctrl+c only close the ? key list instead of quitting. That is the documented behaviour ("Press any key to close") and TestScreenHelpAndReveal asserts it, so it is left as is.

Testing

The code only builds on darwin/arm64 and this was written on Linux, so the suite has not been run on macOS. What was done:

  • GOOS=darwin GOARCH=arm64 go vet ./... passes (code and tests compile).
  • The full suite passes on Linux in a copy with the build tags and two ioctl constants swapped.
  • The two mount tests pass there with tmpfs standing in for hdiutil.
  • The new git-environment, nested-checkout and mount tests each fail when their fix is disabled.

Please run make test on a Mac before merging. TestDevNullIsNotATerminal and the hdiutil mount tests are the ones that exercise macOS-specific code.


Generated by Claude Code

…y helper

The exported At let any caller build a Candidate that Remove accepts
without Scan's checks, such as the one for a volume mounted inside a
target. It is now a helper in the package's tests that fails on a
folder it can't read.

Tests ask Vet directly about each trap, and a new one checks that a
candidate not from Scan is refused even when its path passes Vet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D9oJWw4k81eBvUNWWQjoMK
…aller bugs

Could delete the wrong thing:
- An empty DIR (a script's unset variable) was read as the current folder.
- git was run with the inherited GIT_DIR / GIT_INDEX_FILE, so from a hook
  or a dotfiles shell it answered for another repo and tracked folders
  looked disposable.
- A target with its own .git (a nested clone, a worktree) in an ignored
  build/ was treated as build output.
- A volume mounted inside a listed folder after the scan was emptied.

Smaller:
- /dev/null counted as a terminal, so sweep > /dev/null opened the screen.
- A build whose version is a bare commit hash was told to upgrade on every
  run, and sweep upgrade replaced it.
- A target that vanished during the scan was listed as a 0.0 KB row that
  could never be deleted.
- The scan status line could be cut inside the … on a very narrow terminal.

Faster: targets in one folder are put to git together, so a project's
node_modules, .next and dist cost two git runs instead of five. The
re-check before each delete still asks per folder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D9oJWw4k81eBvUNWWQjoMK
@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e670c81

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devloop01
devloop01 merged commit 16f79e1 into main Nov 13, 2026
1 check passed
devloop01 pushed a commit that referenced this pull request Nov 13, 2026
…anges)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D9oJWw4k81eBvUNWWQjoMK
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.

2 participants