Switch from hex to Base36 encoding for issue IDs (GH #213)

This change improves information density by using Base36 (0-9, a-z) instead
of hex (0-9, a-f) for hash-based issue IDs. Key benefits:

- Shorter IDs: Can now use 3-char IDs (was 4-char minimum)
- Better scaling: 3 chars good for ~160 issues, 4 chars for ~980 issues
- Case-insensitive: Maintains excellent CLI usability
- Backward compatible: Old hex IDs continue to work

Changes:
- Implemented Base36 encoding with proper truncation (keep LSB)
- Updated adaptive length thresholds (3-8 chars instead of 4-8)
- Fixed collision probability math to match encoding (was calculating
  for base36 but encoding in hex - now both use base36)
- Fixed ID parser bug (use prefixWithHyphen for substring matching)
- Updated all tests and test data patterns

Fixes #213

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-03 12:02:15 -08:00
parent add5599d7e
commit b4cb636d92
14 changed files with 176 additions and 89 deletions

View File

@@ -35,10 +35,10 @@ func TestHashIDGeneration(t *testing.T) {
t.Fatalf("Failed to create issue: %v", err)
}
// Verify hash ID format: bd-<4-8 hex chars> with adaptive length (bd-ea2a13)
// For empty/small database, should use 4 chars
if len(issue.ID) < 7 || len(issue.ID) > 11 { // "bd-" (3) + 4-8 hex chars = 7-11
t.Errorf("Expected ID length 7-11, got %d: %s", len(issue.ID), issue.ID)
// Verify hash ID format: bd-<3-8 base36 chars> with adaptive length
// For empty/small database, should use 3 chars
if len(issue.ID) < 6 || len(issue.ID) > 11 { // "bd-" (3) + 3-8 base36 chars = 6-11
t.Errorf("Expected ID length 6-11, got %d: %s", len(issue.ID), issue.ID)
}
if issue.ID[:3] != "bd-" {
@@ -182,9 +182,9 @@ func TestHashIDBatchCreation(t *testing.T) {
}
ids[issue.ID] = true
// Verify hash ID format (4-8 chars with adaptive length)
if len(issue.ID) < 7 || len(issue.ID) > 11 {
t.Errorf("Expected ID length 7-11, got %d: %s", len(issue.ID), issue.ID)
// Verify hash ID format (3-8 chars with adaptive length)
if len(issue.ID) < 6 || len(issue.ID) > 11 {
t.Errorf("Expected ID length 6-11, got %d: %s", len(issue.ID), issue.ID)
}
if issue.ID[:3] != "bd-" {
t.Errorf("Expected ID to start with 'bd-', got: %s", issue.ID)