fix: add missing LinkBranch stubs to test doubles

Fix go vet/test failures by adding LinkBranch methods to stubForge, prCapturingForge, testForge, and fakeForge. Update test data from 'sam/archie' to 'acme/widget' and state label defaults from 'archie:*' to 'agent:*'. Add Taskfile.yml for project build automation. Implement container self-network detection so spawned agents join the daemon's Docker network.
This commit is contained in:
sam committed 2026-07-24 13:32:50 +10:00
1 parent d80401d595
commit 6ebbd3b2cf
22 files changed
+273 -138

No files matched your search

+1
View File
@@ -17,3 +17,4 @@
{"id":"int-8c96ed96d1fd074033c2cdea50978276","kind":"field_change","created_at":"2026-07-24T02:49:55.599150491Z","actor":"Sam Catlow","issue_id":"archie-core-mjj","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Added internal/yaegiutil (New for interpreter+symbol bootstrap, Resolve[T] for eval+type-assert an export, Safe[R] for panic recovery) and migrated all 6 call sites (gate/gateeval, workflow/wfeval, workflow/skillbuild, skillscript, plugin, skill) to use it, removing the duplicated interp.New/stdlib.Symbols/recover boilerplate from each. Preserved each site's distinct symbol tables, export conventions, and panic-recovery scope (recovery now correctly wraps the resolved function's invocation too, not just eval/resolve). All existing tests pass; added yaegiutil_test.go."}}
{"id":"int-4be2b65448981e66c8be987f90dd450a","kind":"field_change","created_at":"2026-07-24T02:49:56.020907928Z","actor":"Sam Catlow","issue_id":"archie-core-cen","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Extracted mergeSkillWorkflows() shared by BuildRegistry and AugmentRegistry in internal/workflow/skillbuild/skillbuild.go, eliminating the copy-pasted catalog/merge loop. loadStage now built on yaegiutil (see archie-core-mjj) removing its separate interpreter-bootstrap duplication; kept the legacy positional-fields fallback and wfeval's distinct stages.Stage export convention since they are genuinely different Yaegi extension conventions, not accidental duplication. All existing skillbuild/wfeval tests pass."}}
{"id":"int-6e7f123e648eede675f71a47a6d625d5","kind":"field_change","created_at":"2026-07-24T02:53:05.487749413Z","actor":"Sam Catlow","issue_id":"archie-core-p9h","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Added internal/natsrpc (Client.Request + generic Call[Resp] for timeout-bounded request/reply, RegisterAll for multi-subject subscribe-with-rollback, Respond for marshal+log-on-failure, Envelope/NewEnvelope/Err for the error-string response field) and migrated storerpc, worktreerpc, forgerpc to build on it, removing the near-identical hand-rolled versions from each. Kept each Client's own Conn/Timeout fields (rather than embedding natsrpc.Client) so existing call-site struct literals in cmd/archie-agent/taskrun.go and cmd/archied/main.go didn't need to change. go build ./... clean; storerpc/natsrpc tests pass; forgerpc/worktreerpc test packages have a pre-existing unrelated build failure (missing LinkBranch on test fakes, predates this work, confirmed via git stash)."}}
{"id":"int-a989b2ac7c63b3fb55d282e31a3762c2","kind":"field_change","created_at":"2026-07-24T03:04:57.847938132Z","actor":"Sam Catlow","issue_id":"archie-core-s1r","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Added LinkBranch stub methods to stubForge, prCapturingForge, testForge, and fakeForge. go build/vet/test ./... now clean across the whole module."}}
+2
View File
@@ -1,3 +1,5 @@
{"_type":"issue","id":"archie-core-jfg","title":"Spawned archie-agent containers not on daemon's docker network — can't reach NATS","description":"Root cause of 'agent still failing on the server': archied's container.Pool.Acquire creates archie-agent containers via the Docker SDK with no NetworkMode set, so Docker attaches them to the default bridge network. archied and nats run on the compose-created 'archie-core_default' network instead, so the spawned container's hostname resolution for 'nats' (from NATS_URL=nats://nats:4222) fails and archie-agent can't connect. Confirmed on carina host logs: archied logs show repeating 'taskrun request failed err=\"nats: no responders available for request\"' for every task, containers created and destroyed within ~1.5s (consistent with archie-agent's NATS client failing fast). Fixed by detecting the daemon's own container's network in NewPool (selfNetwork, via ContainerInspect on os.Hostname()) and setting HostConfig.NetworkMode on spawned containers to match.","status":"open","priority":0,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-07-24T03:10:26Z","created_by":"Sam Catlow","updated_at":"2026-07-24T03:10:26Z","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-s1r","title":"Test forge fakes missing LinkBranch method broke go vet/test for whole module","description":"forge.Forge gained LinkBranch(ctx, owner, repo, issueNumber, branch) error in the branch-linking feature (ff4c51e) but the hand-rolled test doubles (stubForge in cmd/archied/main_test.go, prCapturingForge in cmd/archie-agent/taskrun_test.go, testForge in internal/daemon/daemon_test.go, fakeForge in internal/forgerpc/forgerpc_test.go) never got the method added, so they stopped satisfying forge.Forge. This broke go vet ./... and go test ./... for the entire module, not just those 4 packages, since go vet type-checks all test files as part of module vet. Fixed by adding LinkBranch stubs to all four fakes.","status":"closed","priority":1,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-07-24T03:04:53Z","created_by":"Sam Catlow","updated_at":"2026-07-24T03:04:58Z","closed_at":"2026-07-24T03:04:58Z","close_reason":"Added LinkBranch stub methods to stubForge, prCapturingForge, testForge, and fakeForge. go build/vet/test ./... now clean across the whole module.","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-633","title":"config.docker.toml missing required fields, no overlay merge implemented","description":"config.docker.toml was rewritten to be a docs-as-overlay file (comment says base+overlay merge) but internal/config.Load has no merge logic and docker-compose.yml mounts only config.docker.toml at /etc/archie/config.toml. It is missing bot_user, [forge], [dispatch], [models], [providers], [budgets] which Load requires -\u003e daemon fails to start in docker as currently configured. Implement real base+overlay config loading (or restore a full standalone docker config) so there is one source of truth.","status":"closed","priority":1,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-24T02:42:07Z","created_by":"Sam Catlow","updated_at":"2026-07-24T02:44:53Z","started_at":"2026-07-24T02:42:11Z","closed_at":"2026-07-24T02:44:53Z","close_reason":"Implemented config.LoadOverlay (base decode + overlay decode into same struct, then shared finalize/validate), wired -config-overlay flag in cmd/archied, fixed docker-compose.yml to mount both base config.toml and config.docker.toml overlay, minimized config.docker.toml to true diff-only overlay, added tests proving overlay-omitted required fields (bot_user, repos) still come from base.","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-u64","title":"Daemon: process multiple tasks concurrently (max_concurrency enforcement)","description":"Daemon currently processes one task at a time (docs/prds/archie-core-v2-architecture.md Phase 2). This is the core blocker between current state and any multi-agent scaling mode — needed before container max_concurrency or same-repo concurrency can matter. Wire the daemon's dispatch loop to run N tasks in parallel, respecting a configurable max_concurrency.","design":"internal/container/pool.go already enforces max_concurrency for container lifecycle — reuse that limit/pattern in the daemon's task dispatch rather than inventing a second concurrency control.","acceptance_criteria":"Daemon dispatch loop runs multiple tasks concurrently up to a configured max_concurrency limit; single-task-at-a-time behavior is gone.","status":"closed","priority":1,"issue_type":"feature","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-23T19:36:31Z","created_by":"Sam Catlow","updated_at":"2026-07-23T21:37:42Z","started_at":"2026-07-23T21:29:41Z","closed_at":"2026-07-23T21:37:42Z","close_reason":"Implemented concurrent SQLite and NATS task dispatch using containers.max_concurrency, with default same-repo serialization and race-tested dispatcher coverage.","dependency_count":0,"dependent_count":2,"comment_count":0}
{"_type":"issue","id":"archie-core-mjj","title":"Consolidate 6 duplicated Yaegi interpreter bootstraps","description":"internal/gate/gateeval/yaegi.go, internal/workflow/wfeval/yaegi.go, internal/workflow/skillbuild/skillbuild.go, internal/skillscript/yaegi.go, internal/plugin/plugin.go, internal/skill/plugin.go each hand-roll interp.New/i.Use(stdlib.Symbols)/panic-recovery. Extract a shared helper (new package, e.g. internal/yaegiutil) for interpreter construction + panic-safe eval, used by all six.","status":"closed","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-07-24T02:42:07Z","created_by":"Sam Catlow","updated_at":"2026-07-24T02:49:56Z","closed_at":"2026-07-24T02:49:56Z","close_reason":"Added internal/yaegiutil (New for interpreter+symbol bootstrap, Resolve[T] for eval+type-assert an export, Safe[R] for panic recovery) and migrated all 6 call sites (gate/gateeval, workflow/wfeval, workflow/skillbuild, skillscript, plugin, skill) to use it, removing the duplicated interp.New/stdlib.Symbols/recover boilerplate from each. Preserved each site's distinct symbol tables, export conventions, and panic-recovery scope (recovery now correctly wraps the resolved function's invocation too, not just eval/resolve). All existing tests pass; added yaegiutil_test.go.","dependency_count":0,"dependent_count":0,"comment_count":0}
+1
View File
@@ -0,0 +1 @@
232687984b96b8c6590d03efb71c36df
+77
View File
@@ -0,0 +1,77 @@
version: "3"
vars:
BIN_DIR: "bin"
tasks:
default:
desc: List available tasks
cmds:
- task --list
fmt:
desc: Format and fix Go source (gofumpt, go fix)
cmds:
- gofumpt -w .
- go fix ./...
vet:
desc: Run go vet
cmds:
- go vet ./...
lint:
desc: Run golangci-lint
cmds:
- golangci-lint run ./...
build:
desc: Build archied and archie-agent binaries
sources:
- "**/*.go"
- go.mod
- go.sum
generates:
- "{{.BIN_DIR}}/archied"
- "{{.BIN_DIR}}/archie-agent"
cmds:
- go build -o {{.BIN_DIR}}/archied ./cmd/archied
- go build -o {{.BIN_DIR}}/archie-agent ./cmd/archie-agent
test:
desc: Run the Go test suite
cmds:
- go test ./... -count=1
check:
desc: "Full quality gate: fmt, vet, build, test (matches [[repos.gate]] in config.toml)"
cmds:
- task: fmt
- task: vet
- task: build
- task: test
clean:
desc: Remove build artifacts
cmds:
- rm -rf {{.BIN_DIR}}
docker-build:
desc: Build the archie-agent sandbox image
cmds:
- docker compose build agent
docker-up:
desc: Start the archied + NATS stack via docker compose
cmds:
- docker compose up -d
docker-down:
desc: Stop the docker compose stack
cmds:
- docker compose down
docker-logs:
desc: Follow the archied container logs
cmds:
- docker compose logs -f archied
+2 -2
View File
@@ -22,7 +22,7 @@ func TestBootTaskID(t *testing.T) {
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"})
data, err := json.Marshal(container.TaskPayload{ID: 42, Owner: "acme", Repo: "widget"})
if err != nil {
t.Fatal(err)
}
@@ -48,7 +48,7 @@ func TestBootTaskID(t *testing.T) {
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"})
data, _ := json.Marshal(container.TaskPayload{Owner: "acme", Repo: "widget"})
if err := os.WriteFile(filepath.Join(dir, "task.json"), data, 0o644); err != nil {
t.Fatal(err)
}
+9 -5
View File
@@ -93,6 +93,10 @@ func (f *prCapturingForge) VerifyPush(context.Context, string, string) error {
panic("unexpected call")
}
func (f *prCapturingForge) LinkBranch(context.Context, string, string, int, string) error {
panic("unexpected call")
}
// newLocalRemote mirrors worktree_test.go's helper: a bare repo with one
// commit on main, reachable via file://<host>/<owner>/<repo>.git.
func newLocalRemote(t *testing.T, owner, repo string) string {
@@ -140,12 +144,12 @@ func TestRunTaskExecutesBootstrapWorkflowEndToEnd(t *testing.T) {
t.Skip("git not installed")
}
ctx := context.Background()
host := newLocalRemote(t, "sam", "archie")
host := newLocalRemote(t, "acme", "widget")
// archied side: real Store, a capturing Forge, and the Manager that
// actually holds the (unused-for-file-remotes) push token.
st := store.OpenTest(t)
if _, err := st.EnqueueIssue(ctx, "sam", "archie", 1, "feat: bootstrap test", "", "bootstrap"); err != nil {
if _, err := st.EnqueueIssue(ctx, "acme", "widget", 1, "feat: bootstrap test", "", "bootstrap"); err != nil {
t.Fatalf("enqueue: %v", err)
}
task, err := st.ClaimNext(ctx)
@@ -164,7 +168,7 @@ func TestRunTaskExecutesBootstrapWorkflowEndToEnd(t *testing.T) {
// The daemon always prepares the worktree before container acquire —
// reproduce that here so the container's bind mount has real content.
hostDir, _, err := daemonTrees.Prepare(ctx, "sam", "archie", "main", 1, task.Title, "", "bootstrap")
hostDir, _, err := daemonTrees.Prepare(ctx, "acme", "widget", "main", 1, task.Title, "", "bootstrap")
if err != nil {
t.Fatalf("daemon-side prepare: %v", err)
}
@@ -195,7 +199,7 @@ func TestRunTaskExecutesBootstrapWorkflowEndToEnd(t *testing.T) {
req := taskrun.Request{
Task: task,
Repo: config.Repo{Owner: "sam", Name: "archie", Base: "main"},
Repo: config.Repo{Owner: "acme", Name: "widget", Base: "main"},
Cfg: config.Config{}.ForTask(),
}
@@ -216,7 +220,7 @@ func TestRunTaskExecutesBootstrapWorkflowEndToEnd(t *testing.T) {
// The authoritative state landed in archied's store via storerpc, not
// just in the in-memory tc.Task.
stored, err := st.TaskByIssue(ctx, "sam", "archie", 1)
stored, err := st.TaskByIssue(ctx, "acme", "widget", 1)
if err != nil || stored == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", stored, err)
}
+6 -3
View File
@@ -53,6 +53,9 @@ func (stubForge) CreateIssue(context.Context, string, string, string, string, []
}
func (stubForge) React(context.Context, string, string, int, string) error { panic("unexpected call") }
func (stubForge) VerifyPush(context.Context, string, string) error { panic("unexpected call") }
func (stubForge) LinkBranch(context.Context, string, string, int, string) error {
panic("unexpected call")
}
func startEmbeddedNATS(t *testing.T) *server.Server {
t.Helper()
@@ -90,7 +93,7 @@ func TestRegisterTaskRPCServersReachableFromClient(t *testing.T) {
ctx := context.Background()
storeClient := &storerpc.Client{Conn: clientConn, Timeout: 2 * time.Second}
if _, err := st.EnqueueIssue(ctx, "sam", "archie", 1, "t", "b", ""); err != nil {
if _, err := st.EnqueueIssue(ctx, "acme", "widget", 1, "t", "b", ""); err != nil {
t.Fatalf("enqueue: %v", err)
}
task, err := st.ClaimNext(ctx)
@@ -102,12 +105,12 @@ func TestRegisterTaskRPCServersReachableFromClient(t *testing.T) {
}
forgeClient := &forgerpc.Client{Conn: clientConn, Timeout: 2 * time.Second}
if _, err := forgeClient.Comment(ctx, "sam", "archie", 1, "hi"); err != nil {
if _, err := forgeClient.Comment(ctx, "acme", "widget", 1, "hi"); err != nil {
t.Fatalf("forgerpc Comment unreachable: %v", err)
}
treesClient := &worktreerpc.Client{Conn: clientConn, Timeout: 2 * time.Second}
if _, _, err := treesClient.Prepare(ctx, "sam", "archie", "main", 1, "feat: x", "", ""); err == nil {
if _, _, err := treesClient.Prepare(ctx, "acme", "widget", "main", 1, "feat: x", "", ""); err == nil {
t.Fatal("expected Prepare to fail against a non-git remote, proving the RPC round-tripped")
} else if err.Error() == "" {
t.Fatal("expected a non-empty error from the worktreerpc round trip")
+23 -23
View File
@@ -228,21 +228,21 @@ func TestDispatchDefaults(t *testing.T) {
d.AckReaction = "eyes"
}
// StateLabel should return the legacy constants.
if got := d.StateLabel("queued"); got != "archie:queued" {
t.Errorf("queued: got %q, want archie:queued", got)
// StateLabel should return the default agent:* labels.
if got := d.StateLabel("queued"); got != "agent:queued" {
t.Errorf("queued: got %q, want agent:queued", got)
}
if got := d.StateLabel("working"); got != "archie:working" {
t.Errorf("working: got %q, want archie:working", got)
if got := d.StateLabel("working"); got != "agent:working" {
t.Errorf("working: got %q, want agent:working", got)
}
if got := d.StateLabel("waiting"); got != "archie:waiting" {
t.Errorf("waiting: got %q, want archie:waiting", got)
if got := d.StateLabel("waiting"); got != "agent:waiting" {
t.Errorf("waiting: got %q, want agent:waiting", got)
}
if got := d.StateLabel("pr"); got != "archie:pr" {
t.Errorf("pr: got %q, want archie:pr", got)
if got := d.StateLabel("pr"); got != "agent:pr" {
t.Errorf("pr: got %q, want agent:pr", got)
}
if got := d.StateLabel("parked"); got != "archie:parked" {
t.Errorf("parked: got %q, want archie:parked", got)
if got := d.StateLabel("parked"); got != "agent:parked" {
t.Errorf("parked: got %q, want agent:parked", got)
}
// Unknown state returns empty.
@@ -282,11 +282,11 @@ func TestDispatchCustomLabels(t *testing.T) {
}
// Missing keys fall back to defaults.
if got := d.StateLabel("waiting"); got != "archie:waiting" {
t.Errorf("waiting: got %q, want archie:waiting (fallback)", got)
if got := d.StateLabel("waiting"); got != "agent:waiting" {
t.Errorf("waiting: got %q, want agent:waiting (fallback)", got)
}
if got := d.StateLabel("pr"); got != "archie:pr" {
t.Errorf("pr: got %q, want archie:pr (fallback)", got)
if got := d.StateLabel("pr"); got != "agent:pr" {
t.Errorf("pr: got %q, want agent:pr (fallback)", got)
}
// Empty AckReaction.
@@ -303,7 +303,7 @@ func TestDispatchCustomLabels(t *testing.T) {
for _, v := range vals {
seen[v] = true
}
for _, want := range []string{"bot:queued", "bot:working", "bot:parked", "archie:waiting", "archie:pr", "archie:dead"} {
for _, want := range []string{"bot:queued", "bot:working", "bot:parked", "agent:waiting", "agent:pr", "agent:dead"} {
if !seen[want] {
t.Errorf("LabelValues missing %q", want)
}
@@ -340,7 +340,7 @@ func TestLoadDispatchAckReaction(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
contents := "bot_user = \"archie\"\n" + tt.dispatch + "\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"
contents := "bot_user = \"widget\"\n" + tt.dispatch + "\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"
if err := os.WriteFile(path, []byte(contents), 0o600); err != nil {
t.Fatal(err)
}
@@ -373,7 +373,7 @@ func TestLoadRejectsInvalidConfigEnumsAndGlobs(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
contents := "bot_user = \"archie\"\n"
contents := "bot_user = \"widget\"\n"
if tt.name != "test glob" {
contents += "\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"
}
@@ -406,7 +406,7 @@ func TestLoadAgentDefaultsAndOverrides(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
contents := "bot_user = \"archie\"\n" + tt.agent + "\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"
contents := "bot_user = \"widget\"\n" + tt.agent + "\n[[repos]]\nowner = \"acme\"\nname = \"app\"\n"
if err := os.WriteFile(path, []byte(contents), 0o600); err != nil {
t.Fatal(err)
}
@@ -433,7 +433,7 @@ func TestLoadContainerVolumeTTL(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
contents := "bot_user = \"archie\"\n" +
contents := "bot_user = \"widget\"\n" +
"[agent]\nmode = \"nats\"\n" +
"[nats]\nurl = \"nats://localhost:4222\"\n" +
"[containers]\nenabled = true\nimage = \"archie-agent:test\"\n" + tt.ttl +
@@ -455,7 +455,7 @@ func TestLoadContainerVolumeTTL(t *testing.T) {
func TestLoadRejectsNegativeContainerVolumeTTL(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
contents := "bot_user = \"archie\"\n" +
contents := "bot_user = \"widget\"\n" +
"[agent]\nmode = \"nats\"\n" +
"[nats]\nurl = \"nats://localhost:4222\"\n" +
"[containers]\nenabled = true\nimage = \"archie-agent:test\"\nvolume_ttl = \"-1h\"\n" +
@@ -488,7 +488,7 @@ func TestExampleConfigLoads(t *testing.T) {
func TestLoadOverlay(t *testing.T) {
dir := t.TempDir()
basePath := filepath.Join(dir, "config.toml")
base := "bot_user = \"archie\"\nwork_dir = \"/base/work\"\n" +
base := "bot_user = \"widget\"\nwork_dir = \"/base/work\"\n" +
"[agent]\nmode = \"inprocess\"\n" +
"[[repos]]\nowner = \"acme\"\nname = \"app\"\n"
if err := os.WriteFile(basePath, []byte(base), 0o600); err != nil {
@@ -515,7 +515,7 @@ func TestLoadOverlay(t *testing.T) {
t.Errorf("Agent.Mode: got %q, want %q", cfg.Agent.Mode, "nats")
}
// Fields the overlay omits keep the base value.
if cfg.BotUser != "archie" {
if cfg.BotUser != "widget" {
t.Errorf("BotUser: got %q, want base value", cfg.BotUser)
}
if len(cfg.Repos) != 1 || cfg.Repos[0].Owner != "acme" {
+47 -4
View File
@@ -60,6 +60,12 @@ type Pool struct {
cfg Config
log *slog.Logger
natsURL string
// network is the user-defined Docker network spawned containers join,
// detected from the daemon's own container so they can resolve
// sibling services (nats, etc.) by compose service name. Empty when
// the daemon isn't running in a container on such a network, or when
// detection fails — Docker then falls back to its default bridge.
network string
mu sync.Mutex
active int
@@ -104,6 +110,7 @@ func NewPool(ctx context.Context, cfg Config, natsURL string, log *slog.Logger)
log: log,
natsURL: natsURL,
ownCli: cfg.DockerClient == nil,
network: selfNetwork(ctx, cli, log),
}
// Pull image if needed.
@@ -142,6 +149,18 @@ func (p *Pool) Acquire(ctx context.Context, mounts []storage.Mount, env []string
name := fmt.Sprintf("archie-agent-%d", time.Now().UnixNano())
hostConfig := &container.HostConfig{
Mounts: storage.ConvertMounts(mounts),
AutoRemove: true,
}
if p.network != "" {
// Join the same user-defined network the daemon itself is on, so
// the agent container can resolve sibling compose services (nats,
// etc.) by name — otherwise Docker attaches it to the default
// bridge network, where those hostnames don't resolve.
hostConfig.NetworkMode = container.NetworkMode(p.network)
}
resp, err := p.cli.ContainerCreate(ctx, client.ContainerCreateOptions{
Name: name,
Config: &container.Config{
@@ -151,10 +170,7 @@ func (p *Pool) Acquire(ctx context.Context, mounts []storage.Mount, env []string
"archie-daemon": "true",
},
},
HostConfig: &container.HostConfig{
Mounts: storage.ConvertMounts(mounts),
AutoRemove: true,
},
HostConfig: hostConfig,
})
if err != nil {
p.mu.Lock()
@@ -255,6 +271,33 @@ func (p *Pool) pullImage(ctx context.Context) error {
return nil
}
// selfNetwork detects the user-defined Docker network the current
// process's own container is attached to, by inspecting the container
// named after our hostname (Docker sets a container's hostname to its
// short ID by default). Returns "" if we're not running in a container,
// the inspect fails, or we're only on the default bridge network — in
// all of those cases Acquire falls back to Docker's normal default.
func selfNetwork(ctx context.Context, cli *client.Client, log *slog.Logger) string {
hostname, err := os.Hostname()
if err != nil {
return ""
}
self, err := cli.ContainerInspect(ctx, hostname, client.ContainerInspectOptions{})
if err != nil {
return ""
}
if self.Container.NetworkSettings == nil {
return ""
}
for name := range self.Container.NetworkSettings.Networks {
if name != "bridge" {
log.Info("spawned containers will join daemon's network", "network", name)
return name
}
}
return ""
}
// recoverOrphans stops and removes containers left by a previous daemon.
func (p *Pool) recoverOrphans(ctx context.Context) {
list, err := p.cli.ContainerList(ctx, client.ContainerListOptions{
+2 -2
View File
@@ -54,7 +54,7 @@ func TestContainerSupportsGracePeriod(t *testing.T) {
func TestWriteTaskJSONProducesValidFile(t *testing.T) {
dir := t.TempDir()
payload := TaskPayload{
ID: 42, Owner: "sam", Repo: "todo", Number: 170,
ID: 42, Owner: "acme", Repo: "todo", Number: 170,
Title: "fix bug", Body: "body text",
Labels: []string{"bug"}, Workflow: "tdd",
}
@@ -100,7 +100,7 @@ func TestTaskPayloadWrittenAsVolumeFile(t *testing.T) {
}
payload := TaskPayload{
ID: 42, Owner: "sam", Repo: "todo", Number: 170,
ID: 42, Owner: "acme", Repo: "todo", Number: 170,
Title: "fix bug", Body: "body text",
Labels: []string{"bug"}, Workflow: "tdd",
}
+36 -35
View File
@@ -68,7 +68,7 @@ func TestTaskDispatcherEnforcesMaxConcurrency(t *testing.T) {
var peak atomic.Int32
for i := 1; i <= 3; i++ {
task := &store.Task{Owner: "sam", Repo: "repo-" + string(rune('0'+i))}
task := &store.Task{Owner: "acme", Repo: "repo-" + string(rune('0'+i))}
dispatcher.Submit(context.Background(), task, func(context.Context, *store.Task) {
n := active.Add(1)
for {
@@ -118,14 +118,14 @@ func TestTaskDispatcherSerializesTasksForSameRepo(t *testing.T) {
secondStarted := make(chan struct{})
otherRepoStarted := make(chan struct{})
dispatcher.Submit(context.Background(), &store.Task{Owner: "sam", Repo: "archie"}, func(context.Context, *store.Task) {
dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
close(firstStarted)
<-releaseFirst
})
dispatcher.Submit(context.Background(), &store.Task{Owner: "sam", Repo: "archie"}, func(context.Context, *store.Task) {
dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
close(secondStarted)
})
dispatcher.Submit(context.Background(), &store.Task{Owner: "sam", Repo: "tau"}, func(context.Context, *store.Task) {
dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "gizmo"}, func(context.Context, *store.Task) {
close(otherRepoStarted)
})
@@ -159,17 +159,17 @@ func TestTaskDispatcherRunsConcurrentReposInParallel(t *testing.T) {
t.Parallel()
dispatcher := newTaskDispatcher(3, func(owner, repo string) bool {
return owner == "sam" && repo == "archie"
return owner == "acme" && repo == "widget"
})
releaseFirst := make(chan struct{})
firstStarted := make(chan struct{})
secondStarted := make(chan struct{})
dispatcher.Submit(context.Background(), &store.Task{Owner: "sam", Repo: "archie"}, func(context.Context, *store.Task) {
dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
close(firstStarted)
<-releaseFirst
})
dispatcher.Submit(context.Background(), &store.Task{Owner: "sam", Repo: "archie"}, func(context.Context, *store.Task) {
dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
close(secondStarted)
})
@@ -193,7 +193,7 @@ func TestTaskDispatcherWaitsForRunningTasks(t *testing.T) {
dispatcher := newTaskDispatcher(1, nil)
release := make(chan struct{})
dispatcher.Submit(context.Background(), &store.Task{Owner: "sam", Repo: "archie"}, func(context.Context, *store.Task) {
dispatcher.Submit(context.Background(), &store.Task{Owner: "acme", Repo: "widget"}, func(context.Context, *store.Task) {
<-release
})
@@ -220,19 +220,19 @@ func TestDaemonAllowConcurrentForReadsRepoConfig(t *testing.T) {
d := &Daemon{
Cfg: config.Config{
Repos: []config.Repo{
{Owner: "sam", Name: "archie", AllowConcurrent: true},
{Owner: "sam", Name: "todo"},
{Owner: "acme", Name: "widget", AllowConcurrent: true},
{Owner: "acme", Name: "todo"},
},
},
}
if !d.allowConcurrentFor("sam", "archie") {
if !d.allowConcurrentFor("acme", "widget") {
t.Fatal("expected allow_concurrent=true repo to report concurrent-allowed")
}
if d.allowConcurrentFor("sam", "todo") {
if d.allowConcurrentFor("acme", "todo") {
t.Fatal("expected repo without allow_concurrent to report false")
}
if d.allowConcurrentFor("sam", "unknown") {
if d.allowConcurrentFor("acme", "unknown") {
t.Fatal("expected unknown repo to report false")
}
}
@@ -295,7 +295,7 @@ func TestRunViaAgentParksOnRequestFailure(t *testing.T) {
d, s := daemonWithNATS(t)
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "archie", 1, "t", "b", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 1, "t", "b", ""); err != nil {
t.Fatal(err)
}
task, err := s.ClaimNext(ctx)
@@ -306,9 +306,9 @@ func TestRunViaAgentParksOnRequestFailure(t *testing.T) {
// No responder registered on the taskrun subject — the request must
// fail, and runViaAgent must park rather than leave the task stuck
// running.
d.runViaAgent(ctx, task, config.Repo{Owner: "sam", Name: "archie"})
d.runViaAgent(ctx, task, config.Repo{Owner: "acme", Name: "widget"})
got, err := s.TaskByIssue(ctx, "sam", "archie", 1)
got, err := s.TaskByIssue(ctx, "acme", "widget", 1)
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
@@ -321,7 +321,7 @@ func TestRunViaAgentParksOnRunError(t *testing.T) {
d, s := daemonWithNATS(t)
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "archie", 2, "t", "b", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 2, "t", "b", ""); err != nil {
t.Fatal(err)
}
task, err := s.ClaimNext(ctx)
@@ -338,9 +338,9 @@ func TestRunViaAgentParksOnRunError(t *testing.T) {
}
t.Cleanup(func() { sub.Unsubscribe() })
d.runViaAgent(ctx, task, config.Repo{Owner: "sam", Name: "archie"})
d.runViaAgent(ctx, task, config.Repo{Owner: "acme", Name: "widget"})
got, err := s.TaskByIssue(ctx, "sam", "archie", 2)
got, err := s.TaskByIssue(ctx, "acme", "widget", 2)
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
@@ -354,7 +354,7 @@ func TestRunViaAgentSendsExpectedRequest(t *testing.T) {
d.Cfg.DiffCapLines = 999
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "archie", 3, "t", "b", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 3, "t", "b", ""); err != nil {
t.Fatal(err)
}
task, err := s.ClaimNext(ctx)
@@ -375,7 +375,7 @@ func TestRunViaAgentSendsExpectedRequest(t *testing.T) {
}
t.Cleanup(func() { sub.Unsubscribe() })
repo := config.Repo{Owner: "sam", Name: "archie", Base: "main"}
repo := config.Repo{Owner: "acme", Name: "widget", Base: "main"}
d.runViaAgent(ctx, task, repo)
select {
@@ -383,7 +383,7 @@ func TestRunViaAgentSendsExpectedRequest(t *testing.T) {
if req.Task == nil || req.Task.ID != task.ID {
t.Fatalf("request Task = %+v, want ID %d", req.Task, task.ID)
}
if req.Repo.FullName() != "sam/archie" {
if req.Repo.FullName() != "acme/widget" {
t.Fatalf("request Repo = %+v", req.Repo)
}
if req.Cfg.DiffCapLines != 999 {
@@ -395,7 +395,7 @@ func TestRunViaAgentSendsExpectedRequest(t *testing.T) {
// Success path: runViaAgent must not park a task that archie-agent
// already reported as complete — the daemon just logs it.
got, err := s.TaskByIssue(ctx, "sam", "archie", 3)
got, err := s.TaskByIssue(ctx, "acme", "widget", 3)
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
@@ -474,8 +474,9 @@ func (f *testForge) CloseIssue(context.Context, string, string, int, string) err
func (f *testForge) CreateIssue(context.Context, string, string, string, string, []string) (int, error) {
return 0, nil
}
func (f *testForge) React(context.Context, string, string, int, string) error { return nil }
func (f *testForge) VerifyPush(context.Context, string, string) error { return nil }
func (f *testForge) React(context.Context, string, string, int, string) error { return nil }
func (f *testForge) VerifyPush(context.Context, string, string) error { return nil }
func (f *testForge) LinkBranch(context.Context, string, string, int, string) error { return nil }
func testDaemon(t *testing.T, maxRetries int, _ int) (*Daemon, *store.Store, *testForge) {
t.Helper()
@@ -508,7 +509,7 @@ func setupParkedTask(t *testing.T, s *store.Store, retryCount int) *store.Task {
t.Helper()
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "todo", 1, "t", "b", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "todo", 1, "t", "b", ""); err != nil {
t.Fatal(err)
}
task, err := s.ClaimNext(ctx)
@@ -524,7 +525,7 @@ func setupParkedTask(t *testing.T, s *store.Store, retryCount int) *store.Task {
}
}
task, err = s.TaskByIssue(ctx, "sam", "todo", 1)
task, err = s.TaskByIssue(ctx, "acme", "todo", 1)
if err != nil || task == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", task, err)
}
@@ -538,11 +539,11 @@ func TestMaybeRetryParkedUnderThreshold(t *testing.T) {
_ = setupParkedTask(t, s, 0)
is := forge.Issue{Number: 1, Labels: []string{}}
repo := config.Repo{Owner: "sam", Name: "todo"}
repo := config.Repo{Owner: "acme", Name: "todo"}
d.maybeRetryParked(ctx, repo, is)
task, err := s.TaskByIssue(ctx, "sam", "todo", 1)
task, err := s.TaskByIssue(ctx, "acme", "todo", 1)
if err != nil || task == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", task, err)
}
@@ -567,11 +568,11 @@ func TestMaybeRetryParkedAtThreshold(t *testing.T) {
_ = setupParkedTask(t, s, 3)
is := forge.Issue{Number: 1, Labels: []string{}}
repo := config.Repo{Owner: "sam", Name: "todo"}
repo := config.Repo{Owner: "acme", Name: "todo"}
d.maybeRetryParked(ctx, repo, is)
task, err := s.TaskByIssue(ctx, "sam", "todo", 1)
task, err := s.TaskByIssue(ctx, "acme", "todo", 1)
if err != nil || task == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", task, err)
}
@@ -596,7 +597,7 @@ func TestMaybeRetryParkedSkipsDead(t *testing.T) {
}
is := forge.Issue{Number: 1, Labels: []string{}}
repo := config.Repo{Owner: "sam", Name: "todo"}
repo := config.Repo{Owner: "acme", Name: "todo"}
d.maybeRetryParked(ctx, repo, is)
@@ -613,7 +614,7 @@ func TestMaybeRetryParkedStillParked(t *testing.T) {
ctx := context.Background()
is := forge.Issue{Number: 1, Labels: []string{"archie:parked", "bug"}}
repo := config.Repo{Owner: "sam", Name: "todo"}
repo := config.Repo{Owner: "acme", Name: "todo"}
d.maybeRetryParked(ctx, repo, is)
@@ -629,11 +630,11 @@ func TestMaybeRetryParkedRepoOverride(t *testing.T) {
_ = setupParkedTask(t, s, 1)
is := forge.Issue{Number: 1, Labels: []string{}}
repo := config.Repo{Owner: "sam", Name: "todo", MaxRetries: 1}
repo := config.Repo{Owner: "acme", Name: "todo", MaxRetries: 1}
d.maybeRetryParked(ctx, repo, is)
task, err := s.TaskByIssue(ctx, "sam", "todo", 1)
task, err := s.TaskByIssue(ctx, "acme", "todo", 1)
if err != nil || task == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", task, err)
}
+2 -2
View File
@@ -38,7 +38,7 @@ func TestAssignedIssuesExcludesPRs(t *testing.T) {
func TestIssuesWithLabelExcludesPRs(t *testing.T) {
c, mux := newTestClient(t)
mux.HandleFunc("GET /repos/o/r/issues", func(w http.ResponseWriter, r *http.Request) {
if got := r.URL.Query().Get("labels"); got != "archie" {
if got := r.URL.Query().Get("labels"); got != "widget" {
t.Errorf("labels = %q", got)
}
writeJSON(t, w, []map[string]any{
@@ -46,7 +46,7 @@ func TestIssuesWithLabelExcludesPRs(t *testing.T) {
})
})
issues, err := c.IssuesWithLabel(t.Context(), "o", "r", "archie")
issues, err := c.IssuesWithLabel(t.Context(), "o", "r", "widget")
if err != nil {
t.Fatal(err)
}
+13 -10
View File
@@ -115,6 +115,9 @@ func (f *fakeForge) React(context.Context, string, string, int, string) error {
panic("unexpected call")
}
func (f *fakeForge) VerifyPush(context.Context, string, string) error { panic("unexpected call") }
func (f *fakeForge) LinkBranch(context.Context, string, string, int, string) error {
panic("unexpected call")
}
func newTestServer(t *testing.T) (*fakeForge, *Client) {
t.Helper()
@@ -138,14 +141,14 @@ func newTestServer(t *testing.T) (*fakeForge, *Client) {
func TestClientCommentPersistsViaServer(t *testing.T) {
fg, client := newTestServer(t)
id, err := client.Comment(context.Background(), "sam", "archie", 1, "hello")
id, err := client.Comment(context.Background(), "acme", "widget", 1, "hello")
if err != nil {
t.Fatalf("Comment: %v", err)
}
if id != 99 {
t.Fatalf("expected comment id 99, got %d", id)
}
if len(fg.comments) != 1 || fg.comments[0] != (commentCall{"sam", "archie", 1, "hello"}) {
if len(fg.comments) != 1 || fg.comments[0] != (commentCall{"acme", "widget", 1, "hello"}) {
t.Fatalf("comment did not reach server, got %+v", fg.comments)
}
}
@@ -153,10 +156,10 @@ func TestClientCommentPersistsViaServer(t *testing.T) {
func TestClientCloseIssuePersistsViaServer(t *testing.T) {
fg, client := newTestServer(t)
if err := client.CloseIssue(context.Background(), "sam", "archie", 2, "done"); err != nil {
if err := client.CloseIssue(context.Background(), "acme", "widget", 2, "done"); err != nil {
t.Fatalf("CloseIssue: %v", err)
}
if len(fg.closes) != 1 || fg.closes[0] != (closeCall{"sam", "archie", 2, "done"}) {
if len(fg.closes) != 1 || fg.closes[0] != (closeCall{"acme", "widget", 2, "done"}) {
t.Fatalf("close did not reach server, got %+v", fg.closes)
}
}
@@ -164,14 +167,14 @@ func TestClientCloseIssuePersistsViaServer(t *testing.T) {
func TestClientCreatePRPersistsViaServer(t *testing.T) {
fg, client := newTestServer(t)
num, err := client.CreatePR(context.Background(), "sam", "archie", "title", "head", "main", "body")
num, err := client.CreatePR(context.Background(), "acme", "widget", "title", "head", "main", "body")
if err != nil {
t.Fatalf("CreatePR: %v", err)
}
if num != 7 {
t.Fatalf("expected PR number 7, got %d", num)
}
if len(fg.prs) != 1 || fg.prs[0] != (prCall{"sam", "archie", "title", "head", "main", "body"}) {
if len(fg.prs) != 1 || fg.prs[0] != (prCall{"acme", "widget", "title", "head", "main", "body"}) {
t.Fatalf("PR did not reach server, got %+v", fg.prs)
}
}
@@ -179,13 +182,13 @@ func TestClientCreatePRPersistsViaServer(t *testing.T) {
func TestClientSetStateLabelPersistsViaServer(t *testing.T) {
fg, client := newTestServer(t)
client.SetStateLabel(context.Background(), "sam", "archie", 3, "archie:working", []string{"archie:queued", "archie:working"})
client.SetStateLabel(context.Background(), "acme", "widget", 3, "archie:working", []string{"archie:queued", "archie:working"})
if len(fg.stateLabels) != 1 {
t.Fatalf("expected 1 state label call, got %d", len(fg.stateLabels))
}
got := fg.stateLabels[0]
if got.owner != "sam" || got.repo != "archie" || got.number != 3 || got.label != "archie:working" {
if got.owner != "acme" || got.repo != "widget" || got.number != 3 || got.label != "archie:working" {
t.Fatalf("state label call mismatch: %+v", got)
}
}
@@ -203,7 +206,7 @@ func TestClientPropagatesServerError(t *testing.T) {
t.Cleanup(unsub)
client := &Client{Conn: connect(t, url), Timeout: 2 * time.Second}
_, err = client.Comment(context.Background(), "sam", "archie", 1, "hello")
_, err = client.Comment(context.Background(), "acme", "widget", 1, "hello")
if err == nil {
t.Fatal("expected Comment to propagate the server-side error")
}
@@ -213,7 +216,7 @@ func TestClientCommentTimesOutWithNoResponder(t *testing.T) {
srv := startEmbedded(t)
client := &Client{Conn: connect(t, srv.ClientURL()), Timeout: 100 * time.Millisecond}
_, err := client.Comment(context.Background(), "sam", "archie", 1, "hello")
_, err := client.Comment(context.Background(), "acme", "widget", 1, "hello")
if err == nil {
t.Fatal("expected Comment to time out with no server registered")
}
+2 -2
View File
@@ -61,7 +61,7 @@ func TestConnectAndPublish(t *testing.T) {
defer client.Close()
// Publish a task.
if err := client.PublishTask(ctx, "sam", "todo", 1, "fix bug", "body text", "bug"); err != nil {
if err := client.PublishTask(ctx, "acme", "todo", 1, "fix bug", "body text", "bug"); err != nil {
t.Fatal(err)
}
@@ -78,7 +78,7 @@ func TestConnectAndPublish(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if tm.Owner != "sam" || tm.Repo != "todo" || tm.Number != 1 || tm.Title != "fix bug" || tm.Body != "body text" {
if tm.Owner != "acme" || tm.Repo != "todo" || tm.Number != 1 || tm.Title != "fix bug" || tm.Body != "body text" {
t.Fatalf("unexpected task: %+v", tm)
}
msg.Ack()
+11 -11
View File
@@ -12,14 +12,14 @@ func TestTaskByIssue(t *testing.T) {
s := openTest(t)
ctx := context.Background()
if got, err := s.TaskByIssue(ctx, "sam", "archie", 1); err != nil || got != nil {
if got, err := s.TaskByIssue(ctx, "acme", "widget", 1); err != nil || got != nil {
t.Fatalf("TaskByIssue on empty store = (%+v, %v)", got, err)
}
if _, err := s.EnqueueIssue(ctx, "sam", "archie", 1, "title", "body", "bug"); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 1, "title", "body", "bug"); err != nil {
t.Fatal(err)
}
got, err := s.TaskByIssue(ctx, "sam", "archie", 1)
got, err := s.TaskByIssue(ctx, "acme", "widget", 1)
if err != nil || got == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", got, err)
}
@@ -27,7 +27,7 @@ func TestTaskByIssue(t *testing.T) {
t.Fatalf("TaskByIssue = %+v", got)
}
if got, err := s.TaskByIssue(ctx, "sam", "archie", 2); err != nil || got != nil {
if got, err := s.TaskByIssue(ctx, "acme", "widget", 2); err != nil || got != nil {
t.Fatalf("TaskByIssue for missing issue = (%+v, %v)", got, err)
}
}
@@ -36,7 +36,7 @@ func TestWaitingTasksAndRequeue(t *testing.T) {
s := openTest(t)
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "archie", 1, "t", "b", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 1, "t", "b", ""); err != nil {
t.Fatal(err)
}
task, err := s.ClaimNext(ctx)
@@ -60,7 +60,7 @@ func TestWaitingTasksAndRequeue(t *testing.T) {
if err := s.Requeue(ctx, task.ID, StatusWaitingHuman, "implement"); err != nil {
t.Fatal(err)
}
requeued, err := s.TaskByIssue(ctx, "sam", "archie", 1)
requeued, err := s.TaskByIssue(ctx, "acme", "widget", 1)
if err != nil || requeued == nil || requeued.Status != StatusQueued || requeued.Workflow != "implement" {
t.Fatalf("after forced requeue = %+v, %v", requeued, err)
}
@@ -81,7 +81,7 @@ func TestWaitingTasksAndRequeue(t *testing.T) {
if err := s.Requeue(ctx, task2.ID, StatusParked, ""); err != nil {
t.Fatal(err)
}
retried, err := s.TaskByIssue(ctx, "sam", "archie", 1)
retried, err := s.TaskByIssue(ctx, "acme", "widget", 1)
if err != nil || retried == nil || retried.Status != StatusQueued || retried.Workflow != "feasibility" {
t.Fatalf("after empty-workflow requeue = %+v, %v", retried, err)
}
@@ -103,7 +103,7 @@ func TestWaitingTasksAndRequeue(t *testing.T) {
if err := s.Requeue(ctx, task2.ID, StatusParked, ""); err != nil {
t.Fatal(err)
}
afterRequeue, err := s.TaskByIssue(ctx, "sam", "archie", 1)
afterRequeue, err := s.TaskByIssue(ctx, "acme", "widget", 1)
if err != nil || afterRequeue == nil {
t.Fatalf("TaskByIssue after second requeue = (%+v, %v)", afterRequeue, err)
}
@@ -117,10 +117,10 @@ func TestTasksListingAndStatusCounts(t *testing.T) {
ctx := context.Background()
for i, status := range []string{StatusQueued, StatusRunning, StatusPROpen} {
if _, err := s.EnqueueIssue(ctx, "sam", "archie", i+1, "t", "b", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", i+1, "t", "b", ""); err != nil {
t.Fatal(err)
}
task, err := s.TaskByIssue(ctx, "sam", "archie", i+1)
task, err := s.TaskByIssue(ctx, "acme", "widget", i+1)
if err != nil || task == nil {
t.Fatalf("TaskByIssue(%d) = (%+v, %v)", i+1, task, err)
}
@@ -157,7 +157,7 @@ func TestWorkflowStats(t *testing.T) {
s := openTest(t)
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "archie", 1, "t", "b", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 1, "t", "b", ""); err != nil {
t.Fatal(err)
}
task, err := s.ClaimNext(ctx)
+9 -9
View File
@@ -28,10 +28,10 @@ func TestClearTerminalTasks(t *testing.T) {
statuses := []string{StatusMerged, StatusParked, StatusRejected, StatusClosedWontDo, StatusQueued}
for i, status := range statuses {
if _, err := s.EnqueueIssue(ctx, "sam", "archie", i+1, "t", "b", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", i+1, "t", "b", ""); err != nil {
t.Fatal(err)
}
task, err := s.TaskByIssue(ctx, "sam", "archie", i+1)
task, err := s.TaskByIssue(ctx, "acme", "widget", i+1)
if err != nil || task == nil {
t.Fatalf("TaskByIssue(%d) = (%+v, %v)", i+1, task, err)
}
@@ -71,11 +71,11 @@ func TestEnqueueIsIdempotent(t *testing.T) {
s := openTest(t)
ctx := context.Background()
ins, err := s.EnqueueIssue(ctx, "sam", "todo", 1, "add tests", "body", "archie")
ins, err := s.EnqueueIssue(ctx, "acme", "todo", 1, "add tests", "body", "widget")
if err != nil || !ins {
t.Fatalf("first enqueue = (%v, %v)", ins, err)
}
ins, err = s.EnqueueIssue(ctx, "sam", "todo", 1, "add tests", "body", "archie")
ins, err = s.EnqueueIssue(ctx, "acme", "todo", 1, "add tests", "body", "widget")
if err != nil || ins {
t.Fatalf("duplicate enqueue must be a no-op, got (%v, %v)", ins, err)
}
@@ -120,7 +120,7 @@ func TestIncrementRetryCount(t *testing.T) {
s := openTest(t)
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "todo", 1, "t", "", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "todo", 1, "t", "", ""); err != nil {
t.Fatal(err)
}
task, err := s.ClaimNext(ctx)
@@ -140,7 +140,7 @@ func TestIncrementRetryCount(t *testing.T) {
t.Fatal(err)
}
got, err := s.TaskByIssue(ctx, "sam", "todo", 1)
got, err := s.TaskByIssue(ctx, "acme", "todo", 1)
if err != nil || got == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", got, err)
}
@@ -153,14 +153,14 @@ func TestRetryCountColumn(t *testing.T) {
s := openTest(t)
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "todo", 1, "t", "", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "todo", 1, "t", "", ""); err != nil {
t.Fatal(err)
}
// Verify column exists and defaults to 0 via direct query.
var count int
if err := s.db.QueryRowContext(ctx,
`SELECT retry_count FROM tasks WHERE owner='sam' AND repo='todo' AND issue_number=1`).Scan(&count); err != nil {
`SELECT retry_count FROM tasks WHERE owner='acme' AND repo='todo' AND issue_number=1`).Scan(&count); err != nil {
t.Fatalf("retry_count scan failed: %v", err)
}
if count != 0 {
@@ -172,7 +172,7 @@ func TestClaimTransitionAndRecovery(t *testing.T) {
s := openTest(t)
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "todo", 7, "t", "", "archie,bug"); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "todo", 7, "t", "", "archie,bug"); err != nil {
t.Fatal(err)
}
+3 -3
View File
@@ -53,7 +53,7 @@ func newTestServer(t *testing.T) (*store.Store, *nats.Conn, *Client) {
func enqueueTask(t *testing.T, s *store.Store) *store.Task {
t.Helper()
ctx := context.Background()
if _, err := s.EnqueueIssue(ctx, "sam", "archie", 1, "title", "body", ""); err != nil {
if _, err := s.EnqueueIssue(ctx, "acme", "widget", 1, "title", "body", ""); err != nil {
t.Fatalf("enqueue: %v", err)
}
task, err := s.ClaimNext(ctx)
@@ -80,7 +80,7 @@ func TestClientUpdatePersistsViaServer(t *testing.T) {
t.Fatalf("Update: %v", err)
}
got, err := s.TaskByIssue(context.Background(), "sam", "archie", 1)
got, err := s.TaskByIssue(context.Background(), "acme", "widget", 1)
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
@@ -99,7 +99,7 @@ func TestClientTransitionPersistsViaServer(t *testing.T) {
t.Fatalf("Transition: %v", err)
}
got, err := s.TaskByIssue(context.Background(), "sam", "archie", 1)
got, err := s.TaskByIssue(context.Background(), "acme", "widget", 1)
if err != nil || got == nil {
t.Fatalf("TaskByIssue: (%+v, %v)", got, err)
}
+5 -5
View File
@@ -13,13 +13,13 @@ func TestRequestJSONRoundTrip(t *testing.T) {
req := Request{
Task: &store.Task{
ID: 1,
Owner: "sam",
Repo: "archie",
Owner: "acme",
Repo: "widget",
IssueNumber: 42,
Title: "feat: thing",
Status: store.StatusRunning,
},
Repo: config.Repo{Owner: "sam", Name: "archie", Base: "main"},
Repo: config.Repo{Owner: "acme", Name: "widget", Base: "main"},
Cfg: config.Config{DiffCapLines: 500}.ForTask(),
Providers: map[string]agentexec.Provider{
"anthropic": {Class: "anthropic", APIKeyEnv: "ANTHROPIC_API_KEY"},
@@ -36,10 +36,10 @@ func TestRequestJSONRoundTrip(t *testing.T) {
t.Fatalf("unmarshal: %v", err)
}
if got.Task == nil || got.Task.ID != 1 || got.Task.Owner != "sam" || got.Task.IssueNumber != 42 {
if got.Task == nil || got.Task.ID != 1 || got.Task.Owner != "acme" || got.Task.IssueNumber != 42 {
t.Fatalf("Task did not round-trip: %+v", got.Task)
}
if got.Repo.FullName() != "sam/archie" || got.Repo.BaseBranch() != "main" {
if got.Repo.FullName() != "acme/widget" || got.Repo.BaseBranch() != "main" {
t.Fatalf("Repo did not round-trip: %+v", got.Repo)
}
if got.Cfg.DiffCapLines != 500 {
+4 -4
View File
@@ -30,7 +30,7 @@ func newTestServer(t *testing.T) *Server {
func TestHandleSummary(t *testing.T) {
srv := newTestServer(t)
ctx := t.Context()
if _, err := srv.Store.EnqueueIssue(ctx, "sam", "archie", 1, "t", "b", ""); err != nil {
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "t", "b", ""); err != nil {
t.Fatal(err)
}
@@ -55,7 +55,7 @@ func TestHandleSummary(t *testing.T) {
func TestHandleTasks(t *testing.T) {
srv := newTestServer(t)
ctx := t.Context()
if _, err := srv.Store.EnqueueIssue(ctx, "sam", "archie", 1, "hello", "b", ""); err != nil {
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "hello", "b", ""); err != nil {
t.Fatal(err)
}
@@ -78,10 +78,10 @@ func TestHandleTasks(t *testing.T) {
func TestHandleTask(t *testing.T) {
srv := newTestServer(t)
ctx := t.Context()
if _, err := srv.Store.EnqueueIssue(ctx, "sam", "archie", 1, "t", "b", ""); err != nil {
if _, err := srv.Store.EnqueueIssue(ctx, "acme", "widget", 1, "t", "b", ""); err != nil {
t.Fatal(err)
}
task, err := srv.Store.TaskByIssue(ctx, "sam", "archie", 1)
task, err := srv.Store.TaskByIssue(ctx, "acme", "widget", 1)
if err != nil || task == nil {
t.Fatalf("TaskByIssue = (%+v, %v)", task, err)
}
+2 -2
View File
@@ -47,8 +47,8 @@ func gitRepoWithOriginRef(t *testing.T, base string) string {
func newYaegiGateTaskContext(t *testing.T, dir string) *TaskContext {
t.Helper()
return &TaskContext{
Task: &store.Task{ID: 1, Owner: "sam", Repo: "todo", IssueNumber: 42},
Repo: config.Repo{Owner: "sam", Name: "todo", Base: "main"},
Task: &store.Task{ID: 1, Owner: "acme", Repo: "todo", IssueNumber: 42},
Repo: config.Repo{Owner: "acme", Name: "todo", Base: "main"},
Trees: &worktree.Manager{WorkDir: t.TempDir()},
Dir: dir,
Log: slog.New(slog.DiscardHandler),
+8 -8
View File
@@ -54,7 +54,7 @@ func TestPrepareCommitPushRoundTrip(t *testing.T) {
t.Skip("git not installed")
}
ctx := context.Background()
host := newLocalRemote(t, "sam", "todo")
host := newLocalRemote(t, "acme", "todo")
m := &Manager{
WorkDir: t.TempDir(),
@@ -64,7 +64,7 @@ func TestPrepareCommitPushRoundTrip(t *testing.T) {
BaseURL: "file://" + host,
}
dir, branch, err := m.Prepare(ctx, "sam", "todo", "main", 42, "feat: add test issue title", "", "")
dir, branch, err := m.Prepare(ctx, "acme", "todo", "main", 42, "feat: add test issue title", "", "")
if err != nil {
t.Fatalf("prepare: %v", err)
}
@@ -116,7 +116,7 @@ func TestPrepareCommitPushRoundTrip(t *testing.T) {
// The branch must exist on the remote after push.
cmd := exec.Command("git", "ls-remote", "--heads",
"file://"+filepath.Join(host, "sam", "todo.git"), branch)
"file://"+filepath.Join(host, "acme", "todo.git"), branch)
out, err := cmd.CombinedOutput()
if err != nil || !strings.Contains(string(out), branch) {
t.Fatalf("branch not on remote: %v\n%s", err, out)
@@ -130,7 +130,7 @@ func TestPrepareCommitPushRoundTrip(t *testing.T) {
t.Fatalf("author = %q", got)
}
if err := m.Cleanup("sam", "todo", 42); err != nil {
if err := m.Cleanup("acme", "todo", 42); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(dir); !os.IsNotExist(err) {
@@ -143,7 +143,7 @@ func TestPreparePersistentReusesRepoCacheAndCleanupExpiresIt(t *testing.T) {
t.Skip("git not installed")
}
ctx := context.Background()
host := newLocalRemote(t, "sam", "todo")
host := newLocalRemote(t, "acme", "todo")
m := &Manager{
WorkDir: t.TempDir(),
Token: "unused-for-file-remotes",
@@ -153,16 +153,16 @@ func TestPreparePersistentReusesRepoCacheAndCleanupExpiresIt(t *testing.T) {
}
const ttl = 24 * time.Hour
first, _, err := m.PreparePersistent(ctx, "sam", "todo", "main", 41, "feat: first", "", "", ttl)
first, _, err := m.PreparePersistent(ctx, "acme", "todo", "main", 41, "feat: first", "", "", ttl)
if err != nil {
t.Fatalf("first persistent prepare: %v", err)
}
cache := m.cacheDir("sam", "todo")
cache := m.cacheDir("acme", "todo")
if st, err := os.Stat(filepath.Join(cache, "HEAD")); err != nil || st.IsDir() {
t.Fatalf("repo cache was not created at %s: %v", cache, err)
}
second, _, err := m.PreparePersistent(ctx, "sam", "todo", "main", 42, "feat: second", "", "", ttl)
second, _, err := m.PreparePersistent(ctx, "acme", "todo", "main", 42, "feat: second", "", "", ttl)
if err != nil {
t.Fatalf("second persistent prepare: %v", err)
}
+8 -8
View File
@@ -86,7 +86,7 @@ func TestClientPreparePublishesViaServer(t *testing.T) {
t.Skip("git not installed")
}
ctx := context.Background()
host := newLocalRemote(t, "sam", "archie")
host := newLocalRemote(t, "acme", "widget")
m := &worktree.Manager{
WorkDir: t.TempDir(),
@@ -107,7 +107,7 @@ func TestClientPreparePublishesViaServer(t *testing.T) {
t.Cleanup(unsub)
client := &Client{Conn: connect(t, url), Timeout: 5 * time.Second}
dir, branch, err := client.Prepare(ctx, "sam", "archie", "main", 1, "feat: test", "", "")
dir, branch, err := client.Prepare(ctx, "acme", "widget", "main", 1, "feat: test", "", "")
if err != nil {
t.Fatalf("Prepare: %v", err)
}
@@ -124,7 +124,7 @@ func TestClientPushPublishesViaServer(t *testing.T) {
t.Skip("git not installed")
}
ctx := context.Background()
host := newLocalRemote(t, "sam", "archie")
host := newLocalRemote(t, "acme", "widget")
m := &worktree.Manager{
WorkDir: t.TempDir(),
@@ -134,7 +134,7 @@ func TestClientPushPublishesViaServer(t *testing.T) {
BaseURL: "file://" + host,
}
dir, branch, err := m.Prepare(ctx, "sam", "archie", "main", 1, "feat: test", "", "")
dir, branch, err := m.Prepare(ctx, "acme", "widget", "main", 1, "feat: test", "", "")
if err != nil {
t.Fatalf("prepare: %v", err)
}
@@ -156,11 +156,11 @@ func TestClientPushPublishesViaServer(t *testing.T) {
t.Cleanup(unsub)
client := &Client{Conn: connect(t, url), Timeout: 5 * time.Second}
if err := client.Push(ctx, "sam", "archie", 1, branch); err != nil {
if err := client.Push(ctx, "acme", "widget", 1, branch); err != nil {
t.Fatalf("Push: %v", err)
}
if !remoteHasBranch(t, host, "sam", "archie", branch) {
if !remoteHasBranch(t, host, "acme", "widget", branch) {
t.Fatalf("branch %q was not pushed to the remote", branch)
}
}
@@ -179,7 +179,7 @@ func TestClientPropagatesServerError(t *testing.T) {
client := &Client{Conn: connect(t, url), Timeout: 5 * time.Second}
// No worktree ever prepared at this dir — push must fail.
err = client.Push(context.Background(), "sam", "nonexistent", 999, "some-branch")
err = client.Push(context.Background(), "acme", "nonexistent", 999, "some-branch")
if err == nil {
t.Fatal("expected Push to propagate the server-side git error")
}
@@ -189,7 +189,7 @@ func TestClientPushTimesOutWithNoResponder(t *testing.T) {
srv := startEmbedded(t)
client := &Client{Conn: connect(t, srv.ClientURL()), Timeout: 100 * time.Millisecond}
err := client.Push(context.Background(), "sam", "archie", 1, "branch")
err := client.Push(context.Background(), "acme", "widget", 1, "branch")
if err == nil {
t.Fatal("expected Push to time out with no server registered")
}