Skip to content

Commit f25808f

Browse files
committed
feat(webapp): inherit region on preview branches + test resolver
Preview branches copy the parent env's defaultWorkerGroupId. Adds a unit test for the env -> project -> global fallback order.
1 parent b517650 commit f25808f

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

apps/webapp/app/services/upsertBranch.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export class UpsertBranchService {
119119
pkApiKey,
120120
shortcode,
121121
maximumConcurrencyLimit: parentEnvironment.maximumConcurrencyLimit,
122+
// Inherit the region from the parent preview environment.
123+
defaultWorkerGroupId: parentEnvironment.defaultWorkerGroupId,
122124
organization: {
123125
connect: {
124126
id: parentEnvironment.organization.id,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, expect, it } from "vitest";
2+
import { resolveEffectiveDefaultWorkerGroupId } from "~/v3/regionAccess.server";
3+
4+
describe("resolveEffectiveDefaultWorkerGroupId", () => {
5+
it("prefers the environment default", () => {
6+
expect(
7+
resolveEffectiveDefaultWorkerGroupId({
8+
environmentDefaultWorkerGroupId: "env",
9+
projectDefaultWorkerGroupId: "project",
10+
globalDefaultWorkerGroupId: "global",
11+
})
12+
).toBe("env");
13+
});
14+
15+
it("falls back to the project default when the environment has none", () => {
16+
expect(
17+
resolveEffectiveDefaultWorkerGroupId({
18+
environmentDefaultWorkerGroupId: null,
19+
projectDefaultWorkerGroupId: "project",
20+
globalDefaultWorkerGroupId: "global",
21+
})
22+
).toBe("project");
23+
});
24+
25+
it("falls back to the global default when env and project have none", () => {
26+
expect(
27+
resolveEffectiveDefaultWorkerGroupId({
28+
environmentDefaultWorkerGroupId: null,
29+
projectDefaultWorkerGroupId: null,
30+
globalDefaultWorkerGroupId: "global",
31+
})
32+
).toBe("global");
33+
});
34+
35+
it("returns undefined when nothing is set", () => {
36+
expect(
37+
resolveEffectiveDefaultWorkerGroupId({
38+
environmentDefaultWorkerGroupId: null,
39+
projectDefaultWorkerGroupId: null,
40+
globalDefaultWorkerGroupId: null,
41+
})
42+
).toBeUndefined();
43+
});
44+
});

0 commit comments

Comments
 (0)