fix(utils): parse multi-hyphen prefixes correctly (GH#405)

The ExtractIssuePrefix function was falling back to first-hyphen
extraction when the suffix didn't look like a hash (e.g., 4+ char
words without digits). This broke prefixes like 'hacker-news' where
an issue ID 'hacker-news-test' would incorrectly extract 'hacker'.

Fix: Always use last-hyphen extraction for alphanumeric suffixes.
Only fall back to first-hyphen for non-alphanumeric suffixes.

Examples:
- 'hacker-news-test' -> 'hacker-news' (was: 'hacker')
- 'me-py-toolkit-abc' -> 'me-py-toolkit' (was: 'me')
- 'vc-baseline-hello' -> 'vc-baseline' (was: 'vc')

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-16 01:13:15 -08:00
parent 50608ce3a5
commit 77aeb50d27
5 changed files with 252 additions and 235 deletions

View File

@@ -43,16 +43,18 @@ func TestExtractIssuePrefixAllLetterHash(t *testing.T) {
}
}
// TestExtractIssuePrefixWordSuffix ensures 4+ char word suffixes still work
// TestExtractIssuePrefixWordSuffix tests alphanumeric suffixes (GH#405 fix)
// With the GH#405 fix, all alphanumeric suffixes use last-hyphen extraction,
// even if they look like English words. This fixes multi-hyphen prefix parsing.
func TestExtractIssuePrefixWordSuffix(t *testing.T) {
// These should use first-hyphen extraction (word suffixes, not hashes)
// These should use last-hyphen extraction (alphanumeric = valid issue ID suffix)
wordSuffixes := []struct {
issueID string
expected string
}{
{"vc-baseline-test", "vc"}, // 4-char "test" - word, not hash
{"vc-baseline-hello", "vc"}, // 5-char word
{"vc-some-feature", "vc"}, // multi-word suffix
{"vc-baseline-test", "vc-baseline"}, // GH#405: alphanumeric suffix uses last hyphen
{"vc-baseline-hello", "vc-baseline"}, // GH#405: alphanumeric suffix uses last hyphen
{"vc-some-feature", "vc-some"}, // GH#405: alphanumeric suffix uses last hyphen
}
for _, tc := range wordSuffixes {