Verify vendored recovery after launcher cleanup

This commit is contained in:
2026-11-03 00:23:06 +00:00
parent e0019abe31
commit ee72566263
3 changed files with 54 additions and 29 deletions

View File

@@ -52,18 +52,29 @@ func TestVendoredAPIOnlyPublicationRecovery(t *testing.T) {
if err := os.WriteFile(filepath.Join(remote, "hooks", "pre-receive"), []byte("#!/bin/sh\nexit 1\n"), 0700); err != nil {
t.Fatal(err)
}
var out, diagnostics bytes.Buffer
if status := run(t.Context(), []string{"publish", "--repo", repo, "v1.2.3"}, &out, &diagnostics); status != 1 {
t.Fatalf("publication status=%d: %s", status, &diagnostics)
launcherStore := t.TempDir()
launcherArgs, err := gotool.RecoveryTool(t.Context(), repo, launcherStore)
if err != nil {
t.Fatal(err)
}
command := outputLineValue(diagnostics.String(), "recovery command: ")
launcher := exec.Command(goBinary, append(launcherArgs, "publish", "--repo", repo, "v1.2.3")...)
launcher.Dir = t.TempDir()
publicationOutput, err := launcher.CombinedOutput()
var exitError *exec.ExitError
if !errors.As(err, &exitError) || exitError.ExitCode() != 1 {
t.Fatalf("vendored publication: %v: %s", err, publicationOutput)
}
// The later handoff owns different launch metadata from the original driver.
if err := os.RemoveAll(launcherStore); err != nil {
t.Fatal(err)
}
command := outputLineValue(string(publicationOutput), "recovery command: ")
if command == "" {
t.Fatalf("no handoff: %s", &diagnostics)
t.Fatalf("no handoff: %s", publicationOutput)
}
recovery := exec.Command("sh", "-c", command)
recovery.Dir = t.TempDir()
recovered, err := recovery.CombinedOutput()
var exitError *exec.ExitError
if !errors.As(err, &exitError) || exitError.ExitCode() != 1 || !strings.Contains(string(recovered), "module=example.com/cli-candidate tag=v1.2.3 state=not_published") {
t.Fatalf("vendored recovery: %v: %s", err, recovered)
}