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

94 lines
2.5 KiB
Go

//go:build cgo
package tracker
import (
"context"
"database/sql"
"fmt"
"os"
"testing"
"github.com/steveyegge/beads/internal/storage/dolt"
"github.com/steveyegge/beads/internal/testutil"
)
// testServerPort is the port of the shared test Dolt server.
var testServerPort int
// testSharedDB is the name of the shared database for branch-per-test isolation.
var testSharedDB string
// testSharedConn is a raw *sql.DB for branch operations in the shared database.
var testSharedConn *sql.DB
func TestMain(m *testing.M) {
os.Exit(testMainInner(m))
}
func testMainInner(m *testing.M) int {
os.Setenv("BEADS_TEST_MODE", "1")
if err := testutil.EnsureDoltContainerForTestMain(); err != nil {
fmt.Fprintf(os.Stderr, "WARN: %v, skipping Dolt tests\n", err)
} else {
defer testutil.TerminateDoltContainer()
testServerPort = testutil.DoltContainerPortInt()
// Set up shared database for branch-per-test isolation
testSharedDB = "tracker_pkg_shared"
db, err := testutil.SetupSharedTestDB(testServerPort, testSharedDB)
if err != nil {
fmt.Fprintf(os.Stderr, "FATAL: shared DB setup failed: %v\n", err)
return 1
}
testSharedConn = db
defer db.Close()
// Create schema + config on the shared DB and commit to main
if err := initTrackerSharedSchema(testServerPort); err != nil {
fmt.Fprintf(os.Stderr, "FATAL: shared schema init failed: %v\n", err)
return 1
}
}
code := m.Run()
os.Unsetenv("BEADS_DOLT_PORT")
os.Unsetenv("BEADS_TEST_MODE")
return code
}
func initTrackerSharedSchema(port int) error {
ctx := context.Background()
cfg := &dolt.Config{
Path: "/tmp/tracker-shared-init",
ServerHost: "127.0.0.1",
ServerPort: port,
Database: testSharedDB,
MaxOpenConns: 1,
}
store, err := dolt.New(ctx, cfg)
if err != nil {
return fmt.Errorf("New: %w", err)
}
defer store.Close()
if err := store.SetConfig(ctx, "issue_prefix", "bd"); err != nil {
return fmt.Errorf("SetConfig(issue_prefix): %w", err)
}
// Commit schema to main so branches get a clean snapshot
db := store.DB()
if _, err := db.ExecContext(ctx, "CALL DOLT_ADD('-A')"); err != nil {
return fmt.Errorf("DOLT_ADD: %w", err)
}
if _, err := db.ExecContext(ctx, "CALL DOLT_COMMIT('--allow-empty', '-m', 'test: init shared schema')"); err != nil {
return fmt.Errorf("DOLT_COMMIT: %w", err)
}
if err := testutil.MaterializeLocalTableSchemasForBranchTests(ctx, db); err != nil {
return fmt.Errorf("materialize local table schemas: %w", err)
}
return nil
}