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

main
ts 109 lines 3.48 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 jobs from "@distilled.cloud/gcp/jobs_v4";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { logLevel, currentProject, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 jobs.getProjectsTenants({ 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
22 test.provider.skipIf(!runLifecycle)(
23 "getProjectsTenants on a missing tenant 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 jobs.getProjectsTenants({
31 name: `projects/${project}/tenants/alchemy-missing-tenant`,
32 }),
33 );
34 expect(error._tag).toEqual("NotFound");
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 { tags: ["provider:gcp", "provider:gcp:jobs", "live"], timeout: 90_000 },
39 );
40
41 test.provider.skipIf(runLifecycle)(
42 "createProjectsTenants fails with TalentDataPermissionRequired until onboarded",
43 (stack) =>
44 Effect.gen(function* () {
45 const project = yield* currentProject;
46 yield* stack.destroy();
47
48 const error = yield* Effect.flip(
49 jobs.createProjectsTenants({
50 parent: `projects/${project}`,
51 body: { externalId: "alchemy-jobs-probe" },
52 }),
53 );
54 expect(error._tag).toEqual("TalentDataPermissionRequired");
55
56 yield* stack.destroy();
57 }).pipe(logLevel),
58 { tags: ["provider:gcp", "provider:gcp:jobs", "live"], timeout: 90_000 },
59 );
60
61 test.provider.skipIf(!runLifecycle)(
62 "create, update, and delete a tenant",
63 (stack) =>
64 Effect.gen(function* () {
65 const project = yield* currentProject;
66 yield* stack.destroy();
67
68 const created = yield* stack.deploy(
69 Effect.gen(function* () {
70 return yield* GCP.Jobs.Tenant("Acme", {
71 externalId: "acme-corp",
72 });
73 }),
74 );
75
76 expect(created.name.startsWith(`projects/${project}/tenants/`)).toEqual(true);
77 expect(created.tenantId.length).toBeGreaterThan(0);
78 expect(created.externalId).toEqual("acme-corp");
79 expect(created.project).toEqual(project);
80
81 const fetched = yield* jobs.getProjectsTenants({ name: created.name });
82 expect(fetched.name).toEqual(created.name);
83 expect(fetched.externalId).toContain("[alchemy ");
84 expect(fetched.externalId).toContain("acme-corp");
85
86 const updated = yield* stack.deploy(
87 Effect.gen(function* () {
88 return yield* GCP.Jobs.Tenant("Acme", {
89 tenantId: created.tenantId,
90 externalId: "acme-holdings",
91 });
92 }),
93 );
94
95 expect(updated.name).toEqual(created.name);
96 expect(updated.externalId).toEqual("acme-holdings");
97
98 const fetchedUpdate = yield* jobs.getProjectsTenants({
99 name: created.name,
100 });
101 expect(fetchedUpdate.externalId).toContain("acme-holdings");
102
103 yield* stack.destroy();
104
105 const gone = yield* waitUntilGone(created.name);
106 expect(gone).toEqual("gone");
107 }).pipe(logLevel),
108 { tags: ["provider:gcp", "provider:gcp:jobs", "live"], timeout: 90_000 },
109 );