beads/cmd/bd/restore_test.go
beads/refinery 041b74b54a fix: resolve CI failures on main (6 tests, formatting)
- Fix gofmt: remove trailing blank lines in 4 files
- Skip TestOpenFromConfig_Embedded/DefaultsToEmbedded when no Dolt server
  (these tests connect to 127.0.0.1:3307 which is unavailable in CI)
- Add CheckGitConflicts to collectValidateChecks (was missing, causing
  TestValidateCheck_DetectsGitConflicts to fail)
- Implement CheckGitConflicts for CGO builds (scans JSONL for conflict
  markers; only no-cgo stub existed)
- Fix TestIssueContentSize expected value: "some long description text"
  is 26 chars, not 25
- Fix TestAppend_CreatesFileAndWritesJSONL: create metadata.json instead
  of issues.jsonl so hasBeadsProjectFiles recognizes the BEADS_DIR

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/refinery
Rig: beads
Role: refinery
2026-02-23 09:50:33 -08:00

72 lines
1.5 KiB
Go

//go:build cgo
package main
import (
"context"
"errors"
"path/filepath"
"testing"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/types"
)
func TestIssueContentSize(t *testing.T) {
tests := []struct {
name string
issue *types.Issue
want int
}{
{
name: "empty issue",
issue: &types.Issue{},
want: 0,
},
{
name: "issue with content",
issue: &types.Issue{
Description: "hello",
Design: "world",
AcceptanceCriteria: "foo",
Notes: "bar",
},
want: 5 + 5 + 3 + 3,
},
{
name: "only description",
issue: &types.Issue{
Description: "some long description text",
},
want: 26,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := issueContentSize(tt.issue)
if got != tt.want {
t.Errorf("issueContentSize() = %d, want %d", got, tt.want)
}
})
}
}
// TestRestoreWithInvalidIssueID verifies that restore handles non-existent issues
// gracefully without panicking.
func TestRestoreWithInvalidIssueID(t *testing.T) {
tmpDir := t.TempDir()
dbPath := filepath.Join(tmpDir, ".beads", "beads.db")
testStore := newTestStore(t, dbPath)
defer testStore.Close()
ctx := context.Background()
issue, err := testStore.GetIssue(ctx, "nonexistent-issue-12345")
if !errors.Is(err, storage.ErrNotFound) {
t.Fatalf("GetIssue expected ErrNotFound, got: %v", err)
}
if issue != nil {
t.Fatalf("GetIssue returned issue for non-existent ID: %v", issue)
}
}