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
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Stream } from "@alchemy.run/aws/DSQL"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as dsql from "@distilled.cloud/aws/dsql"; |
| 6 | import * as Data from "effect/Data"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | const getStream = (clusterIdentifier: string, streamIdentifier: string) => |
| 13 | dsql |
| 14 | .getStream({ clusterIdentifier, streamIdentifier }) |
| 15 | .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined))); |
| 16 | |
| 17 | class StreamStillPresent extends Data.TaggedError("StreamStillPresent")<{ |
| 18 | readonly streamId: string; |
| 19 | readonly status: string; |
| 20 | }> {} |
| 21 | |
| 22 | // Skipped under `--fast`: a DSQL CDC stream transitions |
| 23 | // CREATING -> ACTIVE in one to three minutes (AWS docs), which is beyond the |
| 24 | // ~90s async-provisioning budget for the always-on suite. The full lifecycle |
| 25 | // (cluster + Kinesis target + IAM service role + stream + destroy) measures |
| 26 | // ~5-7 minutes wall. |
| 27 | test.provider.skipIf(!!process.env.FAST)( |
| 28 | "create and delete a DSQL CDC stream into Kinesis", |
| 29 | (stack) => |
| 30 | Effect.gen(function* () { |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const created = yield* stack.deploy( |
| 34 | Effect.gen(function* () { |
| 35 | const cluster = yield* AWS.DSQL.Cluster("CdcDb", {}); |
| 36 | // CDC records can approach 10 MiB — the docs require |
| 37 | // maxRecordSizeInKiB 10240 and ON_DEMAND mode on the target. |
| 38 | const target = yield* AWS.Kinesis.Stream("CdcTarget", { |
| 39 | streamMode: "ON_DEMAND", |
| 40 | maxRecordSizeInKiB: 10240, |
| 41 | }); |
| 42 | const role = yield* AWS.IAM.Role("CdcRole", { |
| 43 | assumeRolePolicyDocument: { |
| 44 | Version: "2012-10-17", |
| 45 | Statement: [ |
| 46 | { |
| 47 | Sid: "DSQLAccess", |
| 48 | Effect: "Allow", |
| 49 | Principal: { Service: "dsql.amazonaws.com" }, |
| 50 | Action: ["sts:AssumeRole"], |
| 51 | }, |
| 52 | ], |
| 53 | }, |
| 54 | inlinePolicies: { |
| 55 | kinesis: { |
| 56 | Version: "2012-10-17", |
| 57 | Statement: [ |
| 58 | { |
| 59 | Sid: "KinesisAccess", |
| 60 | Effect: "Allow", |
| 61 | Action: [ |
| 62 | "kinesis:PutRecord", |
| 63 | "kinesis:PutRecords", |
| 64 | "kinesis:DescribeStreamSummary", |
| 65 | "kinesis:ListShards", |
| 66 | ], |
| 67 | Resource: target.streamArn, |
| 68 | }, |
| 69 | ], |
| 70 | }, |
| 71 | }, |
| 72 | }); |
| 73 | const cdc = yield* Stream("Cdc", { |
| 74 | clusterId: cluster.clusterId, |
| 75 | kinesisStreamArn: target.streamArn, |
| 76 | roleArn: role.roleArn, |
| 77 | tags: { app: "alchemy-test" }, |
| 78 | }); |
| 79 | return { |
| 80 | clusterId: cdc.clusterId, |
| 81 | streamId: cdc.streamId, |
| 82 | streamArn: cdc.streamArn, |
| 83 | status: cdc.status, |
| 84 | kinesisStreamArn: cdc.kinesisStreamArn, |
| 85 | roleArn: cdc.roleArn, |
| 86 | }; |
| 87 | }), |
| 88 | ); |
| 89 | |
| 90 | expect(created.streamId).toBeDefined(); |
| 91 | expect(created.status).toBe("ACTIVE"); |
| 92 | expect(created.streamArn).toContain( |
| 93 | `:cluster/${created.clusterId}/stream/${created.streamId}`, |
| 94 | ); |
| 95 | expect(created.kinesisStreamArn).toContain(":stream/"); |
| 96 | expect(created.roleArn).toContain(":role/"); |
| 97 | |
| 98 | // out-of-band verification via distilled |
| 99 | const observed = yield* getStream(created.clusterId, created.streamId); |
| 100 | expect(observed?.status).toBe("ACTIVE"); |
| 101 | expect(observed?.targetDefinition?.kinesis.streamArn).toEqual(created.kinesisStreamArn); |
| 102 | expect(observed?.tags?.app).toEqual("alchemy-test"); |
| 103 | |
| 104 | // destroy everything; typed wait-until-gone on the CDC stream |
| 105 | yield* stack.destroy(); |
| 106 | yield* getStream(created.clusterId, created.streamId).pipe( |
| 107 | Effect.flatMap((stream) => |
| 108 | stream === undefined || stream.status === "DELETED" |
| 109 | ? Effect.void |
| 110 | : Effect.fail( |
| 111 | new StreamStillPresent({ |
| 112 | streamId: created.streamId, |
| 113 | status: stream.status, |
| 114 | }), |
| 115 | ), |
| 116 | ), |
| 117 | Effect.retry({ |
| 118 | while: (e): boolean => e._tag === "StreamStillPresent", |
| 119 | schedule: Schedule.max([Schedule.spaced("5 seconds"), Schedule.recurs(10)]), |
| 120 | }), |
| 121 | ); |
| 122 | }), |
| 123 | { |
| 124 | tags: ["provider:aws", "provider:aws:dsql", "provider:aws:iam", "provider:aws:kinesis", "live"], |
| 125 | timeout: 600_000, |
| 126 | }, |
| 127 | ); |