Skip to content

Behavioural equivalence harness + CardDemo INTCALC vertical slice (#3624) - #3748

Merged
squid-protocol merged 4 commits into
mainfrom
feat/equivalence-3624
Sep 26, 2026
Merged

squid-protocol merged 4 commits into
mainfrom
feat/equivalence-3624

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #3624, the last item of epic #3625.

Result

CardDemo CBACT04C (job INTCALC, the interest calculator), run as COBOL under GnuCOBOL and as the generated Java on the same inputs:

Java side ACCTFILE (rewritten KSDS) TRANSACT (written) total
generated only (stub) 4 / 50 0 / 50 4 / 100
generator + the hand port 50 / 50 50 / 50 100 / 100

Every field matches, decimals exact. That includes S9(09)V99's extremes and the truncation edges: ±999,999,999.99, ±0.01, and a rate's cent boundary.

It found a defect in the original. CBACT04C never adds the last account's interest to its balance. PERFORM UNTIL END-OF-FILE = 'Y' tests the flag before each pass, so the loop's EOF branch (ELSE PERFORM 1050-UPDATE-ACCOUNT) is unreachable. A first port that followed the evident intent scored 49/50 on ACCTFILE. The port now keeps the original behaviour and documents it at the spot; the one-line fix is a business decision.

The harness (tests/tools/equivalence.py, equivalence_java.py)

python tests/tools/equivalence.py run carddemo-intcalc [--keep DIR] [--generated-only]
  • COBOL side: GnuCOBOL 3.1 with BDB indexed files, in tests/equivalence/gnucobol.Dockerfile, compiled -std=ibm -fsign=EBCDIC.
    • Each KSDS is loaded by a generated loader keyed like the program's SELECT, alternate keys included.
    • A generated driver passes the JCL PARM through LINKAGE, and COB_CURRENT_DATE pins the clock.
    • Outputs, and every KSDS the program opens I-O, are unloaded to fixed-length records.
  • Java side: the generated project (config h2) with the case's port/ overlaid, run by a generated JUnit test:
    • each input is loaded through its entity's record codec into H2;
    • runBatch(dds, parm) runs with the pinned clock;
    • outputs are dumped through the same codecs.
  • Diff: each record is laid out by the answer key's own copybook reader. Numeric DISPLAY / COMP-3 / COMP fields are compared as exact decimals, text byte for byte. Results go to report.json and report.md.
  • A case is a case.json: the program, datasets with keys and copybooks, PARM, clock and notes. CardDemo ships every category balance as zero, so this case replaces them with varied ones on the same keys (documented in the case).

Generator additions

  • Record codecs. Every VSAM entity gets fromRecord(byte[], Charset) / toRecord(Charset), field by field at the COBOL offsets, over a shared CobolRecords runtime:

    • supported storage: DISPLAY text, zoned decimal with an overpunched sign, COMP-3 and COMP;
    • stores follow MOVE: decimals are truncated, high-order digits lost, unsigned fields keep the magnitude;
    • anything it can't encode (OCCURS, COMP-1/2, PL/I) gets no codec, with the reason stated.

    This is also how REPRO-unloaded VSAM data migrates into the new database.

  • Step PARM. job_flow STEP rows record the text EXEC PARM= passes: new job_flow_data.parm, rehydrated, EngineJobFlow.parm, and job_steps parm. runBatch is now runBatch(List<Dd> dds, String parm), and each generated step passes its PARM (CBACT04C needs PARM-DATE).

Verification

  • Blast radius: ir_join_diff --rescan changes only job_steps (the parm key). The ledger is clean and the golden masters are unchanged.
  • Compile: all 6 corpora × 17 configs.
  • Suite and gates: full suite and preflight pass.
  • Tests: test_equivalence.py pins the decoder, the diff, the generated loader / driver / JUnit run, the codec kinds and expressions, and PARM parsing. The end-to-end run is opt-in (EQUIVALENCE_E2E=1, which needs Docker and a JDK).

Next

Publishing: a script regenerates the cobol_to_java_examples repo from the verified corpora, with this slice's report and a COBOL-vs-Java GitGalaxy scan comparison. That goes out as a PR to that repo.

🤖 Generated with Claude Code

https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g

)

The harness (tests/tools/equivalence.py + equivalence_java.py) runs a COBOL
program and the generated Java on the same recorded inputs, and diffs their
outputs record by record, field by field, decimals exact.

COBOL side: GnuCOBOL 3.1 (BDB indexed files) in a container
(tests/equivalence/gnucobol.Dockerfile), -std=ibm -fsign=EBCDIC.
- Each KSDS is loaded by a generated loader keyed like the program's SELECT,
  alternate keys included.
- A generated driver passes the JCL PARM through LINKAGE, and
  COB_CURRENT_DATE pins the clock.
- Each output (and each KSDS opened I-O) is unloaded.

Java side: the generated project (target config h2), with the case's port
overlaid, run by a generated JUnit test:
- load each input through the entity's record codec into H2;
- run the step's runBatch(dds, parm) with the clock pinned;
- dump the outputs through the same codecs.

The diff lays each record out with the answer key's copybook reader.
`--generated-only` runs the stub as generated: the generator's own baseline.

Generator additions the harness needs:
- Record codecs: every VSAM entity gets fromRecord(byte[], Charset) /
  toRecord(Charset), field by field at the COBOL offsets, over a shared
  CobolRecords runtime (DISPLAY text, zoned decimal with its sign
  overpunched, COMP-3, COMP; stores follow MOVE: truncation, high-order
  loss). An entity it can't encode (OCCURS, COMP-1/2, PL/I) gets none, with
  the reason. This is also how REPRO-unloaded VSAM data migrates into the
  new database.
- The step's PARM: job_flow STEP rows record the text EXEC PARM= passes (new
  job_flow_data.parm, rehydrated, EngineJobFlow.parm, job_steps "parm"), and
  runBatch is now runBatch(List<Dd> dds, String parm), each generated step
  passing its PARM.

The vertical slice, CardDemo CBACT04C (job INTCALC, the interest
calculator), is ported by hand onto the generated skeleton
(tests/equivalence/carddemo-intcalc/port):
- 100/100 records equal (ACCTFILE 50/50, TRANSACT 50/50), including
  S9(09)V99's extremes and truncation edges;
- the generated stub scores 4/100.

The case's category balances are CardDemo's keys with non-zero balances
(the corpus ships zeros).

The harness found a defect in the original: CBACT04C never adds the last
account's interest to its balance. PERFORM UNTIL tests END-OF-FILE before
each pass, so the EOF branch that updates the last account is unreachable.
The port keeps the behaviour, documented at the spot; the one-line fix is a
business decision.

Verification:
- ir_join_diff --rescan: only job_steps (the parm key).
- Ledger clean; golden masters unchanged.
- All 6 corpora compile on all 17 configs.
- Full suite passes; preflight passes.
- tests/cobol_mainframe/test_equivalence.py pins the harness's pure parts;
  the end-to-end run is opt-in (EQUIVALENCE_E2E=1: Docker + JDK).

Closes #3624

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g
Comment thread tests/tools/equivalence.py Fixed
Comment thread tests/tools/equivalence.py Fixed
Comment thread tests/tools/equivalence_java.py Fixed
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…sh_examples.py (#3624)

CodeQL notes on #3748:
- equivalence_java imported CASES back from equivalence (an import cycle);
  it now locates tests/equivalence itself, and a test pins that the two
  agree;
- equivalence.py imported os without using it.

New tests/tools/publish_examples.py regenerates the cobol_to_java_examples
repository from the six pinned, answer-keyed corpora:
- per example: the generated project (no build output, run timestamps
  blanked), PROVENANCE.md (source commit and licence, generator commit,
  commands) and scan_comparison.md (the source estate and the Java, scanned
  by the same engine);
- the equivalence cases' reports (ported and as generated), their ports and
  how to reproduce;
- a README whose numbers come from the generated trees;
- a compile workflow, with actions pinned by SHA.

A refresh is a pull request on that repository.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g
Comment thread tests/tools/publish_examples.py Fixed
squid-protocol and others added 2 commits September 26, 2026 11:19
The generated examples, the equivalence port and its data are derived from
third-party corpora (Apache-2.0, EPL-2.0, MIT), so publish_examples now:
- copies each source's own LICENSE* / NOTICE* / COPYING* files beside
  what is derived from it (mainframe_corpus.excerpt's rule);
- opens every generated Java file with a notice naming the source, its
  commit and licence, and that it was modified in generation (cobol-to-java
  --header; java_target_matrix.generate gains a `header`);
- writes THIRD_PARTY_NOTICES.md (each directory's source and licence) and a
  trademark note; LICENSE (plain Apache-2.0) covers only the repository's own
  files.

The equivalence case in this repository gets CardDemo's LICENSE and NOTICE,
and its port opens with a notice. tests/equivalence/APACHE-2.0.txt is the
plain licence text the examples repository's LICENSE uses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g
@squid-protocol
squid-protocol merged commit 0c2e001 into main Sep 26, 2026
36 checks passed
@squid-protocol
squid-protocol deleted the feat/equivalence-3624 branch September 26, 2026 15:38
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.

Java conversion: behavioural equivalence harness + CardDemo vertical slice

2 participants