Implement Scriptorium subprocess adapter
This commit is contained in:
77
internal/adapters/scriptorium/fake_test.go
Normal file
77
internal/adapters/scriptorium/fake_test.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package scriptorium
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestFakeRunnerCapturesRunAndRenderRequests(t *testing.T) {
|
||||
fake := &FakeRunner{}
|
||||
dir := t.TempDir()
|
||||
|
||||
runReq := RunArtifactRequest{
|
||||
Binary: "scriptorium",
|
||||
PromptID: "dnd.session_recap",
|
||||
OutputPath: filepath.Join(dir, "artifacts", "session_recap.md"),
|
||||
GeneratedConfigPath: filepath.Join(dir, "config", "scriptorium.run.generated.yml"),
|
||||
StdoutLogPath: filepath.Join(dir, "logs", "scriptorium.run.stdout.log"),
|
||||
StderrLogPath: filepath.Join(dir, "logs", "scriptorium.run.stderr.log"),
|
||||
Timeout: 2 * time.Second,
|
||||
}
|
||||
runRes, err := fake.RunArtifact(context.Background(), runReq)
|
||||
if err != nil {
|
||||
t.Fatalf("RunArtifact() error = %v", err)
|
||||
}
|
||||
if len(fake.RunRequests) != 1 || fake.RunRequests[0].PromptID != runReq.PromptID {
|
||||
t.Fatalf("run requests = %#v, want captured request", fake.RunRequests)
|
||||
}
|
||||
if runRes.OutputPath != runReq.OutputPath {
|
||||
t.Fatalf("run output path = %q, want %q", runRes.OutputPath, runReq.OutputPath)
|
||||
}
|
||||
|
||||
renderReq := RenderArtifactRequest{
|
||||
Binary: "scriptorium",
|
||||
PromptID: "dnd.session_recap",
|
||||
OutputPath: filepath.Join(dir, "artifacts", "session_recap.render.json"),
|
||||
GeneratedConfigPath: filepath.Join(dir, "config", "scriptorium.render.generated.yml"),
|
||||
StdoutLogPath: filepath.Join(dir, "logs", "scriptorium.render.stdout.log"),
|
||||
StderrLogPath: filepath.Join(dir, "logs", "scriptorium.render.stderr.log"),
|
||||
Timeout: 2 * time.Second,
|
||||
}
|
||||
renderRes, err := fake.RenderArtifact(context.Background(), renderReq)
|
||||
if err != nil {
|
||||
t.Fatalf("RenderArtifact() error = %v", err)
|
||||
}
|
||||
if len(fake.RenderRequests) != 1 || fake.RenderRequests[0].PromptID != renderReq.PromptID {
|
||||
t.Fatalf("render requests = %#v, want captured request", fake.RenderRequests)
|
||||
}
|
||||
if renderRes.OutputPath != renderReq.OutputPath {
|
||||
t.Fatalf("render output path = %q, want %q", renderRes.OutputPath, renderReq.OutputPath)
|
||||
}
|
||||
|
||||
cfgData, err := os.ReadFile(runReq.GeneratedConfigPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read generated config: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(cfgData), "placeholder: true") {
|
||||
t.Fatalf("generated config = %q, want placeholder marker", string(cfgData))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFakeRunnerError(t *testing.T) {
|
||||
fake := &FakeRunner{
|
||||
RunErr: errors.New("run boom"),
|
||||
RenderErr: errors.New("render boom"),
|
||||
}
|
||||
if _, err := fake.RunArtifact(context.Background(), RunArtifactRequest{}); err == nil {
|
||||
t.Fatal("expected run error, got nil")
|
||||
}
|
||||
if _, err := fake.RenderArtifact(context.Background(), RenderArtifactRequest{}); err == nil {
|
||||
t.Fatal("expected render error, got nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user