Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

PullRequestSyncReactor.test.ts

705 lines24.6 KB

1import {
2 ProjectId,
3 ProviderInstanceId,
4 PullRequestOperationError,
5 ThreadId,
6 type OrchestrationCommand,
7 type OrchestrationProjectShell,
8 type OrchestrationShellSnapshot,
9 type OrchestrationThreadShell,
10 type PullRequestRef,
11 type PullRequestStack,
12 type PullRequestSummary,
13 type ThreadPullRequestLink,
14 type ThreadPullRequestSnapshot,
15} from "@t3tools/contracts";
16import { assert, describe, it } from "@effect/vitest";
17import * as Crypto from "effect/Crypto";
18import * as Deferred from "effect/Deferred";
19import * as Effect from "effect/Effect";
20import * as Layer from "effect/Layer";
21import * as Queue from "effect/Queue";
22import * as Ref from "effect/Ref";
23import * as Stream from "effect/Stream";
24import { TestClock } from "effect/testing";
25​
26import { PullRequestService } from "../pullRequest/PullRequestService.ts";
27import { ServerActivation } from "../serverActivation.ts";
28import {
29 OrchestrationEngineService,
30 type OrchestrationEngineShape,
31} from "./Services/OrchestrationEngine.ts";
32import { ProjectionSnapshotQuery } from "./Services/ProjectionSnapshotQuery.ts";
33import * as PullRequestSyncReactor from "./PullRequestSyncReactor.ts";
34​
35const NOW = "2026-08-28T12:00:00.000Z";
36const PROJECT_ID = ProjectId.make("sync-project");
37​
38type SyncCommand = Extract<
39 OrchestrationCommand,
40 { readonly type: "thread.pull-request-link.sync" }
41>;
42type LinkCommand = Extract<OrchestrationCommand, { readonly type: "thread.pull-request.link" }>;
43​
44const testCrypto = Crypto.make({
45 randomBytes: (size) => new Uint8Array(size).fill(1),
46 digest: (_algorithm, data) => Effect.succeed(data),
47});
48​
49function makeProject(id: ProjectId = PROJECT_ID): OrchestrationProjectShell {
50 return {
51 id,
52 title: `Project ${id}`,
53 workspaceRoot: "/workspace/project",
54 defaultModelSelection: null,
55 scripts: [],
56 createdAt: "2026-08-01T00:00:00.000Z",
57 updatedAt: NOW,
58 };
60​
61function makeThread(
62 id: string,
63 overrides: Partial<OrchestrationThreadShell> = {},
64): OrchestrationThreadShell {
65 return {
66 id: ThreadId.make(id),
67 projectId: PROJECT_ID,
68 title: id,
69 modelSelection: {
70 instanceId: ProviderInstanceId.make("codex"),
71 model: "gpt-5",
72 },
73 runtimeMode: "full-access",
74 interactionMode: "default",
75 branch: null,
76 worktreePath: null,
77 pullRequests: [],
78 latestTurn: null,
79 createdAt: "2026-08-01T00:00:00.000Z",
80 updatedAt: "2026-08-20T00:00:00.000Z",
81 archivedAt: null,
82 settledOverride: null,
83 settledAt: null,
84 session: null,
85 latestUserMessageAt: "2026-08-20T00:00:00.000Z",
86 hasPendingApprovals: false,
87 hasPendingUserInput: false,
88 hasActionableProposedPlan: false,
89 ...overrides,
90 };
92​
93function makeLink(
94 number: number,
95 snapshot: Partial<ThreadPullRequestSnapshot> | null = null,
96 overrides: Partial<ThreadPullRequestLink> = {},
97): ThreadPullRequestLink {
98 return {
99 host: "github.com",
100 repository: "owner/repository",
101 number,
102 url: `https://github.com/owner/repository/pull/${number}`,
103 source: "manual",
104 linkedAt: "2026-08-10T00:00:00.000Z",
105 snapshot:
106 snapshot === null
107 ? null
108 : {
109 state: "open",
110 title: "Pull request",
111 headBranch: "feature",
112 baseBranch: "main",
113 isDraft: false,
114 updatedAt: "2026-08-27T00:00:00.000Z",
115 syncedAt: "2026-08-27T00:00:00.000Z",
116 ...snapshot,
117 },
118 stack: null,
119 ...overrides,
120 };
122​
123function makeSnapshot(
124 threads: ReadonlyArray<OrchestrationThreadShell>,
125 snapshotSequence = 1,
126): OrchestrationShellSnapshot {
127 return {
128 snapshotSequence,
129 projects: [makeProject()],
130 threads,
131 updatedAt: NOW,
132 };
134​
135function makeSummary(
136 input: PullRequestRef,
137 overrides: Partial<PullRequestSummary> = {},
138): PullRequestSummary {
139 return {
140 provider: "github",
141 projectId: input.projectId,
142 repository: input.repository,
143 number: input.number,
144 title: "Pull request",
145 url: `https://github.com/${input.repository}/pull/${input.number}`,
146 state: "open",
147 headBranch: "feature",
148 baseBranch: "main",
149 updatedAt: "2026-08-27T00:00:00.000Z",
150 ...overrides,
151 };
153​
154interface HarnessOptions {
155 readonly invalidate?: PullRequestService["Service"]["invalidate"];
156 readonly snapshot: OrchestrationShellSnapshot;
157 readonly summary?: (
158 input: PullRequestRef,
159 ) => Effect.Effect<PullRequestSummary, PullRequestOperationError>;
160 readonly stack?: (
161 input: PullRequestRef,
162 ) => Effect.Effect<PullRequestStack | null, PullRequestOperationError>;
164​
165const makeHarness = Effect.fn("makePullRequestSyncHarness")(function* (options: HarnessOptions) {
166 const activation = yield* Deferred.make<void>();
167 const snapshots = yield* Ref.make(options.snapshot);
168 const snapshotReads = yield* Queue.unbounded<void>();
169 const syncCommands = yield* Ref.make<ReadonlyArray<SyncCommand>>([]);
170 const linkCommands = yield* Ref.make<ReadonlyArray<LinkCommand>>([]);
171 const summaryCalls = yield* Ref.make<ReadonlyArray<PullRequestRef>>([]);
172 const stackCalls = yield* Ref.make<ReadonlyArray<PullRequestRef>>([]);
173​
174 const summary: PullRequestService["Service"]["summary"] = (input, readOptions) =>
175 Effect.gen(function* () {
176 assert.strictEqual(readOptions?.recoverTransientFailure, false);
177 yield* Ref.update(summaryCalls, (calls) => [...calls, input]);
178 return yield* options.summary?.(input) ?? Effect.succeed(makeSummary(input));
179 });
180​
181 const stack: PullRequestService["Service"]["stack"] = (input, readOptions) =>
182 Effect.gen(function* () {
183 assert.strictEqual(readOptions?.includeDetails, false);
184 yield* Ref.update(stackCalls, (calls) => [...calls, input]);
185 return yield* options.stack?.(input) ?? Effect.succeed(null);
186 });
187​
188 const dispatch: OrchestrationEngineShape["dispatch"] = (command) => {
189 if (command.type === "thread.pull-request-link.sync") {
190 return Ref.update(syncCommands, (recorded) => [...recorded, command]).pipe(
191 Effect.as({ sequence: 1 }),
192 );
193 }
194 if (command.type === "thread.pull-request.link") {
195 return Ref.update(linkCommands, (recorded) => [...recorded, command]).pipe(
196 Effect.as({ sequence: 1 }),
197 );
198 }
199 return Effect.die(new Error(`Unexpected command: ${command.type}`));
200 };
201​
202 const dependencies = Layer.mergeAll(
203 Layer.mock(ProjectionSnapshotQuery)({
204 getShellSnapshot: () =>
205 Queue.offer(snapshotReads, undefined).pipe(Effect.andThen(Ref.get(snapshots))),
206 }),
207 Layer.mock(PullRequestService)({
208 summary,
209 stack,
210 invalidate: options.invalidate ?? (() => Effect.void),
211 }),
212 Layer.mock(OrchestrationEngineService)({
213 readEvents: () => Stream.empty,
214 dispatch,
215 streamDomainEvents: Stream.empty,
216 latestSequence: Effect.succeed(0),
217 }),
218 Layer.succeed(ServerActivation, Deferred.await(activation)),
219 Layer.succeed(Crypto.Crypto, testCrypto),
220 );
221​
222 return {
223 activation,
224 snapshots,
225 snapshotReads,
226 syncCommands,
227 linkCommands,
228 summaryCalls,
229 stackCalls,
230 layer: PullRequestSyncReactor.layer.pipe(Layer.provide(dependencies)),
231 };
232});
233​
234type Harness = Effect.Success<ReturnType<typeof makeHarness>>;
235​
236const startAndSweep = Effect.fn("startPullRequestSyncHarness")(function* (fixture: Harness) {
237 const reactor = yield* PullRequestSyncReactor.PullRequestSyncReactor;
238 yield* reactor.start();
239 yield* Deferred.succeed(fixture.activation, undefined);
240 yield* Queue.take(fixture.snapshotReads);
241 yield* reactor.drain;
242 return reactor;
243});
244​
245const sweepAgain = Effect.fn("sweepPullRequestSyncHarness")(function* (
246 fixture: Harness,
247 reactor: PullRequestSyncReactor.PullRequestSyncReactor["Service"],
248) {
249 yield* TestClock.adjust("1 minute");
250 yield* Queue.take(fixture.snapshotReads);
251 yield* reactor.drain;
252});
253​
254/** What the reactor would have persisted, so the next sweep sees its own writes. */
255function applySync(
256 snapshot: OrchestrationShellSnapshot,
257 commands: ReadonlyArray<SyncCommand>,
258): OrchestrationShellSnapshot {
259 return {
260 ...snapshot,
261 snapshotSequence: snapshot.snapshotSequence + 1,
262 threads: snapshot.threads.map((thread) => ({
263 ...thread,
264 pullRequests: thread.pullRequests.map((link) => {
265 const command = commands.findLast(
266 (candidate) => candidate.threadId === thread.id && candidate.number === link.number,
267 );
268 return command === undefined
269 ? link
270 : { ...link, snapshot: command.snapshot, stack: command.stack };
271 }),
272 })),
273 };
275​
276describe("PullRequestSyncReactor", () => {
277 it.effect("retries a failed stack read after the summary becomes terminal", () =>
278 Effect.scoped(
279 Effect.gen(function* () {
280 yield* TestClock.setTime(Date.parse(NOW));
281 let attempts = 0;
282 const nativeStack: PullRequestStack = {
283 id: "stack",
284 number: 7,
285 url: "https://github.com/owner/repository/stacks/7",
286 base: "main",
287 layers: [{ number: 7, headBranch: "feature", state: "merged" }],
288 };
289 const fixture = yield* makeHarness({
290 snapshot: makeSnapshot([makeThread("one", { pullRequests: [makeLink(7)] })]),
291 summary: (input) =>
292 Effect.succeed(makeSummary(input, { state: "merged", mergedAt: NOW })),
293 stack: () =>
294 ++attempts === 1
295 ? Effect.fail(
296 new PullRequestOperationError({
297 operation: "stack",
298 detail: "temporary failure",
299 }),
300 )
301 : Effect.succeed(nativeStack),
302 });
303 yield* Effect.gen(function* () {
304 const reactor = yield* startAndSweep(fixture);
305 const commands = yield* Ref.get(fixture.syncCommands);
306 yield* Ref.update(fixture.snapshots, (snapshot) => applySync(snapshot, commands));
307 yield* sweepAgain(fixture, reactor);
308 assert.strictEqual(attempts, 2);
309 assert.deepStrictEqual((yield* Ref.get(fixture.syncCommands)).at(-1)?.stack, {
310 kind: "native",
311 ...nativeStack,
312 });
313 }).pipe(Effect.provide(fixture.layer));
314 }),
315 ),
316 );
317​
318 it.effect("explicit refresh reads a changed stack even when its PR summary is unchanged", () =>
319 Effect.scoped(
320 Effect.gen(function* () {
321 yield* TestClock.setTime(Date.parse(NOW));
322 const fixture = yield* makeHarness({
323 snapshot: makeSnapshot([makeThread("one", { pullRequests: [makeLink(7, {})] })]),
324 });
325 yield* Effect.gen(function* () {
326 const reactor = yield* startAndSweep(fixture);
327 assert.strictEqual((yield* Ref.get(fixture.stackCalls)).length, 0);
328 yield* reactor.requestSync({
329 host: "github.com",
330 repository: "owner/repository",
331 number: 7,
332 });
333 yield* Queue.take(fixture.snapshotReads);
334 yield* reactor.drain;
335 assert.strictEqual((yield* Ref.get(fixture.stackCalls)).length, 1);
336 }).pipe(Effect.provide(fixture.layer));
337 }),
338 ),
339 );
340 it.effect("snapshots an unsynced link once and writes it to the thread", () =>
341 Effect.scoped(
342 Effect.gen(function* () {
343 yield* TestClock.setTime(Date.parse(NOW));
344 const fixture = yield* makeHarness({
345 snapshot: makeSnapshot([makeThread("one", { pullRequests: [makeLink(42)] })]),
346 summary: (input) =>
347 Effect.succeed(makeSummary(input, { title: "Ship it", isDraft: true })),
348 });
349​
350 yield* Effect.gen(function* () {
351 yield* startAndSweep(fixture);
352​
353 assert.deepStrictEqual(yield* Ref.get(fixture.summaryCalls), [
354 {
355 projectId: PROJECT_ID,
356 host: "github.com",
357 repository: "owner/repository",
358 number: 42,
359 },
360 ]);
361 assert.deepStrictEqual(
362 (yield* Ref.get(fixture.syncCommands)).map(({ commandId: _, ...rest }) => rest),
363 [
364 {
365 type: "thread.pull-request-link.sync",
366 threadId: ThreadId.make("one"),
367 host: "github.com",
368 repository: "owner/repository",
369 number: 42,
370 snapshot: {
371 state: "open",
372 title: "Ship it",
373 headBranch: "feature",
374 baseBranch: "main",
375 isDraft: true,
376 updatedAt: "2026-08-27T00:00:00.000Z",
377 syncedAt: NOW,
378 closedAt: null,
379 mergedAt: null,
380 },
381 stack: null,
382 },
383 ],
384 );
385 assert.strictEqual((yield* Ref.get(fixture.stackCalls)).length, 1);
386 }).pipe(Effect.provide(fixture.layer));
387 }),
388 ),
389 );
390​
391 it.effect("asks the host once for a pull request shared by two threads", () =>
392 Effect.scoped(
393 Effect.gen(function* () {
394 yield* TestClock.setTime(Date.parse(NOW));
395 const fixture = yield* makeHarness({
396 snapshot: makeSnapshot([
397 makeThread("one", { pullRequests: [makeLink(42)] }),
398 makeThread("two", {
399 pullRequests: [makeLink(42, null, { repository: "Owner/Repository" })],
400 }),
401 ]),
402 });
403​
404 yield* Effect.gen(function* () {
405 yield* startAndSweep(fixture);
406​
407 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);
408 const commands = yield* Ref.get(fixture.syncCommands);
409 assert.deepStrictEqual(
410 commands
411 .map((command) => [command.threadId, command.repository] as const)
412 .sort((left, right) => left[0].localeCompare(right[0])),
413 [
414 [ThreadId.make("one"), "owner/repository"],
415 [ThreadId.make("two"), "Owner/Repository"],
416 ],
417 );
418 }).pipe(Effect.provide(fixture.layer));
419 }),
420 ),
421 );
422​
423 it.effect("dispatches nothing when the host snapshot is unchanged", () =>
424 Effect.scoped(
425 Effect.gen(function* () {
426 yield* TestClock.setTime(Date.parse(NOW));
427 const fixture = yield* makeHarness({
428 snapshot: makeSnapshot([makeThread("one", { pullRequests: [makeLink(42)] })]),
429 });
430​
431 yield* Effect.gen(function* () {
432 const reactor = yield* startAndSweep(fixture);
433 const firstSweep = yield* Ref.get(fixture.syncCommands);
434 assert.strictEqual(firstSweep.length, 1);
435 yield* Ref.update(fixture.snapshots, (snapshot) => applySync(snapshot, firstSweep));
436​
437 yield* sweepAgain(fixture, reactor);
438​
439 // Still open on an active thread, so the host was asked again, but nothing changed.
440 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);
441 assert.strictEqual((yield* Ref.get(fixture.stackCalls)).length, 1);
442 assert.strictEqual((yield* Ref.get(fixture.syncCommands)).length, 1);
443 }).pipe(Effect.provide(fixture.layer));
444 }),
445 ),
446 );
447​
448 it.effect("refreshes closed links through the reactor's project after reopening elsewhere", () =>
449 Effect.scoped(
450 Effect.gen(function* () {
451 yield* TestClock.setTime(Date.parse(NOW));
452 const stale = yield* Ref.make(true);
453 const fixture = yield* makeHarness({
454 snapshot: makeSnapshot([
455 makeThread("first", { pullRequests: [makeLink(42, { state: "closed" })] }),
456 makeThread("second", {
457 projectId: ProjectId.make("second-project"),
458 pullRequests: [makeLink(42, { state: "closed" })],
459 }),
460 ]),
461 invalidate: ({ reference }) =>
462 reference?.projectId === makeProject().id && reference.host === "github.com"
463 ? Ref.set(stale, false)
464 : Effect.void,
465 summary: (input) =>
466 Ref.get(stale).pipe(
467 Effect.map((cached) => makeSummary(input, { state: cached ? "closed" : "open" })),
468 ),
469 });
470 yield* Effect.gen(function* () {
471 const reactor = yield* startAndSweep(fixture);
472 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);
473 yield* reactor.requestSync({
474 host: "github.com",
475 repository: "owner/repository",
476 number: 42,
477 });
478 yield* Queue.take(fixture.snapshotReads);
479 yield* reactor.drain;
480 const commands = yield* Ref.get(fixture.syncCommands);
481 yield* Ref.update(fixture.snapshots, (snapshot) => applySync(snapshot, commands));
482 const snapshot = yield* Ref.get(fixture.snapshots);
483 assert.deepStrictEqual(
484 snapshot.threads.map((thread) => thread.pullRequests[0]?.snapshot?.state),
485 ["open", "open"],
486 );
487 }).pipe(Effect.provide(fixture.layer));
488 }),
489 ),
490 );
491​
492 it.effect("stops asking the host once a pull request is merged", () =>
493 Effect.scoped(
494 Effect.gen(function* () {
495 yield* TestClock.setTime(Date.parse(NOW));
496 const fixture = yield* makeHarness({
497 snapshot: makeSnapshot([
498 makeThread("merged", { pullRequests: [makeLink(1, { state: "merged" })] }),
499 ]),
500 });
501​
502 yield* Effect.gen(function* () {
503 const reactor = yield* startAndSweep(fixture);
504 yield* sweepAgain(fixture, reactor);
505​
506 assert.deepStrictEqual(yield* Ref.get(fixture.summaryCalls), []);
507 assert.deepStrictEqual(yield* Ref.get(fixture.syncCommands), []);
508​
509 yield* reactor.requestSync({
510 host: "github.com",
511 repository: "owner/repository",
512 number: 1,
513 });
514 yield* Queue.take(fixture.snapshotReads);
515 yield* reactor.drain;
516​
517 assert.deepStrictEqual(
518 (yield* Ref.get(fixture.summaryCalls)).map((call) => call.number),
519 [1],
520 );
521 }).pipe(Effect.provide(fixture.layer));
522 }),
523 ),
524 );
525​
526 it.effect("discovers externally reopened pull requests after fifteen minutes", () =>
527 Effect.scoped(
528 Effect.gen(function* () {
529 yield* TestClock.setTime(Date.parse(NOW));
530 const state = yield* Ref.make<"closed" | "open">("closed");
531 const fixture = yield* makeHarness({
532 snapshot: makeSnapshot([
533 makeThread("closed", { pullRequests: [makeLink(2, { state: "closed" })] }),
534 ]),
535 summary: (input) =>
536 Ref.get(state).pipe(Effect.map((state) => makeSummary(input, { state }))),
537 });
538 yield* Effect.gen(function* () {
539 const reactor = yield* startAndSweep(fixture);
540 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);
541 yield* Ref.set(state, "open");
542 for (let index = 0; index < 14; index += 1) yield* sweepAgain(fixture, reactor);
543 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);
544 yield* sweepAgain(fixture, reactor);
545 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);
546 assert.strictEqual((yield* Ref.get(fixture.syncCommands)).at(-1)?.snapshot.state, "open");
547 }).pipe(Effect.provide(fixture.layer));
548 }),
549 ),
550 );
551​
552 it.effect("preserves a refresh requested while an older host read is in flight", () =>
553 Effect.scoped(
554 Effect.gen(function* () {
555 yield* TestClock.setTime(Date.parse(NOW));
556 const reading = yield* Deferred.make<void>();
557 const release = yield* Deferred.make<void>();
558 let calls = 0;
559 const fixture = yield* makeHarness({
560 snapshot: makeSnapshot([]),
561 summary: (input) =>
562 Effect.gen(function* () {
563 calls += 1;
564 if (calls === 1) {
565 yield* Deferred.succeed(reading, undefined);
566 yield* Deferred.await(release);
567 }
568 return makeSummary(input, { state: calls === 1 ? "closed" : "open" });
569 }),
570 });
571 yield* Effect.gen(function* () {
572 const reactor = yield* startAndSweep(fixture);
573 yield* Ref.set(
574 fixture.snapshots,
575 makeSnapshot([
576 makeThread("closed", { pullRequests: [makeLink(2, { state: "closed" })] }),
577 ]),
578 );
579 const key = { host: "github.com", repository: "owner/repository", number: 2 };
580 yield* reactor.requestSync(key);
581 yield* Deferred.await(reading);
582 yield* reactor.requestSync(key);
583 yield* Deferred.succeed(release, undefined);
584 yield* reactor.drain;
585 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);
586 assert.strictEqual((yield* Ref.get(fixture.syncCommands)).at(-1)?.snapshot.state, "open");
587 }).pipe(Effect.provide(fixture.layer));
588 }),
589 ),
590 );
591​
592 it.effect("polls open pull requests on settled threads every fifteen minutes", () =>
593 Effect.scoped(
594 Effect.gen(function* () {
595 yield* TestClock.setTime(Date.parse(NOW));
596 const fixture = yield* makeHarness({
597 snapshot: makeSnapshot([
598 makeThread("settled", {
599 settledOverride: "settled",
600 settledAt: "2026-08-21T00:00:00.000Z",
601 pullRequests: [makeLink(5, { state: "open" })],
602 }),
603 ]),
604 });
605​
606 yield* Effect.gen(function* () {
607 const reactor = yield* startAndSweep(fixture);
608 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);
609​
610 yield* sweepAgain(fixture, reactor);
611 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);
612​
613 for (let index = 0; index < 13; index += 1) yield* sweepAgain(fixture, reactor);
614 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 1);
615​
616 yield* sweepAgain(fixture, reactor);
617 assert.strictEqual((yield* Ref.get(fixture.summaryCalls)).length, 2);
618 }).pipe(Effect.provide(fixture.layer));
619 }),
620 ),
621 );
622​
623 it.effect("auto-links missing native stack layers and leaves dismissed ones alone", () =>
624 Effect.scoped(
625 Effect.gen(function* () {
626 yield* TestClock.setTime(Date.parse(NOW));
627 const stack: PullRequestStack = {
628 id: "stack-1",
629 number: 42,
630 url: "https://github.com/owner/repository/stack/1",
631 base: "main",
632 layers: [
633 { number: 41, headBranch: "layer-1", state: "merged" },
634 { number: 42, headBranch: "layer-2", state: "open" },
635 { number: 43, headBranch: "layer-3", state: "open" },
636 ],
637 };
638 const fixture = yield* makeHarness({
639 snapshot: makeSnapshot([
640 makeThread("one", {
641 pullRequests: [
642 makeLink(42),
643 makeLink(41, { state: "merged" }, { source: "stack-dismissed" }),
644 ],
645 }),
646 ]),
647 stack: () => Effect.succeed(stack),
648 });
649​
650 yield* Effect.gen(function* () {
651 yield* startAndSweep(fixture);
652​
653 const syncCommands = yield* Ref.get(fixture.syncCommands);
654 assert.deepStrictEqual(
655 syncCommands.map((command) => [command.number, command.stack] as const),
656 [[42, { kind: "native", ...stack }]],
657 );
658 assert.deepStrictEqual(
659 (yield* Ref.get(fixture.linkCommands)).map(({ commandId: _, ...rest }) => rest),
660 [
661 {
662 type: "thread.pull-request.link",
663 threadId: ThreadId.make("one"),
664 host: "github.com",
665 repository: "owner/repository",
666 number: 43,
667 url: "https://github.com/owner/repository/pull/43",
668 source: "stack",
669 },
670 ],
671 );
672 }).pipe(Effect.provide(fixture.layer));
673 }),
674 ),
675 );
676​
677 it.effect("keeps existing snapshots and continues when the host fails", () =>
678 Effect.scoped(
679 Effect.gen(function* () {
680 yield* TestClock.setTime(Date.parse(NOW));
681 const fixture = yield* makeHarness({
682 snapshot: makeSnapshot([
683 makeThread("failing", { pullRequests: [makeLink(7, { state: "open" })] }),
684 makeThread("fine", { pullRequests: [makeLink(8)] }),
685 ]),
686 summary: (input) =>
687 input.number === 7
688 ? Effect.fail(
689 new PullRequestOperationError({ operation: "summary", detail: "host down" }),
690 )
691 : Effect.succeed(makeSummary(input)),
692 });
693​
694 yield* Effect.gen(function* () {
695 yield* startAndSweep(fixture);
696​
697 assert.deepStrictEqual(
698 (yield* Ref.get(fixture.syncCommands)).map((command) => command.number),
699 [8],
700 );
701 }).pipe(Effect.provide(fixture.layer));
702 }),
703 ),
704 );
705});