Repository navigation
Description
Context
A probe for #3810 showed that non-ASCII text silently corrupts GitGalaxy's facts across channels.
- JCL: steps, DD names and EXEC PGM edges are lost; DSNs are truncated.
- CSD: every resource is dropped.
- HLASM: CSECT units are lost.
- COBOL: paragraphs are lost and data items truncated.
An ASCII-transliterated control of the same estate is correct everywhere.
Root causes:
- Decoding. Every source read is
utf-8-sigwitherrors="ignore"(galaxyscope.py:494, plus about 40 othererrors=sites in the tools and recorders). A Latin-1 or cp1252 file loses bytes; a UTF-16 file decodes full of NULs, thenaperture._check_artifact_integritydrops it as binary. - Name patterns. Name captures are ASCII-only classes: about 1,000
[A-Z…]classes across the language standards,mainframe_boundary,detectorand the tools. Keep Unicode and national characters in unit and callee names (#3520) #3522 fixed only PL/I unit names and the CALL verb, using\w.\wstill breaks Indic identifiers: Devanagari and Tamil vowel signs are Mn/Mc and are not\w, and ZWJ/ZWNJ occur inside words. - Case mapping. Upper-casing changes lengths (
ß→SS,fi→FI), which shifts fixed-format columns.
The first pilot customer is Indian, so the target is any script, any encoding.
Intended outcome:
- No read loses or misplaces a character without saying so.
- Names follow each language's real identifier rules (Unicode UAX chore(deps): bump urllib3 from 2.6.3 to 2.7.0 in /gitgalaxy #31 plus that language's extras).
- A metamorphic gauntlet proves it across every language and keeps it proven in CI.
Approach (measure first, then fix, gauntlet as the gate)
1. The Unicode Gauntlet (tests/unicode_gauntlet/, tests/tools/unicode_gauntlet.py)
The oracle is metamorphic: facts(T(seed)) == T(facts(seed)). Take a seed whose facts we trust. Apply a transform T: consistent renaming, injected text, re-encoding, a renamed path. Scan both, then require the transformed scan to equal the seed scan with T applied: same files, LOC, line numbers and signal counts; names and edges mapped. No hand-written expectations per variant.
Seeds:
- (a) keyword-rosetta, all 51 languages. Reuse
tests/tools/rosetta_audit.pyand the corpus'sverify_language.pymanifests (expected_signals.json: counts,expected_function_nodes,calls_out_to); the transformed manifest isT(manifest). - (b) a mainframe channel estate, templated from the National characters (ÆØÅ ÄÖ) and Latin-1 sources: silent losses across JCL, CSD, HLASM, COBOL -- a torture estate in CI #3810 probe: PL/I, COBOL, JCL, CSD, HLASM, copybooks, CICS. It asserts every channel: units, calls and their resolution, datasets/DSN, CSD resources, CICS resources, record items and lineage.
- (c) later: the pinned refraction excerpts, renamed with names taken from their own scan.
Transform dimensions:
- Scripts:
- Latin-1 Western (ÄÖÜß éèç);
- Nordic (ÆØÅ);
- Turkish (İı);
- Greek;
- Cyrillic;
- Devanagari and Tamil (combining marks, ZWJ/ZWNJ);
- Arabic and Hebrew (RTL);
- CJK (Han, Kana), Hangul;
- emoji (outside the BMP);
- NFD-decomposed forms.
- Placements:
- identifiers, only where the language's legality table allows the script (UAX chore(deps): bump urllib3 from 2.6.3 to 2.7.0 in /gitgalaxy #31 for Python / Java / JS / Go / Rust…; national
@#$for PL/I / HLASM / JCL / CSD; ASCII-only languages get no identifier variant); - comments;
- string literals;
- file and directory names (NFC and NFD).
- identifiers, only where the language's legality table allows the script (UAX chore(deps): bump urllib3 from 2.6.3 to 2.7.0 in /gitgalaxy #31 for Python / Java / JS / Go / Rust…; national
- Encodings: UTF-8, UTF-8 with BOM, UTF-16 LE/BE, cp1252 / Latin-1 (for representable scripts), Shift-JIS and GB18030 (CJK), and later EBCDIC code pages.
- Line endings: LF, CRLF, CR.
Output:
- a matrix report (language × script × placement × encoding), with the per-channel diff for each failure;
- a baseline JSON committed as a ratchet, like
refraction_differential/rosetta_audit: known failures are ledgered and new ones fail CI; - a chart.
2. Decoding foundation (gitgalaxy/core/source_text.py)
-
read_source(path, estate_config) -> SourceText(text, encoding, how, lossless):- BOM sniff (UTF-8, UTF-16, UTF-32);
- strict UTF-8;
- a UTF-16 heuristic (NUL pattern);
- a declared estate code page (
--source-encoding, per-glob map); - legacy fallback: cp1252, else Latin-1, which is lossless because every byte maps.
Never
errors="ignore". -
Record the encoding per file: a
file_data.source_encodingcolumn plus the decode method, healed onto older DBs as the channel columns are, and surfaced in the audit / LLM report. -
Route every text read of source through it:
- the engine (
galaxyscope,aperture,guidestar_lens,language_lens); - recorders;
- the refractor and
cobol_to_coboltools; cobol_to_java;- the answer-key reader (
tests/tools/cobol_answer_key.pySource).
The binary check runs after a proper decode, so UTF-16 is no longer "binary".
- the engine (
-
A lint gate (
tests/test_source_reads.py, AST-based): forbiderrors="ignore"|"replace"and rawopen(...).read()/read_text()of source paths ingitgalaxy/, with a reasoned allowlist (e.g. byte-level binary sniffing).
3. Identifier semantics (gitgalaxy/standards/language_standards/identifiers.py)
-
Character classes built once from
unicodedata, with no new dependency (zero-dep mode):ID_START: L*, Nl,_;ID_CONTINUE: ID_START plus Mn, Mc, Nd, Pc, ZWJ/ZWNJ.
Each language composes them with its extras: COBOL
-; mainframe@#$plus letters (Nordic code pages display them as ÆØÅ); PHP bytes 0x80-0xFF; SQL quoted identifiers. -
A per-language legality table drives both the patterns and the gauntlet's identifier transform.
-
Replace ASCII name classes in name captures (not keyword matching) in:
_shared_patterns.py;languages/*.py(the biggest aredb2_sql,pli,hlasm,cobol,jcl);detector._extract_name(move from\wtoID_CONTINUE);mainframe_boundary,file_control,job_flow;- the CSD tokenizer;
- the COBOL record parser and
cobol_graveyard_finder.unit_header.
Keep the ReDoS discipline: bounded classes and the existing prefilter gates (
derive_literal_gate). -
Case mapping: keyword matching uses an ASCII-only fold. Any upper-casing that feeds column arithmetic must be length-preserving (map only ASCII a–z). Audit the
.upper()sites that sit on fixed-format paths.
4. Downstream
cobol_to_java:java_identifier,java_class_baseand there.split(r"[^A-Za-z0-9]+")sites keep Unicode letters (Java-legal), with collision checks;- the build forge declares UTF-8 source encoding;
- the gauntlet estate's generated Java compiles in the java-compile matrix.
- Paths: normalize stored paths to NFC; copybook / include resolution matches across NFC and NFD.
- Equivalence harness: a declared-encoding path for sources and data (it assumes Latin-1 today).
5. Mainframe byte-level (a later phase, own issue)
- Raw EBCDIC downloads (cp037 / cp1047 / cp277 / cp278 / cp930 / cp939), including FB80 record splitting when there are no newlines.
- DBCS in COBOL (
PIC N/G,N"…"/G"…"literals, SO/SI bytes).
Critical files
- New:
gitgalaxy/core/source_text.py;gitgalaxy/standards/language_standards/identifiers.py;tests/tools/unicode_gauntlet.py,tests/unicode_gauntlet/(templates, legality table, baseline);tests/test_source_reads.py.
- Modified:
gitgalaxy/galaxyscope.py:494,gitgalaxy/core/aperture.py:325+,gitgalaxy/core/detector.py(_extract_name);gitgalaxy/standards/language_standards/_shared_patterns.pyandlanguages/*.py;gitgalaxy/core/mainframe_boundary.py,file_control.py,job_flow.py;gitgalaxy/recorders/record_keeper.py(thesource_encodingcolumn);- the about 40
errors=sites ingitgalaxy/tools/**; gitgalaxy/tools/cobol_to_java/cobol_to_java_names.pyandcobol_to_java_common.py;tests/tools/cobol_answer_key.py.
- Reuse:
rosetta_audit.py(seed runner and baseline classify);refraction_differential's baseline-ratchet pattern;galaxy_ir.scan_to_db/load_galaxy_ir(fact comparison);crucible_check.py(golden bless);derive_literal_gate(ReDoS-safe prefilters).
Decisions (from the user)
- Generated Java keeps Unicode identifiers (
BELØP→belØp): the build declares UTF-8 and the gauntlet compiles the output. No transliteration. - Raw EBCDIC and DBCS are a later phase, filed as their own issue right after the Unicode text foundation.
- The gauntlet gates CI from its first PR as a ratchet: today's failures are committed as the baseline, only new failing cells fail, and every fix PR lowers the baseline.
Delivery (an epic, #3810 folded in as a part)
- Gauntlet v1 (seeds a + b, the scripts × placements × UTF-8 / cp1252 / UTF-16 matrix). Report the baseline: expect widespread failures, and ledger them.
- Decoding foundation plus the lint gate.
- Identifier semantics, language family by language family, each PR moving gauntlet cells to pass.
- Downstream (Java, paths, harness).
- EBCDIC / DBCS.
Every PR re-blesses the golden masters as needed (expected: some corpus files gain characters they were losing), passes crucible_check, the rosetta audit and the ground-truth ledger, and ratchets the gauntlet baseline.
Verification
python tests/tools/unicode_gauntlet.py --reportproduces the matrix; CI runs--ciagainst the baseline (fails on any new failing cell).- The National characters (ÆØÅ ÄÖ) and Latin-1 sources: silent losses across JCL, CSD, HLASM, COBOL -- a torture estate in CI #3810 probe estate becomes seed (b): every channel matches its ASCII control in UTF-8, cp1252 and UTF-16.
- Rosetta audit, crucible_check (both legs), the ground-truth ledger, the refraction differential and the mainframe suite stay green. Golden-master diffs are scoped to files that contain non-ASCII text.
- The generated Java for the Nordic / Devanagari seed compiles (java-compile matrix).
Parts (filed below). #3810 is the evidence and is folded in.
🤖 Generated with Claude Code
Activity
#3811: the Unicode Gauntlet side by side with tree-sitter (#3953)
squid-protocol commentedon Sep 28, 2026
Every part is done, and the Unicode Gauntlet is the gate: its baseline is empty, so every language × script × placement × encoding cell passes.
read_sourceladder, declared code pages, a per-file decode record, and a lint gate against lossy reads.Head to head: GitGalaxy vs tree-sitter on the same cells (#3953): 100% vs 45.0% on raw bytes, and 95.1% after decoding.
Follow-up left open: #3954 (Dart is in the legality table by mistake).
🤖 Generated with Claude Code
https://claude.ai/code/session_01TmgE1CwLgaqxqKEgQn5Dw5