@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 126 lines 4.31 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 = (urlMapName: string) =>
15 GcpEnvironment.current.pipe(
16 Effect.flatMap(({ project }) =>
17 compute.getUrlMaps({ project, urlMap: urlMapName }).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 "create, update, and delete a url map",
31 (stack) =>
32 Effect.gen(function* () {
33 const { project } = yield* GcpEnvironment.current;
34 yield* stack.destroy();
35
36 const created = yield* stack.deploy(
37 Effect.gen(function* () {
38 return yield* GCP.Compute.UrlMap("Web", {
39 description: "https redirect",
40 defaultUrlRedirect: {
41 httpsRedirect: true,
42 hostRedirect: "example.com",
43 stripQuery: false,
44 },
45 });
46 }),
47 );
48
49 expect(created.urlMapName).toEqual(expect.any(String));
50 expect(created.description).toEqual("https redirect");
51 expect(created.defaultUrlRedirect?.httpsRedirect).toEqual(true);
52 expect(created.defaultUrlRedirect?.hostRedirect).toEqual("example.com");
53
54 const fetched = yield* compute.getUrlMaps({
55 project,
56 urlMap: created.urlMapName,
57 });
58 expect(fetched.name).toEqual(created.urlMapName);
59 expect(fetched.defaultUrlRedirect?.hostRedirect).toEqual("example.com");
60 expect(fetched.description).toContain("[alchemy ");
61 expect(fetched.description).toContain("https redirect");
62
63 const updated = yield* stack.deploy(
64 Effect.gen(function* () {
65 return yield* GCP.Compute.UrlMap("Web", {
66 urlMapName: created.urlMapName,
67 description: "host rules",
68 defaultUrlRedirect: {
69 httpsRedirect: true,
70 hostRedirect: "example.org",
71 stripQuery: true,
72 },
73 hostRules: [{ hosts: ["example.org"], pathMatcher: "all" }],
74 pathMatchers: [
75 {
76 name: "all",
77 defaultUrlRedirect: {
78 httpsRedirect: true,
79 hostRedirect: "www.example.org",
80 stripQuery: false,
81 },
82 },
83 ],
84 });
85 }),
86 );
87
88 expect(updated.urlMapName).toEqual(created.urlMapName);
89 expect(updated.description).toEqual("host rules");
90 expect(updated.defaultUrlRedirect?.hostRedirect).toEqual("example.org");
91 expect(updated.defaultUrlRedirect?.stripQuery).toEqual(true);
92 expect(updated.hostRules).toEqual(
93 expect.arrayContaining([
94 expect.objectContaining({
95 pathMatcher: "all",
96 hosts: expect.arrayContaining(["example.org"]),
97 }),
98 ]),
99 );
100 expect(updated.pathMatchers).toEqual(
101 expect.arrayContaining([
102 expect.objectContaining({
103 name: "all",
104 defaultUrlRedirect: expect.objectContaining({
105 hostRedirect: "www.example.org",
106 }),
107 }),
108 ]),
109 );
110
111 const refetched = yield* compute.getUrlMaps({
112 project,
113 urlMap: updated.urlMapName,
114 });
115 expect(refetched.defaultUrlRedirect?.hostRedirect).toEqual("example.org");
116 expect(refetched.hostRules?.[0]?.pathMatcher).toEqual("all");
117 expect(refetched.pathMatchers?.[0]?.name).toEqual("all");
118 expect(refetched.description).toContain("host rules");
119
120 yield* stack.destroy();
121
122 const gone = yield* waitUntilGone(created.urlMapName);
123 expect(gone).toEqual("gone");
124 }).pipe(logLevel),
125 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
126 );