Repository navigation
fix(repos): keep trailing-space directory names that really exist #25446
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
Open
ggbdpq
wants to merge
3
commits into
stablyai:main
Choose a base branch
from
ggbdpq:fix/trailing-space-repo-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+312
−16
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
83 changes: 83 additions & 0 deletions
83
src/main/runtime/runtime-repository-registration-create.test.ts
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,83 @@ | ||
| /** | ||
| * Pins the raw-first parent resolution of RuntimeRepositoryRegistrationController.create: | ||
| * a picker-returned parent with a trailing space (legal POSIX name) must be used as | ||
| * typed when it exists, with the trim kept only for typed typos (#25386). | ||
| */ | ||
|
|
||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' | ||
| import { tmpdir } from 'node:os' | ||
| import { join } from 'node:path' | ||
|
|
||
| const { prepareLocalWorktreeRootForRepoMock, detectRepoIconAndUpstreamMock } = vi.hoisted(() => ({ | ||
| prepareLocalWorktreeRootForRepoMock: vi.fn(async () => undefined), | ||
| detectRepoIconAndUpstreamMock: vi.fn(async () => ({})) | ||
| })) | ||
|
|
||
| vi.mock('../repo-icon-autodetect', () => ({ | ||
| detectRepoIconAndUpstream: detectRepoIconAndUpstreamMock | ||
| })) | ||
|
|
||
| vi.mock('../worktree-root-preparation', () => ({ | ||
| prepareLocalWorktreeRootForRepo: prepareLocalWorktreeRootForRepoMock | ||
| })) | ||
|
|
||
| import { RuntimeRepositoryRegistrationController } from './runtime-repository-registration-controller' | ||
|
|
||
| function makeController(): RuntimeRepositoryRegistrationController { | ||
| return new RuntimeRepositoryRegistrationController({ | ||
| getStore: () => | ||
| // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: create() only reads the repo members stubbed here. | ||
| ({ | ||
| getRepos: () => [], | ||
| addRepo: () => undefined, | ||
| getRepo: () => undefined, | ||
| updateRepo: () => undefined | ||
| }) as never, | ||
| invalidateResolvedWorktrees: () => undefined, | ||
| invalidateWorktreeScan: () => undefined, | ||
| notifyReposChanged: () => undefined | ||
| }) | ||
| } | ||
|
|
||
| describe('RuntimeRepositoryRegistrationController.create parent resolution', () => { | ||
| let base: string | ||
|
|
||
| beforeEach(() => { | ||
| base = mkdtempSync(join(tmpdir(), 'orca-repo-create-')) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| rmSync(base, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| it('creates inside a trailing-space parent that exists exactly as requested', async () => { | ||
| const parent = join(base, 'cloud dir ') | ||
| mkdirSync(parent) | ||
| const result = await makeController().create(parent, 'kid', 'folder') | ||
| expect('error' in result && result.error).toBeFalsy() | ||
| if (!('error' in result)) { | ||
| expect(result.repo.path).toBe(join(parent, 'kid')) | ||
| } | ||
| }) | ||
|
|
||
| it('falls back to the trimmed spelling when the raw parent does not exist', async () => { | ||
| const requested = join(base, 'typo dir ') | ||
| const result = await makeController().create(requested, 'kid', 'folder') | ||
| expect('error' in result && result.error).toBeFalsy() | ||
| if (!('error' in result)) { | ||
| expect(result.repo.path).toBe(join(base, 'typo dir', 'kid')) | ||
| } | ||
| }) | ||
|
|
||
| it('surfaces a non-absent probe failure instead of creating at the trimmed spelling', async () => { | ||
| const blocker = join(base, 'blocker') | ||
| writeFileSync(blocker, 'a file, not a directory') | ||
| const requested = join(blocker, 'cloud dir ') | ||
| const result = await makeController().create(requested, 'kid', 'folder') | ||
| expect('error' in result).toBe(true) | ||
| if ('error' in result) { | ||
| expect(result.error).toMatch(/Cannot access parent directory/) | ||
| } | ||
| }) | ||
| }) |
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.