Files
promptkit/execution_controls_conversion_test.go

39 lines
1.3 KiB
Go
Raw Normal View History

package promptkit
import (
"context"
"testing"
"time"
"go.maximumdirect.net/promptkit/internal/domain"
)
func TestExecutionControlsConversion(t *testing.T) {
ctx := context.WithValue(context.Background(), struct{}{}, "selected")
called := false
req := RunRequest{OperationTimeout: 3 * time.Second, OnPrepared: func(got context.Context, details PreparedRun) {
called = true
if got != ctx || details.PromptID != "prompt" {
t.Fatalf("unexpected notification: %v, %+v", got, details)
}
details.InputHashes["input"] = "changed"
}}
converted, err := toDomainRunRequest(req)
if err != nil {
t.Fatal(err)
}
if converted.OperationTimeout != req.OperationTimeout || converted.OnPrepared == nil || called {
t.Fatal("execution controls were not retained without invocation")
}
req.OnPrepared = func(context.Context, PreparedRun) { t.Fatal("callback selection changed") }
prepared := &domain.PreparedRun{PromptID: "prompt", InputHashes: map[string]string{"input": "original"}}
converted.OnPrepared(ctx, prepared)
if !called || prepared.InputHashes["input"] != "original" {
t.Fatal("notification did not deliver detached details")
}
withoutCallback, err := toDomainRunRequest(RunRequest{})
if err != nil || withoutCallback.OnPrepared != nil {
t.Fatalf("nil callback was adapted: %v", err)
}
}