Open History to see the last commit
1import { EnvironmentId, WS_METHODS } from "@t3tools/contracts";
2import { describe, expect, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4
5import {
6 observeBackgroundActivitySubscription,
7 retainedBackgroundScopes,
8 wasRecentlyInteracted,
9} from "./backgroundActivityReporter.ts";
10
11describe("wasRecentlyInteracted", () => {
12 it("expires interaction independently of window focus", () => {
13 expect(wasRecentlyInteracted(10_000, 55_000)).toBe(true);
14 expect(wasRecentlyInteracted(10_000, 55_001)).toBe(false);
15 });
16
17 it("rejects future timestamps", () => {
18 expect(wasRecentlyInteracted(10_001, 10_000)).toBe(false);
19 });
20
21 it.effect("retains an observed subscription until its returned finalizer runs", () =>
22 Effect.gen(function* () {
23 const environmentId = EnvironmentId.make("environment-observation-test");
24 const scope = { type: "vcs-status" as const, cwd: "/repo" };
25 const release = yield* observeBackgroundActivitySubscription({
26 environmentId,
27 method: WS_METHODS.subscribeVcsStatus,
28 input: { cwd: scope.cwd },
29 });
30
31 expect(retainedBackgroundScopes(environmentId)).toEqual([scope]);
32
33 yield* release;
34 expect(retainedBackgroundScopes(environmentId)).toEqual([]);
35 }),
36 );
37
38 it.effect("keeps delimiter-containing environment and scope values distinct", () =>
39 Effect.gen(function* () {
40 const firstEnvironmentId = EnvironmentId.make("a");
41 const secondEnvironmentId = EnvironmentId.make("a:vcs-status:b");
42 const releaseFirst = yield* observeBackgroundActivitySubscription({
43 environmentId: firstEnvironmentId,
44 method: WS_METHODS.subscribeVcsStatus,
45 input: { cwd: "b:vcs-status:c" },
46 });
47 const releaseSecond = yield* observeBackgroundActivitySubscription({
48 environmentId: secondEnvironmentId,
49 method: WS_METHODS.subscribeVcsStatus,
50 input: { cwd: "c" },
51 });
52
53 expect(retainedBackgroundScopes(firstEnvironmentId)).toEqual([
54 { type: "vcs-status", cwd: "b:vcs-status:c" },
55 ]);
56 expect(retainedBackgroundScopes(secondEnvironmentId)).toEqual([
57 { type: "vcs-status", cwd: "c" },
58 ]);
59
60 yield* Effect.all([releaseFirst, releaseSecond]);
61 }),
62 );
63});