@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 147 lines 4.7 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
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 // Needs an App Engine application in the project, which is permanent once
15 // created (it can never be deleted). The testing project has none and the
16 // App Engine Admin API is off (ServiceDisabled: "App Engine Admin API has not been
17 // used in project ... or it is disabled."). Set GCP_TEST_APPENGINE_APP=1 on a
18 // project with an app to run the lifecycle.
19 const runLifecycle = !!process.env.GCP_TEST_APPENGINE_APP;
20
21 const sourceUrl = process.env.GCP_TEST_APPENGINE_SOURCE_URL ?? "";
22
23 const waitUntilGone = (appsId: string, servicesId: string, versionsId: string) =>
24 appengine
25 .getAppsServicesVersions({
26 appsId,
27 servicesId,
28 versionsId,
29 })
30 .pipe(
31 Effect.as("found" as const),
32 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
33 Effect.repeat({
34 schedule: Schedule.spaced("1 second"),
35 until: (status) => status === "gone",
36 times: 10,
37 }),
38 );
39
40 test.provider(
41 "getAppsServicesVersions on a missing version fails with a typed tag",
42 (stack) =>
43 Effect.gen(function* () {
44 const { project } = yield* GcpEnvironment.current;
45 yield* stack.destroy();
46
47 const error = yield* Effect.flip(
48 appengine.getAppsServicesVersions({
49 appsId: project,
50 servicesId: "default",
51 versionsId: "alchemy-missing",
52 }),
53 );
54 expect(["ServiceDisabled", "NotFound"]).toContain(error._tag);
55
56 yield* stack.destroy();
57 }).pipe(logLevel),
58 { tags: ["provider:gcp", "provider:gcp:appengine", "live"], timeout: 90_000 },
59 );
60
61 test.provider.skipIf(runLifecycle)(
62 "createAppsServicesVersions without an App Engine app fails with a typed tag",
63 (stack) =>
64 Effect.gen(function* () {
65 const { project } = yield* GcpEnvironment.current;
66 yield* stack.destroy();
67
68 const error = yield* Effect.flip(
69 appengine.createAppsServicesVersions({
70 appsId: project,
71 servicesId: "default",
72 body: {
73 id: "alchemy-probe",
74 runtime: "python311",
75 },
76 }),
77 );
78 expect(["ServiceDisabled", "NotFound"]).toContain(error._tag);
79
80 yield* stack.destroy();
81 }).pipe(logLevel),
82 { tags: ["provider:gcp", "provider:gcp:appengine", "live"], timeout: 90_000 },
83 );
84
85 test.provider.skipIf(!runLifecycle || sourceUrl.length === 0)(
86 "create, update, and delete a service version",
87 (stack) =>
88 Effect.gen(function* () {
89 yield* stack.destroy();
90
91 const created = yield* stack.deploy(
92 Effect.gen(function* () {
93 return yield* GCP.AppEngine.AppsServicesVersion("Api", {
94 runtime: "python311",
95 servingStatus: "SERVING",
96 automaticScaling: {
97 standardSchedulerSettings: {
98 minInstances: 0,
99 maxInstances: 1,
100 },
101 },
102 deployment: {
103 zip: { sourceUrl },
104 },
105 });
106 }),
107 );
108
109 expect(created.versionId.length).toBeGreaterThan(0);
110 expect(created.runtime).toEqual("python311");
111 expect(created.serviceId).toEqual("default");
112
113 const fetched = yield* appengine.getAppsServicesVersions({
114 appsId: created.appsId,
115 servicesId: created.serviceId,
116 versionsId: created.versionId,
117 view: "FULL",
118 });
119 expect(fetched.id).toEqual(created.versionId);
120 expect(fetched.envVariables?.ALCHEMY_OWNERSHIP).toContain("[alchemy ");
121
122 const updated = yield* stack.deploy(
123 Effect.gen(function* () {
124 return yield* GCP.AppEngine.AppsServicesVersion("Api", {
125 versionId: created.versionId,
126 runtime: "python311",
127 servingStatus: "STOPPED",
128 deployment: {
129 zip: { sourceUrl },
130 },
131 });
132 }),
133 );
134
135 expect(updated.versionId).toEqual(created.versionId);
136 expect(updated.servingStatus).toEqual("STOPPED");
137
138 yield* stack.destroy();
139
140 const gone = yield* waitUntilGone(created.appsId, created.serviceId, created.versionId);
141 expect(gone).toEqual("gone");
142 }).pipe(logLevel),
143 {
144 tags: ["provider:gcp", "provider:gcp:appengine", "live"],
145 timeout: 120_000,
146 },
147 );