This commit is contained in:
greeneclipse committed 2026-10-15 21:22:43 +02:00
1 parent 04794aea54
commit cfd31f398c
61 files changed
+2062 -254

No files matched your search

+22
View File
@@ -1587,6 +1587,28 @@ func (p *Pipeline) processOne(ctx context.Context, companyID, jobID uuid.UUID, i
if err != nil {
return false, 0, StepResult{}, err
}
if strings.EqualFold(strings.TrimSpace(processingType), "seo_meta") {
// SEO metadata processing must not rewrite product display content.
if in.PriorProcessedName != "" {
result.ProcessedName = in.PriorProcessedName
}
if in.PriorProcessedDescription != "" {
result.ProcessedDescription = in.PriorProcessedDescription
}
if in.PriorCategory != "" {
result.Category = in.PriorCategory
}
for lang, fields := range result.LocalizedContent {
previous := company.FieldsForLanguage(in.PriorLocalized, lang)
if previous.ProcessedName != "" {
fields.ProcessedName = previous.ProcessedName
}
if previous.ProcessedDescription != "" {
fields.ProcessedDescription = previous.ProcessedDescription
}
result.LocalizedContent[lang] = fields
}
}
// Persist mapped unique_id only when it exists in the company taxonomy.
// Coerce display names (feed/vector) → unique_id before filtering so A1-style
// name tokens are not wiped. Empty taxonomy set skips filtering (unit tests).
@@ -0,0 +1,42 @@
package processing
import (
"reflect"
"testing"
)
func TestSEOMetaOnlySelectsEnrichmentPrerequisites(t *testing.T) {
steps := resolveSteps("seo_meta")
want := []string{StepNormalize, StepParseSpecs, StepFillFields, StepCategorize, StepAIEnhance}
if !reflect.DeepEqual(steps, want) {
t.Fatalf("seo_meta steps = %v, want %v", steps, want)
}
}
func TestSEOMetaAcceptedByPublicProcess(t *testing.T) {
storage, response, err := ParseV1ProcessingType("seo_meta")
if err != nil || storage != "seo_meta" || response != "seo_meta" {
t.Fatalf("ParseV1ProcessingType(seo_meta) = %q, %v, %v", storage, response, err)
}
}
func TestSEOMetaPartialResultIncludesMetaNotCopy(t *testing.T) {
input := []V1ProcessJobItem{{
"ean": "1234567890123", "name": "Existing name", "description": "Existing description",
"meta_title": "SEO title", "meta_description": "SEO description", "status": "completed",
}}
result := ProjectV1ProcessJobItems("seo_meta", input)
if len(result) != 1 {
t.Fatalf("items = %d", len(result))
}
item := result[0]
if item["meta_title"] != "SEO title" || item["meta_description"] != "SEO description" {
t.Fatalf("missing SEO metadata: %#v", item)
}
if _, found := item["name"]; found {
t.Fatalf("SEO-only response must not project title: %#v", item)
}
if _, found := item["description"]; found {
t.Fatalf("SEO-only response must not project description: %#v", item)
}
}
+55 -5
View File
@@ -314,10 +314,22 @@ func (e *Engine) RunSteps(ctx context.Context, companyID string, in ProductInput
priorDesc = in.PriorProcessedDescription
}
}
metaOnly := strings.EqualFold(strings.TrimSpace(processingType), "seo_meta")
promptName, promptDesc := out.Name, out.Description
if metaOnly {
if priorName != "" {
promptName = priorName
}
if priorDesc != "" {
promptDesc = priorDesc
}
// Bypass unrelated description/title hash caching for a metadata refresh.
priorHash = ""
}
name, desc, tokens, raw, err := e.enhance(ctx, ProductInput{
GTIN: in.GTIN,
Name: out.Name,
Description: out.Description,
Name: promptName,
Description: promptDesc,
Mapped: normalized,
BrandPrompt: in.BrandPrompt,
Language: lang,
@@ -405,6 +417,14 @@ func (e *Engine) RunSteps(ctx context.Context, companyID string, in ProductInput
allUnchanged = false
}
}
if metaOnly {
// Do not persist unrelated AI rewrites on SEO-only jobs.
name, desc = promptName, promptDesc
persistHash = company.FieldsForLanguage(in.PriorLocalized, lang).EnhanceInputHash
if lang == primary && persistHash == "" {
persistHash = in.PriorEnhanceHash
}
}
localized[lang] = company.LocalizedFields{
ProcessedName: name,
ProcessedDescription: desc,
@@ -444,7 +464,7 @@ func (e *Engine) RunSteps(ctx context.Context, companyID string, in ProductInput
}
// Merge LLM attrs onto pipeline attrs (validated against category keys).
// Attrs are independent of title/description soft-fail (synthesized/refused).
if err == nil && status != "failed" && status != "parse_failed" {
if !metaOnly && err == nil && status != "failed" && status != "parse_failed" {
if merged := mergeEnhanceAttrsInto(attrs, enhanceAttrsFromRaw(raw), enhanceAllowedAttrKeys(in, out.Category)); len(merged) > 0 {
attrs = merged
enhanceAttrs = AttrsForEnhance(attrs, enhanceAllowedAttrKeys(in, out.Category))
@@ -576,7 +596,7 @@ func (e *Engine) RunSteps(ctx context.Context, companyID string, in ProductInput
// repair short prose / title echo that ignored A1 description_template.
finalDescTpl := effectiveDescriptionTemplateFor(in, out)
finalRepaired := false
if descriptionNeedsEnhanceRepair(out.ProcessedDescription, finalDescTpl, out.ProcessedName, out.Name) {
if !strings.EqualFold(strings.TrimSpace(processingType), "seo_meta") && descriptionNeedsEnhanceRepair(out.ProcessedDescription, finalDescTpl, out.ProcessedName, out.Name) {
if synth := synthesizeProductDescription(out.ProcessedName, displayCat, in.Language, out.Attributes, finalDescTpl); synth != "" {
out.ProcessedDescription = synth
finalRepaired = true
@@ -605,6 +625,36 @@ func (e *Engine) RunSteps(ctx context.Context, companyID string, in ProductInput
out.LocalizedContent[lang] = lf
}
}
if strings.EqualFold(strings.TrimSpace(processingType), "seo_meta") {
// Preserve existing product copy even if enhancement attempted title/description
// repair internally while building SEO metadata.
if in.PriorProcessedName != "" {
out.ProcessedName = in.PriorProcessedName
} else {
out.ProcessedName = out.Name
}
if in.PriorProcessedDescription != "" {
out.ProcessedDescription = in.PriorProcessedDescription
} else {
out.ProcessedDescription = out.Description
}
for lang, fields := range out.LocalizedContent {
old := company.FieldsForLanguage(in.PriorLocalized, lang)
if old.ProcessedName != "" {
fields.ProcessedName = old.ProcessedName
} else {
fields.ProcessedName = out.Name
}
if old.ProcessedDescription != "" {
fields.ProcessedDescription = old.ProcessedDescription
} else {
fields.ProcessedDescription = out.Description
}
out.LocalizedContent[lang] = fields
}
delete(out.FieldSources, "name")
delete(out.FieldSources, "description")
}
if out.Attributes == nil {
out.Attributes = map[string]any{}
}
@@ -708,7 +758,7 @@ func noteMissingCategory(out *StepResult, policy StepPolicy, vectorEnabled bool)
func resolveSteps(processingType string) []string {
switch strings.ToLower(strings.TrimSpace(processingType)) {
case "enhance", "enhance_only", "enhance-only", "title", "description":
case "enhance", "enhance_only", "enhance-only", "title", "description", "seo_meta":
// parse_specs/fill_fields/categorize feed ai_enhance — they never rewrite
// title/description themselves. Without them enhance ran with empty Attrs
// and (for feeds without a mapped category) no category, so the category
+4 -1
View File
@@ -15,7 +15,7 @@ import (
"github.com/jackc/pgx/v5/pgxpool"
)
var v1PartialSteps = []string{"category", "title", "description", "attributes"}
var v1PartialSteps = []string{"category", "title", "description", "attributes", "seo_meta"}
const v1MetaDescriptionMaxChars = 155
@@ -791,6 +791,9 @@ func ProjectV1ProcessJobItems(storedType string, items []V1ProcessJobItem) []V1P
}
case "attributes":
projected["attributes"] = item["attributes"]
case "seo_meta":
projected["meta_title"] = item["meta_title"]
projected["meta_description"] = item["meta_description"]
}
}
out = append(out, withAlwaysIncluded(projected, main, more, eprel))