Repository navigation
fix(cobol): read the paragraphs of a procedure copybook - #5425
pavansystems wants to merge 3 commits into
Conversation
|
Thanks for the pull request, @pavansystems. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify review 
1 possible issue to check · Medium impact
Headerless COBOL copybooks are now treated as procedure code when a paragraph is followed by a recognized statement.
1 possible issue we couldn't confirm
- A quoted 'EXEC SQL' or 'EXEC CICS' text in a line can make the scan skip the rest of the program ·
graphify/extractors/cobol.py:300
They don't change the score.
Code graph · 44 functions depend on this change
- 625 of 625 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed 33a8af3 · 1 earlier finding not re-checked
| _PERFORM_MODIFIERS = frozenset({ | ||
| "UNTIL", "VARYING", "TIMES", "WITH", "TEST", "FOREVER", | ||
| }) | ||
| # A line that begins with a statement verb. Only procedure code has these; a |
There was a problem hiding this comment.
Paragraphs with unsupported statements stay classified as data
A headerless procedure copybook containing a SORT statement is not recognized as procedure code, so its paragraphs and PERFORM links are omitted.
Broaden _procedure_copybook_start to recognize valid statements such as SORT.
Evidence · checked against the code
Expected: The extractor identifies the copybook as procedure code and extracts its paragraphs and PERFORM links.
Actually: The helper returns None; the extractor stays in data mode and skips procedure parsing.
- Independent source review: The data-copybook test confirms that a lone paragraph-shaped line should not trigger procedure mode, and the existing procedure-copybook test exercises recognized verbs such as
IFandDISPLAY. Neither provides a guard for a validSORTstatement or covers the claimed omission.
Prompt to fix with AI
In graphify/extractors/cobol.py, _procedure_copybook_start (lines 36-39):
Problem: Paragraphs with unsupported statements stay classified as data
Expected: The extractor identifies the copybook as procedure code and extracts its paragraphs and `PERFORM` links.
Actually: The helper returns `None`; the extractor stays in data mode and skips procedure parsing.
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
| # A line that begins with a statement verb. Only procedure code has these; a | ||
| # data description begins with a level number. | ||
| _STATEMENT = re.compile( | ||
| r"^(?:ACCEPT|ADD|CALL|CLOSE|COMPUTE|CONTINUE|DISPLAY|DIVIDE|EVALUATE|EXIT" |
There was a problem hiding this comment.
Some valid procedure copybooks are still treated as data
A headerless copybook whose paragraph contains only an unlisted statement, such as NEXT SENTENCE, is not recognized as procedure code, so its paragraph is lost.
Broaden _procedure_copybook_start to recognize valid statements such as NEXT SENTENCE.
Evidence · checked against the code
Expected: The extractor recognizes the file as procedure code and emits the paragraph.
Actually: The detector returns None; the extractor leaves procedure mode off and skips paragraph extraction.
- Independent source review: The existing headerless-copybook test uses
IF, which is recognized by_STATEMENT, and verifies paragraph extraction for that case; it does not cover or mitigateNEXT SENTENCE. The data-copybook test checks a separate input shape and does not prevent the stated omission.
Prompt to fix with AI
In graphify/extractors/cobol.py, _procedure_copybook_start (lines 39-42):
Problem: Some valid procedure copybooks are still treated as data
Expected: The extractor recognizes the file as procedure code and emits the paragraph.
Actually: The detector returns `None`; the extractor leaves procedure mode off and skips paragraph extraction.
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
1706f5a to
33a8af3
Compare
A copybook of procedure code is pasted into the PROCEDURE DIVISION of the program that copies it, so it holds paragraphs and statements but has no `PROCEDURE DIVISION` header of its own. The extractor starts reading paragraphs only after that header, so such a file was taken for data from its first line to its last: it got a file node and nothing else, and every paragraph and PERFORM in it was missing from the graph. Before reading a file, look for the line where its procedure code begins: the first paragraph or section header, provided the file has neither a PROGRAM-ID nor a PROCEDURE DIVISION header and a statement (a line that begins with a statement verb, or an EXEC block) follows that header. From that line on the file is read as procedure code. The paragraphs hang under the file node, as the data items of a data copybook already do. Every other file is read exactly as before. A lone `NAME.` line is not enough to switch: a data copybook can have one where a VALUE clause runs on to the next line (`SPACES.`), and without a statement after it the file stays data. Not covered: a copybook that holds statements but no paragraph header (a fragment pasted into the middle of a paragraph), and statements that stand before the first header. Regression test: a `.cpy` with two paragraphs and a PERFORM between them, which fails without the change. A data copybook with a lone `SPACES.` line is the control. Co-Authored-By: Claude Fable 5.2 <[email protected]>
A headerless copybook is read as procedure code when a statement follows its first paragraph header. The check knew two dozen verbs, so a copybook whose only statement was a SORT, SEARCH, INSPECT, NEXT SENTENCE or STOP RUN stayed data and lost its paragraphs. The list now holds the statement verbs of the language. Two ways a data copybook with a lone `NAME.` line could be misread as procedure code, and lose its data items, are closed: - The verb had to be followed by a word boundary only, so a name such as `OPEN-FILES.` counted as an OPEN statement. It must now be a whole word. - Any EXEC block counted as a statement. `EXEC SQL INCLUDE` and `EXEC SQL DECLARE` are declarations that the DATA DIVISION has as well, and no longer count, also when the word stands on the line after `EXEC SQL`. Regression tests: a copybook for each of five verbs that were missing and for an EXEC SQL statement on one line and on three, and a data copybook with each of the three lookalikes. The verb and lookalike cases fail without the change. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The check for a headerless procedure copybook looked for EXEC blocks in the whole line, quoted text included. A data copybook with a lone `NAME.` line and a later `VALUE 'EXEC SQL COMMIT END-EXEC'` was read as procedure code and lost its data items. Quoted text is now blanked before the check, as the extractor already does for PERFORM. Regression test: the quoted EXEC SQL value as a further case of the data-copybook lookalike test, which fails without the change, and a quoted `'MOVE A TO B'` as control. Co-Authored-By: Claude Fable 5.2 <[email protected]>
33a8af3 to
783b1bc
Compare
…a-57 Both change extraction output and ship in the same release as the 56->57 bump, so they share schema 57 with a combined rationale. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Shipped in v0.9.121, landed via authorship-preserving cherry-pick so your commits keep your name. Thanks @pavansystems! |
What does this PR do?
A copybook of procedure code is pasted into the
PROCEDURE DIVISIONof the program that copies it, so it holds paragraphs and statements but has noPROCEDURE DIVISIONheader of its own. The extractor starts reading paragraphs only after that header, so such a file is taken for data from its first line to its last: it gets a file node and nothing else, and every paragraph andPERFORMin it is missing from the graph.Before reading a file, this looks for the line where its procedure code begins: the first paragraph or section header, provided that
PROGRAM-IDnor aPROCEDURE DIVISIONheader, andEXECblock).From that line on the file is read as procedure code. The paragraphs hang under the file node, as the data items of a data copybook already do.
Every other file is read exactly as before. A lone
NAME.line is not enough to switch: a data copybook can have one where aVALUEclause runs on to the next line (SPACES.), and without a statement after it the file stays data.Not covered: a copybook that holds statements but no paragraph header (a fragment pasted into the middle of a paragraph), and statements that stand before the first header.
I found no existing issue for this.
Follow-up commit (
fix(cobol): know a procedure copybook by any statement, not a short list), after the automated review. All three points were reproduced first:SORT,SEARCH,INSPECT,NEXT SENTENCEorSTOP RUNstayed data. The check now knows the statement verbs of the language.OPEN-FILES.counted as anOPENstatement, so a data copybook with a loneSPACES.line and such a name was read as procedure code. The verb must now be a whole word.EXECblock counted as a statement, so the same data copybook withEXEC SQL INCLUDE SQLCA END-EXECwas read as procedure code.EXEC SQL INCLUDEandDECLAREno longer count.Rebased onto
v8after #5423 landed, with one more follow-up commit (fix(cobol): do not read a quoted value as a statement in a copybook): reproduced the second automated review's point that a data copybook with a loneNAME.line and a laterVALUE 'EXEC SQL COMMIT END-EXEC'was read as procedure code. Quoted text is now blanked before the check.Type of change
Verification & Invariants
Invariant: a file with a
PROGRAM-IDor aPROCEDURE DIVISIONheader, and a data copybook, are read exactly as before. The control test is a data copybook with a loneSPACES.line, which must still be read as data.Persisted state: the AST cache holds per-file results from before this change, so a cached COBOL file keeps its old result until the file changes or the cache is cleared. I did not bump
_AST_CACHE_SCHEMA, following the earlier COBOL fixes; say so if you want it bumped.How was this tested?
On this branch (macOS, Python from
uv sync --all-extras --frozen):The new tests were also run against unmodified
v8, where they fail.After the rebase, the full suite (
uv run --frozen --all-extras pytest tests) was run on the #5426 branch, which is this branch plus two commits: 11917 passed, 165 skipped, 1 xfailed, none failed.The combined branch was also run on a private COBOL codebase and the result compared with links I had been adding outside Graphify; it produced no link that the comparison did not also have.
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (Not applicable: no skill fragment changed.)The code, tests and this description were written with Claude Code; the commit carries a
Co-Authored-Byline.🤖 Generated with Claude Code