@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, 04:45 UTC

main
ts 108 lines 4.42 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { AWSEnvironment } from "@alchemy.run/aws/Environment";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as keyspacesstreams from "@distilled.cloud/aws/keyspacesstreams";
6 import * as Effect from "effect/Effect";
7 import * as HttpClient from "effect/http/HttpClient";
8 import * as Schedule from "effect/Schedule";
9 import KeyspacesStreamsTestFunctionLive, {
10 KeyspacesStreamsTestFunction,
11 } from "./streams-handler.ts";
12
13 const { test } = Test.make({ providers: AWS.providers() });
14
15 // keyspacesstreams is a data-plane read API over CDC streams of Keyspaces
16 // tables. The ungated probes assert the distilled wiring surfaces typed
17 // errors; the live traverse (which needs a CDC-enabled table + a deployed
18 // Lambda exercising the TableStreams binding, ~2.5 min) is skipped under
19 // --fast.
20 describe(
21 "AWS.Keyspaces.TableStreams",
22 { tags: ["provider:aws", "provider:aws:keyspaces", "live"] },
23 () => {
24 test.provider(
25 "getStream on a nonexistent stream yields a typed error",
26 (_stack) =>
27 Effect.gen(function* () {
28 const { accountId, region } = yield* AWSEnvironment.current;
29 const error = yield* keyspacesstreams
30 .getStream({
31 streamArn: `arn:aws:cassandra:${region}:${accountId}:/keyspace/alchemy_nonexistent_ks/table/nonexistent_tbl/stream/2024-01-01T00:00:00.000`,
32 })
33 .pipe(Effect.flip);
34 expect(["ResourceNotFoundException", "ValidationException"]).toContain(error._tag);
35 }),
36 { timeout: 60_000 },
37 );
38
39 test.provider(
40 "listStreams on a nonexistent table returns an empty stream list",
41 (_stack) =>
42 Effect.gen(function* () {
43 // The API treats an unknown keyspace/table as "no streams" rather
44 // than ResourceNotFound — the round-trip proves the distilled
45 // wiring decodes ListStreamsOutput.
46 const listed = yield* keyspacesstreams.listStreams({
47 keyspaceName: "alchemy_nonexistent_ks",
48 tableName: "nonexistent_tbl",
49 });
50 expect(listed.streams ?? []).toHaveLength(0);
51 }),
52 { timeout: 60_000 },
53 );
54
55 test.provider.skipIf(!!process.env.FAST)(
56 "CDC table exposes latestStreamArn and Lambda traverses the stream via the binding",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const { functionUrl } = yield* stack.deploy(
62 Effect.gen(function* () {
63 return yield* KeyspacesStreamsTestFunction;
64 }).pipe(Effect.provide(KeyspacesStreamsTestFunctionLive)),
65 );
66 expect(functionUrl).toBeTruthy();
67 const baseUrl = functionUrl!.replace(/\/+$/, "");
68
69 // Out-of-band: the CDC stream is enumerable via distilled directly.
70 const listed = yield* keyspacesstreams.listStreams({
71 keyspaceName: "alchemy_streams_test_ks",
72 tableName: "orders",
73 });
74 expect((listed.streams ?? []).length).toBeGreaterThanOrEqual(1);
75
76 // Drive the deployed Lambda through the TableStreams binding —
77 // proves the cassandra:* stream IAM actions and the client wiring.
78 // Retry through function-URL cold start / IAM propagation.
79 const body = yield* HttpClient.get(`${baseUrl}/traverse`).pipe(
80 Effect.flatMap((response) =>
81 response.status === 200
82 ? response.json
83 : Effect.fail(new Error(`traverse not ready: ${response.status}`)),
84 ),
85 Effect.retry({
86 schedule: Schedule.max([Schedule.exponential("1 second"), Schedule.recurs(8)]),
87 }),
88 );
89 const traverse = body as {
90 streamArn: string;
91 streamStatus: string;
92 viewType: string;
93 shardCount: number;
94 recordCount: number;
95 };
96 expect(traverse.streamArn).toContain("/stream/");
97 expect(["ENABLED", "ENABLING"]).toContain(traverse.streamStatus);
98 expect(traverse.viewType).toBe("NEW_AND_OLD_IMAGES");
99 expect(traverse.shardCount).toBeGreaterThanOrEqual(1);
100 // Idle table — no writes were made, so no change records.
101 expect(traverse.recordCount).toBeGreaterThanOrEqual(0);
102
103 yield* stack.destroy();
104 }),
105 { tags: ["provider:aws:lambda"], timeout: 900_000 },
106 );
107 },
108 );