Skip to content

COBOL engine: COPY library resolution (--copy-libraries: SYSLIB order, IN/OF library, collisions) -- part of #4265 - #4405

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

squid-protocol merged 4 commits into
mainfrom
feat/4265-copy-libraries

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #4265 (estate-crucible horror H-0034). Owner-approved design 1 of 2; the REPLACING half stacks on this branch in its own PR.

What was broken

Member lookup for COPY x was by bare name / file stem, with no notion of copy libraries. On estate-crucible, COPY DATEWS in the ACCT and CUST programs resolved to PAYR's DATEWS.cpy, which belongs to another application's library, and not to the shared copylib in their SYSLIB. COPY DATEWS IN SHRCPY in PAYMAIN resolved to PAYR's copy too, because the library-name was ignored. That made the layout 18 bytes instead of 16, and 6 further layout checks that use WS-SHARED-DATE failed with it. Same-named members in different libraries were never reported. The first match won silently.

Fix

A new scan option, galaxyscope --copy-libraries FILE (JSON, or YAML with PyYAML; gitgalaxy/core/copy_libraries.py), declares the library concatenation:

{"libraries": {"PAYRCPY": ["apps/PAYR/copybook"], "SHRCPY": ["shared/copylib"]},
 "syslib": [{"programs": "apps/PAYR/*", "order": ["PAYRCPY", "PAYRDCL", "SHRCPY"]},
            {"programs": "*", "order": ["SHRCPY"]}]}
  • libraries maps a library-name to the scan-relative directories that hold its members. syslib gives the search order per program glob, and the first matching entry wins.
  • An unqualified COPY X resolves to the first library in the program's order that holds X (SYSLIB semantics). COPY X IN|OF LIB searches LIB only. A named library that lacks the member gets no edge, as the compiler would fail too.
  • Collisions: a member found in more than one library of a program's search order is logged and listed under copy_member_collisions in the scan summary (importer, member, chosen library and path, shadowed libraries and paths). The first library still wins, as on z/OS.
  • Anything the declaration does not cover falls back to the existing resolver: a program no glob matches, an unknown library-name, or a member in none of the libraries (SQLCA, DFHAID). Without the option, behaviour is exactly as before. Golden masters and the ledger are unchanged, and scope_check --expect cobol reports 0 differences against origin/main.
  • Persistence, so readers and delta scans see the same thing. These are new nullable columns, each NULL unless a COPY names a library or a declaration was given:
    • file_data.import_libraries: member -> the library-names its COPY statements name.
    • edge_data.copy_libraries: the COPY forms an import edge carries.
    • record_data.copy_libraries: per entry, parallel to copy_members.
  • The state rehydrator restores these columns. GalaxyIR (_copybook_file / _copy_roots) expands COPY X and COPY X IN LIB from the member each one actually resolved to.
  • tests/tools/estate_crucible.py writes the estate's declaration from its manifest (<APP>CPY copybook/, <APP>DCL dclgen/, SHRCPY shared/copylib; a program's SYSLIB is its app's libraries, then SHRCPY) and passes --copy-libraries, the same way it passes --source-encoding.

Before -> after

  • H-0034: FAIL -> PASS. The estate's copies channel goes from 33/3/0/2 to 36/0/0/0 (pass/fail/missing/phantom), and layouts go from 83/4 to 86/1.
  • tests/cobol_mainframe/test_copy_libraries_4265.py (7 tests) covers:
    • the extractor recording each COPY's library;
    • SYSLIB order and IN library each picking their own member;
    • the edge recording the COPY forms that reached it;
    • no declaration -> nothing changes (the negative);
    • a member in several libraries being reported as a collision;
    • a named library that lacks the member drawing no edge;
    • a malformed declaration being rejected before the scan.

Golden masters (vs 575bba16a63e)

full-precision (tests/golden_master_audit): unchanged.

zero-dependency (tests/golden_master_zero_dep_audit): unchanged.

Ground-truth ledger

Ground-truth ledger: no change.

Estate-crucible horrors

Estate-crucible (575bba16a63e -> ea8512c9df3a): horrors passing 45/49 -> 46/49; checks pass 916->922, fail 10->4, phantom 5->3.

horror issue before after title
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 86/1/0/0

Part of #4265

🤖 Generated with Claude Code

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

…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
@squid-protocol
squid-protocol marked this pull request as ready for review October 5, 2026 04:04
@squid-protocol
squid-protocol merged commit 50153d8 into main Oct 5, 2026
44 checks passed
@squid-protocol
squid-protocol deleted the feat/4265-copy-libraries branch October 5, 2026 04:04
squid-protocol added a commit that referenced this pull request Oct 5, 2026
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 added a commit that referenced this pull request Oct 5, 2026
…eplacing) -- fixes #4265, stacked on #4405 (#4407)

* WIP #4265: COPY library resolution (--copy-libraries, IN/OF library, collisions)

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

* WIP #4265: COPY ... REPLACING in record_layout (record_data.copy_replacing, template copybooks)

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

* #4265: REPLACING single-pass, kept parallel through section-level COPYs; 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

* #4265: allowlist the --copy-libraries declaration read in the #3813 source-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

* #4265: a program is never a REPLACING template; bless goldens

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant