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 { LoggingConfiguration, Room } from "@alchemy.run/aws/IVSChat"; |
| 3 | import { LogGroup } from "@alchemy.run/aws/Logs"; |
| 4 | import { expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as ivschat from "@distilled.cloud/aws/ivschat"; |
| 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 assertLoggingConfigurationGone = (arn: string) => |
| 13 | Effect.gen(function* () { |
| 14 | const config = yield* ivschat.getLoggingConfiguration({ identifier: arn }).pipe( |
| 15 | Effect.map((r) => r.arn), |
| 16 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)), |
| 17 | ); |
| 18 | if (config !== undefined) { |
| 19 | return yield* Effect.fail(new Error(`logging configuration '${arn}' still exists`)); |
| 20 | } |
| 21 | }).pipe( |
| 22 | Effect.retry({ |
| 23 | schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(8)]), |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | // Covers create (CloudWatch Logs destination, waits for ACTIVE), |
| 28 | // attachment to a room, no-op, and destroy. |
| 29 | test.provider( |
| 30 | "create, attach, and destroy an IVS Chat logging configuration", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const program = Effect.gen(function* () { |
| 36 | const logGroup = yield* LogGroup("ChatLogGroup", { |
| 37 | logGroupName: "/alchemy-test/ivschat-logging", |
| 38 | retention: "1 day", |
| 39 | }); |
| 40 | const logging = yield* LoggingConfiguration("ChatLogs", { |
| 41 | loggingConfigurationName: "alchemy-test-ivschat-logging", |
| 42 | destinationConfiguration: { |
| 43 | cloudWatchLogs: { logGroupName: logGroup.logGroupName }, |
| 44 | }, |
| 45 | tags: { fixture: "ivschat-logging" }, |
| 46 | }); |
| 47 | const room = yield* Room("LoggedChat", { |
| 48 | roomName: "alchemy-test-ivschat-logged-room", |
| 49 | loggingConfigurationIdentifiers: [logging.loggingConfigurationArn], |
| 50 | }); |
| 51 | return { logging, room }; |
| 52 | }); |
| 53 | |
| 54 | // Create. |
| 55 | const created = yield* stack.deploy(program); |
| 56 | expect(created.logging.loggingConfigurationName).toBe("alchemy-test-ivschat-logging"); |
| 57 | expect(created.logging.loggingConfigurationArn).toContain(":logging-configuration/"); |
| 58 | expect(created.logging.loggingConfigurationId).toBeDefined(); |
| 59 | expect(created.logging.state).toBe("ACTIVE"); |
| 60 | |
| 61 | // Out-of-band verification via distilled. |
| 62 | const observed = yield* ivschat.getLoggingConfiguration({ |
| 63 | identifier: created.logging.loggingConfigurationArn, |
| 64 | }); |
| 65 | expect(observed.state).toBe("ACTIVE"); |
| 66 | expect( |
| 67 | observed.destinationConfiguration && "cloudWatchLogs" in observed.destinationConfiguration |
| 68 | ? observed.destinationConfiguration.cloudWatchLogs?.logGroupName |
| 69 | : undefined, |
| 70 | ).toBe("/alchemy-test/ivschat-logging"); |
| 71 | expect(observed.tags?.["alchemy::id"]).toBe("ChatLogs"); |
| 72 | |
| 73 | // The room is attached to the logging configuration. |
| 74 | const observedRoom = yield* ivschat.getRoom({ |
| 75 | identifier: created.room.roomArn, |
| 76 | }); |
| 77 | expect(observedRoom.loggingConfigurationIdentifiers).toContain( |
| 78 | created.logging.loggingConfigurationArn, |
| 79 | ); |
| 80 | |
| 81 | // No-op redeploy keeps the same configuration. |
| 82 | const noop = yield* stack.deploy(program); |
| 83 | expect(noop.logging.loggingConfigurationArn).toBe(created.logging.loggingConfigurationArn); |
| 84 | |
| 85 | // Destroy and verify out-of-band with a typed wait-until-gone. |
| 86 | yield* stack.destroy(); |
| 87 | yield* assertLoggingConfigurationGone(created.logging.loggingConfigurationArn); |
| 88 | }), |
| 89 | { |
| 90 | tags: ["provider:aws", "provider:aws:ivschat", "provider:aws:logs", "live"], |
| 91 | timeout: 240_000, |
| 92 | }, |
| 93 | ); |