@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 112 lines 3.91 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as ces from "@distilled.cloud/gcp/ces_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const waitUntilGone = (name: string) =>
15 ces.getProjectsLocationsAppsGuardrails({ name }).pipe(
16 Effect.as("found" as const),
17 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
18 Effect.repeat({
19 schedule: Schedule.spaced("1 second"),
20 until: (status) => status === "gone",
21 times: 10,
22 }),
23 );
24
25 test.provider(
26 "getProjectsLocationsAppsGuardrails on a missing guardrail fails with a typed tag",
27 (stack) =>
28 Effect.gen(function* () {
29 const { project } = yield* GcpEnvironment.current;
30
31 yield* stack.destroy();
32
33 const error = yield* Effect.flip(
34 ces.getProjectsLocationsAppsGuardrails({
35 name: `projects/${project}/locations/us/apps/missing/guardrails/missing`,
36 }),
37 );
38 expect(error._tag).toEqual("NotFound");
39
40 yield* stack.destroy();
41 }).pipe(logLevel),
42 { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 },
43 );
44
45 test.provider(
46 "create, update, and delete a guardrail",
47 (stack) =>
48 Effect.gen(function* () {
49 yield* stack.destroy();
50
51 const created = yield* stack.deploy(
52 Effect.gen(function* () {
53 const app = yield* GCP.CES.App("Support", {
54 location: "us",
55 displayName: "support-guardrail",
56 });
57 const guardrail = yield* GCP.CES.AppsGuardrail("Safety", {
58 app: app.name,
59 displayName: "safety",
60 description: "ban phrases",
61 contentFilter: {
62 matchType: "SIMPLE_STRING_MATCH",
63 bannedContents: ["forbidden"],
64 },
65 });
66 return { app, guardrail };
67 }),
68 );
69
70 expect(created.guardrail.name).toContain("/guardrails/");
71 expect(created.guardrail.app).toEqual(created.app.name);
72 expect(created.guardrail.displayName).toEqual("safety");
73 expect(created.guardrail.description).toEqual("ban phrases");
74 expect(created.guardrail.contentFilter?.bannedContents).toContain("forbidden");
75
76 const fetched = yield* ces.getProjectsLocationsAppsGuardrails({
77 name: created.guardrail.name,
78 });
79 expect(fetched.name).toEqual(created.guardrail.name);
80 expect(fetched.description).toContain("alchemy-id=");
81
82 const updated = yield* stack.deploy(
83 Effect.gen(function* () {
84 const app = yield* GCP.CES.App("Support", {
85 appId: created.app.appId,
86 location: created.app.location,
87 displayName: "support-guardrail",
88 });
89 const guardrail = yield* GCP.CES.AppsGuardrail("Safety", {
90 app: app.name,
91 guardrailId: created.guardrail.guardrailId,
92 displayName: "safety",
93 description: "ban more phrases",
94 contentFilter: {
95 matchType: "SIMPLE_STRING_MATCH",
96 bannedContents: ["forbidden", "blocked"],
97 },
98 });
99 return { app, guardrail };
100 }),
101 );
102
103 expect(updated.guardrail.name).toEqual(created.guardrail.name);
104 expect(updated.guardrail.description).toEqual("ban more phrases");
105 expect(updated.guardrail.contentFilter?.bannedContents).toContain("blocked");
106
107 yield* stack.destroy();
108 const gone = yield* waitUntilGone(created.guardrail.name);
109 expect(gone).toEqual("gone");
110 }).pipe(logLevel),
111 { tags: ["provider:gcp", "provider:gcp:ces", "live"], timeout: 300_000 },
112 );