Commit Graph

14 Commits

Author SHA1 Message Date
NB-076 097f5449da fix: 溢出截断 + flatfile字段路由 + 多E2E验证
1. _make_numeric_value截断保护
   PIC 9(3)字段值超过999时截断(之前不截断)
2. flatfile.py字段路由
   write_all_files按FD分配字段值到对应的文件
3. 端到端运行验证:
   01-matching-1-1: PASS (8匹配/9不匹配)
   03-matching-N-1: PASS (COPYBOOK正常解析)
   10-divide-50: 程序自身OPEN逻辑问题
   34-sort-anomaly: PARTIAL(异常测试用例部分通过)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 13:59:54 +08:00
NB-076 0e7472598d fix: 跨文件KEY约束 + PERFORM分支统计 + 平面文件写入
1. 跨文件KEY约束(修复)
   匹配型程的M-KEY与D-KEY值不同导致匹配0条。
   修复: generate_data后处理检测IF KEY比较,
   前半记录对齐KEY值(8条匹配),后半保待差异(9条不匹配).
   实际cobc运行验证: MATCHED=8, PASS.

2. extract_structure PERFORM分支统计(修复)
   _walk函数未添加BrPerform决策点, total_branches缺失.
   修复: 为PERFORM UNTIL/VARYING决策点添加2分支(Enter/Skip).
   之前total_branches=0,现在=2.

3. flatfile.py(新增)
   COBOL固定长平面文件写入器.
   - analyze_fd_layout(): 从COBOL源码自动解析文件布局
   - write_flat_file(): 生成为COBOL可直接读取的二进制格式

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 13:52:56 +08:00
NB-076 bb4a7a2346 fix: classification修复+grammar增强+75/75回归确认
分类修复:
- FILE-CONTROL关键词(0.99)错误覆盖匹配检测信号
- 添加匹配型规则引擎更优优先级,确保匹配检测结果优先
- has_matching_kw特征注入,使IF-less匹配程序也能识别

Grammar增强:
- LEVEL扩展到/[0-9]+/覆盖所有COBOL层级号
- HEX_STRING添加支持X'...'十六进制字面量
- VALUE子句逗号预处理剥离(88-level多值)
- COPY正则支持引号包覆的名称

结果: 内部75/75, 外部基准54/58(93%)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 13:18:07 +08:00
NB-076 3b150b6c54 S14: 58-program benchmark suite — Lark grammar fixes + external COBOL validation
Grammar fixes:
1. COPY regex: handle quoted names COPY "STD-REC.CPY"
2. Quoted name strip: remove quotes before file lookup
3. VALUE clause: support comma-separated 88-level values
4. PIC STRING: support decimal dot (ZZ9.99 -> PICTURE_STRING.99 + DOT)
5. LEVEL: use INT for level number (fixes 05/01/77 all levels)

Results on 58 telecom billing COBOL programs:
- Parse OK: 54/58 (93%)
- Parse fail: 4 (special chars: TAB, X'01', U'NNNN', &)
- Classification known issue: matching programs misclassified as
  '文件编成' because FILE-CONTROL keyword overrides matching signals
  (requires rule engine priority fix - separate issue)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 12:31:00 +08:00
NB-076 6e69dff7a4 fix: 3 bugs confirmed and repaired from honest audit
Bug #1: AND compound branch-body MOVE not propagated (HIGH)
  Root cause: ELSE on same line as false_body, rest of line lost after
  self.advance(). Fix: reinsert ELSE body text same as ELSE IF does.
  Result: MOVE 'Y'/'N' TO WS-FLAG correctly propagated, all 3 paths
  verified (A<=10/B<20=F, A>10/B<20=T, A>10/B>=20=F).

Bug #2: Performance — path explosion (25 IFs = 47s, 10000 records)
  Root cause: BrSeq inner loop combined all paths before capping.
  Fix: early break at _MAX_PATHS in the combo loop.
  + _MAX_PATHS reduced from 10000 to 500.
  Result: 47s/10000rec -> 0.2s/27rec (235x improvement)

Bug #3: COPY+REDEFINES parse failure (test-only)
  Root cause: test code called parse_data_division on full source
  instead of extract_data_division first. Fixed.
  Real pipeline (extract_structure -> generate_data) was never affected.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 11:36:33 +08:00
NB-076 9cefbdf114 R16: 专家漏洞评审 — 发现并修复嵌套COPYBOOK解析bug
评审方法:14项实机验证,非静态审查
  1. 非确定性输出检测 ✓ 5次运行值一致
  2. 边缘COBOL功能crash测试 (ALTER/ENTRY) ✓ 不崩溃
  3. 大规模程序性能 (500字段+250IF) ✓ 数秒完成
  4. 路径爆炸防护 (10IF in PERFORM UNTIL) ✓ 不爆炸
  5. 嵌套COPYBOOK解析 → 发现BUG并修复
  6. 嵌套IF深度  ✓
  7. 畸形JCL输入 (二进制/BOM/1000行延续) ✓ 不崩溃
  8. 注释中KEY字串误触发matching ✓ 不误报
  9. 变量名包含关键词子串FP ✓ WS-SORT-KEY不触发SORT
  10. 非COBOL输入 (中日文/HTML/二进制) ✓ 不误报
  11. OPEN I-O方向解析 ✓
  12. DataWriter JSON格式 ✓
  13. 跨运行隔离 ✓
  14. Config加载 ✓

修复: resolve_copybooks 增加递归参数+深度保护
  之前: COPY L1 -> L1.cpy含'COPY L2.'不被解析
  之后: 递归解析,上限10层防循环

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 10:49:18 +08:00
NB-076 abb283669c R13: final sweep — EXEC stripping + INSPECT bugfix + more EQ assertions
1. Lark: preprocess strips EXEC CICS/SQL...END-EXEC blocks
   -> CI01_CICS/DB01_SELECT_UPDATE now parse, 75/75 samples pass
2. propagate_assignments INSPECT TALLYING bugfix:
   was reading source from count_var (wrong field) instead of
   asgn['tgt']. Now CNT='005' instead of '003' for len(HELLO)=5.
3. 26 new EQ/falsifiable assertions added (propagate chains,
   orchestrator state, data_writer, report generator)
4. Hardened: ACCEPT DATE string len check, DataWriter JSON format

16 suites / 0 FAIL.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 09:37:58 +08:00
NB-076 d8176ea07b fix: generate_data constraint steering fully repaired
Root cause: IF condition and EVALUATE WHEN parsing swallowed entire
line including THEN-body (e.g. '50 MOVE BIG...' instead of just '50').

Fix:
1. Single-line IF cond_text truncated at COBOL statement-starting keywords
   (MOVE/DISPLAY/COMPUTE/ADD/...)
2. Multi-line IF continuation loop also breaks on these keywords (was
   missing DISPLAY, READ, WRITE, CLOSE, OPEN, SEARCH, ...)
3. EVALUATE WHEN raw_val truncated at same keyword set
4. All raw-string escape sequences fixed (Python 3.12 SyntaxWarning)

Verification:
- IF single-line A>50: A=51(true)/12(false) previously A=01/00
- IF multi-line X>50: X=51(true)/12(false) previously not steered
- EVALUATE WHEN 1/2/OTHER: C=1/2/4 previously C=0/0/0
- IF AND compound: (A<=10,B<20), (A>10,B<20), (A>10,B>=20)
- IF >75: A=76(true)/12(false) previously not steered

R11 tests updated: BUG documentation replaced with real assertions.
13 suites / 0 FAIL.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-22 09:10:21 +08:00
NB-076 4be2aae66d fix: 生产级 COBOL 程序解析 — COPY + OCCURS TO + FD 修复
对抗性测试发现的生产程序解析缺陷和修复:

缺陷1: COPY 语句从未被预处理(18 个月 bug)
  - resolve_copybooks() 在 main() CLI 中调用但在 extract_structure() 路径中从未被调用
  - 修复: preprocess() 函数头部调用 resolve_copybooks()
  - 不可解析的 COPY 行被移除(避免 Lark 在 FD 块内遇到无法识别的指令)

缺陷2: Lark 语法的 fd 规则要求 data_item+ (至少一个记录)
  - 生产程序 FD 可以通过 COPY 引入记录定义
  - COPY 被移除后 FD 内无 data_item 导致 Lark 崩溃
  - 修复: fd 改为 data_item* (零或多个)

缺陷3: OCCURS 1 TO 100 TIMES(变量范围表)
  - 语法只支持 OCCURS INT TIMES,不支持 OCCURS 1 TO 100 TIMES
  - 修复: occurs_clause 增加 'TO' INT 可选部分

效果: 4 个生产程序中 2 个成功解析(CRDVAL, GENDATA)
  - 剩余 2 个(CRDCALC, CRDRPT)因固定格式续行限制未修复

全回归: 767 passed(0 new failures)
2026-06-21 16:13:58 +08:00
NB-076 0b0a013f51 fix: 3 critical parsing bugs found through statement benchmark testing
Bug 1: ELSE IF breaks IF false_seq parsing (core.py)
- _parse_if checked self.clean() == 'ELSE' which fails on 'ELSE IF ...'
- Fix: use startswith('ELSE'), reinsert IF portion for recursive parse
- Impact: ALL ELSE IF chains were silently dropped (huge branch loss)

Bug 2: READ skip loop greedily consumes subsequent statements (core.py)
- READ's AT END / NOT AT END skip loop used bare advance() with no
  statement boundary detection
- Fix: add _stmt_boundary regex that stops on IF/PERFORM/READ/etc.
- Impact: everything after first READ was consumed as 'AT END' lines

Bug 3: _walk() in extract_structure doesn't descend into BrPerform (__init__.py)
- Branch counting _walk() only handled BrIf/BrEval/BrSeq
- IF statements inside PERFORM bodies were never counted
- Fix: add BrPerform.body_seq and BrSearch descent

Combined impact: matching programs (MT01-33) now correctly report
their branches instead of 0. Full regression: 749 passed (unchanged).
2026-06-21 12:52:04 +08:00
NB-076 dbee3b7251 fix: Lark grammar + parse_file_section SD/ASCENDING KEY support
Bug fixes found through statement benchmark testing:
1. grammar.lark: Add ASCENDING/DESCENDING KEY IS + INDEXED BY to
   occurs_clause — fixes HINA024 (SEARCH ALL) parsing crash
2. grammar.lark: Add SD (Sort Description) entry type to file_section
   — fixes HINA034 (SORT), ST01, ST02 parsing crashes
3. read.py parse_file_section(): Handle SD blocks alongside FD blocks
   — enables SORT/MERGE file structure extraction

4 previously crashing files now parse successfully:
- HINA024.cbl (SEARCH ALL): paras=3, files=0
- HINA034.cbl (SORT): paras=1, files=3
- ST01_SORT.cbl: paras=2, files=3
- ST02_MERGE.cbl: paras=1, files=4

Regression: 749 passed (unchanged — classify_program internally caught
the crashes, so tests already 'passed'; real improvement is in data
quality: structure extraction now works for these programs)
2026-06-21 12:21:36 +08:00
hangshuo652 bc1d56d1a4 feat: Phase 2 complete — 13 Phases of COBOL type classification and test benchmark
P0.6: gcov infrastructure
P1: extract_structure output expansion (11 new feature fields)
P2: Confusion group rule engine (8 pairs + contradiction + backtrack)
P3: 4-factor confidence calculation + quality gate update
P4: 33+2 COBOL program type test samples (22 files, 7 categories)
P5: parametrized/ test data generation engine
P6: japanese_data.py lookup tables
P7-10: Type-specific test suites (~159 parametrized tests)
P11: Full classification pipeline (classify_program) + orchestrator integration
P12: Documentation (module-interfaces, test-plan v3.0, coverage-matrix)

Architecture decisions:
- classification_pipeline/ merged to hina/pipeline/
- parametrized/ as independent module
- japanese_data.py as root-level file
- hina/__all__ only exports classify_program()

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-19 23:51:55 +08:00
hangshuo652 e2486db510 fix: 3 issues found during real COBOL validation 2026-06-18 16:26:44 +08:00
hangshuo652 097530b036 feat: Phase 1 - cobol_testgen API + quality fields + retry handler 2026-06-18 15:47:35 +08:00