diff --git a/cmd/logos/index.go b/cmd/logos/index.go index 702d2d0..c8277bc 100644 --- a/cmd/logos/index.go +++ b/cmd/logos/index.go @@ -193,6 +193,10 @@ func indexPass(ix *index.Index, w io.Writer, p *provider.Provider, embed string) // nothing" cannot depend on a model being reachable. mems, rescuedMems, edits, err := ix.SyncMemoryEdits(p, embed) if err != nil { + // What the scan found before it refused is still true, and an + // unreadable file left out of this run would otherwise go unnamed + // behind the refusal. + printUnreadMemoryFiles(w, "", edits) return err } printMemoryEdits(w, edits) diff --git a/cmd/logos/index_refuses_unread_test.go b/cmd/logos/index_refuses_unread_test.go new file mode 100644 index 0000000..bdf6872 --- /dev/null +++ b/cmd/logos/index_refuses_unread_test.go @@ -0,0 +1,46 @@ +package main + +import ( + "os" + "path/filepath" + "runtime" + "strings" + "testing" +) + +// A damaged digest elsewhere makes the index refuse, and the refusal returned +// before the notice: the unreadable file the same scan found went unnamed, so +// the one run that had found it said nothing about it. +func TestAnUnreadableMemoryFileIsNamedWhenTheIndexRefuses(t *testing.T) { + if runtime.GOOS == "windows" || os.Geteuid() == 0 { + t.Skip("needs a file permission that stops its owner reading it") + } + vaultDir := t.TempDir() + t.Setenv("LOGOS_VAULT", vaultDir) + t.Setenv("LOGOS_EMBED", "off") + if err := memoryCmd([]string{"add", "--project", "shop", "Deploys go out on Tuesdays"}); err != nil { + t.Fatalf("memory add: %v", err) + } + matches, err := filepath.Glob(filepath.Join(vaultDir, "memories", "fact", "*.md")) + if err != nil || len(matches) != 1 { + t.Fatalf("got %v per-memory fact files (%v), want 1", matches, err) + } + locked := matches[0] + if err := os.Chmod(locked, 0); err != nil { + t.Fatal(err) + } + t.Cleanup(func() { os.Chmod(locked, 0o644) }) + torn := filepath.Join(vaultDir, "memories", "context.md") + if err := os.WriteFile(torn, []byte("- Shipping in November