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 { logLevel, currentProject } from "./common.ts";
8
9const { test } = Test.make({ providers: GCP.providers() });
10
11const waitUntilGone = (name: string) =>
12 containeranalysis.getProjectsNotes({ 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 "getProjectsNotes 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.getProjectsNotes({
31 name: `projects/${project}/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 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.Note("Authority", {
53 shortDescription: "alchemy test attestor",
54 longDescription: "initial",
55 relatedUrl: [
56 { url: "https://example.com/policy", label: "policy" },
57 ],
58 attestation: { hint: { humanReadableName: "Alchemy QA" } },
59 });
60 }),
61 );
62
63 expect(created.name).toContain("/notes/");
64 expect(created.noteId).toEqual(expect.any(String));
65 expect(created.shortDescription).toEqual("alchemy test attestor");
66 expect(created.longDescription).toEqual("initial");
67 expect(created.kind).toEqual("ATTESTATION");
68 expect(created.attestation?.hint?.humanReadableName).toEqual(
69 "Alchemy QA",
70 );
71
72 const fetched = yield* containeranalysis.getProjectsNotes({
73 name: created.name,
74 });
75 expect(fetched.name).toEqual(created.name);
76 expect(fetched.shortDescription).toEqual("alchemy test attestor");
77 expect(fetched.longDescription).toContain("[alchemy ");
78 expect(fetched.longDescription).toContain("initial");
79 expect(fetched.kind).toEqual("ATTESTATION");
80
81 const updated = yield* stack.deploy(
82 Effect.gen(function* () {
83 return yield* GCP.ContainerAnalysis.Note("Authority", {
84 noteId: created.noteId,
85 shortDescription: "alchemy test attestor v2",
86 longDescription: "updated",
87 relatedUrl: [
88 { url: "https://example.com/policy", label: "policy" },
89 { url: "https://example.com/docs", label: "docs" },
90 ],
91 attestation: { hint: { humanReadableName: "Alchemy QA" } },
92 });
93 }),
94 );
95
96 expect(updated.name).toEqual(created.name);
97 expect(updated.shortDescription).toEqual("alchemy test attestor v2");
98 expect(updated.longDescription).toEqual("updated");
99 expect(updated.relatedUrl.length).toBeGreaterThanOrEqual(1);
100
101 yield* stack.destroy();
102 const gone = yield* waitUntilGone(created.name);
103 expect(gone).toEqual("gone");
104 }).pipe(logLevel),
105 {
106 tags: ["provider:gcp", "provider:gcp:containeranalysis", "live"],
107 timeout: 90_000,
108 },
109);