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

main
ts 93 lines 3.15 KB
Raw
1 import { expect } from "@alchemy.run/test";
2 import * as artifactregistry from "@distilled.cloud/gcp/artifactregistry_v1";
3 import * as cloudrun from "@distilled.cloud/gcp/run_v2";
4 import * as Effect from "effect/Effect";
5 import { MinimumLogLevel } from "effect/References";
6 import * as Schedule from "effect/Schedule";
7 import * as pathe from "pathe";
8
9 /**
10 * Shared helpers for the `GCP.Website.*` live tests. Each test deploys a
11 * framework fixture (reused from `test/AWS/Website/fixtures` or the
12 * Cloudflare website fixtures), GETs the Cloud Run URL, then destroys and
13 * verifies out-of-band that the service and its image repository are gone.
14 */
15
16 export const logLevel = Effect.provideService(
17 MinimumLogLevel,
18 process.env.DEBUG ? "Debug" : "Info",
19 );
20
21 export const tempRoot = pathe.resolve(import.meta.dirname, "../../../.tmp");
22
23 export const awsFixture = (name: string) =>
24 pathe.resolve(import.meta.dirname, "../../AWS/Website/fixtures", name);
25
26 export const cloudflareFixture = (name: string) =>
27 pathe.resolve(import.meta.dirname, "../../Cloudflare/Website", name);
28
29 /** Live-test options: image build + push + Cloud Run rollout + destroy. */
30 export const liveOptions = (timeout = 900_000) => ({
31 timeout,
32 retry: 0,
33 tags: ["provider:gcp", "provider:gcp:website", "live"],
34 });
35
36 /** The deployed service identity a test needs to verify teardown. */
37 export interface DeployedService {
38 readonly name: string;
39 readonly serviceId: string;
40 readonly project: string;
41 readonly location: string;
42 }
43
44 export const cloudRunUrl = /^https:\/\/[a-z0-9-]+.*\.run\.app\/?$/;
45
46 const serviceStatus = (name: string) =>
47 cloudrun.getProjectsLocationsServices({ name }).pipe(
48 Effect.as("found" as const),
49 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
50 );
51
52 const repositoryStatus = (name: string) =>
53 artifactregistry.getProjectsLocationsRepositories({ name }).pipe(
54 Effect.as("found" as const),
55 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
56 );
57
58 /** Out-of-band: the Cloud Run service and its `{serviceId}-src` image repository are gone. */
59 export const assertSiteGone = (service: DeployedService) =>
60 Effect.gen(function* () {
61 const service_ = yield* serviceStatus(service.name).pipe(
62 Effect.repeat({
63 schedule: Schedule.spaced("2 seconds"),
64 until: (status) => status === "gone",
65 times: 15,
66 }),
67 );
68 expect(service_).toEqual("gone");
69 const repositoryId = `${service.serviceId}-src`.slice(0, 49).replace(/-+$/g, "");
70 const repository = yield* repositoryStatus(
71 `projects/${service.project}/locations/${service.location}/repositories/${repositoryId}`,
72 ).pipe(
73 Effect.repeat({
74 schedule: Schedule.spaced("2 seconds"),
75 until: (status) => status === "gone",
76 times: 15,
77 }),
78 );
79 expect(repository).toEqual("gone");
80 });
81
82 /** Project the deployed `GCP.Run.Service` attributes a test verifies. */
83 export const serviceIdentity = (service: {
84 name: string;
85 serviceId: string;
86 project: string;
87 location: string;
88 }): DeployedService => ({
89 name: service.name,
90 serviceId: service.serviceId,
91 project: service.project,
92 location: service.location,
93 });