@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 135 lines 4.45 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 firebaseappdistribution from "@distilled.cloud/gcp/firebaseappdistribution_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 const currentParent = GcpEnvironment.current.pipe(
16 Effect.map(({ project }) => `projects/${project}`),
17 );
18 // The Firebase App Distribution API is not enabled in the testing project.
19 // Set GCP_TEST_FIREBASE_APP_DISTRIBUTION=1 on a project where it is.
20 const entitled = !!process.env.GCP_TEST_FIREBASE_APP_DISTRIBUTION;
21
22 const waitUntilGone = (name: string) =>
23 firebaseappdistribution.getProjectsGroups({ name }).pipe(
24 Effect.as("found" as const),
25 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
26 Effect.repeat({
27 schedule: Schedule.spaced("1 second"),
28 until: (status) => status === "gone",
29 times: 10,
30 }),
31 );
32
33 test.provider.skipIf(!entitled)(
34 "getProjectsGroups on a missing group fails with a typed tag",
35 (stack) =>
36 Effect.gen(function* () {
37 const parent = yield* currentParent;
38 yield* stack.destroy();
39
40 const error = yield* Effect.flip(
41 firebaseappdistribution.getProjectsGroups({
42 name: `${parent}/groups/alchemy-missing`,
43 }),
44 );
45 expect(error._tag).toEqual("NotFound");
46
47 yield* stack.destroy();
48 }).pipe(logLevel),
49 {
50 tags: ["provider:gcp", "provider:gcp:firebaseappdistribution", "live"],
51 timeout: 90_000,
52 },
53 );
54
55 test.provider.skipIf(entitled)(
56 "getProjectsGroups fails with ServiceDisabled while the API is disabled",
57 (stack) =>
58 Effect.gen(function* () {
59 // With the API enabled, this project (no App Engine app / no Firebase
60 // setup) answers an untyped INTERNAL / INVALID_ARGUMENT: the probe only
61 // holds while the API is disabled.
62 if (yield* isServiceEnabled("firebaseappdistribution.googleapis.com")) return;
63 const parent = yield* currentParent;
64 yield* stack.destroy();
65
66 const error = yield* Effect.flip(
67 firebaseappdistribution.getProjectsGroups({
68 name: `${parent}/groups/alchemy-missing`,
69 }),
70 );
71 expect(error._tag).toEqual("ServiceDisabled");
72
73 yield* stack.destroy();
74 }).pipe(logLevel),
75 {
76 tags: ["provider:gcp", "provider:gcp:firebaseappdistribution", "live"],
77 timeout: 90_000,
78 },
79 );
80
81 test.provider.skipIf(!entitled)(
82 "create, update, and delete a tester group",
83 (stack) =>
84 Effect.gen(function* () {
85 yield* stack.destroy();
86
87 const created = yield* stack.deploy(
88 Effect.gen(function* () {
89 return yield* GCP.FirebaseAppDistribution.Group("Qa", {
90 displayName: "qa",
91 });
92 }),
93 );
94
95 expect(created.name).toContain("/groups/");
96 expect(created.groupId).toEqual(expect.any(String));
97 expect(created.groupId.length).toBeGreaterThanOrEqual(4);
98 expect(created.project).toEqual(expect.any(String));
99 expect(created.displayName).toEqual("qa");
100
101 const fetched = yield* firebaseappdistribution.getProjectsGroups({
102 name: created.name,
103 });
104 expect(fetched.name).toEqual(created.name);
105 // The display name is shown to testers: no ownership marker.
106 expect(fetched.displayName).toEqual("qa");
107
108 const updated = yield* stack.deploy(
109 Effect.gen(function* () {
110 return yield* GCP.FirebaseAppDistribution.Group("Qa", {
111 groupId: created.groupId,
112 displayName: "qa-prod",
113 });
114 }),
115 );
116
117 expect(updated.name).toEqual(created.name);
118 expect(updated.groupId).toEqual(created.groupId);
119 expect(updated.displayName).toEqual("qa-prod");
120
121 const refetched = yield* firebaseappdistribution.getProjectsGroups({
122 name: created.name,
123 });
124 expect(refetched.displayName).toEqual("qa-prod");
125
126 yield* stack.destroy();
127
128 const gone = yield* waitUntilGone(created.name);
129 expect(gone).toEqual("gone");
130 }).pipe(logLevel),
131 {
132 tags: ["provider:gcp", "provider:gcp:firebaseappdistribution", "live"],
133 timeout: 90_000,
134 },
135 );