1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as containeranalysis from "@distilled.cloud/gcp/containeranalysis_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import * as Schedule from "effect/Schedule";
7import { location, logLevel, currentProject } from "./common.ts";
8
9const { test } = Test.make({ providers: GCP.providers() });
10
11const waitUntilGone = (name: string) =>
12 containeranalysis.getProjectsLocationsNotes({ 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
22test.provider(
23 "getProjectsLocationsNotes on a missing note 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.getProjectsLocationsNotes({
31 name: `projects/${project}/locations/${location}/notes/alchemy-missing-note`,
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
44test.provider(
45 "create, update, and delete a locations note",
46 (stack) =>
47 Effect.gen(function* () {
48 yield* stack.destroy();
49
50 const created = yield* stack.deploy(
51 Effect.gen(function* () {
52 return yield* GCP.ContainerAnalysis.LocationsNote("Authority", {
53 location,
54 shortDescription: "regional attestor",
55 longDescription: "initial",
56 attestation: { hint: { humanReadableName: "Alchemy Regional" } },
57 });
58 }),
59 );
60
61 expect(created.name).toContain(`/locations/${location}/notes/`);
62 expect(created.location).toEqual(location);
63 expect(created.shortDescription).toEqual("regional attestor");
64 expect(created.kind).toEqual("ATTESTATION");
65
66 const fetched = yield* containeranalysis.getProjectsLocationsNotes({
67 name: created.name,
68 });
69 expect(fetched.name).toEqual(created.name);
70 expect(fetched.longDescription).toContain("[alchemy ");
71 expect(fetched.kind).toEqual("ATTESTATION");
72
73 const updated = yield* stack.deploy(
74 Effect.gen(function* () {
75 return yield* GCP.ContainerAnalysis.LocationsNote("Authority", {
76 noteId: created.noteId,
77 location,
78 shortDescription: "regional attestor v2",
79 longDescription: "updated",
80 attestation: { hint: { humanReadableName: "Alchemy Regional" } },
81 });
82 }),
83 );
84
85 expect(updated.name).toEqual(created.name);
86 expect(updated.shortDescription).toEqual("regional attestor v2");
87 expect(updated.longDescription).toEqual("updated");
88
89 yield* stack.destroy();
90 const gone = yield* waitUntilGone(created.name);
91 expect(gone).toEqual("gone");
92 }).pipe(logLevel),
93 {
94 tags: ["provider:gcp", "provider:gcp:containeranalysis", "live"],
95 timeout: 90_000,
96 },
97);