test(brainfs): per-caller in-brain symlink targets for slices 1-3 (#171)
os.Root refuses links that leave the brain on its own, so the slice 1-3 callers' outside-target tests stayed green when a caller read without brainfs's Lstat/SameFile checks (PR #168 round-2 review). Adds a static in-brain link (wiki/w/facts/inlink.md -> ../../../raw/s.md) and an AssertNoLeakFrom swap race with an in-brain target for search.Query, hydrate, vectorstore.Sync, readExcerpt and api.ReadNote. Flip-verified: replacing each caller's bfs.ReadRegular with an os.OpenRoot(brainDir).ReadFile turns every one red on the new assertions (Query, hydrate, Sync, readExcerpt, ReadNote). Also from that review: rename TestReadRegularNever... to ...DoesNotReturn... (rule 9: a sampled race), and AssertNoLeakFrom's failure message names the symlink target instead of 'outside file'. Closes #171 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,11 @@ func TestSyncRefusesSymlinkedNotesAndSurvivesSwapRaces(t *testing.T) {
|
||||
brain := t.TempDir()
|
||||
writeNote(t, brain, "wiki/w/facts/ok.md", "inside note")
|
||||
require.NoError(t, os.Symlink(brainfstest.Outside(t), filepath.Join(brain, "wiki", "w", "facts", "leak.md")))
|
||||
// A link to a file elsewhere in the brain: os.Root allows it, only the
|
||||
// regular-file checks refuse it (hyperguild#171). raw/ is not a scan root,
|
||||
// so its sentinel can only arrive through the link.
|
||||
inBrain := brainfstest.WriteSentinelAt(t, filepath.Join(brain, "raw", "s.md"))
|
||||
require.NoError(t, os.Symlink(filepath.Join("..", "..", "..", "raw", "s.md"), filepath.Join(brain, "wiki", "w", "facts", "inlink.md")))
|
||||
|
||||
emb := &recordingEmbedder{}
|
||||
store := &stubStore{}
|
||||
@@ -51,6 +56,7 @@ func TestSyncRefusesSymlinkedNotesAndSurvivesSwapRaces(t *testing.T) {
|
||||
assert.NotContains(t, emb.all(), brainfstest.Sentinel)
|
||||
for p := range store.upserts {
|
||||
assert.NotContains(t, p, "leak.md")
|
||||
assert.NotContains(t, p, "inlink.md")
|
||||
}
|
||||
|
||||
p := filepath.Join(brain, "knowledge", "r.md")
|
||||
@@ -61,6 +67,7 @@ func TestSyncRefusesSymlinkedNotesAndSurvivesSwapRaces(t *testing.T) {
|
||||
return e.all()
|
||||
}
|
||||
brainfstest.AssertNoLeak(t, p, "inside", 1500*time.Millisecond, sync)
|
||||
brainfstest.AssertNoLeakFrom(t, p, "inside", inBrain, 1500*time.Millisecond, sync)
|
||||
brainfstest.AssertNoHang(t, p, "inside", 1500*time.Millisecond, 6*time.Second, func() { _ = sync() })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user