Files
datatools-dev/test-cases/encodings-corpus/expected_detection.csv
Michael 82d7fef21e feat(gate): CSV-normalization gate with confidence-tiered findings
Adds a Review & Normalize page that sits between upload and every tool
page. The analyzer now tags each finding with confidence (high/medium/low)
and a fix_action; the gate auto-applies high-confidence fixes, surfaces
medium/low ones for user review, and blocks tool pages on error-level
findings until resolved or waived.

Core (src/core/):
  - analyze.py: Finding gains confidence, fix_action, pre_applied; new
    detectors for encoding_uncertain, encoding_decode_failed; new top-
    level encoding_override parameter.
  - fixes.py: registry of fix algorithms keyed by fix_action id.
  - normalize.py: auto_fix(), apply_decisions(), is_normalized(), and
    the NormalizationResult / Decision dataclasses the gate consumes.
  - io.py: detect_encoding tries strict UTF-8 first; repair_bytes now
    transcodes UTF-16/32 to UTF-8 before NUL-strip (fixes UTF-16 corruption)
    and normalizes line endings (fixes bare-CR parser crash); empty file
    handled gracefully instead of EmptyDataError traceback.

GUI (src/gui/):
  - pages/0_Review.py: gate page with per-finding decision controls,
    encoding override picker (16 codepages + custom), and Advanced output
    options (encoding, delimiter, line terminator) on the download.
  - components.py: require_normalization_gate() helper.
  - pages/1-9: gate guard wired on every tool page.

Test corpora:
  - test-cases/encodings-corpus/: 31 encoded CSV fixtures + 9 reference
    UTF-8 files + manifest, synced from Business/DataTools.
  - test-cases/text-cleaner-corpus/test_data/17: synced malformed input
    (unquoted $1,500.00) for the unquoted-delimiter detector.

Tests (94 new):
  - test_normalize.py (48): finding fields, fix registry, auto_fix scope,
    decision paths, gate idempotency, output-options helper.
  - test_encodings_corpus.py (90, 16 xfailed): parametric detection +
    decode + analyzer-no-crash sweep against the manifest.
  - test_analyze.py: encoding override + encoding_uncertain detectors.
  - test_corpus.py: pre-parse repair in the strict reader.

run_tests.py: new aliases --tool normalize, --tool encodings, --tool gate;
encodings corpus added to --fixtures category.

Docs: USER-GUIDE §3.3 covers the gate workflow, encoding override, and
output options; TECHNICAL §10.2.1-10.2.4 documents the analyzer schema,
gate API, Review page, and pre-parse repair pipeline; CLI-REFERENCE adds
the analyzer JSON schema with the new fields; README links to all of it.

Suite: 765 passed, 17 xfailed (was 458 passed).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 20:35:27 +00:00

6.3 KiB

1filenamecanonical_content_idencodinghas_bombyte_lengthexpected_detectiondecode_notes
2E01_western_basic_utf8.csvWESTERN_BASICutf-8no161utf_8|utf-8UTF-8 no BOM. Modern default.
3E02_western_basic_utf8bom.csvWESTERN_BASICutf-8yes164utf_8|utf_8_sig|utf-8|utf-8-sigUTF-8 with BOM. Excel CSV UTF-8 export. BOM must be stripped on read.
4E03_western_basic_cp1252.csvWESTERN_BASICcp1252no153cp1252|windows-1252|iso-8859-1|latin-1Western single-byte. For this content (no euro, no smart quotes, no em-dash), cp1252 and Latin-1 produce IDENTICAL decoded bytes. Detector cannot distinguish - any of cp1252/Latin-1/Latin-9 is a correct answer.
5E04_western_basic_latin1.csvWESTERN_BASICiso-8859-1no153iso-8859-1|latin-1|cp1252|latin_1Latin-1. Identical bytes to cp1252 for this content. Detector ambiguity is expected and acceptable.
6E05_western_basic_latin9.csvWESTERN_BASICiso-8859-15no153iso-8859-15|latin-9|iso-8859-1|cp1252Latin-9. For this content with no euro sign, decodes identically to Latin-1. Detector may pick any.
7E06_western_basic_macroman.csvWESTERN_BASICmac-romanno153mac-roman|macromanMac Roman. Different byte values for the accented chars vs cp1252/Latin-1, so this one is distinguishable.
8E07_western_basic_utf16le.csvWESTERN_BASICutf-16-leyes308utf-16|utf-16-le|utf_16|utf_16_leUTF-16 LE with BOM. Excel 'Unicode Text' export.
9E08_western_basic_utf16be.csvWESTERN_BASICutf-16-beyes308utf-16|utf-16-be|utf_16|utf_16_beUTF-16 BE with BOM. Less common but valid.
10E09_western_basic_utf16le_nobom.csvWESTERN_BASICutf-16-leno306utf-16|utf-16-le|UNRELIABLEUTF-16 LE without BOM. Detection is heuristic and unreliable; bytes look like 'every other byte is null' for ASCII-heavy content, which charset-normalizer may or may not catch. If detector returns wrong encoding here, that is the buyer's responsibility to manually specify - flag in error message.
11E10_western_extended_utf8.csvWESTERN_EXTENDEDutf-8no167utf_8|utf-8UTF-8. Has euro, smart quotes, em-dash.
12E11_western_extended_cp1252.csvWESTERN_EXTENDEDcp1252no154cp1252|windows-1252cp1252. Content uses 0x80-0x9F range (euro, smart quotes, em-dash). Decoding as Latin-1 produces control characters or replacement chars - this file is the cleanest cp1252-vs-Latin-1 discriminator.
13E12_western_extended_utf16le.csvWESTERN_EXTENDEDutf-16-leyes310utf-16|utf-16-leUTF-16 LE with BOM. Same content as E10/E11.
14E13_eastern_european_utf8.csvEASTERN_EUROPEANutf-8no130utf_8|utf-8UTF-8 baseline for Czech/Polish/Hungarian/Slovak content.
15E14_eastern_european_cp1250.csvEASTERN_EUROPEANcp1250no120cp1250|windows-1250cp1250. Decoding as cp1252 produces mojibake (Polish slash-l would become U+0142 vs ascii letter, etc.). Real distinguishing test.
16E15_eastern_european_iso88592.csvEASTERN_EUROPEANiso-8859-2no120iso-8859-2|latin-2|iso8859_2ISO-8859-2 / Latin-2. Different byte assignments than cp1250 for the same characters.
17E16_cyrillic_utf8.csvCYRILLICutf-8no118utf_8|utf-8UTF-8 baseline for Russian content.
18E17_cyrillic_cp1251.csvCYRILLICcp1251no72cp1251|windows-1251cp1251. The dominant Russian Windows encoding.
19E18_cyrillic_koi8r.csvCYRILLICkoi8-rno72koi8-r|koi8_rKOI8-R. Older Unix Russian encoding. Distinct byte patterns from cp1251.
20E19_japanese_utf8.csvJAPANESEutf-8no78utf_8|utf-8UTF-8 baseline for Japanese content.
21E20_japanese_shiftjis.csvJAPANESEshift_jisno64shift_jis|shift-jis|cp932|sjisShift_JIS. Excel on Japanese Windows defaults to this. cp932 is Microsoft's extended variant; either name is acceptable.
22E21_chinese_simplified_utf8.csvCHINESE_SIMPLIFIEDutf-8no66utf_8|utf-8UTF-8 baseline for simplified Chinese.
23E22_chinese_simplified_gb18030.csvCHINESE_SIMPLIFIEDgb18030no56gb18030|gbk|gb2312GB18030. Mainland China default. GB18030 supersets GBK supersets GB2312; for this content any is acceptable.
24E23_chinese_traditional_utf8.csvCHINESE_TRADITIONALutf-8no66utf_8|utf-8UTF-8 baseline for traditional Chinese.
25E24_chinese_traditional_big5.csvCHINESE_TRADITIONALbig5no56big5|big5_hkscs|cp950Big5. Taiwan and Hong Kong default. cp950 is Microsoft's variant.
26E25_korean_utf8.csvKOREANutf-8no72utf_8|utf-8UTF-8 baseline for Korean.
27E26_korean_euckr.csvKOREANeuc-krno60euc-kr|euc_kr|cp949EUC-KR. Korean Windows default. cp949 is the MS variant.
28E27_pathological_ascii_only.csvASCII_ONLYasciino66ascii|utf_8|utf-8|cp1252|iso-8859-1|AMBIGUOUSPure ASCII. Multiple encodings produce identical bytes for this content. Any of ASCII, UTF-8, cp1252, Latin-1 is a correct detection answer because all four decode to the same string. Detector confidence should be high; specific label is interchangeable.
29E28_pathological_invalid_utf8.csvINVALID_UTF8invalid-utf8no67cp1252|iso-8859-1|REJECT_UTF8File starts as if UTF-8 but contains an invalid byte sequence (0xC3 0x28). A strict UTF-8 decoder errors. Detector should reject UTF-8 and fall back to a single-byte encoding; cp1252 will produce mojibake but parse without error. Cleaner should warn the user that encoding detection was uncertain.
30E29_pathological_truncated_utf8.csvTRUNCATED_UTF8invalid-utf8-truncatedno47utf_8_with_errors|cp1252|REJECTValid UTF-8 throughout, but the last byte (0xE4) starts a 3-byte sequence that's never completed. Strict UTF-8 decoder errors at EOF. errors='replace' produces \ufffd. Real-world cause: file was truncated by a transfer interruption or a buggy export. Cleaner should treat as corrupt-input error, not silent data loss.
31E30_pathological_lying_bom.csvWESTERN_EXTENDEDcp1252-with-utf8-bomyes (lying)157utf_8_FAILS|cp1252|AMBIGUOUSFile has UTF-8 BOM but body is cp1252. UTF-8 decoder will see 0x80 (euro in cp1252) as an invalid UTF-8 continuation byte and error out. Better detectors recover by ignoring the BOM and trying cp1252. Cleaner should warn 'BOM suggested UTF-8 but content decoded as cp1252' so the user knows their file is lying about itself.
32E31_pathological_mixed_concat.csvMIXED_CONCATcp1252+utf8-concatenatedno60LOW_CONFIDENCE|cp1252|utf_8|REJECTFirst half cp1252, second half UTF-8. No single encoding decodes both halves correctly. UTF-8 decoder errors on row 1. cp1252 decoder produces mojibake on rows 2-3. charset-normalizer detection confidence should be low. Right behavior for the cleaner: refuse to process and tell the user the file contains mixed encodings.