Fix goconst linter warnings by converting repeated strings to constants

- Added testUserAlice constant for 'alice' in test files
- Added windowsOS constant for 'windows' in test files
- Added testIssueBD1/testIssueBD2 constants for 'bd-1'/'bd-2' in test files
- Added testVersion100 constant for '1.0.0' in version tests
- Added testIssueCustom1 constant for 'custom-1' in lazy init tests

Closes bd-54

Amp-Thread-ID: https://ampcode.com/threads/T-0a4e5d44-2d95-4948-8f4a-d8facf8657c7
Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
Steve Yegge
2025-10-25 13:33:51 -07:00
parent 94fb9fa531
commit 47c915ef10
10 changed files with 79 additions and 62 deletions

View File

@@ -11,6 +11,8 @@ import (
"github.com/steveyegge/beads/internal/types"
)
const testUserAlice = "alice"
func TestCommentsCommand(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "bd-test-comments-*")
if err != nil {
@@ -41,7 +43,7 @@ func TestCommentsCommand(t *testing.T) {
}
t.Run("add comment", func(t *testing.T) {
comment, err := s.AddIssueComment(ctx, issue.ID, "alice", "This is a test comment")
comment, err := s.AddIssueComment(ctx, issue.ID, testUserAlice, "This is a test comment")
if err != nil {
t.Fatalf("Failed to add comment: %v", err)
}
@@ -49,7 +51,7 @@ func TestCommentsCommand(t *testing.T) {
if comment.IssueID != issue.ID {
t.Errorf("Expected issue ID %s, got %s", issue.ID, comment.IssueID)
}
if comment.Author != "alice" {
if comment.Author != testUserAlice {
t.Errorf("Expected author alice, got %s", comment.Author)
}
if comment.Text != "This is a test comment" {

View File

@@ -18,11 +18,13 @@ import (
"github.com/steveyegge/beads/internal/types"
)
const windowsOS = "windows"
func makeSocketTempDir(t testing.TB) string {
t.Helper()
base := "/tmp"
if runtime.GOOS == "windows" {
if runtime.GOOS == windowsOS {
base = os.TempDir()
} else if _, err := os.Stat(base); err != nil {
base = os.TempDir()

View File

@@ -10,6 +10,11 @@ import (
"github.com/steveyegge/beads/internal/types"
)
const (
testIssueBD1 = "bd-1"
testIssueBD2 = "bd-2"
)
// TestRemapCollisionsRemapsImportedNotExisting verifies the bug fix where collision
// resolution incorrectly modified existing issue dependencies.
//
@@ -38,7 +43,7 @@ func TestRemapCollisionsRemapsImportedNotExisting(t *testing.T) {
// Step 1: Create existing issues with dependencies
existingIssues := []*types.Issue{
{
ID: "bd-1",
ID: testIssueBD1,
Title: "Existing BD-1",
Description: "Original database issue 1, depends on bd-2",
Status: types.StatusOpen,
@@ -46,7 +51,7 @@ func TestRemapCollisionsRemapsImportedNotExisting(t *testing.T) {
IssueType: types.TypeTask,
},
{
ID: "bd-2",
ID: testIssueBD2,
Title: "Existing BD-2",
Description: "Original database issue 2",
Status: types.StatusOpen,
@@ -56,7 +61,7 @@ func TestRemapCollisionsRemapsImportedNotExisting(t *testing.T) {
{
ID: "bd-3",
Title: "Existing BD-3",
Description: "Original database issue 3, depends on bd-1",
Description: "Original database issue 3, depends on " + testIssueBD1,
Status: types.StatusOpen,
Priority: 2,
IssueType: types.TypeTask,
@@ -71,13 +76,13 @@ func TestRemapCollisionsRemapsImportedNotExisting(t *testing.T) {
// Add dependencies between existing issues
dep1 := &types.Dependency{
IssueID: "bd-1",
DependsOnID: "bd-2",
IssueID: testIssueBD1,
DependsOnID: testIssueBD2,
Type: types.DepBlocks,
}
dep2 := &types.Dependency{
IssueID: "bd-3",
DependsOnID: "bd-1",
DependsOnID: testIssueBD1,
Type: types.DepBlocks,
}
if err := store.AddDependency(ctx, dep1, "test"); err != nil {
@@ -90,7 +95,7 @@ func TestRemapCollisionsRemapsImportedNotExisting(t *testing.T) {
// Step 2: Simulate importing issues with same IDs but different content
importedIssues := []*types.Issue{
{
ID: "bd-1",
ID: testIssueBD1,
Title: "Imported BD-1",
Description: "From import",
Status: types.StatusOpen,
@@ -98,7 +103,7 @@ func TestRemapCollisionsRemapsImportedNotExisting(t *testing.T) {
IssueType: types.TypeTask,
},
{
ID: "bd-2",
ID: testIssueBD2,
Title: "Imported BD-2",
Description: "From import",
Status: types.StatusOpen,
@@ -172,7 +177,7 @@ func TestRemapCollisionsRemapsImportedNotExisting(t *testing.T) {
t.Errorf("Expected 1 dependency for bd-3, got %d", len(existingDeps3))
} else {
// Verify the dependency is correct
if existingDeps3[0].DependsOnID != "bd-1" {
if existingDeps3[0].DependsOnID != testIssueBD1 {
t.Errorf("Expected bd-3 → bd-1, got bd-3 → %s", existingDeps3[0].DependsOnID)
}
}
@@ -206,7 +211,7 @@ func TestRemapCollisionsDoesNotUpdateNonexistentDependencies(t *testing.T) {
// Step 1: Create existing issue with dependency
existing1 := &types.Issue{
ID: "bd-1",
ID: testIssueBD1,
Title: "Existing BD-1",
Description: "Original database issue",
Status: types.StatusOpen,
@@ -214,7 +219,7 @@ func TestRemapCollisionsDoesNotUpdateNonexistentDependencies(t *testing.T) {
IssueType: types.TypeTask,
}
existing2 := &types.Issue{
ID: "bd-2",
ID: testIssueBD2,
Title: "Existing BD-2",
Description: "Original database issue",
Status: types.StatusOpen,
@@ -230,8 +235,8 @@ func TestRemapCollisionsDoesNotUpdateNonexistentDependencies(t *testing.T) {
// Add dependency between existing issues
existingDep := &types.Dependency{
IssueID: "bd-1",
DependsOnID: "bd-2",
IssueID: testIssueBD1,
DependsOnID: testIssueBD2,
Type: types.DepBlocks,
}
if err := store.AddDependency(ctx, existingDep, "test"); err != nil {
@@ -241,7 +246,7 @@ func TestRemapCollisionsDoesNotUpdateNonexistentDependencies(t *testing.T) {
// Step 2: Import colliding issues (without dependencies in DB)
imported := []*types.Issue{
{
ID: "bd-1",
ID: testIssueBD1,
Title: "Imported BD-1",
Description: "From import, will be remapped",
Status: types.StatusOpen,
@@ -276,7 +281,7 @@ func TestRemapCollisionsDoesNotUpdateNonexistentDependencies(t *testing.T) {
if len(existingDeps) != 1 {
t.Errorf("Expected 1 dependency for existing bd-1, got %d (dependency should not be touched)", len(existingDeps))
} else {
if existingDeps[0].DependsOnID != "bd-2" {
if existingDeps[0].DependsOnID != testIssueBD2 {
t.Errorf("Expected bd-1 → bd-2, got bd-1 → %s", existingDeps[0].DependsOnID)
}
}

View File

@@ -40,7 +40,7 @@ func (h *listTestHelper) createTestIssues() {
Priority: 1,
IssueType: types.TypeFeature,
Status: types.StatusInProgress,
Assignee: "alice",
Assignee: testUserAlice,
},
{
Title: "Task Issue",
@@ -128,10 +128,10 @@ func TestListCommand(t *testing.T) {
})
t.Run("filter by assignee", func(t *testing.T) {
assignee := "alice"
assignee := testUserAlice
results := h.search(types.IssueFilter{Assignee: &assignee})
h.assertCount(len(results), 1, "issues for alice")
h.assertEqual("alice", results[0].Assignee, "assignee")
h.assertEqual(testUserAlice, results[0].Assignee, "assignee")
})
t.Run("filter by issue type", func(t *testing.T) {

View File

@@ -556,7 +556,7 @@ func TestAutoFlushJSONLContent(t *testing.T) {
// TestAutoFlushErrorHandling tests error scenarios in flush operations
func TestAutoFlushErrorHandling(t *testing.T) {
if runtime.GOOS == "windows" {
if runtime.GOOS == windowsOS {
t.Skip("chmod-based read-only directory behavior is not reliable on Windows")
}