Repository navigation
fix(sidebar): place a runtime-stamped project group on its own host #24363
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
innocarpe
wants to merge
2
commits into
stablyai:main
Choose a base branch
from
innocarpe:fix-13944-project-group-host
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.
+259
−11
Open
Changes from all commits
Commits
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
22 changes: 12 additions & 10 deletions
22
src/renderer/src/components/sidebar/folder-workspace-host-id.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 |
|---|---|---|
| @@ -1,21 +1,23 @@ | ||
| import { toSshExecutionHostId, type ExecutionHostId } from '../../../../shared/execution-host' | ||
| import type { ExecutionHostId } from '../../../../shared/execution-host' | ||
| import type { FolderWorkspace } from '../../../../shared/folder-workspace-types' | ||
| import type { ProjectGroup } from '../../../../shared/project-group-types' | ||
| import { getFolderWorkspaceExecutionHostIdForRows } from './worktree-list/listing/host-filtering' | ||
|
|
||
| /** | ||
| * Which host section a folder workspace's row belongs to. | ||
| * | ||
| * Single source of truth: header counting, host bucketing and reveal all resolve | ||
| * the host through here. Two resolvers that drift is how folder workspaces went | ||
| * missing from the sidebar in the first place (#15362). Deliberately distinct | ||
| * from the host *filter* resolver, which also consults executionHostId — this | ||
| * one must match where the row actually renders. | ||
| * Header counting, host bucketing and reveal all resolve the host through here | ||
| * (#15362). This matches the visibility filter: a connectionless runtime stamp | ||
| * is the group's host, not whichever server happens to be focused (#13944). | ||
| */ | ||
| export function getFolderWorkspaceHostId( | ||
| folderWorkspace: Pick<FolderWorkspace, 'connectionId'>, | ||
| projectGroup: Pick<ProjectGroup, 'connectionId'>, | ||
| folderWorkspace: Pick<FolderWorkspace, 'connectionId' | 'executionHostId'>, | ||
| projectGroup: Pick<ProjectGroup, 'connectionId' | 'executionHostId'>, | ||
| defaultHostId: ExecutionHostId | ||
| ): ExecutionHostId { | ||
| const connectionId = folderWorkspace.connectionId ?? projectGroup.connectionId | ||
| return connectionId ? toSshExecutionHostId(connectionId) : defaultHostId | ||
| return getFolderWorkspaceExecutionHostIdForRows({ | ||
| folderWorkspace, | ||
| projectGroup, | ||
| defaultHostId | ||
| }) | ||
| } |
225 changes: 225 additions & 0 deletions
225
src/renderer/src/components/sidebar/host-section-rows.runtime-group.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,225 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import type { FolderWorkspace } from '../../../../shared/folder-workspace-types' | ||
| import type { ExecutionHostId } from '../../../../shared/execution-host' | ||
| import type { ProjectGroup } from '../../../../shared/project-group-types' | ||
| import type { Repo } from '../../../../shared/repo-types' | ||
| import type { Worktree } from '../../../../shared/worktree/types' | ||
| import { addHostSectionRows, type HostSectionOption } from './host-section-rows' | ||
| import type { Row } from './worktree-list/grouping/row-types' | ||
|
|
||
| const FOCUSED: ExecutionHostId = 'runtime:env-1' | ||
| const OWNER: ExecutionHostId = 'runtime:env-2' | ||
|
|
||
| function repo(id: string, executionHostId: ExecutionHostId): Repo { | ||
| return { | ||
| id, | ||
| path: `/${id}`, | ||
| displayName: id, | ||
| badgeColor: '#000000', | ||
| addedAt: 0, | ||
| connectionId: null, | ||
| executionHostId | ||
| } | ||
| } | ||
|
|
||
| function item(id: string, project: Repo): Extract<Row, { type: 'item' }> { | ||
| const worktree: Worktree = { | ||
| id, | ||
| repoId: project.id, | ||
| path: `/${project.id}/${id}`, | ||
| branch: `refs/heads/${id}`, | ||
| head: 'abc123', | ||
| isBare: false, | ||
| isMainWorktree: false, | ||
| linkedIssue: null, | ||
| linkedPR: null, | ||
| linkedLinearIssue: null, | ||
| isArchived: false, | ||
| comment: '', | ||
| isUnread: false, | ||
| isPinned: false, | ||
| displayName: id, | ||
| sortOrder: 0, | ||
| lastActivityAt: 0 | ||
| } | ||
| return { | ||
| type: 'item', | ||
| rowKey: `repo:${project.id}:${id}`, | ||
| sectionKey: `repo:${project.id}`, | ||
| worktree, | ||
| repo: project, | ||
| depth: 0, | ||
| groupDepth: 0, | ||
| lineageTrail: [], | ||
| isLastLineageChild: true, | ||
| lineageChildCount: 0 | ||
| } | ||
| } | ||
|
|
||
| function projectGroup( | ||
| executionHostId: ExecutionHostId | null, | ||
| connectionId: string | null | ||
| ): ProjectGroup { | ||
| return { | ||
| id: 'group-a', | ||
| name: 'Server group', | ||
| parentPath: '/srv/project', | ||
| connectionId, | ||
| executionHostId, | ||
| parentGroupId: null, | ||
| createdFrom: 'manual', | ||
| tabOrder: 0, | ||
| isCollapsed: false, | ||
| color: null, | ||
| createdAt: 1, | ||
| updatedAt: 1 | ||
| } | ||
| } | ||
|
|
||
| function groupHeader(group: ProjectGroup): Extract<Row, { type: 'header' }> { | ||
| return { | ||
| type: 'header', | ||
| key: `group:${group.id}`, | ||
| label: group.name, | ||
| count: 1, | ||
| tone: 'text-foreground', | ||
| projectGroup: group | ||
| } | ||
| } | ||
|
|
||
| function folderRow(group: ProjectGroup): Extract<Row, { type: 'folder-workspace' }> { | ||
| const folderWorkspace: FolderWorkspace = { | ||
| id: 'folder-1', | ||
| projectGroupId: group.id, | ||
| name: 'Folder workspace', | ||
| folderPath: '/srv/project', | ||
| connectionId: null, | ||
| linkedTask: null, | ||
| comment: '', | ||
| isArchived: false, | ||
| isUnread: false, | ||
| isPinned: false, | ||
| sortOrder: 0, | ||
| lastActivityAt: 1, | ||
| createdAt: 1, | ||
| updatedAt: 1 | ||
| } | ||
| return { | ||
| type: 'folder-workspace', | ||
| key: 'folder-workspace:folder-1', | ||
| folderWorkspace, | ||
| projectGroup: group, | ||
| depth: 0, | ||
| groupDepth: 0 | ||
| } | ||
| } | ||
|
|
||
| const hostOptions: HostSectionOption[] = [ | ||
| { id: FOCUSED, kind: 'runtime', label: 'env-1', detail: 'Orca server', health: 'available' }, | ||
| { id: OWNER, kind: 'runtime', label: 'env-2', detail: 'Orca server', health: 'available' } | ||
| ] | ||
|
|
||
| function sectioned(rows: Row[]) { | ||
| return addHostSectionRows({ | ||
| rows, | ||
| hostOptions, | ||
| workspaceHostScope: 'all', | ||
| defaultHostId: FOCUSED | ||
| }) | ||
| } | ||
|
|
||
| function renderedHostFilter(rows: Row[]) { | ||
| return addHostSectionRows({ | ||
| rows, | ||
| hostOptions, | ||
| workspaceHostScope: 'all', | ||
| visibleWorkspaceHostIds: [FOCUSED, OWNER], | ||
| defaultHostId: FOCUSED, | ||
| preferProjectGrouping: true | ||
| }) | ||
| } | ||
|
|
||
| function rowKey(row: { type: string; key?: string; worktree?: { id: string } }): string { | ||
| return row.type === 'item' ? row.worktree!.id : (row.key ?? row.type) | ||
| } | ||
|
|
||
| describe('runtime-stamped project groups', () => { | ||
| it('keeps a connectionless runtime group under its owner when another server is focused', () => { | ||
| const focusedRepo = repo('focused-project', FOCUSED) | ||
| const ownerRepo = repo('owner-project', OWNER) | ||
| const rows = sectioned([ | ||
| groupHeader(projectGroup(OWNER, null)), | ||
| item('focused-wt', focusedRepo), | ||
| item('owner-wt', ownerRepo) | ||
| ]) | ||
|
|
||
| expect(rows.map(rowKey)).toEqual([ | ||
| 'host:runtime:env-1', | ||
| 'focused-wt', | ||
| 'host:runtime:env-2', | ||
| 'group:group-a', | ||
| 'owner-wt' | ||
| ]) | ||
| }) | ||
|
|
||
| it('places a connectionless folder workspace under the stamped group host', () => { | ||
| const focusedRepo = repo('focused-project', FOCUSED) | ||
| const rows = sectioned([item('focused-wt', focusedRepo), folderRow(projectGroup(OWNER, null))]) | ||
|
|
||
| expect(rows.map(rowKey)).toEqual([ | ||
| 'host:runtime:env-1', | ||
| 'focused-wt', | ||
| 'host:runtime:env-2', | ||
| 'folder-workspace:folder-1' | ||
| ]) | ||
| }) | ||
|
|
||
| it('keeps an unstamped project group header buffered across host runs', () => { | ||
| const rows = sectioned([ | ||
| groupHeader(projectGroup(null, null)), | ||
| item('owner-wt', repo('owner-project', OWNER)), | ||
| item('focused-wt', repo('focused-project', FOCUSED)) | ||
| ]) | ||
|
|
||
| expect(rows.map(rowKey)).toEqual([ | ||
| 'host:runtime:env-1', | ||
| 'group:group-a', | ||
| 'focused-wt', | ||
| 'host:runtime:env-2', | ||
| 'group:group-a', | ||
| 'owner-wt' | ||
| ]) | ||
| }) | ||
|
|
||
| it('keeps a runtime-stamped group under its owner when the sidebar filters to both hosts', () => { | ||
| const rows = renderedHostFilter([ | ||
| groupHeader(projectGroup(OWNER, null)), | ||
| item('owner-wt', repo('owner-project', OWNER)), | ||
| item('focused-wt', repo('focused-project', FOCUSED)) | ||
| ]) | ||
|
|
||
| expect(rows.map(rowKey)).toEqual([ | ||
| 'host:runtime:env-1', | ||
| 'focused-wt', | ||
| 'host:runtime:env-2', | ||
| 'group:group-a', | ||
| 'owner-wt' | ||
| ]) | ||
| }) | ||
|
|
||
| it('does not add host headers in the unfiltered projects view', () => { | ||
| const rows = addHostSectionRows({ | ||
| rows: [ | ||
| groupHeader(projectGroup(OWNER, null)), | ||
| item('owner-wt', repo('owner-project', OWNER)) | ||
| ], | ||
| hostOptions, | ||
| workspaceHostScope: 'all', | ||
| visibleWorkspaceHostIds: null, | ||
| defaultHostId: FOCUSED, | ||
| preferProjectGrouping: true | ||
| }) | ||
|
|
||
| expect(rows.map(rowKey)).toEqual(['group:group-a', 'owner-wt']) | ||
| }) | ||
| }) | ||
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
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.