Skip to content

Fix #3986: compare alphanumerics as the mainframe does (CobolCompare) - #4036

Merged
squid-protocol merged 3 commits into
mainfrom
fix/3986-ebcdic-collation
Sep 30, 2026
Merged

squid-protocol merged 3 commits into
mainfrom
fix/3986-ebcdic-collation

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

Resolves #3986. Follow-up: #4035.

Problem

EBCDIC sorts lower case before upper case and letters before digits (a 0x81 < A 0xC1 < 0 0xF0). Java's String.compareTo sorts digits first, so a ported IF CUST-ID > 'A' takes the opposite branch for '1001'. COBOL also pads the shorter operand with spaces ('AB' = 'AB '), which String.equals denies.

The generator never translates COBOL conditions (the AI porter writes that logic from the port ticket), so the fix is a runtime class for the porter to call, plus a rule that requires it.

Changes

  • util/CobolCompare, generated into every project (cobol_to_java_compare_forge.py, written by the controller). It is not tied to VSAM stores the way CobolRecords is.
    • compare, eq, gt, ge, lt, le compare the bytes in the data.code_page (IBM037 by default), with the shorter operand padded with that code page's space.
    • highValues(n) / lowValues(n) give HIGH-VALUES and LOW-VALUES.
    • A null counts as all spaces. A character the code page can't encode throws, rather than being silently replaced with ?.
  • A porting rule in every ticket: alphanumeric relation conditions (IF / EVALUATE / PERFORM UNTIL / SEARCH WHEN) go only through CobolCompare, never compareTo or equals. Numeric comparisons stay BigDecimal.compareTo. A program that declares PROGRAM COLLATING SEQUENCE has to be flagged with a TODO.
  • collation_rules: when culture.key_collation isn't ebcdic, the ticket says that repository browses and CobolCompare can order keys differently, and that such spots should be flagged rather than "fixed". CobolCompare itself always follows the code page, as the program did.
  • port_runner: the agent is shown util/CobolCompare.java along with the other runtime classes.

Snapshot bless

refraction_snapshot.py update (the excerpts) and update --corpus <each> (the 6 full pinned corpora): each generated project gains util/CobolCompare.java and its guardrail-baseline entry, so the audit reads "+1 file, +1 class". Nothing else moved.

dead_key_audit.py: allowlist key_collation. Like decimal_point (#3984), it's a Culture dataclass field that target_as_dict writes with vars(), which the dead-key walker can't trace.

Verification

  • test_cobol_compare.py: the Java test compiles and runs CobolCompare on 8 cases where EBCDIC order differs from Java's, plus padding, null, HIGH-/LOW-VALUES and an unencodable character. It skips without javac; I ran it locally with JDK 21's compiler module.
  • tests/cobol_mainframe + tests/cics_crucible: all pass after the bless. Before the bless, the only 6 failures were the snapshot diffs above.
  • Ruff, mypy and dead-key audits show nothing new, and the touched files are ruff format clean.
  • No parsing logic is touched, so no crucible run was needed.

Not in this PR (#4035)

This PR makes the correct comparison available and requires it. It doesn't yet check that the porter used it. #4035 covers that:

  • a per-program fact table of alphanumeric relation conditions, including level-88 THRU ranges;
  • a guardrail collation violation for compareTo / equals on String fields;
  • equivalence inputs placed on the EBCDIC/ASCII boundary, so a wrong port fails the proof.

🤖 Generated with Claude Code

squid-protocol and others added 2 commits September 30, 2026 09:37
EBCDIC orders lower case before upper and letters before digits; Java's
String.compareTo orders digits first, so a ported `IF CUST-ID > 'A'` took the
other branch for '1001'. COBOL also pads the shorter operand with spaces
('AB' = 'AB  '), which String.equals denies.

- util/CobolCompare, generated into every project: compare / eq / gt / ge /
  lt / le by the data.code_page bytes, the shorter operand space-padded;
  highValues(n) / lowValues(n); a null is spaces, an unencodable character
  throws.
- A porting rule in every ticket: alphanumeric relation conditions only
  through CobolCompare, numeric ones through BigDecimal.compareTo, and a
  PROGRAM COLLATING SEQUENCE flagged in a TODO.
- A ticket rule when culture.key_collation is not ebcdic: browses and
  CobolCompare can then order keys differently.
- The port runner shows the agent CobolCompare with the other runtimes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…st key_collation

Every excerpt's generated project gains util/CobolCompare.java and its
guardrail baseline entry (+1 file, +1 class); nothing else moved.
key_collation, like decimal_point, is a Culture dataclass field that
target_as_dict writes with vars(), which the dead-key walker cannot trace.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

The six pinned corpora's generated projects gain util/CobolCompare.java and
its guardrail baseline entry (+1 file, +1 class); nothing else moved.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@squid-protocol
squid-protocol merged commit e183990 into main Sep 30, 2026
38 checks passed
@squid-protocol
squid-protocol deleted the fix/3986-ebcdic-collation branch September 30, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Globe: EBCDIC Collation Inverts ASCII/Java Business Logic (1 vs A)

1 participant