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 { |
| 2 | activeReplicaRegions, |
| 3 | observedRegion, |
| 4 | regionPlacementPatch, |
| 5 | serviceRegionPlacement, |
| 6 | } from "@alchemy.run/railway/ServiceRegion"; |
| 7 | import { describe, expect, it } from "@alchemy.run/test"; |
| 8 | |
| 9 | describe( |
| 10 | "Railway service region placement", |
| 11 | { tags: ["unit", "provider:railway", "provider:railway:service", "local"] }, |
| 12 | () => { |
| 13 | it("reads deploy.multiRegionConfig and ignores the legacy region field", () => { |
| 14 | const placement = serviceRegionPlacement( |
| 15 | { |
| 16 | services: { |
| 17 | api: { |
| 18 | deploy: { |
| 19 | region: "us-west2", |
| 20 | multiRegionConfig: { |
| 21 | "asia-southeast1-eqsg3a": { numReplicas: 1 }, |
| 22 | "europe-west4-drams3a": null, |
| 23 | }, |
| 24 | }, |
| 25 | }, |
| 26 | }, |
| 27 | }, |
| 28 | "api", |
| 29 | ); |
| 30 | |
| 31 | expect(activeReplicaRegions(placement)).toEqual([ |
| 32 | { region: "asia-southeast1-eqsg3a", replicas: 1 }, |
| 33 | ]); |
| 34 | expect(observedRegion(placement, null)).toEqual("asia-southeast1-eqsg3a"); |
| 35 | }); |
| 36 | |
| 37 | it("moves the workspace default onto the requested region", () => { |
| 38 | const placement = { |
| 39 | "asia-southeast1-eqsg3a": { numReplicas: 1 }, |
| 40 | }; |
| 41 | |
| 42 | expect(regionPlacementPatch("europe-west4-drams3a", placement)).toEqual({ |
| 43 | "europe-west4-drams3a": { numReplicas: 1 }, |
| 44 | "asia-southeast1-eqsg3a": null, |
| 45 | }); |
| 46 | }); |
| 47 | |
| 48 | it("keeps an existing replica count on the target region", () => { |
| 49 | expect( |
| 50 | regionPlacementPatch("us-west2", { |
| 51 | "us-west2": { numReplicas: 3 }, |
| 52 | "us-east4-eqdc4a": { numReplicas: 1 }, |
| 53 | }), |
| 54 | ).toEqual({ |
| 55 | "us-west2": { numReplicas: 3 }, |
| 56 | "us-east4-eqdc4a": null, |
| 57 | }); |
| 58 | }); |
| 59 | |
| 60 | it("leaves a service that is already only in the requested region", () => { |
| 61 | expect( |
| 62 | regionPlacementPatch("us-west2", { |
| 63 | "us-west2": { numReplicas: 2 }, |
| 64 | "europe-west4-drams3a": null, |
| 65 | }), |
| 66 | ).toBeUndefined(); |
| 67 | }); |
| 68 | |
| 69 | it("uses the legacy replica count when placement is empty", () => { |
| 70 | expect(regionPlacementPatch("us-west2", {}, 4)).toEqual({ |
| 71 | "us-west2": { numReplicas: 4 }, |
| 72 | }); |
| 73 | }); |
| 74 | }, |
| 75 | ); |