@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 112 lines 4.04 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { PublicRepository } from "@alchemy.run/aws/ECRPublic";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as ecrpublic from "@distilled.cloud/aws/ecr-public";
6 import { Region } from "@distilled.cloud/aws/Region";
7 import * as Data from "effect/Data";
8 import * as Effect from "effect/Effect";
9 import * as Schedule from "effect/Schedule";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // ECR Public is a global registry hosted only in us-east-1; every out-of-band
14 // verification call must target that region regardless of the stack region.
15 const pin = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
16 effect.pipe(Effect.provideService(Region, Effect.succeed("us-east-1")));
17
18 const findRepository = (repositoryName: string) =>
19 pin(ecrpublic.describeRepositories({ repositoryNames: [repositoryName] })).pipe(
20 Effect.map((r) => r.repositories?.[0]),
21 Effect.catchTag("RepositoryNotFoundException", () => Effect.succeed(undefined)),
22 );
23
24 class RepositoryStillExists extends Data.TaggedError("RepositoryStillExists")<{
25 readonly repositoryName: string;
26 }> {}
27
28 const assertRepositoryDeleted = (repositoryName: string) =>
29 findRepository(repositoryName).pipe(
30 Effect.flatMap((repo) =>
31 repo === undefined ? Effect.void : Effect.fail(new RepositoryStillExists({ repositoryName })),
32 ),
33 Effect.retry({
34 while: (e) => e._tag === "RepositoryStillExists",
35 schedule: Schedule.max([Schedule.spaced("2 seconds"), Schedule.recurs(15)]),
36 }),
37 );
38
39 test.provider(
40 "create, update catalog data, delete public repository",
41 (stack) =>
42 Effect.gen(function* () {
43 yield* stack.destroy();
44
45 const repo = yield* stack.deploy(
46 Effect.gen(function* () {
47 return yield* PublicRepository("TestPublicRepo", {
48 catalogData: {
49 description: "initial description",
50 architectures: ["x86-64"],
51 operatingSystems: ["Linux"],
52 },
53 tags: { Environment: "test" },
54 });
55 }),
56 );
57
58 expect(repo.repositoryName).toBeDefined();
59 expect(repo.repositoryArn).toContain(":repository/");
60 expect(repo.repositoryUri).toContain("public.ecr.aws");
61
62 const created = yield* findRepository(repo.repositoryName);
63 expect(created?.repositoryArn).toBe(repo.repositoryArn);
64
65 const catalog = yield* pin(
66 ecrpublic.getRepositoryCatalogData({
67 repositoryName: repo.repositoryName,
68 }),
69 );
70 expect(catalog.catalogData?.description).toBe("initial description");
71
72 const tags = yield* pin(
73 ecrpublic.listTagsForResource({ resourceArn: repo.repositoryArn }),
74 ).pipe(Effect.map((r) => Object.fromEntries((r.tags ?? []).map((t) => [t.Key, t.Value]))));
75 expect(tags.Environment).toBe("test");
76 expect(tags["alchemy::id"]).toBe("TestPublicRepo");
77
78 // Update catalog data + tags.
79 const updated = yield* stack.deploy(
80 Effect.gen(function* () {
81 return yield* PublicRepository("TestPublicRepo", {
82 catalogData: {
83 description: "updated description",
84 architectures: ["x86-64", "ARM 64"],
85 operatingSystems: ["Linux"],
86 },
87 tags: { Environment: "test", Extra: "yes" },
88 });
89 }),
90 );
91 expect(updated.repositoryArn).toBe(repo.repositoryArn);
92
93 const catalog2 = yield* pin(
94 ecrpublic.getRepositoryCatalogData({
95 repositoryName: repo.repositoryName,
96 }),
97 );
98 expect(catalog2.catalogData?.description).toBe("updated description");
99
100 const tags2 = yield* pin(
101 ecrpublic.listTagsForResource({ resourceArn: repo.repositoryArn }),
102 ).pipe(Effect.map((r) => Object.fromEntries((r.tags ?? []).map((t) => [t.Key, t.Value]))));
103 expect(tags2.Extra).toBe("yes");
104
105 yield* stack.destroy();
106 yield* assertRepositoryDeleted(repo.repositoryName);
107 }),
108 {
109 tags: ["provider:aws", "provider:aws:ecrpublic", "live"],
110 timeout: 180_000,
111 },
112 );