fix(watcher): keep a note that changed while it was being ingested
The archive holds the content read at the start; if Syncthing replaced the note during the (minutes-long) LLM pass, removing the original would drop the newer content. Compare size+mtime before removing; leave it for the next poll. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -444,3 +444,27 @@ func TestProcessDir_KeepsTheOriginalWhenTheArchiveCopyFails(t *testing.T) {
|
||||
_, err := os.Stat(note)
|
||||
assert.NoError(t, err, "original stays in raw/ when it could not be archived")
|
||||
}
|
||||
|
||||
// If the note is replaced (e.g. by Syncthing) while it is being ingested, the
|
||||
// archive holds the OLD content; removing the original would lose the new one.
|
||||
func TestProcessDir_KeepsANoteThatChangedWhileItWasBeingIngested(t *testing.T) {
|
||||
brainDir := setupBrainDir(t)
|
||||
note := filepath.Join(brainDir, "raw", "edited.md")
|
||||
require.NoError(t, os.WriteFile(note, []byte("old"), 0o644))
|
||||
|
||||
cfg := Config{
|
||||
BrainDir: brainDir,
|
||||
Pipeline: pipeline.Config{
|
||||
Complete: func(ctx context.Context, s, u string) (string, error) {
|
||||
require.NoError(t, os.WriteFile(note, []byte("newer and longer content"), 0o644))
|
||||
return successComplete(pipeline.RawPage{Title: "Edited", Type: "source", Subtype: "article", Content: "x\n"})(ctx, s, u)
|
||||
},
|
||||
Schema: "# Schema",
|
||||
},
|
||||
}
|
||||
processDir(context.Background(), cfg, "2026-10-19")
|
||||
|
||||
got, err := os.ReadFile(note)
|
||||
require.NoError(t, err, "a note that changed during ingest must stay in raw/")
|
||||
assert.Equal(t, "newer and longer content", string(got))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user