Move renderer tests to captured templates

This commit is contained in:
2026-11-05 19:59:34 +00:00
parent acaf2ccd8b
commit d78474a3bf
5 changed files with 125 additions and 50 deletions

View File

@@ -13,6 +13,7 @@ import (
"strings"
"sync"
"testing"
"text/template"
"time"
"go.maximumdirect.net/promptkit/internal/capacity"
@@ -41,6 +42,36 @@ type staticPromptRepo struct {
def *domain.PromptDefinition
}
type capturedTemplateFixture struct {
id string
templates prompt.CompiledTemplates
}
func (fixture capturedTemplateFixture) GetCompiledTemplates(id string) (prompt.CompiledTemplates, bool) {
return fixture.templates, id == fixture.id
}
func testCompiledRenderer(t *testing.T, definition *domain.PromptDefinition) prompt.Renderer {
t.Helper()
var templates prompt.CompiledTemplates
if definition.SessionID != "" {
var err error
templates.Session, err = prompt.CompileTemplate("session", definition.SessionID)
if err != nil {
t.Fatal(err)
}
}
templates.Messages = make([]*template.Template, 0, len(definition.Templates))
for _, message := range definition.Templates {
compiled, err := prompt.CompileTemplate("message", message.Content)
if err != nil {
t.Fatal(err)
}
templates.Messages = append(templates.Messages, compiled)
}
return prompt.NewCompiledRenderer(capturedTemplateFixture{id: definition.ID, templates: templates})
}
func (r staticPromptRepo) GetPromptSnapshot(
context.Context,
string,
@@ -449,7 +480,7 @@ func TestRunnerDirectSessionResolution(t *testing.T) {
&fakeExecutionProfileRepo{profiles: map[string]*domain.ExecutionProfile{"exec": defaultExecutionProfile()}},
defaultArtifactReader(),
prompt.NewGoRenderer(),
testCompiledRenderer(t, def),
&fakeLLM{forbid: true},
nil, nil)
@@ -496,7 +527,7 @@ func TestRunnerDirectSessionResolution(t *testing.T) {
&fakeExecutionProfileRepo{profiles: map[string]*domain.ExecutionProfile{"exec": defaultExecutionProfile()}},
defaultArtifactReader(),
prompt.NewGoRenderer(),
testCompiledRenderer(t, def),
&fakeLLM{forbid: true},
nil, nil)
@@ -526,7 +557,7 @@ func TestRunnerDirectSessionResolution(t *testing.T) {
&fakeExecutionProfileRepo{profiles: map[string]*domain.ExecutionProfile{"exec": defaultExecutionProfile()}},
defaultArtifactReader(),
prompt.NewGoRenderer(),
testCompiledRenderer(t, def),
&fakeLLM{forbid: true},
nil, nil)
@@ -886,7 +917,7 @@ func TestRunnerPrepareRequiredInputMissingFails(t *testing.T) {
&fakeExecutionProfileRepo{profiles: map[string]*domain.ExecutionProfile{"exec": defaultExecutionProfile()}},
defaultArtifactReader(),
prompt.NewGoRenderer(),
testCompiledRenderer(t, def),
&fakeLLM{forbid: true},
nil, nil)
@@ -913,7 +944,7 @@ func TestRunnerPrepareUnknownTemplateInputReferenceFails(t *testing.T) {
&fakeExecutionProfileRepo{profiles: map[string]*domain.ExecutionProfile{"exec": defaultExecutionProfile()}},
defaultArtifactReader(),
prompt.NewGoRenderer(),
testCompiledRenderer(t, def),
&fakeLLM{forbid: true},
nil, nil)