Generate 6-char hash IDs with progressive 7/8-char fallback on collision (bd-7c87cf24)
- Changed generateHashID to start with 6 chars (3 bytes), expand to 7/8 on collision - Updated both CreateIssue and CreateIssues (batch) to use progressive length fallback - Updated tests to accept 9-11 char IDs (bd- + 6-8 hex chars) - All new issues now generate with shorter, more readable IDs - Existing 8-char IDs preserved (no migration needed) Amp-Thread-ID: https://ampcode.com/threads/T-8a6058af-9f42-4bff-be02-8c8bce41eeb5 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -38,9 +38,9 @@ func TestHashIDGeneration(t *testing.T) {
|
||||
t.Fatalf("Failed to create issue: %v", err)
|
||||
}
|
||||
|
||||
// Verify hash ID format: bd-<8 hex chars>
|
||||
if len(issue.ID) != 11 { // "bd-" (3) + 8 hex chars = 11
|
||||
t.Errorf("Expected ID length 11, got %d: %s", len(issue.ID), issue.ID)
|
||||
// Verify hash ID format: bd-<6 hex chars> (or 7/8 on collision)
|
||||
if len(issue.ID) < 9 || len(issue.ID) > 11 { // "bd-" (3) + 6-8 hex chars = 9-11
|
||||
t.Errorf("Expected ID length 9-11, got %d: %s", len(issue.ID), issue.ID)
|
||||
}
|
||||
|
||||
if issue.ID[:3] != "bd-" {
|
||||
@@ -66,8 +66,8 @@ func TestHashIDDeterministic(t *testing.T) {
|
||||
actor := "test-actor"
|
||||
timestamp := time.Now()
|
||||
|
||||
id1 := generateHashID(prefix, title, description, actor, timestamp, 0)
|
||||
id2 := generateHashID(prefix, title, description, actor, timestamp, 0)
|
||||
id1 := generateHashID(prefix, title, description, actor, timestamp, 6, 0)
|
||||
id2 := generateHashID(prefix, title, description, actor, timestamp, 6, 0)
|
||||
|
||||
if id1 != id2 {
|
||||
t.Errorf("Expected same hash for same inputs, got %s and %s", id1, id2)
|
||||
@@ -187,9 +187,9 @@ func TestHashIDBatchCreation(t *testing.T) {
|
||||
}
|
||||
ids[issue.ID] = true
|
||||
|
||||
// Verify hash ID format
|
||||
if len(issue.ID) != 11 {
|
||||
t.Errorf("Expected ID length 11, got %d: %s", len(issue.ID), issue.ID)
|
||||
// Verify hash ID format (6-8 chars)
|
||||
if len(issue.ID) < 9 || len(issue.ID) > 11 {
|
||||
t.Errorf("Expected ID length 9-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)
|
||||
|
||||
Reference in New Issue
Block a user