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

203 lines
5.1 KiB
Go

package main
import (
"os"
"os/exec"
"strings"
"testing"
)
// TestGetActorWithGit tests the actor resolution fallback chain.
// Priority: --actor flag > BEADS_ACTOR env > BD_ACTOR env (deprecated) > git config user.name > $USER > "unknown"
func TestGetActorWithGit(t *testing.T) {
// Save original environment and actor variable
origActor := actor
origBdActor, bdActorSet := os.LookupEnv("BD_ACTOR")
origBeadsActor, beadsActorSet := os.LookupEnv("BEADS_ACTOR")
origUser, userSet := os.LookupEnv("USER")
// Cleanup after test
defer func() {
actor = origActor
if bdActorSet {
os.Setenv("BD_ACTOR", origBdActor)
} else {
os.Unsetenv("BD_ACTOR")
}
if beadsActorSet {
os.Setenv("BEADS_ACTOR", origBeadsActor)
} else {
os.Unsetenv("BEADS_ACTOR")
}
if userSet {
os.Setenv("USER", origUser)
} else {
os.Unsetenv("USER")
}
}()
// Helper to get current git user.name (may be empty if not configured)
getGitUserName := func() string {
out, err := exec.Command("git", "config", "user.name").Output()
if err != nil {
return ""
}
return strings.TrimSpace(string(out))
}
gitUserName := getGitUserName()
tests := []struct {
name string
actorFlag string
bdActor string
beadsActor string
user string
expected string
skipIfNoGit bool // Skip if git user.name is not configured
}{
{
name: "actor flag takes priority",
actorFlag: "flag-actor",
bdActor: "bd-actor",
beadsActor: "beads-actor",
user: "system-user",
expected: "flag-actor",
},
{
name: "BEADS_ACTOR takes priority when no flag",
actorFlag: "",
bdActor: "bd-actor",
beadsActor: "beads-actor",
user: "system-user",
expected: "beads-actor",
},
{
name: "BD_ACTOR used as fallback when no BEADS_ACTOR",
actorFlag: "",
bdActor: "bd-actor",
beadsActor: "",
user: "system-user",
expected: "bd-actor",
},
{
name: "git config user.name used when no env vars",
actorFlag: "",
bdActor: "",
beadsActor: "",
user: "system-user",
expected: gitUserName, // Will be git user.name if configured
skipIfNoGit: true,
},
{
name: "USER fallback when no git config",
actorFlag: "",
bdActor: "",
beadsActor: "",
user: "fallback-user",
expected: "fallback-user",
// Note: This test may fail if git user.name is configured
// We handle this by checking the actual git config in the test
},
{
name: "unknown as final fallback",
actorFlag: "",
bdActor: "",
beadsActor: "",
user: "",
expected: "unknown",
// Note: This test may get git user.name instead if configured
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Skip tests that require git user.name to not be configured
if tt.skipIfNoGit && gitUserName == "" {
t.Skip("Skipping: git config user.name is not configured")
}
// For tests expecting USER or unknown, skip if git user.name is configured
// because git takes priority over USER
if (tt.expected == tt.user || tt.expected == "unknown") && gitUserName != "" && tt.bdActor == "" && tt.beadsActor == "" && tt.actorFlag == "" {
t.Skipf("Skipping: git config user.name (%s) takes priority over expected %s", gitUserName, tt.expected)
}
// Set up test environment
actor = tt.actorFlag
if tt.bdActor != "" {
os.Setenv("BD_ACTOR", tt.bdActor)
} else {
os.Unsetenv("BD_ACTOR")
}
if tt.beadsActor != "" {
os.Setenv("BEADS_ACTOR", tt.beadsActor)
} else {
os.Unsetenv("BEADS_ACTOR")
}
if tt.user != "" {
os.Setenv("USER", tt.user)
} else {
os.Unsetenv("USER")
}
// Call the function
result := getActorWithGit()
// Check result
if result != tt.expected {
t.Errorf("getActorWithGit() = %q, want %q", result, tt.expected)
}
})
}
}
// TestGetActorWithGit_PriorityOrder tests that the priority order is respected
func TestGetActorWithGit_PriorityOrder(t *testing.T) {
// Save original state
origActor := actor
origBdActor, bdActorSet := os.LookupEnv("BD_ACTOR")
origBeadsActor, beadsActorSet := os.LookupEnv("BEADS_ACTOR")
defer func() {
actor = origActor
if bdActorSet {
os.Setenv("BD_ACTOR", origBdActor)
} else {
os.Unsetenv("BD_ACTOR")
}
if beadsActorSet {
os.Setenv("BEADS_ACTOR", origBeadsActor)
} else {
os.Unsetenv("BEADS_ACTOR")
}
}()
// Test: flag > BEADS_ACTOR > BD_ACTOR
actor = "from-flag"
os.Setenv("BD_ACTOR", "from-bd-actor")
os.Setenv("BEADS_ACTOR", "from-beads-actor")
result := getActorWithGit()
if result != "from-flag" {
t.Errorf("Expected flag to take priority, got %q", result)
}
// Test: BEADS_ACTOR > BD_ACTOR (no flag)
actor = ""
result = getActorWithGit()
if result != "from-beads-actor" {
t.Errorf("Expected BEADS_ACTOR to take priority over BD_ACTOR, got %q", result)
}
// Test: BD_ACTOR as fallback when BEADS_ACTOR is empty
os.Unsetenv("BEADS_ACTOR")
result = getActorWithGit()
if result != "from-bd-actor" {
t.Errorf("Expected BD_ACTOR to be used as fallback, got %q", result)
}
}