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>
114 lines
4.4 KiB
Go
114 lines
4.4 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package agentic
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
core "dappco.re/go/core"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// --- resume ---
|
|
|
|
func TestResume_Resume_Good(t *testing.T) {
|
|
root := t.TempDir()
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
wsRoot := WorkspaceRoot()
|
|
ws := core.JoinPath(wsRoot, "ws-blocked")
|
|
repoDir := core.JoinPath(ws, "repo")
|
|
fs.EnsureDir(repoDir)
|
|
testCore.Process().Run(context.Background(), "git", "init", repoDir)
|
|
|
|
st := &WorkspaceStatus{Status: "blocked", Repo: "go-io", Agent: "codex", Task: "Fix the tests"}
|
|
fs.Write(core.JoinPath(ws, "status.json"), core.JSONMarshalString(st))
|
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}), backoff: make(map[string]time.Time), failCount: make(map[string]int)}
|
|
_, out, err := s.resume(context.Background(), nil, ResumeInput{
|
|
Workspace: "ws-blocked", Answer: "Use the new Core API", DryRun: true,
|
|
})
|
|
require.NoError(t, err)
|
|
assert.True(t, out.Success)
|
|
assert.Equal(t, "ws-blocked", out.Workspace)
|
|
assert.Equal(t, "codex", out.Agent)
|
|
assert.Contains(t, out.Prompt, "Fix the tests")
|
|
assert.Contains(t, out.Prompt, "Use the new Core API")
|
|
|
|
answerR := fs.Read(core.JoinPath(repoDir, "ANSWER.md"))
|
|
assert.Contains(t, answerR.Value.(string), "Use the new Core API")
|
|
|
|
// Agent override
|
|
_, out2, _ := s.resume(context.Background(), nil, ResumeInput{
|
|
Workspace: "ws-blocked", Agent: "claude:opus", DryRun: true,
|
|
})
|
|
assert.Equal(t, "claude:opus", out2.Agent)
|
|
|
|
// Completed workspace is resumable too
|
|
ws2 := core.JoinPath(wsRoot, "ws-done")
|
|
fs.EnsureDir(core.JoinPath(ws2, "repo"))
|
|
testCore.Process().Run(context.Background(), "git", "init", core.JoinPath(ws2, "repo"))
|
|
st2 := &WorkspaceStatus{Status: "completed", Repo: "go-io", Agent: "codex", Task: "Review code"}
|
|
fs.Write(core.JoinPath(ws2, "status.json"), core.JSONMarshalString(st2))
|
|
|
|
_, out3, err3 := s.resume(context.Background(), nil, ResumeInput{Workspace: "ws-done", DryRun: true})
|
|
require.NoError(t, err3)
|
|
assert.True(t, out3.Success)
|
|
}
|
|
|
|
func TestResume_Resume_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)}
|
|
|
|
// Empty workspace
|
|
_, _, err := s.resume(context.Background(), nil, ResumeInput{})
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "workspace is required")
|
|
|
|
// Workspace not found
|
|
_, _, err = s.resume(context.Background(), nil, ResumeInput{Workspace: "nonexistent"})
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "workspace not found")
|
|
|
|
// Not resumable (running)
|
|
ws := core.JoinPath(WorkspaceRoot(), "ws-running")
|
|
fs.EnsureDir(core.JoinPath(ws, "repo"))
|
|
testCore.Process().Run(context.Background(), "git", "init", core.JoinPath(ws, "repo"))
|
|
st := &WorkspaceStatus{Status: "running", Repo: "test", Agent: "codex"}
|
|
fs.Write(core.JoinPath(ws, "status.json"), core.JSONMarshalString(st))
|
|
|
|
_, _, err = s.resume(context.Background(), nil, ResumeInput{Workspace: "ws-running"})
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "not resumable")
|
|
}
|
|
|
|
func TestResume_Resume_Ugly(t *testing.T) {
|
|
root := t.TempDir()
|
|
t.Setenv("CORE_WORKSPACE", root)
|
|
|
|
// Workspace exists but no status.json
|
|
ws := core.JoinPath(WorkspaceRoot(), "ws-nostatus")
|
|
fs.EnsureDir(core.JoinPath(ws, "repo"))
|
|
testCore.Process().Run(context.Background(), "git", "init", core.JoinPath(ws, "repo"))
|
|
|
|
s := &PrepSubsystem{ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}), backoff: make(map[string]time.Time), failCount: make(map[string]int)}
|
|
_, _, err := s.resume(context.Background(), nil, ResumeInput{Workspace: "ws-nostatus"})
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "no status.json")
|
|
|
|
// No answer provided — prompt has no ANSWER section
|
|
ws2 := core.JoinPath(WorkspaceRoot(), "ws-noanswer")
|
|
fs.EnsureDir(core.JoinPath(ws2, "repo"))
|
|
testCore.Process().Run(context.Background(), "git", "init", core.JoinPath(ws2, "repo"))
|
|
st := &WorkspaceStatus{Status: "blocked", Repo: "test", Agent: "codex", Task: "Fix"}
|
|
fs.Write(core.JoinPath(ws2, "status.json"), core.JSONMarshalString(st))
|
|
|
|
_, out, err := s.resume(context.Background(), nil, ResumeInput{Workspace: "ws-noanswer", DryRun: true})
|
|
require.NoError(t, err)
|
|
assert.NotContains(t, out.Prompt, "ANSWER TO YOUR QUESTION")
|
|
}
|