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
| 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 dns from "@distilled.cloud/gcp/dns_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import { withNetworkSlot } from "../networkQuota.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 14 | |
| 15 | const waitUntilGone = (project: string, responsePolicy: string, ruleName: string) => |
| 16 | dns |
| 17 | .getResponsePolicyRules({ |
| 18 | project, |
| 19 | responsePolicy, |
| 20 | responsePolicyRule: ruleName, |
| 21 | }) |
| 22 | .pipe( |
| 23 | Effect.as("found" as const), |
| 24 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 25 | Effect.repeat({ |
| 26 | schedule: Schedule.spaced("1 second"), |
| 27 | until: (status) => status === "gone", |
| 28 | times: 10, |
| 29 | }), |
| 30 | ); |
| 31 | |
| 32 | test.provider( |
| 33 | "getResponsePolicyRules on a missing rule fails with a typed tag", |
| 34 | (stack) => |
| 35 | Effect.gen(function* () { |
| 36 | yield* stack.destroy(); |
| 37 | |
| 38 | const { project } = yield* GcpEnvironment.current; |
| 39 | const error = yield* Effect.flip( |
| 40 | dns.getResponsePolicyRules({ |
| 41 | project, |
| 42 | responsePolicy: "alchemy-missing-policy", |
| 43 | responsePolicyRule: "alchemy-missing-rule", |
| 44 | }), |
| 45 | ); |
| 46 | expect(error._tag).toEqual("NotFound"); |
| 47 | |
| 48 | yield* stack.destroy(); |
| 49 | }).pipe(logLevel), |
| 50 | { tags: ["provider:gcp", "provider:gcp:dns", "live"], timeout: 90_000 }, |
| 51 | ); |
| 52 | |
| 53 | test.provider( |
| 54 | "create, update, and delete a response policy rule", |
| 55 | (stack) => |
| 56 | Effect.gen(function* () { |
| 57 | yield* stack.destroy(); |
| 58 | |
| 59 | const created = yield* stack.deploy( |
| 60 | Effect.gen(function* () { |
| 61 | const vpc = yield* GCP.Compute.Network("Vpc", { |
| 62 | autoCreateSubnetworks: false, |
| 63 | }); |
| 64 | const policy = yield* GCP.DNS.ResponsePolicy("Overrides", { |
| 65 | description: "alchemy response policy for rule test", |
| 66 | networks: [vpc.networkName], |
| 67 | }); |
| 68 | const rule = yield* GCP.DNS.ResponsePolicyRule("Internal", { |
| 69 | responsePolicy: policy.responsePolicyName, |
| 70 | dnsName: "rule.internal.example.com.", |
| 71 | localData: [{ type: "A", ttl: 300, rrdatas: ["10.0.0.20"] }], |
| 72 | }); |
| 73 | return { vpc, policy, rule }; |
| 74 | }), |
| 75 | ); |
| 76 | |
| 77 | expect(created.rule.responsePolicy).toEqual(created.policy.responsePolicyName); |
| 78 | expect(created.rule.dnsName).toEqual("rule.internal.example.com."); |
| 79 | |
| 80 | const fetched = yield* dns.getResponsePolicyRules({ |
| 81 | project: created.rule.project, |
| 82 | responsePolicy: created.policy.responsePolicyName, |
| 83 | responsePolicyRule: created.rule.ruleName, |
| 84 | }); |
| 85 | expect(fetched.dnsName).toEqual("rule.internal.example.com."); |
| 86 | expect(fetched.localData?.localDatas?.[0]?.rrdatas).toEqual(["10.0.0.20"]); |
| 87 | |
| 88 | const updated = yield* stack.deploy( |
| 89 | Effect.gen(function* () { |
| 90 | const vpc = yield* GCP.Compute.Network("Vpc", { |
| 91 | networkName: created.vpc.networkName, |
| 92 | autoCreateSubnetworks: false, |
| 93 | }); |
| 94 | const policy = yield* GCP.DNS.ResponsePolicy("Overrides", { |
| 95 | responsePolicyName: created.policy.responsePolicyName, |
| 96 | description: "alchemy response policy for rule test", |
| 97 | networks: [vpc.networkName], |
| 98 | }); |
| 99 | const rule = yield* GCP.DNS.ResponsePolicyRule("Internal", { |
| 100 | responsePolicy: policy.responsePolicyName, |
| 101 | ruleName: created.rule.ruleName, |
| 102 | dnsName: "rule.internal.example.com.", |
| 103 | localData: [{ type: "A", ttl: 60, rrdatas: ["10.0.0.21"] }], |
| 104 | }); |
| 105 | return { vpc, policy, rule }; |
| 106 | }), |
| 107 | ); |
| 108 | |
| 109 | expect(updated.rule.ruleName).toEqual(created.rule.ruleName); |
| 110 | expect(updated.rule.localData).toEqual([ |
| 111 | { |
| 112 | name: "rule.internal.example.com.", |
| 113 | type: "A", |
| 114 | ttl: 60, |
| 115 | rrdatas: ["10.0.0.21"], |
| 116 | }, |
| 117 | ]); |
| 118 | |
| 119 | yield* stack.destroy(); |
| 120 | const gone = yield* waitUntilGone( |
| 121 | created.rule.project, |
| 122 | created.policy.responsePolicyName, |
| 123 | created.rule.ruleName, |
| 124 | ); |
| 125 | expect(gone).toEqual("gone"); |
| 126 | }).pipe(logLevel, withNetworkSlot), |
| 127 | { tags: ["provider:gcp", "provider:gcp:dns", "live"], timeout: 120_000 }, |
| 128 | ); |