@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 110 lines 4.4 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import {
3 Application,
4 ApplicationCloudWatchLoggingOption,
5 } from "@alchemy.run/aws/KinesisAnalyticsV2";
6 import { describe, expect } from "@alchemy.run/test";
7 import * as Test from "@alchemy.run/test/Alchemy";
8 import * as analytics from "@distilled.cloud/aws/kinesis-analytics-v2";
9 import * as Data from "effect/Data";
10 import * as Effect from "effect/Effect";
11 import * as Schedule from "effect/Schedule";
12 import { codeKey, deleteCodeBucketIdempotent, provisionCodeBucket } from "./code-bucket.ts";
13
14 const { test } = Test.make({ providers: AWS.providers() });
15
16 // Deterministic out-of-band code bucket (see code-bucket.ts) — an in-stack
17 // bucket orphans on a crashed run because its generated name is lost with
18 // the state.
19 const loggingCodeBucket = "alchemy-test-kav2-logging-code";
20
21 class ApplicationStillExists extends Data.TaggedError("ApplicationStillExists") {}
22
23 const assertApplicationDeleted = Effect.fn(function* (applicationName: string) {
24 yield* analytics.describeApplication({ ApplicationName: applicationName }).pipe(
25 Effect.flatMap(() => Effect.fail(new ApplicationStillExists())),
26 Effect.retry({
27 while: (e: { _tag: string }) => e._tag === "ApplicationStillExists",
28 schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(40)]),
29 }),
30 Effect.catchTag("ResourceNotFoundException", () => Effect.void),
31 );
32 });
33
34 describe.skipIf(!!process.env.FAST)(
35 "AWS.KinesisAnalyticsV2.ApplicationCloudWatchLoggingOption",
36 {
37 tags: [
38 "provider:aws",
39 "provider:aws:kinesisanalyticsv2",
40 "provider:aws:logs",
41 "provider:aws:s3",
42 "live",
43 ],
44 },
45 () => {
46 test.provider(
47 "attach a CloudWatch logging option, detach it, destroy",
48 (stack) =>
49 Effect.gen(function* () {
50 yield* stack.destroy();
51
52 // Stage the code object BEFORE the application exists — the service
53 // reads (and hashes) the object at create/update time.
54 const codeBucketArn = yield* provisionCodeBucket(loggingCodeBucket);
55
56 const makeBase = Effect.gen(function* () {
57 const logGroup = yield* AWS.Logs.LogGroup("FlinkLogGroup", {});
58 const logStream = yield* AWS.Logs.LogStream("FlinkLogStream", {
59 logGroupName: logGroup.logGroupName,
60 });
61 const app = yield* Application("LoggedFlinkApp", {
62 runtimeEnvironment: "FLINK-1_20",
63 code: { bucketArn: codeBucketArn, fileKey: codeKey },
64 });
65 return { logGroup, logStream, app };
66 });
67
68 const deployed = yield* stack.deploy(
69 Effect.gen(function* () {
70 const base = yield* makeBase;
71 const logging = yield* ApplicationCloudWatchLoggingOption("FlinkLogging", {
72 applicationName: base.app.applicationName,
73 logStreamArn: base.logStream.logStreamArn.as<string>(),
74 });
75 return { ...base, logging };
76 }),
77 );
78
79 expect(deployed.logging.applicationName).toEqual(deployed.app.applicationName);
80 expect(deployed.logging.cloudWatchLoggingOptionId).toBeDefined();
81 expect(deployed.logging.logStreamArn).toContain(":log-stream:");
82
83 // Out-of-band: the option is visible on the application.
84 const described = yield* analytics.describeApplication({
85 ApplicationName: deployed.app.applicationName,
86 });
87 const options = described.ApplicationDetail.CloudWatchLoggingOptionDescriptions ?? [];
88 expect(options).toHaveLength(1);
89 expect(options[0]?.LogStreamARN).toEqual(deployed.logging.logStreamArn);
90
91 // Remove the option while the application stays deployed — the
92 // engine deletes just the sub-resource.
93 const detached = yield* stack.deploy(makeBase);
94 expect(detached.app.applicationName).toEqual(deployed.app.applicationName);
95
96 const afterDetach = yield* analytics.describeApplication({
97 ApplicationName: deployed.app.applicationName,
98 });
99 expect(
100 afterDetach.ApplicationDetail.CloudWatchLoggingOptionDescriptions ?? [],
101 ).toHaveLength(0);
102
103 yield* stack.destroy();
104
105 yield* assertApplicationDeleted(deployed.app.applicationName);
106 }).pipe(Effect.ensuring(deleteCodeBucketIdempotent(loggingCodeBucket))),
107 { timeout: 300_000 },
108 );
109 },
110 );