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

@@ -431,6 +431,47 @@ func TestListAttemptsFiltersMixedDirectoryAcrossBatches(t *testing.T) {
}
}
func TestListAttemptsRetainsEntriesWithEnumerationFailure(t *testing.T) {
directory := t.TempDir()
for name, contents := range map[string]string{
"z.json": `{"format_version":1,"evidence":{"tag":"v2.0.0"}}`,
"a.json": `{"format_version":1,"evidence":{"tag":"v1.0.0"}}`,
"broken.json": "{", "unrelated.txt": "ignored",
} {
if err := os.WriteFile(filepath.Join(directory, name), []byte(contents), 0600); err != nil {
t.Fatal(err)
}
}
entries, err := os.ReadDir(directory)
if err != nil {
t.Fatal(err)
}
failure := errors.New("controlled directory read failure")
for _, empty := range []bool{false, true} {
calls := 0
listed, err := listAttempts(t.Context(), "", directory, func(ctx context.Context, dir string) ([]string, error) {
return readRecordPaths(ctx, dir, func(int) ([]os.DirEntry, error) {
calls++
if empty {
return nil, failure
}
return entries, failure
})
})
var recovery *RecoveryError
if !errors.As(err, &recovery) || recovery.Kind != "storage_enumeration" || !errors.Is(err, failure) || calls != 1 {
t.Fatalf("enumeration failure lost: %#v, %v; reads=%d", listed, err, calls)
}
if empty {
if len(listed.Attempts) != 0 || len(listed.Diagnostics) != 0 {
t.Fatalf("empty read: %#v", listed)
}
} else if len(listed.Attempts) != 2 || len(listed.Diagnostics) != 1 || filepath.Base(listed.Attempts[0].RecordPath) != "a.json" || filepath.Base(listed.Attempts[1].RecordPath) != "z.json" || listed.Diagnostics[0].Kind != "record_format" {
t.Fatalf("partial read dropped/reordered records: %#v", listed)
}
}
}
func TestListAttemptsDistinguishesEmptyMissingAndCanceledStorage(t *testing.T) {
empty := t.TempDir()
listed, err := ListAttempts(t.Context(), "", empty)