@avi2dg/subquo 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/.bun-version +1 -0
  2. package/.github/actions/setup/action.yml +21 -0
  3. package/.github/actions/setup/bun-without-unzip.sh +20 -0
  4. package/.github/workflows/ci.yml +177 -0
  5. package/.github/workflows/main.yml +108 -0
  6. package/.github/workflows/mutation.yml +106 -0
  7. package/.github/workflows/pr-title.yml +43 -0
  8. package/.github/workflows/release.yml +34 -0
  9. package/.jscpd.json +5 -0
  10. package/.no-mistakes.yaml +3 -0
  11. package/AGENTS.md +15 -0
  12. package/CHANGELOG.md +21 -0
  13. package/CLAUDE.md +2 -0
  14. package/LICENSE +21 -0
  15. package/README.md +80 -0
  16. package/VISION.md +39 -0
  17. package/bun.lock +909 -0
  18. package/bunfig.toml +3 -0
  19. package/checks.config.ts +7 -0
  20. package/docs/accounts.md +55 -0
  21. package/docs/design.md +122 -0
  22. package/docs/shadow-run.md +49 -0
  23. package/docs/stage-1-findings.md +65 -0
  24. package/knip.config.ts +3 -0
  25. package/oxlint.config.ts +3 -0
  26. package/package.json +45 -3
  27. package/scripts/release-assets.ts +28 -0
  28. package/src/accounts.ts +62 -0
  29. package/src/cli.ts +122 -0
  30. package/src/codex-credentials.ts +1 -0
  31. package/src/collect.ts +45 -0
  32. package/src/collectors.ts +210 -0
  33. package/src/index.ts +146 -0
  34. package/src/keychain.ts +25 -0
  35. package/src/launch.ts +21 -0
  36. package/src/pi-codex.ts +17 -0
  37. package/src/renewal.ts +158 -0
  38. package/src/storage.ts +48 -0
  39. package/src/usage.ts +400 -0
  40. package/stryker.conf.mjs +3 -0
  41. package/templates/adr.md +32 -0
  42. package/templates/agents.md +9 -0
  43. package/templates/changelog.md +39 -0
  44. package/templates/claude.md +2 -0
  45. package/templates/explanation.md +15 -0
  46. package/templates/how-to.md +33 -0
  47. package/templates/readme.md +48 -0
  48. package/templates/reference.md +15 -0
  49. package/templates/tutorial.md +31 -0
  50. package/templates/vision.md +16 -0
  51. package/tests/e2e/cli.test.ts +193 -0
  52. package/tests/e2e/npm-package.test.ts +30 -0
  53. package/tests/e2e/release-assets.test.ts +53 -0
  54. package/tests/fixtures/snapshots/fresh.json +54 -0
  55. package/tests/fixtures/snapshots/incomplete.json +66 -0
  56. package/tests/unit/collect.test.ts +51 -0
  57. package/tests/unit/collectors.test.ts +401 -0
  58. package/tests/unit/no-mistakes.test.ts +8 -0
  59. package/tests/unit/renewal.test.ts +17 -0
  60. package/tests/unit/snapshot.test.ts +169 -0
  61. package/tsconfig.json +46 -0
@@ -0,0 +1,193 @@
1
+ import { expect, test } from "bun:test";
2
+ import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ const cli = new URL("../../src/cli.ts", import.meta.url).pathname;
7
+
8
+ async function setup() {
9
+ const root = await mkdtemp(join(tmpdir(), "subquo-test-"));
10
+ const config = join(root, ".config", "subquo");
11
+ const profile = join(root, "profile");
12
+ await mkdir(config, { recursive: true });
13
+ await mkdir(profile, { recursive: true });
14
+ const env = { HOME: root, PATH: process.env.PATH ?? "", XDG_STATE_HOME: join(root, "state") };
15
+ return { root, config, profile, env };
16
+ }
17
+
18
+ test("read prints the saved quota even when the account list and collector are gone", async () => {
19
+ const { root, config, profile, env } = await setup();
20
+ try {
21
+ const login = join(profile, "auth.json");
22
+ const accounts = join(config, "accounts.toml");
23
+ const canary = crypto.randomUUID();
24
+ await writeFile(login, JSON.stringify({ tokens: { account_id: canary } }));
25
+ await writeFile(accounts, [
26
+ "[[accounts]]",
27
+ "id = \"example\"",
28
+ "provider = \"codex\"",
29
+ "login = { store = \"file\", path = " + JSON.stringify(login) + " }",
30
+ ].join("\n"), { mode: 0o600 });
31
+ const missing = join(profile, "gone.json");
32
+ const refresh = Bun.spawn([process.execPath, "--no-env-file", cli, "refresh"], { env, stderr: "pipe" });
33
+ expect(await refresh.exited).toBe(0);
34
+ expect(await new Response(refresh.stderr).text()).toBe("");
35
+ await writeFile(accounts, [
36
+ "[[accounts]]",
37
+ "id = \"example\"",
38
+ "provider = \"codex\"",
39
+ "login = { store = \"file\", path = " + JSON.stringify(missing) + " }",
40
+ ].join("\n"), { mode: 0o600 });
41
+ const read = Bun.spawn([process.execPath, "--no-env-file", cli, "read", "--json"], { env, stderr: "pipe", stdout: "pipe" });
42
+ const [exit, stdout, stderr] = await Promise.all([read.exited, new Response(read.stdout).text(), new Response(read.stderr).text()]);
43
+ expect(exit).toBe(0);
44
+ expect(stderr).toBe("");
45
+ expect(stdout).not.toContain(canary);
46
+ expect(JSON.parse(stdout)).toMatchObject({ accounts: [{ id: "example", observation: { status: "unavailable" } }] });
47
+ } finally {
48
+ await rm(root, { recursive: true, force: true });
49
+ }
50
+ });
51
+
52
+ async function invoke(
53
+ env: Record<string, string>,
54
+ argv: readonly string[],
55
+ options: { readonly input?: string; readonly preload?: string } = {},
56
+ ) {
57
+ const preload = options.preload === undefined ? [] : ["--preload", options.preload];
58
+ const child = Bun.spawn([process.execPath, "--no-env-file", ...preload, cli, ...argv], {
59
+ env, stdin: options.input === undefined ? "ignore" : new Blob([options.input]), stdout: "pipe", stderr: "pipe",
60
+ });
61
+ const [exit, stdout, stderr] = await Promise.all([child.exited, new Response(child.stdout).text(), new Response(child.stderr).text()]);
62
+ return { exit, stdout, stderr };
63
+ }
64
+
65
+ test("refresh keeps Claude logins separate and does not show a missing expiry as a healthy login", async () => {
66
+ const { root, config, profile, env } = await setup();
67
+ try {
68
+ const second = join(root, "second");
69
+ await mkdir(second);
70
+ const firstLogin = join(profile, ".credentials.json");
71
+ const secondLogin = join(second, ".credentials.json");
72
+ const day = 86_400_000;
73
+ const expiresAt = Date.now() + day / 3;
74
+ await writeFile(firstLogin, JSON.stringify({
75
+ claudeAiOauth: { accessToken: "fake-access-first", expiresAt, refreshTokenExpiresAt: Date.now() + 6.5 * day },
76
+ }));
77
+ await writeFile(secondLogin, JSON.stringify({ claudeAiOauth: { accessToken: "fake-access-second", expiresAt } }));
78
+ await writeFile(join(config, "accounts.toml"), [
79
+ "[[accounts]]", 'id = "example-first"', 'provider = "claude"',
80
+ `login = { store = "file", path = ${JSON.stringify(firstLogin)} }`,
81
+ "[[accounts]]", 'id = "example-second"', 'provider = "claude"',
82
+ `login = { store = "file", path = ${JSON.stringify(secondLogin)} }`,
83
+ ].join("\n"), { mode: 0o600 });
84
+
85
+ const reset = new Date(Date.now() + day).toISOString();
86
+ const preload = join(root, "fake-network.ts");
87
+ await writeFile(preload, `
88
+ globalThis.fetch = async (url, init) => {
89
+ if (new URL(url).pathname !== "/api/oauth/usage" || init.redirect !== "error") throw new Error("wrong request");
90
+ const used = { "Bearer fake-access-first": 25, "Bearer fake-access-second": 40 }[init.headers.authorization];
91
+ if (used === undefined) throw new Error("wrong login");
92
+ return Response.json({ limits: [{ kind: "session", percent: used, resets_at: ${JSON.stringify(reset)} }] });
93
+ };
94
+ `);
95
+
96
+ expect(await invoke(env, ["refresh"], { preload })).toEqual({ exit: 0, stdout: "", stderr: "" });
97
+ const json = await invoke(env, ["read", "--json"]);
98
+ expect(json.exit).toBe(0);
99
+ expect(json.stdout).not.toContain("fake-access-");
100
+ const snapshot = JSON.parse(json.stdout);
101
+ expect(snapshot).toMatchObject({
102
+ version: "subquo.v1",
103
+ accounts: [
104
+ { id: "example-first", loginEndsInDays: 7, observation: { windows: [{ percentLeft: 75 }] } },
105
+ { id: "example-second", loginEndsInDays: null, observation: { windows: [{ percentLeft: 60 }] } },
106
+ ],
107
+ });
108
+ const read = await invoke(env, ["read"]);
109
+ expect(read.stdout).toContain("example-first: fresh, login ends in 7 days");
110
+ expect(read.stdout).toContain("example-second: fresh, login end unknown");
111
+ } finally {
112
+ await rm(root, { recursive: true, force: true });
113
+ }
114
+ });
115
+
116
+ test("an ended Claude sign-in does not read as a healthy login and keeps the quota it read", async () => {
117
+ const { root, config, profile, env } = await setup();
118
+ try {
119
+ const login = join(profile, ".credentials.json");
120
+ const now = Date.now();
121
+ await writeFile(login, JSON.stringify({
122
+ claudeAiOauth: { accessToken: "fake-access-ended", expiresAt: now + 3_600_000, refreshTokenExpiresAt: now - 1_000 },
123
+ }));
124
+ await writeFile(join(config, "accounts.toml"), [
125
+ "[[accounts]]", 'id = "example-ended"', 'provider = "claude"',
126
+ `login = { store = "file", path = ${JSON.stringify(login)} }`,
127
+ ].join("\n"), { mode: 0o600 });
128
+ const reset = new Date(now + 86_400_000).toISOString();
129
+ const preload = join(root, "fake-network.ts");
130
+ await writeFile(preload, `
131
+ globalThis.fetch = async () => Response.json({ limits: [{ kind: "session", percent: 30, resets_at: ${JSON.stringify(reset)} }] });
132
+ `);
133
+
134
+ expect(await invoke(env, ["refresh"], { preload })).toEqual({ exit: 0, stdout: "", stderr: "" });
135
+ const json = await invoke(env, ["read", "--json"]);
136
+ expect(json.exit).toBe(0);
137
+ expect(JSON.parse(json.stdout)).toMatchObject({
138
+ accounts: [{ id: "example-ended", loginEndsInDays: 0, observation: { status: "fresh", windows: [{ percentLeft: 70 }] } }],
139
+ });
140
+ const read = await invoke(env, ["read"]);
141
+ expect(read.stdout).toContain("example-ended: fresh, login has ended");
142
+ expect(read.stdout).toContain("five-hour: 70% left");
143
+ expect(read.stdout).not.toContain("login ends in");
144
+ } finally {
145
+ await rm(root, { recursive: true, force: true });
146
+ }
147
+ });
148
+
149
+ test("a named account whose login is missing reads as login needed", async () => {
150
+ const { root, config, env } = await setup();
151
+ try {
152
+ const accounts = join(config, "accounts.toml");
153
+ await writeFile(accounts, [
154
+ "[[accounts]]",
155
+ "id = \"gone\"",
156
+ "provider = \"codex\"",
157
+ "login = { store = \"file\", path = \"/nonexistent/auth.json\" }",
158
+ ].join("\n"), { mode: 0o600 });
159
+ const refresh = Bun.spawn([process.execPath, "--no-env-file", cli, "refresh"], { env, stderr: "pipe" });
160
+ expect(await refresh.exited).toBe(0);
161
+ const read = Bun.spawn([process.execPath, "--no-env-file", cli, "read", "--json"], { env, stderr: "pipe", stdout: "pipe" });
162
+ const [exit, stdout] = await Promise.all([read.exited, new Response(read.stdout).text()]);
163
+ expect(exit).toBe(0);
164
+ expect(JSON.parse(stdout)).toMatchObject({ accounts: [{ id: "gone", observation: { status: "unavailable", code: "auth_required" } }] });
165
+ } finally {
166
+ await rm(root, { recursive: true, force: true });
167
+ }
168
+ });
169
+
170
+ test("an expired saved pass reads as unchecked without proving a sign-out", async () => {
171
+ const { root, config, profile, env } = await setup();
172
+ try {
173
+ const login = join(profile, ".credentials.json");
174
+ const accounts = join(config, "accounts.toml");
175
+ const canary = crypto.randomUUID();
176
+ await writeFile(login, JSON.stringify({ claudeAiOauth: { accessToken: canary, expiresAt: 1000, refreshToken: canary } }));
177
+ await writeFile(accounts, [
178
+ "[[accounts]]",
179
+ "id = \"old\"",
180
+ "provider = \"claude\"",
181
+ "login = { store = \"file\", path = " + JSON.stringify(login) + " }",
182
+ ].join("\n"), { mode: 0o600 });
183
+ const refresh = Bun.spawn([process.execPath, "--no-env-file", cli, "refresh"], { env, stderr: "pipe" });
184
+ expect(await refresh.exited).toBe(0);
185
+ const read = Bun.spawn([process.execPath, "--no-env-file", cli, "read", "--json"], { env, stderr: "pipe", stdout: "pipe" });
186
+ const [exit, stdout] = await Promise.all([read.exited, new Response(read.stdout).text()]);
187
+ expect(exit).toBe(0);
188
+ expect(stdout).not.toContain(canary);
189
+ expect(JSON.parse(stdout)).toMatchObject({ accounts: [{ id: "old", observation: { status: "unavailable", code: "auth_unverified" } }] });
190
+ } finally {
191
+ await rm(root, { recursive: true, force: true });
192
+ }
193
+ });
@@ -0,0 +1,30 @@
1
+ import { expect, test } from "bun:test";
2
+ import { chmod, copyFile, mkdir, mkdtemp, rm, symlink, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import manifest from "../../package.json";
6
+
7
+ const root = new URL("../..", import.meta.url).pathname;
8
+
9
+ test("launcher forwards arguments and exit status to the installed platform binary instead of source", async () => {
10
+ if (!((process.platform === "linux" && process.arch === "x64") || (process.platform === "darwin" && process.arch === "arm64"))) return;
11
+ const directory = await mkdtemp(join(tmpdir(), "subquo-launch-"));
12
+ try {
13
+ const source = join(directory, "src");
14
+ const platform = join(directory, "node_modules", `${manifest.name}-${process.platform}-${process.arch}`);
15
+ await mkdir(source, { recursive: true });
16
+ await mkdir(platform, { recursive: true });
17
+ await symlink(join(root, "node_modules/effect"), join(directory, "node_modules/effect"));
18
+ await copyFile(join(root, "src/launch.ts"), join(source, "launch.ts"));
19
+ await writeFile(join(directory, "package.json"), JSON.stringify(manifest));
20
+ await writeFile(join(platform, "package.json"), JSON.stringify({ name: `${manifest.name}-${process.platform}-${process.arch}`, version: manifest.version }));
21
+ const binary = join(platform, `subquo-${manifest.version}`);
22
+ await writeFile(binary, '#!/bin/sh\nprintf "%s\\n" "$1"\nexit 17\n');
23
+ await chmod(binary, 0o755);
24
+ const child = Bun.spawn([process.execPath, "--no-env-file", join(source, "launch.ts"), "probe"], { stdout: "pipe" });
25
+ expect(await new Response(child.stdout).text()).toBe("probe\n");
26
+ expect(await child.exited).toBe(17);
27
+ } finally {
28
+ await rm(directory, { recursive: true, force: true });
29
+ }
30
+ });
@@ -0,0 +1,53 @@
1
+ import { expect, test } from "bun:test";
2
+ import { createHash } from "node:crypto";
3
+ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+
7
+ const root = new URL("../..", import.meta.url).pathname;
8
+
9
+ test("compiled release rejects wrong usage, ignores cwd dotenv and preloads, and includes a matching SHA-256 file", async () => {
10
+ const output = await mkdtemp(join(tmpdir(), "subquo-release-"));
11
+ try {
12
+ const build = Bun.spawn([process.execPath, "--no-env-file", join(root, "scripts/release-assets.ts"), output], {
13
+ cwd: root, stdout: "pipe", stderr: "pipe",
14
+ });
15
+ const [buildExit, buildError] = await Promise.all([build.exited, new Response(build.stderr).text()]);
16
+ expect(buildError).toBe("");
17
+ expect(buildExit).toBe(0);
18
+
19
+ const name = `subquo-${process.platform}-${process.arch}`;
20
+ const executable = join(output, name);
21
+ const digest = createHash("sha256").update(await readFile(executable)).digest("hex");
22
+ expect(await readFile(`${executable}.sha256`, "utf8")).toBe(`${digest} ${name}\n`);
23
+
24
+ const env = { HOME: output, PATH: process.env.PATH ?? "" };
25
+ const usage = Bun.spawn([executable], { cwd: output, env, stdout: "pipe", stderr: "pipe" });
26
+ const [usageExit, usageOutput, usageError] = await Promise.all([
27
+ usage.exited, new Response(usage.stdout).text(), new Response(usage.stderr).text(),
28
+ ]);
29
+ expect(usageExit).toBe(1);
30
+ expect(usageOutput).toBe("");
31
+ expect(usageError).toContain("subquo read");
32
+
33
+ const state = join(output, ".local", "state", "subquo");
34
+ const snapshot = { version: "subquo.v1", writtenAt: "2030-01-01T00:00:00.000Z", accounts: [] };
35
+ await mkdir(state, { recursive: true });
36
+ await writeFile(join(state, "snapshot.json"), JSON.stringify(snapshot));
37
+ await writeFile(join(output, ".env"), `XDG_STATE_HOME=${JSON.stringify(join(output, "redirected-state"))}\n`);
38
+ await writeFile(join(output, "bunfig.toml"), 'preload = ["./preload.ts"]\n');
39
+ const marker = join(output, "preload-ran");
40
+ await writeFile(join(output, "preload.ts"), `await Bun.write(${JSON.stringify(marker)}, "ran");\n`);
41
+
42
+ const read = Bun.spawn([executable, "read", "--json"], { cwd: output, env, stdout: "pipe", stderr: "pipe" });
43
+ const [readExit, readOutput, readError] = await Promise.all([
44
+ read.exited, new Response(read.stdout).text(), new Response(read.stderr).text(),
45
+ ]);
46
+ expect(await Bun.file(marker).exists()).toBe(false);
47
+ expect(readError).toBe("");
48
+ expect(readExit).toBe(0);
49
+ expect(JSON.parse(readOutput)).toEqual(snapshot);
50
+ } finally {
51
+ await rm(output, { recursive: true, force: true });
52
+ }
53
+ }, 120_000);
@@ -0,0 +1,54 @@
1
+ {
2
+ "version": "subquo.v1",
3
+ "writtenAt": "2030-01-01T00:00:30.000Z",
4
+ "accounts": [
5
+ {
6
+ "id": "sample-claude",
7
+ "provider": "claude",
8
+ "observation": {
9
+ "status": "fresh",
10
+ "observedAt": "2030-01-01T00:00:00.000Z",
11
+ "source": "provider",
12
+ "validUntil": "2030-01-01T00:02:00.000Z",
13
+ "windows": [
14
+ {
15
+ "id": "five-hour",
16
+ "scope": "account",
17
+ "percentLeft": 40,
18
+ "resetsAt": "2030-01-01T05:00:00.000Z"
19
+ },
20
+ {
21
+ "id": "weekly",
22
+ "scope": "account",
23
+ "percentLeft": 12,
24
+ "resetsAt": "2030-01-08T00:00:00.000Z"
25
+ }
26
+ ]
27
+ }
28
+ },
29
+ {
30
+ "id": "sample-codex",
31
+ "provider": "codex",
32
+ "observation": {
33
+ "status": "fresh",
34
+ "observedAt": "2030-01-01T00:00:10.000Z",
35
+ "source": "provider",
36
+ "validUntil": "2030-01-01T00:01:00.000Z",
37
+ "windows": [
38
+ {
39
+ "id": "weekly",
40
+ "scope": "account",
41
+ "percentLeft": 100,
42
+ "resetsAt": "2030-01-08T00:00:00.000Z"
43
+ },
44
+ {
45
+ "id": "five-hour",
46
+ "scope": "account",
47
+ "percentLeft": 0,
48
+ "resetsAt": "2030-01-01T00:01:00.000Z"
49
+ }
50
+ ]
51
+ }
52
+ }
53
+ ]
54
+ }
@@ -0,0 +1,66 @@
1
+ {
2
+ "version": "subquo.v1",
3
+ "writtenAt": "2030-01-01T00:01:00.000Z",
4
+ "accounts": [
5
+ {
6
+ "id": "sample-claude",
7
+ "provider": "claude",
8
+ "observation": {
9
+ "status": "stale",
10
+ "observedAt": "2030-01-01T00:00:00.000Z",
11
+ "source": "provider",
12
+ "windows": [
13
+ {
14
+ "id": "five-hour",
15
+ "scope": "account",
16
+ "percentLeft": 40,
17
+ "resetsAt": "2030-01-01T05:00:00.000Z"
18
+ }
19
+ ],
20
+ "code": "timeout"
21
+ }
22
+ },
23
+ {
24
+ "id": "sample-codex",
25
+ "provider": "codex",
26
+ "observation": {
27
+ "status": "unavailable",
28
+ "code": "rate_limited"
29
+ }
30
+ },
31
+ {
32
+ "id": "sample-opencode",
33
+ "provider": "opencode-go",
34
+ "observation": {
35
+ "status": "unavailable",
36
+ "code": "auth_unverified"
37
+ }
38
+ },
39
+ {
40
+ "id": "sample-backup",
41
+ "provider": "claude",
42
+ "observation": {
43
+ "status": "unavailable",
44
+ "code": "auth_required"
45
+ }
46
+ },
47
+ {
48
+ "id": "sample-partial",
49
+ "provider": "codex",
50
+ "observation": {
51
+ "status": "fresh",
52
+ "observedAt": "2030-01-01T00:00:00.000Z",
53
+ "source": "provider",
54
+ "validUntil": "2030-01-01T00:02:00.000Z",
55
+ "windows": [
56
+ {
57
+ "id": "weekly",
58
+ "scope": "account",
59
+ "percentLeft": null,
60
+ "resetsAt": null
61
+ }
62
+ ]
63
+ }
64
+ }
65
+ ]
66
+ }
@@ -0,0 +1,51 @@
1
+ import { expect, test } from "bun:test";
2
+ import { Deferred, Effect, Fiber } from "effect";
3
+ import { TestClock } from "effect/testing";
4
+ import { collectSnapshot, type Reading } from "../../src/collect";
5
+
6
+ const observedAt = "2030-01-01T00:00:00.000Z";
7
+ const measured = {
8
+ observedAt,
9
+ windows: [{ id: "weekly", scope: "all", percentLeft: 12, resetsAt: "2030-01-02T00:00:00.000Z" }],
10
+ } satisfies Reading;
11
+
12
+ test("a hanging collector does not delay its peer or outlive its five-second budget", async () => {
13
+ const program = Effect.gen(function*() {
14
+ yield* TestClock.setTime(Date.parse(observedAt));
15
+ const peerFinished = yield* Deferred.make<void>();
16
+ const cycle = yield* collectSnapshot([
17
+ { id: "hung", provider: "claude", read: Effect.never },
18
+ { id: "fast", provider: "codex", read: Effect.as(Deferred.succeed(peerFinished, undefined), measured) },
19
+ ]).pipe(Effect.forkChild);
20
+
21
+ yield* Deferred.await(peerFinished);
22
+ yield* TestClock.adjust(4_999);
23
+ expect(cycle.pollUnsafe()).toBeUndefined();
24
+ yield* TestClock.adjust(1);
25
+ const snapshot = yield* Fiber.join(cycle);
26
+ expect(snapshot.writtenAt).toBe("2030-01-01T00:00:05.000Z");
27
+ expect(snapshot.accounts.map(({ id, observation }) => [id, observation.status])).toEqual([
28
+ ["hung", "unavailable"], ["fast", "fresh"],
29
+ ]);
30
+ expect(snapshot.accounts[0].observation).toEqual({ status: "unavailable", code: "timeout" });
31
+ });
32
+ await Effect.runPromise(program.pipe(Effect.provide(TestClock.layer())));
33
+ });
34
+
35
+ test("the login warning does not start early, and an ended sign-in counts as zero days instead of reading as healthy", async () => {
36
+ const day = 86_400_000;
37
+ const now = Date.parse(observedAt);
38
+ const expiries = [8 * day, 7 * day + 1, 7 * day, day + 1, 1, 0, -1];
39
+ const program = Effect.gen(function*() {
40
+ yield* TestClock.setTime(now);
41
+ const snapshot = yield* collectSnapshot(expiries.map((left, index) => ({
42
+ id: `example-${index}`,
43
+ provider: "claude",
44
+ read: Effect.succeed({ code: "auth_unverified", loginExpiresAt: now + left } satisfies Reading),
45
+ })));
46
+ return snapshot.accounts.map(({ loginEndsInDays }) => loginEndsInDays);
47
+ });
48
+ expect(await Effect.runPromise(program.pipe(Effect.provide(TestClock.layer())))).toEqual([
49
+ undefined, undefined, 7, 2, 1, 0, 0,
50
+ ]);
51
+ });