test(compat): harden fixture containment cleanup

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
naiba
2026-07-14 06:12:00 +00:00
co-authored by naiba/CloudCode
parent 92a1cc76be
commit be9af6fcb3
4 changed files with 91 additions and 0 deletions
@@ -97,6 +97,41 @@ func TestFixture_AgentPathRejectsSymlinkParent(t *testing.T) {
assertPathRejection(t, err, PathRejectionSymlinkParent)
}
func TestFixture_AgentPathRejectsSymlinkTarget(t *testing.T) {
// Given
root := newTestAgentRoot(t, "agent-symlink-target")
outside := filepath.Join(t.TempDir(), "outside.txt")
requireNoFixtureError(t, os.WriteFile(outside, []byte("outside"), 0o600))
requireNoFixtureError(t, os.Symlink(outside, filepath.Join(root.Absolute(), "linked.txt")))
// When
_, err := root.Path("linked.txt")
// Then
assertPathRejection(t, err, PathRejectionSymlinkFinal)
}
func TestFixture_AgentPathRejectsExistingFinalSymlink(t *testing.T) {
// Given
root := newTestAgentRoot(t, "agent-final-symlink")
outside := filepath.Join(t.TempDir(), "outside.txt")
requireNoFixtureError(t, os.WriteFile(outside, []byte("unchanged"), 0o600))
requireNoFixtureError(t, os.Symlink(outside, filepath.Join(root.Absolute(), "linked.txt")))
// When
_, pathErr := root.Path("linked.txt")
_, destructiveErr := root.DestructivePath("linked.txt")
// Then
assertPathRejection(t, pathErr, PathRejectionSymlinkFinal)
assertPathRejection(t, destructiveErr, PathRejectionSymlinkFinal)
content, err := os.ReadFile(outside)
requireNoFixtureError(t, err)
if string(content) != "unchanged" {
t.Fatalf("final symlink target changed: %q", content)
}
}
func TestFixture_AgentPathRejectsCleanedEscape(t *testing.T) {
// Given
root := newTestAgentRoot(t, "agent-cleaned-escape")