Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions apps/server/src/pullRequest/PullRequestService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3090,6 +3090,47 @@ it.effect("close and reopen notify subscribed readers after invalidating their c
}),
);

it.effect("a refused merge notifies readers so they re-read the conflicting state", () =>
Effect.gen(function* () {
let mergeable = true;
const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
const service = yield* makeService({
projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
providers: [
fakePullRequestProvider(SourceControlProviderKind.make("github"), {
getChangeRequestSummary: () =>
Effect.succeed({
...changeRequest(1, "2026-09-16T00:00:00.000Z"),
mergeability: mergeable ? "mergeable" : "conflicting",
}),
runAction: () =>
Effect.suspend(() => {
mergeable = false;
return Effect.fail(
new PullRequestProviderError({
provider: SourceControlProviderKind.make("github"),
operation: "runAction",
reason: "failed",
detail: "Pull Request has merge conflicts",
}),
);
}),
}),
],
});

assert.strictEqual((yield* service.summary(reference)).mergeability, "mergeable");
const refreshed = yield* service.subscribeRefreshes.pipe(
Stream.take(1),
Stream.mapEffect(() => service.summary(reference)),
Stream.runHead,
Effect.forkChild({ startImmediately: true }),
);
yield* Effect.flip(service.runAction({ ...reference, action: "merge" }));
assert.strictEqual(Option.getOrThrow(yield* Fiber.join(refreshed)).mergeability, "conflicting");
}),
);

it.effect("reads a host's repositories in one search, and files the rows back under each", () =>
Effect.gen(function* () {
const asked: Array<ReadonlyArray<string>> = [];
Expand Down
8 changes: 8 additions & 0 deletions apps/server/src/pullRequest/PullRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3989,8 +3989,16 @@ export const make = Effect.gen(function* () {
)(function* (input) {
const ref = yield* canonicalRef(input);
yield* readCache.invalidate(refScope(ref));
// A refusal (e.g. a merge conflict) means readers hold stale state, so refresh them too.
const { repository, summary } = yield* runAction(input).pipe(
Effect.ensuring(readCache.invalidate(refScope(ref))),
Effect.tapError(() =>
Effect.suspend(() => {
bumpRefEpoch(ref);
listingsEpoch = ++epochCounter;
return SubscriptionRef.set(pullRequestRefreshes, listingsEpoch);
}),
),
);
bumpRefEpoch({ ...ref, repository });
listingsEpoch = ++epochCounter;
Expand Down
Loading