@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 213 lines 7.58 KB
Raw
1 import {
2 OrganizationVPCEndpoint,
3 validateOrganizationVPCEndpoint,
4 } from "@alchemy.run/neon/OrganizationVPCEndpoint";
5 import { providers } from "@alchemy.run/neon/Providers";
6 import { expect } from "@alchemy.run/test";
7 import * as Test from "@alchemy.run/test/Alchemy";
8 import * as SDK from "@distilled.cloud/neon";
9 import { adopt } from "alchemy/AdoptPolicy";
10 import * as Output from "alchemy/Output";
11 import * as Effect from "effect/Effect";
12 import * as Result from "effect/Result";
13
14 const { test } = Test.make({ providers: providers() });
15 const props = {
16 orgId: "org-network-fixture",
17 regionId: "aws-us-east-2",
18 vpcEndpointId: "vpce-0123456789abcdef0",
19 label: "Fixture",
20 };
21 const context = {
22 id: "Network",
23 fqn: "Network",
24 instanceId: "network-validation",
25 oldBindings: [],
26 newBindings: [],
27 };
28
29 test(
30 "organization registration validates AWS scope and endpoint identities",
31 Effect.gen(function* () {
32 yield* validateOrganizationVPCEndpoint(props);
33 for (const patch of [
34 { orgId: "" },
35 { regionId: "azure-eastus2" },
36 { vpcEndpointId: "vpc-0123456789abcdef0" },
37 { label: " " },
38 ]) {
39 expect(
40 Result.isFailure(
41 yield* validateOrganizationVPCEndpoint({ ...props, ...patch }).pipe(Effect.result),
42 ),
43 ).toBe(true);
44 }
45 }),
46 { tags: ["provider:neon", "provider:neon:organizationvpcendpoint", "live"] },
47 );
48
49 test.provider(
50 "organization registration scope replacements delete the old scope first",
51 () =>
52 Effect.gen(function* () {
53 const provider = yield* OrganizationVPCEndpoint.Provider;
54 for (const patch of [
55 { orgId: "org-other" },
56 { regionId: "aws-us-west-2" },
57 { vpcEndpointId: "vpce-abcdef01234567890" },
58 { regionId: Output.literal("aws-us-west-2") },
59 ]) {
60 expect(
61 yield* provider.diff!({
62 ...context,
63 olds: props,
64 news: { ...props, ...patch },
65 output: undefined,
66 }),
67 ).toEqual({ action: "replace", deleteFirst: true });
68 }
69 for (const news of [Output.literal(props), Effect.succeed(props)]) {
70 expect(yield* provider.diff!({ ...context, olds: props, news, output: undefined })).toEqual(
71 { action: "replace", deleteFirst: true },
72 );
73 }
74 expect(
75 yield* provider.diff!({
76 ...context,
77 olds: props,
78 news: { ...props, label: Output.literal("Updated") },
79 output: undefined,
80 }),
81 ).toBeUndefined();
82 }).pipe(
83 Effect.provideService(
84 SDK.Credentials,
85 Effect.die("Unexpected Neon request in a no-I/O guard test"),
86 ),
87 ),
88 { tags: ["provider:neon", "provider:neon:organizationvpcendpoint", "live"] },
89 );
90
91 test.provider(
92 "organization registration rejects a cached endpoint from another region before I/O",
93 () =>
94 Effect.gen(function* () {
95 const provider = yield* OrganizationVPCEndpoint.Provider;
96 expect(
97 yield* provider
98 .reconcile({
99 ...context,
100 bindings: [],
101 session: { note: () => Effect.void },
102 olds: undefined,
103 news: { ...props, regionId: "aws-us-west-2" },
104 output: {
105 ...props,
106 initialLabel: props.label,
107 managedLabel: props.label,
108 state: "accepted",
109 },
110 })
111 .pipe(
112 Effect.as(false),
113 Effect.catchTag("InvalidOrganizationVPCEndpoint", () => Effect.succeed(true)),
114 ),
115 ).toBe(true);
116 }).pipe(
117 Effect.provideService(
118 SDK.Credentials,
119 Effect.die("Unexpected Neon request in a no-I/O guard test"),
120 ),
121 ),
122 { tags: ["provider:neon", "provider:neon:organizationvpcendpoint", "live"] },
123 );
124
125 const orgId = process.env.NEON_GOVERNANCE_TEST_ORG_ID;
126 const regionId = process.env.NEON_GOVERNANCE_TEST_VPC_ENDPOINT_REGION;
127 const vpcEndpointId = process.env.NEON_GOVERNANCE_TEST_VPC_ENDPOINT_ID;
128 const enabled =
129 !!orgId && !!regionId && !!vpcEndpointId && process.env.NEON_GOVERNANCE_TEST_NETWORK === "1";
130 const disposable = process.env.NEON_GOVERNANCE_TEST_VPC_UNREGISTER === "1";
131
132 // The ordinary fixture must already be registered; unregistering it is irreversible.
133 test.provider.skipIf(!enabled || disposable)(
134 "dedicated existing organization registration requires adoption and restores its exact label",
135 (stack) =>
136 Effect.gen(function* () {
137 yield* stack.destroy();
138 const scope = { orgId: orgId!, regionId: regionId!, vpcEndpointId: vpcEndpointId! };
139 const request = {
140 org_id: scope.orgId,
141 region_id: scope.regionId,
142 vpc_endpoint_id: scope.vpcEndpointId,
143 };
144 const baseline = yield* SDK.getOrganizationVPCEndpointDetails(request);
145 const application = (label: string, takeOwnership = false) =>
146 OrganizationVPCEndpoint("Network", { ...scope, label }).pipe(adopt(takeOwnership));
147 expect(
148 Result.isFailure(
149 yield* stack.plan(application("Alchemy governance fixture")).pipe(Effect.result),
150 ),
151 ).toBe(true);
152 const adopted = yield* stack.deploy(application("Alchemy governance fixture", true));
153 expect(adopted.initialLabel).toBe(baseline.label);
154 expect((yield* SDK.getOrganizationVPCEndpointDetails(request)).label).toBe(
155 "Alchemy governance fixture",
156 );
157 yield* stack.deploy(application("Alchemy governance updated"));
158 yield* SDK.assignOrganizationVPCEndpoint({ ...request, label: "External fixture label" });
159 expect(Result.isFailure(yield* stack.destroy().pipe(Effect.result))).toBe(true);
160 expect((yield* SDK.getOrganizationVPCEndpointDetails(request)).label).toBe(
161 "External fixture label",
162 );
163 yield* SDK.assignOrganizationVPCEndpoint({ ...request, label: "Alchemy governance updated" });
164 yield* stack.destroy();
165 const restored = yield* SDK.getOrganizationVPCEndpointDetails(request);
166 expect(restored.label).toBe(baseline.label);
167 expect(restored.vpc_endpoint_id).toBe(baseline.vpc_endpoint_id);
168 expect(restored.num_restricted_projects).toBe(baseline.num_restricted_projects);
169 yield* stack.destroy();
170 }),
171 {
172 tags: ["provider:neon", "provider:neon:organizationvpcendpoint", "live"],
173 timeout: 120_000,
174 exclusive: "neon:governance",
175 },
176 );
177
178 test.provider.skipIf(!enabled || !disposable)(
179 "explicit disposable endpoint registration is removed from Neon",
180 (stack) =>
181 Effect.gen(function* () {
182 yield* stack.destroy();
183 const scope = { orgId: orgId!, regionId: regionId!, vpcEndpointId: vpcEndpointId! };
184 const request = {
185 org_id: scope.orgId,
186 region_id: scope.regionId,
187 vpc_endpoint_id: scope.vpcEndpointId,
188 };
189 const list = yield* SDK.listOrganizationVPCEndpoints(request);
190 expect(
191 list.endpoints.some((endpoint) => endpoint.vpc_endpoint_id === scope.vpcEndpointId),
192 ).toBe(false);
193 const created = yield* stack.deploy(
194 OrganizationVPCEndpoint("Network", { ...scope, label: "Alchemy disposable fixture" }),
195 );
196 expect(created.initialLabel).toBeNull();
197 expect((yield* SDK.getOrganizationVPCEndpointDetails(request)).label).toBe(
198 "Alchemy disposable fixture",
199 );
200 yield* stack.destroy();
201 expect(
202 (yield* SDK.listOrganizationVPCEndpoints(request)).endpoints.some(
203 (endpoint) => endpoint.vpc_endpoint_id === scope.vpcEndpointId,
204 ),
205 ).toBe(false);
206 yield* stack.destroy();
207 }),
208 {
209 tags: ["provider:neon", "provider:neon:organizationvpcendpoint", "live"],
210 timeout: 120_000,
211 exclusive: "neon:governance",
212 },
213 );