Skip to content

Commit fefb92a

Browse files
test(copy): fail the build when the site claims something it does not do
Every phrase in this list was found by reading the live site, was false, and had to be corrected - "every score is a percentile rank", "the single best free video for every step", "release cadence", "a syllabus that updates itself", "real-time", "AI-powered". They were found one at a time over a week. This finds them all at once, and finds the next one. It scans the TypeScript a visitor's copy lives in, with code comments stripped so a comment explaining why a claim was removed can still quote it. Each pattern carries the reason it is wrong. Its first run found four the manual sweep had missed - three "Hand-picked" tiles in the plan UI and one more "best free video each step" - which is the case for having it. It also produced two false positives, which shaped the patterns: LearningResources' keyless-fallback banner really is hand-picked, and /compare lists what the page shows (it does display sentiment) rather than what the score is built from. Both patterns now target the claim, not the word. Guards against scanning nothing (>50 files), and the comment stripper is tested against a URL so "https://" is not eaten. 206 pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 52c84e7 commit fefb92a

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

‎backend/tests/test_copy_claims.py‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""Claims the product must not make, checked against the copy a visitor reads.
2+
3+
Every phrase here was found by hand on the live site, said something the code
4+
does not do, and had to be corrected. Finding them by reading is how the same
5+
mistake got made four times in a week; a test finds it the fifth time.
6+
7+
Only the text a visitor sees is scanned: code comments are stripped, because a
8+
comment explaining why a claim was removed has to be free to quote it.
9+
"""
10+
11+
import re
12+
from pathlib import Path
13+
14+
import pytest
15+
16+
REPO = Path(__file__).resolve().parents[2]
17+
FRONTEND = REPO / "frontend" / "src"
18+
19+
# (pattern, why it is wrong). Patterns are case-insensitive regexes.
20+
FORBIDDEN = [
21+
(r"score is a percentile", "scores are absolute; _percentile_rank is unused and test_scoring pins it"),
22+
(r"against each other", "a tool's score does not depend on other tools"),
23+
(r"louder than the others", "same: the score is absolute, not relative"),
24+
(r"single best free video", "only some roadmap steps have a tracked tool, so not every step has a video"),
25+
(r"best free video for every", "20 of 35 steps have a video"),
26+
# Only the keyless FALLBACK list is hand-picked (LearningResources says so
27+
# truthfully), so this targets the marketing form of the claim.
28+
(r"hand-picked(,| and) checked", "videos are ranked by the YouTube API, then verified"),
29+
(r"best free video each", "only steps with a tracked tool have a video"),
30+
(r"release cadence", "only the latest release tag is fetched; nothing measures cadence"),
31+
(r"updates itself", "roadmaps are static seed data"),
32+
(r"real-time", "the pipeline is a 30-minute loop"),
33+
(r"ai-powered", "scoring is arithmetic; the LLM only classifies sentiment"),
34+
(r"strong demand", "an employment claim needs a measurement behind it"),
35+
(r"high demand in the job market", "the momentum score knows nothing about hiring"),
36+
(r"career investment", "an unmeasured employment claim"),
37+
# /compare lists what the page SHOWS (it does display sentiment); this
38+
# targets the claim that sentiment is what the score is built from.
39+
(r"(based on|built from|scored from|computed from)[^.\"`]{0,90}sentiment", "sentiment is displayed but is not a score input"),
40+
]
41+
42+
_BLOCK_COMMENT = re.compile(r"/\*.*?\*/", re.DOTALL)
43+
_LINE_COMMENT = re.compile(r"(?<![:\"'])//[^\n]*")
44+
45+
46+
def visitor_text(path: Path) -> str:
47+
"""Source with comments removed - roughly what a reader could ever see."""
48+
source = path.read_text(encoding="utf-8", errors="replace")
49+
return _LINE_COMMENT.sub("", _BLOCK_COMMENT.sub("", source))
50+
51+
52+
def copy_files():
53+
files = [p for ext in ("*.ts", "*.tsx") for p in FRONTEND.rglob(ext)]
54+
return sorted(files)
55+
56+
57+
def test_the_scan_actually_finds_files():
58+
# A guard that scans nothing passes forever.
59+
assert len(copy_files()) > 50
60+
61+
62+
@pytest.mark.parametrize("pattern, why", FORBIDDEN, ids=[f[0] for f in FORBIDDEN])
63+
def test_no_forbidden_claim_in_frontend_copy(pattern, why):
64+
hits = []
65+
for path in copy_files():
66+
for match in re.finditer(pattern, visitor_text(path), re.IGNORECASE):
67+
hits.append(f"{path.relative_to(FRONTEND)}: ...{match.group(0)}...")
68+
assert not hits, f"{why}\n" + "\n".join(hits)
69+
70+
71+
def test_the_stripper_removes_comments_but_not_urls():
72+
sample = 'const a = "https://x.dev/a"; // real-time in a comment\n/* real-time too */ const b = "ok";'
73+
stripped = _LINE_COMMENT.sub("", _BLOCK_COMMENT.sub("", sample))
74+
assert "real-time" not in stripped
75+
assert "https://x.dev/a" in stripped

0 commit comments

Comments
 (0)