@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 68 lines 2.39 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Snapshot, Volume } from "@alchemy.run/aws/EC2";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as EC2 from "@distilled.cloud/aws/ec2";
6 import * as Data from "effect/Data";
7 import * as Effect from "effect/Effect";
8 import { MinimumLogLevel } from "effect/References";
9 import * as Schedule from "effect/Schedule";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 const AZ = "us-west-2a";
16
17 test.provider(
18 "snapshot a volume, wait for completion, then delete both",
19 (stack) =>
20 Effect.gen(function* () {
21 yield* stack.destroy();
22
23 const { volume, snapshot } = yield* stack.deploy(
24 Effect.gen(function* () {
25 const volume = yield* Volume("SnapSourceVolume", {
26 availabilityZone: AZ,
27 size: 1,
28 volumeType: "gp3",
29 });
30 const snapshot = yield* Snapshot("TestSnapshot", {
31 volumeId: volume.volumeId,
32 description: "alchemy storage-trio test snapshot",
33 });
34 return { volume, snapshot };
35 }),
36 );
37
38 expect(snapshot.snapshotId).toMatch(/^snap-/);
39 expect(snapshot.volumeId).toBe(volume.volumeId);
40 // The provider waits for completion before returning.
41 expect(snapshot.state).toBe("completed");
42
43 // Out-of-band verification.
44 const observed = yield* EC2.describeSnapshots({
45 SnapshotIds: [snapshot.snapshotId],
46 });
47 const s = observed.Snapshots?.[0];
48 expect(s?.State).toBe("completed");
49 expect(s?.VolumeId).toBe(volume.volumeId);
50
51 yield* stack.destroy();
52 yield* assertSnapshotDeleted(snapshot.snapshotId);
53 }).pipe(logLevel),
54 { tags: ["provider:aws", "provider:aws:ec2", "live"], timeout: 180_000 },
55 );
56
57 const assertSnapshotDeleted = Effect.fn(function* (snapshotId: string) {
58 yield* EC2.describeSnapshots({ SnapshotIds: [snapshotId] }).pipe(
59 Effect.flatMap(() => Effect.fail(new SnapshotStillExists())),
60 Effect.retry({
61 while: (e) => e instanceof SnapshotStillExists,
62 schedule: Schedule.max([Schedule.exponential(200), Schedule.recurs(8)]),
63 }),
64 Effect.catchTag("InvalidSnapshot.NotFound", () => Effect.void),
65 );
66 });
67
68 class SnapshotStillExists extends Data.TaggedError("SnapshotStillExists") {}