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>
225 lines
5.3 KiB
Go
225 lines
5.3 KiB
Go
package uow
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"os/signal"
|
|
"path/filepath"
|
|
"runtime"
|
|
"sync"
|
|
"syscall"
|
|
"testing"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
"github.com/steveyegge/beads/internal/storage/dbproxy/proxy"
|
|
"github.com/steveyegge/beads/internal/testutil"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func shutdownOnInterrupt(t *testing.T, rootDir string) {
|
|
t.Helper()
|
|
ch := make(chan os.Signal, 1)
|
|
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
|
|
done := make(chan struct{})
|
|
go func() {
|
|
select {
|
|
case <-ch:
|
|
_ = proxy.Shutdown(rootDir)
|
|
os.Exit(1)
|
|
case <-done:
|
|
}
|
|
}()
|
|
t.Cleanup(func() {
|
|
signal.Stop(ch)
|
|
close(done)
|
|
})
|
|
}
|
|
|
|
func TestNewDoltServerUOWProvider_ValidationErrors(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
database string
|
|
rootUser string
|
|
doltBin string
|
|
backend proxy.Backend
|
|
want string
|
|
}{
|
|
{"empty database", "", "root", "/usr/bin/true", proxy.BackendLocalServer, "database name must not be empty"},
|
|
{"invalid backend", "beads", "root", "/usr/bin/true", proxy.Backend("nope"), "unknown backend"},
|
|
{"empty rootUser", "beads", "", "/usr/bin/true", proxy.BackendLocalServer, "rootUser must not be empty"},
|
|
{"empty doltBin", "beads", "root", "", proxy.BackendLocalServer, "doltBinExec must not be empty"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
p, err := NewDoltServerUOWProvider(
|
|
context.Background(),
|
|
t.TempDir(),
|
|
tc.database,
|
|
"", "", tc.backend,
|
|
tc.rootUser, "", tc.doltBin,
|
|
)
|
|
assert.Nil(t, p)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), tc.want)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewDoltServerUOWProvider_HappyPath(t *testing.T) {
|
|
testutil.RequireDoltBinary(t)
|
|
bin, err := exec.LookPath("dolt")
|
|
require.NoError(t, err)
|
|
|
|
bdBin := buildBDBinary(t)
|
|
prev := proxy.ResolveExecutable
|
|
proxy.ResolveExecutable = func() (string, error) { return bdBin, nil }
|
|
t.Cleanup(func() { proxy.ResolveExecutable = prev })
|
|
|
|
t.Setenv("HOME", t.TempDir())
|
|
|
|
port, err := proxy.PickFreePort()
|
|
require.NoError(t, err)
|
|
storeRootDir := t.TempDir()
|
|
shutdownOnInterrupt(t, storeRootDir)
|
|
t.Cleanup(func() {
|
|
if err := proxy.Shutdown(storeRootDir); err != nil {
|
|
t.Logf("proxy.Shutdown(%s): %v", storeRootDir, err)
|
|
}
|
|
})
|
|
cfgPath := writeServerConfig(t, port)
|
|
logPath := filepath.Join(t.TempDir(), "server.log")
|
|
|
|
provider, err := NewDoltServerUOWProvider(
|
|
context.Background(),
|
|
storeRootDir,
|
|
"beads",
|
|
logPath,
|
|
cfgPath,
|
|
proxy.BackendLocalServer,
|
|
"root",
|
|
"",
|
|
bin,
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
require.NotNil(t, provider)
|
|
t.Cleanup(func() { _ = provider.Close(context.Background()) })
|
|
}
|
|
|
|
func TestNewDoltServerUOWProvider_ConcurrentInstantiation(t *testing.T) {
|
|
testutil.RequireDoltBinary(t)
|
|
bin, err := exec.LookPath("dolt")
|
|
require.NoError(t, err)
|
|
|
|
bdBin := buildBDBinary(t)
|
|
prev := proxy.ResolveExecutable
|
|
proxy.ResolveExecutable = func() (string, error) { return bdBin, nil }
|
|
t.Cleanup(func() { proxy.ResolveExecutable = prev })
|
|
|
|
t.Setenv("HOME", t.TempDir())
|
|
|
|
port, err := proxy.PickFreePort()
|
|
require.NoError(t, err)
|
|
storeRootDir := t.TempDir()
|
|
shutdownOnInterrupt(t, storeRootDir)
|
|
t.Cleanup(func() {
|
|
if err := proxy.Shutdown(storeRootDir); err != nil {
|
|
t.Logf("proxy.Shutdown(%s): %v", storeRootDir, err)
|
|
}
|
|
})
|
|
cfgPath := writeServerConfig(t, port)
|
|
logPath := filepath.Join(t.TempDir(), "server.log")
|
|
|
|
const concurrency = 10
|
|
type result struct {
|
|
provider UnitOfWorkProvider
|
|
err error
|
|
}
|
|
results := make([]result, concurrency)
|
|
|
|
var wg sync.WaitGroup
|
|
wg.Add(concurrency)
|
|
for i := 0; i < concurrency; i++ {
|
|
i := i
|
|
go func() {
|
|
defer wg.Done()
|
|
p, err := NewDoltServerUOWProvider(
|
|
context.Background(),
|
|
storeRootDir,
|
|
"beads",
|
|
logPath,
|
|
cfgPath,
|
|
proxy.BackendLocalServer,
|
|
"root",
|
|
"",
|
|
bin,
|
|
)
|
|
results[i] = result{provider: p, err: err}
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
|
|
t.Cleanup(func() {
|
|
for _, r := range results {
|
|
if r.provider != nil {
|
|
_ = r.provider.Close(context.Background())
|
|
}
|
|
}
|
|
})
|
|
|
|
for i, r := range results {
|
|
assert.NoErrorf(t, r.err, "provider %d", i)
|
|
assert.NotNilf(t, r.provider, "provider %d", i)
|
|
}
|
|
}
|
|
|
|
var (
|
|
bdBinaryOnce sync.Once
|
|
bdBinary string
|
|
bdBinaryErr error
|
|
)
|
|
|
|
func buildBDBinary(t *testing.T) string {
|
|
t.Helper()
|
|
bdBinaryOnce.Do(func() {
|
|
if prebuilt := os.Getenv("BEADS_TEST_BD_BINARY"); prebuilt != "" {
|
|
if _, err := os.Stat(prebuilt); err != nil {
|
|
bdBinaryErr = fmt.Errorf("BEADS_TEST_BD_BINARY=%q not found: %w", prebuilt, err)
|
|
return
|
|
}
|
|
bdBinary = prebuilt
|
|
return
|
|
}
|
|
tmpDir, err := os.MkdirTemp("", "bd-uow-test-*")
|
|
if err != nil {
|
|
bdBinaryErr = fmt.Errorf("temp dir: %w", err)
|
|
return
|
|
}
|
|
name := "bd"
|
|
if runtime.GOOS == "windows" {
|
|
name = "bd.exe"
|
|
}
|
|
bdBinary = filepath.Join(tmpDir, name)
|
|
cmd := exec.Command("go", "build", "-tags", "gms_pure_go", "-o", bdBinary, "github.com/steveyegge/beads/cmd/bd")
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
|
bdBinaryErr = fmt.Errorf("go build bd: %v\n%s", err, out)
|
|
}
|
|
})
|
|
if bdBinaryErr != nil {
|
|
t.Fatalf("build bd: %v", bdBinaryErr)
|
|
}
|
|
return bdBinary
|
|
}
|
|
|
|
func writeServerConfig(t *testing.T, port int) string {
|
|
t.Helper()
|
|
path := filepath.Join(t.TempDir(), "config.yaml")
|
|
body := fmt.Sprintf("log_level: debug\nlistener:\n host: 127.0.0.1\n port: %d\n", port)
|
|
require.NoError(t, os.WriteFile(path, []byte(body), 0o600))
|
|
return path
|
|
}
|