Skip to content

Forge: copybook resolver reads every copy shape (#3414); schema reader reads whole entries (#3348) - #3437

Merged
squid-protocol merged 2 commits into
mainfrom
fix/forge-copybooks-records-3414-3348
Sep 24, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
fix/forge-copybooks-records-3414-3348

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #3414. Refs #3348: this fixes the forge's own record reader. Switching the refractor onto EngineFile.records is #3348's larger scope and is left for that issue.

Together with #3436, this leaves the forge exact against the fully censused answer keys on every field the ledger scores. The ledger keeps only two causes, both deliberate.

#3414: COPY_PATTERN reads every copy shape (cobol_graveyard_finder)

Hand-verified misses, now all resolved (34 → 0):

  • Period on a later line, including after a sequence field: CardDemo COPY 'CSSTRPFY' / ., COPY CSUTLDPY / ., 206400 COPY 'CSSTRPFY' / 206500 ..
  • REPLACING spanning lines: CSSETATY ×39 in COACTUPC.
  • COPY … IN|OF <library>: zopeneditor SAM1LIB.
  • EXEC SQL INCLUDE, one line or split: CBSA's DB2 members, CardDemo's CSDB2R*.
  • .dcl DCLGEN members as copybooks.

The pattern now uses named groups plus copy_member(). resolve_copybooks and the answer-key scorer's forge view both use them, and the scorer's view now trims cols 73–80 exactly as resolve_copybooks does.

#3348: cobol_schema_forge reads whole data entries

The new data_entries() works per data description entry (a sentence), not per line. Record fields go from 3,468 to 3,853 of 3,853: exact on zopeneditor, CBSA and CardDemo, with no false fields. Shapes the line reader lost:

  • Edited pictures: 01 ACTUAL-BALANCE-DISPLAY PIC +9(10).99. The PIC class lacked + , $ / * Z B.
  • PIC after REDEFINES / OCCURS: ACCOUNT-KY2-BYTES REDEFINES ACCOUNT-KY2 PIC X(16).
  • PIC on the next line: DBCRFUN 07 WS-CUSTOMER-RANGE-BOTTOM / PIC ….
  • Sequence-numbered lines and zopeneditor's R2 change markers; a line holding only its sequence number no longer swallows the next entry.
  • Literals are blanked first, so a period inside a VALUE literal can't end an entry.

Latent type bug fixed in passing: the old PIC capture included the entry's terminating period, so PIC 9(4). read as 9(4). and every numeric item ending a line was typed DECIMAL(n, 0). It's now typed as an integer (SMALLINT / INTEGER / BIGINT), and the generated Java fields follow.

Ground truth

Refraction snapshots (re-blessed: excerpts plus full zopeneditor, CBSA and CardDemo)

I read the check diff first. What moved:

  • Added columns, DTO/entity fields and IR entries for the recovered fields. Every removed column line is re-added in the same file; they're trailing-comma moves.

  • Integer types for PIC 9(n)., as above.

  • Two entity renames, which follow the forge's existing "table named after the last 01 group" rule:

    • Cbact01cWsReissueDate → Cbact01cWsAcctReissueDate: WS-REISSUE-DATE … REDEFINES … PIC X(10) is elementary, and the old reader mistook it for a group;
    • zopeneditor …RptStatsDetail → …RptStatsCustDetail: the real last group sits on R2 lines the old reader skipped.

    That naming rule predates this PR and is crude; it's worth revisiting under Refractor: consume fact channels (datasets, records, calls) from EngineFile instead of forge re-parsing #3348.

Test plan

  • 8 COPY_PATTERN shape cases plus a .dcl resolution test; a whole-entry schema test covering 7 shapes (edited PIC, REDEFINES, next-line PIC, sequence field, R2, sequence-only line, literal with a period)
  • test_tool_regex_redos: the new patterns are linear
  • pytest tests/: 11,097 passed; ground_truth_ledger.py check clean
  • ruff / mypy audits clean

Merge note: #3436 also touches ground_truth_ledger.json and cobol_graveyard_finder.py, in different regions. Whichever merges second needs ground_truth_ledger.py update after merging main.

🤖 Generated with Claude Code

https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g

…r reads whole entries (#3348)

cobol_graveyard_finder (#3414): COPY_PATTERN now matches
- COPY with its period on a later line, including after a sequence field
  (CardDemo `COPY 'CSSTRPFY'` / `    .`, `COPY CSUTLDPY` / `    .`);
- REPLACING spanning lines (CSSETATY);
- COPY ... IN|OF <library> (zopeneditor SAM1LIB);
- EXEC SQL INCLUDE, on one line or split (CBSA's DB2 members, CardDemo's
  CSDB2R*).
`.dcl` DCLGEN members are copybooks. Named groups plus copy_member();
resolve_copybooks and the answer-key scorer's forge view both use them.
The scorer's view now trims cols 73-80 as resolve_copybooks does.

cobol_schema_forge (#3348): data_entries() reads per data description
ENTRY, not per line. So a PIC on the next line, a PIC after REDEFINES or
OCCURS, and edited pictures (`+9(10).99`, `ZZZ,ZZ9`) are seen. The cols 1-6
sequence area and zopeneditor's `R2` markers are blanked, sequence-only
lines no longer swallow the next entry, and literals are blanked. It also
fixes a latent type bug: the PIC used to include the entry's terminating
period, so every `PIC 9(n).` was typed DECIMAL(n, 0) instead of an integer.

Ground-truth ledger: -419 forge entries (385 record fields -> 3,853/3,853
exact on all three corpora; 34 copybook paths -> exact). +32 deliberate
`forge_units_include_copied_paragraphs`: the forge reads the compiled
program, so a procedure-division copybook's paragraphs are units of the
program that copies them, which dead-code analysis needs; the key lists
source-file paragraphs.
Refraction snapshots re-blessed: added schema columns, DTO/entity fields
and IR entries for the recovered fields; integer types for PIC 9(n).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ZsVaAkb86P5r5JXDC2Y9g
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…ecords-3414-3348

# Conflicts:
#	tests/cobol_mainframe/ground_truth_ledger.json
#	tests/cobol_mainframe/refraction_snapshot/full/aws-mainframe-modernization-carddemo/clean/04_ir_state_dumps/COACTUPC_ir.json.snap
#	tests/cobol_mainframe/refraction_snapshot/full/aws-mainframe-modernization-carddemo/clean/04_ir_state_dumps/COTRTLIC_ir.json.snap
#	tests/cobol_mainframe/refraction_snapshot/full/aws-mainframe-modernization-carddemo/clean/04_ir_state_dumps/COTRTUPC_ir.json.snap
#	tests/cobol_mainframe/refraction_snapshot/full/aws-mainframe-modernization-carddemo/java/java_migration_audit.txt.snap
#	tests/cobol_mainframe/test_cobol_graveyard_finder.py
@squid-protocol
squid-protocol merged commit 20b9502 into main Sep 24, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the fix/forge-copybooks-records-3414-3348 branch September 24, 2026 01:42
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.

Forge copybook fallback: follow EXEC SQL INCLUDE and COPY … IN <library>

1 participant