Refactor the single-run HTTP contract
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user