@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 83 lines 3.37 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 {
7 assertReplicationGroupGone,
8 getProvisionedNetwork,
9 shareProvisionedNetwork,
10 } from "./ProvisionedFixture.ts";
11
12 const { test, beforeAll, afterAll } = Test.make({
13 providers: AWS.providers(),
14 });
15 shareProvisionedNetwork({ beforeAll, afterAll });
16 test.provider.skipIf(!!process.env.FAST)(
17 "updates a Valkey replication group to a newer supported engine version",
18 (stack) =>
19 Effect.gen(function* () {
20 const versions =
21 (yield* ElastiCache.describeCacheEngineVersions({
22 Engine: "valkey",
23 })).CacheEngineVersions?.map((version) => version.EngineVersion).filter(
24 (version): version is string => version !== undefined,
25 ) ?? [];
26 const ordered = [...new Set(versions)].sort((left, right) =>
27 left.localeCompare(right, undefined, { numeric: true }),
28 );
29 const sameMajorUpgrade = ordered
30 .map((initialVersion, index) => [initialVersion, ordered[index + 1]])
31 .find(
32 ([initialVersion, updatedVersion]) =>
33 updatedVersion !== undefined &&
34 initialVersion.split(".")[0] === updatedVersion.split(".")[0],
35 );
36 const [initialVersion, updatedVersion] = sameMajorUpgrade ?? [ordered[0], ordered[1]];
37 if (!initialVersion || !updatedVersion || initialVersion === updatedVersion) {
38 return yield* Effect.fail(
39 new Error("AWS did not advertise two distinct Valkey engine versions"),
40 );
41 }
42
43 yield* stack.destroy();
44 const net = yield* getProvisionedNetwork;
45 const program = (engineVersion: string) =>
46 Effect.gen(function* () {
47 const cache = yield* AWS.ElastiCache.ReplicationGroup("Cache", {
48 description: "alchemy engine upgrade cache",
49 engine: "valkey",
50 engineVersion,
51 nodeType: "cache.t4g.micro",
52 subnetGroupName: net.subnetGroupName,
53 securityGroupIds: [net.securityGroupId],
54 replicasPerNodeGroup: 0,
55 transitEncryptionEnabled: true,
56 });
57 return { cache };
58 });
59
60 const created = yield* stack.deploy(program(initialVersion));
61 const updated = yield* stack.deploy(program(updatedVersion));
62 expect(updated.cache.replicationGroupId).toBe(created.cache.replicationGroupId);
63 const group = yield* ElastiCache.describeReplicationGroups({
64 ReplicationGroupId: updated.cache.replicationGroupId,
65 });
66 const memberId = group.ReplicationGroups?.[0]?.MemberClusters?.[0];
67 if (!memberId)
68 return yield* Effect.fail(new Error("replication group has no member cluster"));
69 const member = yield* ElastiCache.describeCacheClusters({
70 CacheClusterId: memberId,
71 });
72 // The API accepts a major/minor target such as `9.1`, but reports the
73 // fully resolved patch release (for example `9.1.0`).
74 expect(member.CacheClusters?.[0]?.EngineVersion?.startsWith(updatedVersion)).toBe(true);
75
76 yield* stack.destroy();
77 yield* assertReplicationGroupGone(updated.cache.replicationGroupId);
78 }),
79 {
80 tags: ["provider:aws", "provider:aws:ec2", "provider:aws:elasticache", "live"],
81 timeout: 2_700_000,
82 },
83 );