Add local publication attempt discovery

This commit is contained in:
2026-11-02 19:09:26 +00:00
parent 2a04938a96
commit fb5947ea3a
7 changed files with 200 additions and 7 deletions

View File

@@ -1,11 +1,13 @@
package publish
import (
"context"
"encoding/json"
"errors"
"os"
"os/exec"
"path/filepath"
"sort"
"strings"
"testing"
)
@@ -154,3 +156,47 @@ func TestSaveEvidenceRejectsUnignoredOverrideInsideWorktree(t *testing.T) {
t.Fatalf("unexpected record: %v", err)
}
}
func TestListAttemptsReturnsReadableRecordsAndDiagnosticsInPathOrder(t *testing.T) {
repo := recordRepo(t)
directory := filepath.Join(t.TempDir(), "attempts")
if err := os.Mkdir(directory, 0700); err != nil {
t.Fatal(err)
}
second, _ := SaveEvidence(repo, directory, Evidence{Tag: "v2.0.0"})
first, _ := SaveEvidence(repo, directory, Evidence{Tag: "v1.0.0"})
if err := os.WriteFile(filepath.Join(directory, "broken.json"), []byte("{"), 0600); err != nil {
t.Fatal(err)
}
listed, err := ListAttempts(t.Context(), repo, directory)
if err != nil || len(listed.Attempts) != 2 || len(listed.Diagnostics) != 1 {
t.Fatalf("list=%#v error=%v", listed, err)
}
wantPaths := []string{first, second}
sort.Strings(wantPaths)
if listed.Attempts[0].RecordPath != wantPaths[0] || listed.Attempts[1].RecordPath != wantPaths[1] {
t.Fatalf("attempt order=%v", listed.Attempts)
}
if listed.Diagnostics[0].Kind != "record_format" || listed.Diagnostics[0].RecordPath == "" {
t.Fatalf("diagnostic=%#v", listed.Diagnostics[0])
}
}
func TestListAttemptsDistinguishesEmptyMissingAndCanceledStorage(t *testing.T) {
empty := t.TempDir()
listed, err := ListAttempts(t.Context(), "", empty)
if err != nil || len(listed.Attempts) != 0 || len(listed.Diagnostics) != 0 {
t.Fatalf("empty list=%#v error=%v", listed, err)
}
_, err = ListAttempts(t.Context(), "", filepath.Join(t.TempDir(), "missing"))
var recovery *RecoveryError
if !errors.As(err, &recovery) || recovery.Kind != "storage_enumeration" {
t.Fatalf("missing storage error=%v", err)
}
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err = ListAttempts(ctx, "", empty)
if !errors.As(err, &recovery) || recovery.Kind != "canceled" || !errors.Is(err, context.Canceled) {
t.Fatalf("canceled error=%v", err)
}
}