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

main
ts 133 lines 4.37 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 sasportal from "@distilled.cloud/gcp/sasportal_v1alpha1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { firstCustomerName, logLevel, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 sasportal.getDeploymentsDevices({ 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: 8,
19 }),
20 );
21
22 test.provider(
23 "getDeploymentsDevices on a missing device fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 yield* stack.destroy();
27
28 const error = yield* Effect.flip(
29 sasportal.getDeploymentsDevices({
30 name: "nodes/missing/deployments/missing/devices/alchemy-missing",
31 }),
32 );
33 expect(error._tag).toEqual("NotFound");
34
35 yield* stack.destroy();
36 }).pipe(logLevel),
37 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
38 );
39
40 test.provider.skipIf(runLifecycle)(
41 "createNodesDeploymentsDevices without entitlement fails with a typed tag",
42 (stack) =>
43 Effect.gen(function* () {
44 yield* stack.destroy();
45
46 const error = yield* Effect.flip(
47 sasportal.createNodesDeploymentsDevices({
48 parent: "nodes/missing/deployments/missing",
49 body: {
50 displayName: "alchemy-sasportal-probe",
51 fccId: "TESTFCC",
52 serialNumber: "ALCHEMYPROBE1",
53 },
54 }),
55 );
56 expect(error._tag).toEqual("ServiceDisabled");
57
58 yield* stack.destroy();
59 }).pipe(logLevel),
60 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
61 );
62
63 test.provider.skipIf(!runLifecycle)(
64 "create, update, and delete a nested device",
65 (stack) =>
66 Effect.gen(function* () {
67 yield* stack.destroy();
68
69 const customer = yield* firstCustomerName;
70 expect(customer.length).toBeGreaterThan(0);
71
72 const created = yield* stack.deploy(
73 Effect.gen(function* () {
74 const node = yield* GCP.SasPortal.CustomersNode("Site", {
75 parent: customer,
76 displayName: "site-a",
77 });
78 const deployment = yield* GCP.SasPortal.CustomersNodesDeployment("Campus", {
79 parent: node.name,
80 displayName: "downtown",
81 });
82 const device = yield* GCP.SasPortal.NodesDeploymentsDevice("Cbsd", {
83 parent: deployment.name,
84 displayName: "sector-a",
85 fccId: "TESTFCC",
86 serialNumber: "ALCHSNNEST3",
87 });
88 return { node, deployment, device };
89 }),
90 );
91
92 expect(created.device.name.length).toBeGreaterThan(0);
93 expect(created.device.displayName).toEqual("sector-a");
94
95 const fetched = yield* sasportal.getDeploymentsDevices({
96 name: created.device.name,
97 });
98 expect(fetched.name).toEqual(created.device.name);
99 expect(fetched.displayName).toContain("[alchemy ");
100
101 const updated = yield* stack.deploy(
102 Effect.gen(function* () {
103 const node = yield* GCP.SasPortal.CustomersNode("Site", {
104 parent: customer,
105 name: created.node.name,
106 displayName: "site-a",
107 });
108 const deployment = yield* GCP.SasPortal.CustomersNodesDeployment("Campus", {
109 parent: node.name,
110 name: created.deployment.name,
111 displayName: "downtown",
112 });
113 const device = yield* GCP.SasPortal.NodesDeploymentsDevice("Cbsd", {
114 parent: deployment.name,
115 name: created.device.name,
116 displayName: "sector-b",
117 fccId: "TESTFCC",
118 serialNumber: "ALCHSNNEST3",
119 });
120 return { node, deployment, device };
121 }),
122 );
123
124 expect(updated.device.name).toEqual(created.device.name);
125 expect(updated.device.displayName).toEqual("sector-b");
126
127 yield* stack.destroy();
128
129 const gone = yield* waitUntilGone(created.device.name);
130 expect(gone).toEqual("gone");
131 }).pipe(logLevel),
132 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
133 );