Skip to content

fix(shopping): normalize chatgpt-shopping cards — pickParser gains a ChatGPT branch - #408

Merged
gkhngyk merged 1 commit into
mainfrom
fix/chatgpt-shopping-card-parser
Jul 12, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/chatgpt-shopping-card-parser

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

ChatGPT Shopping results were being captured (prompt_results.shopping_cards fills up correctly) but never normalized into prompt_result_shopping_cards: pickParser in server/src/lib/shopping-cards.js had no branch for chatgpt-shopping, so normalizeShoppingCards always returned [] and the Shopping dashboard only ever showed Copilot cards.

Changes

  • parseChatgptCard — normalizes the { products, tags } wrapper products. The shape was derived from real captured production payloads, not guessed: title, url (+ offers[0].url fallback), formatted price strings, image_urls[0], merchants string, rating / num_reviews, provider-flat position.
    • raw intentionally keeps a compact subset: a single ChatGPT product runs to tens of KB (variants, price_history, specs, analytics metadata), and the full original is already persisted on prompt_results.shopping_cards — which is exactly what the backfill script re-derives from, so nothing is lost.
  • pickParser matches chatgpt-shopping exactly — plain chatgpt-web answers never carry cards, and the existing "unsupported platform → []" test for it stays green.
  • parsePrice separator fix (shared by all parsers): "₺2.699,99" previously parsed as 2.699 — the thousands dot was read as a decimal point. The string branch now disambiguates: when both separators appear the last one is the decimal; a lone separator is decimal only with 1-2 trailing digits. Covers US (1,299.99), EU/TR (2.699,99) and multi-group (1.234.567) conventions.
  • 13 new tests (wrapper flattening, field mapping, offer fallbacks, price separator matrix) — 112/112 passing. Also smoke-tested end to end against real captured payloads: correct amount/currency (TRY), merchant domain extraction, and matchCardBrand competitor matching.

Backfill

No changes needed — the script is platform-agnostic and picks up the new parser. After merge, run once to rebuild history from the already-captured raw cards:

cd server && node src/scripts/backfill-shopping-cards.js

Fixes #399

Type of change

  • fix — Bug fix
  • feat — New feature
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npm test — 112 passing (13 new in shopping-cards.test.js).
  2. With a shopping-mode brand, wait for (or trigger) a tracking run: new chatgpt-shopping results now produce rows in prompt_result_shopping_cards with platform = 'chatgpt-shopping'.
  3. Run the backfill; /dashboard/shopping should now show ChatGPT alongside Copilot in the platform filters, with own/competitor matching populated.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • npm run lint passes (run from server/)
  • npm run format:check passes (run from server/)
  • npm test passes (run from server/)
  • Changes are focused — one concern per PR

…ChatGPT branch

ChatGPT Shopping results were captured into prompt_results.shopping_cards
but never reached prompt_result_shopping_cards: pickParser had no branch
for the platform, so normalizeShoppingCards always returned []. The
dashboard therefore only ever showed Copilot cards (#399).

- parseChatgptCard: normalizes the { products, tags } wrapper products
  (shape derived from captured production payloads) — title, offer/url
  merchant fallbacks, image_urls[0], rating/num_reviews. raw keeps a
  compact subset: a single ChatGPT product runs to tens of KB and the
  full original stays on prompt_results.shopping_cards (which is what
  the backfill script re-derives from).
- pickParser matches 'chatgpt-shopping' exactly — plain chatgpt-web
  never carries cards and keeps its unsupported-platform behavior.
- parsePrice: disambiguate thousand/decimal separators. "₺2.699,99"
  previously parsed as 2.699; now 2699.99 (US/EU/TR conventions all
  covered, shared by every parser).
- 13 new tests (wrapper flatten, field mapping, offer fallbacks, price
  separator matrix); verified against real captured payloads end to end.

Backfill needs no changes — it is platform-agnostic and picks up the new
parser: node src/scripts/backfill-shopping-cards.js

Fixes #399
@gkhngyk
gkhngyk merged commit b990cca into main Jul 12, 2026
5 checks passed
@gkhngyk gkhngyk mentioned this pull request Jul 12, 2026
7 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(shopping): chatgpt-shopping cards are captured but never normalized — pickParser has no ChatGPT branch

1 participant