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

main
ts 144 lines 4.65 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as firebaseapphosting from "@distilled.cloud/gcp/firebaseapphosting_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import {
8 location,
9 logLevel,
10 missingBackendOf,
11 currentProject,
12 serviceAccountOf,
13 } from "./common.ts";
14
15 const { test } = Test.make({ providers: GCP.providers() });
16
17 const helloImage = "us-docker.pkg.dev/cloudrun/container/hello";
18
19 const waitUntilGone = (name: string) =>
20 firebaseapphosting.getProjectsLocationsBackendsBuilds({ name }).pipe(
21 Effect.as("found" as const),
22 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
23 Effect.repeat({
24 schedule: Schedule.spaced("3 seconds"),
25 until: (status) => status === "gone",
26 times: 10,
27 }),
28 );
29
30 test.provider(
31 "getProjectsLocationsBackendsBuilds on a missing build fails with a typed tag",
32 (stack) =>
33 Effect.gen(function* () {
34 const project = yield* currentProject;
35 const missingBackend = missingBackendOf(project);
36
37 yield* stack.destroy();
38
39 const error = yield* Effect.flip(
40 firebaseapphosting.getProjectsLocationsBackendsBuilds({
41 name: `${missingBackend()}/builds/alchemy-missing-build`,
42 }),
43 );
44 expect(error._tag).toEqual("NotFound");
45
46 const page = yield* firebaseapphosting.listProjectsLocationsBackendsBuilds({
47 parent: `projects/${project}/locations/-/backends/-`,
48 pageSize: 10,
49 });
50 expect((page.builds ?? []).map((item) => item.name)).not.toContain(
51 `${missingBackend()}/builds/alchemy-missing-build`,
52 );
53
54 yield* stack.destroy();
55 }).pipe(logLevel),
56 {
57 tags: ["provider:gcp", "provider:gcp:firebaseapphosting", "live"],
58 timeout: 90_000,
59 },
60 );
61
62 test.provider(
63 "create against a missing backend is rejected with a typed tag",
64 (stack) =>
65 Effect.gen(function* () {
66 const project = yield* currentProject;
67 const missingBackend = missingBackendOf(project);
68
69 yield* stack.destroy();
70
71 const error = yield* Effect.flip(
72 stack.deploy(
73 Effect.gen(function* () {
74 return yield* GCP.FirebaseAppHosting.BackendsBuild("Hello", {
75 backend: missingBackend(),
76 source: { container: { image: helloImage } },
77 labels: { env: "test" },
78 });
79 }),
80 ),
81 );
82 expect(error._tag).toEqual("NotFound");
83
84 yield* stack.destroy();
85 }).pipe(logLevel),
86 {
87 tags: ["provider:gcp", "provider:gcp:firebaseapphosting", "live"],
88 timeout: 90_000,
89 },
90 );
91
92 // A build reaches READY in about a minute, but its delete LRO was still
93 // `done: false` after 14 minutes, so the test cannot clean up. Set
94 // GCP_TEST_FIREBASE_APP_HOSTING_BUILD=1 to run it anyway.
95 test.provider.skipIf(!process.env.GCP_TEST_FIREBASE_APP_HOSTING_BUILD)(
96 "create, verify, and delete a backend build",
97 (stack) =>
98 Effect.gen(function* () {
99 const project = yield* currentProject;
100 const serviceAccount = serviceAccountOf(project);
101
102 yield* stack.destroy();
103
104 const created = yield* stack.deploy(
105 Effect.gen(function* () {
106 const backend = yield* GCP.FirebaseAppHosting.Backend("Web", {
107 serviceAccount,
108 servingLocality: "GLOBAL_ACCESS",
109 displayName: "alchemy-test-build-backend",
110 labels: { env: "test" },
111 });
112 const build = yield* GCP.FirebaseAppHosting.BackendsBuild("Hello", {
113 backend: backend.name,
114 source: { container: { image: helloImage } },
115 displayName: "alchemy-test-build",
116 labels: { env: "test" },
117 });
118 return { backend, build };
119 }),
120 );
121
122 expect(created.build.name).toContain("/builds/");
123 expect(created.build.backend).toEqual(created.backend.name);
124 expect(created.build.location).toEqual(location);
125 expect(created.build.source?.container?.image).toEqual(helloImage);
126 expect(created.build.labels).toMatchObject({ env: "test" });
127
128 const fetched = yield* firebaseapphosting.getProjectsLocationsBackendsBuilds({
129 name: created.build.name,
130 });
131 expect(fetched.name).toEqual(created.build.name);
132 expect(fetched.source?.container?.image).toEqual(helloImage);
133 expect(fetched.labels?.env).toEqual("test");
134
135 yield* stack.destroy();
136
137 const gone = yield* waitUntilGone(created.build.name);
138 expect(gone).toEqual("gone");
139 }).pipe(logLevel),
140 {
141 tags: ["provider:gcp", "provider:gcp:firebaseapphosting", "live"],
142 timeout: 900_000,
143 },
144 );