Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
129 lines
3.8 KiB
Go
129 lines
3.8 KiB
Go
//go:build cgo
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/storage/dolt"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
func TestRepairMultiplePrefixes(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
testDBPath := filepath.Join(tmpDir, "test.db")
|
|
|
|
ctx := context.Background()
|
|
|
|
testStore, err := dolt.New(ctx, &dolt.Config{Path: testDBPath})
|
|
if err != nil {
|
|
t.Skipf("skipping: Dolt server not available: %v", err)
|
|
}
|
|
defer testStore.Close()
|
|
|
|
// Set globals following TestRenamePrefixCommand pattern
|
|
oldStore := store
|
|
oldActor := actor
|
|
oldDBPath := dbPath
|
|
store = testStore
|
|
actor = "test"
|
|
dbPath = testDBPath
|
|
defer func() {
|
|
store = oldStore
|
|
actor = oldActor
|
|
dbPath = oldDBPath
|
|
}()
|
|
|
|
// Set initial prefix
|
|
if err := testStore.SetConfig(ctx, "issue_prefix", "test"); err != nil {
|
|
t.Fatalf("failed to set prefix: %v", err)
|
|
}
|
|
|
|
// Create issues with multiple prefixes (simulating corruption).
|
|
// CreateIssue accepts explicit IDs without prefix validation,
|
|
// so we can create issues with different prefixes to simulate
|
|
// a corrupted database state.
|
|
testIssues := []types.Issue{
|
|
{ID: "test-1", Title: "Test issue 1", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask},
|
|
{ID: "test-2", Title: "Test issue 2", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask},
|
|
{ID: "old-1", Title: "Old issue 1", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask},
|
|
{ID: "old-2", Title: "Old issue 2", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask},
|
|
{ID: "another-1", Title: "Another issue 1", Status: types.StatusOpen, Priority: 2, IssueType: types.TypeTask},
|
|
}
|
|
|
|
for i := range testIssues {
|
|
if err := testStore.CreateIssue(ctx, &testIssues[i], "test"); err != nil {
|
|
t.Fatalf("failed to create issue %s: %v", testIssues[i].ID, err)
|
|
}
|
|
}
|
|
|
|
// Verify we have multiple prefixes
|
|
allIssues, err := testStore.SearchIssues(ctx, "", types.IssueFilter{})
|
|
if err != nil {
|
|
t.Fatalf("failed to search issues: %v", err)
|
|
}
|
|
|
|
prefixes := detectPrefixes(allIssues)
|
|
if len(prefixes) != 3 {
|
|
t.Fatalf("expected 3 prefixes, got %d: %v", len(prefixes), prefixes)
|
|
}
|
|
|
|
// Test repair — now uses UpdateIssueID (Dolt rename semantics)
|
|
// instead of the old CreateIssue+DeleteIssue approach that caused deadlocks
|
|
if err := repairPrefixes(ctx, testStore, "test", "test", allIssues, prefixes, false); err != nil {
|
|
t.Fatalf("repair failed: %v", err)
|
|
}
|
|
|
|
// Verify all issues now have correct prefix
|
|
allIssues, err = testStore.SearchIssues(ctx, "", types.IssueFilter{})
|
|
if err != nil {
|
|
t.Fatalf("failed to search issues after repair: %v", err)
|
|
}
|
|
|
|
prefixes = detectPrefixes(allIssues)
|
|
if len(prefixes) != 1 {
|
|
t.Fatalf("expected 1 prefix after repair, got %d: %v", len(prefixes), prefixes)
|
|
}
|
|
|
|
if _, ok := prefixes["test"]; !ok {
|
|
t.Fatalf("expected prefix 'test', got %v", prefixes)
|
|
}
|
|
|
|
// Verify the original test-1 and test-2 are unchanged
|
|
for _, id := range []string{"test-1", "test-2"} {
|
|
issue, err := testStore.GetIssue(ctx, id)
|
|
if err != nil {
|
|
t.Fatalf("expected issue %s to exist unchanged: %v", id, err)
|
|
}
|
|
if issue == nil {
|
|
t.Fatalf("expected issue %s to exist", id)
|
|
}
|
|
}
|
|
|
|
// Verify total count: 2 original (test-1, test-2) + 3 renamed = 5
|
|
if len(allIssues) != 5 {
|
|
t.Fatalf("expected 5 issues total, got %d", len(allIssues))
|
|
}
|
|
|
|
// Count issues with correct prefix
|
|
testPrefixCount := 0
|
|
for _, issue := range allIssues {
|
|
if len(issue.ID) > 5 && issue.ID[:5] == "test-" {
|
|
testPrefixCount++
|
|
}
|
|
}
|
|
if testPrefixCount != 5 {
|
|
t.Fatalf("expected all 5 issues to have 'test-' prefix, got %d", testPrefixCount)
|
|
}
|
|
|
|
// Verify old IDs no longer exist
|
|
for _, oldID := range []string{"old-1", "old-2", "another-1"} {
|
|
issue, err := testStore.GetIssue(ctx, oldID)
|
|
if err == nil && issue != nil {
|
|
t.Fatalf("expected old ID %s to no longer exist", oldID)
|
|
}
|
|
}
|
|
}
|