Refactor the single-run HTTP contract

This commit is contained in:
2026-11-18 19:12:07 +00:00
parent de7c866662
commit f858d57322
6 changed files with 125 additions and 59 deletions

View File

@@ -11,6 +11,36 @@ import (
"go.maximumdirect.net/promptkit"
)
func TestRestrictedArtifactReaderReturnsDetachedBodies(t *testing.T) {
root := t.TempDir()
if err := os.WriteFile(filepath.Join(root, "input.txt"), []byte("original"), 0o644); err != nil {
t.Fatal(err)
}
reader, err := NewRestrictedArtifactReader(root, 0)
if err != nil {
t.Fatal(err)
}
for _, ref := range []promptkit.ArtifactRef{promptkit.Inline("original"), promptkit.File("input.txt")} {
first, err := reader.Read(context.Background(), ref)
if err != nil {
t.Fatal(err)
}
second, err := reader.Read(context.Background(), ref)
if err != nil {
t.Fatal(err)
}
first.Body[0] = 'X'
first.Name = "changed"
if string(second.Body) != "original" || second.Name == "changed" {
t.Fatalf("read results share mutable state: %+v", second)
}
second.Body[1] = 'Y'
if string(first.Body) != "Xriginal" {
t.Fatalf("reader retained a body alias: %q", first.Body)
}
}
}
func TestRestrictedArtifactReaderReadsContainedFiles(t *testing.T) {
root := t.TempDir()
outside := t.TempDir()