Filter publication record names before sorting directory results

This commit is contained in:
2026-11-02 22:36:35 +00:00
parent 781341a0ba
commit 3b8bacf114
3 changed files with 62 additions and 7 deletions

View File

@@ -371,6 +371,34 @@ func TestListAttemptsReturnsReadableRecordsAndDiagnosticsInPathOrder(t *testing.
}
}
func TestListAttemptsFiltersMixedDirectoryAcrossBatches(t *testing.T) {
directory := t.TempDir()
for i := range 400 {
if err := os.WriteFile(filepath.Join(directory, fmt.Sprintf("unrelated-%04d.txt", i)), []byte("not a record"), 0600); err != nil {
t.Fatal(err)
}
}
if err := os.Mkdir(filepath.Join(directory, "directory.json"), 0700); err != nil {
t.Fatal(err)
}
names := []string{"z.json", "b.json", "a.json"}
for _, name := range names {
if err := os.WriteFile(filepath.Join(directory, name), []byte(`{"format_version":1,"evidence":{"tag":"v1.2.3"}}`), 0600); err != nil {
t.Fatal(err)
}
}
listed, err := ListAttempts(t.Context(), "", directory)
if err != nil || len(listed.Diagnostics) != 0 || len(listed.Attempts) != len(names) {
t.Fatalf("filtered result = %#v, %v", listed, err)
}
sort.Strings(names)
for i, name := range names {
if listed.Attempts[i].RecordPath != filepath.Join(directory, name) {
t.Fatalf("incorrect path order: %#v", listed.Attempts)
}
}
}
func TestListAttemptsDistinguishesEmptyMissingAndCanceledStorage(t *testing.T) {
empty := t.TempDir()
listed, err := ListAttempts(t.Context(), "", empty)