test_ingest_one_doc_file_skips_non_utf8

Tests › tests/test_build_docs_db.py

passed Passed in the packaged run.

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

  1. db_path = tmp_path / "clew.db"
  2. conn = sqlite3.connect(str(db_path))
3 more
  1. conn.execute("CREATE VIRTUAL TABLE supplementary_docs USING fts5(file_path, heading, content)")
  2. bad = tmp_path / "iot_error_definition.md"
  3. bad.write_bytes(b"# Title\n\xb4\x8f\xbf\xed bytes that are not utf-8\n")
→

When

  1. result = _ingest_one_doc_file(conn, bad, "iot_error_definition.md")
  2. rows = conn.execute("SELECT COUNT(*) FROM supplementary_docs").fetchone()
→

Then

  1. ✓ result equals 0
  2. ✓ rows[0] equals 0

tests/test_build_docs_db.py:380 · its file's page

What it checks (2)

  1. assert result == 0, "non-UTF-8 file must be skipped, not ingested" observes _ingest_one_doc_file via result
  2. assert rows[0] == 0 not 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_file

What 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.

test_ingest_one_doc_file_skips_non_utf8 · 2 checks_ingest_one_doc_filememoizedREQ-DDB-INDEX-002 · measured

Requirements it verifies (2)

requirementlinked byimplementers exercised
REQ-DDB-PIPE-001catalogunknown
REQ-DDB-PIPE-010catalogunknown
Also reaches 1 requirement

Its run touches their code; that is reach, not proof.