Skip to content

Commit 32eb5d7

Browse files
committed
fix(verify): prefer chipset source year over late SoC placeholder
1 parent 06703a3 commit 32eb5d7

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

‎app/verify/common.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import hashlib
1212
import json
13+
import re
1314
import sys
1415
from collections.abc import Iterable
1516
from pathlib import Path
@@ -30,6 +31,7 @@
3031
)
3132

3233
VERIFY_DIR = DATA_DIR / "_verify"
34+
_RAW_CHIPSET_YEAR = re.compile(r"^[^,]+,\s*((?:19|20)\d{2})\s*,")
3335
LEDGER_PATH = VERIFY_DIR / "ledger.jsonl" # git-tracked: promotion decisions only
3436
STATE_DIR = VERIFY_DIR / "state" # gitignored caches
3537
SCORES_PATH = STATE_DIR / "scores.jsonl" # full Tier 0 results (cheap to recompute)
@@ -95,14 +97,22 @@ def foreign_key_sets(
9597
"""Build FK lookups the way ``app.validate`` does, plus a SoC release-date map.
9698
9799
Returns ``(brand_slugs, soc_slugs, soc_release_date)`` where ``soc_release_date``
98-
maps a SoC slug to its ISO release date (used for "chip can't postdate device").
100+
maps a SoC slug to its best available ISO release date (used for "chip can't
101+
postdate device"). A structured year in ``raw_chipset`` takes precedence
102+
when the normalized January 1 placeholder is later. The raw import often
103+
records the chip's year while the normalized date is several years late.
99104
"""
100105
brand_slugs = {r.slug for r in records.get("brand", []) if r.slug}
101106
soc_slugs = {r.slug for r in records.get("soc", []) if r.slug}
102107
soc_release: dict[str, str] = {}
103108
for r in records.get("soc", []):
104109
rd = r.data.get("release_date")
105110
if r.slug and isinstance(rd, str):
111+
raw = r.data.get("raw_chipset")
112+
if rd.endswith("-01-01") and isinstance(raw, str):
113+
match = _RAW_CHIPSET_YEAR.search(raw)
114+
if match and match.group(1) < rd[:4]:
115+
rd = f"{match.group(1)}-01-01"
106116
soc_release[r.slug] = rd
107117
return brand_slugs, soc_slugs, soc_release
108118

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Use a source chip year when a normalized SoC date is a later placeholder."""
2+
3+
from app.verify import offline
4+
from app.verify.common import Record, foreign_key_sets
5+
6+
7+
def _release_for(release_date: str, raw_chipset: str | None) -> str:
8+
soc = Record("soc", "soc/chip-x.json", {
9+
"slug": "chip-x", "release_date": release_date, "raw_chipset": raw_chipset,
10+
})
11+
return foreign_key_sets({"soc": [soc]})[2]["chip-x"]
12+
13+
14+
def test_earlier_structured_chip_year_corrects_late_placeholder():
15+
assert _release_for(
16+
"2025-01-01", "Qualcomm Snapdragon 680 SM6225, 2021, 64 bit, octa-core"
17+
) == "2021-01-01"
18+
19+
phone = Record("smartphone", "smartphone/phone-x.json", {
20+
"slug": "phone-x", "soc": "chip-x", "release_date": "2022-08-01",
21+
"source_urls": ["https://www.qualcomm.com/products/mobile/snapdragon"],
22+
})
23+
before = offline.score_record(phone, 2026, {"chip-x": "2025-01-01"})
24+
after = offline.score_record(phone, 2026, {"chip-x": "2021-01-01"})
25+
assert "soc_not_after_device" in before.flags
26+
assert "soc_not_after_device" not in after.flags
27+
28+
29+
def test_precise_or_unstructured_dates_keep_the_normalized_date():
30+
assert _release_for("2024-05-07", "Chip X, 2021, 8 cores") == "2024-05-07"
31+
assert _release_for("2025-01-01", "Chip X with 2021 revision") == "2025-01-01"
32+
assert _release_for("2025-01-01", None) == "2025-01-01"
33+
assert _release_for("2025-01-01", "Chip X, 2026, 8 cores") == "2025-01-01"
34+
35+
36+
def test_raw_chip_year_still_flags_a_genuine_era_mismatch():
37+
release = _release_for(
38+
"2024-01-01", "Qualcomm Snapdragon 8s Gen 3 SM8635, 2024, 8 cores"
39+
)
40+
phone = Record("smartphone", "smartphone/phone-x.json", {
41+
"slug": "phone-x", "soc": "chip-x", "release_date": "2015-01-09",
42+
})
43+
score = offline.score_record(phone, 2026, {"chip-x": release})
44+
assert "soc_not_after_device" in score.flags

0 commit comments

Comments
 (0)