From 7e723b47a0b221542145ced469be0c0dafcf5fa2 Mon Sep 17 00:00:00 2001 From: archie Date: Fri, 24 Jul 2026 05:27:26 +0000 Subject: [PATCH 1/6] test: failing repro for #58 --- .git-askpass | 2 + internal/worktree/worktree_test.go | 307 +++++++++++++++++++++++++++++ task.json | 1 + 3 files changed, 310 insertions(+) create mode 100755 .git-askpass create mode 100644 task.json diff --git a/.git-askpass b/.git-askpass new file mode 100755 index 000000000..ac06c1b86 --- /dev/null +++ b/.git-askpass @@ -0,0 +1,2 @@ +#!/bin/sh +echo "$ARCHIE_GIT_TOKEN" diff --git a/internal/worktree/worktree_test.go b/internal/worktree/worktree_test.go index bb921d1d7..64b39c732 100644 --- a/internal/worktree/worktree_test.go +++ b/internal/worktree/worktree_test.go @@ -207,3 +207,310 @@ func TestCacheDirCannotEscapeWorkDir(t *testing.T) { t.Fatalf("cache path escaped managed root: %s", cache) } } + +// --------------------------------------------------------------------------- +// Repro tests for uncovered code paths (issue #58) +// --------------------------------------------------------------------------- + +// TestPrepareIdempotentFastPath proves the "already prepared" short-circuit +// in prepare(). The second call must return the same dir/branch without +// error, and the worktree must remain functional (fetch+checkout+reset). +func TestPrepareIdempotentFastPath(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not installed") + } + ctx := context.Background() + host := newLocalRemote(t, "acme", "idem") + + m := &Manager{ + WorkDir: t.TempDir(), + Token: "unused-for-file-remotes", + BotUser: "archie-bot", + BotEmail: "archie-bot@example.com", + BaseURL: "file://" + host, + } + + dir1, branch1, err := m.Prepare(ctx, "acme", "idem", "main", 1, "feat: idempotent", "", "") + if err != nil { + t.Fatalf("first prepare: %v", err) + } + if _, err := os.Stat(filepath.Join(dir1, ".git")); err != nil { + t.Fatalf("worktree not created: %v", err) + } + + // Second Prepare with the same arguments must hit the fast path. + dir2, branch2, err := m.Prepare(ctx, "acme", "idem", "main", 1, "feat: idempotent", "", "") + if err != nil { + t.Fatalf("second prepare (fast path): %v", err) + } + if dir1 != dir2 { + t.Fatalf("fast path returned different dir: %q vs %q", dir1, dir2) + } + if branch1 != branch2 { + t.Fatalf("fast path returned different branch: %q vs %q", branch1, branch2) + } + + // The worktree must still be usable after the fast path. + if _, err := os.Stat(filepath.Join(dir2, ".git")); err != nil { + t.Fatalf("fast path broke .git: %v", err) + } + + // After the fast path, we should be able to commit and push. + if err := os.WriteFile(filepath.Join(dir2, "fast.txt"), []byte("fast path\n"), 0o644); err != nil { + t.Fatal(err) + } + changed, err := m.CommitAll(ctx, dir2, "test fast path") + if err != nil { + t.Fatalf("CommitAll after fast path: %v", err) + } + if !changed { + t.Fatal("CommitAll after fast path reported clean tree, expected changes") + } + if err := m.Push(ctx, dir2, branch2); err != nil { + t.Fatalf("Push after fast path: %v", err) + } +} + +// TestPrepareBadBaseBranch proves that prepare() propagates git clone +// failures when the requested base branch does not exist. +func TestPrepareBadBaseBranch(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not installed") + } + ctx := context.Background() + host := newLocalRemote(t, "acme", "badbase") + + m := &Manager{ + WorkDir: t.TempDir(), + Token: "unused-for-file-remotes", + BotUser: "archie-bot", + BotEmail: "archie-bot@example.com", + BaseURL: "file://" + host, + } + + _, _, err := m.Prepare(ctx, "acme", "badbase", "nonexistent-branch", 1, "feat: test", "", "") + if err == nil { + t.Fatal("expected error for nonexistent base branch, got nil") + } + // The error must mention the git command ("clone") and the bad branch. + if !strings.Contains(err.Error(), "clone") { + t.Fatalf("error should mention 'clone', got: %v", err) + } + if !strings.Contains(err.Error(), "nonexistent-branch") { + t.Fatalf("error should mention bad branch, got: %v", err) + } +} + +// TestPrepareBadCloneURL proves that prepare() propagates git clone +// failures when the clone URL points to a nonexistent repository. +func TestPrepareBadCloneURL(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not installed") + } + ctx := context.Background() + + m := &Manager{ + WorkDir: t.TempDir(), + Token: "unused-for-file-remotes", + BotUser: "archie-bot", + BotEmail: "archie-bot@example.com", + BaseURL: "file:///nonexistent/path/that/does/not/exist", + } + + _, _, err := m.Prepare(ctx, "acme", "norepo", "main", 1, "feat: test", "", "") + if err == nil { + t.Fatal("expected error for bad clone URL, got nil") + } + // The error must mention the git command ("clone"). + if !strings.Contains(err.Error(), "clone") { + t.Fatalf("error should mention 'clone', got: %v", err) + } +} + +// TestCommitAllInNonGitDir proves that CommitAll returns an error when +// invoked in a directory that is not a git repository. +func TestCommitAllInNonGitDir(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not installed") + } + ctx := context.Background() + + m := &Manager{ + WorkDir: t.TempDir(), + Token: "unused", + BotUser: "bot", + BotEmail: "bot@example.com", + } + + dir := t.TempDir() // plain directory, no .git + changed, err := m.CommitAll(ctx, dir, "should fail") + if err == nil { + t.Fatalf("expected error for CommitAll in non-git dir, got (changed=%v, err=nil)", changed) + } + if changed { + t.Fatal("CommitAll in non-git dir reported changes, expected false") + } +} + +// TestChangedLinesInNonGitDir proves that ChangedLines returns an error +// when invoked in a directory that is not a git repository. +func TestChangedLinesInNonGitDir(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not installed") + } + ctx := context.Background() + + m := &Manager{ + WorkDir: t.TempDir(), + Token: "unused", + BotUser: "bot", + BotEmail: "bot@example.com", + } + + dir := t.TempDir() // plain directory, no .git + lines, err := m.ChangedLines(ctx, dir, "main") + if err == nil { + t.Fatalf("expected error for ChangedLines in non-git dir, got (lines=%d, err=nil)", lines) + } + if lines != 0 { + t.Fatalf("ChangedLines in non-git dir returned non-zero lines: %d", lines) + } +} + +// TestDiffInNonGitDir proves that Diff returns an error when invoked +// in a directory that is not a git repository. +func TestDiffInNonGitDir(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not installed") + } + ctx := context.Background() + + m := &Manager{ + WorkDir: t.TempDir(), + Token: "unused", + BotUser: "bot", + BotEmail: "bot@example.com", + } + + dir := t.TempDir() // plain directory, no .git + diff, err := m.Diff(ctx, dir, "main") + if err == nil { + t.Fatalf("expected error for Diff in non-git dir, got diff=%q, err=nil", diff) + } + if diff != "" { + t.Fatalf("Diff in non-git dir returned non-empty output: %q", diff) + } +} + +// TestPushRejected proves that Push returns an error when the remote +// rejects the push (e.g. non-fast-forward). +func TestPushRejected(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not installed") + } + ctx := context.Background() + host := newLocalRemote(t, "acme", "reject") + + m := &Manager{ + WorkDir: t.TempDir(), + Token: "unused-for-file-remotes", + BotUser: "archie-bot", + BotEmail: "archie-bot@example.com", + BaseURL: "file://" + host, + } + + dir, branch, err := m.Prepare(ctx, "acme", "reject", "main", 1, "feat: push test", "", "") + if err != nil { + t.Fatalf("prepare: %v", err) + } + + // Push once so the branch exists on the remote. + if err := os.WriteFile(filepath.Join(dir, "first.txt"), []byte("first\n"), 0o644); err != nil { + t.Fatal(err) + } + if _, err := m.CommitAll(ctx, dir, "first commit"); err != nil { + t.Fatal(err) + } + if err := m.Push(ctx, dir, branch); err != nil { + t.Fatalf("first push: %v", err) + } + + // Now advance the remote branch independently (simulate another + // client pushing), then try to push again from the stale local branch. + // We do this by creating a second worktree that pushes to the same + // branch, making the first worktree's branch out of date. + dir2, _, err := m.Prepare(ctx, "acme", "reject", "main", 2, "feat: conflicting", "", "") + if err != nil { + t.Fatalf("second prepare: %v", err) + } + // Checkout the same branch in the second worktree. + if _, err := exec.Command("git", "-C", dir2, "fetch", "origin", branch).CombinedOutput(); err != nil { + t.Fatalf("fetch branch in second worktree: %v", err) + } + if _, err := exec.Command("git", "-C", dir2, "checkout", "-b", branch, "origin/"+branch).CombinedOutput(); err != nil { + t.Fatalf("checkout branch in second worktree: %v", err) + } + if err := os.WriteFile(filepath.Join(dir2, "second.txt"), []byte("second\n"), 0o644); err != nil { + t.Fatal(err) + } + // Commit and push from the second worktree using raw git to bypass Manager. + cmd := exec.Command("git", "-C", dir2, "add", "-A") + cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0") + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("add in second worktree: %v\n%s", err, out) + } + cmd = exec.Command("git", "-C", dir2, "commit", "-m", "second commit") + cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0") + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("commit in second worktree: %v\n%s", err, out) + } + cmd = exec.Command("git", "-C", dir2, "push", "origin", branch) + cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0") + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("push from second worktree: %v\n%s", err, out) + } + + // Now the first worktree's branch is behind origin/branch. + // Make a change and try to push — it should be rejected. + if err := os.WriteFile(filepath.Join(dir, "third.txt"), []byte("third\n"), 0o644); err != nil { + t.Fatal(err) + } + if _, err := m.CommitAll(ctx, dir, "third commit"); err != nil { + t.Fatal(err) + } + err = m.Push(ctx, dir, branch) + if err == nil { + t.Fatal("expected push rejection due to non-fast-forward, got nil error") + } +} + +// TestGitErrorWrapping proves that git() wraps errors with the command +// name and preserves the underlying error via %w. +func TestGitErrorWrapping(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not installed") + } + ctx := context.Background() + + m := &Manager{ + WorkDir: t.TempDir(), + Token: "unused", + BotUser: "bot", + BotEmail: "bot@example.com", + } + + dir := t.TempDir() // plain directory, no .git + _, err := m.CommitAll(ctx, dir, "test message") + if err == nil { + t.Fatal("expected error from git in non-repo dir") + } + + // The error must contain "git" and the specific command ("add"). + errStr := err.Error() + if !strings.Contains(errStr, "git") { + t.Fatalf("error should contain 'git' prefix: %v", err) + } + if !strings.Contains(errStr, "add") { + t.Fatalf("error should mention the failing command 'add': %v", err) + } +} diff --git a/task.json b/task.json new file mode 100644 index 000000000..025d26439 --- /dev/null +++ b/task.json @@ -0,0 +1 @@ +{"id":4,"owner":"sam","repo":"archie-core","issue_number":58,"title":"Add tests for Prepare's idempotent fast path and git error paths","body":"## Problem\n\n`internal/worktree/worktree_test.go` contains a single test, `TestPrepareCommitPushRoundTrip` (worktree_test.go:51), which only exercises the full happy path: clone → checkout → commit → push → verify remote branch. It never:\n\n1. Calls `Prepare` a second time on the same `(owner, repo, issue)` to verify the existing-worktree short-circuit at `internal/worktree/worktree.go:77-79`:\n ```go\n // Already prepared (daemon cloned before container acquire).\n if st, statErr := os.Stat(filepath.Join(dir, \".git\")); statErr == nil \u0026\u0026 st.IsDir() {\n return dir, branch, nil\n }\n ```\n2. Exercises any git-command failure propagation paths in `git()`, `CommitAll`, `Push`, `ChangedLines`, or `Diff` — e.g. a bad clone URL, an invalid base branch name, or a rejected push.\n\n## Why it matters\n\nThe \"already prepared\" short-circuit is a fragile, filesystem-presence-based idempotency check (it only verifies `.git` exists as a directory, not that the worktree is on the correct branch or otherwise valid). Since it is currently unverified by any test, a regression here (e.g. returning a stale/wrong branch, or failing to detect a corrupt partial clone) would go unnoticed. Similarly, all error-return branches in the git-wrapping methods are untested, so failures in argument construction or error wrapping (`fmt.Errorf(\"git %s: %w\\n%s\", ...)`) could silently break without any test catching it.\n\n## Suggested fix\n\n- Add a case to `TestPrepareCommitPushRoundTrip` (or a new test) that calls `m.Prepare` twice with the same arguments and asserts the second call returns the same `dir`/`branch` without re-cloning (e.g. assert no network/clone call occurs, or that repo state is unchanged).\n- Add table-driven or dedicated tests for failure paths:\n - `Prepare` with a nonexistent base branch or bad clone URL, expecting a non-nil error.\n - `Push` against a URL/remote that rejects the push.\n - `CommitAll`, `ChangedLines`, `Diff` invoked in a directory that is not a valid git repo, expecting errors to propagate correctly.\n","labels":["agent:dead","bug"],"workflow":"","branch":"fix/58-add-tests-for-prepares-idempotent-fast-path-and-git-error-pa"} \ No newline at end of file From cd2da34c39de2ddd70abac39666e07e0582c0096 Mon Sep 17 00:00:00 2001 From: archie Date: Fri, 24 Jul 2026 05:28:19 +0000 Subject: [PATCH 2/6] fix: Add tests for Prepare's idempotent fast path and git error paths (archie) Fixes #58 --- internal/worktree/worktree.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/worktree/worktree.go b/internal/worktree/worktree.go index 55b08f5fb..14a73cf7e 100644 --- a/internal/worktree/worktree.go +++ b/internal/worktree/worktree.go @@ -351,7 +351,11 @@ func (m *Manager) ChangedLines(ctx context.Context, dir, base string) (int, erro // Diff returns the unified diff of all committed changes against base. func (m *Manager) Diff(ctx context.Context, dir, base string) (string, error) { - return m.git(ctx, dir, "diff", "origin/"+base+"...HEAD") + out, err := m.git(ctx, dir, "diff", "origin/"+base+"...HEAD") + if err != nil { + return "", err + } + return out, nil } // ChangedFiles lists the repo-relative paths changed against base. From d2d10685e7aca74e3f1d3f79a1bd96eac80001d1 Mon Sep 17 00:00:00 2001 From: archie Date: Fri, 24 Jul 2026 05:32:41 +0000 Subject: [PATCH 3/6] Prepare() treats worktree as ready from .git dir existence alone (archie) Implements #57 --- .git-askpass | 2 + internal/worktree/worktree.go | 23 ++++++- internal/worktree/worktree_test.go | 96 ++++++++++++++++++++++++++++++ task.json | 1 + 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100755 .git-askpass create mode 100644 task.json diff --git a/.git-askpass b/.git-askpass new file mode 100755 index 000000000..ac06c1b86 --- /dev/null +++ b/.git-askpass @@ -0,0 +1,2 @@ +#!/bin/sh +echo "$ARCHIE_GIT_TOKEN" diff --git a/internal/worktree/worktree.go b/internal/worktree/worktree.go index 55b08f5fb..2f77c230b 100644 --- a/internal/worktree/worktree.go +++ b/internal/worktree/worktree.go @@ -98,9 +98,9 @@ func (m *Manager) prepare(ctx context.Context, owner, repo, base string, issue i dir = m.Dir(owner, repo, issue) branch = archieBranch(issue, title, body, labels) - // Already prepared (daemon cloned before container acquire). - // Pull latest to avoid working on stale code. - if st, statErr := os.Stat(filepath.Join(dir, ".git")); statErr == nil && st.IsDir() { + // Already prepared: sentinel proves clone + checkout + config completed. + sentinel := filepath.Join(dir, ".archie-prepared") + if _, err := os.Stat(sentinel); err == nil { if _, err := m.git(ctx, dir, "fetch", "origin"); err != nil { return "", "", err } @@ -139,6 +139,23 @@ func (m *Manager) prepare(ctx context.Context, owner, repo, base string, issue i return "", "", err } } + // Exclude the sentinel from git tracking via the local exclude file. + exclude := filepath.Join(dir, ".git", "info", "exclude") + f, err := os.OpenFile(exclude, os.O_APPEND|os.O_WRONLY, 0o644) + if err != nil { + return "", "", err + } + if _, err := f.WriteString(".archie-prepared\n"); err != nil { + f.Close() + return "", "", err + } + if err := f.Close(); err != nil { + return "", "", err + } + // Write sentinel to mark the worktree as fully prepared. + if err := os.WriteFile(filepath.Join(dir, ".archie-prepared"), nil, 0o644); err != nil { + return "", "", err + } return dir, branch, nil } diff --git a/internal/worktree/worktree_test.go b/internal/worktree/worktree_test.go index bb921d1d7..954bc2a21 100644 --- a/internal/worktree/worktree_test.go +++ b/internal/worktree/worktree_test.go @@ -72,6 +72,11 @@ func TestPrepareCommitPushRoundTrip(t *testing.T) { t.Fatalf("branch = %q", branch) } + // Sentinel must exist after successful Prepare. + if _, err := os.Stat(filepath.Join(dir, ".archie-prepared")); err != nil { + t.Fatalf("sentinel missing after prepare: %v", err) + } + // Clean tree commits nothing. changed, err := m.CommitAll(ctx, dir, "noop") if err != nil || changed { @@ -196,6 +201,97 @@ func TestPreparePersistentReusesRepoCacheAndCleanupExpiresIt(t *testing.T) { } } +func TestPrepareResumesAfterInterruptedClone(t *testing.T) { + if _, err := exec.LookPath("git"); err != nil { + t.Skip("git not installed") + } + ctx := context.Background() + host := newLocalRemote(t, "acme", "interrupt") + + m := &Manager{ + WorkDir: t.TempDir(), + Token: "unused-for-file-remotes", + BotUser: "archie-bot", + BotEmail: "archie-bot@example.com", + BaseURL: "file://" + host, + } + + dir := m.Dir("acme", "interrupt", 1) + + // Simulate an interrupted clone: create parent dir with a bare-bones + // .git directory (via git init + remote + fetch) but no checked-out + // files and no .archie-prepared sentinel. + if err := os.MkdirAll(dir, 0o755); err != nil { + t.Fatal(err) + } + run := func(dir string, args ...string) { + t.Helper() + cmd := exec.Command("git", args...) + cmd.Dir = dir + cmd.Env = append(os.Environ(), "GIT_TERMINAL_PROMPT=0") + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("git %v: %v\n%s", args, err, out) + } + } + run(dir, "init") + run(dir, "remote", "add", "origin", "file://"+filepath.Join(host, "acme", "interrupt.git")) + run(dir, "fetch", "origin") + + // Confirm the broken state: .git exists but no sentinel and no README.md. + if _, err := os.Stat(filepath.Join(dir, ".git")); err != nil { + t.Fatalf(".git missing in simulated broken clone: %v", err) + } + if _, err := os.Stat(filepath.Join(dir, ".archie-prepared")); !os.IsNotExist(err) { + t.Fatal("sentinel unexpectedly exists in broken clone") + } + if _, err := os.Stat(filepath.Join(dir, "README.md")); !os.IsNotExist(err) { + t.Fatal("working tree files unexpectedly exist in broken clone") + } + + // Prepare must detect the broken state, remove it, and do a fresh clone. + dir2, branch, err := m.Prepare(ctx, "acme", "interrupt", "main", 1, "feat: interrupted", "", "") + if err != nil { + t.Fatalf("prepare after interrupted clone: %v", err) + } + + // The sentinel must exist after a successful Prepare. + if _, err := os.Stat(filepath.Join(dir2, ".archie-prepared")); err != nil { + t.Fatalf("sentinel missing after prepare: %v", err) + } + + // The working tree must be fully functional: files from the remote exist. + if _, err := os.Stat(filepath.Join(dir2, "README.md")); err != nil { + t.Fatalf("working tree missing README.md after prepare: %v", err) + } + + // CommitAll must work — the sentinel is excluded from git tracking. + changed, err := m.CommitAll(ctx, dir2, "noop") + if err != nil || changed { + t.Fatalf("clean CommitAll = (%v, %v), want (false, nil)", changed, err) + } + + // Push must work. + if err := m.Push(ctx, dir2, branch); err != nil { + t.Fatalf("push: %v", err) + } + + // A second Prepare call must short-circuit via the sentinel — no re-clone. + dir3, _, err := m.Prepare(ctx, "acme", "interrupt", "main", 1, "feat: interrupted", "", "") + if err != nil { + t.Fatalf("second prepare: %v", err) + } + if dir3 != dir2 { + t.Fatalf("second prepare created a different directory: %q vs %q", dir3, dir2) + } + + if err := m.Cleanup("acme", "interrupt", 1); err != nil { + t.Fatal(err) + } + if _, err := os.Stat(dir3); !os.IsNotExist(err) { + t.Fatal("cleanup left the worktree behind") + } +} + func TestCacheDirCannotEscapeWorkDir(t *testing.T) { m := &Manager{WorkDir: t.TempDir()} cache := m.cacheDir("../outside", `..\also-outside`) diff --git a/task.json b/task.json new file mode 100644 index 000000000..5f79095e3 --- /dev/null +++ b/task.json @@ -0,0 +1 @@ +{"id":5,"owner":"sam","repo":"archie-core","issue_number":57,"title":"Prepare() treats worktree as ready from .git dir existence alone","body":"## Problem\n\n`Manager.Prepare` in `internal/worktree/worktree.go:76-79` decides whether a task worktree is already fully prepared solely by checking that a `.git` directory exists:\n\n```go\n// Already prepared (daemon cloned before container acquire).\nif st, statErr := os.Stat(filepath.Join(dir, \".git\")); statErr == nil \u0026\u0026 st.IsDir() {\n return dir, branch, nil\n}\n```\n\n`git clone` creates the `.git` directory early in the clone process, before the checkout of the working tree completes, and well before the subsequent `checkout -b archie/issue-N` step (worktree.go:93) runs. If `archied` is killed or restarted (OOM, deploy, crash) while a clone is in progress, on the next start `Prepare()` will see the existing `.git` directory and short-circuit, assuming the worktree is fully set up — skipping the clone, the `checkout -b` branch creation, and any config steps.\n\n## Why it matters\n\nThis directly conflicts with the package's stated goal of being safely restartable: the package doc for `internal/daemon/daemon.go:3` states \"the daemon is restartable ... at any point.\" With this shortcut, a restart mid-clone leaves a `.git` directory but an incomplete/missing working tree and no `archie/issue-N` branch. Later calls to `CommitAll` (git add/status/commit) or `Push` (git push -u origin branch) will then operate on this broken state — failing with confusing errors, or in the worst case running against whatever branch actually exists (e.g. the base branch) rather than the intended `archie/issue-N` branch.\n\n## Suggested fix\n\nStrengthen the \"already prepared\" check to verify actual completion, not just `.git` existence, e.g.:\n- Confirm the target branch exists and is checked out (`git rev-parse --verify \u003cbranch\u003e` / check `HEAD`), and\n- Confirm the working tree is non-empty / clone actually finished (e.g. check for a marker file written only after the full clone+checkout sequence succeeds, or verify `git status` runs without error and matches expected branch).\n\nA simple robust option: write a sentinel file (e.g. `.archie-prepared`) as the very last step of the success path, and gate the early-return solely on that sentinel rather than on `.git` alone.\n\u003c/refined_body\u003e\n","labels":["agent:dead"],"workflow":"","branch":"feat/57-prepare-treats-worktree-as-ready-from-git-dir-existence-alon"} \ No newline at end of file From bb784297ae6053d610ec227519bbd88d6fa6a939 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 24 Jul 2026 16:35:00 +1000 Subject: [PATCH 4/6] feat: fix webui task table and add merge-to-deploy automation - webui: task rows referenced Go-style field names but store.Task JSON-marshals with lowercase tags, so every task row rendered blank - add .gitea/workflows/deploy.yml: build+push archied and archie-agent images to the registry on merge to main - docker-compose.yml: add a watchtower service so carina picks up new images and restarts the daemons without needing CI to SSH in --- .gitea/workflows/deploy.yml | 29 +++++++++++++++++++++++++++++ docker-compose.yml | 15 +++++++++++++++ internal/webui/index.html | 10 +++++----- 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 .gitea/workflows/deploy.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 000000000..fd47ede44 --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,29 @@ +# Builds and pushes the archied and archie-agent images on every merge +# to main. carina's watchtower container (see docker-compose.yml) picks +# up the new images and restarts the running daemons — this workflow +# never touches carina directly. +name: deploy + +on: + push: + branches: [main] + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Log in to registry + run: echo "${{ secrets.DEPLOY_TOKEN }}" | docker login git.catlow.cloud -u sam --password-stdin + + - name: Build and push archied + run: | + docker build -f Dockerfile.archied -t git.catlow.cloud/sam/archied:latest . + docker push git.catlow.cloud/sam/archied:latest + + - name: Build and push archie-agent + run: | + docker build -f Dockerfile -t git.catlow.cloud/sam/archie-agent:latest . + docker push git.catlow.cloud/sam/archie-agent:latest diff --git a/docker-compose.yml b/docker-compose.yml index e9ec20706..45882482b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -53,5 +53,20 @@ services: entrypoint: [""] restart: "no" + # ── deploy watcher ────────────────────────────────────────────────── + # Polls the registry for new archied/archie-agent images (pushed by + # .gitea/workflows/deploy.yml on merge to main) and restarts the + # containers that changed. Registry auth comes from the host's + # existing `docker login` config, mounted read-only. + watchtower: + image: nickfedor/watchtower + environment: + - DOCKER_CONFIG=/ + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - ${HOME}/.docker/config.json:/config.json:ro + command: --interval 60 --cleanup archie-core-archied-1 archie-core-archied-winter-1 + restart: unless-stopped + volumes: nats_data: diff --git a/internal/webui/index.html b/internal/webui/index.html index 7b5235f43..d992dd41a 100644 --- a/internal/webui/index.html +++ b/internal/webui/index.html @@ -157,11 +157,11 @@ async function refresh() { .join("") || '
0
tasks
'; $("#tasks tbody").innerHTML = (tasks ?? []).map(t => ` - - ${esc(t.Owner)}/${esc(t.Repo)}#${t.IssueNumber} - ${esc(t.Title)}${esc(t.Workflow)} - ${esc(t.Status)} - ${fmt(t.Iterations)}${fmt(t.TokensUsed)} + + ${esc(t.owner)}/${esc(t.repo)}#${t.issue_number} + ${esc(t.title)}${esc(t.workflow)} + ${esc(t.status)} + ${fmt(t.iterations)}${fmt(t.tokens_used)} `).join(""); $("#workflows tbody").innerHTML = (summary.workflows ?? []).map(w => ` From 4d9e2600462c99abe29fb4b003123ffb1c3a5706 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 24 Jul 2026 17:43:00 +1000 Subject: [PATCH 5/6] fix: update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b2421041d..30ddcc58f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ .references/ .claude/ .env +task.json From 4336dcf4420824cb6c4e8d987185f8fae9e344ce Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 24 Jul 2026 17:44:30 +1000 Subject: [PATCH 6/6] chore: remove task.json --- task.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 task.json diff --git a/task.json b/task.json deleted file mode 100644 index 025d26439..000000000 --- a/task.json +++ /dev/null @@ -1 +0,0 @@ -{"id":4,"owner":"sam","repo":"archie-core","issue_number":58,"title":"Add tests for Prepare's idempotent fast path and git error paths","body":"## Problem\n\n`internal/worktree/worktree_test.go` contains a single test, `TestPrepareCommitPushRoundTrip` (worktree_test.go:51), which only exercises the full happy path: clone → checkout → commit → push → verify remote branch. It never:\n\n1. Calls `Prepare` a second time on the same `(owner, repo, issue)` to verify the existing-worktree short-circuit at `internal/worktree/worktree.go:77-79`:\n ```go\n // Already prepared (daemon cloned before container acquire).\n if st, statErr := os.Stat(filepath.Join(dir, \".git\")); statErr == nil \u0026\u0026 st.IsDir() {\n return dir, branch, nil\n }\n ```\n2. Exercises any git-command failure propagation paths in `git()`, `CommitAll`, `Push`, `ChangedLines`, or `Diff` — e.g. a bad clone URL, an invalid base branch name, or a rejected push.\n\n## Why it matters\n\nThe \"already prepared\" short-circuit is a fragile, filesystem-presence-based idempotency check (it only verifies `.git` exists as a directory, not that the worktree is on the correct branch or otherwise valid). Since it is currently unverified by any test, a regression here (e.g. returning a stale/wrong branch, or failing to detect a corrupt partial clone) would go unnoticed. Similarly, all error-return branches in the git-wrapping methods are untested, so failures in argument construction or error wrapping (`fmt.Errorf(\"git %s: %w\\n%s\", ...)`) could silently break without any test catching it.\n\n## Suggested fix\n\n- Add a case to `TestPrepareCommitPushRoundTrip` (or a new test) that calls `m.Prepare` twice with the same arguments and asserts the second call returns the same `dir`/`branch` without re-cloning (e.g. assert no network/clone call occurs, or that repo state is unchanged).\n- Add table-driven or dedicated tests for failure paths:\n - `Prepare` with a nonexistent base branch or bad clone URL, expecting a non-nil error.\n - `Push` against a URL/remote that rejects the push.\n - `CommitAll`, `ChangedLines`, `Diff` invoked in a directory that is not a valid git repo, expecting errors to propagate correctly.\n","labels":["agent:dead","bug"],"workflow":"","branch":"fix/58-add-tests-for-prepares-idempotent-fast-path-and-git-error-pa"} \ No newline at end of file