Skip to content

Fix #3998: no-scan refractor lineage reads SELECT with the engine's reader - #3999

Merged
squid-protocol merged 1 commit into
mainfrom
fix/3998-noscan-select-lineage
Sep 29, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/3998-noscan-select-lineage

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Fixes #3998

Problem

Without --scan, the refractor gets a program's file lineage (analysis.lineage.inputs/outputs) from cobol_dag_architect.extract_lineage. That function had its own SELECT regex, _SELECT, which it ran over a view with literal contents blanked. So:

  • ASSIGN TO "./IN-FILE" read TO as the DD, because (?:TO\s+)? backtracked onto the blanked literal.
  • SELECT OPTIONAL f took OPTIONAL as the file name.
  • Japanese, national and full-width file names didn't match [A-Z0-9\-].

With --scan, lineage comes from the engine's dataset_data, which gets all three right. So the same program got different lineage depending on the path. The issue's reproduction gave inputs: ['TO'], outputs: [] without --scan and inputs: ['./IN-FILE', 'CUSTDD'], outputs: ['OUTDD'] with it.

Approach: reuse the engine's reader

The --scan lineage doesn't come from core/file_control.py. It comes from mainframe_boundary._cobol_datasets, through its _SELECT_ASSIGN + _ASSIGN_DEVICE_PREFIX → dataset_data → engine_sourcing.engine_lineage. file_control.py feeds file_control_data, which records organization and keys and isn't part of lineage. So the reader to share is _cobol_datasets's SELECT half:

  • mainframe_boundary.py: the SELECT loop of _cobol_datasets moves unchanged into _select_assigns(sentences). _cobol_datasets builds its records from it, with the same keys in the same order. A new public helper, cobol_select_assigns(code_stream) -> {internal: dd_name}, exposes the mapping. Engine output doesn't change (it's a pure extraction).
  • cobol_dag_architect.py: _SELECT is deleted. file_map = cobol_select_assigns(code_view(text, blank_literals=False)). code_view gets a blank_literals flag so the ASSIGN literal survives. Comment and debug lines, the sequence area and cols 73+ are still dropped, and there's a test that a commented-out SELECT is still ignored. The OPEN walk, dead-paragraph masking and dynamic-CALL detection are unchanged and still run on the literal-blanked view.

Why reuse the reader instead of fixing the regex: one reader can't drift. OPTIONAL, literal targets, the COBOL word class (national, full-width digits and hyphens from #3955/#3991/#3995) and the device-prefix rules all come from the reader --scan already uses. It's a pure function over a string, so the no-scan path doesn't need a scan or a DB.

Behaviour changes on the no-scan path. All of them are parity with --scan:

  • Device prefixes: UT-S- / UR-S- are still stripped. DA-S-, UT-, UR-, DA- are now stripped as well, the way the engine does it.
  • If a program SELECTs the same internal name twice, the first one wins, as in the engine. Before, the last one won.

Tests

  • New file tests/cobol_mainframe/test_noscan_select_lineage.py:
    • Unit tests of cobol_select_assigns for each form: ASSIGN TO literal (both quote styles), ASSIGN literal with no TO, plain, ASSIGN with no TO, OPTIONAL, a Japanese name, a full-width-digit name, UT-S- and UR-S-, and a multi-line SELECT. Also checks that TO/OPTIONAL are never read as names and that the first SELECT of a name wins.
    • extract_lineage on a program that has every form, across INPUT/OUTPUT/I-O/EXTEND, and a test that a commented SELECT is still ignored.
    • Parity test: runs cobol-refractor on the same estate without and then with --scan, and asserts that analysis.lineage is identical and correct.
    • With only cobol_dag_architect.py reverted to origin/main, the lineage test and the parity test fail (they show TO). The unit tests need the new helper.
  • tests/cobol_mainframe + tests/tools_recorders: 1359 passed, 32 skipped. The tests/core_engine files that import mainframe_boundary: 325 passed. field_testing.py check: valid, report up to date.
  • ruff_audit --ci, mypy_audit --ci, dead_key_audit --ci: no new findings. tool_regex_redos --ci: 0 offenders (no new regex). ruff format was run on the touched files only.

Corpus output

  • java_target_matrix.py --same-as origin/main --only default on CardDemo, CBSA, GenApp, zopeneditor, zECS and DSF:
    • Plain path: every generated file is identical. With the lineage fix alone, both paths were identical too, before the field-testing commit.
    • --scan path: the diff is only the field-testing status changes described below, in Javadoc comments, skeleton / port-ticket JSON and markdown, plus those files' sha256 / bytes / tokens metadata. I checked that every changed .java line is a comment line: 48 files in CardDemo, 58 in CBSA, 57 in GenApp, 3 in zopeneditor, 9 in zECS, 419 in DSF. No code line changes, so CI's compile will rebuild but has nothing new to compile.
  • extract_lineage over all 123 lineage-bearing COBOL programs in those six corpora is identical to main.
  • ground_truth_ledger.py check: ledger clean.
  • crucible_check.py: full_precision PASS, zero_dependency PASS (the engine change is a pure extraction).
  • opensourcecobol4j estate (2,858 programs): 277 programs' no-scan lineage changes. Every change replaces TO or an empty set with the real target (for example ./TEST-FILE, ./INPUT.TXT, ./テスト_ファイル). No program loses a non-TO value.

Field-testing log: opensourcecobol4j fresh-estate defects (D029-D035)

tests/cobol_mainframe/field_testing.json now logs the defects the opensourcecobol4j fresh estate (#3806) exposed, plus this one. opensourcecobol4j isn't added to estates: it's GPL, unkeyed and kept outside the repo, and a public estate has to be a keyed corpus. So each entry has "estate": null, "after_round": 6.

id issue / fix side severity fields
D029 #3955 / #3967 engine fact program_id, record fields, units
D030 #3956 / #3966 engine fact record fields, copybook paths
D031 #3991 / #3995 engine fact record fields, units
D032 #3992 / #3994 forge fact file control, inputs
D033 #3957 / #3965 forge attribute file control
D034 #3958 / #3961 forge attribute record fields
D035 #3998 (this PR) forge fact inputs, outputs, file control

This resets the clean fresh-round counts for every field an engine defect names. Only engine defects reset them; forge defects only add to the forge column. fact_channel_confidence.json and docs/language_status/cics_field_testing.md were regenerated. Changed rows:

field before after
record fields engine 0, forge 1, clean fresh 3 / 1,622 facts, field-tested engine 3, forge 2, clean fresh 0 / 0, open
program_id engine 1, clean fresh 3 / 43, open engine 2, clean fresh 0 / 0, open
copybook paths engine 2, clean fresh 2 / 41, open engine 3, clean fresh 0 / 0, open
units engine 3, clean fresh 0 engine 5, clean fresh 0
inputs forge 0 forge 2
outputs forge 0 forge 1
file control forge 0 forge 3

record fields losing field-tested is why the --scan-path Java comments and skeleton JSON say open instead of field-tested for record layouts.

🤖 Generated with Claude Code

The refractor without --scan mapped files with cobol_dag_architect's own
_SELECT regex over a literal-blanked view: `ASSIGN TO "x"` read the DD as
`TO`, `SELECT OPTIONAL f` took OPTIONAL as the file, and Japanese /
full-width file names never matched, so lineage differed from --scan.

The SELECT half of mainframe_boundary._cobol_datasets (what --scan's
dataset_data lineage uses) is split out as _select_assigns and exposed as
cobol_select_assigns; extract_lineage now builds its file_map from it over
a literal-keeping code view. Engine output is unchanged.

Also logs the opensourcecobol4j fresh-estate defects (#3955, #3956, #3991,
#3992, #3957, #3958) and this one in field_testing.json as D029-D035, lets
field_testing.py place a defect found on an unkeyed estate by after_round
like a review find, and regenerates the field-testing report and
fact_channel_confidence.json.

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

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 716ac4f into main Sep 29, 2026
38 checks passed
@squid-protocol
squid-protocol deleted the fix/3998-noscan-select-lineage branch September 29, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant