daemon.process() branches on ContainerPool != nil: sandboxed tasks publish a taskrun.Request to archie.taskrun.<id> and await the response via the new runViaAgent method, instead of running workflow.Route/workflow.Run locally. Non-container mode is unchanged. Every durable side effect (Store, Forge, git push) already landed via the storerpc/forgerpc/ worktreerpc proxies during archie-agent's run by the time runViaAgent returns — it only parks the task itself on transport/setup failure, never duplicating a terminal state archie-agent's own workflow.Run already recorded. Also fixes a real correctness gap: with concurrent multi-task dispatch (archie-core-u64/g1l) plus containerized archie-agent, a shared queue-group subscription could let one container answer a sibling's taskrun message while having a *different* task's worktree mounted. archie-agent now reads its boot-time task.json and subscribes to its own exact per-task subject when present, falling back to the shared queue group only in dev/pool mode (no task.json). Adds agentexec.ProvidersFromConfig, deduped from cmd/archied's former executionProviders. Closes the archie-core-5zh epic: archie-agent runs an entire task's workflow per invocation instead of one stage per round trip, with all credentials staying daemon-side throughout.
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log/slog"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/container"
|
|
)
|
|
|
|
func TestBootTaskID(t *testing.T) {
|
|
log := slog.New(slog.DiscardHandler)
|
|
|
|
t.Run("no task.json — shared pool mode", func(t *testing.T) {
|
|
id, ok := bootTaskID(t.TempDir(), log)
|
|
if ok || id != 0 {
|
|
t.Fatalf("bootTaskID() = (%d, %v), want (0, false)", id, ok)
|
|
}
|
|
})
|
|
|
|
t.Run("valid task.json — dedicated per-task mode", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
data, err := json.Marshal(container.TaskPayload{ID: 42, Owner: "sam", Repo: "archie"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "task.json"), data, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
id, ok := bootTaskID(dir, log)
|
|
if !ok || id != 42 {
|
|
t.Fatalf("bootTaskID() = (%d, %v), want (42, true)", id, ok)
|
|
}
|
|
})
|
|
|
|
t.Run("malformed task.json falls back to shared pool mode", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, "task.json"), []byte("not json"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
id, ok := bootTaskID(dir, log)
|
|
if ok || id != 0 {
|
|
t.Fatalf("bootTaskID() = (%d, %v), want (0, false)", id, ok)
|
|
}
|
|
})
|
|
|
|
t.Run("zero ID falls back to shared pool mode", func(t *testing.T) {
|
|
dir := t.TempDir()
|
|
data, _ := json.Marshal(container.TaskPayload{Owner: "sam", Repo: "archie"})
|
|
if err := os.WriteFile(filepath.Join(dir, "task.json"), data, 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
id, ok := bootTaskID(dir, log)
|
|
if ok || id != 0 {
|
|
t.Fatalf("bootTaskID() = (%d, %v), want (0, false)", id, ok)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestNATSConnectionSettings(t *testing.T) {
|
|
getenv := func(name string) string {
|
|
switch name {
|
|
case "NATS_URL":
|
|
return "nats://nats.example:4222"
|
|
case "NATS_TOKEN":
|
|
return "test-nats-token"
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
t.Run("container environment", func(t *testing.T) {
|
|
url, token := natsConnectionSettings("", getenv)
|
|
if url != "nats://nats.example:4222" || token != "test-nats-token" {
|
|
t.Fatalf("natsConnectionSettings() = (%q, %q)", url, token)
|
|
}
|
|
})
|
|
|
|
t.Run("flag URL takes precedence", func(t *testing.T) {
|
|
url, token := natsConnectionSettings("nats://flag.example:4222", getenv)
|
|
if url != "nats://flag.example:4222" || token != "test-nats-token" {
|
|
t.Fatalf("natsConnectionSettings() = (%q, %q)", url, token)
|
|
}
|
|
})
|
|
}
|