Skip to content

Commit 9b7887a

Browse files
versecafeclaude
andcommitted
fix(gitcafe): address review on stack discovery, lifecycle actions, review dispatch and images
- A discovered latest stack operation never settles a lost request; the record stays unknown until dismissed. - Merged pull requests offer no lifecycle actions; closed ones only reopen. - Review failures before this attempt's first write report notDispatched. - GitCafe PR images keep authored attributes and skip the workspace frame. - GitCafeCli.make is module-private. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 19eee7b commit 9b7887a

9 files changed

Lines changed: 106 additions & 29 deletions

File tree

‎apps/server/src/pullRequest/GitCafePullRequestProvider.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ describe("deployed GitCafe PR API", () => {
8484
expect(permissions.actions).toEqual([]);
8585
});
8686

87+
it("offers no lifecycle actions on a merged pull request and only reopen on a closed one", () => {
88+
const actions = (state: "open" | "closed" | "merged") =>
89+
gitCafeViewerPermissions({
90+
...detail,
91+
state,
92+
author: { ...detail.author, kind: "local" },
93+
mergeRoute: "native",
94+
capabilities: { comment: false, review: false, merge: true, edit: true, moderate: false },
95+
}).actions;
96+
expect(actions("merged")).toEqual([]);
97+
expect(actions("closed")).toEqual(["reopen"]);
98+
expect(actions("open")).toEqual(["draft", "close", "merge"]);
99+
});
100+
87101
it("keeps a locked conversation's composer for moderators only", () => {
88102
const locked = (moderate: boolean) =>
89103
gitCafeViewerPermissions({

‎apps/server/src/pullRequest/GitCafePullRequestProvider.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ export function gitCafeViewerPermissions(
213213
const merge = capabilities?.merge ?? false;
214214
return {
215215
actions: [
216-
...(edit
217-
? ([
218-
pull?.draft ? "ready" : "draft",
219-
pull?.state === "closed" ? "reopen" : "close",
220-
] as const)
221-
: []),
216+
// A merged pull request is settled; a closed one can only be reopened.
217+
...(edit && pull?.state === "open"
218+
? ([pull.draft ? "ready" : "draft", "close"] as const)
219+
: edit && pull?.state === "closed"
220+
? (["reopen"] as const)
221+
: []),
222222
...(merge && pull?.state === "open" && !pull.draft ? (["merge"] as const) : []),
223223
],
224224
stackRebase: merge,

‎apps/server/src/pullRequest/gitCafeActionWrites.ts‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { NonNegativeInt, PositiveInt, type PullRequestActionOutcome } from "@t3t
44

55
import type * as GitCafeCli from "../sourceControl/GitCafeCli.ts";
66
import { PullRequestProviderError, type PullRequestProviderApi } from "./PullRequestProvider.ts";
7-
import { gitCafeWriteApi } from "./gitCafeWriteApi.ts";
7+
import { gitCafeWriteApi, markNotDispatched } from "./gitCafeWriteApi.ts";
88

99
const Oid = Schema.String.check(Schema.isPattern(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/u));
1010
const Pull = Schema.Struct({
@@ -94,18 +94,6 @@ const fail = (operation: string, detail: string) =>
9494
detail,
9595
notDispatched: true,
9696
});
97-
const markNotDispatched = (error: PullRequestProviderError) =>
98-
error.notDispatched === true
99-
? error
100-
: new PullRequestProviderError({
101-
provider: error.provider,
102-
operation: error.operation,
103-
reason: error.reason,
104-
detail: error.detail,
105-
notDispatched: true,
106-
...(error.retryAt === undefined ? {} : { retryAt: error.retryAt }),
107-
cause: error,
108-
});
10997
const requestIdError = (requestId: string | undefined) =>
11098
requestId === undefined
11199
? "A request ID is required to submit durable GitCafe work."

‎apps/server/src/pullRequest/gitCafeReviewWrites.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,33 @@ const savedDraft = (version = 0, changes: Record<string, unknown> = {}) => ({
6666
});
6767

6868
describe("GitCafe review writes", () => {
69+
it.effect("says nothing was sent when a first attempt stops before any write", () =>
70+
Effect.gen(function* () {
71+
const cases = [
72+
// The account could not be read.
73+
fixture((call) => (call.endpoint === "/auth/principal" ? failure(503) : revision())),
74+
// GitCafe has not observed the base, so a commented review cannot be anchored.
75+
fixture((call) =>
76+
call.endpoint === "/auth/principal" ? identity() : revision({ observedBaseOid: null }),
77+
),
78+
// A draft T3 did not create is in the way.
79+
fixture((call) =>
80+
call.endpoint === "/auth/principal"
81+
? identity()
82+
: call.endpoint.endsWith("/review-draft/")
83+
? { draft: { ...savedDraft(), stale: false, comments: [] } }
84+
: revision(),
85+
),
86+
];
87+
for (const [index, attempt] of cases.entries()) {
88+
const error = yield* Effect.flip(
89+
attempt.writes.submitReview(input({ requestId: `review-${index}`, comments: [line()] })),
90+
);
91+
expect(error.notDispatched).toBe(true);
92+
expect(attempt.calls.some((call) => call.method !== undefined)).toBe(false);
93+
}
94+
}),
95+
);
6996
it.effect("rejects anything except the exact reviewed head and pull version", () =>
7097
Effect.gen(function* () {
7198
for (const changed of [{ version: 5 }, { headOid: moved }]) {

‎apps/server/src/pullRequest/gitCafeReviewWrites.ts‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from "@t3tools/contracts";
99
import type * as GitCafeCli from "../sourceControl/GitCafeCli.ts";
1010
import { PullRequestProviderError, type PullRequestProviderApi } from "./PullRequestProvider.ts";
11-
import { gitCafeWriteApi } from "./gitCafeWriteApi.ts";
11+
import { gitCafeWriteApi, markNotDispatched } from "./gitCafeWriteApi.ts";
1212

1313
const Oid = Schema.String.check(Schema.isPattern(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u));
1414
const DraftRef = Schema.Struct({ id: Schema.String, version: NonNegativeInt });
@@ -140,11 +140,17 @@ export function makeGitCafeReviewWrites(
140140
.api({ cwd: raw.cwd, host: raw.host, endpoint: "/auth/principal" })
141141
.pipe(
142142
Effect.mapError((cause) =>
143-
fail("GitCafe could not verify the current account before submitting the review.", cause),
143+
fail(
144+
"GitCafe could not verify the current account before submitting the review.",
145+
cause,
146+
true,
147+
),
144148
),
145149
);
146150
const identity = yield* Schema.decodeEffect(Schema.fromJsonString(Principal))(response).pipe(
147-
Effect.mapError((cause) => fail("GitCafe returned an unreadable account identity.", cause)),
151+
Effect.mapError((cause) =>
152+
fail("GitCafe returned an unreadable account identity.", cause, true),
153+
),
148154
);
149155
return identity.actorId;
150156
});
@@ -198,6 +204,12 @@ export function makeGitCafeReviewWrites(
198204
);
199205
const state = remembered ?? { fingerprint, actorId };
200206
remember(key, state);
207+
// Whether a refusal can say nothing was sent: only on a first attempt, and only before this
208+
// invocation's own first write.
209+
let wrote = false;
210+
const unsent = () => remembered === undefined && !wrote;
211+
const beforeWrite = (error: PullRequestProviderError) =>
212+
unsent() ? markNotDispatched(error) : error;
201213

202214
const finalBody = {
203215
verdict: mappedVerdict,
@@ -216,7 +228,9 @@ export function makeGitCafeReviewWrites(
216228
state.finalDraft === undefined ? finalBody : { ...finalBody, draft: state.finalDraft },
217229
}).pipe(Effect.asVoid);
218230

219-
const fresh = yield* request(raw, path, PullRevision, { operation: "submitReview" });
231+
const fresh = yield* request(raw, path, PullRevision, { operation: "submitReview" }).pipe(
232+
Effect.mapError(beforeWrite),
233+
);
220234
if (fresh.version !== revision.version || fresh.headOid !== revision.headOid)
221235
return yield* fail(
222236
"The GitCafe pull request changed since this review was written. Refresh the diff and review the new revision before submitting.",
@@ -226,6 +240,7 @@ export function makeGitCafeReviewWrites(
226240

227241
if (comments.length === 0) {
228242
state.submitted = true;
243+
wrote = true;
229244
return yield* request(raw, `${path}/reviews`, Submitted, {
230245
operation: "submitReview",
231246
method: "POST",
@@ -236,17 +251,22 @@ export function makeGitCafeReviewWrites(
236251
if (fresh.observedBaseOid === null)
237252
return yield* fail(
238253
"GitCafe has not observed the pull request base revision. Refresh the pull request and retry.",
254+
undefined,
255+
unsent(),
239256
);
240257

241258
const read = yield* request(raw, `${path}/review-draft/`, DraftRead, {
242259
operation: "submitReview",
243-
});
260+
}).pipe(Effect.mapError(beforeWrite));
244261
let draft: Draft;
245262
if (read.draft === null) {
246263
if (state.uncertainDraft === true)
247264
return yield* fail(
248265
`GitCafe still reports no review draft, but T3 cannot prove that the earlier creation is not in flight. Open https://${raw.host}/${raw.repository}/pulls/${raw.number} and inspect the draft before retrying; do not create another review yet.`,
266+
undefined,
267+
unsent(),
249268
);
269+
wrote = true;
250270
const created = yield* request(raw, `${path}/review-draft/`, SavedDraft, {
251271
operation: "submitReview",
252272
method: "PUT",
@@ -274,6 +294,8 @@ export function makeGitCafeReviewWrites(
274294
if (!ours)
275295
return yield* fail(
276296
`An existing GitCafe review draft cannot be safely claimed by T3. Open https://${raw.host}/${raw.repository}/pulls/${raw.number}, submit or discard that draft, then retry.`,
297+
undefined,
298+
unsent(),
277299
);
278300
if (
279301
draft.stale ||
@@ -285,6 +307,8 @@ export function makeGitCafeReviewWrites(
285307
)
286308
return yield* fail(
287309
"The GitCafe review draft no longer matches this request. Open GitCafe and inspect the draft before retrying.",
310+
undefined,
311+
unsent(),
288312
);
289313
}
290314
if (
@@ -293,10 +317,14 @@ export function makeGitCafeReviewWrites(
293317
)
294318
return yield* fail(
295319
"The GitCafe review draft contains unrelated line comments. Open GitCafe and inspect the draft before retrying.",
320+
undefined,
321+
unsent(),
296322
);
297323
if (state.uncertainComment === true)
298324
return yield* fail(
299325
`T3 cannot prove whether the last draft comment was saved. Open https://${raw.host}/${raw.repository}/pulls/${raw.number} and inspect the review draft before retrying.`,
326+
undefined,
327+
unsent(),
300328
);
301329

302330
let ref = { id: draft.id, version: draft.version };

‎apps/server/src/pullRequest/gitCafeWriteApi.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ import * as Schema from "effect/Schema";
44
import type * as GitCafeCli from "../sourceControl/GitCafeCli.ts";
55
import { PullRequestProviderError, type ProviderRepositoryRef } from "./PullRequestProvider.ts";
66

7+
/** Marks a failure that happened before this invocation sent anything that could mutate. */
8+
export const markNotDispatched = (error: PullRequestProviderError) =>
9+
error.notDispatched === true
10+
? error
11+
: new PullRequestProviderError({
12+
provider: error.provider,
13+
operation: error.operation,
14+
reason: error.reason,
15+
detail: error.detail,
16+
notDispatched: true,
17+
...(error.retryAt === undefined ? {} : { retryAt: error.retryAt }),
18+
cause: error,
19+
});
20+
721
/** Authenticated, repository-relative requests shared by GitCafe mutations. */
822
export function gitCafeWriteApi(cli: GitCafeCli.GitCafeCli["Service"]) {
923
return <S extends Schema.Top & { readonly DecodingServices: never }>(

‎apps/server/src/sourceControl/GitCafeCli.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ function normalizePull(
166166
};
167167
}
168168

169-
/** @public Service construction is part of the canonical Effect module API. */
170-
export const make = Effect.gen(function* () {
169+
const make = Effect.gen(function* () {
171170
const process = yield* VcsProcess.VcsProcess;
172171
const git = yield* GitVcsDriver.GitVcsDriver;
173172
const httpClient = yield* HttpClient.HttpClient;

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,7 +3166,13 @@ const CHAT_MARKDOWN_COMPONENTS = {
31663166
alt={altText}
31673167
copyMarkdown={copyMarkdown}
31683168
standalone={standalone}
3169+
className={className}
31693170
style={authoredSizeStyle}
3171+
imageProps={imageProps}
3172+
srcFragment={markdownImageSourceFragment(classifiedSrc)}
3173+
originalUrl={srcString}
3174+
// Only pull request bodies resolve these, and they draw their own boxes.
3175+
framed={false}
31703176
onImageExpand={imageExpand}
31713177
/>
31723178
);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@ export function PullRequestStackMenu({
283283
});
284284
return;
285285
}
286-
if (discovering && outcome.state === "pending") {
287-
// Latest is useful discovery, but does not identify the lost request's operation. Once it
288-
// settles, the stack revision has moved, so a repeated request is fenced off anyway.
286+
if (discovering) {
287+
// The latest operation may be an older one, so whatever it says proves nothing about the
288+
// lost request: report it and keep the record. Dismiss is the way out once GitCafe shows
289+
// what happened.
289290
remember(
290291
{
291292
input: storedAction.input,

0 commit comments

Comments
 (0)