The code cited its plan instead of saying why: `E28 review J4`, `(R6 S3b)`, `S1 justified…`,
`deep-review round 5`. That plan lives in the private ops repo, so for every reader of this one the
citation was noise, and a sentence whose subject was the plan step ("round 2 showed…") hid its
lesson behind an id. Each one is gone and the "why" kept: a bare citation is deleted, a sentence
carrying a lesson is reworded around it ("a later attempt showed…").
Measured (`scripts/audit_metrics.py`, product code): 652 lines in 270 files carried an epic code by
the definition the next commit holds (507 / 241 by the old, two-digit-only one) -> 0. Across all
code, tests, scripts and configs: ~1100 epic-code lines plus ~320 sprint/round ids.
Behaviour unchanged, checked mechanically: every changed .py file has the same AST once docstrings
are blanked; css/sh/toml/yml/json files are identical once comments are stripped; the only
non-comment changes in TS/JS are test titles, one description string in a contract table, and five
ESLint messages, whose text is all the gates snapshot diff holds. Not touched: Markdown (docs and
the changelog keep their history), Alembic migrations, TV episode notation (`S2 · E5`), DESIGN.md
ids (`C1`, `B4`, `S3h`), tracker ids (`SEC-16`, `DX-17`).
One stale claim fixed on the way: test_hls_reaper's docstring said the player checkpoints "every
10 s whether or not it is playing", which plex/stream.py calls wrong; it now says what the code does.
75 lines
2.6 KiB
Python
75 lines
2.6 KiB
Python
"""iso(): the single date/datetime→JSON serializer the routes share; to_tsquery_str()."""
|
|
|
|
from datetime import date, datetime, timezone
|
|
|
|
from app.utils import iso, normalize_description, to_tsquery_str
|
|
|
|
|
|
def test_none_maps_to_none():
|
|
assert iso(None) is None
|
|
|
|
|
|
def test_plain_date_serializes_as_iso_date():
|
|
# MediaAsset.upload_date is a `date`, not a datetime — the contract must accept it.
|
|
assert iso(date(2026, 7, 26)) == "2026-07-26"
|
|
|
|
|
|
def test_aware_datetime_keeps_offset():
|
|
dt = datetime(2026, 7, 26, 12, 30, 0, tzinfo=timezone.utc)
|
|
assert iso(dt) == "2026-07-26T12:30:00+00:00"
|
|
|
|
|
|
def test_naive_datetime_serializes_without_offset():
|
|
dt = datetime(2026, 7, 26, 12, 30, 0)
|
|
assert iso(dt) == "2026-07-26T12:30:00"
|
|
|
|
|
|
def test_matches_datetime_isoformat_contract():
|
|
# iso is exactly `dt.isoformat()` for a present value — guards the routes that used to
|
|
# hand-roll `x.isoformat() if x else None`.
|
|
dt = datetime(2020, 1, 2, 3, 4, 5, 678901, tzinfo=timezone.utc)
|
|
assert iso(dt) == dt.isoformat()
|
|
|
|
|
|
def test_normalize_description_none_stays_none():
|
|
assert normalize_description(None) is None
|
|
|
|
|
|
def test_normalize_description_drops_blank_lines():
|
|
# A YouTube contact block padded with runs of blank lines — the waste we strip before storing.
|
|
raw = "Contact us\n\n\nEmail: a@b.com\n \nInstagram: @x\n\n\n"
|
|
assert normalize_description(raw) == "Contact us\nEmail: a@b.com\nInstagram: @x"
|
|
|
|
|
|
def test_normalize_description_right_strips_and_trims():
|
|
assert normalize_description(" hi there \n\n bye ") == " hi there\n bye"
|
|
|
|
|
|
def test_normalize_description_all_blank_collapses_to_empty():
|
|
assert normalize_description("\n \n\t\n") == ""
|
|
|
|
|
|
def test_normalize_description_single_line_unchanged():
|
|
assert normalize_description("just one line") == "just one line"
|
|
|
|
|
|
def test_normalize_description_folds_crlf_line_endings():
|
|
# splitlines() folds CR/CRLF to \n — a documented, benign line-ending normalization.
|
|
assert normalize_description("a\r\nb\r\n\r\nc") == "a\nb\nc"
|
|
|
|
|
|
def test_tsquery_prefix_matches_a_last_word_of_three_or_more():
|
|
assert to_tsquery_str("ti amo magyar") == "ti & amo & magyar:*"
|
|
assert to_tsquery_str("min") == "min:*"
|
|
|
|
|
|
def test_tsquery_matches_a_short_last_word_whole():
|
|
# A 1-2 letter prefix made ts_rank score most of the library (5-8 s on prod).
|
|
assert to_tsquery_str("m") == "m"
|
|
assert to_tsquery_str("minecraft 4k") == "minecraft & 4k"
|
|
assert to_tsquery_str("ti amo m") == "ti & amo & m"
|
|
|
|
|
|
def test_tsquery_without_a_word_is_none():
|
|
assert to_tsquery_str("?! --") is None
|