Skip to content

Commit c23e110

Browse files
committed
fix(github): separate routed pull request caches by account
1 parent 3a68352 commit c23e110

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,6 +3653,41 @@ it.effect("shares linked summaries and reuses them for display without asking th
36533653
}),
36543654
);
36553655

3656+
it.effect("keeps routed summaries and details separate when the GitHub account changes", () =>
3657+
Effect.gen(function* () {
3658+
for (const operation of ["summary", "detail"] as const) {
3659+
let failing = false;
3660+
let calls = 0;
3661+
const read = () =>
3662+
Effect.suspend(() => {
3663+
calls += 1;
3664+
return failing
3665+
? Effect.fail(requestFailed)
3666+
: Effect.succeed(hostedChangeRequest("account A content"));
3667+
});
3668+
const service = yield* makeService({
3669+
projects: [
3670+
project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
3671+
],
3672+
providers: [
3673+
fakeProvider("github", { getChangeRequestSummary: read, getChangeRequest: read }),
3674+
],
3675+
});
3676+
const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 1 };
3677+
yield* service[operation]({ ...reference, expectedAccountId: "101" });
3678+
failing = true;
3679+
3680+
for (const allowStale of [false, true]) {
3681+
const error = yield* Effect.flip(
3682+
service[operation]({ ...reference, expectedAccountId: "202", allowStale }),
3683+
);
3684+
assert.strictEqual(error._tag, "PullRequestOperationError");
3685+
}
3686+
assert.strictEqual(calls, 3);
3687+
}
3688+
}),
3689+
);
3690+
36563691
it.effect("answers a known pull request immediately while the host refreshes", () =>
36573692
Effect.gen(function* () {
36583693
const gate = yield* Deferred.make<void>();

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2315,18 +2315,21 @@ export const make = Effect.gen(function* () {
23152315
ref.host?.toLowerCase() ?? null,
23162316
ref.repository.toLowerCase(),
23172317
ref.number,
2318+
ref.expectedAccountId ?? null,
23182319
]);
23192320
const refOfCacheKey = (key: string): PullRequestRef => {
2320-
const [, projectId, host, repository, number] = JSON.parse(key) as [
2321+
const [, projectId, host, repository, number, expectedAccountId] = JSON.parse(key) as [
23212322
number,
23222323
string,
23232324
string | null,
23242325
string,
23252326
number,
2327+
string | null,
23262328
];
23272329
return {
23282330
projectId,
23292331
...(host === null ? {} : { host }),
2332+
...(expectedAccountId === null ? {} : { expectedAccountId }),
23302333
repository,
23312334
number,
23322335
} as PullRequestRef;
@@ -2387,6 +2390,7 @@ export const make = Effect.gen(function* () {
23872390
project.project.id,
23882391
project.project.workspaceRoot,
23892392
String(input.number),
2393+
input.expectedAccountId ?? "",
23902394
]
23912395
.map(encodeURIComponent)
23922396
.join(":");

0 commit comments

Comments
 (0)