@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 103 lines 3.84 KB
Raw
1 import { normalizeTransferredFrom } from "@alchemy.run/cloudflare/Workers/DurableObject";
2 import { Worker } from "@alchemy.run/cloudflare/Workers/Worker";
3 import { expect, test } from "@alchemy.run/test";
4 import { Platform, type PlatformIdentity, type PlatformProps } from "alchemy/Platform";
5 import type { Resource } from "alchemy/Resource";
6 import type { BaseRuntimeContext } from "alchemy/RuntimeContext";
7 import * as Effect from "effect/Effect";
8
9 interface TestProps extends PlatformProps {
10 env?: Record<string, string>;
11 }
12 interface TestResource extends Resource<"Test.PlatformIdentity", TestProps, {}> {}
13
14 const identity = <const Id extends string>(declaration: PlatformIdentity<Id>): Id =>
15 declaration.LogicalId;
16
17 test(
18 "Platform declarations expose their logical id without evaluating effects",
19 () => {
20 const TestPlatform: Platform<TestResource, never, {}, BaseRuntimeContext> =
21 Platform<TestResource>("Test.PlatformIdentity", {
22 createRuntimeContext: () => {
23 throw new Error("Reading identity must not create a runtime context");
24 },
25 });
26 const props = Effect.sync(() => {
27 throw new Error("Reading identity must not evaluate props");
28 });
29 const impl = Effect.sync(() => {
30 throw new Error("Reading identity must not evaluate the implementation");
31 });
32
33 class Modular extends TestPlatform<Modular, {}>()("Modular") {}
34 class Bare extends TestPlatform<Bare>()("Bare") {}
35 class Inline extends TestPlatform<Inline>()("Inline", {}, impl) {}
36 class EffectProps extends TestPlatform<EffectProps>()("EffectProps", props, impl) {}
37 const External = TestPlatform("External", {});
38 const ExternalEffect = TestPlatform("ExternalEffect", props);
39 const Functional = TestPlatform("Functional", {}, impl);
40 const FunctionalEffect = TestPlatform("FunctionalEffect", props, impl);
41
42 Modular.make(props, impl);
43 Bare.make(props, impl);
44
45 for (const [id, declaration] of Object.entries({
46 Modular,
47 Bare,
48 Inline,
49 EffectProps,
50 External,
51 ExternalEffect,
52 Functional,
53 FunctionalEffect,
54 })) {
55 expect(identity(declaration)).toBe(id);
56 expect(Effect.isEffect(declaration)).toBe(true);
57 }
58 expect(Modular.of({})).not.toHaveProperty("LogicalId");
59 expect(TestPlatform).not.toHaveProperty("LogicalId");
60 },
61 { tags: ["unit", "local"] },
62 );
63
64 test(
65 "ordinary Worker declarations retain logical ids before yielding",
66 () => {
67 const props = Effect.sync(() => {
68 throw new Error("Reading identity must not evaluate Worker props");
69 });
70 const impl = Effect.sync(() => {
71 throw new Error("Reading identity must not evaluate Worker implementation");
72 });
73
74 class Modular extends Worker<Modular, {}>()("Modular") {}
75 class Inline extends Worker<Inline>()("Inline", {}, impl) {}
76 class EffectProps extends Worker<EffectProps>()("EffectProps", props, impl) {}
77 class External extends Worker<External>()("External", {}) {}
78 class ExternalEffect extends Worker<ExternalEffect>()("ExternalEffect", props) {}
79 const Functional = Worker("Functional", {}, impl);
80 const ExternalFunctional = Worker("ExternalFunctional", {});
81 const ExternalFunctionalEffect = Worker("ExternalFunctionalEffect", props);
82
83 Modular.make(props, impl);
84
85 for (const [id, declaration] of Object.entries({
86 Modular,
87 Inline,
88 EffectProps,
89 External,
90 ExternalEffect,
91 Functional,
92 ExternalFunctional,
93 ExternalFunctionalEffect,
94 })) {
95 expect(identity(declaration)).toBe(id);
96 expect(Effect.isEffect(declaration)).toBe(true);
97 expect(normalizeTransferredFrom(declaration)).toEqual([id]);
98 }
99 expect(Modular.of({})).not.toHaveProperty("LogicalId");
100 expect(Worker).not.toHaveProperty("LogicalId");
101 },
102 { tags: ["unit", "provider:cloudflare", "provider:cloudflare:worker", "local"] },
103 );