Verify prepared notification ownership and cleanup

This commit is contained in:
2026-11-14 17:43:40 +00:00
parent 2b9badb3a5
commit a8698d45a8
5 changed files with 203 additions and 1 deletions

View File

@@ -50,8 +50,20 @@ func TestPreparedExecutionFreezesSourcesAndReturnsIndependentDetails(t *testing.
extraParams := map[string]any{
"nested": map[string]any{"source": "original"},
}
var notified *promptkit.PreparedRun
request := promptkit.RunRequest{
PromptID: "prepared",
APIKey: "synthetic-direct-key",
OnPrepared: func(_ context.Context, details promptkit.PreparedRun) {
notified = &details
if strings.Contains(fmt.Sprintf("%#v", details), "synthetic-direct-key") {
t.Error("notification exposed credential")
}
details.Messages[0].Content = "mutated notification"
details.InputHashes["input"] = "mutated notification"
details.EffectiveModelParams.ExtraParams["nested"].(map[string]any)["source"] = "mutated notification"
details.StructuredOutput.JSONSchema.Schema.(map[string]any)["title"] = "mutated notification"
},
Inputs: map[string]promptkit.ArtifactRef{
"input": promptkit.Inline("original request input"),
},
@@ -119,12 +131,18 @@ func TestPreparedExecutionFreezesSourcesAndReturnsIndependentDetails(t *testing.
if reader.callCount() != 1 {
t.Fatalf("execution reopened artifact source: calls=%d", reader.callCount())
}
if notified == nil || prepared.Details().Messages[0].Content != second.Messages[0].Content || prepared.Details().StructuredOutput.JSONSchema.Schema.(map[string]any)["title"] != "original root" {
t.Fatal("notification changed prepared state")
}
requests := client.snapshot()
if len(requests) != 1 {
t.Fatalf("generation calls=%d, want 1", len(requests))
}
generated := requests[0]
if generated.APIKey != "synthetic-direct-key" {
t.Fatal("direct credential did not reach client")
}
if generated.Prompt.Messages[0].Content != second.Messages[0].Content ||
generated.Target.Model != second.EffectiveModelParams.Model ||
!reflect.DeepEqual(generated.Target.ExtraParams, second.EffectiveModelParams.ExtraParams) ||