Skip to content

COBOL: a COPY / EXEC SQL INCLUDE after a separator period on the same line is an import (#4303) - #4350

Merged
squid-protocol merged 1 commit into
mainfrom
fix/4303-copy-any-position
Oct 4, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/4303-copy-any-position

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Fixes #4303

What was broken

The COBOL import and _dependency_capture rules anchored COPY at the start of a line (^ + sequence area + blanks). Two shapes were therefore never seen:

  • a COPY after another clause on the same line: 01 WS-REC. COPY CUSTREC.
  • several COPYs on one line: 01 PARENT. COPY A. COPY B. COPY C.

file_data.raw_imports stayed empty and no import edge was drawn, even though record_data.copy_members already listed those members.

The fix

A COPY or a full EXEC SQL INCLUDE now also starts a statement when it follows a separator period on the same line, and each occurrence is its own match. Line-start matching is unchanged.

A bare INCLUDE still counts only at line start, where it is the second line of the two-line EXEC SQL / INCLUDE X form. Elsewhere it would be ambiguous.

I chose the period anchor rather than "COPY anywhere" because the code stream keeps literals. Blanking literals would also blank quoted members (COPY 'CSUTLDWY'). "After a separator period" is the statement boundary IBM's grammar gives for this shape, and it can't fire inside DISPLAY '...'.

Evidence

  • estate-crucible v0.3.0, H-0004 (apps/ACCT/cobol/ACCTRPT.cbl, 01 WS-RPT-HEAD. COPY RPTHDR. / 01 WS-RPT-TOTALS. COPY RPTTOT. COPY RPTCNT.):

    before (main) after
    H-0004 FAIL: missing copies RPTHDR @21, RPTTOT @22, RPTCNT @22; fail layouts WS-RPT-HEAD @21 (+1) PASS (7/7)
    channel copies 29 pass / 4 missing 32 pass / 1 missing
    channel layouts 75 pass / 9 fail 77 pass / 7 fail
    total 805 pass / 23 fail / 33 missing 810 / 21 / 30

    No other horror's verdict changed, and no channel got worse.

  • The issue's REPRO6 now gives raw_imports = [CPYB, CPYC, CPYD] and 3 import hits, which agrees with record_data.copy_members (CPYB, CPYC,CPYD).

  • Tests in tests/extraction/languages/test_cobol.py:

    • valid: a COPY after a level entry, and EXEC SQL INCLUDE after a period;
    • invalid: . INCLUDE-FLAG, and a bare . INCLUDE Y. mid-line;
    • three COPYs on one line yield [A, B, C] from both rules;
    • a ReDoS sweep on a long run of . .

Golden-master diff (both legs regenerated: 88 diffs each)

  • Extracted Dependencies / Module Dependencies (Imports): lsp fixtures TEST.CBL goes from [] to [A, B, C] (line 18). outline.cbl goes from [] to [AST] (line 18).
  • Import Edges: TEST.CBL gains import:hlasm/che4z_hlasm/A.hlasm and …/B.hlasm. C and AST don't resolve.
    • ⚠️ These two edges are wrong, and they come from the resolver, not this change. _narrow_ambiguous only restricts a source-member import to the importer's own language when there are several candidates. A single candidate in another language (A.hlasm) is still taken.
    • The same false edge already exists on main: lsp testing_A.cpy COPY B → B.hlasm.
    • This PR only makes two more COPYs visible to that resolver. Fixing it means applying the language guard to the unique-candidate path too, which is copybook resolution (COBOL engine: copybook resolution in the wild (REPLACING-generated names, search-path order, same-named members) #4265's area), so I left it out of this PR.
  • Follow-on effects of those 2 edges and the 4 new raw imports:
    • A.hlasm / B.hlasm: downstream blast radius +1 and popularity rank.
    • TEST.CBL / outline.cbl: upstream fragility, fingerprint, drift and composition fit.
    • Global: network macro (modularity −0.0005, assortativity, path length) and imports_unknown +4.
    • The undocumented-critical-path list.
  • pytest -m golden_crucible passes in both venvs.

Ground-truth ledger

ground_truth_ledger.py check is clean. tests/cobol_mainframe, tests/extraction and tests/core_engine pass with the pinned corpora (12,922), completeness pins included.

Local checks

mypy_audit --ci, ruff_audit --ci (0.16.0), dead_key_audit --ci: nothing new.

🤖 Generated with Claude Code

… line is an import (#4303)

The `import` and `_dependency_capture` rules anchored COPY at line start,
so `01 WS-REC. COPY CPYB.` and `01 PARENT. COPY A. COPY B. COPY C.` drew
no import and no edge, while record_data already read those members. A
COPY or a full EXEC SQL INCLUDE now also opens a statement after a
separator period, each occurrence its own match; a bare INCLUDE still
counts only at line start (the second line of the two-line EXEC SQL form).

estate-crucible v0.3.0 H-0004: FAIL -> PASS. Golden masters regenerated in
both legs.

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

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol marked this pull request as ready for review October 4, 2026 19:01
@squid-protocol
squid-protocol merged commit 8be548a into main Oct 4, 2026
38 checks passed
@squid-protocol
squid-protocol deleted the fix/4303-copy-any-position branch October 4, 2026 19:01
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: a COPY that does not start its line (01 WS-REC. COPY CUSTREC.) draws no import edge

1 participant