@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.46 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 compute from "@distilled.cloud/gcp/compute_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (project: string, region: string, urlMapName: string) =>
14 compute.getRegionUrlMaps({ project, region, urlMap: urlMapName }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 test.provider(
25 "create, update, and delete a regional url map",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29
30 const created = yield* stack.deploy(
31 Effect.gen(function* () {
32 return yield* GCP.Compute.RegionUrlMap("Web", {
33 region: "us-central1",
34 description: "https redirect",
35 defaultUrlRedirect: {
36 httpsRedirect: true,
37 hostRedirect: "example.com",
38 stripQuery: false,
39 },
40 });
41 }),
42 );
43
44 expect(created.urlMapName).toEqual(expect.any(String));
45 expect(created.region).toEqual("us-central1");
46 expect(created.description).toEqual("https redirect");
47 expect(created.defaultUrlRedirect?.httpsRedirect).toEqual(true);
48 expect(created.defaultUrlRedirect?.hostRedirect).toEqual("example.com");
49
50 const fetched = yield* compute.getRegionUrlMaps({
51 project: created.project,
52 region: created.region,
53 urlMap: created.urlMapName,
54 });
55 expect(fetched.name).toEqual(created.urlMapName);
56 expect(fetched.defaultUrlRedirect?.hostRedirect).toEqual("example.com");
57 expect(fetched.description).toContain("[alchemy ");
58 expect(fetched.description).toContain("https redirect");
59
60 const updated = yield* stack.deploy(
61 Effect.gen(function* () {
62 return yield* GCP.Compute.RegionUrlMap("Web", {
63 urlMapName: created.urlMapName,
64 region: "us-central1",
65 description: "host rules",
66 defaultUrlRedirect: {
67 httpsRedirect: true,
68 hostRedirect: "example.org",
69 stripQuery: true,
70 },
71 hostRules: [{ hosts: ["example.org"], pathMatcher: "all" }],
72 pathMatchers: [
73 {
74 name: "all",
75 defaultUrlRedirect: {
76 httpsRedirect: true,
77 hostRedirect: "www.example.org",
78 stripQuery: false,
79 },
80 },
81 ],
82 });
83 }),
84 );
85
86 expect(updated.urlMapName).toEqual(created.urlMapName);
87 expect(updated.region).toEqual("us-central1");
88 expect(updated.description).toEqual("host rules");
89 expect(updated.defaultUrlRedirect?.hostRedirect).toEqual("example.org");
90 expect(updated.defaultUrlRedirect?.stripQuery).toEqual(true);
91 expect(updated.hostRules).toEqual(
92 expect.arrayContaining([
93 expect.objectContaining({
94 pathMatcher: "all",
95 hosts: expect.arrayContaining(["example.org"]),
96 }),
97 ]),
98 );
99 expect(updated.pathMatchers).toEqual(
100 expect.arrayContaining([
101 expect.objectContaining({
102 name: "all",
103 defaultUrlRedirect: expect.objectContaining({
104 hostRedirect: "www.example.org",
105 }),
106 }),
107 ]),
108 );
109
110 const refetched = yield* compute.getRegionUrlMaps({
111 project: updated.project,
112 region: updated.region,
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.project, created.region, created.urlMapName);
123 expect(gone).toEqual("gone");
124 }).pipe(logLevel),
125 { tags: ["provider:gcp", "provider:gcp:compute", "live"], timeout: 90_000 },
126 );