Files
beads/internal/storage/versioned_test.go
quartz 94581ab233 feat(storage): add VersionedStorage interface with history/diff/branch operations
Extends Storage interface with Dolt-specific version control capabilities:

- New VersionedStorage interface in storage/versioned.go with:
  - History queries: History(), AsOf(), Diff()
  - Branch operations: Branch(), Merge(), CurrentBranch(), ListBranches()
  - Commit operations: Commit(), GetCurrentCommit()
  - Conflict resolution: GetConflicts(), ResolveConflicts()
  - Helper types: HistoryEntry, DiffEntry, Conflict

- DoltStore implements VersionedStorage interface

- New CLI commands:
  - bd history <id> - Show issue version history
  - bd diff <from> <to> - Show changes between commits/branches
  - bd branch [name] - List or create branches
  - bd vc merge <branch> - Merge branch to current
  - bd vc commit -m <msg> - Create a commit
  - bd vc status - Show current branch/commit

- Added --as-of flag to bd show for time-travel queries

- IsVersioned() helper for graceful SQLite backend detection

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-17 01:55:16 -08:00

87 lines
2.2 KiB
Go

package storage_test
import (
"testing"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/memory"
)
// TestIsVersioned verifies the IsVersioned type detection helper.
func TestIsVersioned(t *testing.T) {
// Memory storage is NOT versioned
memStore := memory.New("")
if storage.IsVersioned(memStore) {
t.Error("IsVersioned should return false for memory storage")
}
// Test AsVersioned returns false for non-versioned storage
vs, ok := storage.AsVersioned(memStore)
if ok {
t.Error("AsVersioned should return false for memory storage")
}
if vs != nil {
t.Error("AsVersioned should return nil for memory storage")
}
}
// TestVersionedStorageInterface ensures the interface is correctly defined.
func TestVersionedStorageInterface(t *testing.T) {
// This test verifies that the interface types exist and have the expected methods.
// Actual implementation testing would be done in the dolt package.
// HistoryEntry should have the expected fields
entry := storage.HistoryEntry{
CommitHash: "abc123",
Committer: "test",
}
if entry.CommitHash != "abc123" {
t.Error("HistoryEntry.CommitHash not working")
}
// DiffEntry should have the expected fields
diff := storage.DiffEntry{
IssueID: "bd-123",
DiffType: "modified",
}
if diff.IssueID != "bd-123" {
t.Error("DiffEntry.IssueID not working")
}
if diff.DiffType != "modified" {
t.Error("DiffEntry.DiffType not working")
}
// Conflict should have the expected fields
conflict := storage.Conflict{
IssueID: "bd-456",
Field: "title",
}
if conflict.IssueID != "bd-456" {
t.Error("Conflict.IssueID not working")
}
if conflict.Field != "title" {
t.Error("Conflict.Field not working")
}
}
// TestVersionedStorageTypes verifies type values work as expected.
func TestVersionedStorageTypes(t *testing.T) {
// Test DiffEntry types
testCases := []struct {
diffType string
valid bool
}{
{"added", true},
{"modified", true},
{"removed", true},
}
for _, tc := range testCases {
entry := storage.DiffEntry{DiffType: tc.diffType}
if entry.DiffType != tc.diffType {
t.Errorf("DiffEntry.DiffType mismatch: expected %s, got %s", tc.diffType, entry.DiffType)
}
}
}