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

main
ts 109 lines 3.87 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 containeranalysis from "@distilled.cloud/gcp/containeranalysis_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { logLevel, currentProject, TEST_ATTESTATION, TEST_RESOURCE_URI } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 containeranalysis.getProjectsOccurrences({ 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 "getProjectsOccurrences on a missing occurrence 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 containeranalysis.getProjectsOccurrences({
31 name: `projects/${project}/occurrences/alchemy-missing-occurrence`,
32 }),
33 );
34 expect(error._tag).toEqual("NotFound");
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 {
39 tags: ["provider:gcp", "provider:gcp:containeranalysis", "live"],
40 timeout: 90_000,
41 },
42 );
43
44 test.provider(
45 "create, update, and delete an occurrence",
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: "occurrence attestor",
54 attestation: { hint: { humanReadableName: "Alchemy QA" } },
55 });
56 const occurrence = yield* GCP.ContainerAnalysis.Occurrence("Signed", {
57 noteName: note.name,
58 resourceUri: TEST_RESOURCE_URI,
59 remediation: "initial",
60 attestation: TEST_ATTESTATION,
61 });
62 return { note, occurrence };
63 }),
64 );
65
66 expect(created.occurrence.name).toContain("/occurrences/");
67 expect(created.occurrence.noteName).toEqual(created.note.name);
68 expect(created.occurrence.resourceUri).toEqual(TEST_RESOURCE_URI);
69 expect(created.occurrence.remediation).toEqual("initial");
70 expect(created.occurrence.kind).toEqual("ATTESTATION");
71
72 const fetched = yield* containeranalysis.getProjectsOccurrences({
73 name: created.occurrence.name,
74 });
75 expect(fetched.name).toEqual(created.occurrence.name);
76 expect(fetched.noteName).toEqual(created.note.name);
77 expect(fetched.resourceUri).toEqual(TEST_RESOURCE_URI);
78 expect(fetched.remediation).toContain("[alchemy ");
79 expect(fetched.kind).toEqual("ATTESTATION");
80
81 const updated = yield* stack.deploy(
82 Effect.gen(function* () {
83 const note = yield* GCP.ContainerAnalysis.Note("Authority", {
84 noteId: created.note.noteId,
85 shortDescription: "occurrence attestor",
86 attestation: { hint: { humanReadableName: "Alchemy QA" } },
87 });
88 const occurrence = yield* GCP.ContainerAnalysis.Occurrence("Signed", {
89 noteName: note.name,
90 resourceUri: TEST_RESOURCE_URI,
91 remediation: "rebuild from a patched base",
92 attestation: TEST_ATTESTATION,
93 });
94 return { note, occurrence };
95 }),
96 );
97
98 expect(updated.occurrence.name).toEqual(created.occurrence.name);
99 expect(updated.occurrence.remediation).toEqual("rebuild from a patched base");
100
101 yield* stack.destroy();
102 const gone = yield* waitUntilGone(created.occurrence.name);
103 expect(gone).toEqual("gone");
104 }).pipe(logLevel),
105 {
106 tags: ["provider:gcp", "provider:gcp:containeranalysis", "live"],
107 timeout: 90_000,
108 },
109 );