Document prepared message content hashes
This commit is contained in:
@@ -17,7 +17,7 @@ func contentHashEngine(t *testing.T, promptID, profileID, backendID, content str
|
||||
}
|
||||
config := promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{Source: configkit.Mapping("hash test", map[string]any{
|
||||
"backends": []any{map[string]any{"id": backendID, "endpoint": "https://example.test/v1"}},
|
||||
"profiles": []any{map[string]any{"id": profileID, "backend": backendID, "model": "model-" + profileID}},
|
||||
"profiles": []any{map[string]any{"id": profileID, "backend": backendID, "model": "model"}},
|
||||
"prompts": []any{map[string]any{"id": promptID, "default_profile": profileID, "inputs": []any{map[string]any{"name": "input", "required": false}}, "messages": []any{message}, "output": output}},
|
||||
})}}}
|
||||
engine, err := promptkit.NewEngine(config, opts...)
|
||||
@@ -44,15 +44,23 @@ func TestMessageContentHashIgnoresPreparationMetadata(t *testing.T) {
|
||||
baseEngine := contentHashEngine(t, "first", "alpha", "one", "same", textOutput, false)
|
||||
base := prepareContentHash(t, baseEngine, promptkit.RunRequest{PromptID: "first"})
|
||||
repeated := prepareContentHash(t, baseEngine, promptkit.RunRequest{PromptID: "first"})
|
||||
other := contentHashEngine(t, "second", "beta", "two", "same", textOutput, false)
|
||||
otherPrepared := prepareContentHash(t, other, promptkit.RunRequest{PromptID: "second", APIKey: "synthetic-key", Execution: &promptkit.ExecutionTargetOverride{Model: "other-model"}})
|
||||
otherPrompt := contentHashEngine(t, "second", "alpha", "one", "same", textOutput, false)
|
||||
otherProfile := contentHashEngine(t, "first", "beta", "one", "same", textOutput, false)
|
||||
otherBackend := contentHashEngine(t, "first", "alpha", "two", "same", textOutput, false)
|
||||
credential := prepareContentHash(t, baseEngine, promptkit.RunRequest{PromptID: "first", APIKey: "synthetic-key"})
|
||||
settings := prepareContentHash(t, baseEngine, promptkit.RunRequest{PromptID: "first", Execution: &promptkit.ExecutionTargetOverride{Model: "other-model"}})
|
||||
session := prepareContentHash(t, baseEngine, promptkit.RunRequest{PromptID: "first", SessionID: "other-session"})
|
||||
cacheEngine := contentHashEngine(t, "first", "alpha", "one", "same", textOutput, true)
|
||||
cached := prepareContentHash(t, cacheEngine, promptkit.RunRequest{PromptID: "first"})
|
||||
schemas := fstest.MapFS{"schema.json": &fstest.MapFile{Data: []byte(`{"type":"object"}`)}}
|
||||
schemaEngine := contentHashEngine(t, "first", "alpha", "one", "same", map[string]any{"format": "json", "validation_mode": "json_schema", "schema_path": "schema.json"}, false, promptkit.WithSchemaFS(schemas, "."))
|
||||
schema := prepareContentHash(t, schemaEngine, promptkit.RunRequest{PromptID: "first"})
|
||||
for name, prepared := range map[string]*promptkit.PreparedRun{"repeat": repeated, "identifiers and model": otherPrepared, "session": session, "cache": cached, "schema": schema} {
|
||||
for name, prepared := range map[string]*promptkit.PreparedRun{
|
||||
"repeat": repeated, "prompt": prepareContentHash(t, otherPrompt, promptkit.RunRequest{PromptID: "second"}),
|
||||
"profile": prepareContentHash(t, otherProfile, promptkit.RunRequest{PromptID: "first"}),
|
||||
"backend": prepareContentHash(t, otherBackend, promptkit.RunRequest{PromptID: "first"}),
|
||||
"credential": credential, "settings": settings, "session": session, "cache": cached, "schema": schema,
|
||||
} {
|
||||
if prepared.MessageContentHash != base.MessageContentHash {
|
||||
t.Errorf("%s changed content hash", name)
|
||||
}
|
||||
@@ -65,10 +73,10 @@ func TestMessageContentHashIgnoresPreparationMetadata(t *testing.T) {
|
||||
func TestMessageContentHashUsesRenderedInputBytes(t *testing.T) {
|
||||
reader := &mutablePreparedArtifactReader{body: "body", hash: "first-hash"}
|
||||
engine := contentHashEngine(t, "prompt", "profile", "backend", `{{input "input"}} {{.label}}`, map[string]any{"format": "text", "validation_mode": "none"}, false, promptkit.WithArtifactReader(reader))
|
||||
request := promptkit.RunRequest{PromptID: "prompt", Inputs: map[string]promptkit.ArtifactRef{"input": promptkit.Inline("first")}, Vars: map[string]string{"label": "label", "unused": "first"}}
|
||||
request := promptkit.RunRequest{PromptID: "prompt", Inputs: map[string]promptkit.ArtifactRef{"input": promptkit.File("first")}, Vars: map[string]string{"label": "label", "unused": "first"}}
|
||||
base := prepareContentHash(t, engine, request)
|
||||
reader.set("body", "other-hash")
|
||||
request.Inputs["input"] = promptkit.Inline("other")
|
||||
request.Inputs["input"] = promptkit.File("other")
|
||||
request.Vars["unused"] = "other"
|
||||
unchanged := prepareContentHash(t, engine, request)
|
||||
if unchanged.MessageContentHash != base.MessageContentHash {
|
||||
|
||||
Reference in New Issue
Block a user