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

VcsStatusBroadcaster.test.ts

1,114 lines45.3 KB

1import { SourceControlProviderKind } from "@t3tools/contracts";
2import { assert, it, describe } from "@effect/vitest";
3import * as NodeServices from "@effect/platform-node/NodeServices";
4import * as Deferred from "effect/Deferred";
5import * as DateTime from "effect/DateTime";
6import * as Duration from "effect/Duration";
7import * as Effect from "effect/Effect";
8import * as Fiber from "effect/Fiber";
9import * as Exit from "effect/Exit";
10import * as FileSystem from "effect/FileSystem";
11import * as Layer from "effect/Layer";
12import * as Option from "effect/Option";
13import * as Path from "effect/Path";
14import * as Scope from "effect/Scope";
15import * as Scheduler from "effect/Scheduler";
16import * as Stream from "effect/Stream";
17import * as TestClock from "effect/testing/TestClock";
18import * as Tracer from "effect/Tracer";
19import type {
20 BackgroundScope,
21 VcsStatusLocalResult,
22 VcsStatusRemoteResult,
23 VcsStatusStreamEvent,
24} from "@t3tools/contracts";
25import { GitCommandError, GitManagerError } from "@t3tools/contracts";
26​
27import * as VcsStatusBroadcaster from "./VcsStatusBroadcaster.ts";
28import * as BackgroundPolicy from "../background/BackgroundPolicy.ts";
29import * as GitWorkflowService from "../git/GitWorkflowService.ts";
30import { symlinksSupported } from "@t3tools/shared/testing/symlinks";
31​
32const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z");
33​
34const baseLocalStatus: VcsStatusLocalResult = {
35 isRepo: true,
36 sourceControlProvider: {
37 kind: SourceControlProviderKind.make("github"),
38 name: "GitHub",
39 baseUrl: "https://github.com",
40 },
41 hasPrimaryRemote: true,
42 isDefaultRef: false,
43 refName: "feature/status-broadcast",
44 hasWorkingTreeChanges: false,
45 workingTree: { files: [], insertions: 0, deletions: 0 },
46};
47​
48const baseRemoteStatus: VcsStatusRemoteResult = {
49 hasUpstream: true,
50 aheadCount: 0,
51 behindCount: 0,
52 pr: null,
53};
54​
55const remoteStatusWithPr: VcsStatusRemoteResult = {
56 ...baseRemoteStatus,
57 pr: {
58 number: 2978,
59 title: "[codex] Rewrite client connection architecture",
60 url: "https://github.com/pingdotgg/t3code/pull/2978",
61 baseRef: "main",
62 headRef: "upstream-topic",
63 state: "open",
64 },
65};
66​
67function layerTestFor(state: {
68 currentLocalStatus: VcsStatusLocalResult;
69 currentRemoteStatus: VcsStatusRemoteResult | null;
70 localStatusCalls: number;
71 remoteStatusCalls: number;
72 localInvalidationCalls: number;
73 remoteInvalidationCalls: number;
74 remoteStatusRefreshUpstreamValues?: Array<boolean | undefined>;
75 remoteStatusError?: GitManagerError;
76 backgroundWorkEnabled?: boolean;
77 automaticFetchInterval?: Effect.Effect<Duration.Duration>;
78 beforeRemoteStatus?: Effect.Effect<void>;
79 beforeLocalStatus?: Effect.Effect<void>;
80 fileSystem?: FileSystem.FileSystem;
81 pullCurrentBranch?: GitWorkflowService.GitWorkflowService["Service"]["pullCurrentBranch"];
82}) {
83 return VcsStatusBroadcaster.layer.pipe(
84 Layer.provideMerge(
85 state.fileSystem
86 ? Layer.succeed(FileSystem.FileSystem, state.fileSystem)
87 : NodeServices.layer,
88 ),
89 Layer.provide(layerBackgroundPolicy(() => state.backgroundWorkEnabled !== false)),
90 Layer.provide(
91 Layer.succeed(
92 VcsStatusBroadcaster.VcsAutomaticFetchInterval,
93 state.automaticFetchInterval ?? Effect.succeed(Duration.seconds(30)),
94 ),
95 ),
96 Layer.provide(
97 Layer.mock(GitWorkflowService.GitWorkflowService)({
98 localStatus: () =>
99 Effect.suspend(() => {
100 state.localStatusCalls += 1;
101 return (state.beforeLocalStatus ?? Effect.void).pipe(
102 Effect.as(state.currentLocalStatus),
103 );
104 }),
105 currentBranch: () => Effect.sync(() => state.currentLocalStatus.refName),
106 remoteStatus: (_input, options) =>
107 Effect.suspend(() => {
108 return (state.beforeRemoteStatus ?? Effect.void).pipe(
109 Effect.andThen(
110 Effect.sync(() => {
111 state.remoteStatusCalls += 1;
112 state.remoteStatusRefreshUpstreamValues?.push(options?.refreshUpstream);
113 return state.currentRemoteStatus;
114 }),
115 ),
116 Effect.tap(() =>
117 state.remoteStatusError ? Effect.fail(state.remoteStatusError) : Effect.void,
118 ),
119 );
120 }),
121 invalidateLocalStatus: () =>
122 Effect.sync(() => {
123 state.localInvalidationCalls += 1;
124 }),
125 invalidateRemoteStatus: () =>
126 Effect.sync(() => {
127 state.remoteInvalidationCalls += 1;
128 }),
129 invalidateStatus: () =>
130 Effect.sync(() => {
131 state.localInvalidationCalls += 1;
132 state.remoteInvalidationCalls += 1;
133 }),
134 ...(state.pullCurrentBranch ? { pullCurrentBranch: state.pullCurrentBranch } : {}),
135 }),
136 ),
137 );
139​
140function layerBackgroundPolicy(shouldRunScopeWork: (scope: BackgroundScope) => boolean) {
141 return Layer.mock(BackgroundPolicy.BackgroundPolicy)({
142 reportClientActivity: () => Effect.void,
143 removeRpcClient: () => Effect.void,
144 snapshot: Effect.succeed({
145 hostPower: {
146 source: "unknown",
147 idle: "unknown",
148 idleSeconds: null,
149 locked: "unknown",
150 suspended: false,
151 onBattery: "unknown",
152 lowPowerMode: "unknown",
153 thermalState: "unknown",
154 stale: true,
155 updatedAt: TEST_EPOCH,
156 },
157 leases: [],
158 activeForegroundLeaseCount: 0,
159 activeScopeKeys: [],
160 shouldRunOpportunisticWork: false,
161 updatedAt: TEST_EPOCH,
162 }),
163 shouldRunScopeWork: (scope) => Effect.sync(() => shouldRunScopeWork(scope)),
164 shouldRunOpportunisticWork: Effect.succeed(true),
165 });
167​
168describe("VcsStatusBroadcaster", () => {
169 it.effect("refreshes queued behind a running one share the next git status read", () => {
170 const state: Parameters<typeof layerTestFor>[0] = {
171 currentLocalStatus: baseLocalStatus,
172 currentRemoteStatus: baseRemoteStatus,
173 localStatusCalls: 0,
174 remoteStatusCalls: 0,
175 localInvalidationCalls: 0,
176 remoteInvalidationCalls: 0,
177 fileSystem: FileSystem.makeNoop({ realPath: (cwd) => Effect.succeed(cwd) }),
178 };
179​
180 return Effect.gen(function* () {
181 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
182 const started = yield* Deferred.make<void>();
183 const release = yield* Deferred.make<void>();
184 state.beforeLocalStatus = Deferred.succeed(started, undefined).pipe(
185 Effect.andThen(Deferred.await(release)),
186 );
187 const running = yield* broadcaster
188 .refreshLocalStatus("/repo")
189 .pipe(Effect.forkScoped({ startImmediately: true }));
190 yield* Deferred.await(started);
191 // Requested while the first read runs, so that read may predate their change.
192 state.currentLocalStatus = { ...baseLocalStatus, hasWorkingTreeChanges: true };
193 const queued = yield* Effect.all(
194 [broadcaster.refreshLocalStatus("/repo"), broadcaster.refreshLocalStatus("/repo")],
195 { concurrency: "unbounded" },
196 ).pipe(Effect.forkScoped({ startImmediately: true }));
197 yield* Deferred.succeed(release, undefined);
198​
199 assert.isFalse((yield* Fiber.join(running)).hasWorkingTreeChanges);
200 const [second, third] = yield* Fiber.join(queued);
201 assert.isTrue(second.hasWorkingTreeChanges);
202 assert.isTrue(third.hasWorkingTreeChanges);
203 assert.strictEqual(state.localStatusCalls, 2);
204​
205 yield* broadcaster.refreshLocalStatus("/repo");
206 assert.strictEqual(state.localStatusCalls, 3);
207 }).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
208 });
209​
210 it.effect("publishes terminal branch switches and validates cached status reads", () => {
211 const state: Parameters<typeof layerTestFor>[0] = {
212 currentLocalStatus: baseLocalStatus,
213 currentRemoteStatus: remoteStatusWithPr,
214 localStatusCalls: 0,
215 remoteStatusCalls: 0,
216 localInvalidationCalls: 0,
217 remoteInvalidationCalls: 0,
218 };
219​
220 return Effect.gen(function* () {
221 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
222 yield* broadcaster.getStatus({ cwd: "/repo" });
223 const branchEvents = yield* broadcaster.streamBranchChanges.pipe(
224 Stream.take(2),
225 Stream.runCollect,
226 Effect.forkScoped({ startImmediately: true }),
227 );
228 const subscribed = yield* Deferred.make<void>();
229 const events = yield* broadcaster.streamStatus({ cwd: "/repo", includeRemote: false }).pipe(
230 Stream.tap((event) =>
231 event._tag === "snapshot" ? Deferred.succeed(subscribed, undefined) : Effect.void,
232 ),
233 Stream.take(3),
234 Stream.runCollect,
235 Effect.forkScoped,
236 );
237 yield* Deferred.await(subscribed);
238​
239 state.currentLocalStatus = { ...baseLocalStatus, refName: "main" };
240 const refreshed = yield* broadcaster.refreshStatus("/repo", { localOnly: true });
241 assert.equal(refreshed.refName, "main");
242 assert.isNull(refreshed.pr);
243 assert.equal(state.localInvalidationCalls, 1);
244 assert.equal(state.remoteStatusCalls, 1);
245 assert.equal(state.remoteInvalidationCalls, 2);
246 assert.deepStrictEqual((yield* Fiber.join(events)).slice(1), [
247 { _tag: "remoteUpdated", remote: null },
248 { _tag: "localUpdated", local: state.currentLocalStatus },
249 ]);
250 assert.isNull((yield* broadcaster.getStatus({ cwd: "/repo" })).pr);
251 state.currentLocalStatus = { ...state.currentLocalStatus, hasWorkingTreeChanges: true };
252 yield* broadcaster.refreshLocalStatus("/repo");
253 state.currentLocalStatus = { ...baseLocalStatus, refName: "union" };
254 state.currentRemoteStatus = null;
255 const queried = yield* broadcaster.getStatus({ cwd: "/repo" });
256 assert.equal(queried.refName, "union");
257 assert.isNull(queried.pr);
258 const snapshot = yield* broadcaster
259 .streamStatus({ cwd: "/repo", includeRemote: false })
260 .pipe(Stream.take(1), Stream.runCollect);
261 assert.deepStrictEqual(snapshot[0], {
262 _tag: "snapshot",
263 local: state.currentLocalStatus,
264 remote: null,
265 });
266 assert.deepStrictEqual(yield* Fiber.join(branchEvents), [
267 { cwd: "/repo", refName: "main" },
268 { cwd: "/repo", refName: "union" },
269 ]);
270 }).pipe(Effect.provide(layerTestFor(state)));
271 });
272​
273 it.effect(
274 "preserves cached remote status when a local-only refresh stays on the same branch",
275 () => {
276 const state = {
277 currentLocalStatus: baseLocalStatus,
278 currentRemoteStatus: { ...remoteStatusWithPr, aheadCount: 2, behindCount: 3 },
279 localStatusCalls: 0,
280 remoteStatusCalls: 0,
281 localInvalidationCalls: 0,
282 remoteInvalidationCalls: 0,
283 };
284​
285 return Effect.gen(function* () {
286 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
287 const initial = yield* broadcaster.getStatus({ cwd: "/repo" });
288 const refreshed = yield* broadcaster.refreshStatus("/repo", { localOnly: true });
289 assert.deepStrictEqual(refreshed, initial);
290 assert.deepStrictEqual(yield* broadcaster.getStatus({ cwd: "/repo" }), refreshed);
291 assert.equal(state.localInvalidationCalls, 1);
292 assert.equal(state.remoteInvalidationCalls, 1);
293 assert.equal(state.remoteStatusCalls, 1);
294 }).pipe(Effect.provide(layerTestFor(state)));
295 },
296 );
297​
298 it.effect("clears the previous branch's remote status after an in-flight PR refresh", () => {
299 const remoteReadStarted = Deferred.makeUnsafe<void>();
300 const releaseRemoteRead = Deferred.makeUnsafe<void>();
301 const state = {
302 currentLocalStatus: baseLocalStatus,
303 currentRemoteStatus: remoteStatusWithPr,
304 localStatusCalls: 0,
305 remoteStatusCalls: 0,
306 localInvalidationCalls: 0,
307 remoteInvalidationCalls: 0,
308 beforeRemoteStatus: Effect.void,
309 };
310​
311 return Effect.gen(function* () {
312 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
313 yield* broadcaster.getStatus({ cwd: "/repo" });
314 state.beforeRemoteStatus = Deferred.succeed(remoteReadStarted, undefined).pipe(
315 Effect.andThen(Deferred.await(releaseRemoteRead)),
316 );
317 const remoteRefresh = yield* broadcaster
318 .refreshPullRequestStatus("/repo")
319 .pipe(Effect.forkScoped);
320 yield* Deferred.await(remoteReadStarted);
321 state.currentLocalStatus = { ...baseLocalStatus, refName: "main" };
322 const localRefresh = yield* broadcaster
323 .refreshStatus("/repo", { localOnly: true })
324 .pipe(Effect.forkScoped);
325 yield* Deferred.succeed(releaseRemoteRead, undefined);
326 yield* Fiber.join(remoteRefresh);
327 yield* Fiber.join(localRefresh);
328​
329 const status = yield* broadcaster.getStatus({ cwd: "/repo" });
330 assert.equal(status.refName, "main");
331 assert.isNull(status.pr);
332 assert.equal(status.aheadCount, 0);
333 assert.equal(status.behindCount, 0);
334 assert.equal(state.remoteStatusCalls, 2);
335 }).pipe(Effect.provide(layerTestFor(state)));
336 });
337​
338 it.effect.skipIf(!symlinksSupported)(
339 "automatically pulls an enabled clean default branch when status detects it is behind",
340 () => {
341 let remoteStatus: VcsStatusRemoteResult = { ...baseRemoteStatus, behindCount: 2 };
342 let pullCalls = 0;
343 let configuredWorkspaceRoot = "";
344 const localStatus: VcsStatusLocalResult = {
345 ...baseLocalStatus,
346 isDefaultRef: true,
347 refName: "main",
348 };
349 const layerTest = VcsStatusBroadcaster.layer.pipe(
350 Layer.provideMerge(NodeServices.layer),
351 Layer.provide(layerBackgroundPolicy(() => true)),
352 Layer.provide(
353 Layer.succeed(VcsStatusBroadcaster.VcsAutoPullPolicy, {
354 isEnabled: (cwd) => Effect.succeed(cwd === configuredWorkspaceRoot),
355 }),
356 ),
357 Layer.provide(
358 Layer.mock(GitWorkflowService.GitWorkflowService)({
359 localStatus: () => Effect.succeed(localStatus),
360 currentBranch: () => Effect.succeed(localStatus.refName),
361 remoteStatus: () => Effect.succeed(remoteStatus),
362 invalidateLocalStatus: () => Effect.void,
363 invalidateRemoteStatus: () => Effect.void,
364 invalidateStatus: () => Effect.void,
365 pullCurrentBranch: () =>
366 Effect.sync(() => {
367 pullCalls += 1;
368 remoteStatus = { ...remoteStatus, behindCount: 0 };
369 return {
370 status: "pulled" as const,
371 refName: "main",
372 upstreamRef: "origin/main",
373 };
374 }),
375 }),
376 ),
377 );
378​
379 return Effect.gen(function* () {
380 const fileSystem = yield* FileSystem.FileSystem;
381 const path = yield* Path.Path;
382 const realDir = yield* fileSystem.makeTempDirectoryScoped({
383 prefix: "t3-vcs-auto-pull-real-",
384 });
385 const linkParent = yield* fileSystem.makeTempDirectoryScoped({
386 prefix: "t3-vcs-auto-pull-link-",
387 });
388 configuredWorkspaceRoot = path.join(linkParent, "repo-link");
389 yield* fileSystem.symlink(realDir, configuredWorkspaceRoot);
390​
391 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
392 const status = yield* broadcaster.refreshStatus(configuredWorkspaceRoot);
393​
394 assert.equal(pullCalls, 1);
395 assert.equal(status.behindCount, 0);
396 }).pipe(Effect.provide(layerTest));
397 },
398 );
399​
400 it.effect("refreshes a loaded cwd without reusing a previous branch's PR", () => {
401 const state: Parameters<typeof layerTestFor>[0] = {
402 currentLocalStatus: baseLocalStatus,
403 currentRemoteStatus: { ...baseRemoteStatus, aheadCount: 3, behindCount: 5 },
404 localStatusCalls: 0,
405 remoteStatusCalls: 0,
406 localInvalidationCalls: 0,
407 remoteInvalidationCalls: 0,
408 remoteStatusRefreshUpstreamValues: [],
409 };
410​
411 return Effect.gen(function* () {
412 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
413​
414 assert.isNull(yield* broadcaster.refreshPullRequestStatus("/repo"));
415 assert.equal(state.remoteStatusCalls, 0);
416​
417 yield* broadcaster.getStatus({ cwd: "/repo" });
418 assert.equal(state.remoteStatusCalls, 1);
419​
420 state.backgroundWorkEnabled = false;
421 state.currentRemoteStatus = { ...remoteStatusWithPr, aheadCount: 7 };
422 const refreshed = yield* broadcaster.refreshPullRequestStatus("/repo");
423 assert.deepStrictEqual(refreshed, state.currentRemoteStatus);
424 const merged = yield* broadcaster.getStatus({ cwd: "/repo" });
425 assert.equal(merged.aheadCount, 7);
426 assert.equal(merged.behindCount, 0);
427 assert.equal(state.remoteStatusRefreshUpstreamValues?.at(-1), false);
428 assert.equal(state.remoteStatusCalls, 2);
429 assert.equal(state.remoteInvalidationCalls, 2);
430​
431 state.currentLocalStatus = { ...baseLocalStatus, refName: "feature/next" };
432 state.currentRemoteStatus = baseRemoteStatus;
433 yield* broadcaster.refreshLocalStatus("/repo");
434 const refreshedBranch = yield* broadcaster.refreshPullRequestStatus("/repo");
435 assert.deepStrictEqual(refreshedBranch, baseRemoteStatus);
436 assert.equal(state.remoteStatusCalls, 3);
437 const refreshedStatus = yield* broadcaster.getStatus({ cwd: "/repo" });
438 assert.equal(refreshedStatus.refName, "feature/next");
439 assert.isNull(refreshedStatus.pr);
440 assert.equal(state.remoteStatusCalls, 3);
441 assert.equal(state.remoteInvalidationCalls, 3);
442 }).pipe(Effect.provide(layerTestFor(state)));
443 });
444​
445 it.effect("a poll that started before the turn-end refresh cannot overwrite its PR", () => {
446 const releaseFirstPoll = Deferred.makeUnsafe<void>();
447 const firstPollStarted = Deferred.makeUnsafe<void>();
448 let remoteReads = 0;
449 const layer = VcsStatusBroadcaster.layer.pipe(
450 Layer.provideMerge(NodeServices.layer),
451 Layer.provide(layerBackgroundPolicy(() => true)),
452 Layer.provide(
453 Layer.mock(GitWorkflowService.GitWorkflowService)({
454 localStatus: () => Effect.succeed(baseLocalStatus),
455 currentBranch: () => Effect.succeed(baseLocalStatus.refName),
456 remoteStatus: () =>
457 Effect.gen(function* () {
458 remoteReads += 1;
459 if (remoteReads === 2) {
460 yield* Deferred.succeed(firstPollStarted, undefined);
461 yield* Deferred.await(releaseFirstPoll);
462 return baseRemoteStatus;
463 }
464 return remoteReads === 1 ? baseRemoteStatus : remoteStatusWithPr;
465 }),
466 invalidateLocalStatus: () => Effect.void,
467 invalidateRemoteStatus: () => Effect.void,
468 invalidateStatus: () => Effect.void,
469 }),
470 ),
471 );
472​
473 return Effect.gen(function* () {
474 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
475 yield* broadcaster.getStatus({ cwd: "/repo" });
476​
477 const poll = yield* broadcaster.refreshStatus("/repo").pipe(Effect.forkScoped);
478 yield* Deferred.await(firstPollStarted);
479 const refresh = yield* broadcaster.refreshPullRequestStatus("/repo").pipe(Effect.forkScoped);
480 yield* Deferred.succeed(releaseFirstPoll, undefined);
481 yield* Fiber.join(poll);
482 const refreshed = yield* Fiber.join(refresh);
483​
484 assert.deepStrictEqual(refreshed, remoteStatusWithPr);
485 const final = yield* broadcaster.getStatus({ cwd: "/repo" });
486 assert.deepStrictEqual(final.pr, remoteStatusWithPr.pr);
487 }).pipe(Effect.provide(layer), Effect.scoped);
488 });
489​
490 it.effect("an initial status read cannot overwrite an explicit refresh", () => {
491 const firstReadStarted = Deferred.makeUnsafe<void>();
492 const releaseFirstRead = Deferred.makeUnsafe<void>();
493 let remoteReads = 0;
494 const layer = VcsStatusBroadcaster.layer.pipe(
495 Layer.provide(FileSystem.layerNoop({ realPath: (path) => Effect.succeed(path) })),
496 Layer.provideMerge(NodeServices.layer),
497 Layer.provide(layerBackgroundPolicy(() => true)),
498 Layer.provide(
499 Layer.mock(GitWorkflowService.GitWorkflowService)({
500 localStatus: () => Effect.succeed(baseLocalStatus),
501 currentBranch: () => Effect.succeed(baseLocalStatus.refName),
502 remoteStatus: () =>
503 Effect.gen(function* () {
504 remoteReads += 1;
505 if (remoteReads === 1) {
506 yield* Deferred.succeed(firstReadStarted, undefined);
507 yield* Deferred.await(releaseFirstRead);
508 return baseRemoteStatus;
509 }
510 return remoteStatusWithPr;
511 }),
512 invalidateLocalStatus: () => Effect.void,
513 invalidateRemoteStatus: () => Effect.void,
514 invalidateStatus: () => Effect.void,
515 }),
516 ),
517 );
518 return Effect.gen(function* () {
519 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
520 const initial = yield* broadcaster.getStatus({ cwd: "/repo" }).pipe(Effect.forkScoped);
521 yield* Deferred.await(firstReadStarted);
522 const refresh = yield* broadcaster.refreshStatus("/repo").pipe(Effect.forkScoped);
523 yield* TestClock.adjust(Duration.zero);
524 yield* Deferred.succeed(releaseFirstRead, undefined);
525 yield* Fiber.join(initial);
526 yield* Fiber.join(refresh);
527 assert.deepStrictEqual(
528 (yield* broadcaster.getStatus({ cwd: "/repo" })).pr,
529 remoteStatusWithPr.pr,
530 );
531 }).pipe(Effect.provide(layer), Effect.scoped);
532 });
533​
534 it.effect("keeps the published local snapshot when a refresh remote read fails", () => {
535 const state = {
536 currentLocalStatus: baseLocalStatus,
537 currentRemoteStatus: baseRemoteStatus,
538 localStatusCalls: 0,
539 remoteStatusCalls: 0,
540 localInvalidationCalls: 0,
541 remoteInvalidationCalls: 0,
542 failRemoteStatus: false,
543 };
544 const layerTest = VcsStatusBroadcaster.layer.pipe(
545 Layer.provideMerge(NodeServices.layer),
546 Layer.provide(layerBackgroundPolicy(() => true)),
547 Layer.provide(
548 Layer.mock(GitWorkflowService.GitWorkflowService)({
549 localStatus: () =>
550 Effect.sync(() => {
551 state.localStatusCalls += 1;
552 return state.currentLocalStatus;
553 }),
554 currentBranch: () => Effect.succeed(state.currentLocalStatus.refName),
555 remoteStatus: () =>
556 Effect.suspend(() => {
557 state.remoteStatusCalls += 1;
558 return state.failRemoteStatus
559 ? Effect.fail(
560 new GitManagerError({
561 operation: "VcsStatusBroadcaster.test",
562 cwd: "/repo",
563 detail: "remote status failed",
564 }),
565 )
566 : Effect.succeed(state.currentRemoteStatus);
567 }),
568 invalidateLocalStatus: () =>
569 Effect.sync(() => {
570 state.localInvalidationCalls += 1;
571 }),
572 invalidateRemoteStatus: () =>
573 Effect.sync(() => {
574 state.remoteInvalidationCalls += 1;
575 }),
576 invalidateStatus: () =>
577 Effect.sync(() => {
578 state.localInvalidationCalls += 1;
579 state.remoteInvalidationCalls += 1;
580 }),
581 }),
582 ),
583 );
584​
585 return Effect.gen(function* () {
586 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
587 yield* broadcaster.getStatus({ cwd: "/repo" });
588​
589 state.currentLocalStatus = {
590 ...baseLocalStatus,
591 refName: "feature/partial-refresh",
592 };
593 state.currentRemoteStatus = {
594 ...baseRemoteStatus,
595 aheadCount: 3,
596 };
597 state.failRemoteStatus = true;
598​
599 const refreshExit = yield* broadcaster.refreshStatus("/repo").pipe(Effect.exit);
600 const snapshot = yield* Stream.runHead(
601 broadcaster.streamStatus({ cwd: "/repo", includeRemote: false }),
602 );
603​
604 assert.isTrue(Exit.isFailure(refreshExit));
605 assert.isTrue(Option.isSome(snapshot));
606 const event = Option.getOrThrow(snapshot);
607 assert.equal(event._tag, "snapshot");
608 if (event._tag === "snapshot") {
609 assert.equal(event.local.refName, "feature/partial-refresh");
610 assert.isNull(event.remote);
611 }
612 }).pipe(Effect.provide(layerTest));
613 });
614​
615 it.effect.skipIf(!symlinksSupported)(
616 "normalizes symlinked CWDs before cache lookup and workflow calls",
617 () => {
618 const seenCwds: string[] = [];
619 const state = {
620 currentLocalStatus: baseLocalStatus,
621 currentRemoteStatus: baseRemoteStatus,
622 localStatusCalls: 0,
623 remoteStatusCalls: 0,
624 localInvalidationCalls: 0,
625 remoteInvalidationCalls: 0,
626 };
627 const layerTest = VcsStatusBroadcaster.layer.pipe(
628 Layer.provideMerge(NodeServices.layer),
629 Layer.provide(layerBackgroundPolicy(() => true)),
630 Layer.provide(
631 Layer.mock(GitWorkflowService.GitWorkflowService)({
632 localStatus: (input) =>
633 Effect.sync(() => {
634 seenCwds.push(input.cwd);
635 state.localStatusCalls += 1;
636 return state.currentLocalStatus;
637 }),
638 currentBranch: () => Effect.succeed(state.currentLocalStatus.refName),
639 remoteStatus: (input) =>
640 Effect.sync(() => {
641 seenCwds.push(input.cwd);
642 state.remoteStatusCalls += 1;
643 return state.currentRemoteStatus;
644 }),
645 invalidateLocalStatus: () =>
646 Effect.sync(() => {
647 state.localInvalidationCalls += 1;
648 }),
649 invalidateRemoteStatus: () =>
650 Effect.sync(() => {
651 state.remoteInvalidationCalls += 1;
652 }),
653 } satisfies Partial<GitWorkflowService.GitWorkflowService["Service"]>),
654 ),
655 );
656​
657 return Effect.gen(function* () {
658 const fileSystem = yield* FileSystem.FileSystem;
659 const path = yield* Path.Path;
660 const realDir = yield* fileSystem.makeTempDirectoryScoped({
661 prefix: "t3-vcs-status-real-",
662 });
663 const linkParent = yield* fileSystem.makeTempDirectoryScoped({
664 prefix: "t3-vcs-status-link-",
665 });
666 const linkDir = path.join(linkParent, "repo-link");
667 yield* fileSystem.symlink(realDir, linkDir);
668 const realPath = yield* fileSystem.realPath(realDir);
669​
670 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
671 yield* broadcaster.getStatus({ cwd: linkDir });
672 yield* broadcaster.getStatus({ cwd: realDir });
673​
674 assert.deepStrictEqual(seenCwds, [realPath, realPath]);
675 assert.equal(state.localStatusCalls, 1);
676 assert.equal(state.remoteStatusCalls, 1);
677 }).pipe(Effect.provide(layerTest));
678 },
679 );
680​
681 it.effect("a remote poll refreshes Changes totals when divergence counts stay the same", () => {
682 const state: Parameters<typeof layerTestFor>[0] = {
683 currentLocalStatus: {
684 ...baseLocalStatus,
685 branchChanges: { baseRef: "origin/main", insertions: 745, deletions: 24 },
686 },
687 currentRemoteStatus: baseRemoteStatus,
688 localStatusCalls: 0,
689 remoteStatusCalls: 0,
690 localInvalidationCalls: 0,
691 remoteInvalidationCalls: 0,
692 };
693​
694 return Effect.gen(function* () {
695 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
696 yield* broadcaster.getStatus({ cwd: "/repo" });
697 const subscribed = yield* Deferred.make<void>();
698 const polled = yield* Deferred.make<void>();
699 yield* broadcaster.streamStatus({ cwd: "/repo" }).pipe(
700 Stream.runForEach((event) => {
701 if (event._tag === "snapshot") return Deferred.succeed(subscribed, undefined);
702 if (event._tag === "remoteUpdated") return Deferred.succeed(polled, undefined);
703 return Effect.void;
704 }),
705 Effect.forkScoped,
706 );
707 yield* Deferred.await(subscribed);
708 state.currentLocalStatus = {
709 ...baseLocalStatus,
710 branchChanges: { baseRef: "origin/main", insertions: 107, deletions: 4 },
711 };
712 state.currentRemoteStatus = remoteStatusWithPr;
713 yield* TestClock.adjust("30 seconds");
714 yield* Deferred.await(polled);
715 const status = yield* broadcaster.getStatus({ cwd: "/repo" });
716 assert.deepStrictEqual(status.branchChanges, state.currentLocalStatus.branchChanges);
717 }).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
718 });
719​
720 it.effect("an explicit refresh reads local totals after the fetch", () => {
721 return Effect.gen(function* () {
722 const fetchStarted = yield* Deferred.make<void>();
723 const finishFetch = yield* Deferred.make<void>();
724 let local: VcsStatusLocalResult = {
725 ...baseLocalStatus,
726 branchChanges: { baseRef: "origin/main", insertions: 745, deletions: 24 },
727 };
728 let cachedLocal: VcsStatusLocalResult | undefined;
729 const readLocalStatus = () => Effect.sync(() => (cachedLocal ??= local));
730 const layerTest = VcsStatusBroadcaster.layer.pipe(
731 Layer.provideMerge(NodeServices.layer),
732 Layer.provide(layerBackgroundPolicy(() => true)),
733 Layer.provide(
734 Layer.mock(GitWorkflowService.GitWorkflowService)({
735 localStatus: readLocalStatus,
736 invalidateStatus: () =>
737 Effect.sync(() => {
738 cachedLocal = undefined;
739 }),
740 invalidateLocalStatus: () =>
741 Effect.sync(() => {
742 cachedLocal = undefined;
743 }),
744 currentBranch: () => Effect.succeed(baseLocalStatus.refName),
745 invalidateRemoteStatus: () => Effect.void,
746 remoteStatus: () =>
747 Deferred.succeed(fetchStarted, undefined).pipe(
748 Effect.andThen(Deferred.await(finishFetch)),
749 Effect.as(baseRemoteStatus),
750 ),
751 }),
752 ),
753 );
754 yield* Effect.gen(function* () {
755 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
756 const refresh = yield* broadcaster.refreshStatus("/repo").pipe(Effect.forkScoped);
757 yield* Deferred.await(fetchStarted);
758 // Another reader can refill the local cache while fetch is still running.
759 yield* readLocalStatus();
760 local = {
761 ...baseLocalStatus,
762 branchChanges: { baseRef: "origin/main", insertions: 0, deletions: 0 },
763 };
764 yield* Deferred.succeed(finishFetch, undefined);
765 const status = yield* Fiber.join(refresh);
766 assert.deepStrictEqual(status.branchChanges, local.branchChanges);
767 }).pipe(Effect.provide(layerTest));
768 });
769 });
770​
771 it.effect("publishes local status while an earlier lookup holds the remote lock", () => {
772 const state: Parameters<typeof layerTestFor>[0] = {
773 currentLocalStatus: baseLocalStatus,
774 currentRemoteStatus: baseRemoteStatus,
775 localStatusCalls: 0,
776 remoteStatusCalls: 0,
777 localInvalidationCalls: 0,
778 remoteInvalidationCalls: 0,
779 };
780​
781 return Effect.gen(function* () {
782 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
783 yield* broadcaster.getStatus({ cwd: "/repo" });
784 const subscribed = yield* Deferred.make<void>();
785 const published = yield* Deferred.make<VcsStatusLocalResult>();
786 yield* broadcaster.streamStatus({ cwd: "/repo", includeRemote: false }).pipe(
787 Stream.runForEach((event) => {
788 if (event._tag === "snapshot") return Deferred.succeed(subscribed, undefined);
789 if (event._tag === "localUpdated") return Deferred.succeed(published, event.local);
790 return Effect.void;
791 }),
792 Effect.forkScoped,
793 );
794 yield* Deferred.await(subscribed);
795 const started = yield* Deferred.make<void>();
796 const release = yield* Deferred.make<void>();
797 state.beforeRemoteStatus = Deferred.succeed(started, undefined).pipe(
798 Effect.andThen(Deferred.await(release)),
799 );
800 const earlier = yield* broadcaster.refreshPullRequestStatus("/repo").pipe(Effect.forkScoped);
801 yield* Deferred.await(started);
802 state.currentLocalStatus = { ...baseLocalStatus, hasWorkingTreeChanges: true };
803 const completed = yield* Deferred.make<void>();
804 const refresh = yield* broadcaster
805 .refreshStatus("/repo")
806 .pipe(Effect.ensuring(Deferred.succeed(completed, undefined)), Effect.forkScoped);
807​
808 assert.deepStrictEqual(yield* Deferred.await(published), state.currentLocalStatus);
809 assert.isFalse(yield* Deferred.isDone(completed));
810 assert.isFalse(yield* Deferred.isDone(release));
811 state.currentRemoteStatus = remoteStatusWithPr;
812 yield* Deferred.succeed(release, undefined);
813 yield* Fiber.join(earlier);
814 const status = yield* Fiber.join(refresh);
815 assert.isTrue(status.hasWorkingTreeChanges);
816 assert.deepStrictEqual(status.pr, remoteStatusWithPr.pr);
817 }).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
818 });
819​
820 it.effect("publishes local changes before a remote error and propagates that error", () => {
821 const remoteError = new GitManagerError({
822 operation: "VcsStatusBroadcaster.remoteStatus",
823 cwd: "/repo",
824 detail: "The controlled remote lookup failed.",
825 });
826 const state: Parameters<typeof layerTestFor>[0] = {
827 currentLocalStatus: baseLocalStatus,
828 currentRemoteStatus: remoteStatusWithPr,
829 localStatusCalls: 0,
830 remoteStatusCalls: 0,
831 localInvalidationCalls: 0,
832 remoteInvalidationCalls: 0,
833 };
834​
835 return Effect.gen(function* () {
836 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
837 yield* broadcaster.getStatus({ cwd: "/repo" });
838 const subscribed = yield* Deferred.make<void>();
839 const published = yield* Deferred.make<VcsStatusLocalResult>();
840 yield* broadcaster.streamStatus({ cwd: "/repo", includeRemote: false }).pipe(
841 Stream.runForEach((event) => {
842 if (event._tag === "snapshot") return Deferred.succeed(subscribed, undefined);
843 if (event._tag === "localUpdated") return Deferred.succeed(published, event.local);
844 return Effect.void;
845 }),
846 Effect.forkScoped,
847 );
848 yield* Deferred.await(subscribed);
849 const started = yield* Deferred.make<void>();
850 const release = yield* Deferred.make<void>();
851 const completed = yield* Deferred.make<void>();
852 state.beforeRemoteStatus = Deferred.succeed(started, undefined).pipe(
853 Effect.andThen(Deferred.await(release)),
854 );
855 state.currentLocalStatus = { ...baseLocalStatus, hasWorkingTreeChanges: true };
856 state.remoteStatusError = remoteError;
857 const refresh = yield* broadcaster
858 .refreshStatus("/repo")
859 .pipe(
860 Effect.result,
861 Effect.ensuring(Deferred.succeed(completed, undefined)),
862 Effect.forkScoped,
863 );
864 yield* Deferred.await(started);
865 assert.isFalse(yield* Deferred.isDone(completed));
866 const pending = Option.getOrThrow(
867 yield* Stream.runHead(broadcaster.streamStatus({ cwd: "/repo", includeRemote: false })),
868 );
869 assert.equal(pending._tag, "snapshot");
870 if (pending._tag === "snapshot") assert.isTrue(pending.local.hasWorkingTreeChanges);
871 yield* Deferred.succeed(release, undefined);
872 const result = yield* Fiber.join(refresh);
873 assert.equal(result._tag, "Failure");
874 if (result._tag === "Failure") assert.strictEqual(result.failure, remoteError);
875 const cached = yield* broadcaster.getStatus({ cwd: "/repo" });
876 assert.isTrue(cached.hasWorkingTreeChanges);
877 assert.deepStrictEqual(cached.pr, remoteStatusWithPr.pr);
878 assert.deepStrictEqual(yield* Deferred.await(published), state.currentLocalStatus);
879 }).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
880 });
881​
882 it.effect.each(["getStatus", "refreshStatus", "autoPull", "autoPullFailure"] as const)(
883 "%s keeps response parts consistent when local state changes after the remote cache write",
884 (operation) => {
885 const state: Parameters<typeof layerTestFor>[0] = {
886 currentLocalStatus: baseLocalStatus,
887 currentRemoteStatus: { ...remoteStatusWithPr, aheadCount: 3, behindCount: 5 },
888 localStatusCalls: 0,
889 remoteStatusCalls: 0,
890 localInvalidationCalls: 0,
891 remoteInvalidationCalls: 0,
892 fileSystem: FileSystem.makeNoop({ realPath: (cwd) => Effect.succeed(cwd) }),
893 };
894 const autoPull = operation === "autoPull" || operation === "autoPullFailure";
895 if (autoPull) {
896 state.currentLocalStatus = { ...baseLocalStatus, isDefaultRef: true };
897 state.currentRemoteStatus = { ...remoteStatusWithPr, aheadCount: 0, behindCount: 5 };
898 state.pullCurrentBranch = () =>
899 operation === "autoPullFailure"
900 ? Effect.fail(
901 new GitCommandError({
902 operation: "test.pull",
903 command: "pull",
904 cwd: "/repo",
905 detail: "Pull failed.",
906 }),
907 )
908 : Effect.succeed({
909 status: "pulled",
910 refName: "feature/status-broadcast",
911 upstreamRef: "origin/main",
912 });
913 }
914 const layerTest = layerTestFor(state).pipe(
915 Layer.provide(
916 Layer.succeed(VcsStatusBroadcaster.VcsAutoPullPolicy, {
917 isEnabled: () => Effect.succeed(autoPull),
918 }),
919 ),
920 );
921 return Effect.gen(function* () {
922 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
923 let switched = false;
924 let remoteWritten = false;
925 const writeCompleted = yield* Deferred.make<void>();
926 const localRefresh = yield* Effect.gen(function* () {
927 yield* Deferred.await(writeCompleted);
928 state.currentLocalStatus = { ...baseLocalStatus, refName: "feature/next-status" };
929 yield* broadcaster.refreshLocalStatus("/repo");
930 switched = true;
931 }).pipe(Effect.forkScoped);
932 const scheduler = new Scheduler.MixedScheduler();
933 const shouldYield = scheduler.shouldYield.bind(scheduler);
934 scheduler.shouldYield = (fiber) => (remoteWritten && !switched) || shouldYield(fiber);
935 const tracer = Tracer.make({
936 span: (options) => {
937 const span = new Tracer.NativeSpan(options);
938 const end = span.end.bind(span);
939 span.end = (time, exit) => {
940 end(time, exit);
941 if (
942 options.name !== "VcsStatusBroadcaster.updateCachedRemoteStatus" ||
943 remoteWritten
944 ) {
945 return;
946 }
947 // Yield this reader after its write until the local refresh finishes.
948 remoteWritten = true;
949 Deferred.doneUnsafe(writeCompleted, Effect.void);
950 };
951 return span;
952 },
953 });
954 const status = yield* (
955 operation === "getStatus"
956 ? broadcaster.getStatus({ cwd: "/repo" })
957 : broadcaster.refreshStatus("/repo")
958 ).pipe(Effect.withTracer(tracer), Effect.provideService(Scheduler.Scheduler, scheduler));
959 yield* Fiber.join(localRefresh);
960 assert.isTrue(switched);
961 assert.equal(status.refName, "feature/next-status");
962 assert.isNull(status.pr);
963 assert.equal(status.aheadCount, 0);
964 assert.equal(status.behindCount, 0);
965 }).pipe(Effect.provide(layerTest), Effect.scoped);
966 },
967 );
968​
969 it.effect("recovers a discarded branch lookup on the next turn-end refresh", () => {
970 const state: Parameters<typeof layerTestFor>[0] = {
971 currentLocalStatus: baseLocalStatus,
972 currentRemoteStatus: { ...remoteStatusWithPr, aheadCount: 3, behindCount: 5 },
973 localStatusCalls: 0,
974 remoteStatusCalls: 0,
975 localInvalidationCalls: 0,
976 remoteInvalidationCalls: 0,
977 };
978​
979 return Effect.gen(function* () {
980 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
981 const started = yield* Deferred.make<void>();
982 const release = yield* Deferred.make<void>();
983 state.beforeRemoteStatus = Deferred.succeed(started, undefined).pipe(
984 Effect.andThen(Deferred.await(release)),
985 );
986 const lookup = yield* broadcaster.getStatus({ cwd: "/repo" }).pipe(Effect.forkScoped);
987 yield* Deferred.await(started);
988 state.currentLocalStatus = { ...baseLocalStatus, refName: "feature/next-status" };
989 yield* Deferred.succeed(release, undefined);
990 const discarded = yield* Fiber.join(lookup);
991 assert.equal(discarded.refName, state.currentLocalStatus.refName);
992 assert.isNull(discarded.pr);
993 assert.equal(discarded.aheadCount, 0);
994 assert.equal(discarded.behindCount, 0);
995 const snapshot = Option.getOrThrow(
996 yield* Stream.runHead(broadcaster.streamStatus({ cwd: "/repo", includeRemote: false })),
997 );
998 assert.equal(snapshot._tag, "snapshot");
999 if (snapshot._tag === "snapshot") assert.isNull(snapshot.remote);
1000​
1001 state.beforeRemoteStatus = Effect.void;
1002 state.currentRemoteStatus = {
1003 ...baseRemoteStatus,
1004 aheadCount: 2,
1005 pr: { ...remoteStatusWithPr.pr!, number: 2979, headRef: "feature/next-status" },
1006 };
1007 state.backgroundWorkEnabled = false;
1008 const recovered = yield* broadcaster.refreshPullRequestStatus("/repo");
1009 assert.deepStrictEqual(recovered, state.currentRemoteStatus);
1010 const cached = yield* broadcaster.getStatus({ cwd: "/repo" });
1011 assert.equal(cached.refName, state.currentLocalStatus.refName);
1012 assert.deepStrictEqual(cached.pr, state.currentRemoteStatus.pr);
1013 assert.equal(cached.aheadCount, 2);
1014 assert.equal(state.remoteStatusCalls, 2);
1015 }).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
1016 });
1017​
1018 it.effect("releases remote demand while passive observers remain", () => {
1019 const state = {
1020 currentLocalStatus: baseLocalStatus,
1021 currentRemoteStatus: baseRemoteStatus,
1022 localStatusCalls: 0,
1023 remoteStatusCalls: 0,
1024 localInvalidationCalls: 0,
1025 remoteInvalidationCalls: 0,
1026 };
1027 let remoteInterruptedDeferred: Deferred.Deferred<void, never> | null = null;
1028 let remoteStartedDeferred: Deferred.Deferred<void, never> | null = null;
1029 const layerTest = VcsStatusBroadcaster.layer.pipe(
1030 Layer.provideMerge(NodeServices.layer),
1031 Layer.provide(layerBackgroundPolicy(() => true)),
1032 Layer.provide(
1033 Layer.mock(GitWorkflowService.GitWorkflowService)({
1034 localStatus: () =>
1035 Effect.sync(() => {
1036 state.localStatusCalls += 1;
1037 return state.currentLocalStatus;
1038 }),
1039 currentBranch: () => Effect.succeed(state.currentLocalStatus.refName),
1040 remoteStatus: () =>
1041 Effect.sync(() => {
1042 state.remoteStatusCalls += 1;
1043 }).pipe(
1044 Effect.andThen(
1045 remoteStartedDeferred
1046 ? Deferred.succeed(remoteStartedDeferred, undefined).pipe(Effect.ignore)
1047 : Effect.void,
1048 ),
1049 Effect.andThen(Effect.never as Effect.Effect<VcsStatusRemoteResult | null, never>),
1050 Effect.onInterrupt(() =>
1051 remoteInterruptedDeferred
1052 ? Deferred.succeed(remoteInterruptedDeferred, undefined).pipe(Effect.ignore)
1053 : Effect.void,
1054 ),
1055 ),
1056 invalidateLocalStatus: () =>
1057 Effect.sync(() => {
1058 state.localInvalidationCalls += 1;
1059 }),
1060 invalidateRemoteStatus: () =>
1061 Effect.sync(() => {
1062 state.remoteInvalidationCalls += 1;
1063 }),
1064 } satisfies Partial<GitWorkflowService.GitWorkflowService["Service"]>),
1065 ),
1066 );
1067​
1068 return Effect.gen(function* () {
1069 const remoteInterrupted = yield* Deferred.make<void>();
1070 const remoteStarted = yield* Deferred.make<void>();
1071 remoteInterruptedDeferred = remoteInterrupted;
1072 remoteStartedDeferred = remoteStarted;
1073​
1074 const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
1075 const firstSnapshot = yield* Deferred.make<VcsStatusStreamEvent>();
1076 const secondSnapshot = yield* Deferred.make<VcsStatusStreamEvent>();
1077 const firstScope = yield* Scope.make();
1078 const secondScope = yield* Scope.make();
1079 const passiveSnapshot = yield* Deferred.make<VcsStatusStreamEvent>();
1080 yield* Stream.runForEach(
1081 broadcaster.streamStatus({ cwd: "/repo", includeRemote: false }),
1082 (event) =>
1083 event._tag === "snapshot"
1084 ? Deferred.succeed(passiveSnapshot, event).pipe(Effect.ignore)
1085 : Effect.void,
1086 ).pipe(Effect.forkScoped);
1087 yield* Deferred.await(passiveSnapshot);
1088 assert.equal(state.remoteStatusCalls, 0);
1089 yield* Stream.runForEach(broadcaster.streamStatus({ cwd: "/repo" }), (event) =>
1090 event._tag === "snapshot"
1091 ? Deferred.succeed(firstSnapshot, event).pipe(Effect.ignore)
1092 : Effect.void,
1093 ).pipe(Effect.forkIn(firstScope));
1094 yield* Stream.runForEach(broadcaster.streamStatus({ cwd: "/repo" }), (event) =>
1095 event._tag === "snapshot"
1096 ? Deferred.succeed(secondSnapshot, event).pipe(Effect.ignore)
1097 : Effect.void,
1098 ).pipe(Effect.forkIn(secondScope));
1099​
1100 yield* Deferred.await(firstSnapshot);
1101 yield* Deferred.await(secondSnapshot);
1102 yield* Deferred.await(remoteStarted);
1103​
1104 assert.equal(state.remoteStatusCalls, 1);
1105​
1106 yield* Scope.close(firstScope, Exit.void);
1107 assert.isTrue(Option.isNone(yield* Deferred.poll(remoteInterrupted)));
1108​
1109 yield* Scope.close(secondScope, Exit.void).pipe(Effect.forkScoped);
1110 yield* Deferred.await(remoteInterrupted);
1111 assert.isTrue(Option.isSome(yield* Deferred.poll(remoteInterrupted)));
1112 }).pipe(Effect.provide(layerTest));
1113 });
1114});