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

main
ts 98 lines 3.58 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 recaptchaenterprise from "@distilled.cloud/gcp/recaptchaenterprise_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (name: string) =>
14 recaptchaenterprise.getProjectsKeys({ name }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider(
25 "create, update, and delete a reCAPTCHA key",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 return yield* GCP.RecaptchaEnterprise.Key("Signup", {
33 displayName: "alchemy recaptcha signup",
34 labels: { env: "test" },
35 testingOptions: { testingScore: 0.9 },
36 webSettings: {
37 integrationType: "SCORE",
38 allowAllDomains: true,
39 },
40 });
41 }),
42 );
43
44 expect(created.name).toContain("/keys/");
45 expect(created.keyId).toEqual(expect.any(String));
46 expect(created.displayName).toEqual("alchemy recaptcha signup");
47 expect(created.labels).toMatchObject({ env: "test" });
48 expect(created.webSettings?.integrationType).toEqual("SCORE");
49 expect(created.testingOptions?.testingScore).toEqual(0.9);
50
51 const fetched = yield* recaptchaenterprise.getProjectsKeys({
52 name: created.name,
53 });
54 expect(fetched.name).toEqual(created.name);
55 expect(fetched.displayName).toEqual("alchemy recaptcha signup");
56 expect(fetched.labels?.env).toEqual("test");
57 expect(fetched.labels?.["alchemy-id"]).toEqual(expect.any(String));
58 expect(fetched.webSettings?.integrationType).toEqual("SCORE");
59
60 const updated = yield* stack.deploy(
61 Effect.gen(function* () {
62 return yield* GCP.RecaptchaEnterprise.Key("Signup", {
63 keyId: created.keyId,
64 displayName: "alchemy recaptcha signup v2",
65 labels: { env: "prod", role: "bot" },
66 testingOptions: { testingScore: 0.9 },
67 webSettings: {
68 integrationType: "SCORE",
69 allowAllDomains: true,
70 },
71 });
72 }),
73 );
74
75 expect(updated.name).toEqual(created.name);
76 expect(updated.keyId).toEqual(created.keyId);
77 expect(updated.displayName).toEqual("alchemy recaptcha signup v2");
78 expect(updated.labels).toMatchObject({ env: "prod", role: "bot" });
79 expect(updated.testingOptions?.testingScore).toEqual(0.9);
80
81 const fetchedUpdate = yield* recaptchaenterprise.getProjectsKeys({
82 name: created.name,
83 });
84 expect(fetchedUpdate.displayName).toEqual("alchemy recaptcha signup v2");
85 expect(fetchedUpdate.labels?.env).toEqual("prod");
86 expect(fetchedUpdate.labels?.role).toEqual("bot");
87 expect(fetchedUpdate.labels?.["alchemy-id"]).toEqual(expect.any(String));
88
89 yield* stack.destroy();
90
91 const gone = yield* waitUntilGone(created.name);
92 expect(gone).toEqual("gone");
93 }).pipe(logLevel),
94 {
95 tags: ["provider:gcp", "provider:gcp:recaptchaenterprise", "live"],
96 timeout: 90_000,
97 },
98 );