-
Notifications
You must be signed in to change notification settings - Fork 3k
refactor(review): share the probe-worktree path helper; harden the stale-tree sweep #6841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
555d549
refactor(review): share the probe-worktree path helper; harden the st…
wenshao 2e9f319
fix(review): make releaseWorktree actually remove an unregistered lef…
wenshao 92d7854
refactor(review): apply the leftover-safe sweep to the probe's finall…
wenshao 3f53585
test(review): pin the probe create-failure detail with a pure helper
wenshao 48047ea
fix(review): keep releaseWorktree non-throwing, and keep the discard'…
wenshao 8542b48
fix(review): stop releaseWorktree losing the reason a path survived
wenshao 86e4df1
fix(review): un-strand releaseWorktree's doc; stop "Nothing to clean"…
wenshao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| // `releaseWorktree`'s I/O is pinned against real git in `git.integration.test.ts`. | ||
| // What is pinned here is the one outcome real git cannot produce on demand: the | ||
| // path was there, and we could NOT free it. That needs `rmSync` to hit EPERM or | ||
| // EBUSY, and nothing portable forces those — as root the permission lever is | ||
| // bypassed outright, under CI's unprivileged user it behaves differently, and a | ||
| // `node:fs` module mock does not reach the module under this suite's config. So | ||
| // the ruling is a pure function, and it is tested as one. | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
| import { worktreeReleaseResult } from './git.js'; | ||
|
|
||
| describe('worktreeReleaseResult', () => { | ||
| it('reports a path that was there and is gone now', () => { | ||
| expect(worktreeReleaseResult(true, false)).toEqual({ | ||
| existed: true, | ||
| freed: true, | ||
| reason: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it('reports nothing-to-do without inventing a reason', () => { | ||
| // Nothing was there. Not a failure, so no reason — cleanup should stay quiet | ||
| // rather than announce a removal it did not perform. | ||
| expect(worktreeReleaseResult(false, false)).toEqual({ | ||
| existed: false, | ||
| freed: false, | ||
| reason: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it('carries the rmSync error out when the path survived', () => { | ||
| // The outcome a boolean return could not express, and the one that made | ||
| // cleanup either lie ("Removed …") or go silent — both were shipped here and | ||
| // caught in review. `existed && !freed` must arrive with the WHY attached: | ||
| // someone has to delete this tree by hand. | ||
| const got = worktreeReleaseResult( | ||
| true, | ||
| true, | ||
| new Error("EBUSY: resource busy or locked, rmdir '/w/wt'"), | ||
| ); | ||
| expect(got).toMatchObject({ existed: true, freed: false }); | ||
| expect(got.reason).toContain('EBUSY'); | ||
| }); | ||
|
|
||
| it('names the situation when the path survived with no exception to quote', () => { | ||
| // `rmSync` returned cleanly and the path is still there anyway. There is no | ||
| // errno to hand over, but `reason` must not come back undefined — a silent | ||
| // "still there" is exactly the failure mode being fixed. | ||
| const got = worktreeReleaseResult(true, true); | ||
| expect(got).toMatchObject({ existed: true, freed: false }); | ||
| expect(got.reason).toMatch(/still there/); | ||
| }); | ||
|
|
||
| it('stringifies a non-Error throw rather than dropping it', () => { | ||
| expect(worktreeReleaseResult(true, true, 'boom').reason).toBe('boom'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.