@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 106 lines 3.78 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 aiplatform from "@distilled.cloud/gcp/aiplatform_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 // Policies govern an existing Vertex AI Agent
15 // (`projects/{p}/locations/{l}/agents/{a}`), which the v1 API cannot create.
16 // Set GCP_TEST_AGENT to that agent's resource name to run the lifecycle.
17 const runLifecycle = !process.env.FAST && !!process.env.GCP_TEST_AGENT;
18
19 const waitUntilGone = (name: string) =>
20 aiplatform.getProjectsLocationsSemanticGovernancePolicies({ name }).pipe(
21 Effect.as("found" as const),
22 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
23 Effect.repeat({
24 schedule: Schedule.spaced("2 seconds"),
25 until: (status) => status === "gone",
26 times: 10,
27 }),
28 );
29
30 test.provider(
31 "getProjectsLocationsSemanticGovernancePolicies on a missing policy fails with a typed tag",
32 (stack) =>
33 Effect.gen(function* () {
34 const { project } = yield* GcpEnvironment.current;
35 yield* stack.destroy();
36
37 const error = yield* Effect.flip(
38 aiplatform.getProjectsLocationsSemanticGovernancePolicies({
39 name: `projects/${project}/locations/us-central1/semanticGovernancePolicies/alchemy-sgp-missing`,
40 }),
41 );
42 expect(error._tag).toEqual("NotFound");
43
44 yield* stack.destroy();
45 }).pipe(logLevel),
46 {
47 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
48 timeout: 90_000,
49 },
50 );
51
52 test.provider.skipIf(!runLifecycle)(
53 "create, update, and delete a semantic governance policy",
54 (stack) =>
55 Effect.gen(function* () {
56 const { project } = yield* GcpEnvironment.current;
57 const agent =
58 process.env.GCP_TEST_AGENT ??
59 `projects/${project}/locations/us-central1/reasoningEngines/missing-agent`;
60 yield* stack.destroy();
61
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 return yield* GCP.AIPlatform.SemanticGovernancePolicy("Safety", {
65 location: "us-central1",
66 displayName: "safety",
67 description: "no pii",
68 agent,
69 naturalLanguageConstraint: "Never share customer PII.",
70 });
71 }),
72 );
73
74 expect(created.name).toContain("/semanticGovernancePolicies/");
75 expect(created.naturalLanguageConstraint).toEqual("Never share customer PII.");
76
77 const fetched = yield* aiplatform.getProjectsLocationsSemanticGovernancePolicies({
78 name: created.name,
79 });
80 expect(fetched.name).toEqual(created.name);
81 expect(fetched.description).toContain("alchemy-id=");
82
83 const updated = yield* stack.deploy(
84 Effect.gen(function* () {
85 return yield* GCP.AIPlatform.SemanticGovernancePolicy("Safety", {
86 location: "us-central1",
87 semanticGovernancePolicyId: created.semanticGovernancePolicyId,
88 displayName: "safety-v2",
89 description: "no pii v2",
90 agent,
91 naturalLanguageConstraint: "Never share secrets or PII.",
92 });
93 }),
94 );
95 expect(updated.name).toEqual(created.name);
96 expect(updated.naturalLanguageConstraint).toEqual("Never share secrets or PII.");
97
98 yield* stack.destroy();
99 const gone = yield* waitUntilGone(created.name);
100 expect(gone).toEqual("gone");
101 }).pipe(logLevel),
102 {
103 tags: ["provider:gcp", "provider:gcp:aiplatform", "live"],
104 timeout: 120_000,
105 },
106 );