@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 74 lines 2.6 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { UserPool, UserPoolDomain } from "@alchemy.run/aws/Cognito";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as cip from "@distilled.cloud/aws/cognito-identity-provider";
6 import * as Data from "effect/Data";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 class DomainStillExists extends Data.TaggedError("DomainStillExists")<{
13 readonly domain: string;
14 }> {}
15
16 const assertDomainDeleted = (domain: string) =>
17 cip.describeUserPoolDomain({ Domain: domain }).pipe(
18 Effect.flatMap((r) =>
19 r.DomainDescription?.UserPoolId === undefined
20 ? Effect.void
21 : Effect.fail(new DomainStillExists({ domain })),
22 ),
23 Effect.retry({
24 while: (e) => e._tag === "DomainStillExists",
25 schedule: Schedule.max([Schedule.exponential(500), Schedule.recurs(8)]),
26 }),
27 );
28
29 test.provider(
30 "cognito-prefix domain lifecycle",
31 (stack) =>
32 Effect.gen(function* () {
33 yield* stack.destroy();
34
35 const outputs = yield* stack.deploy(
36 Effect.gen(function* () {
37 const pool = yield* UserPool("DomainTestPool", {});
38 const domain = yield* UserPoolDomain("AuthDomain", {
39 userPoolId: pool.userPoolId,
40 });
41 return { pool, domain };
42 }),
43 );
44
45 expect(outputs.domain.domain).toMatch(/^[a-z0-9-]+$/);
46 expect(outputs.domain.domain).not.toContain("cognito");
47 expect(outputs.domain.domain).not.toContain("aws");
48 expect(outputs.domain.userPoolId).toBe(outputs.pool.userPoolId);
49 expect(outputs.domain.cloudFrontDomain).toBeTruthy();
50
51 // out-of-band verification via distilled
52 const described = yield* cip.describeUserPoolDomain({
53 Domain: outputs.domain.domain,
54 });
55 expect(described.DomainDescription?.UserPoolId).toBe(outputs.pool.userPoolId);
56 expect(described.DomainDescription?.Status).toBe("ACTIVE");
57
58 // no-op deploy converges without error
59 const noop = yield* stack.deploy(
60 Effect.gen(function* () {
61 const pool = yield* UserPool("DomainTestPool", {});
62 const domain = yield* UserPoolDomain("AuthDomain", {
63 userPoolId: pool.userPoolId,
64 });
65 return { pool, domain };
66 }),
67 );
68 expect(noop.domain.domain).toBe(outputs.domain.domain);
69
70 yield* stack.destroy();
71 yield* assertDomainDeleted(outputs.domain.domain);
72 }),
73 { tags: ["provider:aws", "provider:aws:cognito", "live"], timeout: 180_000 },
74 );