Skip to content

Commit 35f0572

Browse files
committed
fix(review): address cross-client review findings
1 parent 44d579d commit 35f0572

14 files changed

Lines changed: 121 additions & 38 deletions

‎apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,12 @@ function PullRequestRouteContent({ route }: StaticScreenProps<PullRequestParams>
358358
rememberPullRequestView(viewMemoryKey, { section: next });
359359
};
360360
const topInset = insets.top;
361-
if (!guidesEnabled && section === "guide") setSection("overview");
361+
if (!guidesEnabled && section === "guide") {
362+
setSection("overview");
363+
setVisitedSections((current) =>
364+
current.has("overview") ? current : new Set(current).add("overview"),
365+
);
366+
}
362367
useLayoutEffect(() => {
363368
if (!guidesEnabled && requestedSection.current === "guide") {
364369
requestedSection.current = "overview";

‎apps/mobile/src/features/pull-requests/guide/PullRequestGuideChapterScreen.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ export function PullRequestGuideStopScreen({ route }: StaticScreenProps<GuideSto
127127
</Text>
128128
</Pressable>
129129
{expanded ? (
130-
<PullRequestMarkdownRepository value={params.repository} params={params}>
130+
<PullRequestMarkdownRepository
131+
value={detail.data?.provider === "github" ? detail.data.url : null}
132+
params={params}
133+
>
131134
<View className="gap-2 pt-2">
132135
{stop.attention ? <PullRequestMarkdown markdown={stop.attention.note} /> : null}
133136
{stop.notes.map((note) => (

‎apps/mobile/src/features/pull-requests/guide/PullRequestGuideScreen.tsx‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GuideViewOptionsButton } from "./GuideViewOptions";
66
import { AppText as Text } from "../../../components/AppText";
77
import { GuideOutline } from "./GuideOutline";
88
import { GuideGeneratingFiles } from "./GuideGeneratingFiles";
9-
import { reviewGuideState } from "./reviewGuideState";
9+
import { reviewGuideState, shouldAutoGenerateGuide } from "./reviewGuideState";
1010
import { GuideNotice } from "./GuideNotice";
1111
import Animated from "react-native-reanimated";
1212
import { PR_ROW_ENTER, PR_ROW_EXIT, PR_ROW_LAYOUT } from "../pullRequestAnimations";
@@ -55,14 +55,8 @@ export function PullRequestGuideContent({
5555
if (active && hasMissingFiles && diff.canLoadMore) loadMore();
5656
}, [active, hasMissingFiles, diff.canLoadMore, loadMore]);
5757
const attempted = useRef<string | null>(null);
58-
const generationKey = `${params.environmentId}:${params.repository}:${params.number}`;
59-
const shouldGenerate =
60-
active &&
61-
state.data !== null &&
62-
!guide &&
63-
!state.running &&
64-
state.canWrite &&
65-
state.data.run?._tag !== "Failed";
58+
const generationKey = `${params.environmentId}:${params.repository}:${params.number}:${state.data?.currentHeadSha}`;
59+
const shouldGenerate = active && shouldAutoGenerateGuide(state);
6660
const generate = useEffectEvent(() => {
6761
void state.write();
6862
});

‎apps/mobile/src/features/pull-requests/guide/reviewGuideState.test.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
ProviderInstanceId,
55
type PullRequestReviewGuideResult,
66
} from "@t3tools/contracts";
7-
import { guideNoticeState, reviewGuideState } from "./reviewGuideState";
7+
import { guideNoticeState, reviewGuideState, shouldAutoGenerateGuide } from "./reviewGuideState";
88

99
const guide: NonNullable<PullRequestReviewGuideResult["guide"]> = {
1010
headSha: "old-head",
@@ -99,6 +99,32 @@ describe("guide notice transitions", () => {
9999
expect(guideNoticeState({ ...view, data, running: true }).kind).toBe("writing");
100100
});
101101

102+
it("automatically writes for a new head after a previous head failed", () => {
103+
const data: PullRequestReviewGuideResult = {
104+
guide: null,
105+
currentHeadSha: "new-head",
106+
run: {
107+
_tag: "Failed",
108+
headSha: "old-head",
109+
failedAt: guide.generatedAt,
110+
detail: "Writer disconnected",
111+
},
112+
};
113+
expect(shouldAutoGenerateGuide({ ...view, data })).toBe(true);
114+
expect(guideNoticeState({ ...view, data }).kind).toBe("writing");
115+
const failedHead = { ...data, currentHeadSha: "old-head" };
116+
expect(shouldAutoGenerateGuide({ ...view, data: failedHead })).toBe(false);
117+
expect(guideNoticeState({ ...view, data: failedHead }).kind).toBe("failed");
118+
});
119+
120+
it("does not auto-start without data or permission, during a run, or over a saved guide", () => {
121+
expect(shouldAutoGenerateGuide(view)).toBe(false);
122+
const data = { guide: null, run: null, currentHeadSha: "head" };
123+
expect(shouldAutoGenerateGuide({ ...view, data, canWrite: false })).toBe(false);
124+
expect(shouldAutoGenerateGuide({ ...view, data, running: true })).toBe(false);
125+
expect(shouldAutoGenerateGuide({ ...view, data: { ...data, guide } })).toBe(false);
126+
});
127+
102128
it("keeps a stale guide readable through rewriting and completion", () => {
103129
const data = { guide, currentHeadSha: "head", run: null };
104130
expect(guideNoticeState({ ...view, data }).kind).toBe("stale");

‎apps/mobile/src/features/pull-requests/guide/reviewGuideState.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ export function reviewGuideState(data: PullRequestReviewGuideResult | null) {
1313
};
1414
}
1515

16+
/** The generating notice and auto-start effect must agree on failures from older heads. */
17+
export function shouldAutoGenerateGuide(state: {
18+
readonly data: PullRequestReviewGuideResult | null;
19+
readonly running: boolean;
20+
readonly canWrite: boolean;
21+
}) {
22+
const { guide, failure } = reviewGuideState(state.data);
23+
return state.data !== null && !guide && !state.running && state.canWrite && failure === null;
24+
}
25+
26+
/** A pending refresh must not hide cached content, or a new run reveal an old failure. */
1627
export function guideNoticeState(state: {
1728
readonly data: PullRequestReviewGuideResult | null;
1829
readonly isPending: boolean;
@@ -67,7 +78,7 @@ export function guideNoticeState(state: {
6778
}
6879
// The screen starts the writer automatically; do not offer a manual action between
6980
// the initial empty response and the generation effect committing its busy state.
70-
if (!guide && state.canWrite) {
81+
if (shouldAutoGenerateGuide(state)) {
7182
return {
7283
kind: "writing" as const,
7384
title: "Generating guide",

‎apps/server/src/review/ReviewService.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ export const make = Effect.gen(function* () {
105105
return yield* new VcsRepositoryDetectionError({
106106
operation,
107107
cwd,
108-
detail:
109-
operation === "ReviewService.getDiffPreview"
110-
? "Review diff preview cwd must stay within the configured workspace root."
111-
: "Review diff file contents cwd must stay within the configured workspace root.",
108+
detail: "Review operations must stay within the configured workspace root.",
112109
});
113110
});
114111

‎apps/web/src/components/diffs/WorkingChangesReview.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function useWorkingChanges(
108108
}),
109109
);
110110
const refresh = query.refresh;
111-
const revision = scope ? props.revision : null;
111+
const revision = props.revision;
112112
useEffect(() => {
113113
refresh();
114114
}, [refresh, revision, generation]);

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,9 +1863,7 @@ export function PullRequestDetailPanel({
18631863
{handoffSummary.state === "open" && handoffSummary.mergeability === "conflicting"
18641864
? resolveConflictsControl
18651865
: null}
1866-
{primaryAction === "auto-merge-armed" && showsMergeNow
1867-
? renderMergeControl(false)
1868-
: null}
1866+
{showsMergeNow ? renderMergeControl(false) : null}
18691867
{checkoutControl}
18701868
</TooltipProvider>
18711869
) : undefined
@@ -2169,9 +2167,7 @@ export function PullRequestDetailPanel({
21692167
) : null}
21702168
{/* Keep checkout beside the menu so host actions arriving on its left cannot
21712169
move a different action under the reader's pointer. */}
2172-
{primaryAction === "auto-merge-armed" && showsMergeNow
2173-
? renderMergeControl(false)
2174-
: null}
2170+
{showsMergeNow ? renderMergeControl(false) : null}
21752171
{checkoutControl}
21762172
<Menu>
21772173
<Tooltip>
@@ -2291,9 +2287,10 @@ export function PullRequestDetailPanel({
22912287
) : null}
22922288
{showsMergeMethods ? (
22932289
<>
2294-
{showsDraftToggle || showsMergeNow || showsAutoMerge ? (
2295-
<MenuSeparator />
2296-
) : null}
2290+
{/* Only below the draft control. A host with no draft of its own, or
2291+
a draft whose control is already the header button, would leave
2292+
this against the separator that opened the group. */}
2293+
{showsDraftToggle || showsAutoMerge ? <MenuSeparator /> : null}
22972294
<MenuRadioGroup
22982295
value={selectedMergeMethod}
22992296
onValueChange={(method) => {
@@ -2320,7 +2317,7 @@ export function PullRequestDetailPanel({
23202317
) : null}
23212318
{pullRequestActionMenuHasGroup(
23222319
showsDraftToggle,
2323-
showsAutoMerge || showsMergeNow,
2320+
showsAutoMerge,
23242321
showsMergeMethods,
23252322
) ? (
23262323
<MenuSeparator />

‎apps/web/src/components/pullRequest/PullRequestTimelineTab.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ export function PullRequestTimelineTab({
733733
environmentId={environmentId}
734734
reference={reference}
735735
canCopyLink={
736-
detail.capabilities.review.inlineComment && detail.viewerPermissions.comment
736+
detail.capabilities.review.draftComment === true && detail.viewerPermissions.comment
737737
}
738738
onAddToComposer={
739739
onAddPendingToComposer ? () => onAddPendingToComposer(comment) : undefined

‎apps/web/src/diffPanelStore.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ describe("diffPanelStore", () => {
100100
).toEqual({ kind: "unstaged" });
101101
});
102102

103+
it("keeps the unsaved Uncommitted snapshot stable until initialization", () => {
104+
const { byThreadKey, initializeGitScope } = useDiffPanelStore.getState();
105+
const initial = selectThreadDiffPanelSelection(byThreadKey, THREAD_REF, true);
106+
expect(initial).toEqual({ kind: "unstaged" });
107+
expect(selectThreadDiffPanelSelection(byThreadKey, THREAD_REF, true)).toBe(initial);
108+
109+
initializeGitScope(THREAD_REF, true);
110+
expect(
111+
selectThreadDiffPanelSelection(useDiffPanelStore.getState().byThreadKey, THREAD_REF, true),
112+
).toBe(initial);
113+
});
114+
103115
it("opens clean threads to Changes and keeps the initial choice after status changes", () => {
104116
const store = useDiffPanelStore.getState();
105117
store.initializeGitScope(THREAD_REF, false);

0 commit comments

Comments
 (0)