Adopt Promptkit at application boundaries
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/scriptorium"
|
||||
"gitea.maximumdirect.net/eric/promptkit"
|
||||
)
|
||||
|
||||
func TestRestrictedArtifactReaderReadsContainedFiles(t *testing.T) {
|
||||
@@ -37,9 +37,9 @@ func TestRestrictedArtifactReaderReadsContainedFiles(t *testing.T) {
|
||||
t.Fatalf("construct restricted reader: %v", err)
|
||||
}
|
||||
|
||||
for _, ref := range []scriptorium.ArtifactRef{
|
||||
{Type: scriptorium.ArtifactRefFile, URI: "nested/../input.html"},
|
||||
{Type: scriptorium.ArtifactRefFile, URI: inputPath},
|
||||
for _, ref := range []promptkit.ArtifactRef{
|
||||
{Type: promptkit.ArtifactRefFile, URI: "nested/../input.html"},
|
||||
{Type: promptkit.ArtifactRefFile, URI: inputPath},
|
||||
} {
|
||||
artifact, err := reader.Read(context.Background(), ref)
|
||||
if err != nil {
|
||||
@@ -56,7 +56,7 @@ func TestRestrictedArtifactReaderReadsContainedFiles(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
artifact, err := reader.Read(context.Background(), scriptorium.File("input.unknown"))
|
||||
artifact, err := reader.Read(context.Background(), promptkit.File("input.unknown"))
|
||||
if err != nil {
|
||||
t.Fatalf("read unknown-extension path: %v", err)
|
||||
}
|
||||
@@ -64,9 +64,9 @@ func TestRestrictedArtifactReaderReadsContainedFiles(t *testing.T) {
|
||||
t.Fatalf("unexpected fallback content type: %q", artifact.ContentType)
|
||||
}
|
||||
|
||||
for _, ref := range []scriptorium.ArtifactRef{
|
||||
{Type: scriptorium.ArtifactRefFile, URI: filepath.Join("..", filepath.Base(outside), "secret.txt")},
|
||||
{Type: scriptorium.ArtifactRefFile, URI: filepath.Join(outside, "secret.txt")},
|
||||
for _, ref := range []promptkit.ArtifactRef{
|
||||
{Type: promptkit.ArtifactRefFile, URI: filepath.Join("..", filepath.Base(outside), "secret.txt")},
|
||||
{Type: promptkit.ArtifactRefFile, URI: filepath.Join(outside, "secret.txt")},
|
||||
} {
|
||||
_, err := reader.Read(context.Background(), ref)
|
||||
if !errors.Is(err, ErrFileOutsideRoot) {
|
||||
@@ -90,7 +90,7 @@ func TestRestrictedArtifactReaderFollowsSymlinkAfterLexicalCheck(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("construct restricted reader: %v", err)
|
||||
}
|
||||
artifact, err := reader.Read(context.Background(), scriptorium.File("linked.txt"))
|
||||
artifact, err := reader.Read(context.Background(), promptkit.File("linked.txt"))
|
||||
if err != nil {
|
||||
t.Fatalf("read symlink inside root: %v", err)
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func TestRestrictedArtifactReaderWithoutRootDeniesFiles(t *testing.T) {
|
||||
t.Fatalf("construct rootless reader: %v", err)
|
||||
}
|
||||
|
||||
artifact, err := reader.Read(context.Background(), scriptorium.Inline("inline"))
|
||||
artifact, err := reader.Read(context.Background(), promptkit.Inline("inline"))
|
||||
if err != nil {
|
||||
t.Fatalf("read inline artifact: %v", err)
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func TestRestrictedArtifactReaderWithoutRootDeniesFiles(t *testing.T) {
|
||||
t.Fatalf("unexpected inline artifact: %#v", artifact)
|
||||
}
|
||||
|
||||
_, err = reader.Read(context.Background(), scriptorium.File("input.txt"))
|
||||
_, err = reader.Read(context.Background(), promptkit.File("input.txt"))
|
||||
if !errors.Is(err, ErrFileNotAllowed) {
|
||||
t.Fatalf("expected ErrFileNotAllowed, got %v", err)
|
||||
}
|
||||
@@ -132,11 +132,11 @@ func TestRestrictedArtifactReaderEnforcesLimits(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("construct limited reader: %v", err)
|
||||
}
|
||||
artifact, err := reader.Read(context.Background(), scriptorium.File("exact.txt"))
|
||||
artifact, err := reader.Read(context.Background(), promptkit.File("exact.txt"))
|
||||
if err != nil || string(artifact.Body) != "12345" {
|
||||
t.Fatalf("expected exact-limit artifact, got %#v and %v", artifact, err)
|
||||
}
|
||||
_, err = reader.Read(context.Background(), scriptorium.File("large.txt"))
|
||||
_, err = reader.Read(context.Background(), promptkit.File("large.txt"))
|
||||
if !errors.Is(err, ErrFileTooLarge) {
|
||||
t.Fatalf("expected ErrFileTooLarge, got %v", err)
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func TestRestrictedArtifactReaderEnforcesLimits(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("construct unlimited reader: %v", err)
|
||||
}
|
||||
artifact, err = unlimited.Read(context.Background(), scriptorium.File("large.txt"))
|
||||
artifact, err = unlimited.Read(context.Background(), promptkit.File("large.txt"))
|
||||
if err != nil || string(artifact.Body) != "123456" {
|
||||
t.Fatalf("expected unlimited artifact, got %#v and %v", artifact, err)
|
||||
}
|
||||
@@ -163,9 +163,9 @@ func TestRestrictedArtifactReaderRejectsCanceledAndMalformedReferences(t *testin
|
||||
|
||||
canceledCtx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
for _, ref := range []scriptorium.ArtifactRef{
|
||||
scriptorium.Inline("input"),
|
||||
scriptorium.File("input.txt"),
|
||||
for _, ref := range []promptkit.ArtifactRef{
|
||||
promptkit.Inline("input"),
|
||||
promptkit.File("input.txt"),
|
||||
} {
|
||||
_, err := reader.Read(canceledCtx, ref)
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
@@ -173,10 +173,10 @@ func TestRestrictedArtifactReaderRejectsCanceledAndMalformedReferences(t *testin
|
||||
}
|
||||
}
|
||||
|
||||
for _, ref := range []scriptorium.ArtifactRef{
|
||||
{Type: scriptorium.ArtifactRefType("unsupported")},
|
||||
{Type: scriptorium.ArtifactRefInline},
|
||||
{Type: scriptorium.ArtifactRefFile},
|
||||
for _, ref := range []promptkit.ArtifactRef{
|
||||
{Type: promptkit.ArtifactRefType("unsupported")},
|
||||
{Type: promptkit.ArtifactRefInline},
|
||||
{Type: promptkit.ArtifactRefFile},
|
||||
} {
|
||||
if _, err := reader.Read(context.Background(), ref); err == nil {
|
||||
t.Fatalf("expected malformed reference %#v to fail", ref)
|
||||
|
||||
Reference in New Issue
Block a user