@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 104 lines 3.33 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { GcpEnvironment } from "@alchemy.run/gcp/Environment";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as compute from "@distilled.cloud/gcp/compute_v1";
6 import * as Effect from "effect/Effect";
7 import { MinimumLogLevel } from "effect/References";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: GCP.providers() });
11
12 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
13
14 const waitUntilGone = (license: string) =>
15 GcpEnvironment.current.pipe(
16 Effect.flatMap(({ project }) =>
17 compute.getLicenses({ project, license }).pipe(
18 Effect.as("found" as const),
19 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
20 Effect.repeat({
21 schedule: Schedule.spaced("1 second"),
22 until: (status) => status === "gone",
23 times: 10,
24 }),
25 ),
26 ),
27 );
28
29 test.provider(
30 "getLicenses on a missing license fails with NotFound",
31 (stack) =>
32 Effect.gen(function* () {
33 const { project } = yield* GcpEnvironment.current;
34 yield* stack.destroy();
35
36 const error = yield* Effect.flip(
37 compute.getLicenses({
38 project,
39 license: "alchemy-missing-license",
40 }),
41 );
42 expect(error._tag).toBe("NotFound");
43
44 yield* stack.destroy();
45 }).pipe(logLevel),
46 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
47 );
48
49 test.provider(
50 "create, update, and delete a license",
51 (stack) =>
52 Effect.gen(function* () {
53 yield* stack.destroy();
54
55 const created = yield* stack.deploy(
56 Effect.gen(function* () {
57 return yield* GCP.Compute.License("ImageLicense", {
58 description: "marketplace os",
59 transferable: true,
60 });
61 }),
62 );
63
64 expect(created.licenseName).toEqual(expect.any(String));
65 expect(created.description).toEqual("marketplace os");
66 expect(created.transferable).toEqual(true);
67 expect(created.selfLink).toEqual(expect.any(String));
68
69 const fetched = yield* compute.getLicenses({
70 project: created.project,
71 license: created.licenseName,
72 });
73 expect(fetched.name).toEqual(created.licenseName);
74 expect(fetched.description).toContain("[alchemy ");
75 expect(fetched.description).toContain("marketplace os");
76
77 const updated = yield* stack.deploy(
78 Effect.gen(function* () {
79 return yield* GCP.Compute.License("ImageLicense", {
80 licenseName: created.licenseName,
81 description: "marketplace os",
82 transferable: true,
83 appendableToDisk: true,
84 });
85 }),
86 );
87
88 expect(updated.licenseName).toEqual(created.licenseName);
89 expect(updated.description).toEqual("marketplace os");
90 expect(updated.appendableToDisk).toEqual(true);
91
92 const refetched = yield* compute.getLicenses({
93 project: updated.project,
94 license: updated.licenseName,
95 });
96 expect(refetched.appendableToDisk).toEqual(true);
97
98 yield* stack.destroy();
99
100 const gone = yield* waitUntilGone(created.licenseName);
101 expect(gone).toEqual("gone");
102 }).pipe(logLevel),
103 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
104 );