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

main
ts 102 lines 3.96 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 compute from "@distilled.cloud/gcp/compute_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9 import { CERT_A_PEM, CERT_B_PEM, KEY_A_PEM, KEY_B_PEM } from "./fixtures/https-proxy-cert.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 waitUntilGone = (sslCertificateName: string) =>
16 GcpEnvironment.current.pipe(
17 Effect.flatMap(({ project }) =>
18 compute.getSslCertificates({ project, sslCertificate: sslCertificateName }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("1 second"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 ),
27 ),
28 );
29
30 test.provider(
31 "create, replace, and delete an ssl certificate",
32 (stack) =>
33 Effect.gen(function* () {
34 const { project } = yield* GcpEnvironment.current;
35 yield* stack.destroy();
36
37 const created = yield* stack.deploy(
38 Effect.gen(function* () {
39 return yield* GCP.Compute.SslCertificate("FrontendTls", {
40 description: "frontend tls a",
41 certificate: CERT_A_PEM,
42 privateKey: KEY_A_PEM,
43 });
44 }),
45 );
46
47 expect(created.sslCertificateName).toEqual(expect.any(String));
48 expect(created.type).toEqual("SELF_MANAGED");
49 expect(created.description).toEqual("frontend tls a");
50 expect(created.certificate).toContain("MIIDIDCCAgigAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWMw");
51 expect(created.expireTime).toEqual(expect.any(String));
52 expect(created.selfLink).toEqual(expect.any(String));
53
54 const fetched = yield* compute.getSslCertificates({
55 project,
56 sslCertificate: created.sslCertificateName,
57 });
58 expect(fetched.name).toEqual(created.sslCertificateName);
59 expect(fetched.type).toEqual("SELF_MANAGED");
60 expect(fetched.description).toContain("[alchemy ");
61 expect(fetched.description).toContain("frontend tls a");
62 expect(fetched.certificate).toContain("BEGIN CERTIFICATE");
63 expect(fetched.certificate).toContain("MIIDIDCCAgigAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWMw");
64
65 const listed = yield* compute.listSslCertificates({
66 project,
67 maxResults: 500,
68 });
69 expect((listed.items ?? []).some((cert) => cert.name === created.sslCertificateName)).toEqual(
70 true,
71 );
72
73 const updated = yield* stack.deploy(
74 Effect.gen(function* () {
75 return yield* GCP.Compute.SslCertificate("FrontendTls", {
76 sslCertificateName: created.sslCertificateName,
77 description: "frontend tls b",
78 certificate: CERT_B_PEM,
79 privateKey: KEY_B_PEM,
80 });
81 }),
82 );
83
84 expect(updated.sslCertificateName).toEqual(created.sslCertificateName);
85 expect(updated.description).toEqual("frontend tls b");
86 expect(updated.certificate).toContain("MIIDITCCAgmgAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWQw");
87 expect(updated.certificate).not.toContain("MIIDIDCCAgigAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWMw");
88
89 const refetched = yield* compute.getSslCertificates({
90 project,
91 sslCertificate: updated.sslCertificateName,
92 });
93 expect(refetched.description).toContain("frontend tls b");
94 expect(refetched.certificate).toContain("MIIDITCCAgmgAwIBAgIUD2oKsfjRQWSWaAiVXJCmak8GeWQw");
95
96 yield* stack.destroy();
97
98 const gone = yield* waitUntilGone(created.sslCertificateName);
99 expect(gone).toEqual("gone");
100 }).pipe(logLevel),
101 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
102 );