@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, 07:15 UTC

main
ts 187 lines 6.77 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as Core from "@alchemy.run/test/Core";
5 import * as iotfleetwise from "@distilled.cloud/aws/iotfleetwise";
6 import { Region } from "@distilled.cloud/aws/Region";
7 import * as Effect from "effect/Effect";
8 import * as HttpClient from "effect/http/HttpClient";
9 import * as Schedule from "effect/Schedule";
10 import FleetWiseBindingsFunctionLive, { FleetWiseBindingsFunction } from "./bindings-handler";
11
12 const testOptions = { providers: AWS.providers() };
13 const { test, beforeAll, afterAll } = Test.make(testOptions);
14
15 // AWS IoT FleetWise is allowlist-gated — accounts without service access
16 // observe AccessDeniedException on every operation. The live Lambda E2E
17 // needs real FleetWise resources, so it is gated behind
18 // AWS_TEST_IOTFLEETWISE=1 for allowlisted accounts.
19 const RUN_LIVE = !!process.env.AWS_TEST_IOTFLEETWISE;
20
21 // FleetWise is offered in us-east-1/eu-central-1 only — pin every
22 // out-of-band distilled call to the service's home region.
23 const inHomeRegion = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
24 effect.pipe(Effect.provideService(Region, Effect.succeed("us-east-1")));
25
26 // Ungated typed-error probes: prove the distilled error unions the bindings
27 // depend on decode on every account, allowlisted or not, at near-zero cost.
28 test.provider(
29 "getVehicleStatus on a nonexistent vehicle fails with a typed tag",
30 () =>
31 Effect.gen(function* () {
32 const error = yield* Effect.flip(
33 iotfleetwise
34 .getVehicleStatus({ vehicleName: "alchemy-nonexistent-vehicle-probe" })
35 .pipe(inHomeRegion),
36 );
37 expect(["ResourceNotFoundException", "AccessDeniedException"]).toContain(error._tag);
38 }),
39 { tags: ["provider:aws", "provider:aws:iotfleetwise", "live"] },
40 );
41
42 test.provider(
43 "listVehiclesInFleet on a nonexistent fleet fails with a typed tag",
44 () =>
45 Effect.gen(function* () {
46 const error = yield* Effect.flip(
47 iotfleetwise
48 .listVehiclesInFleet({ fleetId: "alchemy-nonexistent-fleet-probe" })
49 .pipe(inHomeRegion),
50 );
51 expect(["ResourceNotFoundException", "AccessDeniedException"]).toContain(error._tag);
52 }),
53 { tags: ["provider:aws", "provider:aws:iotfleetwise", "live"] },
54 );
55
56 const sharedStack = Core.scratchStack(testOptions, "FleetWiseBindings");
57
58 let baseUrl: string;
59
60 const get = (path: string) =>
61 HttpClient.get(`${baseUrl}${path}`).pipe(Effect.flatMap((r) => r.json));
62 const post = (path: string) =>
63 HttpClient.post(`${baseUrl}${path}`).pipe(Effect.flatMap((r) => r.json));
64
65 describe(
66 "IoTFleetWise Bindings (E2E)",
67 {
68 tags: [
69 "provider:aws",
70 "provider:aws:batch",
71 "provider:aws:iotfleetwise",
72 "provider:aws:lambda",
73 "provider:aws:s3",
74 "live",
75 ],
76 },
77 () => {
78 beforeAll(
79 Effect.gen(function* () {
80 if (!RUN_LIVE) return;
81 yield* Effect.logInfo("FleetWise E2E setup: destroying previous run");
82 yield* sharedStack.destroy();
83
84 yield* Effect.logInfo("FleetWise E2E setup: deploying resources + Lambda");
85 const { functionUrl } = yield* sharedStack.deploy(
86 Effect.gen(function* () {
87 return yield* FleetWiseBindingsFunction;
88 }).pipe(Effect.provide(FleetWiseBindingsFunctionLive)),
89 );
90
91 expect(functionUrl).toBeTruthy();
92 baseUrl = functionUrl!.replace(/\/+$/, "");
93
94 // Readiness probe — fresh function URLs take seconds to serve 200s.
95 yield* HttpClient.get(`${baseUrl}/bindings`).pipe(
96 Effect.flatMap((response) =>
97 response.status === 200
98 ? Effect.succeed(response)
99 : Effect.fail(new Error(`Function not ready: ${response.status}`)),
100 ),
101 Effect.retry({
102 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(60)]),
103 }),
104 );
105 }),
106 { timeout: 600_000 },
107 );
108 afterAll(
109 Effect.gen(function* () {
110 if (!RUN_LIVE) return;
111 yield* sharedStack.destroy();
112 }),
113 { timeout: 600_000 },
114 );
115
116 test.provider.skipIf(!RUN_LIVE)("all 13 capabilities initialize in the runtime", () =>
117 Effect.gen(function* () {
118 const response = (yield* get("/bindings")) as any;
119 expect(response.bound).toHaveLength(13);
120 }),
121 );
122
123 test.provider.skipIf(!RUN_LIVE)(
124 "GetVehicleStatus reads the bound vehicle's campaign deployments",
125 () =>
126 Effect.gen(function* () {
127 const response = (yield* get("/vehicle-status")) as any;
128 expect(typeof response.campaigns).toBe("number");
129 }),
130 );
131
132 test.provider.skipIf(!RUN_LIVE)(
133 "Associate/Disassociate + ListVehiclesInFleet + ListFleetsForVehicle round-trip",
134 () =>
135 Effect.gen(function* () {
136 const associated = (yield* post("/fleet/associate")) as any;
137 expect(associated.count).toBeGreaterThanOrEqual(1);
138 const fleets = (yield* get("/vehicle-fleets")) as any;
139 expect(fleets.count).toBeGreaterThanOrEqual(1);
140 const disassociated = (yield* post("/fleet/disassociate")) as any;
141 expect(disassociated.ok).toBe(true);
142 }),
143 );
144
145 test.provider.skipIf(!RUN_LIVE)(
146 "signal-definition reads cover catalog, model, and decoder",
147 () =>
148 Effect.gen(function* () {
149 const catalogNodes = (yield* get("/catalog-nodes")) as any;
150 expect(catalogNodes.count).toBe(3);
151 const modelNodes = (yield* get("/model-nodes")) as any;
152 expect(modelNodes.count).toBeGreaterThanOrEqual(2);
153 const interfaces = (yield* get("/decoder-interfaces")) as any;
154 expect(interfaces.count).toBe(1);
155 const signals = (yield* get("/decoder-signals")) as any;
156 expect(signals.count).toBe(1);
157 }),
158 );
159
160 test.provider.skipIf(!RUN_LIVE)("ListVehicles filters by the bound model manifest", () =>
161 Effect.gen(function* () {
162 const response = (yield* get("/vehicles")) as any;
163 expect(response.count).toBeGreaterThanOrEqual(1);
164 }),
165 );
166
167 test.provider.skipIf(!RUN_LIVE)(
168 "UpdateCampaign suspends and resumes the running campaign",
169 () =>
170 Effect.gen(function* () {
171 const response = (yield* post("/campaign/suspend-resume")) as any;
172 expect(response.ok).toBe(true);
173 }),
174 );
175
176 test.provider.skipIf(!RUN_LIVE)(
177 "BatchUpdateVehicle succeeds and BatchCreateVehicle surfaces per-item errors",
178 () =>
179 Effect.gen(function* () {
180 const response = (yield* post("/vehicles/batch")) as any;
181 expect(response.updated).toBe(1);
182 expect(response.updateErrors).toBe(0);
183 expect(response.createErrors).toBe(1);
184 }),
185 );
186 },
187 );