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

80 lines
2.1 KiB
Go

//go:build !windows
package testutil
import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/dolt"
)
// ContainerProvider manages a testcontainers Dolt SQL server for integration
// tests. Use NewContainerProvider to start the container, Port() to get the
// mapped host port, and Stop() to tear it down.
type ContainerProvider struct {
container *dolt.DoltContainer
port int
}
// NewContainerProvider starts a Dolt container and returns a provider.
func NewContainerProvider() (*ContainerProvider, error) {
if state := checkDolt(); state != doltReady {
return nil, fmt.Errorf("cannot create container provider: %s", state)
}
ctx, cancel := context.WithTimeout(context.Background(), serverStartTimeout)
defer cancel()
ctr, err := dolt.Run(ctx, DoltDockerImage,
dolt.WithDatabase("beads_test"),
testcontainers.WithEnv(map[string]string{"DOLT_ROOT_HOST": "%"}),
)
if err != nil {
return nil, fmt.Errorf("starting Dolt container: %w", err)
}
p, err := ctr.MappedPort(ctx, "3306/tcp")
if err != nil {
_ = testcontainers.TerminateContainer(ctr)
return nil, fmt.Errorf("getting mapped port: %w", err)
}
port, err := strconv.Atoi(p.Port())
if err != nil {
_ = testcontainers.TerminateContainer(ctr)
return nil, fmt.Errorf("parsing port %q: %w", p.Port(), err)
}
return &ContainerProvider{
container: ctr,
port: port,
}, nil
}
// Port returns the host-mapped port the container is listening on.
func (p *ContainerProvider) Port() int {
return p.port
}
// WritePortFile writes the container port to the given shared server directory
// so that bd subprocesses can discover it via DefaultConfig / readPortFile.
func (p *ContainerProvider) WritePortFile(serverDir string) error {
portPath := filepath.Join(serverDir, "dolt-server.port")
return os.WriteFile(portPath, []byte(strconv.Itoa(p.port)), 0600)
}
// Stop terminates the container.
func (p *ContainerProvider) Stop() error {
if p.container == nil {
return nil
}
err := testcontainers.TerminateContainer(p.container)
p.container = nil
return err
}