@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 73 lines 2.15 KB
Raw
1 import { expect, it } from "@alchemy.run/test";
2 import * as ConfigProvider from "effect/ConfigProvider";
3 import * as Effect from "effect/Effect";
4 import * as Redacted from "effect/Redacted";
5 import { AuthError } from "@/Auth/AuthProvider.ts";
6 import {
7 getEnv,
8 getEnvRedacted,
9 getEnvRedactedRequired,
10 getEnvRequired,
11 mapPromptCancellation,
12 } from "@/Auth/Env.ts";
13 import { TerminalCancelled } from "@/Interaction.ts";
14
15 const provideConfig = (values: Record<string, unknown>) =>
16 Effect.provideService(ConfigProvider.ConfigProvider, ConfigProvider.fromUnknown(values));
17
18 it.effect(
19 "reads optional environment configuration",
20 () =>
21 Effect.gen(function* () {
22 expect(yield* getEnv("PRESENT")).toBe("value");
23 expect(yield* getEnv("MISSING")).toBeUndefined();
24 }).pipe(provideConfig({ PRESENT: "value" })),
25 { tags: ["unit", "local"] },
26 );
27
28 it.effect(
29 "preserves the configuration error as the cause of AuthError",
30 () =>
31 getEnvRequired("MISSING").pipe(
32 Effect.flip,
33 Effect.tap((error) =>
34 Effect.sync(() => {
35 expect(error).toBeInstanceOf(AuthError);
36 expect(error.message).toBe("Missing required env: MISSING");
37 expect(error.cause).toBeDefined();
38 }),
39 ),
40 provideConfig({}),
41 ),
42 { tags: ["unit", "local"] },
43 );
44
45 it.effect(
46 "handles optional and required redacted configuration",
47 () =>
48 Effect.gen(function* () {
49 const present = yield* getEnvRedactedRequired("SECRET");
50 expect(Redacted.value(present)).toBe("secret");
51 expect(yield* getEnvRedacted("MISSING")).toBeUndefined();
52 }).pipe(provideConfig({ SECRET: "secret" })),
53 { tags: ["unit", "local"] },
54 );
55
56 it.effect(
57 "maps prompt cancellation without retrying the prompt",
58 () =>
59 Effect.gen(function* () {
60 let attempts = 0;
61 const error = yield* mapPromptCancellation(
62 Effect.suspend(() => {
63 attempts++;
64 return Effect.fail(new TerminalCancelled());
65 }),
66 ).pipe(Effect.flip);
67
68 expect(attempts).toBe(1);
69 expect(error).toBeInstanceOf(AuthError);
70 expect(error.cause).toBeInstanceOf(TerminalCancelled);
71 }),
72 { tags: ["unit", "local"] },
73 );