feat(scanner): country-aware submission quality scoring (#931)#944
feat(scanner): country-aware submission quality scoring (#931)#944ericsocrat merged 1 commit intomainfrom
Conversation
Signal 3 in _score_submission_quality is now country-aware: - Same-country EAN match: +15 (sets v_existing_pid) - Cross-country EAN match: +5 (no v_existing_pid) - Unknown EAN globally: +0 - NULL country fallback: global check +15/+0 Old 5-param function dropped; new 6-param version has p_suggested_country text DEFAULT NULL for backward compat. score_submission_quality(uuid) and trig_auto_triage_submission() updated to pass suggested_country from submissions. 6 new pgTAP tests (plan 101->107) covering all 4 scoring scenarios + signal name verification.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR makes scanner submission quality scoring (Signal 3: “EAN matches existing product”) country-aware by adjusting scoring and behavior based on whether the EAN exists in the submission’s suggested country versus only other countries, while preserving a NULL-country fallback for backwards compatibility.
Changes:
- Adds a new migration that updates
_score_submission_qualityto apply country-aware Signal 3 scoring (+15 same-country, +5 cross-country, +0 unknown; NULL-country fallback uses global match). - Updates
score_submission_quality(uuid)andtrig_auto_triage_submission()to passsuggested_countryinto the scoring helper. - Extends pgTAP coverage with 6 new tests for the country-aware Signal 3 scenarios and updates the plan count.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| supabase/migrations/20260321000600_country_aware_quality_scoring.sql | Updates the scoring helper + wrapper + trigger to incorporate suggested_country and adjust Signal 3 behavior. |
| supabase/tests/scanner_functions.test.sql | Adds pgTAP assertions for same-country vs cross-country vs unknown EAN and NULL-country fallback behavior. |
| -- Fallback: no country specified, global check (original behavior) | ||
| SELECT product_id INTO v_existing_pid | ||
| FROM products | ||
| WHERE ean = p_ean AND is_deprecated IS NOT TRUE; | ||
|
|
||
| IF v_existing_pid IS NOT NULL THEN | ||
| v_score := v_score + 15; | ||
| v_signals := v_signals || jsonb_build_array( | ||
| jsonb_build_object('signal', 'ean_exists', 'impact', 15, | ||
| 'detail', format('Matches product_id %s', v_existing_pid)) | ||
| ); | ||
| END IF; |
| -- Check cross-country (EAN exists in another country) | ||
| IF EXISTS ( | ||
| SELECT 1 FROM products | ||
| WHERE ean = p_ean AND is_deprecated IS NOT TRUE | ||
| ) THEN | ||
| v_score := v_score + 5; | ||
| v_signals := v_signals || jsonb_build_array( | ||
| jsonb_build_object('signal', 'ean_exists_other_country', 'impact', 5, | ||
| 'detail', format('EAN exists in another country but not in %s', p_suggested_country)) | ||
| ); | ||
| -- Do NOT set v_existing_pid — product doesn't exist in target country | ||
| END IF; |
| -- 6. NULL country fallback → global match → +15 (score 65) | ||
| SELECT is( | ||
| ((_score_submission_quality( | ||
| '00000000-0000-0000-0000-000000000099'::uuid, | ||
| '5901234123457', NULL, NULL, NULL, NULL | ||
| ))->>'quality_score')::int, | ||
| 65, | ||
| '_score_submission_quality: NULL country fallback gives +15 for existing EAN (#931)' | ||
| ); |
| -- 1. Same-country EAN match → +15 (score 65) | ||
| SELECT is( | ||
| ((_score_submission_quality( | ||
| '00000000-0000-0000-0000-000000000099'::uuid, | ||
| '5901234123457', NULL, NULL, NULL, 'XX' | ||
| ))->>'quality_score')::int, | ||
| 65, | ||
| '_score_submission_quality: same-country EAN match gives +15 (#931)' | ||
| ); |
Summary
Closes #931 — Makes Signal 3 (EAN match) in
_score_submission_qualitycountry-aware.Signal 3 Scoring Changes
ean_exists_same_countryean_exists_other_countryean_existsKey Design Decisions
v_existing_pid— preventsauto_resolve_existingaction from firing when the product only exists in another countryDEFAULT NULL) get global match at +15Migration
20260321000600_country_aware_quality_scoring.sql:DROP FUNCTION IF EXISTS _score_submission_quality(uuid, text, text, text, text)— removes old overloadCREATE OR REPLACE FUNCTION _score_submission_quality(uuid, text, text, text, text, text)— 6-param with country-aware Signal 3score_submission_quality(uuid)— updated to passv_sub.suggested_countrytrig_auto_triage_submission()— updated to passNEW.suggested_countryTests
6 new pgTAP tests (plan 101 → 107) in
scanner_functions.test.sql:ean_exists_same_countryean_exists_other_countrySide effect: Pre-existing test 54 now PASSES (score reduced from 80 → 65, correctly returns
manual_reviewinstead ofauto_resolve_existing).Verification
File Impact
2 files changed, +366 / -1 lines