Skip to content

feat(scanner): country-aware submission quality scoring (#931)#944

Merged
ericsocrat merged 1 commit intomainfrom
feat/931-country-aware-quality-scoring
Mar 17, 2026
Merged

feat(scanner): country-aware submission quality scoring (#931)#944
ericsocrat merged 1 commit intomainfrom
feat/931-country-aware-quality-scoring

Conversation

@ericsocrat
Copy link
Copy Markdown
Owner

Summary

Closes #931 — Makes Signal 3 (EAN match) in _score_submission_quality country-aware.

Signal 3 Scoring Changes

Scenario Old Score New Score Signal Name
Same-country EAN match +30 +15 ean_exists_same_country
Cross-country EAN match +30 +5 ean_exists_other_country
Unknown EAN globally +0 +0 (none)
NULL country fallback +30 +15 ean_exists

Key Design Decisions

  • Cross-country matches do NOT set v_existing_pid — prevents auto_resolve_existing action from firing when the product only exists in another country
  • NULL fallback preserves global behavior — 5-arg callers (backward compat via DEFAULT NULL) get global match at +15
  • Old 5-param function explicitly dropped — ensures all calls route through the new 6-param version

Migration

20260321000600_country_aware_quality_scoring.sql:

  1. DROP FUNCTION IF EXISTS _score_submission_quality(uuid, text, text, text, text) — removes old overload
  2. CREATE OR REPLACE FUNCTION _score_submission_quality(uuid, text, text, text, text, text) — 6-param with country-aware Signal 3
  3. score_submission_quality(uuid) — updated to pass v_sub.suggested_country
  4. trig_auto_triage_submission() — updated to pass NEW.suggested_country

Tests

6 new pgTAP tests (plan 101 → 107) in scanner_functions.test.sql:

  • Same-country EAN match: score = 65, signal = ean_exists_same_country
  • Cross-country EAN match: score = 55, signal = ean_exists_other_country
  • Unknown EAN globally: score = 50
  • NULL country fallback: score = 65

Side effect: Pre-existing test 54 now PASSES (score reduced from 80 → 65, correctly returns manual_review instead of auto_resolve_existing).

Verification

supabase db reset    → migration applies cleanly
supabase test db     → 6/6 new tests pass (107 total)
                       pre-existing failures unchanged (tests 53,55-56 shifted values, still failing)

File Impact

2 files changed, +366 / -1 lines

  • 1 new DB migration (293 lines)
  • 1 modified pgTAP test file (+73 lines, 6 new tests)

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.
Copilot AI review requested due to automatic review settings March 17, 2026 17:16
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
tryvit Ready Ready Preview, Comment Mar 17, 2026 5:18pm

@ericsocrat ericsocrat merged commit 6af20bd into main Mar 17, 2026
16 of 17 checks passed
@ericsocrat ericsocrat deleted the feat/931-country-aware-quality-scoring branch March 17, 2026 17:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_quality to 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) and trig_auto_triage_submission() to pass suggested_country into 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.

Comment on lines +119 to +130
-- 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;
Comment on lines +105 to +116
-- 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;
Comment on lines +909 to +917
-- 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)'
);
Comment on lines +861 to +869
-- 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)'
);
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.

feat(scanner): country-aware submission quality scoring

2 participants