Files
tutti/packages/agent/host/external_consumer_test.go
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

71 lines
2.3 KiB
Go

package agenthost
import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
)
func TestExternalConsumerCompilesWithoutDaemonDependency(t *testing.T) {
_, currentFile, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("resolve Host module path")
}
hostDir := filepath.Dir(currentFile)
fixtureDir := filepath.Join(hostDir, "testdata", "external-consumer")
tempDir := t.TempDir()
template, err := os.ReadFile(filepath.Join(fixtureDir, "go.mod.tmpl"))
if err != nil {
t.Fatalf("read external consumer go.mod: %v", err)
}
replacements := map[string]string{
"{{HOST_DIR}}": hostDir,
"{{STORE_DIR}}": filepath.Join(hostDir, "..", "store-sqlite"),
"{{CANONICAL_DIR}}": filepath.Join(hostDir, "..", "store-sqlite", "canonical"),
"{{REPLICATION_DIR}}": filepath.Join(hostDir, "..", "activity-replication"),
}
goMod := string(template)
for marker, path := range replacements {
goMod = strings.ReplaceAll(goMod, marker, filepath.ToSlash(path))
}
if err := os.WriteFile(filepath.Join(tempDir, "go.mod"), []byte(goMod), 0o600); err != nil {
t.Fatalf("write external consumer go.mod: %v", err)
}
consumer, err := os.ReadFile(filepath.Join(fixtureDir, "consumer.go"))
if err != nil {
t.Fatalf("read external consumer source: %v", err)
}
if err := os.WriteFile(filepath.Join(tempDir, "consumer.go"), consumer, 0o600); err != nil {
t.Fatalf("write external consumer source: %v", err)
}
runExternalGo(t, tempDir, "test", "-mod=mod", ".")
dependencies := runExternalGo(t, tempDir, "list", "-mod=mod", "-deps", ".")
modules := runExternalGo(t, tempDir, "list", "-mod=mod", "-m", "all")
for _, forbidden := range []string{
"github.com/tutti-os/tutti/packages/agent/daemon",
"github.com/tutti-os/tutti/services/tuttid",
"sidecar",
} {
if strings.Contains(dependencies, forbidden) || strings.Contains(modules, forbidden) {
t.Fatalf("external Host consumer dependency closure contains %q", forbidden)
}
}
}
func runExternalGo(t *testing.T, dir string, args ...string) string {
t.Helper()
command := exec.Command("go", args...)
command.Dir = dir
command.Env = append(os.Environ(), "GOWORK=off")
output, err := command.CombinedOutput()
if err != nil {
t.Fatalf("go %s failed: %v\n%s", strings.Join(args, " "), err, output)
}
return string(output)
}