fix(server): propagate linked pr changes and settle threads immediately (#12161)
This commit is contained in:
1 parent
c12ba7581a
commit
19ee856ec0
8 files changed
+617
-102
No files matched your search
@@ -1093,8 +1093,13 @@ it.effect("publishes a merge for immediate settlement only after host confirmati
|
||||
|
||||
// Queueing succeeds while the host still reports an open PR.
|
||||
yield* service.runAction({ ...reference, action: "merge" });
|
||||
const queuedRefresh = Option.getOrThrow(yield* Stream.runHead(service.subscribeRefreshes));
|
||||
confirmationFails = true;
|
||||
yield* service.runAction({ ...reference, action: "merge" });
|
||||
assert.isAbove(
|
||||
Option.getOrThrow(yield* Stream.runHead(service.subscribeRefreshes)),
|
||||
queuedRefresh,
|
||||
);
|
||||
confirmationFails = false;
|
||||
state = "merged";
|
||||
yield* TestClock.setTime(Date.parse(mergedAt));
|
||||
@@ -1113,6 +1118,53 @@ it.effect("publishes a merge for immediate settlement only after host confirmati
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("refreshes every reader before a queued merge confirmation finishes", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
const confirmationStarted = yield* Deferred.make<void>();
|
||||
const confirm = yield* Deferred.make<void>();
|
||||
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: [
|
||||
fakeProvider("github", {
|
||||
getChangeRequestSummary: () =>
|
||||
Effect.gen(function* () {
|
||||
yield* Deferred.succeed(confirmationStarted, undefined);
|
||||
yield* Deferred.await(confirm);
|
||||
return changeRequest(1, "2026-09-16T00:00:00.000Z");
|
||||
}),
|
||||
}),
|
||||
],
|
||||
});
|
||||
const merges = yield* service.subscribeMerges;
|
||||
const observedMerge = yield* Stream.runHead(merges).pipe(
|
||||
Effect.forkChild({ startImmediately: true }),
|
||||
);
|
||||
const readers = yield* Effect.forEach([0, 1], () =>
|
||||
Stream.runHead(service.subscribeRefreshes).pipe(
|
||||
Effect.forkChild({ startImmediately: true }),
|
||||
),
|
||||
);
|
||||
const action = yield* service
|
||||
.runAction({ ...reference, action: "merge" })
|
||||
.pipe(Effect.forkChild({ startImmediately: true }));
|
||||
yield* Deferred.await(confirmationStarted);
|
||||
const revisions = yield* Effect.forEach(readers, (reader) =>
|
||||
Fiber.join(reader).pipe(Effect.map(Option.getOrThrow)),
|
||||
);
|
||||
assert.isAbove(revisions[0]!, 0);
|
||||
assert.strictEqual(revisions[0], revisions[1]);
|
||||
assert.isUndefined(action.pollUnsafe());
|
||||
yield* Deferred.succeed(confirm, undefined);
|
||||
yield* Fiber.join(action);
|
||||
assert.isUndefined(observedMerge.pollUnsafe());
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("refuses an action this viewer may not take, and says what access it takes", () =>
|
||||
Effect.gen(function* () {
|
||||
let ran: string | null = null;
|
||||
@@ -2378,10 +2430,16 @@ it.effect("invalidates the cached activity after reacting, like the other mutati
|
||||
],
|
||||
});
|
||||
|
||||
yield* service.refreshAfterTurn(reference.projectId);
|
||||
const previousRefresh = Option.getOrThrow(yield* Stream.runHead(service.subscribeRefreshes));
|
||||
yield* service.activity(reference);
|
||||
assert.strictEqual(activityCalls, 1);
|
||||
|
||||
yield* service.setReaction({ ...reference, content: "heart", reacted: true });
|
||||
assert.isAbove(
|
||||
Option.getOrThrow(yield* Stream.runHead(service.subscribeRefreshes)),
|
||||
previousRefresh,
|
||||
);
|
||||
yield* service.activity(reference);
|
||||
|
||||
assert.strictEqual(activityCalls, 2);
|
||||
@@ -3255,31 +3313,106 @@ it.effect("explicit and turn invalidations make the next listing ask the host ag
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("a mutation makes the next listing ask the host again, with no client asking", () =>
|
||||
Effect.gen(function* () {
|
||||
let hostCalls = 0;
|
||||
const service = yield* makeService({
|
||||
projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
|
||||
providers: [
|
||||
fakeProvider("github", {
|
||||
listChangeRequests: () => {
|
||||
hostCalls += 1;
|
||||
return Effect.succeed({ items: [], truncated: false, continues: false });
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
it.effect("close and reopen notify subscribed readers after invalidating their cached state", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
let hostCalls = 0;
|
||||
let state: "open" | "closed" = "open";
|
||||
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: [
|
||||
fakeProvider("github", {
|
||||
getChangeRequestSummary: () =>
|
||||
Effect.succeed({ ...changeRequest(1, "2026-09-16T00:00:00.000Z"), state }),
|
||||
runAction: (input) =>
|
||||
Effect.sync(() => {
|
||||
state = input.action === "close" ? "closed" : "open";
|
||||
}),
|
||||
listChangeRequests: () => {
|
||||
hostCalls += 1;
|
||||
return Effect.succeed({ items: [], truncated: false, continues: false });
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
yield* service.list({ state: "open" });
|
||||
yield* service.runAction({
|
||||
projectId: "p1" as ProjectId,
|
||||
repository: "acme/web",
|
||||
number: 1,
|
||||
action: "close",
|
||||
});
|
||||
yield* service.list({ state: "open" });
|
||||
assert.strictEqual(hostCalls, 2);
|
||||
}),
|
||||
yield* service.refreshAfterTurn(reference.projectId);
|
||||
yield* service.list({ state: "open" });
|
||||
assert.strictEqual((yield* service.summary(reference)).state, "open");
|
||||
for (const action of ["close", "reopen"] as const) {
|
||||
const refreshed = yield* service.subscribeRefreshes.pipe(
|
||||
Stream.drop(1),
|
||||
Stream.take(1),
|
||||
Stream.mapEffect(() =>
|
||||
Effect.gen(function* () {
|
||||
yield* service.list({ state: "open" });
|
||||
return yield* service.summary(reference);
|
||||
}),
|
||||
),
|
||||
Stream.runHead,
|
||||
Effect.forkChild({ startImmediately: true }),
|
||||
);
|
||||
yield* service.runAction({ ...reference, action });
|
||||
assert.strictEqual(
|
||||
Option.getOrThrow(yield* Fiber.join(refreshed)).state,
|
||||
action === "close" ? "closed" : "open",
|
||||
);
|
||||
}
|
||||
assert.strictEqual(hostCalls, 3);
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("explicit invalidation refreshes origin readers after a routed host mutation", () =>
|
||||
Effect.scoped(
|
||||
Effect.gen(function* () {
|
||||
let state: "open" | "closed" = "open";
|
||||
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: [
|
||||
fakeProvider("github", {
|
||||
getChangeRequestSummary: () =>
|
||||
Effect.succeed({ ...changeRequest(1, "2026-09-16T00:00:00.000Z"), state }),
|
||||
}),
|
||||
],
|
||||
});
|
||||
yield* service.refreshAfterTurn(reference.projectId);
|
||||
let revision = Option.getOrThrow(yield* Stream.runHead(service.subscribeRefreshes));
|
||||
// The sync reactor invalidates before reading; it must not notify itself again.
|
||||
yield* service.invalidate({ reference });
|
||||
assert.strictEqual(
|
||||
Option.getOrThrow(yield* Stream.runHead(service.subscribeRefreshes)),
|
||||
revision,
|
||||
);
|
||||
assert.strictEqual((yield* service.summary(reference)).state, "open");
|
||||
|
||||
for (const nextState of ["closed", "open"] as const) {
|
||||
const refreshed = yield* service.subscribeRefreshes.pipe(
|
||||
Stream.drop(1),
|
||||
Stream.take(1),
|
||||
Stream.mapEffect((nextRevision) =>
|
||||
service
|
||||
.summary(reference)
|
||||
.pipe(Effect.map((summary) => ({ revision: nextRevision, state: summary.state }))),
|
||||
),
|
||||
Stream.runHead,
|
||||
Effect.forkChild({ startImmediately: true }),
|
||||
);
|
||||
state = nextState;
|
||||
yield* service.invalidate({ reference }, { notifyReaders: true });
|
||||
const result = Option.getOrThrow(yield* Fiber.join(refreshed));
|
||||
assert.strictEqual(result.state, nextState);
|
||||
assert.isAbove(result.revision, revision);
|
||||
revision = result.revision;
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
it.effect("does not cache a failed listing", () =>
|
||||
|
||||
@@ -232,7 +232,10 @@ export class PullRequestService extends Context.Service<
|
||||
readonly setLabels: (
|
||||
input: PullRequestLabelChangeInput,
|
||||
) => Effect.Effect<void, PullRequestError>;
|
||||
readonly invalidate: (input: PullRequestInvalidateInput) => Effect.Effect<void>;
|
||||
readonly invalidate: (
|
||||
input: PullRequestInvalidateInput,
|
||||
options?: { readonly notifyReaders?: boolean },
|
||||
) => Effect.Effect<void>;
|
||||
}
|
||||
>()("t3/pullRequest/PullRequestService") {}
|
||||
|
||||
@@ -2839,10 +2842,12 @@ export const make = Effect.gen(function* () {
|
||||
return { stats: [...held, ...result.stats] };
|
||||
});
|
||||
|
||||
const invalidate: PullRequestService["Service"]["invalidate"] = (input) => {
|
||||
const invalidate: PullRequestService["Service"]["invalidate"] = Effect.fn(
|
||||
"PullRequestService.invalidate",
|
||||
)(function* (input, options) {
|
||||
const reference = input.reference;
|
||||
if (reference !== undefined) {
|
||||
return canonicalRef(reference).pipe(
|
||||
yield* canonicalRef(reference).pipe(
|
||||
Effect.flatMap((ref) =>
|
||||
readCache
|
||||
.invalidate(refScope(ref))
|
||||
@@ -2850,12 +2855,15 @@ export const make = Effect.gen(function* () {
|
||||
),
|
||||
Effect.ignore,
|
||||
);
|
||||
}
|
||||
return Effect.sync(() => {
|
||||
} else {
|
||||
listingsEpoch = ++epochCounter;
|
||||
viewersByHost.clear();
|
||||
}).pipe(Effect.andThen(Cache.invalidateAll(viewerFlights)));
|
||||
};
|
||||
yield* Cache.invalidateAll(viewerFlights);
|
||||
}
|
||||
if (options?.notifyReaders) {
|
||||
yield* SubscriptionRef.set(pullRequestRefreshes, ++epochCounter);
|
||||
}
|
||||
});
|
||||
|
||||
const refreshAfterTurn: PullRequestService["Service"]["refreshAfterTurn"] = (projectId) =>
|
||||
Effect.suspend(() => {
|
||||
@@ -2874,9 +2882,7 @@ export const make = Effect.gen(function* () {
|
||||
.pipe(Effect.andThen(SubscriptionRef.set(pullRequestRefreshes, listingsEpoch)));
|
||||
});
|
||||
|
||||
// A mutation's own client re-reads right after it, and every other client's next read must
|
||||
// see the action too — so a write forgets the change request it touched and the listings its
|
||||
// state change reorders, for everyone, without any client asking.
|
||||
// Invalidate before notifying every client so mounted readers immediately fetch the edit.
|
||||
const invalidatedByMutation =
|
||||
<I extends PullRequestRef>(
|
||||
method: (input: I) => Effect.Effect<void, PullRequestError>,
|
||||
@@ -2894,6 +2900,7 @@ export const make = Effect.gen(function* () {
|
||||
}),
|
||||
),
|
||||
);
|
||||
yield* SubscriptionRef.set(pullRequestRefreshes, listingsEpoch);
|
||||
});
|
||||
const runActionAndInvalidate: PullRequestService["Service"]["runAction"] = Effect.fn(
|
||||
"PullRequestService.runActionAndInvalidate",
|
||||
@@ -2905,6 +2912,7 @@ export const make = Effect.gen(function* () {
|
||||
);
|
||||
bumpRefEpoch({ ...ref, repository });
|
||||
listingsEpoch = ++epochCounter;
|
||||
yield* SubscriptionRef.set(pullRequestRefreshes, listingsEpoch);
|
||||
if (input.action === "merge") {
|
||||
// A successful merge action can merely enqueue the PR or enable auto-merge.
|
||||
const confirmed = yield* summaryUncached({ ...input, repository }).pipe(
|
||||
|
||||
Reference in new issue
Block a user