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 { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as ElastiCache from "@distilled.cloud/aws/elasticache"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import { |
| 8 | assertReplicationGroupGone, |
| 9 | getProvisionedNetwork, |
| 10 | shareProvisionedNetwork, |
| 11 | } from "./ProvisionedFixture.ts"; |
| 12 | |
| 13 | const { test, beforeAll, afterAll } = Test.make({ |
| 14 | providers: AWS.providers(), |
| 15 | }); |
| 16 | shareProvisionedNetwork({ beforeAll, afterAll }); |
| 17 | const listTagsWhenAvailable = (resourceName: string) => |
| 18 | ElastiCache.listTagsForResource({ ResourceName: resourceName }).pipe( |
| 19 | Effect.retry({ |
| 20 | while: (error) => (error as { _tag?: string })._tag === "InvalidReplicationGroupStateFault", |
| 21 | schedule: Schedule.max([Schedule.fixed("15 seconds"), Schedule.recurs(100)]), |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | test.provider.skipIf(!!process.env.FAST)( |
| 26 | "updates replication-group tags and VPC security groups in place", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | yield* stack.destroy(); |
| 30 | const deploy = (phase: "one" | "two") => |
| 31 | stack.deploy( |
| 32 | Effect.gen(function* () { |
| 33 | const net = yield* getProvisionedNetwork; |
| 34 | const replacementSecurityGroup = yield* AWS.EC2.SecurityGroup( |
| 35 | "ReplacementSecurityGroup", |
| 36 | { |
| 37 | vpcId: net.vpcId, |
| 38 | description: "ElastiCache replacement integration-test access", |
| 39 | tags: { fixture: "elasticache-provisioned" }, |
| 40 | }, |
| 41 | ); |
| 42 | const cache = yield* AWS.ElastiCache.ReplicationGroup("Cache", { |
| 43 | description: "alchemy configuration cache", |
| 44 | engine: "valkey", |
| 45 | nodeType: "cache.t4g.micro", |
| 46 | subnetGroupName: net.subnetGroupName, |
| 47 | securityGroupIds: [ |
| 48 | phase === "one" ? net.securityGroupId : replacementSecurityGroup.groupId, |
| 49 | ], |
| 50 | replicasPerNodeGroup: 0, |
| 51 | transitEncryptionEnabled: true, |
| 52 | tags: |
| 53 | phase === "one" |
| 54 | ? { |
| 55 | fixture: "elasticache-provisioned", |
| 56 | phase: "one", |
| 57 | remove: "me", |
| 58 | } |
| 59 | : { fixture: "elasticache-provisioned", phase: "two" }, |
| 60 | }); |
| 61 | return { |
| 62 | cache, |
| 63 | activeSecurityGroupId: |
| 64 | phase === "one" ? net.securityGroupId : replacementSecurityGroup.groupId, |
| 65 | }; |
| 66 | }), |
| 67 | ); |
| 68 | |
| 69 | const created = yield* deploy("one"); |
| 70 | const createdTags = yield* listTagsWhenAvailable(created.cache.replicationGroupArn); |
| 71 | expect(createdTags.TagList).toContainEqual({ |
| 72 | Key: "phase", |
| 73 | Value: "one", |
| 74 | }); |
| 75 | expect(createdTags.TagList).toContainEqual({ |
| 76 | Key: "remove", |
| 77 | Value: "me", |
| 78 | }); |
| 79 | |
| 80 | const updated = yield* deploy("two"); |
| 81 | expect(updated.cache.replicationGroupId).toBe(created.cache.replicationGroupId); |
| 82 | const updatedTags = yield* listTagsWhenAvailable(updated.cache.replicationGroupArn); |
| 83 | expect(updatedTags.TagList).toContainEqual({ |
| 84 | Key: "phase", |
| 85 | Value: "two", |
| 86 | }); |
| 87 | expect(updatedTags.TagList).not.toContainEqual({ |
| 88 | Key: "remove", |
| 89 | Value: "me", |
| 90 | }); |
| 91 | |
| 92 | const group = yield* ElastiCache.describeReplicationGroups({ |
| 93 | ReplicationGroupId: updated.cache.replicationGroupId, |
| 94 | }); |
| 95 | const memberId = group.ReplicationGroups?.[0]?.MemberClusters?.[0]; |
| 96 | if (!memberId) |
| 97 | return yield* Effect.fail(new Error("replication group has no member cluster")); |
| 98 | const member = yield* ElastiCache.describeCacheClusters({ |
| 99 | CacheClusterId: memberId, |
| 100 | }); |
| 101 | expect(member.CacheClusters?.[0]?.SecurityGroups?.map((sg) => sg.SecurityGroupId)).toEqual([ |
| 102 | updated.activeSecurityGroupId, |
| 103 | ]); |
| 104 | |
| 105 | yield* stack.destroy(); |
| 106 | yield* assertReplicationGroupGone(updated.cache.replicationGroupId); |
| 107 | }), |
| 108 | { |
| 109 | tags: ["provider:aws", "provider:aws:ec2", "provider:aws:elasticache", "live"], |
| 110 | timeout: 2_700_000, |
| 111 | }, |
| 112 | ); |