The best way to control Claude Code, Codex and more from any computer or phone

main
ts 103 lines 4.05 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { DomainName } from "@alchemy.run/aws/ApiGatewayV2";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as agw2 from "@distilled.cloud/aws/apigatewayv2";
6 import * as Provider from "alchemy/Provider";
7 import * as Effect from "effect/Effect";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // Ungated live probe: `list()` enumerates every v2 custom domain in the
12 // account/region and maps each item to the `read` Attributes shape. A
13 // custom domain cannot be provisioned in CI (it needs a validated ACM
14 // certificate for a domain we own — see the gated test below), but this
15 // still verifies pagination + mapping against the live API.
16 test.provider.skipIf(!!process.env.FAST)(
17 "list returns the account/region domain names",
18 () =>
19 Effect.gen(function* () {
20 const provider = yield* Provider.findProvider(DomainName);
21 const all = yield* provider.list();
22
23 expect(Array.isArray(all)).toBe(true);
24 for (const domain of all) {
25 expect(typeof domain.domainName).toBe("string");
26 expect(domain.tags).toBeDefined();
27 }
28 }),
29 { tags: ["provider:aws", "provider:aws:apigatewayv2", "live"] },
30 );
31
32 // Full lifecycle. SKIPPED by default: an API Gateway v2 custom domain
33 // requires a validated REGIONAL ACM certificate for a domain you own (ACM
34 // issuance needs DNS/email validation, which CI cannot complete). Set
35 // AWS_TEST_APIGATEWAYV2_DOMAIN_NAME (a domain you own) and
36 // AWS_TEST_APIGATEWAY_CERT_ARN (a validated regional ACM cert in this
37 // region) to run it on an entitled account unchanged. The domain must differ
38 // from the v1 test's AWS_TEST_APIGATEWAY_DOMAIN_NAME: API Gateway v1 and v2
39 // share one custom-domain namespace and the two files run concurrently, so a
40 // shared name would make both tests adopt and delete the same domain. A
41 // wildcard cert covering both names can be shared via the cert var.
42 const domainName = process.env.AWS_TEST_APIGATEWAYV2_DOMAIN_NAME;
43 const certificateArn = process.env.AWS_TEST_APIGATEWAY_CERT_ARN;
44
45 test.provider.skipIf(!!process.env.FAST || !domainName || !certificateArn)(
46 "create domain name, map an API, delete",
47 (stack) =>
48 Effect.gen(function* () {
49 yield* stack.destroy();
50
51 const out = yield* stack.deploy(
52 Effect.gen(function* () {
53 const domain = yield* AWS.ApiGatewayV2.DomainName("V2Domain", {
54 domainName: domainName!,
55 domainNameConfigurations: [
56 {
57 CertificateArn: certificateArn!,
58 EndpointType: "REGIONAL",
59 SecurityPolicy: "TLS_1_2",
60 },
61 ],
62 });
63
64 const api = yield* AWS.ApiGatewayV2.Api("V2DomainApi", {});
65 const stage = yield* AWS.ApiGatewayV2.Stage("V2DomainStage", { api, autoDeploy: true });
66
67 const mapping = yield* AWS.ApiGatewayV2.ApiMapping("V2Mapping", {
68 api,
69 domainName: domain.domainName,
70 stage: stage.stageName,
71 apiMappingKey: "v2test",
72 });
73
74 return {
75 domainName: domain.domainName,
76 apiId: api.apiId,
77 apiMappingId: mapping.apiMappingId,
78 };
79 }),
80 );
81
82 const remoteDomain = yield* agw2.getDomainName({ DomainName: out.domainName });
83 expect(remoteDomain.DomainName).toBe(domainName);
84
85 const remoteMapping = yield* agw2.getApiMapping({
86 DomainName: out.domainName,
87 ApiMappingId: out.apiMappingId,
88 });
89 expect(remoteMapping.ApiId).toBe(out.apiId);
90 expect(remoteMapping.ApiMappingKey).toBe("v2test");
91
92 yield* stack.destroy();
93
94 const gone = yield* agw2
95 .getApiMapping({ DomainName: out.domainName, ApiMappingId: out.apiMappingId })
96 .pipe(
97 Effect.map(() => "still-exists" as const),
98 Effect.catchTag("NotFoundException", () => Effect.succeed("deleted" as const)),
99 );
100 expect(gone).toBe("deleted");
101 }),
102 { tags: ["provider:aws", "provider:aws:apigatewayv2", "live"], timeout: 240_000 },
103 );