Skip to content

Commit ac85969

Browse files
committed
fix(webapp): make dev branch shortcodes deterministic
1 parent e236e0f commit ac85969

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { logger } from "./logger.server";
1717
import { getCurrentPlan, getLimit } from "./platform.v3.server";
1818
import { type z } from "zod";
1919
import invariant from "tiny-invariant";
20-
import { nanoid } from "nanoid";
2120
import { type CreateBranchOptions } from "~/utils/branches";
2221
import {
2322
applyBillingLimitPauseAfterEnvCreate,
@@ -148,8 +147,11 @@ export class UpsertBranchService {
148147
const pkApiKey = createPkApiKeyForEnv(parentEnvironment.type);
149148
const isDevelopmentBranch = parentEnvironment.type === "DEVELOPMENT";
150149
// Dev branch slugs are member-scoped, but shortcodes remain project-scoped.
151-
// Keep the readable slug while giving each member's branch a unique shortcode.
152-
const shortcode = isDevelopmentBranch ? `${branchSlug}-${nanoid()}` : branchSlug;
150+
// The parent shortcode is already unique within the project, so it gives
151+
// each member's branch a stable, readable shortcode without a migration.
152+
const shortcode = isDevelopmentBranch
153+
? `${branchSlug}-${parentEnvironment.shortcode}`
154+
: branchSlug;
153155
let branchWhere: Prisma.RuntimeEnvironmentWhereUniqueInput;
154156
if (isDevelopmentBranch) {
155157
invariant(parentEnvironment.orgMemberId, "Development branches require an org member");

apps/webapp/test/devBranchServices.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe("UpsertBranchService — DEVELOPMENT parent", () => {
9797
},
9898
});
9999

100-
await Promise.all([
100+
const [firstRoot, secondRoot] = await Promise.all([
101101
createDevRoot(prisma, project.id, organization.id, firstMember.id),
102102
createDevRoot(prisma, project.id, organization.id, secondMember.id),
103103
]);
@@ -122,7 +122,8 @@ describe("UpsertBranchService — DEVELOPMENT parent", () => {
122122
if (!firstResult.success || !secondResult.success) return;
123123
expect(firstResult.branch.id).not.toBe(secondResult.branch.id);
124124
expect(firstResult.branch.slug).toBe(secondResult.branch.slug);
125-
expect(firstResult.branch.shortcode).not.toBe(secondResult.branch.shortcode);
125+
expect(firstResult.branch.shortcode).toBe(`dev-shared-name-${firstRoot.shortcode}`);
126+
expect(secondResult.branch.shortcode).toBe(`dev-shared-name-${secondRoot.shortcode}`);
126127
expect(firstResult.branch.orgMemberId).toBe(firstMember.id);
127128
expect(secondResult.branch.orgMemberId).toBe(secondMember.id);
128129

0 commit comments

Comments
 (0)