@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 154 lines 5.35 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 appengine from "@distilled.cloud/gcp/appengine_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { isServiceEnabled } from "../ServiceState.ts";
10
11 const { test } = Test.make({ providers: GCP.providers() });
12
13 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
14
15 // Needs an App Engine application in the project, which is permanent once
16 // created (it can never be deleted). The testing project has none and the
17 // App Engine Admin API is off (ServiceDisabled: "App Engine Admin API has not been
18 // used in project ... or it is disabled."). Set GCP_TEST_APPENGINE_APP=1 on a
19 // project with an app to run the lifecycle.
20 const runLifecycle = !!process.env.GCP_TEST_APPENGINE_APP;
21
22 const location = "us-central";
23 const domain = process.env.GCP_TEST_APPENGINE_DOMAIN ?? "alchemy-appengine.test";
24
25 const waitUntilGone = (
26 projectsId: string,
27 locationsId: string,
28 applicationsId: string,
29 domainId: string,
30 ) =>
31 appengine
32 .getProjectsLocationsApplicationsDomainMappings({
33 projectsId,
34 locationsId,
35 applicationsId,
36 domainMappingsId: domainId,
37 })
38 .pipe(
39 Effect.as("found" as const),
40 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
41 Effect.repeat({
42 schedule: Schedule.spaced("1 second"),
43 until: (status) => status === "gone",
44 times: 10,
45 }),
46 );
47
48 test.provider(
49 "getProjectsLocationsApplicationsDomainMappings on a missing mapping fails with a typed tag",
50 (stack) =>
51 Effect.gen(function* () {
52 // With the API enabled, this project (no App Engine app / no Firebase
53 // setup) answers an untyped INTERNAL / INVALID_ARGUMENT: the probe only
54 // holds while the API is disabled.
55 if (yield* isServiceEnabled("appengine.googleapis.com")) return;
56 const { project } = yield* GcpEnvironment.current;
57 yield* stack.destroy();
58
59 const error = yield* Effect.flip(
60 appengine.getProjectsLocationsApplicationsDomainMappings({
61 projectsId: project,
62 locationsId: location,
63 applicationsId: project,
64 domainMappingsId: "alchemy-missing.example.com",
65 }),
66 );
67 expect(error._tag).toEqual("ServiceDisabled");
68
69 yield* stack.destroy();
70 }).pipe(logLevel),
71 { tags: ["provider:gcp", "provider:gcp:appengine", "live"], timeout: 90_000 },
72 );
73
74 test.provider.skipIf(runLifecycle)(
75 "createProjectsLocationsApplicationsDomainMappings without an App Engine app fails with a typed tag",
76 (stack) =>
77 Effect.gen(function* () {
78 // With the API enabled, this project (no App Engine app / no Firebase
79 // setup) answers an untyped INTERNAL / INVALID_ARGUMENT: the probe only
80 // holds while the API is disabled.
81 if (yield* isServiceEnabled("appengine.googleapis.com")) return;
82 const { project } = yield* GcpEnvironment.current;
83 yield* stack.destroy();
84
85 const error = yield* Effect.flip(
86 appengine.createProjectsLocationsApplicationsDomainMappings({
87 projectsId: project,
88 locationsId: location,
89 applicationsId: project,
90 body: {
91 id: "alchemy-missing.example.com",
92 sslSettings: { sslManagementType: "AUTOMATIC" },
93 },
94 }),
95 );
96 expect(error._tag).toEqual("ServiceDisabled");
97
98 yield* stack.destroy();
99 }).pipe(logLevel),
100 { tags: ["provider:gcp", "provider:gcp:appengine", "live"], timeout: 90_000 },
101 );
102
103 test.provider.skipIf(!runLifecycle)(
104 "create, update, and delete an applications domain mapping",
105 (stack) =>
106 Effect.gen(function* () {
107 const { project } = yield* GcpEnvironment.current;
108 yield* stack.destroy();
109
110 const created = yield* stack.deploy(
111 Effect.gen(function* () {
112 return yield* GCP.AppEngine.ApplicationsDomainMapping("Www", {
113 domain,
114 sslSettings: { sslManagementType: "AUTOMATIC" },
115 });
116 }),
117 );
118
119 expect(created.domain).toEqual(domain);
120 expect(created.applicationsId).toEqual(project);
121
122 const fetched = yield* appengine.getProjectsLocationsApplicationsDomainMappings({
123 projectsId: created.project,
124 locationsId: created.location,
125 applicationsId: created.applicationsId,
126 domainMappingsId: created.domain,
127 });
128 expect(fetched.id).toEqual(created.domain);
129
130 const updated = yield* stack.deploy(
131 Effect.gen(function* () {
132 return yield* GCP.AppEngine.ApplicationsDomainMapping("Www", {
133 domain: created.domain,
134 location: created.location,
135 sslSettings: { sslManagementType: "MANUAL" },
136 });
137 }),
138 );
139
140 expect(updated.domain).toEqual(created.domain);
141 expect(updated.sslManagementType).toEqual("MANUAL");
142
143 yield* stack.destroy();
144
145 const gone = yield* waitUntilGone(
146 created.project,
147 created.location,
148 created.applicationsId,
149 created.domain,
150 );
151 expect(gone).toEqual("gone");
152 }).pipe(logLevel),
153 { tags: ["provider:gcp", "provider:gcp:appengine", "live"], timeout: 90_000 },
154 );