agent/pkg/agentic/auto_pr_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

94 lines
2.7 KiB
Go

// SPDX-License-Identifier: EUPL-1.2
package agentic
import (
"context"
"testing"
"time"
core "dappco.re/go/core"
"github.com/stretchr/testify/assert"
)
func TestAutopr_AutoCreatePR_Good(t *testing.T) {
t.Skip("needs real git + forge integration")
}
func TestAutopr_AutoCreatePR_Bad(t *testing.T) {
root := t.TempDir()
t.Setenv("CORE_WORKSPACE", root)
s := &PrepSubsystem{
ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}),
backoff: make(map[string]time.Time),
failCount: make(map[string]int),
}
// No status file → early return (no panic)
wsNoStatus := core.JoinPath(root, "ws-no-status")
fs.EnsureDir(wsNoStatus)
assert.NotPanics(t, func() {
s.autoCreatePR(wsNoStatus)
})
// Empty branch → early return
wsNoBranch := core.JoinPath(root, "ws-no-branch")
fs.EnsureDir(wsNoBranch)
fs.Write(core.JoinPath(wsNoBranch, "status.json"), core.JSONMarshalString(&WorkspaceStatus{
Status: "completed", Agent: "codex", Repo: "go-io", Branch: "",
}))
assert.NotPanics(t, func() {
s.autoCreatePR(wsNoBranch)
})
// Empty repo → early return
wsNoRepo := core.JoinPath(root, "ws-no-repo")
fs.EnsureDir(wsNoRepo)
fs.Write(core.JoinPath(wsNoRepo, "status.json"), core.JSONMarshalString(&WorkspaceStatus{
Status: "completed", Agent: "codex", Repo: "", Branch: "agent/fix-tests",
}))
assert.NotPanics(t, func() {
s.autoCreatePR(wsNoRepo)
})
}
func TestAutopr_AutoCreatePR_Ugly(t *testing.T) {
root := t.TempDir()
t.Setenv("CORE_WORKSPACE", root)
// Set up a real git repo with no commits ahead of origin/dev
wsDir := core.JoinPath(root, "ws-no-ahead")
repoDir := core.JoinPath(wsDir, "repo")
fs.EnsureDir(repoDir)
// Init the repo
testCore.Process().Run(context.Background(), "git", "init", "-b", "dev", repoDir)
testCore.Process().RunIn(context.Background(), repoDir, "git", "config", "user.name", "Test")
testCore.Process().RunIn(context.Background(), repoDir, "git", "config", "user.email", "test@test.com")
fs.Write(core.JoinPath(repoDir, "README.md"), "# test")
testCore.Process().RunIn(context.Background(), repoDir, "git", "add", ".")
testCore.Process().RunIn(context.Background(), repoDir, "git", "commit", "-m", "init")
// Write status with valid branch + repo
st := &WorkspaceStatus{
Status: "completed",
Agent: "codex",
Repo: "go-io",
Branch: "agent/fix-tests",
StartedAt: time.Now(),
}
fs.Write(core.JoinPath(wsDir, "status.json"), core.JSONMarshalString(st))
s := &PrepSubsystem{
ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}),
backoff: make(map[string]time.Time),
failCount: make(map[string]int),
}
// git log origin/dev..HEAD will fail (no origin remote) → early return
assert.NotPanics(t, func() {
s.autoCreatePR(wsDir)
})
}