Skip to content

πŸ’« Toolkit to help you get started with SDD or any other process!

fix(scripts): use case-sensitive match for acronym retention in PS branch names (#3130)

Quratulain-bilal37e0e71b4ec2
diff --git a/scripts/powershell/create-new-feature.ps1 b/scripts/powershell/create-new-feature.ps1
index 8627caa6e..12f15ba31 100644
--- a/scripts/powershell/create-new-feature.ps1
+++ b/scripts/powershell/create-new-feature.ps1
@@ -111,8 +111,11 @@ function Get-BranchName {
# Keep words that are length >= 3 OR appear as uppercase in original (likely acronyms)
if ($word.Length -ge 3) {
$meaningfulWords += $word
- } elseif ($Description -match "\b$($word.ToUpper())\b") {
- # Keep short words if they appear as uppercase in original (likely acronyms)
+ } elseif ($Description -cmatch "\b$($word.ToUpper())\b") {
+ # Keep short words only if they appear as uppercase in original (likely
+ # acronyms). Use -cmatch so the comparison is case-sensitive, matching the
+ # bash script's case-sensitive grep; -match would be case-insensitive and
+ # would keep every short word.
$meaningfulWords += $word
}
}
diff --git a/tests/test_timestamp_branches.py b/tests/test_timestamp_branches.py
index 1856afb97..aa48a597f 100644
--- a/tests/test_timestamp_branches.py
+++ b/tests/test_timestamp_branches.py
@@ -869,6 +869,52 @@ class TestPowerShellDryRun:
assert "DRY_RUN" not in data, f"DRY_RUN should not be in normal JSON: {data}"
+# ── Short-Word / Acronym Branch-Name Tests ──────────────────────────────────
+
+
+def _branch_from_output(stdout: str) -> str | None:
+ for line in stdout.splitlines():
+ if line.startswith("BRANCH_NAME:"):
+ return line.split(":", 1)[1].strip()
+ return None
+
+
+SHORT_WORD_CASES = [
+ # description, expected branch β€” "go" (lowercase short word) is dropped,
+ # "AI" (uppercase short word / acronym) is kept, "now" (>=3 chars) is kept.
+ ("go AI now", "001-ai-now"),
+ # A short word that is lowercase everywhere is dropped entirely.
+ ("go to the pub", "001-pub"),
+]
+
+
+@requires_bash
+class TestShortWordRetentionBash:
+ """A short word is kept only when it appears in uppercase (an acronym)."""
+
+ @pytest.mark.parametrize("description,expected", SHORT_WORD_CASES)
+ def test_short_word_retention(self, git_repo: Path, description: str, expected: str):
+ result = run_script(git_repo, "--dry-run", description)
+ assert result.returncode == 0, result.stderr
+ assert _branch_from_output(result.stdout) == expected
+
+
[email protected](not _has_pwsh(), reason="pwsh not available")
+class TestShortWordRetentionPowerShell:
+ """PowerShell must match bash: a short word is kept only when uppercase.
+
+ Regression guard for the `-match` (case-insensitive) vs `-cmatch`
+ (case-sensitive) divergence β€” with `-match`, every short non-stop word
+ leaked into the branch name even when it was lowercase.
+ """
+
+ @pytest.mark.parametrize("description,expected", SHORT_WORD_CASES)
+ def test_short_word_retention(self, ps_git_repo: Path, description: str, expected: str):
+ result = run_ps_script(ps_git_repo, "-DryRun", description)
+ assert result.returncode == 0, result.stderr
+ assert _branch_from_output(result.stdout) == expected
+
+
# ── GIT_BRANCH_NAME Override Tests ──────────────────────────────────────────