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

main
ts 122 lines 4.32 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 binaryauthorization from "@distilled.cloud/gcp/binaryauthorization_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { logLevel, currentProject, TEST_PKIX_PUBLIC_KEY_PEM } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 binaryauthorization.getProjectsAttestors({ name }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.repeat({
16 schedule: Schedule.spaced("1 second"),
17 until: (status) => status === "gone",
18 times: 10,
19 }),
20 );
21
22 test.provider(
23 "getProjectsAttestors on a missing attestor fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 const project = yield* currentProject;
27 yield* stack.destroy();
28
29 const error = yield* Effect.flip(
30 binaryauthorization.getProjectsAttestors({
31 name: `projects/${project}/attestors/alchemy-missing-attestor`,
32 }),
33 );
34 expect(error._tag).toEqual("NotFound");
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 {
39 tags: ["provider:gcp", "provider:gcp:binaryauthorization", "live"],
40 timeout: 90_000,
41 },
42 );
43
44 test.provider(
45 "create, update, and delete an attestor",
46 (stack) =>
47 Effect.gen(function* () {
48 yield* stack.destroy();
49
50 const created = yield* stack.deploy(
51 Effect.gen(function* () {
52 const note = yield* GCP.ContainerAnalysis.Note("Authority", {
53 shortDescription: "alchemy binauthz attestor",
54 attestation: { hint: { humanReadableName: "Alchemy QA" } },
55 });
56 const attestor = yield* GCP.BinaryAuthorization.Attestor("Qa", {
57 noteReference: note.name,
58 description: "initial",
59 });
60 return { note, attestor };
61 }),
62 );
63
64 expect(created.attestor.name).toContain("/attestors/");
65 expect(created.attestor.attestorId).toEqual(expect.any(String));
66 expect(created.attestor.description).toEqual("initial");
67 expect(created.attestor.noteReference).toEqual(created.note.name);
68 expect(created.attestor.publicKeys).toEqual([]);
69
70 const fetched = yield* binaryauthorization.getProjectsAttestors({
71 name: created.attestor.name,
72 });
73 expect(fetched.name).toEqual(created.attestor.name);
74 expect(fetched.description).toContain("[alchemy ");
75 expect(fetched.description).toContain("initial");
76 expect(fetched.userOwnedGrafeasNote?.noteReference).toEqual(created.note.name);
77
78 const updated = yield* stack.deploy(
79 Effect.gen(function* () {
80 const note = yield* GCP.ContainerAnalysis.Note("Authority", {
81 noteId: created.note.noteId,
82 shortDescription: "alchemy binauthz attestor",
83 attestation: { hint: { humanReadableName: "Alchemy QA" } },
84 });
85 const attestor = yield* GCP.BinaryAuthorization.Attestor("Qa", {
86 attestorId: created.attestor.attestorId,
87 noteReference: note.name,
88 description: "updated",
89 publicKeys: [
90 {
91 comment: "ci",
92 pkixPublicKey: {
93 publicKeyPem: TEST_PKIX_PUBLIC_KEY_PEM,
94 signatureAlgorithm: "EC_SIGN_P256_SHA256",
95 },
96 },
97 ],
98 });
99 return { note, attestor };
100 }),
101 );
102
103 expect(updated.attestor.name).toEqual(created.attestor.name);
104 expect(updated.attestor.description).toEqual("updated");
105 expect(updated.attestor.publicKeys.length).toEqual(1);
106 expect(updated.attestor.publicKeys[0]?.comment).toEqual("ci");
107
108 const fetchedUpdate = yield* binaryauthorization.getProjectsAttestors({
109 name: updated.attestor.name,
110 });
111 expect(fetchedUpdate.description).toContain("updated");
112 expect(fetchedUpdate.userOwnedGrafeasNote?.publicKeys?.length).toEqual(1);
113
114 yield* stack.destroy();
115 const gone = yield* waitUntilGone(created.attestor.name);
116 expect(gone).toEqual("gone");
117 }).pipe(logLevel),
118 {
119 tags: ["provider:gcp", "provider:gcp:binaryauthorization", "live"],
120 timeout: 90_000,
121 },
122 );