This commit is contained in:
2026-08-23 20:49:40 +02:00
parent 3b678ca857
commit f3d4fb56ed
31 changed files with 3608 additions and 111 deletions
@@ -34,6 +34,36 @@ func TestHashEnhanceInput_stableAndSensitive(t *testing.T) {
}
}
// enhanceHashFor runs the real pipeline once with a compliant stub reply and
// returns the enhance_input_hash it stamped. Deriving it this way keeps hash-skip
// tests correct as the steps feeding enhance (parsed specs, filled fields,
// category) evolve — hard-coding HashEnhanceInput args silently drifts instead.
func enhanceHashFor(t *testing.T, in ProductInput, processingType string) string {
t.Helper()
e := &Engine{
Completer: stubCompleter{fn: func(string, string) (Completion, error) {
return Completion{
Text: `{"name":"Seed Title","description":"Seed retail copy with enough factual detail to pass the enhance quality gate."}`,
TotalTokens: 1,
}, nil
}},
Vector: NoopVectorCategorizer{},
}
seed := in
seed.PriorEnhanceHash = ""
seed.PriorProcessedName = ""
seed.PriorProcessedDescription = ""
out, err := e.RunSteps(context.Background(), "co", seed, processingType, nil, StepPolicy{AllowAI: true, AllowEPREL: true})
if err != nil {
t.Fatal(err)
}
hash, _ := out.FieldSources[FieldEnhanceInputHash].(string)
if hash == "" {
t.Fatalf("seed run did not stamp an enhance hash: sources=%v notes=%v", out.FieldSources, out.Notes)
}
return hash
}
func TestRunSteps_skipsEnhanceWhenInputHashUnchanged(t *testing.T) {
calls := 0
e := &Engine{
@@ -51,13 +81,7 @@ func TestRunSteps_skipsEnhanceWhenInputHashUnchanged(t *testing.T) {
PriorProcessedName: "Cached Widget",
PriorProcessedDescription: priorDesc,
}
// First pass without prior hash to compute the hash shape via enhance path is awkward;
// compute the same hash RunSteps will see after normalize (name/desc from mapped).
// enhance_only: normalize then enhance with out.Name from normalized.
normName := "Widget"
normDesc := "A widget with enough mapped detail for hashing."
sysTpl, userTpl := resolveProductPromptTemplates(ProductInput{})
in.PriorEnhanceHash = HashEnhanceInput("", normName, normDesc, "", "", sysTpl, userTpl, map[string]any{})
in.PriorEnhanceHash = enhanceHashFor(t, in, "enhance_only")
out, err := e.RunSteps(context.Background(), "co", in, "enhance_only", nil, StepPolicy{AllowAI: true, AllowEPREL: true})
if err != nil {
@@ -381,16 +405,15 @@ func TestRunSteps_synthPriorHashDoesNotSkipReprocess(t *testing.T) {
if !company.LooksLikeHeuristicSynthesize(synthPrior) {
t.Fatalf("expected invent synth prior, got %q", synthPrior)
}
sysTpl, userTpl := resolveProductPromptTemplates(ProductInput{})
priorHash := HashEnhanceInput("", normName, normDesc, "", "", sysTpl, userTpl, map[string]any{})
out, err := e.RunSteps(context.Background(), "co", ProductInput{
Name: normName,
Description: normDesc,
Mapped: map[string]any{"name": normName, "description": normDesc},
PriorEnhanceHash: priorHash,
PriorProcessedName: normName,
PriorProcessedDescription: synthPrior,
}, "enhance_only", nil, StepPolicy{AllowAI: true, AllowEPREL: true})
base := ProductInput{
Name: normName,
Description: normDesc,
Mapped: map[string]any{"name": normName, "description": normDesc},
}
base.PriorEnhanceHash = enhanceHashFor(t, base, "enhance_only")
base.PriorProcessedName = normName
base.PriorProcessedDescription = synthPrior
out, err := e.RunSteps(context.Background(), "co", base, "enhance_only", nil, StepPolicy{AllowAI: true, AllowEPREL: true})
if err != nil {
t.Fatal(err)
}