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>
151 lines
4.4 KiB
Go
151 lines
4.4 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package agentic
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
|
|
core "dappco.re/go/core"
|
|
"dappco.re/go/core/forge"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// --- commentOnIssue ---
|
|
|
|
func TestPr_CommentOnIssue_Good_PostsCommentOnPR(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
assert.Equal(t, "POST", r.Method)
|
|
assert.Contains(t, r.URL.Path, "/issues/7/comments")
|
|
|
|
var body map[string]string
|
|
bodyStr := core.ReadAll(r.Body)
|
|
core.JSONUnmarshalString(bodyStr.Value.(string), &body)
|
|
assert.Equal(t, "Test comment", body["body"])
|
|
|
|
w.Write([]byte(core.JSONMarshalString(map[string]any{"id": 99})))
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
|
|
s := &PrepSubsystem{
|
|
ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}),
|
|
forge: forge.NewForge(srv.URL, "test-token"),
|
|
forgeURL: srv.URL,
|
|
forgeToken: "test-token",
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
|
|
s.commentOnIssue(context.Background(), "core", "repo", 7, "Test comment")
|
|
}
|
|
|
|
// --- autoVerifyAndMerge integration (extended) ---
|
|
|
|
func TestVerify_AutoVerifyAndMerge_Good_FullPipeline(t *testing.T) {
|
|
// Mock Forge API for merge + comment
|
|
mergeOK := false
|
|
commented := false
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch {
|
|
case r.Method == "POST" && r.URL.Path == "/api/v1/repos/core/test-repo/pulls/5/merge":
|
|
mergeOK = true
|
|
w.WriteHeader(200)
|
|
case r.Method == "POST" && r.URL.Path == "/api/v1/repos/core/test-repo/issues/5/comments":
|
|
commented = true
|
|
w.Write([]byte(core.JSONMarshalString(map[string]any{"id": 1})))
|
|
default:
|
|
w.WriteHeader(200)
|
|
}
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
|
|
dir := t.TempDir()
|
|
wsDir := core.JoinPath(dir, "ws")
|
|
repoDir := core.JoinPath(wsDir, "repo")
|
|
fs.EnsureDir(repoDir)
|
|
|
|
// No go.mod, composer.json, or package.json = no test runner = passes
|
|
st := &WorkspaceStatus{
|
|
Status: "completed",
|
|
Repo: "test-repo",
|
|
Org: "core",
|
|
Branch: "agent/fix",
|
|
PRURL: "https://forge.lthn.ai/core/test-repo/pulls/5",
|
|
}
|
|
fs.Write(core.JoinPath(wsDir, "status.json"), core.JSONMarshalString(st))
|
|
|
|
s := &PrepSubsystem{
|
|
ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}),
|
|
forge: forge.NewForge(srv.URL, "test-token"),
|
|
forgeURL: srv.URL,
|
|
forgeToken: "test-token",
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
|
|
s.autoVerifyAndMerge(wsDir)
|
|
assert.True(t, mergeOK, "should have called merge API")
|
|
assert.True(t, commented, "should have posted comment")
|
|
|
|
// Status should be marked as merged
|
|
updated, err := ReadStatus(wsDir)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "merged", updated.Status)
|
|
}
|
|
|
|
// --- attemptVerifyAndMerge ---
|
|
|
|
func TestVerify_AttemptVerifyAndMerge_Good_TestsPassMergeSucceeds(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path == "/api/v1/repos/core/test/pulls/1/merge" {
|
|
w.WriteHeader(200)
|
|
} else {
|
|
w.Write([]byte(core.JSONMarshalString(map[string]any{"id": 1})))
|
|
}
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
|
|
dir := t.TempDir() // No project files = passes verification
|
|
|
|
s := &PrepSubsystem{
|
|
ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}),
|
|
forge: forge.NewForge(srv.URL, "test-token"),
|
|
forgeURL: srv.URL,
|
|
forgeToken: "test-token",
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
|
|
result := s.attemptVerifyAndMerge(dir, "core", "test", "agent/fix", 1)
|
|
assert.Equal(t, mergeSuccess, result)
|
|
}
|
|
|
|
func TestVerify_AttemptVerifyAndMerge_Bad_MergeFails(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path == "/api/v1/repos/core/test/pulls/1/merge" {
|
|
w.WriteHeader(409)
|
|
w.Write([]byte(core.JSONMarshalString(map[string]any{"message": "conflict"})))
|
|
} else {
|
|
w.Write([]byte(core.JSONMarshalString(map[string]any{"id": 1})))
|
|
}
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
|
|
dir := t.TempDir()
|
|
|
|
s := &PrepSubsystem{
|
|
ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}),
|
|
forge: forge.NewForge(srv.URL, "test-token"),
|
|
forgeURL: srv.URL,
|
|
forgeToken: "test-token",
|
|
backoff: make(map[string]time.Time),
|
|
failCount: make(map[string]int),
|
|
}
|
|
|
|
result := s.attemptVerifyAndMerge(dir, "core", "test", "agent/fix", 1)
|
|
assert.Equal(t, mergeConflict, result)
|
|
}
|