gitgram/aitimemachine/beads/cmd/bd/backup_restore_test.go
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
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>
2026-06-23 14:14:09 +03:00

87 lines
2.3 KiB
Go

//go:build cgo
package main
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"github.com/steveyegge/beads/internal/beads"
"github.com/steveyegge/beads/internal/git"
"github.com/steveyegge/beads/internal/testutil"
)
func TestBackupRestoreMissingDir(t *testing.T) {
if testDoltServerPort == 0 {
t.Skip("Dolt test server not available")
}
if testutil.DoltContainerCrashed() {
t.Skipf("Dolt test server crashed: %v", testutil.DoltContainerCrashError())
}
ensureTestMode(t)
dbName := uniqueTestDBName(t)
testDBPath := filepath.Join(t.TempDir(), "dolt")
writeTestMetadata(t, testDBPath, dbName)
s := newTestStoreWithPrefix(t, testDBPath, "dn")
t.Cleanup(func() { _ = s.Close() })
ctx := context.Background()
err := runBackupRestore(ctx, s, "/nonexistent/path", false)
if err == nil {
t.Error("expected error for nonexistent backup dir")
}
}
func TestSyncProjectIDFromDB_NoWorkspaceUsesActiveWorkspaceError(t *testing.T) {
if testDoltServerPort == 0 {
t.Skip("Dolt test server not available")
}
if testutil.DoltContainerCrashed() {
t.Skipf("Dolt test server crashed: %v", testutil.DoltContainerCrashError())
}
ensureTestMode(t)
ctx := context.Background()
repoDir := t.TempDir()
testDBPath := filepath.Join(repoDir, ".beads", "beads.db")
s := newTestStoreWithPrefix(t, testDBPath, "bp")
t.Cleanup(func() { _ = s.Close() })
if err := s.SetMetadata(ctx, "_project_id", "project-123"); err != nil {
t.Fatalf("SetMetadata(_project_id): %v", err)
}
noWorkspaceDir := t.TempDir()
t.Chdir(noWorkspaceDir)
t.Setenv("BEADS_DIR", "")
t.Setenv("BEADS_DB", "")
beads.ResetCaches()
git.ResetCaches()
t.Cleanup(func() {
beads.ResetCaches()
git.ResetCaches()
})
err := syncProjectIDFromDB(ctx, s)
if err == nil {
t.Fatal("expected syncProjectIDFromDB to fail without an active workspace")
}
if !strings.Contains(err.Error(), activeWorkspaceNotFoundError()) {
t.Fatalf("syncProjectIDFromDB error = %q, want active workspace wording", err)
}
if !strings.Contains(err.Error(), diagHint()) {
t.Fatalf("syncProjectIDFromDB error = %q, want diag hint", err)
}
if _, statErr := os.Stat(filepath.Join(noWorkspaceDir, ".beads")); !os.IsNotExist(statErr) {
t.Fatalf("syncProjectIDFromDB should not create local .beads, stat err = %v", statErr)
}
}