@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 84 lines 3.13 KB
Raw
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 const { test, beforeAll, afterAll } = Test.make({
13 providers: AWS.providers(),
14 });
15 shareProvisionedNetwork({ beforeAll, afterAll });
16 const snapshotName = "alchemy-elasticache-provisioned-restore";
17
18 const deleteSnapshot = () =>
19 ElastiCache.deleteSnapshot({ SnapshotName: snapshotName }).pipe(
20 Effect.catchTag("SnapshotNotFoundFault", () => Effect.void),
21 Effect.retry({
22 while: (error) => error._tag === "InvalidSnapshotStateFault",
23 schedule: Schedule.max([Schedule.fixed("15 seconds"), Schedule.recurs(12)]),
24 }),
25 );
26
27 const waitForSnapshot = () =>
28 ElastiCache.describeSnapshots({ SnapshotName: snapshotName }).pipe(
29 Effect.flatMap((response) =>
30 response.Snapshots?.[0]?.SnapshotStatus === "available"
31 ? Effect.void
32 : Effect.fail(new Error(`snapshot '${snapshotName}' is not available`)),
33 ),
34 Effect.retry({
35 schedule: Schedule.max([Schedule.fixed("30 seconds"), Schedule.recurs(30)]),
36 }),
37 );
38
39 test.provider.skipIf(!!process.env.FAST)(
40 "restores a new Valkey replication group from a final snapshot",
41 (stack) =>
42 Effect.gen(function* () {
43 yield* stack.destroy();
44 yield* deleteSnapshot();
45 const deploy = (snapshotNameToRestore?: string, finalSnapshotName?: string) =>
46 stack.deploy(
47 Effect.gen(function* () {
48 const net = yield* getProvisionedNetwork;
49 const cache = yield* AWS.ElastiCache.ReplicationGroup("Cache", {
50 description: "alchemy snapshot restore cache",
51 engine: "valkey",
52 nodeType: "cache.t4g.micro",
53 subnetGroupName: net.subnetGroupName,
54 securityGroupIds: [net.securityGroupId],
55 replicasPerNodeGroup: 0,
56 transitEncryptionEnabled: true,
57 snapshotName: snapshotNameToRestore,
58 finalSnapshotName,
59 });
60 return { cache };
61 }),
62 );
63
64 const source = yield* deploy(undefined, snapshotName);
65 yield* stack.destroy();
66 yield* assertReplicationGroupGone(source.cache.replicationGroupId);
67 yield* waitForSnapshot();
68
69 const restored = yield* deploy(snapshotName);
70 const observed = yield* ElastiCache.describeReplicationGroups({
71 ReplicationGroupId: restored.cache.replicationGroupId,
72 });
73 expect(observed.ReplicationGroups?.[0]?.Status).toBe("available");
74 expect(observed.ReplicationGroups?.[0]?.Engine).toBe("valkey");
75
76 yield* stack.destroy();
77 yield* assertReplicationGroupGone(restored.cache.replicationGroupId);
78 yield* deleteSnapshot();
79 }).pipe(Effect.ensuring(deleteSnapshot().pipe(Effect.ignore))),
80 {
81 tags: ["provider:aws", "provider:aws:ec2", "provider:aws:elasticache", "live"],
82 timeout: 2_700_000,
83 },
84 );