Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
branch-rename.test.ts9.7 KB · 341 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/**
 * Block J24 — Branch rename. Pure validation + plan tests.
 */

import { describe, it, expect } from "bun:test";
import {
  MAX_BRANCH_NAME_LENGTH,
  validateBranchName,
  branchValidationMessage,
  planRename,
  shouldRewriteProtectionPattern,
  __internal,
} from "../lib/branch-rename";

describe("branch-rename — validateBranchName (valid cases)", () => {
  it("accepts simple names", () => {
    expect(validateBranchName("main").ok).toBe(true);
    expect(validateBranchName("develop").ok).toBe(true);
    expect(validateBranchName("release").ok).toBe(true);
  });

  it("accepts slash-separated components", () => {
    expect(validateBranchName("feat/login").ok).toBe(true);
    expect(validateBranchName("release/v1.0").ok).toBe(true);
    expect(validateBranchName("release/v1.0.0-rc.1").ok).toBe(true);
  });

  it("accepts numeric + underscore + hyphen", () => {
    expect(validateBranchName("123abc").ok).toBe(true);
    expect(validateBranchName("snake_case_branch").ok).toBe(true);
    expect(validateBranchName("kebab-case-branch").ok).toBe(true);
  });

  it("accepts names up to MAX_BRANCH_NAME_LENGTH", () => {
    const maxName = "a".repeat(MAX_BRANCH_NAME_LENGTH);
    expect(validateBranchName(maxName).ok).toBe(true);
  });

  it("accepts single dots inside components", () => {
    expect(validateBranchName("v1.0.0").ok).toBe(true);
  });
});

describe("branch-rename — validateBranchName (invalid cases)", () => {
  it("rejects non-string", () => {
    expect(validateBranchName(null).ok).toBe(false);
    expect(validateBranchName(undefined).ok).toBe(false);
    expect(validateBranchName(123).ok).toBe(false);
  });

  it("rejects empty string", () => {
    const r = validateBranchName("");
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("empty");
  });

  it("rejects too-long names", () => {
    const r = validateBranchName("a".repeat(MAX_BRANCH_NAME_LENGTH + 1));
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("too_long");
  });

  it("rejects a bare '@'", () => {
    const r = validateBranchName("@");
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("only_at");
  });

  it("rejects '@{'", () => {
    const r = validateBranchName("foo@{1}");
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("at_brace");
  });

  it("rejects leading or trailing '/'", () => {
    expect(validateBranchName("/foo").ok).toBe(false);
    expect(validateBranchName("foo/").ok).toBe(false);
  });

  it("rejects '//' anywhere", () => {
    expect(validateBranchName("foo//bar").ok).toBe(false);
  });

  it("rejects leading '-'", () => {
    const r = validateBranchName("-no");
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("leading_dash");
  });

  it("rejects leading or trailing '.'", () => {
    expect(validateBranchName(".foo").ok).toBe(false);
    expect(validateBranchName("foo.").ok).toBe(false);
  });

  it("rejects '..'", () => {
    const r = validateBranchName("foo..bar");
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("double_dot");
  });

  it("rejects '.lock' suffix", () => {
    expect(validateBranchName("foo.lock").ok).toBe(false);
  });

  it("rejects '.lock' on a component", () => {
    const r = validateBranchName("release/v1.lock");
    expect(r.ok).toBe(false);
    if (!r.ok) {
      // either `lock_suffix` (whole name) or `lock_component` — both valid
      expect(["lock_suffix", "lock_component"]).toContain(r.reason);
    }
  });

  it("rejects whitespace", () => {
    expect(validateBranchName("has space").ok).toBe(false);
    expect(validateBranchName("has\ttab").ok).toBe(false);
  });

  it("rejects forbidden characters", () => {
    for (const ch of ["~", "^", ":", "?", "*", "[", "\\"]) {
      expect(validateBranchName(`foo${ch}bar`).ok).toBe(false);
    }
  });

  it("rejects control characters", () => {
    expect(validateBranchName("foo\u0001bar").ok).toBe(false);
    expect(validateBranchName("foo\u001fbar").ok).toBe(false);
    expect(validateBranchName("foo\u007fbar").ok).toBe(false);
  });

  it("rejects component starting or ending with '.'", () => {
    expect(validateBranchName("release/.hidden").ok).toBe(false);
    expect(validateBranchName("release/trailing.").ok).toBe(false);
  });
});

describe("branch-rename — branchValidationMessage", () => {
  it("returns non-empty strings for every reason code", () => {
    const reasons = [
      "not_string",
      "empty",
      "too_long",
      "slash_boundary",
      "leading_dash",
      "dot_boundary",
      "consecutive_slashes",
      "double_dot",
      "at_brace",
      "only_at",
      "lock_suffix",
      "forbidden_char",
      "control_char",
      "empty_component",
      "dot_component",
      "lock_component",
    ] as const;
    for (const r of reasons) {
      const msg = branchValidationMessage(r);
      expect(typeof msg).toBe("string");
      expect(msg.length).toBeGreaterThan(0);
    }
  });
});

describe("branch-rename — planRename", () => {
  const existing = ["main", "develop", "feat/login"];

  it("approves a valid rename", () => {
    const r = planRename({
      from: "feat/login",
      to: "feat/auth",
      existingBranches: existing,
      defaultBranch: "main",
    });
    expect(r.ok).toBe(true);
    if (r.ok) {
      expect(r.from).toBe("feat/login");
      expect(r.to).toBe("feat/auth");
      expect(r.updatesDefault).toBe(false);
    }
  });

  it("flags rename of the default branch", () => {
    const r = planRename({
      from: "main",
      to: "trunk",
      existingBranches: existing,
      defaultBranch: "main",
    });
    expect(r.ok).toBe(true);
    if (r.ok) expect(r.updatesDefault).toBe(true);
  });

  it("rejects same-name rename", () => {
    const r = planRename({
      from: "main",
      to: "main",
      existingBranches: existing,
      defaultBranch: "main",
    });
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("same_name");
  });

  it("rejects missing source branch", () => {
    const r = planRename({
      from: "ghost",
      to: "new",
      existingBranches: existing,
      defaultBranch: "main",
    });
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("from_missing");
  });

  it("rejects when destination already exists", () => {
    const r = planRename({
      from: "feat/login",
      to: "develop",
      existingBranches: existing,
      defaultBranch: "main",
    });
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("to_exists");
  });

  it("rejects invalid source name", () => {
    const r = planRename({
      from: "bad..name",
      to: "ok",
      existingBranches: existing,
      defaultBranch: "main",
    });
    expect(r.ok).toBe(false);
    if (!r.ok) {
      expect(r.reason).toBe("invalid_from");
      expect(r.detail).toBe("double_dot");
    }
  });

  it("rejects invalid destination name", () => {
    const r = planRename({
      from: "main",
      to: "has space",
      existingBranches: existing,
      defaultBranch: "main",
    });
    expect(r.ok).toBe(false);
    if (!r.ok) {
      expect(r.reason).toBe("invalid_to");
      expect(r.detail).toBe("forbidden_char");
    }
  });

  it("is case-sensitive ('Main' and 'main' are different)", () => {
    const r = planRename({
      from: "main",
      to: "Main",
      existingBranches: ["main"],
      defaultBranch: "main",
    });
    expect(r.ok).toBe(true);
  });

  it("handles empty existingBranches", () => {
    const r = planRename({
      from: "main",
      to: "trunk",
      existingBranches: [],
      defaultBranch: null,
    });
    expect(r.ok).toBe(false);
    if (!r.ok) expect(r.reason).toBe("from_missing");
  });

  it("does not mark updatesDefault when defaultBranch is null", () => {
    const r = planRename({
      from: "main",
      to: "trunk",
      existingBranches: ["main"],
      defaultBranch: null,
    });
    expect(r.ok).toBe(true);
    if (r.ok) expect(r.updatesDefault).toBe(false);
  });
});

describe("branch-rename — shouldRewriteProtectionPattern", () => {
  it("rewrites an exact match", () => {
    expect(shouldRewriteProtectionPattern("main", "main")).toBe(true);
  });

  it("does not rewrite a different exact", () => {
    expect(shouldRewriteProtectionPattern("main", "develop")).toBe(false);
  });

  it("does not rewrite globs even if they match", () => {
    expect(shouldRewriteProtectionPattern("release/*", "release/*")).toBe(
      false
    );
  });

  it("does not rewrite ? or [ globs", () => {
    expect(shouldRewriteProtectionPattern("feat/?", "feat/?")).toBe(false);
    expect(shouldRewriteProtectionPattern("feat/[abc]", "feat/[abc]")).toBe(
      false
    );
  });
});

describe("branch-rename — routes", () => {
  it("GET /settings/branches redirects unauthenticated users", async () => {
    const { default: app } = await import("../app");
    const res = await app.request("/alice/repo/settings/branches");
    expect([302, 401, 403, 404]).toContain(res.status);
  });

  it("POST rename redirects unauthenticated users", async () => {
    const { default: app } = await import("../app");
    const form = new FormData();
    form.append("from", "main");
    form.append("to", "trunk");
    const res = await app.request(
      "/alice/repo/settings/branches/rename",
      { method: "POST", body: form }
    );
    expect([302, 401, 403, 404]).toContain(res.status);
  });
});

describe("branch-rename — __internal parity", () => {
  it("re-exports helpers", () => {
    expect(__internal.validateBranchName).toBe(validateBranchName);
    expect(__internal.planRename).toBe(planRename);
    expect(__internal.branchValidationMessage).toBe(branchValidationMessage);
    expect(__internal.shouldRewriteProtectionPattern).toBe(
      shouldRewriteProtectionPattern
    );
    expect(__internal.MAX_BRANCH_NAME_LENGTH).toBe(MAX_BRANCH_NAME_LENGTH);
  });
});