-
Notifications
You must be signed in to change notification settings - Fork 470
fix(workspace): dedupe workspaces across Windows path spelling variants #1809
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
sailist
merged 3 commits into
MoonshotAI:main
from
sailist:fix/workspace-windows-path-dedup
Jul 17, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
714f42b
fix(workspace): dedupe workspaces across Windows path spelling variants
sailist cf46bd0
fix(workspace): fold the runtime touch path and drive-root identity keys
sailist 7d940b9
fix(workspace): unfold symmetric operations that escaped the identity…
sailist 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| web: Fix duplicate workspace groups on Windows when the same folder is opened with different path spellings, such as a different drive-letter casing; all of the folder's sessions now list under the single merged group. |
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,164 @@ | ||
| // apps/kimi-web/src/lib/mergeWorkspaces.test.ts | ||
| import { describe, expect, it } from 'vitest'; | ||
| import type { AppWorkspace } from '../api/types'; | ||
| import { mergeWorkspaces, type MergeWorkspacesInput } from './mergeWorkspaces'; | ||
| import { workspaceRootKey } from './rootKey'; | ||
|
|
||
| function ws(root: string, extra: Partial<AppWorkspace> = {}): AppWorkspace { | ||
| return { id: `wd_${root}`, root, name: root, sessionCount: 0, ...extra }; | ||
| } | ||
|
|
||
| function input(overrides: Partial<MergeWorkspacesInput>): MergeWorkspacesInput { | ||
| return { | ||
| workspaces: [], | ||
| sessions: [], | ||
| hiddenWorkspaceRoots: [], | ||
| sessionsHasMoreByWorkspace: {}, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe('mergeWorkspaces — folded root identity', () => { | ||
| it('assigns a session to the registered workspace when only the drive-letter case differs', () => { | ||
| const w = ws('C:\\Users\\Foo\\Proj', { id: 'wd_proj' }); | ||
| const result = mergeWorkspaces( | ||
| input({ workspaces: [w], sessions: [{ id: 's1', cwd: 'c:\\Users\\Foo\\Proj' }] }), | ||
| ); | ||
| expect(result).toHaveLength(1); // no derived duplicate group | ||
| expect(result[0]!.id).toBe('wd_proj'); | ||
| expect(result[0]!.root).toBe('C:\\Users\\Foo\\Proj'); // registered spelling kept | ||
| expect(result[0]!.sessionCount).toBe(1); // counted under the registered id | ||
| }); | ||
|
|
||
| it('collapses legacy registered duplicates whose roots only differ by case', () => { | ||
| const first = ws('C:\\Users\\Foo\\Proj', { id: 'wd_first' }); | ||
| const second = ws('c:\\Users\\Foo\\Proj', { id: 'wd_second' }); | ||
| const result = mergeWorkspaces( | ||
| input({ | ||
| workspaces: [first, second], | ||
| sessions: [ | ||
| { id: 's1', cwd: 'C:\\Users\\Foo\\Proj' }, | ||
| { id: 's2', cwd: 'c:\\Users\\Foo\\Proj' }, | ||
| ], | ||
| }), | ||
| ); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0]!.id).toBe('wd_first'); // daemon order: first entry wins | ||
| expect(result[0]!.root).toBe('C:\\Users\\Foo\\Proj'); | ||
| expect(result[0]!.sessionCount).toBe(2); // both cwd variants assigned to it | ||
| }); | ||
|
|
||
| it('merges slash variants of the same Windows path', () => { | ||
| const w = ws('C:/Users/Foo/Proj', { id: 'wd_proj' }); | ||
| const result = mergeWorkspaces( | ||
| input({ workspaces: [w], sessions: [{ id: 's1', cwd: 'C:\\Users\\Foo\\Proj' }] }), | ||
| ); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0]!.id).toBe('wd_proj'); | ||
| expect(result[0]!.root).toBe('C:/Users/Foo/Proj'); | ||
| expect(result[0]!.sessionCount).toBe(1); | ||
| }); | ||
|
|
||
| it('hides Windows-shaped roots case-insensitively', () => { | ||
| const w = ws('C:\\Users\\Foo\\Proj', { id: 'wd_proj' }); | ||
| const result = mergeWorkspaces( | ||
| input({ | ||
| workspaces: [w], | ||
| sessions: [{ id: 's1', cwd: 'c:\\Users\\Foo\\Proj' }], | ||
| hiddenWorkspaceRoots: ['c:\\users\\foo\\proj'], | ||
| }), | ||
| ); | ||
| expect(result).toHaveLength(0); // one casing removed, all spellings hidden | ||
| }); | ||
|
|
||
| it('hides POSIX roots only by exact directory (trailing slash tolerated)', () => { | ||
| const hidden = mergeWorkspaces( | ||
| input({ workspaces: [ws('/home/Foo')], hiddenWorkspaceRoots: ['/home/Foo/'] }), | ||
| ); | ||
| expect(hidden).toHaveLength(0); | ||
| const kept = mergeWorkspaces( | ||
| input({ workspaces: [ws('/home/Foo')], hiddenWorkspaceRoots: ['/home/foo'] }), | ||
| ); | ||
| expect(kept).toHaveLength(1); | ||
| }); | ||
|
|
||
| it('keeps POSIX paths case-sensitive', () => { | ||
| const result = mergeWorkspaces( | ||
| input({ workspaces: [ws('/home/Foo', { id: 'wd_a' }), ws('/home/foo', { id: 'wd_b' })] }), | ||
| ); | ||
| expect(result.map((w) => w.root)).toEqual(['/home/Foo', '/home/foo']); | ||
| }); | ||
|
|
||
| it('keeps case-variant derived POSIX cwds as separate groups', () => { | ||
| const result = mergeWorkspaces( | ||
| input({ | ||
| sessions: [ | ||
| { id: 's1', cwd: '/home/Foo' }, | ||
| { id: 's2', cwd: '/home/foo' }, | ||
| ], | ||
| }), | ||
| ); | ||
| expect(result).toHaveLength(2); | ||
| }); | ||
|
|
||
| it('merges derived groups whose session cwds differ only by case', () => { | ||
| const result = mergeWorkspaces( | ||
| input({ | ||
| sessions: [ | ||
| { id: 's1', cwd: 'C:\\Users\\Foo\\Proj' }, | ||
| { id: 's2', cwd: 'c:\\Users\\Foo\\Proj' }, | ||
| ], | ||
| }), | ||
| ); | ||
| expect(result).toHaveLength(1); | ||
| expect(result[0]!.root).toBe('C:\\Users\\Foo\\Proj'); // first-seen cwd kept | ||
| }); | ||
|
|
||
| it('orders real workspaces in daemon order and derived ones by display root', () => { | ||
| const result = mergeWorkspaces( | ||
| input({ | ||
| workspaces: [ws('/home/x/bbb'), ws('/home/x/aaa')], | ||
| sessions: [ | ||
| { id: 's1', cwd: '/home/x/ccc' }, | ||
| { id: 's2', cwd: '/home/x/000' }, | ||
| ], | ||
| }), | ||
| ); | ||
| expect(result.map((w) => w.root)).toEqual([ | ||
| '/home/x/bbb', | ||
| '/home/x/aaa', | ||
| '/home/x/000', | ||
| '/home/x/ccc', | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('workspaceRootKey', () => { | ||
| it('folds drive-letter casing', () => { | ||
| expect(workspaceRootKey('C:\\Users\\Foo')).toBe(workspaceRootKey('c:\\Users\\Foo')); | ||
| expect(workspaceRootKey('C:\\Users\\Foo')).toBe('c:/users/foo'); | ||
| }); | ||
|
|
||
| it('folds drive roots before separator stripping can mask the shape', () => { | ||
| // `C:\` would strip to `C:` and stop reading as Windows-shaped. | ||
| expect(workspaceRootKey('C:\\')).toBe('c:'); | ||
| expect(workspaceRootKey('C:\\')).toBe(workspaceRootKey('c:\\')); | ||
| expect(workspaceRootKey('C:\\')).toBe(workspaceRootKey('c:/')); | ||
| }); | ||
|
|
||
| it('folds UNC paths', () => { | ||
| expect(workspaceRootKey('\\\\HOST\\Share\\Dir')).toBe('//host/share/dir'); | ||
| expect(workspaceRootKey('\\\\HOST\\Share\\Dir')).toBe(workspaceRootKey('//host/share/dir')); | ||
| }); | ||
|
|
||
| it('normalizes slashes and strips trailing separators', () => { | ||
| expect(workspaceRootKey('C:\\Users\\Foo\\')).toBe('c:/users/foo'); | ||
| expect(workspaceRootKey('C:/Users/Foo/')).toBe('c:/users/foo'); | ||
| expect(workspaceRootKey('/home/Foo/')).toBe('/home/Foo'); | ||
| }); | ||
|
|
||
| it('never folds POSIX paths', () => { | ||
| expect(workspaceRootKey('/home/Foo')).toBe('/home/Foo'); | ||
| expect(workspaceRootKey('/home/Foo')).not.toBe(workspaceRootKey('/home/foo')); | ||
| }); | ||
| }); |
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,26 @@ | ||
| // apps/kimi-web/src/lib/rootKey.ts | ||
|
|
||
| // Windows-shaped: drive-letter (C:\, C:/) or UNC (\\host\share, //host/share). | ||
| // Shape-based detection (not any platform check): the daemon may run on | ||
| // Windows while the browser runs anywhere, and tests must fold the same way | ||
| // on every host. | ||
| const WIN_SHAPED = /^(?:[A-Za-z]:[\\/]|\\\\|\/\/)/; | ||
|
|
||
| /** | ||
| * Identity key for "same workspace directory?" comparisons: slash-normalize, | ||
| * strip trailing separators, case-fold Windows-shaped paths (NTFS lookups are | ||
| * case-insensitive by default). Display strings are never rewritten — this is | ||
| * for comparison only. Mirrors the server-side copies (agent-core | ||
| * session/store/workdir-key.ts, agent-core-v2 _base/utils/workdir-slug.ts); | ||
| * keep the three in sync. Per-directory case sensitivity / WSL paths are a | ||
| * documented non-goal; POSIX paths never fold. | ||
| */ | ||
| export function workspaceRootKey(root: string): string { | ||
| const slashed = root.replaceAll('\\', '/'); | ||
| // Test the shape BEFORE stripping trailing separators: a drive root | ||
| // (`C:\`) loses its only separator to the strip (`C:`) and would no | ||
| // longer read as Windows-shaped, escaping the case-fold. | ||
| const shaped = WIN_SHAPED.test(slashed); | ||
| const normalized = slashed.replace(/\/+$/, ''); | ||
| return shaped ? normalized.toLowerCase() : normalized; | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user removes
C:\Fooand later adds the same Windows directory asc:\fooor with different slashes, the stored hidden root is not cleared becauseupsertWorkspacePreserveOrderstill removes hidden entries by exact string. This new folded hidden set then keeps hiding the re-added workspace, so the add flow can succeed while the group remains absent until localStorage is cleared. Clear hidden entries using the sameworkspaceRootKeycomparison on re-add.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — the hide/unhide sides were asymmetric.
upsertWorkspacePreserveOrdernow clears hidden entries by the same foldedworkspaceRootKeycomparison (inuseWorkspaceState.ts), so re-adding an alias spelling un-hides the workspace. Fixed in 7d940b9 with regression tests (Windows-fold unhide, POSIX case-distinct stays hidden).