-
Notifications
You must be signed in to change notification settings - Fork 808
fix(cli): unblock fresh runs after missing custody head #871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dexventures-ai
wants to merge
7
commits into
kunchenguid:main
Choose a base branch
from
dexventures-ai:fm/no-mistakes-missing-head-custody
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c4efe8e
fix(cli): unblock fresh runs after missing custody head
dexventures-ai 269f08a
fix(git): fail closed on object lookup errors
dexventures-ai 8571448
no-mistakes(review): Handle no-op fresh runs after missing custody heads
dexventures-ai f64b539
no-mistakes(review): Centralized fail-closed custody and preserved fr…
dexventures-ai 56b6ca9
test(cli): repair missing-head validation fixture
dexventures-ai 7729058
no-mistakes(review): Hardened fresh-run custody and exact run handoff
dexventures-ai 6394245
test(cli): repair fresh-run handoff fixture
dexventures-ai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/kunchenguid/no-mistakes/internal/config" | ||
| "github.com/kunchenguid/no-mistakes/internal/custody" | ||
| "github.com/kunchenguid/no-mistakes/internal/types" | ||
| ) | ||
|
|
||
| // TestFreshRunBranchOwnershipDistinguishesMissingTerminalHead reproduces the | ||
| // custody deadlock caused by a terminal run whose moved head is no longer | ||
| // available. That state must remain manual-only for recovery, while it must | ||
| // not keep unrelated fresh work behind a custody claim for commits that no | ||
| // longer exist. | ||
| func TestFreshRunBranchOwnershipDistinguishesMissingTerminalHead(t *testing.T) { | ||
| for _, tc := range []struct { | ||
| name string | ||
| recordedHead func(t *testing.T, submitted string) string | ||
| advanceWorktree bool | ||
| gatePresent bool | ||
| survivingAnchor bool | ||
| verifiedHead bool | ||
| wantFreshBlocked bool | ||
| wantSafety string | ||
| }{ | ||
| { | ||
| name: "terminal unmoved releases branch", | ||
| recordedHead: func(_ *testing.T, submitted string) string { | ||
| return submitted | ||
| }, | ||
| verifiedHead: true, | ||
| wantFreshBlocked: false, | ||
| wantSafety: "user_owned", | ||
| }, | ||
| { | ||
| name: "terminal recoverable moved head keeps custody", | ||
| recordedHead: func(_ *testing.T, submitted string) string { | ||
| return submitted | ||
| }, | ||
| advanceWorktree: true, | ||
| verifiedHead: true, | ||
| wantFreshBlocked: true, | ||
| wantSafety: "blocked_pipeline_owned_recoverable", | ||
| }, | ||
| { | ||
| name: "terminal missing moved head releases fresh path", | ||
| recordedHead: func(_ *testing.T, _ string) string { | ||
| return strings.Repeat("f", 40) | ||
| }, | ||
| gatePresent: true, | ||
| wantFreshBlocked: false, | ||
| wantSafety: "blocked_recover_preserved_head_missing", | ||
| }, | ||
| { | ||
| name: "missing head with recovery evidence keeps custody", | ||
| recordedHead: func(_ *testing.T, _ string) string { | ||
| return strings.Repeat("f", 40) | ||
| }, | ||
| gatePresent: true, | ||
| survivingAnchor: true, | ||
| wantFreshBlocked: true, | ||
| wantSafety: "blocked_recover_preserved_head_missing", | ||
| }, | ||
| } { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| repoDir, paths, database, repo := setupAxiQueryRepo(t) | ||
| cliGit(t, repoDir, "checkout", "-b", "feature/missing-head") | ||
| chdir(t, repoDir) | ||
|
|
||
| submitted := cliGit(t, repoDir, "rev-parse", "HEAD") | ||
| recorded := tc.recordedHead(t, submitted) | ||
| if tc.advanceWorktree { | ||
| cliGit(t, repoDir, "commit", "--allow-empty", "-m", "pipeline fix") | ||
| recorded = cliGit(t, repoDir, "rev-parse", "HEAD") | ||
| } | ||
| if tc.gatePresent { | ||
| gateDir := paths.RepoDir(repo.ID) | ||
| if err := os.MkdirAll(gateDir, 0o755); err != nil { | ||
| t.Fatalf("create gate directory: %v", err) | ||
| } | ||
| cliGit(t, gateDir, "init", "--bare") | ||
| cliGit(t, repoDir, "push", gateDir, "HEAD:refs/heads/feature/missing-head") | ||
| } | ||
|
|
||
| pipelineRun, err := database.InsertRun(repo.ID, "feature/missing-head", submitted, submitted) | ||
| if err != nil { | ||
| t.Fatalf("insert pipeline run: %v", err) | ||
| } | ||
| if err := database.UpdateRunHeadSHA(pipelineRun.ID, recorded); err != nil { | ||
| t.Fatalf("record pipeline head: %v", err) | ||
| } | ||
| if tc.verifiedHead { | ||
| if err := database.UpdateRunStatusWithVerifiedHead(pipelineRun.ID, types.RunCancelled, recorded); err != nil { | ||
| t.Fatalf("terminalize pipeline run: %v", err) | ||
| } | ||
| } else if err := database.UpdateRunStatus(pipelineRun.ID, types.RunCancelled); err != nil { | ||
| t.Fatalf("terminalize pipeline run: %v", err) | ||
| } | ||
| if tc.survivingAnchor { | ||
| cliGit(t, paths.RepoDir(repo.ID), "update-ref", custody.RecoveryRef(pipelineRun.ID), submitted) | ||
| } | ||
|
|
||
| env := &axiEnv{p: paths, d: database, repo: repo, cfg: config.DefaultGlobalConfig()} | ||
| state := inspectAxiBranchSync(context.Background(), env) | ||
| if state.Safety != tc.wantSafety { | ||
| t.Fatalf("branch ownership state = %s, want %s: %#v", state.Safety, tc.wantSafety, state) | ||
| } | ||
| blocked := freshRunBranchOwnershipState(context.Background(), env) | ||
| if (blocked != nil) != tc.wantFreshBlocked { | ||
| t.Fatalf("fresh-run ownership = %#v, blocked = %t, want blocked = %t", blocked, blocked != nil, tc.wantFreshBlocked) | ||
| } | ||
| if tc.wantFreshBlocked && blocked.NextAction == nil { | ||
| t.Fatal("recoverable terminal head lost its custody guidance") | ||
| } | ||
| if tc.wantSafety == "blocked_recover_preserved_head_missing" && | ||
| (state.NextAction == nil || state.NextAction.Code != "inspect_and_reconcile_manually") { | ||
| t.Fatalf("missing-head state lost manual reconciliation guidance: %#v", state) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.