Retain discovered publication records when enumeration fails

This commit is contained in:
2026-11-02 22:41:18 +00:00
parent cd274512e7
commit 363f7cd513
7 changed files with 123 additions and 8 deletions

View File

@@ -93,7 +93,11 @@ func runRecovery(ctx context.Context, invocation cli.Invocation, stdout, stderr
return runReconcile(ctx, invocation, stdout, stderr)
}
listed, err := releasekit.ListPublicationAttempts(ctx, releasekit.PublicationAttemptsRequest{RepositoryDir: invocation.Repository, RecordDir: invocation.RecordDir})
if invocation.JSON {
return reportAttempts(listed, err, invocation.JSON, stdout, stderr)
}
func reportAttempts(listed releasekit.PublicationAttemptsResult, err error, jsonOutput bool, stdout, stderr io.Writer) int {
if jsonOutput {
attempts := make([]attemptDocument, 0, len(listed.Attempts))
for _, item := range listed.Attempts {
attempts = append(attempts, attemptDocument{RecordPath: git.DisplayDiagnostic(item.RecordPath), Evidence: safe(item.Evidence)})

View File

@@ -50,6 +50,32 @@ func TestRecoveryCommandsReportJSONWriteFailure(t *testing.T) {
}
}
func TestDiscoveryReportsPartialAttemptsAndEnumerationFailure(t *testing.T) {
listed := releasekit.PublicationAttemptsResult{
RecordDir: "records",
Attempts: []releasekit.PublicationAttempt{{RecordPath: "good.json", Evidence: releasekit.PublicationEvidence{Tag: "v1.2.3"}}},
Diagnostics: []*releasekit.PublicationRecoveryError{{Kind: "record_format", RecordPath: "broken.json"}},
}
failure := &releasekit.PublicationRecoveryError{Kind: "storage_enumeration"}
for _, jsonOutput := range []bool{false, true} {
var stdout, stderr bytes.Buffer
if status := reportAttempts(listed, failure, jsonOutput, &stdout, &stderr); status != 1 {
t.Fatalf("partial discovery status=%d", status)
}
if jsonOutput {
var document attemptsDocument
if err := json.Unmarshal(stdout.Bytes(), &document); err != nil {
t.Fatal(err)
}
if len(document.Attempts) != 1 || document.Attempts[0].RecordPath != "good.json" || len(document.Diagnostics) != 1 || document.Diagnostics[0].RecordPath != "broken.json" || document.Diagnostic == nil || document.Diagnostic.Kind != "storage_enumeration" {
t.Fatalf("partial JSON lost data: %s", &stdout)
}
} else if !strings.Contains(stdout.String(), "good.json") || !strings.Contains(stderr.String(), "broken.json") || !strings.Contains(stderr.String(), "storage_enumeration") {
t.Fatalf("partial human output lost data: %s%s", &stdout, &stderr)
}
}
}
func TestRecoveryDisplaysRedactCredentialPathsAndMetadata(t *testing.T) {
secret := "audit-secret"
raw := "https://audit-user:" + secret + "@example.invalid/attempt.json"