@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 117 lines 4.01 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 {
8 location,
9 logLevel,
10 currentProject,
11 TEST_ATTESTATION,
12 TEST_RESOURCE_URI,
13 } from "./common.ts";
14
15 const { test } = Test.make({ providers: GCP.providers() });
16
17 const waitUntilGone = (name: string) =>
18 containeranalysis.getProjectsLocationsOccurrences({ name }).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 test.provider(
29 "getProjectsLocationsOccurrences on a missing occurrence fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const project = yield* currentProject;
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 containeranalysis.getProjectsLocationsOccurrences({
37 name: `projects/${project}/locations/${location}/occurrences/alchemy-missing-occurrence`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 yield* stack.destroy();
43 }).pipe(logLevel),
44 {
45 tags: ["provider:gcp", "provider:gcp:containeranalysis", "live"],
46 timeout: 90_000,
47 },
48 );
49
50 test.provider(
51 "create, update, and delete a locations occurrence",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 const note = yield* GCP.ContainerAnalysis.LocationsNote("Authority", {
59 location,
60 shortDescription: "regional occurrence attestor",
61 attestation: { hint: { humanReadableName: "Alchemy Regional" } },
62 });
63 const occurrence = yield* GCP.ContainerAnalysis.LocationsOccurrence("Signed", {
64 location,
65 noteName: note.name,
66 resourceUri: TEST_RESOURCE_URI,
67 remediation: "initial",
68 attestation: TEST_ATTESTATION,
69 });
70 return { note, occurrence };
71 }),
72 );
73
74 expect(created.occurrence.name).toContain(`/locations/${location}/occurrences/`);
75 expect(created.occurrence.location).toEqual(location);
76 expect(created.occurrence.noteName).toEqual(created.note.name);
77 expect(created.occurrence.resourceUri).toEqual(TEST_RESOURCE_URI);
78 expect(created.occurrence.kind).toEqual("ATTESTATION");
79
80 const fetched = yield* containeranalysis.getProjectsLocationsOccurrences({
81 name: created.occurrence.name,
82 });
83 expect(fetched.name).toEqual(created.occurrence.name);
84 expect(fetched.remediation).toContain("[alchemy ");
85 expect(fetched.kind).toEqual("ATTESTATION");
86
87 const updated = yield* stack.deploy(
88 Effect.gen(function* () {
89 const note = yield* GCP.ContainerAnalysis.LocationsNote("Authority", {
90 noteId: created.note.noteId,
91 location,
92 shortDescription: "regional occurrence attestor",
93 attestation: { hint: { humanReadableName: "Alchemy Regional" } },
94 });
95 const occurrence = yield* GCP.ContainerAnalysis.LocationsOccurrence("Signed", {
96 location,
97 noteName: note.name,
98 resourceUri: TEST_RESOURCE_URI,
99 remediation: "rebuild from a patched base",
100 attestation: TEST_ATTESTATION,
101 });
102 return { note, occurrence };
103 }),
104 );
105
106 expect(updated.occurrence.name).toEqual(created.occurrence.name);
107 expect(updated.occurrence.remediation).toEqual("rebuild from a patched base");
108
109 yield* stack.destroy();
110 const gone = yield* waitUntilGone(created.occurrence.name);
111 expect(gone).toEqual("gone");
112 }).pipe(logLevel),
113 {
114 tags: ["provider:gcp", "provider:gcp:containeranalysis", "live"],
115 timeout: 90_000,
116 },
117 );