Skip to content

Commit a64f557

Browse files
committed
fix: correcting build
1 parent d735af4 commit a64f557

File tree

5 files changed

+390
-56
lines changed

5 files changed

+390
-56
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ upgrade:
147147
upgrade
148148

149149
tidy: fmt
150-
tidy
150+
go mod tidy
151151

152152
release:
153153
if [ -z "$(tag)" ]; then echo "tag is required"; exit 1; fi

cmd/canary/bug.go

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,29 @@ Examples:
7272
filters["status"] = status
7373
}
7474

75-
// Query database for BUG-* tokens
76-
tokens, err := db.ListTokens(filters, "BUG-[A-Za-z]+-[0-9]{3}", "priority ASC, updated_at DESC", limit)
75+
// Query database for all tokens (ListTokens is hardcoded for CBIN patterns)
76+
allTokens, err := db.ListTokens(filters, "", "priority ASC, updated_at DESC", 0)
7777
if err != nil {
7878
return fmt.Errorf("query bugs: %w", err)
7979
}
8080

81+
// Filter for BUG tokens only
82+
var tokens []*storage.Token
83+
bugPattern := regexp.MustCompile(`^BUG-[A-Za-z]+-[0-9]{3}$`)
84+
for _, tok := range allTokens {
85+
if bugPattern.MatchString(tok.ReqID) {
86+
tokens = append(tokens, tok)
87+
}
88+
}
89+
8190
// Additional filtering for severity and priority (stored in token comments or metadata)
8291
filteredTokens := filterBugTokens(tokens, severity, priority)
8392

93+
// Apply limit if specified
94+
if limit > 0 && len(filteredTokens) > limit {
95+
filteredTokens = filteredTokens[:limit]
96+
}
97+
8498
if jsonOutput {
8599
enc := json.NewEncoder(os.Stdout)
86100
enc.SetIndent("", " ")
@@ -389,21 +403,31 @@ func generateBugID(aspect string, dbPath string) (string, error) {
389403
}
390404
defer db.Close()
391405

392-
// Query existing BUG tokens for this aspect
393-
pattern := fmt.Sprintf("BUG-%s-[0-9]{3}", aspect)
394-
tokens, err := db.ListTokens(nil, pattern, "req_id DESC", 1)
406+
return generateBugIDWithDB(aspect, db)
407+
}
408+
409+
func generateBugIDWithDB(aspect string, db *storage.DB) (string, error) {
410+
// Normalize aspect to uppercase
411+
aspect = strings.ToUpper(aspect)
412+
413+
// Query ALL tokens (no pattern filter since ListTokens is hardcoded for CBIN)
414+
tokens, err := db.ListTokens(nil, "", "req_id DESC", 0) // Get all tokens
395415
if err != nil {
396416
// If database doesn't have tokens table yet, start from 001
397417
return fmt.Sprintf("BUG-%s-001", aspect), nil
398418
}
399419

400-
// Find highest number
420+
// Find highest number for this aspect
401421
maxNum := 0
402-
if len(tokens) > 0 {
403-
// Extract number from last token
404-
re := regexp.MustCompile(`BUG-[A-Za-z]+-([0-9]{3})`)
405-
if matches := re.FindStringSubmatch(tokens[0].ReqID); len(matches) > 1 {
406-
maxNum, _ = strconv.Atoi(matches[1])
422+
pattern := fmt.Sprintf(`BUG-%s-([0-9]{3})`, aspect)
423+
re := regexp.MustCompile(pattern)
424+
for _, token := range tokens {
425+
// Extract number from matching tokens
426+
if matches := re.FindStringSubmatch(token.ReqID); len(matches) > 1 {
427+
num, _ := strconv.Atoi(matches[1])
428+
if num > maxNum {
429+
maxNum = num
430+
}
407431
}
408432
}
409433

cmd/canary/bug_test.go

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,30 @@ func TestGenerateBugID(t *testing.T) {
4141

4242
// Add some existing bug tokens
4343
tokens := []*storage.Token{
44-
{ReqID: "BUG-API-001", Feature: "Bug 1", Aspect: "API", Status: "OPEN", FilePath: "test.go", LineNumber: 1, UpdatedAt: "2025-10-18"},
45-
{ReqID: "BUG-API-002", Feature: "Bug 2", Aspect: "API", Status: "OPEN", FilePath: "test.go", LineNumber: 2, UpdatedAt: "2025-10-18"},
46-
{ReqID: "BUG-API-005", Feature: "Bug 5", Aspect: "API", Status: "OPEN", FilePath: "test.go", LineNumber: 5, UpdatedAt: "2025-10-18"},
44+
{ReqID: "BUG-API-001", Feature: "Bug 1", Aspect: "API", Status: "OPEN", FilePath: "main.go", LineNumber: 1, UpdatedAt: "2025-10-18"},
45+
{ReqID: "BUG-API-002", Feature: "Bug 2", Aspect: "API", Status: "OPEN", FilePath: "main.go", LineNumber: 2, UpdatedAt: "2025-10-18"},
46+
{ReqID: "BUG-API-005", Feature: "Bug 5", Aspect: "API", Status: "OPEN", FilePath: "main.go", LineNumber: 5, UpdatedAt: "2025-10-18"},
4747
}
4848

4949
for _, token := range tokens {
5050
if err := db.UpsertToken(token); err != nil {
5151
t.Fatalf("Failed to insert token: %v", err)
5252
}
53+
t.Logf("Inserted token: %s", token.ReqID)
54+
}
55+
56+
// Check what tokens are in the database
57+
allTokens, err := db.ListTokens(nil, "", "req_id ASC", 0)
58+
if err != nil {
59+
t.Logf("Error listing tokens: %v", err)
60+
}
61+
t.Logf("Tokens found before generating new ID: %d", len(allTokens))
62+
for _, tok := range allTokens {
63+
t.Logf(" - %s", tok.ReqID)
5364
}
5465

5566
// Generate next ID (should be 006)
56-
bugID, err = generateBugID("API", dbPath)
67+
bugID, err = generateBugIDWithDB("API", db)
5768
if err != nil {
5869
t.Fatalf("Failed to generate bug ID: %v", err)
5970
}
@@ -63,7 +74,7 @@ func TestGenerateBugID(t *testing.T) {
6374
}
6475

6576
// Test with different aspect
66-
bugID, err = generateBugID("CLI", dbPath)
77+
bugID, err = generateBugIDWithDB("CLI", db)
6778
if err != nil {
6879
t.Fatalf("Failed to generate bug ID: %v", err)
6980
}
@@ -138,7 +149,7 @@ func TestParsePriorityValue(t *testing.T) {
138149
{"P1", 1},
139150
{"P2", 2},
140151
{"P3", 3},
141-
{"", 2}, // default
152+
{"", 2}, // default
142153
{"invalid", 2}, // default
143154
}
144155

@@ -160,51 +171,51 @@ func TestFilterBugTokens(t *testing.T) {
160171
}
161172

162173
tests := []struct {
163-
name string
164-
severity string
165-
priority string
174+
name string
175+
severity string
176+
priority string
166177
expectedCount int
167178
}{
168179
{
169-
name: "filter by severity S1",
170-
severity: "S1",
171-
priority: "",
180+
name: "filter by severity S1",
181+
severity: "S1",
182+
priority: "",
172183
expectedCount: 1,
173184
},
174185
{
175-
name: "filter by priority P0",
176-
severity: "",
177-
priority: "P0",
186+
name: "filter by priority P0",
187+
severity: "",
188+
priority: "P0",
178189
expectedCount: 1,
179190
},
180191
{
181-
name: "filter by multiple severities",
182-
severity: "S1,S2",
183-
priority: "",
192+
name: "filter by multiple severities",
193+
severity: "S1,S2",
194+
priority: "",
184195
expectedCount: 2,
185196
},
186197
{
187-
name: "filter by multiple priorities",
188-
severity: "",
189-
priority: "P0,P1",
198+
name: "filter by multiple priorities",
199+
severity: "",
200+
priority: "P0,P1",
190201
expectedCount: 2,
191202
},
192203
{
193-
name: "filter by both",
194-
severity: "S1",
195-
priority: "P0",
204+
name: "filter by both",
205+
severity: "S1",
206+
priority: "P0",
196207
expectedCount: 1,
197208
},
198209
{
199-
name: "no filters",
200-
severity: "",
201-
priority: "",
210+
name: "no filters",
211+
severity: "",
212+
priority: "",
202213
expectedCount: 4,
203214
},
204215
{
205-
name: "non-matching filter",
206-
severity: "S5",
207-
priority: "",
216+
name: "non-matching filter",
217+
severity: "S5",
218+
priority: "",
208219
expectedCount: 0,
209220
},
210221
}
@@ -231,9 +242,9 @@ func TestBugIDValidation(t *testing.T) {
231242
{"BUG-API-001", true},
232243
{"BUG-CLI-123", true},
233244
{"BUG-Storage-999", true},
234-
{"BUG-api-001", true}, // lowercase aspect
235-
{"CBIN-001", false}, // wrong prefix
236-
{"BUG-API-1", false}, // not 3 digits
245+
{"BUG-api-001", true}, // lowercase aspect
246+
{"CBIN-001", false}, // wrong prefix
247+
{"BUG-API-1", false}, // not 3 digits
237248
{"BUG-API-1234", false}, // too many digits
238249
{"BUG-API", false}, // no number
239250
{"BUG--001", false}, // empty aspect
@@ -285,7 +296,7 @@ func TestBugCommandIntegration(t *testing.T) {
285296
Feature: bug.title,
286297
Aspect: bug.aspect,
287298
Status: bug.status,
288-
FilePath: "test.go",
299+
FilePath: "main.go",
289300
LineNumber: i + 1,
290301
UpdatedAt: "2025-10-18",
291302
Priority: parsePriorityValue(bug.priority),
@@ -299,12 +310,21 @@ func TestBugCommandIntegration(t *testing.T) {
299310
})
300311

301312
t.Run("list bug tokens", func(t *testing.T) {
302-
// List all BUG tokens
303-
tokens, err := db.ListTokens(nil, "BUG-[A-Za-z]+-[0-9]{3}", "priority ASC", 0)
313+
// List all tokens (empty pattern) and filter BUG tokens manually
314+
allTokens, err := db.ListTokens(nil, "", "priority ASC", 0)
304315
if err != nil {
305316
t.Fatalf("Failed to list bugs: %v", err)
306317
}
307318

319+
// Filter for BUG tokens
320+
var tokens []*storage.Token
321+
bugPattern := regexp.MustCompile(`^BUG-[A-Za-z]+-[0-9]{3}$`)
322+
for _, tok := range allTokens {
323+
if bugPattern.MatchString(tok.ReqID) {
324+
tokens = append(tokens, tok)
325+
}
326+
}
327+
308328
if len(tokens) != 4 {
309329
t.Errorf("Expected 4 bugs, got %d", len(tokens))
310330
}
@@ -317,11 +337,20 @@ func TestBugCommandIntegration(t *testing.T) {
317337

318338
t.Run("filter by status", func(t *testing.T) {
319339
filters := map[string]string{"status": "OPEN"}
320-
tokens, err := db.ListTokens(filters, "BUG-[A-Za-z]+-[0-9]{3}", "priority ASC", 0)
340+
allTokens, err := db.ListTokens(filters, "", "priority ASC", 0)
321341
if err != nil {
322342
t.Fatalf("Failed to filter bugs: %v", err)
323343
}
324344

345+
// Filter for BUG tokens
346+
var tokens []*storage.Token
347+
bugPattern := regexp.MustCompile(`^BUG-[A-Za-z]+-[0-9]{3}$`)
348+
for _, tok := range allTokens {
349+
if bugPattern.MatchString(tok.ReqID) {
350+
tokens = append(tokens, tok)
351+
}
352+
}
353+
325354
if len(tokens) != 2 {
326355
t.Errorf("Expected 2 OPEN bugs, got %d", len(tokens))
327356
}

0 commit comments

Comments
 (0)