fix(worktree): reject diffs without merge base

This commit is contained in:
sam committed 2026-08-22 22:06:54 +10:00
1 parent 6988f8b4a2
commit 770cada41a
4 files changed
+61 -5

No files matched your search

+1
View File
@@ -42,3 +42,4 @@
{"id":"int-3eca62d9ff92647ebeb091e5afe7e80a","kind":"field_change","created_at":"2026-08-22T11:47:02.632518654Z","actor":"Sam Catlow","issue_id":"archie-core-1ysw.2","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Implemented per-dispatch publication grants, removed sandbox-selected prepare/path authority, made repository worktree keys collision-free, and added fail-closed legacy migration/cleanup coverage."}}
{"id":"int-389951a8f299a389cbb0432044362797","kind":"field_change","created_at":"2026-08-22T11:55:19.903017141Z","actor":"Sam Catlow","issue_id":"archie-core-1ysw.3","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Retry refresh now removes all non-HEAD worktree content including ignored output while preserving .git, tracked symlinks, and gitlinks; missing bases fail closed."}}
{"id":"int-56c541cf59441d3b82a65bc0ee53e38c","kind":"field_change","created_at":"2026-08-22T11:55:20.137923996Z","actor":"Sam Catlow","issue_id":"archie-core-1ysw.4","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Retry refresh now removes all non-HEAD worktree content including ignored output while preserving .git, tracked symlinks, and gitlinks; missing bases fail closed."}}
{"id":"int-91757c22c0f3dff173e70e5eeff9447c","kind":"field_change","created_at":"2026-08-22T11:59:36.859035164Z","actor":"Sam Catlow","issue_id":"archie-core-1ysw.5","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Three-dot diff operations now fail closed when base and HEAD have no common ancestor; regression covers Diff, ChangedFiles, and ChangedLines."}}
+1 -1
View File
@@ -43,7 +43,7 @@
{"_type":"issue","id":"archie-core-hqst","title":"TestApplicationOwnsNoTransportWireMechanics fails: persistent_runner.go imports encoding/json","description":"internal/app/agentworker/architecture_test.go's TestApplicationOwnsNoTransportWireMechanics fails on main (pre-existing, unrelated to archie-core-qk8m): persistent_runner.go imports encoding/json, tripping the check that agentworker's app layer owns no transport wire mechanics. Introduced by e351581 (feat(storage): persist agent project state). Confirmed via git stash that this fails identically with none of the mcp-npm-cache changes applied.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:09:58Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:09:58Z","dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-1ysw.9","title":"Align branch naming behavior, API, tests, and documentation","description":"branchPrefix ignores title and body despite the documented title-prefix contract, contains a checked-in lint-failing FIXME and a no-op, and branchSlug documents 40 characters while implementing 60.","acceptance_criteria":"The chosen title/label precedence is explicit and tested for unlabeled and conflicting inputs; dead parameters and no-op residue are removed; slug documentation and boundary tests agree with 60; scoped lint passes.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:48Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:48Z","dependencies":[{"issue_id":"archie-core-1ysw.9","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:48Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-1ysw.7","title":"Clean no-change worktrees at terminal completion","description":"BuildNoChanges transitions directly to merged without a PR, bypassing the only production worktree cleanup path and leaking a full clone.","acceptance_criteria":"Both direct and container no-change completion remove the identity-correct worktree while parked worktrees remain available; lifecycle regression tests cover the terminal path.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:47Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:47Z","dependencies":[{"issue_id":"archie-core-1ysw.7","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:46Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-1ysw.5","title":"Preserve three-dot failure semantics without a merge base","description":"patch silently computes a direct tree diff when base and HEAD have no merge base, contradicting its three-dot contract and corrupting diff-cap and gate inputs.","acceptance_criteria":"Unrelated histories return a clear error from Diff, ChangedFiles, and ChangedLines; shared-history merge-base behavior remains covered.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:46Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:46Z","dependencies":[{"issue_id":"archie-core-1ysw.5","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:45Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-1ysw.5","title":"Preserve three-dot failure semantics without a merge base","description":"patch silently computes a direct tree diff when base and HEAD have no merge base, contradicting its three-dot contract and corrupting diff-cap and gate inputs.","acceptance_criteria":"Unrelated histories return a clear error from Diff, ChangedFiles, and ChangedLines; shared-history merge-base behavior remains covered.","status":"closed","priority":2,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:46Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:59:37Z","started_at":"2026-08-22T11:55:44Z","closed_at":"2026-08-22T11:59:37Z","close_reason":"Three-dot diff operations now fail closed when base and HEAD have no common ancestor; regression covers Diff, ChangedFiles, and ChangedLines.","dependencies":[{"issue_id":"archie-core-1ysw.5","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:45Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-1ysw.6","title":"Do not report push failure after successful publication","description":"Push publishes the remote ref before writing unused local upstream metadata, then returns local config errors as if publication failed.","acceptance_criteria":"A post-publication metadata failure cannot park the task as an unsuccessful push; tests verify the remote ref and returned result remain consistent.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:46Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:01:46Z","dependencies":[{"issue_id":"archie-core-1ysw.6","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:46Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-1ysw.4","title":"Fail refresh when the configured base cannot resolve","description":"Prepared worktrees currently swallow every resolveBase error and report successful refresh against stale history.","acceptance_criteria":"Prepared-worktree refresh returns a contextual error for a missing, renamed, or invalid base; fresh and reused Prepare paths have consistent tests.","status":"closed","priority":2,"issue_type":"bug","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-22T11:01:45Z","created_by":"Sam Catlow","updated_at":"2026-08-22T11:55:20Z","started_at":"2026-08-22T11:52:19Z","closed_at":"2026-08-22T11:55:20Z","close_reason":"Retry refresh now removes all non-HEAD worktree content including ignored output while preserving .git, tracked symlinks, and gitlinks; missing bases fail closed.","dependencies":[{"issue_id":"archie-core-1ysw.4","depends_on_id":"archie-core-1ysw","type":"parent-child","created_at":"2026-08-22T21:01:44Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
{"_type":"issue","id":"archie-core-j8b4","title":"Implement persistent session memory and plugin storage","description":"Replace the PRD section 3 placeholder in internal/storage/storage.go with the specified persistent storage behavior for session.jsonl, memory.jsonl, and plugins.","status":"closed","priority":2,"issue_type":"task","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-08-22T10:32:31Z","created_by":"Sam Catlow","updated_at":"2026-08-22T10:56:59Z","started_at":"2026-08-22T10:32:37Z","closed_at":"2026-08-22T10:56:59Z","close_reason":"Implemented persistent session transcript, cross-session memory, and staged plugin storage","dependency_count":0,"dependent_count":0,"comment_count":0}
+7 -4
View File
@@ -488,11 +488,14 @@ func (m *Manager) patch(ctx context.Context, dir, base string) (*object.Patch, e
if err != nil {
return nil, fmt.Errorf("load head commit: %w", err)
}
from := baseCommit
if bases, err := baseCommit.MergeBase(headCommit); err == nil && len(bases) > 0 {
from = bases[0]
bases, err := baseCommit.MergeBase(headCommit)
if err != nil {
return nil, fmt.Errorf("find merge base for %s...HEAD: %w", remoteBase(base), err)
}
p, err := from.PatchContext(ctx, headCommit)
if len(bases) == 0 {
return nil, fmt.Errorf("find merge base for %s...HEAD: no common ancestor", remoteBase(base))
}
p, err := bases[0].PatchContext(ctx, headCommit)
if err != nil {
return nil, fmt.Errorf("diff %s...HEAD: %w", remoteBase(base), err)
}
+52
View File
@@ -502,6 +502,58 @@ func TestDiffUsesMergeBaseNotRemoteTip(t *testing.T) {
}
}
func TestDiffOperationsRejectUnrelatedBaseHistory(t *testing.T) {
ctx := context.Background()
host := newLocalRemote(t, "acme", "todo")
m := newManager(t, host)
dir, _, err := m.Prepare(ctx, "acme", "todo", testBase, 6, "feat: task", "", "feature")
if err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "task.txt"), []byte("task\n"), 0o600); err != nil {
t.Fatal(err)
}
if changed, err := m.CommitAll(ctx, dir, "feat: task"); err != nil || !changed {
t.Fatalf("CommitAll() = (%v, %v)", changed, err)
}
orphanDir := t.TempDir()
orphan, err := git.PlainInit(orphanDir, false, git.WithDefaultBranch(plumbing.NewBranchReferenceName(testBase)))
if err != nil {
t.Fatal(err)
}
writeSeedCommit(t, orphan, orphanDir, "orphan.txt", "unrelated\n", "orphan history")
if _, err := orphan.CreateRemote(&gitconfig.RemoteConfig{Name: git.DefaultRemoteName, URLs: []string{filepath.Join(host, "acme", "todo.git")}}); err != nil {
t.Fatal(err)
}
ref := plumbing.NewBranchReferenceName(testBase)
if err := orphan.Push(&git.PushOptions{RemoteName: git.DefaultRemoteName, RefSpecs: []gitconfig.RefSpec{gitconfig.RefSpec("+" + ref + ":" + ref)}}); err != nil {
t.Fatal(err)
}
r, err := git.PlainOpen(dir)
if err != nil {
t.Fatal(err)
}
if err := r.Fetch(&git.FetchOptions{RemoteName: git.DefaultRemoteName, Force: true}); err != nil {
t.Fatal(err)
}
for _, operation := range []struct {
name string
run func() error
}{
{name: "Diff", run: func() error { _, err := m.Diff(ctx, dir, testBase); return err }},
{name: "ChangedFiles", run: func() error { _, err := m.ChangedFiles(ctx, dir, testBase); return err }},
{name: "ChangedLines", run: func() error { _, err := m.ChangedLines(ctx, dir, testBase); return err }},
} {
t.Run(operation.name, func(t *testing.T) {
if err := operation.run(); err == nil {
t.Fatal("operation accepted histories without a merge base")
}
})
}
}
func TestBranchNaming(t *testing.T) {
tests := []struct {
name string