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:
@@ -23,6 +23,13 @@ func TestReadNoteRefusesSymlinksAndSurvivesSwapRaces(t *testing.T) {
|
||||
_, body, _, err := api.ReadNote(brain, "wiki/w/facts/leak.md")
|
||||
assert.Error(t, err)
|
||||
assert.NotContains(t, body, brainfstest.Sentinel)
|
||||
// A link to a file elsewhere in the brain: os.Root allows it, only the
|
||||
// regular-file check refuses it (hyperguild#171).
|
||||
brainfstest.WriteSentinelAt(t, filepath.Join(brain, "raw", "s.md"))
|
||||
require.NoError(t, os.Symlink(filepath.Join("..", "..", "..", "raw", "s.md"), filepath.Join(facts, "inlink.md")))
|
||||
_, body, _, err = api.ReadNote(brain, "wiki/w/facts/inlink.md")
|
||||
assert.Error(t, err)
|
||||
assert.NotContains(t, body, brainfstest.Sentinel)
|
||||
|
||||
p := filepath.Join(facts, "r.md")
|
||||
require.NoError(t, os.WriteFile(p, []byte("---\nx: y\n---\ninside"), 0o644))
|
||||
@@ -39,5 +46,7 @@ func TestReadNoteRefusesSymlinksAndSurvivesSwapRaces(t *testing.T) {
|
||||
return s
|
||||
}
|
||||
brainfstest.AssertNoLeak(t, p, "---\nx: y\n---\ninside", 1500*time.Millisecond, read)
|
||||
inBrain := brainfstest.WriteSentinelAt(t, filepath.Join(brain, "raw", "s.md"))
|
||||
brainfstest.AssertNoLeakFrom(t, p, "---\nx: y\n---\ninside", inBrain, 1500*time.Millisecond, read)
|
||||
brainfstest.AssertNoHang(t, p, "---\nx: y\n---\ninside", 1500*time.Millisecond, 6*time.Second, func() { _ = read() })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user