Skip to content

COBOL engine: COPY ... REPLACING in record_layout (record_data.copy_replacing) -- fixes #4265, stacked on #4405 - #4407

Merged
squid-protocol merged 10 commits into
mainfrom
feat/4265-copy-replacing
Oct 5, 2026
Merged

squid-protocol merged 10 commits into
mainfrom
feat/4265-copy-replacing

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Stacked on #4405 (feat/4265-copy-libraries). Both PRs add record_data columns side by side, and this branch reads copy_libraries alongside the new column. Merge #4405 first, and this diff then reduces to the REPLACING change. Until then, the estate numbers below include H-0034 from #4405. Owner-approved design 2 of 2 for #4265 (estate-crucible horror H-0016).

What was broken

Take 01 WS-EMP. COPY PAYTPL REPLACING ==:TAG:== BY ==EMP==. over a template copybook (05 :TAG:-ID PIC X(6). ...). The engine's record_layout gave bytes: None, with the first field WS-EMP at 0 bytes. The key expects EMP-ID / EMP-NAME / EMP-RATE, 40 bytes. There were two causes:

  • the extractor did not recognise 05 :TAG:-ID as an entry at all (the level regex needs a plain data-name), so the template had no records;
  • nothing carried the REPLACING operands to the reader.

Fix (design: a new record_data column, not attributes)

  • Extractor (mainframe_boundary.py):
    • An entry name may carry a pseudo-text tag (:TAG:-ID), kept as written.
    • Each COPY's REPLACING phrase is parsed into operand pairs: ==pseudo-text== (stored without its ==), a word or a literal, and LEADING / TRAILING.
  • New column record_data.copy_replacing (TEXT, JSON): a list parallel to copy_members, one element per COPY, either null or [[from, to(, LEADING|TRAILING)], ...]. The column is NULL when no COPY on the entry replaces anything, so existing rows keep their shape. It is documented in recorders/README.md and core/README.md. It is written by record_keeper, restored by state_rehydrator, and read by galaxy_ir.load_galaxy_ir, all guarded with _has_column for older DBs.
    • Every record_data reader was checked. The others either select named columns (test_record_data, estate_crucible, engine_sourcing via GalaxyIR) or render items (audit_recorder), and none needs the column. No schema-contract test enumerates the record_data columns.
  • Reader (galaxy_ir):
    • A COBOL copybook (not a program) whose entries carry a tag is a template. Its tree is kept in EngineFile.template_records, and its data_items / records stay empty, because the tagged entries are not data-names until replaced.
    • record_layout expands COPY X REPLACING ... from the replaced copy, in one left-to-right pass as the compiler does (the first matching pair wins, and replaced text is not matched again). A :tag: / (tag) operand replaces partial words, LEADING / TRAILING replace word starts or ends, and any other operand replaces whole words only. The replacement covers the name, REDEFINES, OCCURS DEPENDING ON, PIC and VALUE.
    • The section-level COPY pass keeps copy_replacing parallel to the members it keeps.
  • Still out of scope, and now stated explicitly: the data-flow reader does not resolve a procedure operand that only a REPLACING produces (MOVE ... TO EMP-ID) to its copied entry. That operand stays an unresolved operand gap, and the comment in core/data_moves.py says so.

Before -> after

  • H-0016: FAIL -> PASS. WS-EMP is 40 bytes: EMP-ID 6, EMP-NAME 30, EMP-RATE 4.
  • tests/cobol_mainframe/test_copy_replacing_4265.py (7 tests) covers:
    • the operands kept per COPY, with a plain COPY keeping its old shape;
    • the template keeping its tagged names;
    • the operand forms, whole-word vs partial matching, and the single pass;
    • the layout applying REPLACING, with two tags on one template and LEADING;
    • template entries not being data-names;
    • nearest negatives: the same copybook copied without REPLACING keeps its own names and stays data_items, and a program with tagged entries (awaiting its own REPLACE statement) is not a template.

Every golden change, explained. Only the tagged-entry recognition moves anything, in both legs identically:

  • record_layout: 32 new rows across three corpus files whose entries carry pseudo-text tags, which were previously not recognised as entries:
    • zopeneditor-sample/CUSTCOPY.cpy (IBM's :TAG: template; it now carries facts for the first time);
    • cobol-check/REPLAC.CBL (3 01 :PROGRAM:-PARAM-style entries awaiting its REPLACE statement);
    • che4z lsp testing_DIAGNOS.CPY (2 entries). Its 01 A also no longer takes its child's PIC x: the 05 :baaaaa: pic x line was invisible before, so its PIC was attributed to A.
  • llm_brief: coverage counts follow, 755 -> 756 files and 33039 -> 33071 record items (+32).
  • An earlier bless also moved data flows (+5 unresolved operands): the template rule cleared REPLAC.CBL's data_items. That bless is not committed. A program is now never a template, so data flows are unchanged.

scope_check --expect cobol reports 3 cobol differences, plus 1 unattributed: the LLM brief's repo-wide coverage line above.

Golden masters (vs 575bba16a63e)

full-precision (tests/golden_master_audit): 2 fixture file(s), 2 channel(s), 3 scanned file(s) moved (cobol 3).

channel files changed +added -removed leaves sample
10. Mainframe System Facts / Record Layout 2 1 0 449 cobol/che-che4z_lsp_project_fixtures/testing_DIAGNOS.CPY, cobol/cobol-check/src_main_cobol_REPLAC.CBL, cobol/zopeneditor-sample/CUSTCOPY.cpy
12. Scan Output Snapshots / LLM Brief 0 0 0 2

Most-moved scanned files (channels): cobol/cobol-check/src_main_cobol_REPLAC.CBL (1), cobol/che-che4z_lsp_project_fixtures/testing_DIAGNOS.CPY (1), cobol/zopeneditor-sample/CUSTCOPY.cpy (1)

zero-dependency (tests/golden_master_zero_dep_audit): 2 fixture file(s), 2 channel(s), 3 scanned file(s) moved (cobol 3).

channel files changed +added -removed leaves sample
10. Mainframe System Facts / Record Layout 2 1 0 449 cobol/che-che4z_lsp_project_fixtures/testing_DIAGNOS.CPY, cobol/cobol-check/src_main_cobol_REPLAC.CBL, cobol/zopeneditor-sample/CUSTCOPY.cpy
12. Scan Output Snapshots / LLM Brief 0 0 0 2

Most-moved scanned files (channels): cobol/cobol-check/src_main_cobol_REPLAC.CBL (1), cobol/che-che4z_lsp_project_fixtures/testing_DIAGNOS.CPY (1), cobol/zopeneditor-sample/CUSTCOPY.cpy (1)

Ground-truth ledger

Ground-truth ledger: no change.

Estate-crucible horrors

Estate-crucible (575bba16a63e -> 0b0f5f77e84c+dirty): horrors passing 45/49 -> 47/49; checks pass 916->923, fail 10->3, phantom 5->3.

horror issue before after title
H-0016 #3414 FAIL (1 not passing) PASS COPY forms: REPLACING ==pseudo-text==, a quoted text-name, IN library
H-0034 #4265 FAIL (1 not passing) PASS Same-named copybook in two libraries: SYSLIB order picks the app's own
channel before (pass/fail/missing/phantom) after
copies 33/3/0/2 36/0/0/0
layouts 83/4/0/0 87/0/0/0

Fixes #4265

🤖 Generated with Claude Code

https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo

squid-protocol and others added 9 commits October 4, 2026 20:27
…Ys; docs + negative tests

record_layout applies a COPY's REPLACING operands in one left-to-right pass (first matching pair
wins, replaced text is not re-matched); the section-level pass keeps copy_replacing parallel to the
copy_members it keeps and reads a template copybook's own levels. record_data.copy_libraries /
copy_replacing documented in recorders/README.md; data_moves notes what is still unresolved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo
…ource-read gate

The declaration is the scan's own configuration (like --config), not a file of the estate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo
A COBOL program whose entries carry a pseudo-text tag (cobol-check REPLAC.CBL, awaiting its own REPLACE
statement) keeps its data_items; only a copybook is a template. Goldens: record_layout gains the tagged
entries of CUSTCOPY.cpy, REPLAC.CBL and DIAGNOS.CPY (32 rows) and DIAGNOS's 01 A no longer takes its
child's PIC; the LLM brief's coverage counts follow (+1 file, +32 record items).

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

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

Conflicts in 5 files resolved to this branch's side: after #4405 was
squash-merged, main's copies of those files are byte-identical to the
libraries commit this branch is built on, so every hunk is only this
branch's REPLACING additions. #4406 (data_moves.py) merged cleanly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@squid-protocol
squid-protocol marked this pull request as ready for review October 5, 2026 05:06
@squid-protocol
squid-protocol merged commit 10d5ab6 into main Oct 5, 2026
38 checks passed
@squid-protocol
squid-protocol deleted the feat/4265-copy-replacing branch October 5, 2026 05:07
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.

COBOL engine: copybook resolution in the wild (REPLACING-generated names, search-path order, same-named members)

1 participant