@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 129 lines 4.27 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/nodes/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 "createSignedNodesNodesDevices 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.createSignedNodesNodesDevices({
48 parent: "nodes/missing/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: "campus",
73 });
74 const child = yield* GCP.SasPortal.NodesNode("Sector", {
75 parent: parent.name,
76 displayName: "sector-1",
77 });
78 const device = yield* GCP.SasPortal.SignedNodesNodesDevice("Cbsd", {
79 parent: child.name,
80 displayName: "sector-a",
81 encodedDevice: signedDeviceProbe.encodedDevice,
82 installerId: signedDeviceProbe.installerId,
83 });
84 return { parent, child, device };
85 }),
86 );
87
88 expect(created.device.name.length).toBeGreaterThan(0);
89 expect(created.device.displayName).toEqual("sector-a");
90
91 const fetched = yield* sasportal.getNodesDevices({
92 name: created.device.name,
93 });
94 expect(fetched.name).toEqual(created.device.name);
95 expect(fetched.displayName).toContain("[alchemy ");
96
97 const updated = yield* stack.deploy(
98 Effect.gen(function* () {
99 const parent = yield* GCP.SasPortal.CustomersNode("Site", {
100 parent: customer,
101 name: created.parent.name,
102 displayName: "campus",
103 });
104 const child = yield* GCP.SasPortal.NodesNode("Sector", {
105 parent: parent.name,
106 name: created.child.name,
107 displayName: "sector-1",
108 });
109 const device = yield* GCP.SasPortal.SignedNodesNodesDevice("Cbsd", {
110 parent: child.name,
111 name: created.device.name,
112 displayName: "sector-b",
113 encodedDevice: signedDeviceProbe.encodedDevice,
114 installerId: signedDeviceProbe.installerId,
115 });
116 return { parent, child, device };
117 }),
118 );
119
120 expect(updated.device.name).toEqual(created.device.name);
121 expect(updated.device.displayName).toEqual("sector-b");
122
123 yield* stack.destroy();
124
125 const gone = yield* waitUntilGone(created.device.name);
126 expect(gone).toEqual("gone");
127 }).pipe(logLevel),
128 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
129 );