agent/pkg/setup/setup_test.go
Snider 537226bd4d feat: AX v0.8.0 upgrade — Core features + quality gates
AX Quality Gates (RFC-025):
- Eliminate os/exec from all test + production code (12+ files)
- Eliminate encoding/json from all test files (15 files, 66 occurrences)
- Eliminate os from all test files except TestMain (Go runtime contract)
- Eliminate path/filepath, net/url from all files
- String concat: 39 violations replaced with core.Concat()
- Test naming AX-7: 264 test functions renamed across all 6 packages
- Example test 1:1 coverage complete

Core Features Adopted:
- Task Composition: agent.completion pipeline (QA → PR → Verify → Ingest → Poke)
- PerformAsync: completion pipeline runs with WaitGroup + progress tracking
- Config: agents.yaml loaded once, feature flags (auto-qa/pr/merge/ingest)
- Named Locks: c.Lock("drain") for queue serialisation
- Registry: workspace state with cross-package QUERY access
- QUERY: c.QUERY(WorkspaceQuery{Status: "running"}) for cross-service queries
- Action descriptions: 25+ Actions self-documenting
- Data mounts: prompts/tasks/flows/personas/workspaces via c.Data()
- Content Actions: agentic.prompt/task/flow/persona callable via IPC
- Drive endpoints: forge + brain registered with tokens
- Drive REST helpers: DriveGet/DrivePost/DriveDo for Drive-aware HTTP
- HandleIPCEvents: auto-discovered by WithService (no manual wiring)
- Entitlement: frozen-queue gate on write Actions
- CLI dispatch: workspace dispatch wired to real dispatch method
- CLI: --quiet/-q and --debug/-d global flags
- CLI: banner, version, check (with service/action/command counts), env
- main.go: minimal — 5 services + c.Run(), no os import
- cmd tests: 84.2% coverage (was 0%)

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 06:38:02 +00:00

85 lines
2.6 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package setup
import (
"testing"
core "dappco.re/go/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// testSvc creates a setup Service for tests.
func testSvc() *Service {
c := core.New()
return &Service{ServiceRuntime: core.NewServiceRuntime(c, SetupOptions{})}
}
func TestSetup_Detect_Good(t *testing.T) {
dir := t.TempDir()
require.True(t, fs.WriteMode(core.JoinPath(dir, "go.mod"), "module example.com/test\n", 0644).OK)
assert.Equal(t, TypeGo, Detect(dir))
assert.Equal(t, []ProjectType{TypeGo}, DetectAll(dir))
}
func TestSetup_GenerateBuildConfig_Good(t *testing.T) {
cfg, err := GenerateBuildConfig("/tmp/example", TypeGo)
require.NoError(t, err)
assert.Contains(t, cfg, "# example build configuration")
assert.Contains(t, cfg, "project:")
assert.Contains(t, cfg, "name: example")
assert.Contains(t, cfg, "type: go")
assert.Contains(t, cfg, "main: ./cmd/example")
assert.Contains(t, cfg, "cgo: false")
}
func TestSetup_ParseGitRemote_Good(t *testing.T) {
tests := map[string]string{
"https://github.com/dAppCore/go-io.git": "dAppCore/go-io",
"git@github.com:dAppCore/go-io.git": "dAppCore/go-io",
"ssh://git@forge.lthn.ai:2223/core/agent.git": "core/agent",
"ssh://git@forge.lthn.ai:2223/core/agent": "core/agent",
"git@forge.lthn.ai:core/agent.git": "core/agent",
"/srv/git/core/agent.git": "srv/git/core/agent",
}
for remote, want := range tests {
assert.Equal(t, want, parseGitRemote(remote), remote)
}
}
func TestSetup_ParseGitRemote_Bad(t *testing.T) {
assert.Equal(t, "", parseGitRemote(""))
assert.Equal(t, "", parseGitRemote("origin"))
}
func TestSetup_Run_Good(t *testing.T) {
dir := t.TempDir()
require.True(t, fs.WriteMode(core.JoinPath(dir, "go.mod"), "module example.com/test\n", 0644).OK)
err := testSvc().Run(Options{Path: dir})
require.NoError(t, err)
build := fs.Read(core.JoinPath(dir, ".core", "build.yaml"))
require.True(t, build.OK)
assert.Contains(t, build.Value.(string), "type: go")
test := fs.Read(core.JoinPath(dir, ".core", "test.yaml"))
require.True(t, test.OK)
assert.Contains(t, test.Value.(string), "go test ./...")
}
func TestSetup_RunTemplateAlias_Good(t *testing.T) {
dir := t.TempDir()
require.True(t, fs.WriteMode(core.JoinPath(dir, "go.mod"), "module example.com/test\n", 0644).OK)
err := testSvc().Run(Options{Path: dir, Template: "agent"})
require.NoError(t, err)
prompt := fs.Read(core.JoinPath(dir, "PROMPT.md"))
require.True(t, prompt.OK)
assert.Contains(t, prompt.Value.(string), "This workspace was scaffolded by pkg/setup.")
}