@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 111 lines 3.58 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.getCustomersDevices({ 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 "getCustomersDevices 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.getCustomersDevices({
30 name: "customers/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 "createSignedCustomersDevices 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.createSignedCustomersDevices({
48 parent: "customers/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 device = yield* GCP.SasPortal.SignedCustomersDevice("Cbsd", {
71 parent: customer,
72 displayName: "sector-a",
73 encodedDevice: signedDeviceProbe.encodedDevice,
74 installerId: signedDeviceProbe.installerId,
75 });
76 return { device };
77 }),
78 );
79
80 expect(created.device.name.length).toBeGreaterThan(0);
81 expect(created.device.displayName).toEqual("sector-a");
82
83 const fetched = yield* sasportal.getCustomersDevices({
84 name: created.device.name,
85 });
86 expect(fetched.name).toEqual(created.device.name);
87 expect(fetched.displayName).toContain("[alchemy ");
88
89 const updated = yield* stack.deploy(
90 Effect.gen(function* () {
91 const device = yield* GCP.SasPortal.SignedCustomersDevice("Cbsd", {
92 parent: customer,
93 name: created.device.name,
94 displayName: "sector-b",
95 encodedDevice: signedDeviceProbe.encodedDevice,
96 installerId: signedDeviceProbe.installerId,
97 });
98 return { device };
99 }),
100 );
101
102 expect(updated.device.name).toEqual(created.device.name);
103 expect(updated.device.displayName).toEqual("sector-b");
104
105 yield* stack.destroy();
106
107 const gone = yield* waitUntilGone(created.device.name);
108 expect(gone).toEqual("gone");
109 }).pipe(logLevel),
110 { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 },
111 );