Repository navigation
Description
Summary
The intent-extraction logic is copy-pasted between the volumes route and the manual smoke script, and the two copies have already drifted apart — so the script no longer tests what production actually does.
Three definitions are duplicated:
intentKeywordSchemaINTENT_SYSTEM_PROMPTAI_VOLUME_MULTIPLIER
in both server/src/routes/volumes.js and server/src/test-volumes.js.
The drift
routes/volumes.js (production) |
test-volumes.js (smoke) |
|
|---|---|---|
| Prompt | "5 short HEAD keywords, 1–3 words (strict)", with worked examples and a "strip modifiers" rule | "5 keyword phrases, 2–5 words each", no examples |
Schema intent enum |
9 values (includes other) |
7 values |
| keyword field | described as a Google head term with measurable volume | undescribed |
Production deliberately asks for short head terms (because Google Ads returns 0 volume for long-tail strings); the smoke script still asks for 2–5 word phrases. The script tests a prompt/schema that production no longer uses.
Duplication inside the route, too
The same generateObject({ model, schema: intentKeywordSchema, system: INTENT_SYSTEM_PROMPT, prompt: ... }) call appears twice in volumes.js — at volumes.js:201 and volumes.js:321 — with identical arguments.
Suggested fix
Extract a single source of truth, e.g. server/src/lib/intent-extraction.js, exporting:
intentKeywordSchemaINTENT_SYSTEM_PROMPTAI_VOLUME_MULTIPLIER- a small helper, e.g.
extractIntentKeywords(promptText, model), that wraps the sharedgenerateObjectcall and returns{ intent, keywords }.
Then:
routes/volumes.jsimports from the module and both call sites (lines 201, 321) collapse to oneawait extractIntentKeywords(...).- If the smoke script survives (see chore(server): move or remove the manual smoke scripts under src/ #240), it imports the same module instead of carrying its own copy — drift becomes impossible.
Relationship to #240
This overlaps with #240 (move/remove the manual smoke scripts):
- If
test-volumes.jsis deleted there, the cross-file duplication disappears and this issue narrows to the in-route dedup (lines 201/321) plus the lib extraction. - If it is moved and kept, this extraction is what lets it import the canonical definitions instead of a drifted copy.
Either way, the production-side extraction stands on its own and is worth doing.
Type
refactor — no behavior change to the volumes endpoint; production keeps its current (head-term) prompt and schema.
Activity
refactor(server): consolidate intent-extraction logic into a single m…