Skip to content

Commit 12df782

Browse files
committed
fix(github): preserve source paths and bound post-action cleanup
1 parent c23e110 commit 12df782

5 files changed

Lines changed: 78 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,8 @@ it.effect("routing verifies the current account on the requested host without ca
10061006
provider: "github",
10071007
viewer: "first-account",
10081008
accountId: "123",
1009+
projectTitle: "web",
1010+
workspaceRoot: "/a",
10091011
});
10101012
viewer = "second-account";
10111013
assert.strictEqual((yield* service.routing(ref)).viewer, "second-account");

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,13 @@ export const make = Effect.gen(function* () {
13111311
detail: "The signed-in account could not be verified.",
13121312
});
13131313
}
1314-
return { host: project.host, provider: project.api.kind, ...identity };
1314+
return {
1315+
host: project.host,
1316+
provider: project.api.kind,
1317+
...identity,
1318+
projectTitle: project.project.title,
1319+
workspaceRoot: project.project.workspaceRoot,
1320+
};
13151321
});
13161322

13171323
const summaryUncached: PullRequestService["Service"]["summary"] = (input) =>

‎packages/client-runtime/src/state/pullRequestRouting.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ export function createPullRequestRouter() {
177177
[...refs.map((reference) => ({ reference })), {}],
178178
(invalidation) =>
179179
request(WS_METHODS.pullRequestsInvalidate, invalidation).pipe(
180+
// GitHub already accepted the write. A stalled reader on another
181+
// environment must not keep its confirmation pending indefinitely.
182+
Effect.timeoutOption("1 second"),
180183
Effect.orElseSucceed(() => undefined),
181184
),
182185
{ concurrency: 3, discard: true },
@@ -282,7 +285,13 @@ export function createPullRequestRouter() {
282285
}),
283286
Effect.map((result) =>
284287
typeof result === "object" && result !== null && "projectId" in result
285-
? { ...result, projectId: ref.projectId }
288+
? {
289+
...result,
290+
projectId: ref.projectId,
291+
...(tag === WS_METHODS.pullRequestsDetail
292+
? { projectTitle: identity.projectTitle, workspaceRoot: identity.workspaceRoot }
293+
: {}),
294+
}
286295
: result,
287296
),
288297
);

‎packages/client-runtime/src/state/pullRequests.test.ts‎

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ for (const scenario of [
4646
"keeps a local origin ahead of another local environment",
4747
"keeps mutations on an old origin server without retrying them",
4848
"skips an old alternate server before dispatching a mutation",
49+
"returns a successful mutation when source invalidation stalls",
4950
] as const) {
50-
it.effect(scenario, () =>
51+
(scenario === "returns a successful mutation when source invalidation stalls"
52+
? it.live
53+
: it.effect)(scenario, () =>
5154
Effect.scoped(
5255
Effect.gen(function* () {
5356
const calls: string[] = [];
@@ -98,8 +101,14 @@ for (const scenario of [
98101
return null;
99102
}),
100103
[WS_METHODS.pullRequestsInvalidate]: () =>
101-
Effect.sync(() => {
104+
Effect.gen(function* () {
102105
calls.push(`${name}:invalidate`);
106+
if (
107+
!local &&
108+
scenario === "returns a successful mutation when source invalidation stalls"
109+
) {
110+
return yield* Effect.never;
111+
}
103112
}),
104113
} as unknown as WsRpcProtocolClient;
105114
};
@@ -316,6 +325,52 @@ for (const source of ["pending", "pending-local", "failed", "offline"] as const)
316325
);
317326
}
318327

328+
it.live("keeps source workspace metadata when an alternate answers a detail read", () =>
329+
Effect.scoped(
330+
Effect.gen(function* () {
331+
const clientFor = (local: boolean) =>
332+
({
333+
[WS_METHODS.pullRequestsRouting]: () =>
334+
Effect.succeed({
335+
host: "github.com",
336+
provider: "github",
337+
viewer: "maria-rcks",
338+
accountId: "123",
339+
projectTitle: local ? "local project" : "source project",
340+
workspaceRoot: local ? "/Users/local/repo" : "/srv/source/repo",
341+
}),
342+
[WS_METHODS.pullRequestsDetail]: () =>
343+
local
344+
? Effect.succeed({
345+
projectId: "local-project",
346+
projectTitle: "local project",
347+
workspaceRoot: "/Users/local/repo",
348+
title: "github title",
349+
})
350+
: Effect.never,
351+
}) as unknown as WsRpcProtocolClient;
352+
const { environmentRegistry, supervisor } = yield* makeTestRuntime(
353+
clientFor(false),
354+
clientFor(true),
355+
);
356+
const result = yield* createPullRequestRouter()(WS_METHODS.pullRequestsDetail, {
357+
projectId: ProjectId.make("project-1"),
358+
repository: "acme/web",
359+
number: 7,
360+
}).pipe(
361+
Effect.provideService(EnvironmentRegistry.EnvironmentRegistry, environmentRegistry),
362+
Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
363+
);
364+
expect(result).toEqual({
365+
projectId: "project-1",
366+
projectTitle: "source project",
367+
workspaceRoot: "/srv/source/repo",
368+
title: "github title",
369+
});
370+
}),
371+
),
372+
);
373+
319374
it.live(
320375
"refreshes identity before writes and invalidates prior readers across router instances",
321376
() =>

‎packages/contracts/src/pullRequest.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ export const PullRequestRoutingResult = Schema.Struct({
657657
host: TrimmedNonEmptyString,
658658
provider: SourceControlProviderKind,
659659
viewer: TrimmedNonEmptyString,
660+
projectTitle: TrimmedNonEmptyString,
661+
workspaceRoot: TrimmedNonEmptyString,
660662
});
661663
export type PullRequestRoutingResult = typeof PullRequestRoutingResult.Type;
662664

0 commit comments

Comments
 (0)