fix: resolve merge conflicts with main
This commit is contained in:
commit
918b198258
7 files changed
+479
-10
No files matched your search
@@ -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
|
||||
@@ -5,3 +5,4 @@
|
||||
.references/
|
||||
.claude/
|
||||
.env
|
||||
task.json
|
||||
@@ -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:
|
||||
@@ -157,11 +157,11 @@ async function refresh() {
|
||||
.join("") || '<div class="card"><div class="n">0</div><div class="l">tasks</div></div>';
|
||||
|
||||
$("#tasks tbody").innerHTML = (tasks ?? []).map(t => `
|
||||
<tr class="task" onclick="showTask(${t.ID}, '${esc(t.Owner)}/${esc(t.Repo)}#${t.IssueNumber}')">
|
||||
<td>${esc(t.Owner)}/${esc(t.Repo)}</td><td>#${t.IssueNumber}</td>
|
||||
<td>${esc(t.Title)}</td><td>${esc(t.Workflow)}</td>
|
||||
<td><span class="status ${esc(t.Status)}">${esc(t.Status)}</span></td>
|
||||
<td class="num">${fmt(t.Iterations)}</td><td class="num">${fmt(t.TokensUsed)}</td>
|
||||
<tr class="task" onclick="showTask(${t.id}, '${esc(t.owner)}/${esc(t.repo)}#${t.issue_number}')">
|
||||
<td>${esc(t.owner)}/${esc(t.repo)}</td><td>#${t.issue_number}</td>
|
||||
<td>${esc(t.title)}</td><td>${esc(t.workflow)}</td>
|
||||
<td><span class="status ${esc(t.status)}">${esc(t.status)}</span></td>
|
||||
<td class="num">${fmt(t.iterations)}</td><td class="num">${fmt(t.tokens_used)}</td>
|
||||
</tr>`).join("");
|
||||
|
||||
$("#workflows tbody").innerHTML = (summary.workflows ?? []).map(w => `
|
||||
|
||||
@@ -106,9 +106,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
|
||||
}
|
||||
@@ -147,6 +147,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
|
||||
}
|
||||
|
||||
@@ -359,7 +376,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.
|
||||
|
||||
@@ -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,7 @@ func TestPreparePersistentReusesRepoCacheAndCleanupExpiresIt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
func TestAskpassWrittenOnce(t *testing.T) {
|
||||
m := &Manager{WorkDir: t.TempDir()}
|
||||
|
||||
@@ -236,6 +242,96 @@ func TestAskpassWrittenOnce(t *testing.T) {
|
||||
want := "#!/bin/sh\necho \"$ARCHIE_GIT_TOKEN\"\n"
|
||||
if string(b) != want {
|
||||
t.Fatalf("content = %q, want %q", string(b), want)
|
||||
=======
|
||||
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")
|
||||
>>>>>>> origin/main
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,3 +346,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)
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
{"id":3,"owner":"sam","repo":"archie-core","issue_number":59,"title":"askpass helper rewritten on every git call despite \"(once)\" comment","body":"## Problem\n\n`Manager.askpass()` in `internal/worktree/worktree.go:36` is documented as writing the helper script \"(once)\":\n\n```go\n// askpass writes (once) a helper script that emits the token, so git\n// authenticates without the token appearing in argv or .git/config.\nfunc (m *Manager) askpass() (string, error) {\n\tpath := filepath.Join(m.WorkDir, \".git-askpass\")\n\tscript := \"#!/bin/sh\\necho \\\"$ARCHIE_GIT_TOKEN\\\"\\n\"\n\tif err := os.MkdirAll(m.WorkDir, 0o755); err != nil {\n\t\treturn \"\", err\n\t}\n\tif err := os.WriteFile(path, []byte(script), 0o700); err != nil {\n\t\treturn \"\", err\n\t}\n\treturn path, nil\n}\n```\n\nIn reality there is no existence check, cache, or `sync.Once` — it unconditionally runs `os.MkdirAll` + `os.WriteFile` every time it's called. It's invoked from `git()` (worktree.go:48-49) on **every single git command** (clone, config, commit, push, diff, etc.), so the same static file is truncated and rewritten repeatedly, contradicting its own comment.\n\n## Why it matters\n\n- Wasted filesystem I/O (mkdir + open/write/close) on every git invocation, for content that never changes.\n- Latent race condition: if concurrent task processing is ever introduced (multiple goroutines calling `git()` against the same `Manager`/`WorkDir` concurrently), this becomes a genuine race — one goroutine's `os.WriteFile` (which truncates then writes) could interleave with another's read of the same path, or with git actually invoking the script mid-truncate, causing an intermittent empty/malformed askpass script and auth failures.\n- Currently low severity since processing is single-threaded and the script content is static/idempotent, but it's tech debt that will bite silently if concurrency is added without revisiting this code.\n\n## Suggested fix\n\nWrite the helper file once (e.g., guarded by `sync.Once`, or check `os.Stat` before writing, or write it once during `Manager` construction) instead of on every `git()` call. If concurrent workers will ever share a `WorkDir`, consider using a per-worker or per-task path, or writing to a temp file and atomically renaming it into place to avoid partial-write races.\n\u003c/refined_body\u003e\n","labels":[""],"workflow":"","branch":"feat/59-askpass-helper-rewritten-on-every-git-call-despite-once-comm"}
|
||||
{"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"}
|
||||
Reference in new issue
Block a user