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

main
ts 135 lines 4.42 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 Output from "alchemy/Output";
6 import * as Effect from "effect/Effect";
7 import {
8 logLevel,
9 probeAccountName,
10 runLifecycle,
11 waitUntilCustomerRepricingGone,
12 } from "./common.ts";
13
14 const { test } = Test.make({ providers: GCP.providers() });
15
16 const probeParent = `${probeAccountName}/customers/alchemy-missing`;
17 const probeMonth = { year: 2099, month: 1, day: 0 };
18
19 test.provider(
20 "getAccountsCustomersCustomerRepricingConfigs on a missing config fails with a typed tag",
21 (stack) =>
22 Effect.gen(function* () {
23 yield* stack.destroy();
24
25 const error = yield* Effect.flip(
26 cloudchannel.getAccountsCustomersCustomerRepricingConfigs({
27 name: `${probeParent}/customerRepricingConfigs/alchemy-missing`,
28 }),
29 );
30 expect(error._tag).toEqual("Forbidden");
31
32 yield* stack.destroy();
33 }).pipe(logLevel),
34 {
35 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
36 timeout: 90_000,
37 },
38 );
39
40 test.provider.skipIf(runLifecycle)(
41 "createAccountsCustomersCustomerRepricingConfigs without Cloud Channel access fails with a typed entitlement error",
42 (stack) =>
43 Effect.gen(function* () {
44 yield* stack.destroy();
45
46 const error = yield* Effect.flip(
47 cloudchannel.createAccountsCustomersCustomerRepricingConfigs({
48 parent: probeParent,
49 body: {
50 repricingConfig: {
51 effectiveInvoiceMonth: probeMonth,
52 rebillingBasis: "COST_AT_LIST",
53 adjustment: {
54 percentageAdjustment: { percentage: { value: "0.00" } },
55 },
56 entitlementGranularity: {
57 entitlement: `${probeParent}/entitlements/alchemy-missing`,
58 },
59 },
60 },
61 }),
62 );
63 expect(error._tag).toEqual("Forbidden");
64
65 yield* stack.destroy();
66 }).pipe(logLevel),
67 {
68 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
69 timeout: 90_000,
70 },
71 );
72
73 test.provider.skipIf(!runLifecycle)(
74 "create, update, and delete a customer repricing config",
75 (stack) =>
76 Effect.gen(function* () {
77 yield* stack.destroy();
78
79 const entitlement = process.env.GCP_CLOUDCHANNEL_ENTITLEMENT?.trim();
80
81 const created = yield* stack.deploy(
82 Effect.gen(function* () {
83 const customer = yield* GCP.CloudChannel.Customer("AcmeBill", {
84 parent: probeAccountName,
85 orgDisplayName: "Acme Billing",
86 });
87 const config = yield* GCP.CloudChannel.CustomersCustomerRepricingConfig("AcmeRule", {
88 parent: customer.name,
89 effectiveInvoiceMonth: probeMonth,
90 adjustmentPercentage: "0.00",
91 entitlement: entitlement ?? Output.interpolate`${customer.name}/entitlements/alchemy`,
92 });
93 return { customer, config };
94 }),
95 );
96
97 expect(created.config.name).toContain("/customerRepricingConfigs/");
98 expect(created.config.parent).toEqual(created.customer.name);
99
100 const fetched = yield* cloudchannel.getAccountsCustomersCustomerRepricingConfigs({
101 name: created.config.name,
102 });
103 expect(fetched.name).toEqual(created.config.name);
104
105 const updated = yield* stack.deploy(
106 Effect.gen(function* () {
107 const customer = yield* GCP.CloudChannel.Customer("AcmeBill", {
108 parent: probeAccountName,
109 customerId: created.customer.customerId,
110 orgDisplayName: "Acme Billing",
111 domain: created.customer.domain,
112 });
113 const config = yield* GCP.CloudChannel.CustomersCustomerRepricingConfig("AcmeRule", {
114 parent: customer.name,
115 configId: created.config.configId,
116 effectiveInvoiceMonth: probeMonth,
117 adjustmentPercentage: "1.00",
118 entitlement: entitlement ?? Output.interpolate`${customer.name}/entitlements/alchemy`,
119 });
120 return { customer, config };
121 }),
122 );
123
124 expect(updated.config.name).toEqual(created.config.name);
125
126 yield* stack.destroy();
127
128 const gone = yield* waitUntilCustomerRepricingGone(created.config.name);
129 expect(gone).toEqual("gone");
130 }).pipe(logLevel),
131 {
132 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
133 timeout: 90_000,
134 },
135 );