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 * as IAM from "@alchemy.run/aws/IAM"; |
| 3 | import * as S3 from "@alchemy.run/aws/S3"; |
| 4 | import * as SNS from "@alchemy.run/aws/SNS"; |
| 5 | import { Database, ScheduledQuery, Table } from "@alchemy.run/aws/Timestream"; |
| 6 | import { withQueryEndpoint } from "@alchemy.run/aws/Timestream/internal"; |
| 7 | import { describe, expect } from "@alchemy.run/test"; |
| 8 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 9 | import * as TSQ from "@distilled.cloud/aws/timestream-query"; |
| 10 | import * as Output from "alchemy/Output"; |
| 11 | import * as Effect from "effect/Effect"; |
| 12 | |
| 13 | const { test } = Test.make({ providers: AWS.providers() }); |
| 14 | |
| 15 | // Amazon Timestream for LiveAnalytics is closed to new AWS customers; the |
| 16 | // testing account receives the typed `TimestreamNotOnboarded` gate on every |
| 17 | // operation, including the endpoint-discovery call every scheduled-query |
| 18 | // request must make first. The ungated probe asserts the gate surfaces as a |
| 19 | // typed error through the discovery wrapper the provider uses; the full |
| 20 | // lifecycle is gated behind AWS_TEST_TIMESTREAM=1 so an onboarded account can |
| 21 | // run it unchanged. |
| 22 | describe( |
| 23 | "AWS.Timestream.ScheduledQuery", |
| 24 | { tags: ["provider:aws", "provider:aws:timestream", "live"] }, |
| 25 | () => { |
| 26 | test.provider( |
| 27 | "listScheduledQueries reports typed TimestreamNotOnboarded via endpoint discovery", |
| 28 | (_stack) => |
| 29 | Effect.gen(function* () { |
| 30 | const error = yield* withQueryEndpoint(TSQ.listScheduledQueries({})).pipe(Effect.flip); |
| 31 | expect(error._tag).toBe("TimestreamNotOnboarded"); |
| 32 | }), |
| 33 | { timeout: 60_000 }, |
| 34 | ); |
| 35 | |
| 36 | test.provider.skipIf(!process.env.AWS_TEST_TIMESTREAM)( |
| 37 | "create, pause, and delete a scheduled query", |
| 38 | (stack) => |
| 39 | Effect.gen(function* () { |
| 40 | const infra = Effect.gen(function* () { |
| 41 | const database = yield* Database("SqMetrics"); |
| 42 | const table = yield* Table("SqCpu", { databaseName: database.databaseName }); |
| 43 | const topic = yield* SNS.Topic("SqNotifications"); |
| 44 | const bucket = yield* S3.Bucket("SqErrorReports", { forceDestroy: true }); |
| 45 | const role = yield* IAM.Role("SqExecutionRole", { |
| 46 | assumeRolePolicyDocument: { |
| 47 | Version: "2012-10-17", |
| 48 | Statement: [ |
| 49 | { |
| 50 | Effect: "Allow", |
| 51 | Principal: { Service: "timestream.amazonaws.com" }, |
| 52 | Action: ["sts:AssumeRole"], |
| 53 | }, |
| 54 | ], |
| 55 | }, |
| 56 | inlinePolicies: { |
| 57 | scheduledQuery: { |
| 58 | Version: "2012-10-17", |
| 59 | Statement: [ |
| 60 | { |
| 61 | Effect: "Allow", |
| 62 | Action: [ |
| 63 | "timestream:Select", |
| 64 | "timestream:SelectValues", |
| 65 | "timestream:WriteRecords", |
| 66 | "timestream:DescribeEndpoints", |
| 67 | ], |
| 68 | Resource: ["*"], |
| 69 | }, |
| 70 | { Effect: "Allow", Action: ["sns:Publish"], Resource: [topic.topicArn] }, |
| 71 | { |
| 72 | Effect: "Allow", |
| 73 | Action: ["s3:PutObject", "s3:GetBucketAcl"], |
| 74 | Resource: [bucket.bucketArn, Output.interpolate`${bucket.bucketArn}/*`], |
| 75 | }, |
| 76 | ], |
| 77 | }, |
| 78 | }, |
| 79 | }); |
| 80 | const scheduledQuery = yield* ScheduledQuery("HourlyCount", { |
| 81 | queryString: Output.interpolate`SELECT COUNT(*) FROM "${database.databaseName}"."${table.tableName}"`, |
| 82 | scheduleExpression: "rate(1 hour)", |
| 83 | notificationTopicArn: topic.topicArn, |
| 84 | executionRoleArn: role.roleArn, |
| 85 | errorReportS3: { bucketName: bucket.bucketName }, |
| 86 | tags: { Environment: "test" }, |
| 87 | }); |
| 88 | return { scheduledQuery }; |
| 89 | }); |
| 90 | |
| 91 | const { scheduledQuery } = yield* stack.deploy(infra); |
| 92 | expect(scheduledQuery.scheduledQueryArn).toBeTruthy(); |
| 93 | expect(scheduledQuery.state).toBe("ENABLED"); |
| 94 | |
| 95 | // Out-of-band verification via distilled through the discovered |
| 96 | // endpoint. |
| 97 | const described = yield* withQueryEndpoint( |
| 98 | TSQ.describeScheduledQuery({ ScheduledQueryArn: scheduledQuery.scheduledQueryArn }), |
| 99 | ); |
| 100 | expect(described.ScheduledQuery.State).toBe("ENABLED"); |
| 101 | |
| 102 | yield* stack.destroy(); |
| 103 | |
| 104 | const gone = yield* withQueryEndpoint( |
| 105 | TSQ.describeScheduledQuery({ ScheduledQueryArn: scheduledQuery.scheduledQueryArn }), |
| 106 | ).pipe( |
| 107 | Effect.map(() => false), |
| 108 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)), |
| 109 | ); |
| 110 | expect(gone).toBe(true); |
| 111 | }), |
| 112 | { tags: ["provider:aws:iam", "provider:aws:s3", "provider:aws:sns"], timeout: 600_000 }, |
| 113 | ); |
| 114 | }, |
| 115 | ); |