@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 89 lines 3.84 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { DomainName } from "@alchemy.run/aws/ApiGateway";
3 import { expect } from "@alchemy.run/test";
4 import * as ag from "@distilled.cloud/aws/api-gateway";
5 import * as Provider from "alchemy/Provider";
6 import * as Effect from "effect/Effect";
7 import { driftOf, repairDrift, waitForDrift } from "../drift.ts";
8 import { assertDomainNameDeleted } from "./assertions.ts";
9 import * as Test from "./Test.ts";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // Ungated live probe: `list()` enumerates every custom domain in the
14 // account/region. It paginates `getDomainNames` exhaustively and maps each item
15 // to the same Attributes shape `read` returns. We don't deploy here because an
16 // API Gateway custom domain can't be provisioned in CI (see the gated test
17 // below) — but this still verifies the pagination + mapping against the live
18 // API and asserts every returned row is well-formed.
19 test.provider.skipIf(!!process.env.FAST)(
20 "list returns the account/region domain names",
21 () =>
22 Effect.gen(function* () {
23 const provider = yield* Provider.findProvider(DomainName);
24 const all = yield* provider.list();
25
26 expect(Array.isArray(all)).toBe(true);
27 for (const d of all) {
28 expect(typeof d.domainName).toBe("string");
29 expect(d.tags).toBeDefined();
30 }
31 }),
32 { tags: ["provider:aws", "provider:aws:apigateway", "live"] },
33 );
34
35 // Full deploy-then-list assertion. SKIPPED by default because an API Gateway
36 // custom domain requires a certificate that AWS accepts:
37 // - EDGE + uploaded cert -> CloudFront rejects a self-signed cert:
38 // BadRequestException "The certificate that is attached to your
39 // distribution was not issued by a trusted Certificate Authority."
40 // - REGIONAL -> requires an ACM `regionalCertificateArn` for a
41 // domain you own (ACM issuance needs DNS/email validation).
42 // Set AWS_TEST_APIGATEWAY_DOMAIN_NAME (a domain you own) and
43 // AWS_TEST_APIGATEWAY_CERT_ARN (a validated regional ACM cert in this region)
44 // to run it on an entitled account unchanged.
45 const domainName = process.env.AWS_TEST_APIGATEWAY_DOMAIN_NAME;
46 const certificateArn = process.env.AWS_TEST_APIGATEWAY_CERT_ARN;
47
48 test.provider.skipIf(!!process.env.FAST || !domainName || !certificateArn)(
49 "list enumerates the deployed domain name",
50 (stack) =>
51 Effect.gen(function* () {
52 yield* stack.destroy();
53
54 const domain = yield* stack.deploy(
55 Effect.gen(function* () {
56 return yield* DomainName("ListDomain", {
57 domainName: domainName!,
58 regionalCertificateArn: certificateArn!,
59 endpointConfiguration: { types: ["REGIONAL"] },
60 securityPolicy: "TLS_1_2",
61 });
62 }),
63 );
64
65 const provider = yield* Provider.findProvider(DomainName);
66 const all = yield* provider.list();
67
68 expect(all.some((d) => d.domainName === domain.domainName)).toBe(true);
69
70 // #2688: `read` must observe the TLS policy and certificates, or an
71 // out-of-band change reads as `unchanged`.
72 expect((yield* driftOf(stack, "ListDomain"))?.action).toBe("unchanged");
73 yield* ag.updateDomainName({
74 domainName: domain.domainName,
75 patchOperations: [{ op: "replace", path: "/securityPolicy", value: "TLS_1_0" }],
76 });
77 expect(
78 (yield* waitForDrift(stack, "ListDomain", "drifted"))?.attr?.configuration?.securityPolicy,
79 ).toBe("TLS_1_0");
80 yield* repairDrift(stack);
81 expect((yield* waitForDrift(stack, "ListDomain", "unchanged"))?.action).toBe("unchanged");
82 const restored = yield* ag.getDomainName({ domainName: domain.domainName });
83 expect(restored.securityPolicy).toBe("TLS_1_2");
84
85 yield* stack.destroy();
86 yield* assertDomainNameDeleted(domain.domainName);
87 }),
88 { tags: ["provider:aws", "provider:aws:apigateway", "live"] },
89 );