@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 136 lines 5.59 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { ServiceQuotaIncreaseRequest } from "@alchemy.run/aws/ServiceQuotas";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as servicequotas from "@distilled.cloud/aws/service-quotas";
6 import * as Effect from "effect/Effect";
7
8 const { test } = Test.make({ providers: AWS.providers() });
9
10 // VPCs per region (default 5) and Subnets per VPC (default 200) — both
11 // always exist, so a desiredValue of 1 is always already satisfied and the
12 // reconciler never submits a real increase request.
13 const VPCS_PER_REGION = "L-F678F1CE";
14 const SUBNETS_PER_VPC = "L-407747CB";
15
16 // Ungated typed-error probe: prove the distilled error union carries the
17 // not-found tag this provider's observe/read paths depend on. Runs in every
18 // CI pass at near-zero cost, unlike the gated live increase below.
19 test.provider(
20 "getServiceQuota with a bogus quota code fails with NoSuchResourceException",
21 () =>
22 Effect.gen(function* () {
23 const error = yield* Effect.flip(
24 servicequotas.getServiceQuota({ ServiceCode: "vpc", QuotaCode: "L-00000000" }),
25 );
26 expect(error._tag).toBe("NoSuchResourceException");
27 }),
28 { tags: ["provider:aws", "provider:aws:servicequotas", "live"] },
29 );
30
31 // Full engine lifecycle on the SAFE path: a desired value at or below the
32 // applied quota is already satisfied, so no real increase request (and no
33 // support case) is ever opened. Covers create, no-op update, and
34 // replacement (quotaCode change).
35 test.provider(
36 "already-satisfied desired value deploys without submitting a request",
37 (stack) =>
38 Effect.gen(function* () {
39 yield* stack.destroy();
40
41 const deployQuota = (quotaCode: string, desiredValue: number) =>
42 stack.deploy(
43 Effect.gen(function* () {
44 const request = yield* ServiceQuotaIncreaseRequest("VpcQuota", {
45 serviceCode: "vpc",
46 quotaCode,
47 desiredValue,
48 });
49 return { request };
50 }),
51 );
52
53 // 1. Create — satisfied, so no request is submitted.
54 const { request } = yield* deployQuota(VPCS_PER_REGION, 1);
55 expect(request.serviceCode).toBe("vpc");
56 expect(request.quotaCode).toBe(VPCS_PER_REGION);
57 expect(request.desiredValue).toBe(1);
58 expect(request.requestId).toBeUndefined();
59 expect(request.status).toBeUndefined();
60 // The VPCs-per-region quota defaults to 5 — always >= 1.
61 expect(request.appliedValue).toBeGreaterThanOrEqual(1);
62 expect(request.quotaName).toBeDefined();
63
64 // 2. Update desiredValue (still satisfied) — default update path, no
65 // request submitted.
66 const second = yield* deployQuota(VPCS_PER_REGION, 2);
67 expect(second.request.desiredValue).toBe(2);
68 expect(second.request.requestId).toBeUndefined();
69
70 // 3. Replacement — quotaCode change replaces the resource. Still
71 // satisfied (Subnets per VPC defaults to 200), so still no request.
72 const third = yield* deployQuota(SUBNETS_PER_VPC, 1);
73 expect(third.request.quotaCode).toBe(SUBNETS_PER_VPC);
74 expect(third.request.requestId).toBeUndefined();
75 expect(third.request.appliedValue).toBeGreaterThanOrEqual(1);
76
77 yield* stack.destroy();
78 }),
79 { tags: ["provider:aws", "provider:aws:servicequotas", "live"], timeout: 120_000 },
80 );
81
82 // Submitting a REAL quota increase request may open an AWS Support case and
83 // cannot be cancelled via the API — gated behind AWS_TEST_SERVICE_QUOTAS=1.
84 test.provider.skipIf(!process.env.AWS_TEST_SERVICE_QUOTAS)(
85 "submits a real quota increase request and adopts it on re-deploy",
86 (stack) =>
87 Effect.gen(function* () {
88 yield* stack.destroy();
89
90 // Observe the current applied value out-of-band so the requested
91 // value is always strictly above it (AWS rejects <= applied).
92 const current = yield* servicequotas
93 .getServiceQuota({ ServiceCode: "vpc", QuotaCode: VPCS_PER_REGION })
94 .pipe(
95 Effect.map((r) => r.Quota?.Value),
96 Effect.catchTag("NoSuchResourceException", () =>
97 servicequotas
98 .getAWSDefaultServiceQuota({ ServiceCode: "vpc", QuotaCode: VPCS_PER_REGION })
99 .pipe(Effect.map((r) => r.Quota?.Value)),
100 ),
101 );
102 const desiredValue = Math.ceil(current ?? 5) + 1;
103
104 const deployIncrease = stack.deploy(
105 Effect.gen(function* () {
106 const request = yield* ServiceQuotaIncreaseRequest("VpcIncrease", {
107 serviceCode: "vpc",
108 quotaCode: VPCS_PER_REGION,
109 desiredValue,
110 });
111 return { request };
112 }),
113 );
114
115 const { request } = yield* deployIncrease;
116 expect(request.requestId).toBeDefined();
117 expect(["PENDING", "CASE_OPENED", "APPROVED"]).toContain(request.status);
118 expect(request.desiredValue).toBe(desiredValue);
119
120 // Out-of-band verification via distilled.
121 const observed = yield* servicequotas.getRequestedServiceQuotaChange({
122 RequestId: request.requestId!,
123 });
124 expect(observed.RequestedQuota?.QuotaCode).toBe(VPCS_PER_REGION);
125 expect(observed.RequestedQuota?.DesiredValue).toBe(desiredValue);
126
127 // Idempotency: a second deploy converges on the SAME open request
128 // instead of submitting a duplicate.
129 const second = yield* deployIncrease;
130 expect(second.request.requestId).toBe(request.requestId);
131
132 // Destroy only forgets the request — Service Quotas has no cancel API.
133 yield* stack.destroy();
134 }),
135 { tags: ["provider:aws", "provider:aws:servicequotas", "live"], timeout: 180_000 },
136 );