Files
archie/internal/daemon/agent_status_test.go
T
sam f92c5b4536
ci/woodpecker/pr/quality Pipeline was successful
Quality / check (pull_request) Canceled after 7m39s
chore(runtime): delete Kit and external agent harness support (#1877)
Archie runs its own agent loop only. Removes Kit resolution and launch,
the harness runner and adapters, the setup terminal and sandbox view,
harness secrets and OAuth capture (table dropped in migration 0075), the
task-tools contract that only Kit containers reached, and the
sandbox-kit-spec dependency. Agent profiles carry image and tools only.
The egress proxy keeps the model-session path; the sandbox relay code
stays for #1867.
2026-11-12 21:29:05 +11:00

94 lines
3.3 KiB
Go

package daemon
import (
"context"
"encoding/json"
"log/slog"
"strings"
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/eventbus"
"github.com/samcharles93/archie-core/internal/events"
"github.com/samcharles93/archie-core/internal/taskrun"
"github.com/samcharles93/archie-core/internal/taskstate"
)
// statusStore records the parks a taskrun reply drove.
type statusStore struct {
storecontract.TaskStore
parks []string
class taskstate.ParkClass
}
func (s *statusStore) InsertEvent(context.Context, events.Event) (int64, error) { return 0, nil }
func (s *statusStore) ParkTask(_ context.Context, _ int64, _, reason string, class taskstate.ParkClass, _ taskstate.Blocker) error {
s.parks = append(s.parks, reason)
s.class = class
return nil
}
// statusBus answers every taskrun request with the same reply.
type statusBus struct{ reply []byte }
func (statusBus) PublishUnique(context.Context, string, string, []byte) error { return nil }
func (statusBus) Fetch(context.Context) (eventbus.Message, error) { return nil, nil }
func (b statusBus) Request(context.Context, string, []byte) ([]byte, error) { return b.reply, nil }
// TestRunViaAgentRequiresTerminalStatus pins that a run which recorded no
// outcome is parked rather than reported as complete: the agent applies the
// task's own transition, so a status the task cannot reach from running means
// nothing landed and the row would stay running forever.
func TestRunViaAgentRequiresTerminalStatus(t *testing.T) {
for _, tc := range []struct {
name string
status string
wantPark string
wantClass taskstate.ParkClass
}{
{name: "empty status parks", status: "", wantPark: "no status", wantClass: taskstate.ParkTransient},
{name: "still running parks", status: taskstate.Running, wantPark: taskstate.Running},
{name: "unknown status parks", status: "done-ish", wantPark: "done-ish"},
{name: "completed status completes", status: taskstate.Completed},
{name: "pr open status completes", status: taskstate.PROpen},
{name: "parked status completes", status: taskstate.Parked},
} {
t.Run(tc.name, func(t *testing.T) {
reply, err := json.Marshal(taskrun.Response{Status: tc.status})
if err != nil {
t.Fatalf("marshal response: %v", err)
}
store := &statusStore{}
d := &Daemon{
Cfg: config.NewHolder(config.Config{}),
Store: store,
Tasks: statusBus{reply: reply},
Log: slog.New(slog.DiscardHandler),
}
d.runViaAgent(t.Context(), &workflow.Task{ID: 7, Attempt: 1, Owner: "owner", Repo: "repo", Workflow: "implement"},
config.Repo{}, config.AgentProfile{}, "")
if tc.wantPark == "" {
if len(store.parks) != 0 {
t.Fatalf("valid status %q parked the task: %v", tc.status, store.parks)
}
return
}
if len(store.parks) != 1 {
t.Fatalf("status %q parked %d times, want 1 (task would stay running)", tc.status, len(store.parks))
}
if !strings.Contains(store.parks[0], tc.wantPark) {
t.Fatalf("park reason %q does not name the condition %q", store.parks[0], tc.wantPark)
}
if tc.wantClass != "" && store.class != tc.wantClass {
t.Fatalf("park class = %q, want %q", store.class, tc.wantClass)
}
})
}
}