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

main
ts 120 lines 3.89 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, signedDeviceProbe } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 sasportal.getNodesDevices({ 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 "getNodesDevices 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.getNodesDevices({
30 name: "nodes/missing/devices/alchemy-missing",
31 }),
32 );
33 expect(error._tag).toEqual("ServiceDisabled");
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 "createSignedNodesDevices 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.createSignedNodesDevices({
48 parent: "nodes/missing",
49 body: signedDeviceProbe,
50 }),
51 );
52 expect(error._tag).toEqual("ServiceDisabled");
53
54 yield* stack.destroy();
55 }).pipe(logLevel),
56 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
57 );
58
59 test.provider.skipIf(!runLifecycle)(
60 "create, update, and delete a signed device",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const customer = yield* firstCustomerName;
66 expect(customer.length).toBeGreaterThan(0);
67
68 const created = yield* stack.deploy(
69 Effect.gen(function* () {
70 const parent = yield* GCP.SasPortal.CustomersNode("Site", {
71 parent: customer,
72 displayName: "site-a",
73 });
74 const device = yield* GCP.SasPortal.SignedNodesDevice("Cbsd", {
75 parent: parent.name,
76 displayName: "sector-a",
77 encodedDevice: signedDeviceProbe.encodedDevice,
78 installerId: signedDeviceProbe.installerId,
79 });
80 return { parent, device };
81 }),
82 );
83
84 expect(created.device.name.length).toBeGreaterThan(0);
85 expect(created.device.displayName).toEqual("sector-a");
86
87 const fetched = yield* sasportal.getNodesDevices({
88 name: created.device.name,
89 });
90 expect(fetched.name).toEqual(created.device.name);
91 expect(fetched.displayName).toContain("[alchemy ");
92
93 const updated = yield* stack.deploy(
94 Effect.gen(function* () {
95 const parent = yield* GCP.SasPortal.CustomersNode("Site", {
96 parent: customer,
97 name: created.parent.name,
98 displayName: "site-a",
99 });
100 const device = yield* GCP.SasPortal.SignedNodesDevice("Cbsd", {
101 parent: parent.name,
102 name: created.device.name,
103 displayName: "sector-b",
104 encodedDevice: signedDeviceProbe.encodedDevice,
105 installerId: signedDeviceProbe.installerId,
106 });
107 return { parent, device };
108 }),
109 );
110
111 expect(updated.device.name).toEqual(created.device.name);
112 expect(updated.device.displayName).toEqual("sector-b");
113
114 yield* stack.destroy();
115
116 const gone = yield* waitUntilGone(created.device.name);
117 expect(gone).toEqual("gone");
118 }).pipe(logLevel),
119 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
120 );