From 9dc7b008bbcc7ce6ac31c3011ba10a595f8399e8 Mon Sep 17 00:00:00 2001 From: wSedlacek Date: Thu, 5 Nov 2026 19:01:20 -0800 Subject: [PATCH 1/4] fix(mobile): show linked pull requests in thread git menus --- .../review/useReviewHeaderPresentation.tsx | 10 ++- .../features/threads/DraftThreadHeader.tsx | 10 ++- .../threads/LinkedPullRequestList.tsx | 12 +-- .../src/features/threads/ThreadHeader.tsx | 50 +++++++++--- .../threads/ThreadPullRequestsSheet.tsx | 2 +- .../features/threads/ThreadRouteScreen.tsx | 8 +- .../features/threads/git/GitOverviewSheet.tsx | 32 ++++---- .../src/state/thread-pr-presentation.ts | 27 +++++++ apps/mobile/src/state/use-thread-pr.test.ts | 76 +++++++++++++++++++ 9 files changed, 189 insertions(+), 38 deletions(-) diff --git a/apps/mobile/src/features/review/useReviewHeaderPresentation.tsx b/apps/mobile/src/features/review/useReviewHeaderPresentation.tsx index d0fda18cf60c..68979559f415 100644 --- a/apps/mobile/src/features/review/useReviewHeaderPresentation.tsx +++ b/apps/mobile/src/features/review/useReviewHeaderPresentation.tsx @@ -2,6 +2,7 @@ import { useEnvironmentQuery } from "../../state/query"; import { useSelectedThreadGitActions } from "../../state/use-selected-thread-git-actions"; import { useSelectedThreadGitState } from "../../state/use-selected-thread-git-state"; import { useThreadSelection } from "../../state/use-thread-selection"; +import { withThreadOpenPullRequest } from "../../state/thread-pr-presentation"; import { vcsEnvironment } from "../../state/vcs"; import { useThreadGitMenuDefinition } from "../threads/ThreadGitControls"; import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; @@ -27,7 +28,7 @@ export function useReviewHeaderPresentation(props: { readonly selectedSection: ReviewSectionItem | null; readonly onRefresh: () => Promise; }): ReviewHeaderPresentation { - const { selectedThread } = useThreadSelection(); + const { selectedThread, selectedEnvironmentRuntime } = useThreadSelection(); const gitState = useSelectedThreadGitState(); const gitActions = useSelectedThreadGitActions(); const gitStatusQuery = useEnvironmentQuery( @@ -45,7 +46,12 @@ export function useReviewHeaderPresentation(props: { environmentId: props.environmentId, threadId: props.threadId, currentBranch: selectedThread?.branch ?? null, - gitStatus: gitStatusQuery.data, + gitStatus: withThreadOpenPullRequest( + gitStatusQuery.data ?? null, + selectedThread?.pullRequests ?? [], + selectedEnvironmentRuntime?.serverConfig?.environment.capabilities.threadPullRequests === + true, + ), gitOperationLabel: gitState.gitOperationLabel, onPull: gitActions.onPullSelectedThreadBranch, onRunAction: gitActions.onRunSelectedThreadGitAction, diff --git a/apps/mobile/src/features/threads/DraftThreadHeader.tsx b/apps/mobile/src/features/threads/DraftThreadHeader.tsx index 043273ee79be..5950a7a6e030 100644 --- a/apps/mobile/src/features/threads/DraftThreadHeader.tsx +++ b/apps/mobile/src/features/threads/DraftThreadHeader.tsx @@ -11,6 +11,8 @@ import type { import { useEnvironmentQuery } from "../../state/query"; import { useEnvironmentScope } from "../../state/session"; import { useAtomCommand } from "../../state/use-atom-command"; +import { useRemoteEnvironmentRuntime } from "../../state/use-remote-environment-registry"; +import { withThreadOpenPullRequest } from "../../state/thread-pr-presentation"; import { vcsActionManager, vcsEnvironment } from "../../state/vcs"; import { useVcsActionState } from "../../state/use-vcs-action-state"; import { ThreadHeader } from "./ThreadHeader"; @@ -22,6 +24,7 @@ export function DraftThreadHeader(props: { }) { const navigation = useNavigation(); const environmentId = props.thread.environmentId; + const runtime = useRemoteEnvironmentRuntime(environmentId); const canReadFiles = useEnvironmentScope(environmentId, AuthFilesystemReadScope); const canWriteGit = useEnvironmentScope(environmentId, AuthSourceControlWriteScope); const status = useEnvironmentQuery( @@ -46,6 +49,7 @@ export function DraftThreadHeader(props: { return ( { - const chains = resolveThreadPullRequestChains(supported ? (pullRequests ?? []) : []); + const chains = resolveThreadPullRequestChains(pullRequests ?? []); const open = chains.filter((chain) => chain.layers.some(isOpenLink)); const done = chains.filter((chain) => !chain.layers.some(isOpenLink)); return [...pullRequestListLines(open), ...pullRequestListLines(done)]; - }, [pullRequests, supported]); + }, [pullRequests]); } function isOpenLink(link: PullRequestListLine["link"]) { diff --git a/apps/mobile/src/features/threads/ThreadHeader.tsx b/apps/mobile/src/features/threads/ThreadHeader.tsx index 5a85bb4f9119..edd3a54dbafb 100644 --- a/apps/mobile/src/features/threads/ThreadHeader.tsx +++ b/apps/mobile/src/features/threads/ThreadHeader.tsx @@ -1,8 +1,16 @@ +import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; +import { useMemo } from "react"; import { AppBar } from "../../components/ui/AppBar"; import type { AppBarAction, AppBarMenu } from "../../components/ui/AppBar.types"; import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout"; import type { ThreadInspectorMode } from "./thread-inspector-navigation"; import { useWorkspaceBackNavigation } from "../layout/workspace/useAndroidWorkspaceNavigation"; +import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs"; +import { + presentThreadLinkedPullRequests, + resolveThreadPrBadgeAction, +} from "../../state/thread-pr-presentation"; +import { useOpenThreadPullRequests } from "./use-open-thread-pull-requests"; import { threadTerminalMenu, useThreadGitMenuDefinition, @@ -12,6 +20,7 @@ import { export function ThreadHeader(props: { readonly title: string; readonly subtitle: string; + readonly thread: EnvironmentThreadShell; readonly gitControls: ThreadGitControlsProps; readonly onReturnToThread?: () => void; readonly draft?: boolean; @@ -24,19 +33,36 @@ export function ThreadHeader(props: { useAdaptiveWorkspaceLayout(); const gitMenu = useThreadGitMenuDefinition(props.gitControls); const terminalMenu = threadTerminalMenu(props.gitControls); + const openThreadPullRequests = useOpenThreadPullRequests(); + const linkedPullRequest = useMemo( + () => presentThreadLinkedPullRequests(props.thread.pullRequests), + [props.thread.pullRequests], + ); const filesVisible = props.inspectorMode === "files" && panes.auxiliaryPaneVisible; - const actions: AppBarAction[] = props.hasThreadCwd - ? [ - { - accessibilityLabel: filesVisible ? "Close files" : "Open files", - icon: "folder", - selected: filesVisible, - disabled: !props.gitControls.canOpenFiles, - separateBackground: false, - onPress: filesVisible ? toggleAuxiliaryPane : props.onOpenFilesInspector, - }, - ] - : []; + const actions: AppBarAction[] = [ + ...(props.hasThreadCwd + ? [ + { + accessibilityLabel: filesVisible ? "Close files" : "Open files", + icon: "folder" as const, + selected: filesVisible, + disabled: !props.gitControls.canOpenFiles, + separateBackground: false, + onPress: filesVisible ? toggleAuxiliaryPane : props.onOpenFilesInspector, + }, + ] + : []), + ...(linkedPullRequest !== null + ? [ + { + accessibilityLabel: resolveThreadPrBadgeAction(linkedPullRequest).accessibilityLabel, + icon: PullRequestGlyph.pullRequest, + separateBackground: false, + onPress: () => openThreadPullRequests(props.thread, linkedPullRequest), + }, + ] + : []), + ]; const menus = [gitMenu, terminalMenu].filter((menu): menu is AppBarMenu => menu !== null); return ( diff --git a/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx b/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx index dd20c0a162f7..81629ff60e87 100644 --- a/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx +++ b/apps/mobile/src/features/threads/ThreadPullRequestsSheet.tsx @@ -23,7 +23,7 @@ export function ThreadPullRequestsSheet( const insets = useSafeAreaInsets(); const { selectedThread, selectedThreadProject, selectedEnvironmentRuntime } = useThreadSelection(); - const lines = useLinkedPullRequestLines(selectedThread, selectedEnvironmentRuntime); + const lines = useLinkedPullRequestLines(selectedThread); const openCount = useMemo( () => lines.filter((line) => line.link.snapshot === null || line.link.snapshot.state === "open") diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx index 8dc3ac882c95..9f7088a4412c 100644 --- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx @@ -105,6 +105,7 @@ import { threadRouteOpensDraft, } from "./thread-route-hydration"; import { ThreadHeader } from "./ThreadHeader"; +import { withThreadOpenPullRequest } from "../../state/thread-pr-presentation"; import { resumeThread } from "./resume-thread"; import { useAndroidWorkspaceBack, @@ -779,7 +780,11 @@ function ThreadRouteContent( ? () => void handleMergeBack() : undefined, currentBranch: selectedThread?.branch ?? null, - gitStatus: gitStatus.data, + gitStatus: withThreadOpenPullRequest( + gitStatus.data ?? null, + selectedThread?.pullRequests ?? [], + routeEnvironmentRuntime?.serverConfig?.environment.capabilities.threadPullRequests === true, + ), gitOperationLabel: gitState.gitOperationLabel, canOpenTerminal: Boolean(selectedThreadProject?.workspaceRoot) && (canReadTerminal || canOperateTerminal), @@ -954,6 +959,7 @@ function ThreadRouteContent( ({ item: { @@ -116,18 +122,18 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { ? "This connection cannot change source control." : getGitActionDisabledReason({ item, - gitStatus: gitStatus.data, + gitStatus: gitStatusData, isBusy: busy, hasOriginRemote: hasPrimaryRemote, }), })); const { shortLabel, singular } = sourceControlClients.get( - gitStatus.data?.sourceControlProvider?.kind, + gitStatusData?.sourceControlProvider?.kind, ).changeRequest; const openExistingPr = async () => { - const prUrl = gitStatus.data?.pr?.state === "open" ? gitStatus.data.pr.url : null; + const prUrl = gitStatusData?.pr?.state === "open" ? gitStatusData.pr.url : null; if (!prUrl) { Dialog.alert(`No open ${shortLabel}`, `This branch does not have an open ${singular}.`); return; @@ -146,7 +152,7 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { input.action === "commit_push_pr" ? input.action : null; - const branchName = gitStatus.data?.refName; + const branchName = gitStatusData?.refName; if ( branchName && confirmableAction && @@ -199,7 +205,7 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { }; const rowStatusDetail = (item: (typeof menuItems)[number]): string | undefined => { - const status = gitStatus.data; + const status = gitStatusData; if (status == null) { return undefined; } @@ -217,7 +223,7 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { return undefined; }; - const behindCount = gitStatus.data?.behindCount ?? 0; + const behindCount = gitStatusData?.behindCount ?? 0; // Background refreshes also report pending; using that query flag would stick the RefreshControl spinner. const [isRefreshing, setIsRefreshing] = useState(false); diff --git a/apps/mobile/src/state/thread-pr-presentation.ts b/apps/mobile/src/state/thread-pr-presentation.ts index a44f410b54ca..5794fcf8a216 100644 --- a/apps/mobile/src/state/thread-pr-presentation.ts +++ b/apps/mobile/src/state/thread-pr-presentation.ts @@ -133,6 +133,33 @@ export function resolveThreadPrBadgeAction(pr: ThreadPrPresentation) { : { kind: "open" as const, accessibilityLabel: `Open ${pr.accessibilityLabel}` }; } +/** Checkout open PR wins; else an open linked PR. Unsynced links need snapshot support. */ +export function withThreadOpenPullRequest( + status: VcsStatusResult | null, + links: ReadonlyArray, + supportsSnapshots: boolean, +): VcsStatusResult | null { + if (status === null || status.pr?.state === "open") return status; + const link = resolveThreadCurrentPullRequestLink(links); + const snapshot = link?.snapshot ?? null; + if (link === null || (snapshot === null ? !supportsSnapshots : snapshot.state !== "open")) { + return status; + } + return { + ...status, + pr: { + number: link.number, + title: snapshot?.title ?? `#${link.number}`, + url: link.url, + baseRef: snapshot?.baseBranch ?? "unknown", + headRef: snapshot?.headBranch ?? "unknown", + state: "open", + isDraft: snapshot?.isDraft === true, + updatedAt: snapshot?.updatedAt ?? null, + }, + }; +} + /** Records `value` as the newest entry, evicting the least recently answered beyond `limit`. */ export function rememberBounded( current: ReadonlyMap, diff --git a/apps/mobile/src/state/use-thread-pr.test.ts b/apps/mobile/src/state/use-thread-pr.test.ts index 4edbb903dbeb..c01b11b2e9e0 100644 --- a/apps/mobile/src/state/use-thread-pr.test.ts +++ b/apps/mobile/src/state/use-thread-pr.test.ts @@ -3,7 +3,10 @@ import { type PullRequestSummary, SourceControlProviderKind, type ThreadPullRequestLink, + type VcsStatusResult, } from "@t3tools/contracts"; +import { buildMenuItems } from "@t3tools/client-runtime/state/vcs"; +import { threadPullRequestsOf } from "@t3tools/client-runtime/thread-pull-requests"; import { describe, expect, it } from "vite-plus/test"; import { @@ -11,6 +14,7 @@ import { presentThreadLinkedPullRequests, rememberBounded, resolveThreadPrSource, + withThreadOpenPullRequest, } from "./thread-pr-presentation"; function linkedPr( @@ -175,3 +179,75 @@ describe("rememberBounded", () => { ]); }); }); + +describe("withThreadOpenPullRequest", () => { + const status: VcsStatusResult = { + isRepo: true, + hasPrimaryRemote: true, + isDefaultRef: false, + refName: "local-work", + hasWorkingTreeChanges: false, + workingTree: { files: [], insertions: 0, deletions: 0 }, + hasUpstream: true, + aheadCount: 1, + behindCount: 0, + pr: null, + }; + const prLabel = (next: VcsStatusResult | null) => + buildMenuItems(next, false).find((item) => item.id === "pr")?.label; + + it("offers the linked open pull request when the checkout's ref has none", () => { + const next = withThreadOpenPullRequest(status, [linkedPr(42)], true); + expect(next?.pr).toMatchObject({ number: 42, url: linkedPr(42).url, state: "open" }); + expect(prLabel(next)).toBe("View PR"); + }); + + it("treats a link waiting for its first sync as open", () => { + expect( + withThreadOpenPullRequest(status, [linkedPr(42, { snapshot: null })], true)?.pr, + ).toMatchObject({ number: 42, state: "open" }); + }); + + it("keeps checkout status for a legacy link whose state the server cannot report", () => { + const legacy = threadPullRequestsOf({ + linkedPullRequest: { + projectId: ProjectId.make("project"), + repository: "t3tools/t3code", + number: 42, + url: linkedPr(42).url, + }, + }); + expect(withThreadOpenPullRequest(status, legacy, false)).toBe(status); + expect(prLabel(withThreadOpenPullRequest(status, legacy, false))).toBe("Create PR"); + }); + + it("keeps the checkout ref's own open pull request", () => { + const own: VcsStatusResult = { + ...status, + pr: { + number: 3, + title: "Own change", + url: "https://github.com/t3tools/t3code/pull/3", + baseRef: "main", + headRef: "local-work", + state: "open", + }, + }; + expect(withThreadOpenPullRequest(own, [linkedPr(42)], true)).toBe(own); + }); + + it("ignores links that are no longer open", () => { + const merged = linkedPr(42, { snapshot: { ...linkedPr(42).snapshot!, state: "merged" } }); + const closed = linkedPr(43, { snapshot: { ...linkedPr(43).snapshot!, state: "closed" } }); + expect(withThreadOpenPullRequest(status, [merged, closed], true)).toBe(status); + expect(prLabel(withThreadOpenPullRequest(status, [merged], true))).toBe("Create PR"); + }); + + it("prefers an open link over a merged one", () => { + const merged = linkedPr(41, { + linkedAt: "2026-09-10T00:00:00.000Z", + snapshot: { ...linkedPr(41).snapshot!, state: "merged" }, + }); + expect(withThreadOpenPullRequest(status, [merged, linkedPr(42)], true)?.pr?.number).toBe(42); + }); +}); From 649f7d935a52da5e3903b61d421ce075d29353a6 Mon Sep 17 00:00:00 2001 From: wSedlacek Date: Fri, 6 Nov 2026 05:16:27 -0800 Subject: [PATCH 2/4] fix(mobile): keep View PR in the thread git menu --- .../features/threads/ThreadGitControls.tsx | 16 ++++ .../features/threads/threadGitMenu.test.ts | 75 +++++++++++++++++++ .../src/features/threads/threadGitMenu.ts | 19 +++++ 3 files changed, 110 insertions(+) create mode 100644 apps/mobile/src/features/threads/threadGitMenu.test.ts create mode 100644 apps/mobile/src/features/threads/threadGitMenu.ts diff --git a/apps/mobile/src/features/threads/ThreadGitControls.tsx b/apps/mobile/src/features/threads/ThreadGitControls.tsx index 57d26e3b65d0..26bedbbdf7a6 100644 --- a/apps/mobile/src/features/threads/ThreadGitControls.tsx +++ b/apps/mobile/src/features/threads/ThreadGitControls.tsx @@ -26,6 +26,7 @@ import { type TerminalMenuSession, } from "../terminal/terminalMenu"; import { projectScriptMenuLabel } from "@t3tools/shared/projectScripts"; +import { resolveThreadGitViewPrItem } from "./threadGitMenu"; function truncateMiddle(value: string, maxLength: number): string { if (value.length <= maxLength) { @@ -239,6 +240,7 @@ function useThreadGitControlModel(props: ThreadGitMenuProps) { return { currentBranchLabel, isRepo, + openExistingPr, openGitInspector, openReview, quickAction, @@ -304,6 +306,7 @@ export function threadTerminalMenu(props: ThreadGitControlsProps): AppBarMenu | /** The thread's git menu, shared by the thread bar and Review. */ export function useThreadGitMenuDefinition(props: ThreadGitMenuProps): AppBarMenu | null { const model = useThreadGitControlModel(props); + const viewPr = resolveThreadGitViewPrItem(props.gitStatus, model.quickAction.kind); return { title: "Git controls", icon: "point.topleft.down.curvedto.point.bottomright.up", @@ -327,6 +330,19 @@ export function useThreadGitMenuDefinition(props: ThreadGitMenuProps): AppBarMen void model.runQuickAction(); }, }, + ...(viewPr + ? [ + { + id: "git-view-pr", + title: viewPr.title, + icon: PullRequestGlyph.pullRequest, + subtitle: viewPr.subtitle, + onPress: () => { + void model.openExistingPr(); + }, + }, + ] + : []), { id: "git-review", title: "Review changes", diff --git a/apps/mobile/src/features/threads/threadGitMenu.test.ts b/apps/mobile/src/features/threads/threadGitMenu.test.ts new file mode 100644 index 000000000000..5ab73a1ec29f --- /dev/null +++ b/apps/mobile/src/features/threads/threadGitMenu.test.ts @@ -0,0 +1,75 @@ +import { SourceControlProviderKind, type VcsStatusResult } from "@t3tools/contracts"; +import { resolveQuickAction } from "@t3tools/client-runtime/state/vcs"; +import { describe, expect, it } from "vite-plus/test"; + +import { resolveThreadGitViewPrItem } from "./threadGitMenu"; + +function status(overrides: Partial = {}): VcsStatusResult { + return { + isRepo: true, + hasPrimaryRemote: true, + isDefaultRef: false, + refName: "feature/test", + hasWorkingTreeChanges: false, + workingTree: { files: [], insertions: 0, deletions: 0 }, + hasUpstream: true, + aheadCount: 0, + behindCount: 0, + pr: null, + ...overrides, + }; +} + +const openPr = { + number: 42, + title: "Feature", + url: "https://github.com/t3tools/t3code/pull/42", + baseRef: "main", + headRef: "feature/test", + state: "open" as const, +}; + +describe("resolveThreadGitViewPrItem", () => { + it("stays out when the quick action is already View PR", () => { + const gitStatus = status({ pr: openPr }); + expect(resolveQuickAction(gitStatus, false).kind).toBe("open_pr"); + expect(resolveThreadGitViewPrItem(gitStatus, "open_pr")).toBeNull(); + }); + + it("keeps View PR in the first git menu when the quick action is Commit & push", () => { + const gitStatus = status({ + pr: openPr, + hasWorkingTreeChanges: true, + workingTree: { + files: [{ path: "a.ts", insertions: 1, deletions: 0 }], + insertions: 1, + deletions: 0, + }, + }); + expect(resolveQuickAction(gitStatus, false).kind).toBe("run_action"); + expect(resolveThreadGitViewPrItem(gitStatus, "run_action")).toEqual({ + title: "View PR", + subtitle: "PR #42", + }); + }); + + it("says View MR for a GitLab open change request", () => { + const gitStatus = status({ + pr: openPr, + aheadCount: 1, + sourceControlProvider: { + kind: SourceControlProviderKind.make("gitlab"), + name: "GitLab", + baseUrl: "https://gitlab.com", + }, + }); + expect(resolveThreadGitViewPrItem(gitStatus, "run_action")).toEqual({ + title: "View MR", + subtitle: "MR #42", + }); + }); + + it("omits the row when there is no open pull request", () => { + expect(resolveThreadGitViewPrItem(status(), "show_hint")).toBeNull(); + }); +}); diff --git a/apps/mobile/src/features/threads/threadGitMenu.ts b/apps/mobile/src/features/threads/threadGitMenu.ts new file mode 100644 index 000000000000..8565bb37f89c --- /dev/null +++ b/apps/mobile/src/features/threads/threadGitMenu.ts @@ -0,0 +1,19 @@ +import { + changeRequestTerminologyFor, + type GitQuickAction, +} from "@t3tools/client-runtime/state/vcs"; +import type { VcsStatusResult } from "@t3tools/contracts"; + +/** Own row when an open PR exists and the quick action is already something else. */ +export function resolveThreadGitViewPrItem( + gitStatus: VcsStatusResult | null, + quickActionKind: GitQuickAction["kind"], +): { readonly title: string; readonly subtitle: string } | null { + const pr = gitStatus?.pr; + if (pr?.state !== "open" || quickActionKind === "open_pr") return null; + const { shortLabel } = changeRequestTerminologyFor(gitStatus); + return { + title: `View ${shortLabel}`, + subtitle: `${shortLabel} #${pr.number}`, + }; +} From 67c09a242742d59300b0371ba56e3f988e74e5d7 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 03:30:33 +0000 Subject: [PATCH 3/4] test(mobile): trim redundant linked PR menu cases AI-assisted; verified with the tests and tools listed above. --- .../src/features/threads/threadGitMenu.test.ts | 18 +----------------- apps/mobile/src/state/use-thread-pr.test.ts | 2 -- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/apps/mobile/src/features/threads/threadGitMenu.test.ts b/apps/mobile/src/features/threads/threadGitMenu.test.ts index 5ab73a1ec29f..05de31bd2b24 100644 --- a/apps/mobile/src/features/threads/threadGitMenu.test.ts +++ b/apps/mobile/src/features/threads/threadGitMenu.test.ts @@ -1,4 +1,4 @@ -import { SourceControlProviderKind, type VcsStatusResult } from "@t3tools/contracts"; +import type { VcsStatusResult } from "@t3tools/contracts"; import { resolveQuickAction } from "@t3tools/client-runtime/state/vcs"; import { describe, expect, it } from "vite-plus/test"; @@ -53,22 +53,6 @@ describe("resolveThreadGitViewPrItem", () => { }); }); - it("says View MR for a GitLab open change request", () => { - const gitStatus = status({ - pr: openPr, - aheadCount: 1, - sourceControlProvider: { - kind: SourceControlProviderKind.make("gitlab"), - name: "GitLab", - baseUrl: "https://gitlab.com", - }, - }); - expect(resolveThreadGitViewPrItem(gitStatus, "run_action")).toEqual({ - title: "View MR", - subtitle: "MR #42", - }); - }); - it("omits the row when there is no open pull request", () => { expect(resolveThreadGitViewPrItem(status(), "show_hint")).toBeNull(); }); diff --git a/apps/mobile/src/state/use-thread-pr.test.ts b/apps/mobile/src/state/use-thread-pr.test.ts index c01b11b2e9e0..edf2a926dbea 100644 --- a/apps/mobile/src/state/use-thread-pr.test.ts +++ b/apps/mobile/src/state/use-thread-pr.test.ts @@ -218,7 +218,6 @@ describe("withThreadOpenPullRequest", () => { }, }); expect(withThreadOpenPullRequest(status, legacy, false)).toBe(status); - expect(prLabel(withThreadOpenPullRequest(status, legacy, false))).toBe("Create PR"); }); it("keeps the checkout ref's own open pull request", () => { @@ -240,7 +239,6 @@ describe("withThreadOpenPullRequest", () => { const merged = linkedPr(42, { snapshot: { ...linkedPr(42).snapshot!, state: "merged" } }); const closed = linkedPr(43, { snapshot: { ...linkedPr(43).snapshot!, state: "closed" } }); expect(withThreadOpenPullRequest(status, [merged, closed], true)).toBe(status); - expect(prLabel(withThreadOpenPullRequest(status, [merged], true))).toBe("Create PR"); }); it("prefers an open link over a merged one", () => { From ed9af30f25a4ba35fb9abc416f6d80454b656cf8 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 03:51:43 +0000 Subject: [PATCH 4/4] fix(mobile): keep git actions on the checkout's own PR A thread's linked PR can sit on another ref, so feeding it into the git status made the quick action and Git sheet drop Create PR for the current branch. The linked PR now only adds the View PR row and its open target. AI-assisted; verified with the tests and tools listed above. --- .../review/useReviewHeaderPresentation.tsx | 6 +- .../features/threads/DraftThreadHeader.tsx | 6 +- .../features/threads/ThreadGitControls.tsx | 16 +++++- .../features/threads/ThreadRouteScreen.tsx | 6 +- .../features/threads/git/GitOverviewSheet.tsx | 30 ++++------ .../features/threads/threadGitMenu.test.ts | 35 ++++++++++-- .../src/features/threads/threadGitMenu.ts | 16 +++++- .../src/state/thread-pr-presentation.ts | 29 ++++------ apps/mobile/src/state/use-thread-pr.test.ts | 56 +++++-------------- 9 files changed, 101 insertions(+), 99 deletions(-) diff --git a/apps/mobile/src/features/review/useReviewHeaderPresentation.tsx b/apps/mobile/src/features/review/useReviewHeaderPresentation.tsx index 68979559f415..cf25d74ac111 100644 --- a/apps/mobile/src/features/review/useReviewHeaderPresentation.tsx +++ b/apps/mobile/src/features/review/useReviewHeaderPresentation.tsx @@ -2,7 +2,7 @@ import { useEnvironmentQuery } from "../../state/query"; import { useSelectedThreadGitActions } from "../../state/use-selected-thread-git-actions"; import { useSelectedThreadGitState } from "../../state/use-selected-thread-git-state"; import { useThreadSelection } from "../../state/use-thread-selection"; -import { withThreadOpenPullRequest } from "../../state/thread-pr-presentation"; +import { resolveThreadOpenLinkedPullRequest } from "../../state/thread-pr-presentation"; import { vcsEnvironment } from "../../state/vcs"; import { useThreadGitMenuDefinition } from "../threads/ThreadGitControls"; import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; @@ -46,8 +46,8 @@ export function useReviewHeaderPresentation(props: { environmentId: props.environmentId, threadId: props.threadId, currentBranch: selectedThread?.branch ?? null, - gitStatus: withThreadOpenPullRequest( - gitStatusQuery.data ?? null, + gitStatus: gitStatusQuery.data, + linkedPullRequest: resolveThreadOpenLinkedPullRequest( selectedThread?.pullRequests ?? [], selectedEnvironmentRuntime?.serverConfig?.environment.capabilities.threadPullRequests === true, diff --git a/apps/mobile/src/features/threads/DraftThreadHeader.tsx b/apps/mobile/src/features/threads/DraftThreadHeader.tsx index 5950a7a6e030..67eaa2b6923f 100644 --- a/apps/mobile/src/features/threads/DraftThreadHeader.tsx +++ b/apps/mobile/src/features/threads/DraftThreadHeader.tsx @@ -12,7 +12,7 @@ import { useEnvironmentQuery } from "../../state/query"; import { useEnvironmentScope } from "../../state/session"; import { useAtomCommand } from "../../state/use-atom-command"; import { useRemoteEnvironmentRuntime } from "../../state/use-remote-environment-registry"; -import { withThreadOpenPullRequest } from "../../state/thread-pr-presentation"; +import { resolveThreadOpenLinkedPullRequest } from "../../state/thread-pr-presentation"; import { vcsActionManager, vcsEnvironment } from "../../state/vcs"; import { useVcsActionState } from "../../state/use-vcs-action-state"; import { ThreadHeader } from "./ThreadHeader"; @@ -60,8 +60,8 @@ export function DraftThreadHeader(props: { threadId: props.thread.id, hasThread: false, currentBranch: props.thread.branch, - gitStatus: withThreadOpenPullRequest( - status.data ?? null, + gitStatus: status.data, + linkedPullRequest: resolveThreadOpenLinkedPullRequest( props.thread.pullRequests, runtime?.serverConfig?.environment.capabilities.threadPullRequests === true, ), diff --git a/apps/mobile/src/features/threads/ThreadGitControls.tsx b/apps/mobile/src/features/threads/ThreadGitControls.tsx index 26bedbbdf7a6..7a1115fe1f2f 100644 --- a/apps/mobile/src/features/threads/ThreadGitControls.tsx +++ b/apps/mobile/src/features/threads/ThreadGitControls.tsx @@ -26,7 +26,8 @@ import { type TerminalMenuSession, } from "../terminal/terminalMenu"; import { projectScriptMenuLabel } from "@t3tools/shared/projectScripts"; -import { resolveThreadGitViewPrItem } from "./threadGitMenu"; +import type { ThreadPr } from "../../state/thread-pr-presentation"; +import { resolveThreadGitViewablePr, resolveThreadGitViewPrItem } from "./threadGitMenu"; function truncateMiddle(value: string, maxLength: number): string { if (value.length <= maxLength) { @@ -84,6 +85,8 @@ export type ThreadGitMenuProps = { readonly currentBranch: string | null; readonly hasThread?: boolean; readonly gitStatus: VcsStatusResult | null; + /** Open PR linked to the thread, possibly on another ref; only adds a View PR row. */ + readonly linkedPullRequest?: ThreadPr | null; readonly gitOperationLabel: string | null; readonly onOpenFilesInspector?: () => void; readonly onOpenGitInspector?: () => void; @@ -154,11 +157,13 @@ function useThreadGitControlModel(props: ThreadGitMenuProps) { return "arrow.up.right.circle"; })(); + const viewablePr = resolveThreadGitViewablePr(gitStatus, props.linkedPullRequest ?? null); + const openExistingPr = async () => { const { shortLabel, singular } = sourceControlClients.get( gitStatus?.sourceControlProvider?.kind, ).changeRequest; - const prUrl = gitStatus?.pr?.state === "open" ? gitStatus.pr.url : null; + const prUrl = viewablePr?.url ?? null; if (!prUrl) { Dialog.alert(`No open ${shortLabel}`, `This branch does not have an open ${singular}.`); return; @@ -244,6 +249,7 @@ function useThreadGitControlModel(props: ThreadGitMenuProps) { openGitInspector, openReview, quickAction, + viewablePr, quickActionHint, quickActionIcon, runQuickAction, @@ -306,7 +312,11 @@ export function threadTerminalMenu(props: ThreadGitControlsProps): AppBarMenu | /** The thread's git menu, shared by the thread bar and Review. */ export function useThreadGitMenuDefinition(props: ThreadGitMenuProps): AppBarMenu | null { const model = useThreadGitControlModel(props); - const viewPr = resolveThreadGitViewPrItem(props.gitStatus, model.quickAction.kind); + const viewPr = resolveThreadGitViewPrItem( + props.gitStatus, + model.viewablePr, + model.quickAction.kind, + ); return { title: "Git controls", icon: "point.topleft.down.curvedto.point.bottomright.up", diff --git a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx index 78a624c40fd7..9e81c72c666e 100644 --- a/apps/mobile/src/features/threads/ThreadRouteScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadRouteScreen.tsx @@ -109,7 +109,7 @@ import { threadRouteOpensDraft, } from "./thread-route-hydration"; import { ThreadHeader } from "./ThreadHeader"; -import { withThreadOpenPullRequest } from "../../state/thread-pr-presentation"; +import { resolveThreadOpenLinkedPullRequest } from "../../state/thread-pr-presentation"; import { resumeThread } from "./resume-thread"; import { useAndroidWorkspaceBack, @@ -784,8 +784,8 @@ function ThreadRouteContent( ? () => void handleMergeBack() : undefined, currentBranch: selectedThread?.branch ?? null, - gitStatus: withThreadOpenPullRequest( - gitStatus.data ?? null, + gitStatus: gitStatus.data, + linkedPullRequest: resolveThreadOpenLinkedPullRequest( selectedThread?.pullRequests ?? [], routeEnvironmentRuntime?.serverConfig?.environment.capabilities.threadPullRequests === true, ), diff --git a/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx b/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx index 4f99d8696e35..c51d502ab8a7 100644 --- a/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx +++ b/apps/mobile/src/features/threads/git/GitOverviewSheet.tsx @@ -32,7 +32,6 @@ import { useSelectedThreadGitActions } from "../../../state/use-selected-thread- import { useSelectedThreadGitState } from "../../../state/use-selected-thread-git-state"; import { useSelectedThreadWorktree } from "../../../state/use-selected-thread-worktree"; import { vcsEnvironment } from "../../../state/vcs"; -import { withThreadOpenPullRequest } from "../../../state/thread-pr-presentation"; import { menuItemIconName, statusSummary } from "./gitSheetComponents"; import { LinkedPullRequestRow, @@ -95,22 +94,17 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { }) : null, ); - const gitStatusData = withThreadOpenPullRequest( - gitStatus.data ?? null, - selectedThread?.pullRequests ?? [], - selectedEnvironmentRuntime?.serverConfig?.environment.capabilities.threadPullRequests === true, - ); - const currentBranchLabel = gitStatusData?.refName ?? selectedThread?.branch ?? "Detached HEAD"; - const currentStatusSummary = statusSummary(gitStatusData); + const currentBranchLabel = gitStatus.data?.refName ?? selectedThread?.branch ?? "Detached HEAD"; + const currentStatusSummary = statusSummary(gitStatus.data); const currentWorktreePath = selectedThreadWorktreePath; const gitOperationLabel = gitState.gitOperationLabel; const busy = gitOperationLabel !== null; - const isRepo = gitStatusData?.isRepo ?? true; - const hasPrimaryRemote = gitStatusData?.hasPrimaryRemote ?? false; - const isDefaultRef = gitStatusData?.isDefaultRef ?? false; + const isRepo = gitStatus.data?.isRepo ?? true; + const hasPrimaryRemote = gitStatus.data?.hasPrimaryRemote ?? false; + const isDefaultRef = gitStatus.data?.isDefaultRef ?? false; - const menuItems = isRepo ? buildMenuItems(gitStatusData, busy, hasPrimaryRemote) : []; + const menuItems = isRepo ? buildMenuItems(gitStatus.data, busy, hasPrimaryRemote) : []; const sheetMenuItems = menuItems.map((item) => ({ item: { @@ -122,18 +116,18 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { ? "This connection cannot change source control." : getGitActionDisabledReason({ item, - gitStatus: gitStatusData, + gitStatus: gitStatus.data, isBusy: busy, hasOriginRemote: hasPrimaryRemote, }), })); const { shortLabel, singular } = sourceControlClients.get( - gitStatusData?.sourceControlProvider?.kind, + gitStatus.data?.sourceControlProvider?.kind, ).changeRequest; const openExistingPr = async () => { - const prUrl = gitStatusData?.pr?.state === "open" ? gitStatusData.pr.url : null; + const prUrl = gitStatus.data?.pr?.state === "open" ? gitStatus.data.pr.url : null; if (!prUrl) { Dialog.alert(`No open ${shortLabel}`, `This branch does not have an open ${singular}.`); return; @@ -152,7 +146,7 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { input.action === "commit_push_pr" ? input.action : null; - const branchName = gitStatusData?.refName; + const branchName = gitStatus.data?.refName; if ( branchName && confirmableAction && @@ -205,7 +199,7 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { }; const rowStatusDetail = (item: (typeof menuItems)[number]): string | undefined => { - const status = gitStatusData; + const status = gitStatus.data; if (status == null) { return undefined; } @@ -223,7 +217,7 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) { return undefined; }; - const behindCount = gitStatusData?.behindCount ?? 0; + const behindCount = gitStatus.data?.behindCount ?? 0; // Background refreshes also report pending; using that query flag would stick the RefreshControl spinner. const [isRefreshing, setIsRefreshing] = useState(false); diff --git a/apps/mobile/src/features/threads/threadGitMenu.test.ts b/apps/mobile/src/features/threads/threadGitMenu.test.ts index 05de31bd2b24..c7d55cc30c1d 100644 --- a/apps/mobile/src/features/threads/threadGitMenu.test.ts +++ b/apps/mobile/src/features/threads/threadGitMenu.test.ts @@ -2,7 +2,7 @@ import type { VcsStatusResult } from "@t3tools/contracts"; import { resolveQuickAction } from "@t3tools/client-runtime/state/vcs"; import { describe, expect, it } from "vite-plus/test"; -import { resolveThreadGitViewPrItem } from "./threadGitMenu"; +import { resolveThreadGitViewablePr, resolveThreadGitViewPrItem } from "./threadGitMenu"; function status(overrides: Partial = {}): VcsStatusResult { return { @@ -29,11 +29,13 @@ const openPr = { state: "open" as const, }; -describe("resolveThreadGitViewPrItem", () => { +describe("thread git menu View PR row", () => { it("stays out when the quick action is already View PR", () => { const gitStatus = status({ pr: openPr }); expect(resolveQuickAction(gitStatus, false).kind).toBe("open_pr"); - expect(resolveThreadGitViewPrItem(gitStatus, "open_pr")).toBeNull(); + expect( + resolveThreadGitViewPrItem(gitStatus, resolveThreadGitViewablePr(gitStatus, null), "open_pr"), + ).toBeNull(); }); it("keeps View PR in the first git menu when the quick action is Commit & push", () => { @@ -47,13 +49,34 @@ describe("resolveThreadGitViewPrItem", () => { }, }); expect(resolveQuickAction(gitStatus, false).kind).toBe("run_action"); - expect(resolveThreadGitViewPrItem(gitStatus, "run_action")).toEqual({ + expect( + resolveThreadGitViewPrItem( + gitStatus, + resolveThreadGitViewablePr(gitStatus, null), + "run_action", + ), + ).toEqual({ title: "View PR", subtitle: "PR #42" }); + }); + + it("adds the linked PR beside Push & create PR for a branch without its own PR", () => { + const gitStatus = status({ refName: "feature-b", aheadCount: 1 }); + const linked = { ...openPr, number: 7, headRef: "feature-a" }; + const quickAction = resolveQuickAction(gitStatus, false); + expect(quickAction.label).toBe("Push & create PR"); + const viewable = resolveThreadGitViewablePr(gitStatus, linked); + expect(viewable).toBe(linked); + expect(resolveThreadGitViewPrItem(gitStatus, viewable, quickAction.kind)).toEqual({ title: "View PR", - subtitle: "PR #42", + subtitle: "PR #7", }); }); + it("prefers the checkout's own open PR over a linked one", () => { + const gitStatus = status({ pr: openPr }); + expect(resolveThreadGitViewablePr(gitStatus, { ...openPr, number: 7 })).toBe(gitStatus.pr); + }); + it("omits the row when there is no open pull request", () => { - expect(resolveThreadGitViewPrItem(status(), "show_hint")).toBeNull(); + expect(resolveThreadGitViewPrItem(status(), null, "show_hint")).toBeNull(); }); }); diff --git a/apps/mobile/src/features/threads/threadGitMenu.ts b/apps/mobile/src/features/threads/threadGitMenu.ts index 8565bb37f89c..db104b5676f2 100644 --- a/apps/mobile/src/features/threads/threadGitMenu.ts +++ b/apps/mobile/src/features/threads/threadGitMenu.ts @@ -4,13 +4,23 @@ import { } from "@t3tools/client-runtime/state/vcs"; import type { VcsStatusResult } from "@t3tools/contracts"; -/** Own row when an open PR exists and the quick action is already something else. */ +import type { ThreadPr } from "../../state/thread-pr-presentation"; + +/** The checkout's open PR, else the thread's open linked PR; never feeds git action decisions. */ +export function resolveThreadGitViewablePr( + gitStatus: VcsStatusResult | null, + linkedPullRequest: ThreadPr | null, +): ThreadPr | null { + return gitStatus?.pr?.state === "open" ? gitStatus.pr : linkedPullRequest; +} + +/** Own row when a viewable PR exists and the quick action is not already View PR. */ export function resolveThreadGitViewPrItem( gitStatus: VcsStatusResult | null, + pr: ThreadPr | null, quickActionKind: GitQuickAction["kind"], ): { readonly title: string; readonly subtitle: string } | null { - const pr = gitStatus?.pr; - if (pr?.state !== "open" || quickActionKind === "open_pr") return null; + if (pr === null || quickActionKind === "open_pr") return null; const { shortLabel } = changeRequestTerminologyFor(gitStatus); return { title: `View ${shortLabel}`, diff --git a/apps/mobile/src/state/thread-pr-presentation.ts b/apps/mobile/src/state/thread-pr-presentation.ts index 5794fcf8a216..4f7d14f06ae4 100644 --- a/apps/mobile/src/state/thread-pr-presentation.ts +++ b/apps/mobile/src/state/thread-pr-presentation.ts @@ -133,30 +133,25 @@ export function resolveThreadPrBadgeAction(pr: ThreadPrPresentation) { : { kind: "open" as const, accessibilityLabel: `Open ${pr.accessibilityLabel}` }; } -/** Checkout open PR wins; else an open linked PR. Unsynced links need snapshot support. */ -export function withThreadOpenPullRequest( - status: VcsStatusResult | null, +/** The thread's open linked PR; unsynced links count only where the server syncs snapshots. */ +export function resolveThreadOpenLinkedPullRequest( links: ReadonlyArray, supportsSnapshots: boolean, -): VcsStatusResult | null { - if (status === null || status.pr?.state === "open") return status; +): ThreadPr | null { const link = resolveThreadCurrentPullRequestLink(links); const snapshot = link?.snapshot ?? null; if (link === null || (snapshot === null ? !supportsSnapshots : snapshot.state !== "open")) { - return status; + return null; } return { - ...status, - pr: { - number: link.number, - title: snapshot?.title ?? `#${link.number}`, - url: link.url, - baseRef: snapshot?.baseBranch ?? "unknown", - headRef: snapshot?.headBranch ?? "unknown", - state: "open", - isDraft: snapshot?.isDraft === true, - updatedAt: snapshot?.updatedAt ?? null, - }, + number: link.number, + title: snapshot?.title ?? `#${link.number}`, + url: link.url, + baseRef: snapshot?.baseBranch ?? "unknown", + headRef: snapshot?.headBranch ?? "unknown", + state: "open", + isDraft: snapshot?.isDraft === true, + updatedAt: snapshot?.updatedAt ?? null, }; } diff --git a/apps/mobile/src/state/use-thread-pr.test.ts b/apps/mobile/src/state/use-thread-pr.test.ts index edf2a926dbea..312cca5a8d3c 100644 --- a/apps/mobile/src/state/use-thread-pr.test.ts +++ b/apps/mobile/src/state/use-thread-pr.test.ts @@ -3,9 +3,7 @@ import { type PullRequestSummary, SourceControlProviderKind, type ThreadPullRequestLink, - type VcsStatusResult, } from "@t3tools/contracts"; -import { buildMenuItems } from "@t3tools/client-runtime/state/vcs"; import { threadPullRequestsOf } from "@t3tools/client-runtime/thread-pull-requests"; import { describe, expect, it } from "vite-plus/test"; @@ -14,7 +12,7 @@ import { presentThreadLinkedPullRequests, rememberBounded, resolveThreadPrSource, - withThreadOpenPullRequest, + resolveThreadOpenLinkedPullRequest, } from "./thread-pr-presentation"; function linkedPr( @@ -180,35 +178,22 @@ describe("rememberBounded", () => { }); }); -describe("withThreadOpenPullRequest", () => { - const status: VcsStatusResult = { - isRepo: true, - hasPrimaryRemote: true, - isDefaultRef: false, - refName: "local-work", - hasWorkingTreeChanges: false, - workingTree: { files: [], insertions: 0, deletions: 0 }, - hasUpstream: true, - aheadCount: 1, - behindCount: 0, - pr: null, - }; - const prLabel = (next: VcsStatusResult | null) => - buildMenuItems(next, false).find((item) => item.id === "pr")?.label; - - it("offers the linked open pull request when the checkout's ref has none", () => { - const next = withThreadOpenPullRequest(status, [linkedPr(42)], true); - expect(next?.pr).toMatchObject({ number: 42, url: linkedPr(42).url, state: "open" }); - expect(prLabel(next)).toBe("View PR"); +describe("resolveThreadOpenLinkedPullRequest", () => { + it("returns the linked open pull request", () => { + expect(resolveThreadOpenLinkedPullRequest([linkedPr(42)], true)).toMatchObject({ + number: 42, + url: linkedPr(42).url, + state: "open", + }); }); it("treats a link waiting for its first sync as open", () => { expect( - withThreadOpenPullRequest(status, [linkedPr(42, { snapshot: null })], true)?.pr, + resolveThreadOpenLinkedPullRequest([linkedPr(42, { snapshot: null })], true), ).toMatchObject({ number: 42, state: "open" }); }); - it("keeps checkout status for a legacy link whose state the server cannot report", () => { + it("ignores a legacy link whose state the server cannot report", () => { const legacy = threadPullRequestsOf({ linkedPullRequest: { projectId: ProjectId.make("project"), @@ -217,28 +202,13 @@ describe("withThreadOpenPullRequest", () => { url: linkedPr(42).url, }, }); - expect(withThreadOpenPullRequest(status, legacy, false)).toBe(status); - }); - - it("keeps the checkout ref's own open pull request", () => { - const own: VcsStatusResult = { - ...status, - pr: { - number: 3, - title: "Own change", - url: "https://github.com/t3tools/t3code/pull/3", - baseRef: "main", - headRef: "local-work", - state: "open", - }, - }; - expect(withThreadOpenPullRequest(own, [linkedPr(42)], true)).toBe(own); + expect(resolveThreadOpenLinkedPullRequest(legacy, false)).toBeNull(); }); it("ignores links that are no longer open", () => { const merged = linkedPr(42, { snapshot: { ...linkedPr(42).snapshot!, state: "merged" } }); const closed = linkedPr(43, { snapshot: { ...linkedPr(43).snapshot!, state: "closed" } }); - expect(withThreadOpenPullRequest(status, [merged, closed], true)).toBe(status); + expect(resolveThreadOpenLinkedPullRequest([merged, closed], true)).toBeNull(); }); it("prefers an open link over a merged one", () => { @@ -246,6 +216,6 @@ describe("withThreadOpenPullRequest", () => { linkedAt: "2026-09-10T00:00:00.000Z", snapshot: { ...linkedPr(41).snapshot!, state: "merged" }, }); - expect(withThreadOpenPullRequest(status, [merged, linkedPr(42)], true)?.pr?.number).toBe(42); + expect(resolveThreadOpenLinkedPullRequest([merged, linkedPr(42)], true)?.number).toBe(42); }); });