Make prompt tests resilient to wording changes

This commit is contained in:
2026-11-26 03:04:54 +00:00
parent 97e9d51db0
commit fef0530533
9 changed files with 84 additions and 103 deletions

View File

@@ -40,17 +40,9 @@ func TestCombatPromptPairPreservesNativeContractAndFixedGrounding(t *testing.T)
if first.SelectedProfileID != "notarius/dnd-extraction" || first.SelectedProfileID != next.SelectedProfileID || first.StructuredOutput == nil || !reflect.DeepEqual(first.OutputContract, next.OutputContract) {
t.Fatal("combat native pair lost its schema/default profile")
}
var system, all string
var all string
for _, message := range first.Messages {
all += message.Content
if message.Role == "system" {
system += message.Content
}
}
for _, principle := range []string{"Unmatched actors remain permitted.", "Exclude initiative setup without a turn", "Transcript units are the only evidence", "legendary_action", "lair_action"} {
if !strings.Contains(strings.Join(strings.Fields(system), " "), principle) {
t.Fatalf("missing enduring rule %q", principle)
}
}
for _, marker := range []string{"combat-transcript-marker", "combat-npc-marker", "combat-party-marker"} {
if strings.Count(all, marker) != 1 {

View File

@@ -151,16 +151,15 @@ func TestRegistryNormalizationPromptPairsRetainTheirNativeContracts(t *testing.T
for _, test := range []struct {
id string
guidance string
rules []string
}{
{"notarius/dnd.npc_registry.normalize", "Preserve distinct individuals.", []string{"same individual", "unadorned proper name"}},
{"notarius/dnd.location_registry.normalize", "Keep parent and child places separate.", []string{"same physical place", "parent and child places"}},
{"notarius/dnd.npc_registry.normalize", "Preserve distinct individuals."},
{"notarius/dnd.location_registry.normalize", "Keep parent and child places separate."},
} {
t.Run(test.id, func(t *testing.T) {
initial, err := engine.PrepareExecution(context.Background(), promptkit.RunRequest{
PromptID: test.id, APIKey: "test-only", Inputs: map[string]promptkit.ArtifactRef{
"candidates": promptkit.Inline(`{"candidate_number_range":{"first":1,"last":2},"candidates":[]}`),
"transcript": promptkit.Inline(`{"windows":[]}`),
"candidates": promptkit.Inline(`{"sentinel":"normalization-candidates-sentinel"}`),
"transcript": promptkit.Inline(`{"sentinel":"normalization-transcript-sentinel"}`),
},
})
if err != nil {
@@ -180,20 +179,15 @@ func TestRegistryNormalizationPromptPairsRetainTheirNativeContracts(t *testing.T
first.StructuredOutput == nil || next.StructuredOutput == nil || !reflect.DeepEqual(first.OutputContract, next.OutputContract) {
t.Fatal("normalization pair lost its shared native defaults/output contract")
}
var system string
for _, message := range first.Messages {
if message.Role == "system" {
system += message.Content
}
}
for _, rule := range append(test.rules, "candidate_number_range", "start_unit_id", "canonical_candidate_number") {
if !strings.Contains(system, rule) {
t.Fatalf("missing enduring system principle %q", rule)
}
}
if len(next.Messages) != 1 || next.Messages[0].Role != "user" || !strings.Contains(next.Messages[0].Content, test.guidance) {
t.Fatal("correction did not supply only the findings and replacement assignment")
}
for _, sentinel := range []string{"normalization-candidates-sentinel", "normalization-transcript-sentinel"} {
renderedInputMessageIndex(t, first.Messages, sentinel)
if strings.Contains(next.Messages[0].Content, sentinel) {
t.Fatalf("correction repeated input %q", sentinel)
}
}
})
}
}

View File

@@ -2,25 +2,32 @@ package assets_test
import (
"context"
"io/fs"
"strings"
"testing"
"gitea.maximumdirect.net/eric/notarius/assets"
"go.maximumdirect.net/promptkit"
)
func TestExtractionPromptComposition(t *testing.T) {
const (
transcriptSentinel = "shared-transcript-sentinel"
playersSentinel = "shared-players-sentinel"
partySentinel = "shared-party-sentinel"
glossarySentinel = "shared-glossary-sentinel"
npcSentinel = "npc-registry-sentinel"
catalogSentinel = "spell-catalog-sentinel"
evidenceSentinel = "Transcript units are the only evidence"
endpointOrderSentinel = "according to transcript order"
combatPolicySentinel = "substantive active combat materially organizes the"
transcriptSentinel = "shared-transcript-sentinel"
playersSentinel = "shared-players-sentinel"
partySentinel = "shared-party-sentinel"
glossarySentinel = "shared-glossary-sentinel"
npcSentinel = "npc-registry-sentinel"
catalogSentinel = "spell-catalog-sentinel"
)
_, engine := loadNativeAssets(t)
evidence, err := fs.ReadFile(assets.FS(), "dnd/shared/prompts/common-dnd-extraction-evidence.md")
if err != nil {
t.Fatal(err)
}
combatPolicy, err := fs.ReadFile(assets.FS(), "dnd/shared/prompts/common-dnd-scene-combat-policy.md")
if err != nil {
t.Fatal(err)
}
commonInputs := map[string]promptkit.ArtifactRef{
"transcript": promptkit.InlineWithURI("file:///session.json", `{"sentinel":"`+transcriptSentinel+`"}`),
"players": promptkit.Inline(playersSentinel),
@@ -28,26 +35,26 @@ func TestExtractionPromptComposition(t *testing.T) {
"glossary": promptkit.Inline(glossarySentinel),
}
cases := []struct {
name string
promptID string
inputs map[string]promptkit.ArtifactRef
suffixGroups [][]string
middleSentinel string
name string
promptID string
inputs map[string]promptkit.ArtifactRef
suffixGroups [][]string
scenePolicy bool
}{
{name: "npcs", promptID: "notarius/dnd.npc_registry", inputs: commonInputs, suffixGroups: [][]string{{evidenceSentinel, endpointOrderSentinel}}},
{name: "locations", promptID: "notarius/dnd.location_registry", inputs: commonInputs, suffixGroups: [][]string{{evidenceSentinel, endpointOrderSentinel}}},
{name: "npcs", promptID: "notarius/dnd.npc_registry", inputs: commonInputs},
{name: "locations", promptID: "notarius/dnd.location_registry", inputs: commonInputs},
{name: "item occurrences", promptID: "notarius/dnd.item_occurrences", inputs: withPromptInputs(commonInputs, map[string]promptkit.ArtifactRef{
"item_registry": promptkit.Inline(`{"items":[{"id":"item-registry-sentinel","name":"Torch"}]}`),
}), suffixGroups: [][]string{{evidenceSentinel, endpointOrderSentinel}, {"item-registry-sentinel"}}},
{name: "item registry", promptID: "notarius/dnd.item_registry", inputs: commonInputs, suffixGroups: [][]string{{evidenceSentinel, endpointOrderSentinel}}},
{name: "scene descriptions", promptID: "notarius/dnd.scene_descriptions", inputs: commonInputs, middleSentinel: combatPolicySentinel},
}), suffixGroups: [][]string{{"item-registry-sentinel"}}},
{name: "item registry", promptID: "notarius/dnd.item_registry", inputs: commonInputs},
{name: "scene descriptions", promptID: "notarius/dnd.scene_descriptions", inputs: commonInputs, scenePolicy: true},
{
name: "combat turns",
promptID: "notarius/dnd.combat_turns",
inputs: withPromptInputs(commonInputs, map[string]promptkit.ArtifactRef{
"npc_registry": promptkit.Inline(`{"sentinel":"` + npcSentinel + `"}`),
}),
suffixGroups: [][]string{{evidenceSentinel, endpointOrderSentinel}, {npcSentinel}},
suffixGroups: [][]string{{npcSentinel}},
},
{
name: "enemy events",
@@ -58,7 +65,6 @@ func TestExtractionPromptComposition(t *testing.T) {
"npc_occurrences": promptkit.Inline(`{"sentinel":"npc-occurrences-sentinel"}`),
}),
suffixGroups: [][]string{
{evidenceSentinel, endpointOrderSentinel},
{npcSentinel},
{"combat-turns-sentinel", "npc-occurrences-sentinel"},
},
@@ -69,7 +75,7 @@ func TestExtractionPromptComposition(t *testing.T) {
inputs: withPromptInputs(commonInputs, map[string]promptkit.ArtifactRef{
"npc_registry": promptkit.Inline(`{"sentinel":"` + npcSentinel + `"}`),
}),
suffixGroups: [][]string{{evidenceSentinel, endpointOrderSentinel}, {npcSentinel}},
suffixGroups: [][]string{{npcSentinel}},
},
{
name: "location occurrences",
@@ -77,7 +83,7 @@ func TestExtractionPromptComposition(t *testing.T) {
inputs: withPromptInputs(commonInputs, map[string]promptkit.ArtifactRef{
"location_registry": promptkit.Inline(`{"sentinel":"location-registry-sentinel"}`),
}),
suffixGroups: [][]string{{evidenceSentinel, endpointOrderSentinel}, {"location-registry-sentinel"}},
suffixGroups: [][]string{{"location-registry-sentinel"}},
},
{
name: "spells",
@@ -86,7 +92,7 @@ func TestExtractionPromptComposition(t *testing.T) {
"npc_registry": promptkit.Inline(`{"sentinel":"` + npcSentinel + `"}`),
"spell_catalog": promptkit.Inline(`{"sentinel":"` + catalogSentinel + `"}`),
}),
suffixGroups: [][]string{{evidenceSentinel, endpointOrderSentinel}, {npcSentinel}, {catalogSentinel}},
suffixGroups: [][]string{{npcSentinel}, {catalogSentinel}},
},
}
@@ -105,12 +111,24 @@ func TestExtractionPromptComposition(t *testing.T) {
prepared := handle.Details()
transcriptIndex := renderedInputMessageIndex(t, prepared.Messages, transcriptSentinel)
referenceIndex := renderedInputMessageIndex(t, prepared.Messages, playersSentinel)
for _, sentinel := range []string{partySentinel, glossarySentinel} {
if index := renderedInputMessageIndex(t, prepared.Messages, sentinel); index != referenceIndex {
t.Fatalf("reference %q rendered at message %d, want %d", sentinel, index, referenceIndex)
}
}
if referenceIndex >= transcriptIndex {
t.Fatalf("campaign references rendered at message %d, want before transcript message %d", referenceIndex, transcriptIndex)
}
assertEphemeralCache(t, prepared.Messages, referenceIndex)
assertEphemeralCache(t, prepared.Messages, transcriptIndex)
previousIndex := transcriptIndex
shared := evidence
if testCase.scenePolicy {
shared = combatPolicy
}
previousIndex := renderedInputMessageIndex(t, prepared.Messages, strings.TrimSpace(string(shared)))
if previousIndex <= transcriptIndex || prepared.Messages[previousIndex].Role != "system" {
t.Fatal("shared system message must follow the transcript")
}
for _, group := range testCase.suffixGroups {
groupIndex := -1
for _, sentinel := range group {
@@ -127,12 +145,6 @@ func TestExtractionPromptComposition(t *testing.T) {
previousIndex = groupIndex
}
instructionIndex := len(prepared.Messages) - 1
if testCase.middleSentinel != "" {
policyIndex := renderedInputMessageIndex(t, prepared.Messages, testCase.middleSentinel)
if policyIndex <= transcriptIndex || policyIndex >= instructionIndex {
t.Fatalf("combat policy rendered at message %d, want after transcript message %d and before instructions message %d", policyIndex, transcriptIndex, instructionIndex)
}
}
if instructionIndex <= previousIndex {
t.Fatalf("instructions rendered at message %d, want after lane input message %d", instructionIndex, previousIndex)
}

View File

@@ -12,15 +12,14 @@ import (
"go.maximumdirect.net/promptkit"
)
func TestRegistryExtractionPromptPairsRetainDomainRulesAndContracts(t *testing.T) {
func TestRegistryExtractionPromptPairsRetainInputsAndContracts(t *testing.T) {
_, engine := loadNativeAssets(t)
for _, test := range []struct {
family, instruction string
rules []string
}{
{"npc", "Revise the NPC citations.", []string{"proper name or a stable, individually distinguishing", "factual third-party mention", "Exclude human players"}},
{"item", "Revise the item citations.", []string{"named unique items", "concrete reusable item types", "currency denomination", "generic weapons", "Do not use capitalization as an eligibility test"}},
{"location", "Revise the location citations.", []string{"stable proper name or unique in-world designation", "the room", "Do not use capitalization as an eligibility test"}},
{"npc", "Revise the NPC citations."},
{"item", "Revise the item citations."},
{"location", "Revise the location citations."},
} {
t.Run(test.family, func(t *testing.T) {
id := "notarius/dnd." + test.family + "_registry"
@@ -47,23 +46,15 @@ func TestRegistryExtractionPromptPairsRetainDomainRulesAndContracts(t *testing.T
first.StructuredOutput == nil || correction.StructuredOutput == nil || !reflect.DeepEqual(first.OutputContract, correction.OutputContract) {
t.Fatal("registry prompt pair lost native schema/defaults")
}
var system, all string
var all string
for _, message := range first.Messages {
all += message.Content
if message.Role == "system" {
system += message.Content
}
if strings.Contains(message.Content, "registry-transcript") || strings.Contains(message.Content, "registry-players") {
if message.CacheControl == nil || message.CacheControl.Type != promptkit.CacheControlEphemeral {
t.Fatal("fixed input cache hint lost")
}
}
}
for _, rule := range append(test.rules, "Transcript units are the only evidence", "Use the most specific supported in-world") {
if !strings.Contains(strings.Join(strings.Fields(system), " "), rule) {
t.Fatalf("missing enduring domain rule %q", rule)
}
}
for _, input := range []string{"registry-transcript", "registry-players", "registry-party", "registry-glossary"} {
if strings.Count(all, input) != 1 {
t.Fatalf("fixed input not rendered once: %q", input)

View File

@@ -97,19 +97,11 @@ func TestSceneDescriptionPromptPairRetainsPolicyAndFixedInputs(t *testing.T) {
if first.SelectedProfileID != "notarius/dnd-extraction" || first.SelectedProfileID != next.SelectedProfileID || first.StructuredOutput == nil || !reflect.DeepEqual(first.OutputContract, next.OutputContract) {
t.Fatal("scene pair lost schema/defaults")
}
var system, all string
var all string
for _, message := range first.Messages {
all += message.Content
if message.Role == "system" {
system += message.Content
}
}
for _, rule := range []string{"complete chunk is the evidence boundary", "substantive active combat materially organizes the", "must not invent a proper noun"} {
if !strings.Contains(strings.Join(strings.Fields(system), " "), rule) {
t.Fatalf("missing enduring rule %q", rule)
}
}
for _, material := range []string{"scene-description-transcript", "scene-description-player", "substantive active combat materially organizes the"} {
for _, material := range []string{"scene-description-transcript", "scene-description-player"} {
if strings.Count(all, material) != 1 {
t.Fatalf("fixed input/policy repeated: %q", material)
}

View File

@@ -594,6 +594,10 @@ choice, not a reason to add locks everywhere or promise universal thread safety.
**Assessment:** Test-maintenance weakness; original P3.
**Status:** Resolved. Prompt tests exercise supplied inputs, native contracts,
shared asset placement, cache hints, and follow-up routing without pinning prose.
The targeted asset, reconciliation, and extraction suites pass.
**Source:** [TEST-005](08-testing.md#test-005--prompt-tests-contain-prose-change-detectors).
Several asset/module tests require literal prose fragments; composition tests

View File

@@ -866,6 +866,8 @@ Update relevant canonical-input explanations.
## Stage 32 — Replace Prompt-Prose Change Detectors
**Completed.**
**Coverage:** CAT-026. **Prerequisites:** prior operation/capture work settled.
Inspect asset registry/scene/combat/package/composition, reconciliation, and spell

View File

@@ -17,7 +17,7 @@ func TestNativeReconciliationPromptPairPreparesOffline(t *testing.T) {
if err != nil {
t.Fatal(err)
}
correction := CorrectionRequest(CorrectionPromptID, "test-profile", "session-1", []string{"Use only candidate numbers in the supplied range.", "Preserve distinct entities."})
correction := CorrectionRequest(CorrectionPromptID, "test-profile", "session-1", []string{"guidance-one-sentinel", "guidance-two-sentinel"})
if len(correction.Inputs) != 1 {
t.Fatal("correction regenerated fixed evidence")
}
@@ -37,23 +37,12 @@ func TestNativeReconciliationPromptPairPreparesOffline(t *testing.T) {
}
if i == 0 {
first = prepared
var system string
for _, message := range prepared.Messages {
if message.Role == "system" {
system += message.Content
}
}
for _, rule := range []string{"candidate_number_range", "not candidate numbers", "do not copy candidate names", "Preserve distinct entities"} {
if !strings.Contains(system, rule) {
t.Fatalf("missing enduring system principle %q", rule)
}
}
} else {
if !reflect.DeepEqual(first.OutputContract, prepared.OutputContract) || len(prepared.Messages) != 1 || prepared.Messages[0].Role != "user" {
t.Fatal("correction changed native contract or supplied more than a follow-up assignment")
}
text := prepared.Messages[0].Content
if !strings.Contains(text, "Use only candidate numbers") || !strings.Contains(text, "complete replacement proposal") {
if strings.Count(text, "guidance-one-sentinel") != 1 || strings.Count(text, "guidance-two-sentinel") != 1 {
t.Fatal("correction lost findings or assignment")
}
for _, material := range preparation.Materials() {

View File

@@ -17,9 +17,9 @@ func TestSpellPromptPairSharesNativeContractAndDefaultProfile(t *testing.T) {
inputs := map[string]promptkit.ArtifactRef{"guidance": promptkit.Inline("Fix the rejected cast.")}
if id == PromptID {
inputs = map[string]promptkit.ArtifactRef{
"transcript": promptkit.Inline(`{"units":[1,2]}`),
"spell_catalog": promptkit.Inline(`{"spells":[]}`),
"npc_registry": promptkit.Inline(`{"npcs":[]}`),
"transcript": promptkit.Inline(`{"sentinel":"spell-transcript-sentinel"}`),
"spell_catalog": promptkit.Inline(`{"sentinel":"spell-catalog-sentinel"}`),
"npc_registry": promptkit.Inline(`{"sentinel":"spell-npcs-sentinel"}`),
"players": promptkit.Inline(" "), "party": promptkit.Inline(" "), "glossary": promptkit.Inline(" "),
}
}
@@ -37,19 +37,24 @@ func TestSpellPromptPairSharesNativeContractAndDefaultProfile(t *testing.T) {
}
if id == PromptID {
initial = prepared
var system string
for _, message := range prepared.Messages {
if message.Role == "system" {
system += message.Content
for _, sentinel := range []string{"spell-transcript-sentinel", "spell-catalog-sentinel", "spell-npcs-sentinel"} {
var count int
for _, message := range prepared.Messages {
count += strings.Count(message.Content, sentinel)
}
if count != 1 {
t.Fatalf("input %q rendered %d times", sentinel, count)
}
}
if !strings.Contains(system, "canonical spelling exactly") || !strings.Contains(system, "in-world caster") {
t.Fatal("enduring spell constraints missing from initial system context")
}
} else {
if !reflect.DeepEqual(initial.OutputContract, prepared.OutputContract) || len(prepared.Messages) != 1 || prepared.Messages[0].Role != "user" || !strings.Contains(prepared.Messages[0].Content, "Fix the rejected cast.") {
t.Fatal("correction must supply only findings and a replacement assignment with the same contract")
}
for _, sentinel := range []string{"spell-transcript-sentinel", "spell-catalog-sentinel", "spell-npcs-sentinel"} {
if strings.Contains(prepared.Messages[0].Content, sentinel) {
t.Fatalf("correction repeated input %q", sentinel)
}
}
}
}
if len(client.requests) != 0 {