test_ingest_one_doc_file_skips_non_utf8¶
Tests › tests/test_build_docs_db.py
What this test is for
Why it exists
Regression for 2026-05-14 mojibake bug: a GBK-encoded markdown file (iot_error_definition.md) was previously ingested via `read_text(errors="replace")`, substituting every invalid byte with U+FFFD. The garbage flowed to the model via `docs.search_prose` and caused hallucinated citations. The fix is strict UTF-8 decode; non-UTF-8 files are skipped + logged.
Verifies REQ-DDB-PIPE-001 REQ-DDB-PIPE-010
Given
db_path = tmp_path / "clew.db"conn = sqlite3.connect(str(db_path))
3 more
conn.execute("CREATE VIRTUAL TABLE supplementary_docs USING fts5(file_path, heading, content)")bad = tmp_path / "iot_error_definition.md"bad.write_bytes(b"# Title\n\xb4\x8f\xbf\xed bytes that are not utf-8\n")
When
result = _ingest_one_doc_file(conn, bad, "iot_error_definition.md")rows = conn.execute("SELECT COUNT(*) FROM supplementary_docs").fetchone()
Then
- ✓ result equals 0
- ✓ rows[0] equals 0
tests/test_build_docs_db.py:380 · its file's page
What it checks (2)
assert result == 0, "non-UTF-8 file must be skipped, not ingested"observes_ingest_one_doc_fileviaresultassert rows[0] == 0not attributed
Where the product reaches it
No product flow reaches this code: no product entry point's flow calls any of the functions this test calls.
Call flow
test_ingest_one_doc_file_skips_non_utf8→_ingest_one_doc_fileWhat it reaches
Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.
Requirements it verifies (2)
| requirement | linked by | implementers exercised |
|---|---|---|
| REQ-DDB-PIPE-001 | catalog | unknown |
| REQ-DDB-PIPE-010 | catalog | unknown |
Also reaches 1 requirement
Its run touches their code; that is reach, not proof.
- REQ-DDB-INDEX-002 measured