The best way to control Claude Code, Codex and more from any computer or phone

main
ts 81 lines 2.8 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 serviceusage from "@distilled.cloud/gcp/serviceusage_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 // An API no other suite uses, so disabling it cannot break a concurrent test.
15 const THROWAWAY_API = "kgsearch.googleapis.com";
16
17 const stateOf = (project: string, service: string) =>
18 serviceusage
19 .getServices({ name: `projects/${project}/services/${service}` })
20 .pipe(Effect.map((current) => current.state));
21
22 const waitUntilDisabled = (project: string, service: string) =>
23 stateOf(project, service).pipe(
24 Effect.repeat({
25 schedule: Schedule.spaced("2 seconds"),
26 until: (state) => state === "DISABLED",
27 times: 10,
28 }),
29 );
30
31 test.provider(
32 "adopts an enabled API and leaves it enabled on destroy",
33 (stack) =>
34 Effect.gen(function* () {
35 const { project } = yield* GcpEnvironment.current;
36 yield* stack.destroy();
37
38 const enabled = yield* stack.deploy(
39 GCP.ServiceUsage.ProjectService("ServiceUsageApi", {
40 service: "serviceusage.googleapis.com",
41 }),
42 );
43
44 expect(enabled.project).toEqual(project);
45 expect(enabled.service).toEqual("serviceusage.googleapis.com");
46 expect(enabled.state).toEqual("ENABLED");
47 expect(enabled.disableOnDestroy).toEqual(false);
48 expect(yield* stateOf(project, enabled.service)).toEqual("ENABLED");
49
50 yield* stack.destroy();
51
52 expect(yield* stateOf(project, enabled.service)).toEqual("ENABLED");
53 }).pipe(logLevel),
54 { tags: ["provider:gcp", "provider:gcp:serviceusage", "live"], timeout: 120_000 },
55 );
56
57 test.provider(
58 "enables an API and disables it on destroy",
59 (stack) =>
60 Effect.gen(function* () {
61 const { project } = yield* GcpEnvironment.current;
62 yield* stack.destroy();
63
64 const enabled = yield* stack.deploy(
65 GCP.ServiceUsage.ProjectService("ThrowawayApi", {
66 service: THROWAWAY_API,
67 disableOnDestroy: true,
68 }),
69 );
70
71 expect(enabled.service).toEqual(THROWAWAY_API);
72 expect(enabled.state).toEqual("ENABLED");
73 expect(enabled.disableOnDestroy).toEqual(true);
74 expect(yield* stateOf(project, THROWAWAY_API)).toEqual("ENABLED");
75
76 yield* stack.destroy();
77
78 expect(yield* waitUntilDisabled(project, THROWAWAY_API)).toEqual("DISABLED");
79 }).pipe(logLevel),
80 { tags: ["provider:gcp", "provider:gcp:serviceusage", "live"], timeout: 120_000 },
81 );