Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/focus-setting-read-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
2 src/renderer/src/runtime/web-session-tabs-sync/global-session-subscription.ts
1 src/renderer/src/runtime/web-session-tabs-sync/tracking-decisions.ts
3 src/renderer/src/runtime/web-session-tabs-sync/use-web-session-tabs-sync.ts
2 src/renderer/src/store/github/visible-hosted-review-refresh-targets.ts
1 src/renderer/src/store/github/visible-hosted-review-refresh-targets.ts
9 src/renderer/src/store/index.ts
2 src/renderer/src/store/project-groups/project-group-mutations.ts
1 src/renderer/src/store/repos/all-host-repo-catalog-actions.ts
Expand Down Expand Up @@ -324,7 +324,7 @@
2 src/renderer/src/store/slices/worktrees/listing/fetch-detected-worktrees.ts
2 src/renderer/src/store/slices/worktrees/listing/fetch-worktrees.ts
1 src/renderer/src/store/slices/worktrees/listing/worktree-host-ownership.ts
2 src/renderer/src/store/slices/worktrees/metadata/update-worktree-meta.ts
1 src/renderer/src/store/slices/worktrees/metadata/update-worktree-meta.ts
1 src/renderer/src/store/slices/worktrees/metadata/worktree-lineage-actions.ts
3 src/renderer/src/store/slices/worktrees/metadata/worktree-lineage-host-merge.ts
3 src/renderer/src/store/slices/worktrees/session/worktree-terminal-reference.ts
Expand Down
24 changes: 24 additions & 0 deletions src/main/ipc/github-repo-routing-twin-host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ describe('registered GitHub repo lookup for a repo id on two hosts', () => {
).toBe(samePathSshTwin)
})

it('keeps checks and comments on the requested host when both copies share a path', () => {
const store = storeWith([localTwin, samePathSshTwin])
expect(
assertRegisteredGitHubRepo(
{
repoPath: localTwin.path,
repoId: localTwin.id,
repoOwnerExecutionHostId: 'ssh:builder'
},
store
)
).toBe(samePathSshTwin)
expect(() =>
assertRegisteredGitHubRepo(
{
repoPath: localTwin.path,
repoId: localTwin.id,
repoOwnerExecutionHostId: 'ssh:missing'
},
store
)
).toThrow('host does not match repository host')
})

it("keeps a lone row's own host over a stale candidate host", () => {
const result = validateAutomaticPRRefreshCandidate(
candidate({ repoPath: localTwin.path, connectionId: 'gone' }),
Expand Down
18 changes: 15 additions & 3 deletions src/main/ipc/github-repo-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { guardWslUncPathAccess, WslDistroStoppedError } from '../wsl/wsl-unc-acc
export type GitHubRepoScopedArgs = {
repoPath: string
repoId?: string | null
repoOwnerExecutionHostId?: string
sourceContext?: TaskSourceContext | null
}

Expand All @@ -30,6 +31,7 @@ type RegisteredRepoValidationResult =
type RegisteredRepoQuery = {
repoPath: string
repoId?: string | null
repoOwnerExecutionHostId?: string
/** Picks between twins (one id on two hosts); a lone row's own fields still win (they may be stale). */
hostHint?: Parameters<typeof getRepoExecutionHostId>[0] | null
sourceContext?: TaskSourceContext | null
Expand Down Expand Up @@ -66,9 +68,14 @@ function validateRegisteredRepo(
message: 'Access denied: unknown repository path'
}
}
if (sourceContext?.provider === 'github') {
const ownerHostId =
query.repoOwnerExecutionHostId ??
(sourceContext?.provider === 'github' ? sourceContext.hostId : null)
if (ownerHostId) {
const repo = pathRows.find(
(candidate) => getRepoExecutionHostId(candidate) === sourceContext.hostId
(candidate) =>
getRepoExecutionHostId(candidate) === ownerHostId &&
(sourceContext?.provider !== 'github' || sourceContext.hostId === ownerHostId)
)
return repo
? { kind: 'ok', repo }
Expand All @@ -89,7 +96,12 @@ function validateRegisteredRepo(
function registeredRepoQuery(args: string | GitHubRepoScopedArgs): RegisteredRepoQuery {
return typeof args === 'string'
? { repoPath: args }
: { repoPath: args.repoPath, repoId: args.repoId, sourceContext: args.sourceContext }
: {
repoPath: args.repoPath,
repoId: args.repoId,
repoOwnerExecutionHostId: args.repoOwnerExecutionHostId,
sourceContext: args.sourceContext
}
}

function prRefreshCandidateQuery(candidate: GitHubPRRefreshCandidate): RegisteredRepoQuery {
Expand Down
7 changes: 5 additions & 2 deletions src/main/ipc/hosted-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ function assertRegisteredRepo(repoPath: string, store: Store, repoId?: string):
return repo
}

function assertRegisteredRepoForBranch(args: HostedReviewForBranchArgs, store: Store): Repo {
function assertRegisteredRepoForBranch(
args: Pick<HostedReviewForBranchArgs, 'repoPath' | 'repoId' | 'repoOwnerExecutionHostId'>,
store: Store
): Repo {
if (!args.repoOwnerExecutionHostId) {
return assertRegisteredRepo(args.repoPath, store, args.repoId)
}
Expand Down Expand Up @@ -152,7 +155,7 @@ export function registerHostedReviewHandlers(store: Store, stats: StatsCollector
ipcMain.handle(
'hostedReview:getCreationEligibility',
async (_event, args: HostedReviewCreationEligibilityArgs) => {
const repo = assertRegisteredRepo(args.repoPath, store, args.repoId)
const repo = assertRegisteredRepoForBranch(args, store)
const localGitOptions = getLocalProjectGhExecOptions(store, repo)
// Source Control asks on mount; only the user's Create PR may start a stopped distro (E9).
return guardWslUncPathAccess(
Expand Down
5 changes: 5 additions & 0 deletions src/preload/api/github-pull-request-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type GithubPullRequestApi = {
prForBranch: (args: {
repoPath: string
repoId?: string
repoOwnerExecutionHostId?: string
branch: string
linkedPRNumber?: number | null
fallbackPRNumber?: number | null
Expand Down Expand Up @@ -86,6 +87,7 @@ export type GithubPullRequestApi = {
prCheckDetails: (args: {
repoPath: string
repoId?: string
repoOwnerExecutionHostId?: string
sourceContext?: TaskSourceContext | null
checkRunId?: number
workflowRunId?: number
Expand All @@ -104,6 +106,7 @@ export type GithubPullRequestApi = {
prComments: (args: {
repoPath: string
repoId?: string
repoOwnerExecutionHostId?: string
sourceContext?: TaskSourceContext | null
prNumber: number
prRepo?: GitHubOwnerRepo | null
Expand All @@ -112,6 +115,7 @@ export type GithubPullRequestApi = {
setPRCommentReaction: (args: {
repoPath: string
repoId?: string
repoOwnerExecutionHostId?: string
sourceContext?: TaskSourceContext | null
reactionSubjectId: string
content: GitHubReactionContent
Expand All @@ -121,6 +125,7 @@ export type GithubPullRequestApi = {
resolveReviewThread: (args: {
repoPath: string
repoId?: string
repoOwnerExecutionHostId?: string
sourceContext?: TaskSourceContext | null
threadId: string
resolve: boolean
Expand Down
1 change: 1 addition & 0 deletions src/preload/api/github-work-item-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import type {
import type { GitHubCreateIssueResult, GitHubIssueUpdate } from '../../shared/issue-mutation-types'

export type GitHubRepoSelectorArgs = {
repoOwnerExecutionHostId?: string
repoPath: string
repoId?: string | null
sourceContext?: TaskSourceContext | null
Expand Down
81 changes: 41 additions & 40 deletions src/renderer/src/app-shell/use-visible-review-refresh-reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,30 @@ import type { AppState } from '../store/types'
import { rightSidebarShowsPullRequestData } from '../lib/right-sidebar-visibility'
import { findWorktreeById, buildPRRefreshCandidate } from '../store/github/worktree-refresh'
import { getHostedReviewCacheKey } from '../store/slices/hosted-review-cache-identity'
import { getIndexedRepoMap } from '../store/worktree-repo-index'
import { getVisibleHostedReviewWorkspaces } from '../store/github/visible-hosted-review-refresh-targets'
import { shouldCoordinateVisibleGitHubReview } from '../store/github/visible-hosted-review-refresh-ownership'
import { getPRRefreshRuntimeRepoTarget } from '../store/github/repository-routing'
import {
reviewRefreshIntervalMs,
REVIEW_REFRESH_COOLDOWN_MS
} from '../../../shared/review-refresh-policy'
import { selectWorktreesByRepo } from '@/store/workspace-record-selectors'
import {
selectDetectedWorktreesByRepo,
selectWorktreesByRepo
} from '@/store/workspace-record-selectors'

export function visibleReviewWorktreeIdsForState(state: AppState): string[] {
function visibleReviewWorkspacesForState(state: AppState) {
const ids = new Set(state.visibleReviewCardWorktreeIds ?? [])
const repos = getIndexedRepoMap(state.repos)
if (state.activeWorktreeId && rightSidebarShowsPullRequestData(state)) {
ids.add(state.activeWorktreeId)
}
return Array.from(ids).filter((id) => {
const worktree = findWorktreeById(state, id)
const repo = worktree && repos.get(worktree.repoId)
return (
worktree &&
repo &&
(repo.kind ?? 'git') === 'git' &&
!worktree.isBare &&
!worktree.isArchived &&
Boolean(worktree.branch)
)
})
return [...getVisibleHostedReviewWorkspaces(state, { worktreeIds: [...ids] })].filter(
({ worktree }) => Boolean(worktree.branch)
)
}

export function visibleReviewWorktreeIdsForState(state: AppState): string[] {
return [...new Set(visibleReviewWorkspacesForState(state).map(({ worktree }) => worktree.id))]
}

function reportIdentity(state: AppState): string {
Expand All @@ -39,38 +36,32 @@ function reportIdentity(state: AppState): string {
rightSidebarShowsPullRequestData(state),
state.sshConnectedGeneration,
state.prVisibleRefreshGeneration,
visibleReviewWorktreeIdsForState(state).map((id) => {
const worktree = findWorktreeById(state, id)
if (!worktree) {
return id
}
const candidate = buildPRRefreshCandidate(state, worktree)
const key =
candidate &&
getHostedReviewCacheKey(
candidate.repoPath,
candidate.branch,
state.settings,
candidate.repoId,
candidate.connectionId,
candidate.executionHostId,
true
)
visibleReviewWorkspacesForState(state).map(({ worktree, repo, candidate, selected }) => {
const key = getHostedReviewCacheKey(
candidate.repoPath,
candidate.branch,
state.settings,
candidate.repoId,
candidate.connectionId,
candidate.executionHostId,
true
)
return [
id,
worktree.id,
selected,
worktree.branch,
worktree.head,
worktree.linkedPR,
worktree.linkedGitLabMR,
worktree.linkedBitbucketPR,
worktree.linkedAzureDevOpsPR,
worktree.linkedGiteaPR,
candidate?.connectionState,
candidate?.executionHostId,
candidate?.cacheKey,
getIndexedRepoMap(state.repos).get(worktree.repoId)?.gitRemoteIdentity?.canonicalKey,
Boolean(candidate && state.prCache[candidate.cacheKey]?.data),
key ? state.hostedReviewCache[key]?.data?.provider : null
candidate.connectionState,
candidate.executionHostId,
candidate.cacheKey,
repo.gitRemoteIdentity?.canonicalKey,
Boolean(state.prCache[candidate.cacheKey]?.data),
state.hostedReviewCache[key]?.data?.provider
]
})
])
Expand All @@ -79,11 +70,16 @@ function reportIdentity(state: AppState): string {
const REPORT_INPUT_KEYS = [
'activeView',
'activeWorktreeId',
'activeWorkspaceExecutionHostId',
'rightSidebarOpen',
'rightSidebarTab',
'visibleReviewCardWorktreeIds',
'visibleWorkspaceHostIds',
'workspaceHostScope',
'repos',
'worktreesByRepo',
'detectedWorktreesByRepo',
'wslHostStatuses',
'settings',
'sshConnectionStates',
'sshConnectedGeneration',
Expand All @@ -106,11 +102,16 @@ export function createVisibleReviewReportIdentitySelector(): (state: AppState) =
previous = {
activeView: state.activeView,
activeWorktreeId: state.activeWorktreeId,
activeWorkspaceExecutionHostId: state.activeWorkspaceExecutionHostId,
rightSidebarOpen: state.rightSidebarOpen,
rightSidebarTab: state.rightSidebarTab,
visibleReviewCardWorktreeIds: state.visibleReviewCardWorktreeIds,
visibleWorkspaceHostIds: state.visibleWorkspaceHostIds,
workspaceHostScope: state.workspaceHostScope,
repos: state.repos,
worktreesByRepo: selectWorktreesByRepo(state),
detectedWorktreesByRepo: selectDetectedWorktreesByRepo(state),
wslHostStatuses: state.wslHostStatuses,
settings: state.settings,
sshConnectionStates: state.sshConnectionStates,
sshConnectedGeneration: state.sshConnectedGeneration,
Expand Down
26 changes: 26 additions & 0 deletions src/renderer/src/app-shell/visible-review-reporting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ describe('review surface visibility union', () => {
})

describe('review report selector work', () => {
it.each(['ssh:builder', 'runtime:server'] as const)(
'updates the report when switching between same-ID local and %s worktrees',
(hostId) => {
const store = state()
const localRepo = store.getState().repos[0]
const localWorktree = makePRRefreshWorktree({ id: 'selected', hostId: 'local' })
store.setState({
repos: [localRepo, { ...localRepo, executionHostId: hostId }],
worktreesByRepo: {
'repo-1': [localWorktree, { ...localWorktree, hostId }]
},
activeWorkspaceExecutionHostId: 'local'
})
const select = createVisibleReviewReportIdentitySelector()
const localReport = select(store.getState())

store.setState({ activeWorkspaceExecutionHostId: hostId })
const remoteReport = select(store.getState())
expect(remoteReport).not.toBe(localReport)
expect(remoteReport).toBe(createVisibleReviewReportIdentitySelector()(store.getState()))

store.setState({ activeWorkspaceExecutionHostId: 'local' })
expect(select(store.getState())).toBe(localReport)
}
)

it('does not rebuild candidates or serialize on unrelated agent updates', () => {
const current = state().getState()
const select = createVisibleReviewReportIdentitySelector()
Expand Down
Loading
Loading