Skip to content

Commit d28eff9

Browse files
Fail landed waits on terminal publish errors
Co-authored-by: Andrew <andrewxhill@gmail.com>
1 parent fce7af3 commit d28eff9

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

internal/app/app_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,51 @@ func TestWaitBySubmissionIDReturnsLandedOutcome(t *testing.T) {
283283
}
284284
}
285285

286+
func TestWaitBySubmissionIDReturnsFailedWhenCorrelatedPublishFails(t *testing.T) {
287+
repoRoot, _ := createTestRepoWithRemote(t)
288+
initRepoForWorker(t, repoRoot)
289+
updatePublishMode(t, repoRoot, "auto")
290+
291+
gateFlag := filepath.Join(t.TempDir(), "block-publish")
292+
hookPath := filepath.Join(hooksDirForRepo(t, repoRoot), "pre-push")
293+
if err := os.WriteFile(hookPath, []byte("#!/bin/sh\nif [ ! -f "+gateFlag+" ]; then\n echo gate failed >&2\n exit 9\nfi\nexit 0\n"), 0o755); err != nil {
294+
t.Fatalf("WriteFile: %v", err)
295+
}
296+
297+
featurePath := filepath.Join(t.TempDir(), "feature-wait-publish-failed")
298+
runTestCommand(t, repoRoot, "git", "worktree", "add", "-b", "feature/wait-publish-failed", featurePath)
299+
writeFileAndCommit(t, featurePath, "wait.txt", "wait\n", "wait feature")
300+
301+
var submitOut bytes.Buffer
302+
var submitErr bytes.Buffer
303+
if err := runSubmit([]string{"--repo", featurePath, "--json"}, &submitOut, &submitErr); err != nil {
304+
t.Fatalf("runSubmit returned error: %v", err)
305+
}
306+
var submit submitResult
307+
if err := json.Unmarshal(submitOut.Bytes(), &submit); err != nil {
308+
t.Fatalf("Unmarshal submit: %v", err)
309+
}
310+
311+
var waitOut bytes.Buffer
312+
var waitErr bytes.Buffer
313+
err := runCLI([]string{"wait", "--repo", repoRoot, "--submission", strconv.FormatInt(submit.SubmissionID, 10), "--for", "landed", "--json", "--timeout", "10s"}, &waitOut, &waitErr)
314+
if err == nil {
315+
t.Fatalf("expected landed wait to fail when publish fails")
316+
}
317+
var exitErr *cliExitError
318+
if !errors.As(err, &exitErr) || CLIExitCode(err) != 1 {
319+
t.Fatalf("expected exit code 1, got %v", err)
320+
}
321+
322+
var result submissionWaitResult
323+
if err := json.Unmarshal(waitOut.Bytes(), &result); err != nil {
324+
t.Fatalf("Unmarshal wait: %v", err)
325+
}
326+
if result.Outcome != waitOutcomeFailed || result.PublishStatus != "failed" || result.PublishRequestID == 0 {
327+
t.Fatalf("expected failed landed wait with failed publish correlation, got %+v", result)
328+
}
329+
}
330+
286331
func TestStatusJSONCorrelatesSubmissionToPublish(t *testing.T) {
287332
repoRoot, _ := createTestRepoWithRemote(t)
288333
initRepoForWorker(t, repoRoot)

internal/app/wait.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,18 @@ func waitForSubmissionTarget(queued queuedSubmission, target waitTarget, timeout
341341
result.DurationMS = time.Since(start).Milliseconds()
342342
return result, nil
343343
}
344+
switch info.PublishStatus {
345+
case "failed":
346+
result.Outcome = waitOutcomeFailed
347+
result.DurationMS = time.Since(start).Milliseconds()
348+
result.Error = fmt.Sprintf("publish request %d failed", info.PublishRequestID)
349+
return result, exitWithCode(1, fmt.Errorf("publish request %d failed", info.PublishRequestID))
350+
case "cancelled":
351+
result.Outcome = waitOutcomeCancelled
352+
result.DurationMS = time.Since(start).Milliseconds()
353+
result.Error = fmt.Sprintf("publish request %d cancelled", info.PublishRequestID)
354+
return result, exitWithCode(1, fmt.Errorf("publish request %d cancelled", info.PublishRequestID))
355+
}
344356
}
345357

346358
cycleResult, err := runOneCycle(queued.Config.Repo.MainWorktree)

0 commit comments

Comments
 (0)