@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 101 lines 3.65 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as apim from "@distilled.cloud/gcp/apim_v1alpha";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { DEFAULT_NETWORK } from "../networkQuota.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 // The API Management API is not enabled in the testing project: every call
16 // answers 403 SERVICE_DISABLED (typed `ServiceDisabled`). Set GCP_TEST_APIM=1
17 // on a project with the API enabled to run the lifecycle.
18 const apimEnabled = !!process.env.GCP_TEST_APIM;
19 const runLifecycle = !process.env.FAST && apimEnabled;
20 const location = "us-central1";
21
22 const waitUntilGone = (name: string) =>
23 apim.getProjectsLocationsObservationSources({ name }).pipe(
24 Effect.as("found" as const),
25 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
26 Effect.repeat({
27 schedule: Schedule.spaced("2 seconds"),
28 until: (status) => status === "gone",
29 times: 10,
30 }),
31 );
32
33 test.provider(
34 "getProjectsLocationsObservationSources on a missing source fails with ServiceDisabled while the API is disabled",
35 (stack) =>
36 Effect.gen(function* () {
37 const { project } = yield* GcpEnvironment.current;
38 const parent = `projects/${project}/locations/${location}`;
39
40 yield* stack.destroy();
41
42 const error = yield* Effect.flip(
43 apim.getProjectsLocationsObservationSources({
44 name: `${parent}/observationSources/alchemy-missing-src`,
45 }),
46 );
47 expect(["ServiceDisabled", "NotFound"]).toContain(error._tag);
48
49 yield* stack.destroy();
50 }).pipe(logLevel),
51 { tags: ["provider:gcp", "provider:gcp:apim", "live"], timeout: 90_000 },
52 );
53
54 test.provider.skipIf(!runLifecycle)(
55 "create and delete an API Observation source",
56 (stack) =>
57 Effect.gen(function* () {
58 const { project } = yield* GcpEnvironment.current;
59 const parent = `projects/${project}/locations/${location}`;
60
61 yield* stack.destroy();
62
63 const created = yield* stack.deploy(
64 Effect.gen(function* () {
65 const subnet = yield* GCP.Compute.Subnetwork("ApimSrcSubnet", {
66 network: DEFAULT_NETWORK,
67 region: location,
68 ipCidrRange: "172.20.12.0/24",
69 privateIpGoogleAccess: true,
70 });
71 const source = yield* GCP.Apim.ObservationSource("Edge", {
72 location,
73 gclbObservationSource: {
74 pscNetworkConfigs: [
75 {
76 network: DEFAULT_NETWORK,
77 subnetwork: subnet.subnetworkName,
78 },
79 ],
80 },
81 });
82 return { subnet, source };
83 }),
84 );
85
86 expect(created.source.name).toContain("/observationSources/");
87 expect(created.source.observationSourceId).toEqual(expect.any(String));
88 expect(created.source.location).toEqual(location);
89 expect(created.source.gclbObservationSource?.pscNetworkConfigs.length).toBeGreaterThan(0);
90
91 const fetched = yield* apim.getProjectsLocationsObservationSources({
92 name: created.source.name,
93 });
94 expect(fetched.name).toEqual(created.source.name);
95
96 yield* stack.destroy();
97 const gone = yield* waitUntilGone(created.source.name);
98 expect(gone).toEqual("gone");
99 }).pipe(logLevel),
100 { tags: ["provider:gcp", "provider:gcp:apim", "live"], timeout: 120_000 },
101 );