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

main
ts 108 lines 3.07 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 cloudchannel from "@distilled.cloud/gcp/cloudchannel_v1";
5 import * as Effect from "effect/Effect";
6 import {
7 logLevel,
8 probeAccountName,
9 probeCustomerBody,
10 runLifecycle,
11 waitUntilCustomerGone,
12 } from "./common.ts";
13
14 const { test } = Test.make({ providers: GCP.providers() });
15
16 test.provider(
17 "getAccountsCustomers on a missing customer fails with a typed tag",
18 (stack) =>
19 Effect.gen(function* () {
20 yield* stack.destroy();
21
22 const error = yield* Effect.flip(
23 cloudchannel.getAccountsCustomers({
24 name: `${probeAccountName}/customers/alchemy-missing`,
25 }),
26 );
27 expect(error._tag).toEqual("Forbidden");
28
29 yield* stack.destroy();
30 }).pipe(logLevel),
31 {
32 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
33 timeout: 90_000,
34 },
35 );
36
37 test.provider.skipIf(runLifecycle)(
38 "createAccountsCustomers without Cloud Channel access fails with a typed entitlement error",
39 (stack) =>
40 Effect.gen(function* () {
41 yield* stack.destroy();
42
43 const error = yield* Effect.flip(
44 cloudchannel.createAccountsCustomers({
45 parent: probeAccountName,
46 body: probeCustomerBody,
47 }),
48 );
49 expect(error._tag).toEqual("Forbidden");
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 {
54 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
55 timeout: 90_000,
56 },
57 );
58
59 test.provider.skipIf(!runLifecycle)(
60 "create, update, and delete a customer",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const created = yield* stack.deploy(
66 Effect.gen(function* () {
67 return yield* GCP.CloudChannel.Customer("Acme", {
68 parent: probeAccountName,
69 orgDisplayName: "Acme Corp",
70 });
71 }),
72 );
73
74 expect(created.name.startsWith(`${probeAccountName}/customers/`)).toEqual(true);
75 expect(created.customerId.length).toBeGreaterThan(0);
76 expect(created.orgDisplayName).toEqual("Acme Corp");
77 expect(created.domain).toEqual(expect.any(String));
78
79 const fetched = yield* cloudchannel.getAccountsCustomers({
80 name: created.name,
81 });
82 expect(fetched.name).toEqual(created.name);
83 expect(fetched.orgDisplayName).toEqual("Acme Corp");
84
85 const updated = yield* stack.deploy(
86 Effect.gen(function* () {
87 return yield* GCP.CloudChannel.Customer("Acme", {
88 parent: probeAccountName,
89 customerId: created.customerId,
90 orgDisplayName: "Acme Corporation",
91 domain: created.domain,
92 });
93 }),
94 );
95
96 expect(updated.name).toEqual(created.name);
97 expect(updated.orgDisplayName).toEqual("Acme Corporation");
98
99 yield* stack.destroy();
100
101 const gone = yield* waitUntilCustomerGone(created.name);
102 expect(gone).toEqual("gone");
103 }).pipe(logLevel),
104 {
105 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
106 timeout: 90_000,
107 },
108 );