@@ -285,6 +285,105 @@ it.effect(
285285 }),
286286);
287287
288+ it.effect.each([false, true])(
289+ "pins workspace credentials for concurrent summaries, fallback=%s",
290+ (fallback) =>
291+ Effect.gen(function* () {
292+ const commands: VcsProcess.VcsProcessInput[] = [];
293+ const github = yield* GitHubCli.make.pipe(
294+ Effect.provide(Layer.merge(GitHubGraphQlBudget.layer, SourceControlRateLimit.layer)),
295+ Effect.provideService(VcsProcess.VcsProcess, {
296+ run: (input) =>
297+ Effect.sync(() => {
298+ commands.push(input);
299+ const token = input.cwd === "/b" ? "token-b" : "token-a";
300+ if (input.args[0] === "auth") return output(token);
301+ if (input.args[1] === "user") return output('{"id":123,"login":"same-viewer"}');
302+ if (input.args.includes("rate_limit")) {
303+ expect(["token-a", "token-b"]).toContain(input.env?.GH_TOKEN);
304+ return output(
305+ encodeJson({
306+ data: {
307+ rateLimit: {
308+ cost: 1,
309+ limit: 5000,
310+ remaining: 4999,
311+ resetAt: "2099-01-01T00:00:00Z",
312+ },
313+ },
314+ }),
315+ );
316+ }
317+ expect(input.env?.GH_TOKEN).toBe(token);
318+ if (input.args[0] === "pr")
319+ return output(
320+ encodeJson({
321+ ...coreResponse().data.repository.pullRequest,
322+ number: Number(input.args[2]),
323+ author: null,
324+ isDraft: false,
325+ additions: 1,
326+ deletions: 0,
327+ changedFiles: 1,
328+ mergedAt: null,
329+ closedAt: null,
330+ reviewDecision: null,
331+ mergeable: "MERGEABLE",
332+ reviewRequests: [],
333+ labels: [],
334+ statusCheckRollup: [],
335+ body: "",
336+ }),
337+ );
338+ const query = input.args.find((arg) => arg.startsWith("query=")) ?? "";
339+ const data: Record<string, unknown> = {};
340+ for (const match of query.matchAll(
341+ /(s\d+): repository\(owner: "([^"]+)", name: "([^"]+)"\) \{ pullRequest\(number: (\d+)\)/g,
342+ )) {
343+ expect(match[2] === "b" ? "token-b" : "token-a").toBe(token);
344+ data[match[1]!] = {
345+ pullRequest: {
346+ ...coreResponse().data.repository.pullRequest,
347+ number: Number(match[4]),
348+ author: null,
349+ isDraft: false,
350+ additions: 1,
351+ deletions: 0,
352+ changedFiles: 1,
353+ mergedAt: null,
354+ closedAt: null,
355+ reviewDecision: null,
356+ mergeable: "MERGEABLE",
357+ },
358+ };
359+ }
360+ return output(encodeJson({ data: fallback ? {} : data }));
361+ }).pipe(Effect.delay(input.args[0] === "auth" ? (input.cwd === "/b" ? 40 : 20) : 0)),
362+ }),
363+ );
364+ const cli = yield* GitHubPullRequestCli.make.pipe(
365+ Effect.provideService(GitHubCli.GitHubCli, github),
366+ Effect.provide(GitHubGraphQlBudget.layer),
367+ );
368+ const reads = yield* Effect.forEach(
369+ ["a", "b", "c", "a"],
370+ (name, index) =>
371+ cli.getPullRequestSummary({
372+ cwd: `/${name}`,
373+ repository: `${name}/repo`,
374+ host: "github.com",
375+ number: index + 1,
376+ }),
377+ { concurrency: "unbounded" },
378+ ).pipe(Effect.forkChild);
379+ yield* TestClock.adjust("100 millis");
380+ expect((yield* Fiber.join(reads)).map((row) => row.number)).toEqual([1, 2, 3, 4]);
381+ expect(commands.filter((command) => command.args[1] === "graphql")).toHaveLength(2);
382+ expect(commands.filter((command) => command.args[0] === "auth")).toHaveLength(3);
383+ expect(commands.filter((command) => command.args[0] === "pr")).toHaveLength(fallback ? 4 : 0);
384+ }),
385+ );
386+
288387layer("GitHubPullRequestCli.layer", (it) => {
289388 it.effect("admits only one concurrent preview above the reserve and resumes after reset", () =>
290389 Effect.gen(function* () {
@@ -474,13 +573,16 @@ layer("GitHubPullRequestCli.layer", (it) => {
474573 closedAt: null,
475574 commits: { nodes: [{ commit: { statusCheckRollup: { state: "SUCCESS" } } }] },
476575 });
477- mockedExecute.mockReturnValueOnce(
576+ mockedExecute.mockImplementation((input) =>
478577 Effect.succeed(
479578 output(
480- // @effect-diagnostics-next-line preferSchemaOverJson:off
481- JSON.stringify({
482- data: { s0: { pullRequest: node(7) }, s1: { pullRequest: node(8) } },
483- }),
579+ input.args[0] === "auth"
580+ ? "summary-credential"
581+ : input.args[1] === "user"
582+ ? '{"id":123,"login":"viewer"}'
583+ : encodeJson({
584+ data: { s0: { pullRequest: node(7) }, s1: { pullRequest: node(8) } },
585+ }),
484586 ),
485587 ),
486588 );
@@ -523,8 +625,9 @@ layer("GitHubPullRequestCli.layer", (it) => {
523625 },
524626 );
525627 assert.strictEqual(eight?.headBranch, "feat/8");
526- expect(mockedExecute).toHaveBeenCalledOnce();
527- const document = callAt(0).args.at(-1) ?? "";
628+ const graphql = mockedExecute.mock.calls.filter(([input]) => input.args[1] === "graphql");
629+ expect(graphql).toHaveLength(1);
630+ const document = graphql[0]![0].args.at(-1) ?? "";
528631 expect(document).toContain(
529632 's0: repository(owner: "acme", name: "web") { pullRequest(number: 7)',
530633 );
@@ -534,43 +637,46 @@ layer("GitHubPullRequestCli.layer", (it) => {
534637
535638 it.effect("reads a pull request the batch said nothing about on its own", () =>
536639 Effect.gen(function* () {
537- mockedExecute
538- .mockReturnValueOnce(Effect.succeed(output('{"data":{"s0":{"pullRequest":null}}}')))
539- .mockReturnValueOnce(
540- Effect.succeed(
541- output(
542- // @effect-diagnostics-next-line preferSchemaOverJson:off
543- JSON.stringify({
544- number: 7,
545- title: "Reuse the summary",
546- url: "https://github.com/acme/web/pull/7",
547- author: { login: "octocat", name: "Octo Cat" },
548- baseRefName: "main",
549- headRefName: "feat/summary",
550- state: "OPEN",
551- isDraft: false,
552- mergeable: "MERGEABLE",
553- reviewDecision: "APPROVED",
554- additions: 12,
555- deletions: 3,
556- changedFiles: 2,
557- createdAt: "2026-08-20T00:00:00.000Z",
558- updatedAt: "2026-08-24T12:34:56.000Z",
559- reviewRequests: [],
560- labels: [],
561- statusCheckRollup: [
562- {
563- __typename: "CheckRun",
564- status: "COMPLETED",
565- conclusion: "SUCCESS",
566- name: "ci",
567- },
568- ],
569- body: "",
570- }),
571- ),
640+ mockedExecute.mockImplementation((input) =>
641+ Effect.succeed(
642+ output(
643+ input.args[0] === "auth"
644+ ? "summary-credential"
645+ : input.args[1] === "user"
646+ ? '{"id":123,"login":"viewer"}'
647+ : input.args[1] === "graphql"
648+ ? '{"data":{"s0":{"pullRequest":null}}}'
649+ : encodeJson({
650+ number: 7,
651+ title: "Reuse the summary",
652+ url: "https://github.com/acme/web/pull/7",
653+ author: { login: "octocat", name: "Octo Cat" },
654+ baseRefName: "main",
655+ headRefName: "feat/summary",
656+ state: "OPEN",
657+ isDraft: false,
658+ mergeable: "MERGEABLE",
659+ reviewDecision: "APPROVED",
660+ additions: 12,
661+ deletions: 3,
662+ changedFiles: 2,
663+ createdAt: "2026-08-20T00:00:00.000Z",
664+ updatedAt: "2026-08-24T12:34:56.000Z",
665+ reviewRequests: [],
666+ labels: [],
667+ statusCheckRollup: [
668+ {
669+ __typename: "CheckRun",
670+ status: "COMPLETED",
671+ conclusion: "SUCCESS",
672+ name: "ci",
673+ },
674+ ],
675+ body: "",
676+ }),
572677 ),
573- );
678+ ),
679+ );
574680 const cli = yield* GitHubPullRequestCli.GitHubPullRequestCli;
575681
576682 const read = yield* cli
@@ -581,8 +687,9 @@ layer("GitHubPullRequestCli.layer", (it) => {
581687
582688 assert.strictEqual(summary.headBranch, "feat/summary");
583689 assert.strictEqual(summary.checksState, "passing");
584- assert.strictEqual(mockedExecute.mock.calls.length, 2);
585- expect(callAt(1).args).toEqual([
690+ const views = mockedExecute.mock.calls.filter(([input]) => input.args[0] === "pr");
691+ expect(views).toHaveLength(1);
692+ expect(views[0]![0].args).toEqual([
586693 "pr",
587694 "view",
588695 "7",
0 commit comments