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>
199 lines
5.7 KiB
Go
199 lines
5.7 KiB
Go
package doctor
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestIntegrityChecks_NoBeadsDir verifies all integrity check functions handle
|
|
// missing .beads directories gracefully. This replaces 4 individual subtests.
|
|
func TestIntegrityChecks_NoBeadsDir(t *testing.T) {
|
|
checks := []struct {
|
|
name string
|
|
fn func(string) DoctorCheck
|
|
wantName string
|
|
}{
|
|
{"IDFormat", CheckIDFormat, "Issue IDs"},
|
|
{"DependencyCycles", CheckDependencyCycles, "Dependency Cycles"},
|
|
{"DeletionsManifest", CheckDeletionsManifest, "Deletions Manifest"},
|
|
}
|
|
|
|
for _, tc := range checks {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
result := tc.fn(tmpDir)
|
|
|
|
if result.Name != tc.wantName {
|
|
t.Errorf("Name = %q, want %q", result.Name, tc.wantName)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestIntegrityChecks_EmptyBeadsDir verifies all integrity check functions return OK
|
|
// when .beads directory exists but is empty (no database/files to check).
|
|
func TestIntegrityChecks_EmptyBeadsDir(t *testing.T) {
|
|
checks := []struct {
|
|
name string
|
|
fn func(string) DoctorCheck
|
|
}{
|
|
{"IDFormat", CheckIDFormat},
|
|
{"DependencyCycles", CheckDependencyCycles},
|
|
{"DeletionsManifest", CheckDeletionsManifest},
|
|
}
|
|
|
|
for _, tc := range checks {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.Mkdir(beadsDir, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
result := tc.fn(tmpDir)
|
|
|
|
if result.Status != StatusOK {
|
|
t.Errorf("Status = %q, want %q", result.Status, StatusOK)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestCheckDeletionsManifest_LegacyFile tests the specific case where a legacy
|
|
// deletions.jsonl file exists and should trigger a warning.
|
|
func TestCheckDeletionsManifest_LegacyFile(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.Mkdir(beadsDir, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Create a deletions.jsonl file
|
|
deletionsPath := filepath.Join(beadsDir, "deletions.jsonl")
|
|
if err := os.WriteFile(deletionsPath, []byte(`{"id":"test-1"}`), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckDeletionsManifest(tmpDir)
|
|
|
|
// Should warn about legacy deletions file
|
|
if check.Status != StatusWarning {
|
|
t.Errorf("Status = %q, want %q", check.Status, StatusWarning)
|
|
}
|
|
}
|
|
|
|
// TestIsHashID verifies the hash-based ID detection heuristic.
|
|
func TestIsHashID(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
id string
|
|
want bool
|
|
}{
|
|
{"hash with letters", "bd-0jkc", true},
|
|
{"hash with only digits short", "bd-88", false},
|
|
{"hash 5+ chars all digits", "bd-12345", true},
|
|
{"all digits 4 chars", "bd-0088", false}, // isHashID needs letters for < 5 chars
|
|
{"sequential numeric", "bd-1", false},
|
|
{"sequential two digit", "bd-42", false},
|
|
{"no separator", "abc", false},
|
|
{"empty suffix", "bd-", false},
|
|
{"hierarchical hash", "bd-0jkc.1", true},
|
|
{"hierarchical sequential", "bd-1.2", false},
|
|
{"uppercase rejected", "bd-ABCD", false},
|
|
{"special chars rejected", "bd-ab!c", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := isHashID(tt.id)
|
|
if got != tt.want {
|
|
t.Errorf("isHashID(%q) = %v, want %v", tt.id, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestCheckIDFormat_DeadBranch documents the dead branch bug in CheckIDFormat.
|
|
// Both branches after DetectHashBasedIDs return identical results ("hash-based ✓"),
|
|
// so the function reports the same status regardless of detection outcome.
|
|
func TestCheckIDFormat_DeadBranch(t *testing.T) {
|
|
// We can't easily test with a real DB in a non-cgo test,
|
|
// but we can verify the dead branch exists by checking that both
|
|
// code paths (lines 78-84 and 86-90) produce identical output.
|
|
// This test documents the bug for future fix.
|
|
|
|
// Verify the function returns "Issue IDs" check name for no-beads-dir case
|
|
tmpDir := t.TempDir()
|
|
check := CheckIDFormat(tmpDir)
|
|
if check.Name != "Issue IDs" {
|
|
t.Errorf("Name = %q, want %q", check.Name, "Issue IDs")
|
|
}
|
|
}
|
|
|
|
// TestCheckRepoFingerprint_NoDatabase verifies graceful handling when no database exists.
|
|
func TestCheckRepoFingerprint_NoDatabase(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckRepoFingerprint(tmpDir)
|
|
|
|
if check.Name != "Repo Fingerprint" {
|
|
t.Errorf("Name = %q, want %q", check.Name, "Repo Fingerprint")
|
|
}
|
|
if check.Status != StatusOK {
|
|
t.Errorf("Status = %q, want %q", check.Status, StatusOK)
|
|
}
|
|
if !strings.Contains(check.Message, "N/A") {
|
|
t.Errorf("Message = %q, want it to contain 'N/A'", check.Message)
|
|
}
|
|
}
|
|
|
|
// TestTruncateID verifies safe truncation of repo IDs for display.
|
|
// Regression test for the [:8] panic in CheckRepoFingerprint.
|
|
func TestTruncateID(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
id string
|
|
want string
|
|
}{
|
|
{"long ID", "abcdefghijklmnop", "abcdefgh"},
|
|
{"exactly 8", "abcdefgh", "abcdefgh"},
|
|
{"short ID", "abc", "abc"},
|
|
{"empty", "", ""},
|
|
{"one char", "x", "x"},
|
|
{"seven chars", "abcdefg", "abcdefg"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := truncateID(tt.id)
|
|
if got != tt.want {
|
|
t.Errorf("truncateID(%q) = %q, want %q", tt.id, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestCheckDependencyCycles_NoDatabase verifies graceful handling when no database exists.
|
|
func TestCheckDependencyCycles_NoDatabase(t *testing.T) {
|
|
tmpDir := t.TempDir()
|
|
beadsDir := filepath.Join(tmpDir, ".beads")
|
|
if err := os.MkdirAll(beadsDir, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
check := CheckDependencyCycles(tmpDir)
|
|
|
|
if check.Name != "Dependency Cycles" {
|
|
t.Errorf("Name = %q, want %q", check.Name, "Dependency Cycles")
|
|
}
|
|
if check.Status != StatusOK {
|
|
t.Errorf("Status = %q, want %q", check.Status, StatusOK)
|
|
}
|
|
}
|