From b385cd441bdac19ae8d498e52b3eee517753cbb0 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 24 Jun 2026 09:57:17 -0400 Subject: [PATCH] refactor(audit): remove dead DSL parser (DSL files no longer produced) The v2 postfix DSL parser (DSL_WORD_ARITY_V2, _atom, to_dsl_v2, parse_dsl_v2) was implemented during the 14-phase DSL plan but never reached production: run_audit() (line ~1217 after this change) only writes .md files (AUDIT_REPORT.md plus per-aggregate markdowns via to_markdown/to_tree), never .dsl files. The DSL parser carried latent arity bugs (DSL_WORD_ARITY_V2 declared 5 for 'result-coverage' but writer emits 4; 4 for 'type-alias-coverage' but writer emits 3) which would have caused silent parse failures. Also removed the now-unused 'import re' statement (was only used by parse_dsl_v2). The 'from datetime import date as date_mod' is retained (still used at line ~1259, 1275, 1291 in the markdown renderer). Tests deleted in lockstep: - tests/test_code_path_audit_phase78.py: test_dsl_word_arity_v2_14_new_words - tests/test_code_path_audit_phase89.py: test_to_dsl_v2_includes_aggregate_kind_section, test_parse_dsl_v2_round_trip_aggregate_kind, test_parse_dsl_v2_malformed Verification: - grep -c 'to_dsl_v2|parse_dsl_v2|DSL_WORD_ARITY_V2' src/code_path_audit.py = 0 - 127 of 127 remaining tests pass (was 131; -4 tests deleted) --- src/code_path_audit.py | 148 -------------------------- tests/test_code_path_audit_phase78.py | 15 --- tests/test_code_path_audit_phase89.py | 24 ----- 3 files changed, 187 deletions(-) diff --git a/src/code_path_audit.py b/src/code_path_audit.py index 14172e25..9b69ed50 100644 --- a/src/code_path_audit.py +++ b/src/code_path_audit.py @@ -839,99 +839,8 @@ def run_all_cross_audit_reads(audit_inputs_dir: str) -> dict[str, dict]: out[audit_name] = {} return out -DSL_WORD_ARITY_V2: dict[str, int] = { - "kind": 1, - "mem-dim": 1, - "fn-ref": 4, - "access-pattern": 1, - "ap-evidence": 4, - "frequency": 1, - "freq-evidence": 4, - "result-coverage": 5, - "type-alias-coverage": 4, - "cross-audit-finding": 5, - "cross-audit-findings": 5, - "decomp-cost": 8, - "opt-candidate": 7, - "is-candidate": 1, -} - -import re from datetime import date as date_mod -def _atom(s: str) -> str: - """Format a string as a postfix DSL atom (bare or quoted).""" - if any(c in s for c in ('"', "'", " ", "\t", "\n", "(", ")", "{", "}")): - return f'"{s}"' - return s - -def to_dsl_v2(profile: AggregateProfile, generated_date: str = "") -> str: - """Serialize an AggregateProfile to v2 postfix DSL (flat sections).""" - lines: list[str] = [] - lines.append(f'\\ AggregateProfile: "{profile.name}"') - lines.append(f"\\ generated {generated_date} by src.code_path_audit v2") - lines.append("") - lines.append("\\ === aggregate_kind ===") - lines.append(f' "{profile.aggregate_kind}" kind') - lines.append("") - lines.append("\\ === memory_dim ===") - lines.append(f' "{profile.memory_dim}" mem-dim') - lines.append("") - lines.append(f"\\ === producers ({len(profile.producers)} items) ===") - for p in profile.producers: - lines.append(f' "{p.fqname}" "{p.file}" {p.line} "{p.role}" fn-ref') - lines.append("") - lines.append(f"\\ === consumers ({len(profile.consumers)} items) ===") - for c in profile.consumers: - lines.append(f' "{c.fqname}" "{c.file}" {c.line} "{c.role}" fn-ref') - lines.append("") - lines.append("\\ === access_pattern ===") - lines.append(f' "{profile.access_pattern}" access-pattern') - lines.append("") - lines.append(f"\\ === access_pattern_evidence ({len(profile.access_pattern_evidence)} items) ===") - for ev in profile.access_pattern_evidence: - lines.append(f' "{ev.function.fqname}" "{ev.pattern}" {len(ev.field_accesses)} "{ev.confidence}" ap-evidence') - lines.append("") - lines.append("\\ === frequency ===") - lines.append(f' "{profile.frequency}" frequency') - lines.append("") - lines.append(f"\\ === frequency_evidence ({len(profile.frequency_evidence)} items) ===") - for ev in profile.frequency_evidence: - lines.append(f' "{ev.function.fqname}" "{ev.frequency}" "{ev.source}" "{ev.note}" freq-evidence') - lines.append("") - rc = profile.result_coverage - lines.append("\\ === result_coverage ===") - lines.append(f" {rc.total_producers} {rc.result_producers} {rc.total_consumers} {rc.result_consumers} result-coverage") - lines.append("") - tac = profile.type_alias_coverage - lines.append("\\ === type_alias_coverage ===") - lines.append(f" {tac.total_sites} {tac.typed_sites} {tac.untyped_sites} type-alias-coverage") - lines.append("") - lines.append("\\ === cross_audit_findings ===") - for f in profile.cross_audit_findings.weak_types: - lines.append(f' "{f.audit_script}" {f.site_count} "{f.example_file}" {f.example_line} "{f.note}" cross-audit-finding') - for f in profile.cross_audit_findings.exception_handling: - lines.append(f' "{f.audit_script}" {f.site_count} "{f.example_file}" {f.example_line} "{f.note}" cross-audit-finding') - for f in profile.cross_audit_findings.optional_in_baseline: - lines.append(f' "{f.audit_script}" {f.site_count} "{f.example_file}" {f.example_line} "{f.note}" cross-audit-finding') - for f in profile.cross_audit_findings.config_io_ownership: - lines.append(f' "{f.audit_script}" {f.site_count} "{f.example_file}" {f.example_line} "{f.note}" cross-audit-finding') - for f in profile.cross_audit_findings.import_graph: - lines.append(f' "{f.audit_script}" {f.site_count} "{f.example_file}" {f.example_line} "{f.note}" cross-audit-finding') - lines.append(" 5 cross-audit-findings") - lines.append("") - dc = profile.decomposition_cost - lines.append("\\ === decomposition_cost ===") - batch_size_str = str(dc.batch_size) if dc.batch_size is not None else "nil" - lines.append(f" {dc.current_cost_estimate} {dc.componentize_savings} {dc.unify_savings} \"{dc.recommended_direction}\" \"{dc.recommended_rationale}\" {batch_size_str} {dc.struct_field_count} {str(dc.struct_frozen).lower()} decomp-cost") - lines.append("") - lines.append(f"\\ === optimization_candidates ({len(profile.optimization_candidates)} items) ===") - for cand in profile.optimization_candidates: - lines.append(f' "{cand.candidate}" "{cand.direction}" {len(cand.affected_files)} {cand.estimated_savings_us} "{cand.effort}" "{cand.priority}" "{cand.cross_ref}" opt-candidate') - lines.append("") - lines.append("\\ === is_candidate ===") - lines.append(f" {'true' if profile.is_candidate else 'false'} is-candidate") - return "\n".join(lines) def to_markdown(profile: AggregateProfile) -> str: """Render the per-aggregate markdown (10 sections).""" @@ -1028,63 +937,6 @@ def to_tree(profile: AggregateProfile) -> str: lines.append(f"|- optimization_candidates: [{len(profile.optimization_candidates)}]") return "\n".join(lines) -def parse_dsl_v2(text: str) -> Result[dict]: - """Parse a v2 postfix DSL into a nested dict (round-trip).""" - tokens: list[str] = [] - for line in text.splitlines(): - line = re.sub(r"\\.*", "", line) - if not line.strip(): - continue - i = 0 - while i < len(line): - c = line[i] - if c.isspace(): - i += 1 - continue - if c == '"': - j = line.find('"', i + 1) - if j == -1: - j = len(line) - tokens.append(line[i + 1 : j]) - i = j + 1 - else: - j = i - while j < len(line) and not line[j].isspace(): - j += 1 - tokens.append(line[i:j]) - i = j - stack: list = [] - i = 0 - while i < len(tokens): - t = tokens[i] - if t == "list" and stack and isinstance(stack[-1], int): - count = stack.pop() - items = stack[-count:] if count > 0 else [] - stack = stack[:-count] if count > 0 else stack - stack.append(items) - i += 1 - continue - if t in DSL_WORD_ARITY_V2: - nargs = DSL_WORD_ARITY_V2[t] - args = stack[-nargs:] if nargs else [] - stack = stack[:-nargs] if nargs else stack - stack.append({"_tag": t, "_args": args}) - i += 1 - continue - if t in ("true", "false"): - stack.append(t == "true") - elif t == "nil": - stack.append(None) - elif t.lstrip("-").isdigit(): - stack.append(int(t)) - else: - stack.append(t) - i += 1 - if len(stack) != 1: - return Result( -data={"_sections": stack}, - ) - return Result(data=stack[0]) AGGREGATES_IN_SCOPE: tuple[str, ...] = ( "Metadata", diff --git a/tests/test_code_path_audit_phase78.py b/tests/test_code_path_audit_phase78.py index c0db63a5..7fdde391 100644 --- a/tests/test_code_path_audit_phase78.py +++ b/tests/test_code_path_audit_phase78.py @@ -67,7 +67,6 @@ from src.code_path_audit import ( compute_type_alias_coverage, aggregate_cross_audit_findings, run_all_cross_audit_reads, - DSL_WORD_ARITY_V2, ) from src.result_types import Result, ErrorInfo, ErrorKind @@ -206,17 +205,3 @@ def test_run_all_cross_audit_reads_partial() -> None: result = run_all_cross_audit_reads(tmp) assert "audit_weak_types" in result assert "audit_exception_handling" in result - -# Phase 8 Task 8.1 test -def test_dsl_word_arity_v2_14_new_words() -> None: - """DSL_WORD_ARITY_V2 has 14 new tagged words.""" - expected_words = { - "kind", "mem-dim", "fn-ref", "access-pattern", "ap-evidence", - "frequency", "freq-evidence", "result-coverage", "type-alias-coverage", - "cross-audit-finding", "cross-audit-findings", "decomp-cost", - "opt-candidate", "is-candidate", - } - assert expected_words.issubset(set(DSL_WORD_ARITY_V2.keys())) - assert DSL_WORD_ARITY_V2["kind"] == 1 - assert DSL_WORD_ARITY_V2["fn-ref"] == 4 - assert DSL_WORD_ARITY_V2["decomp-cost"] == 8 \ No newline at end of file diff --git a/tests/test_code_path_audit_phase89.py b/tests/test_code_path_audit_phase89.py index 2d2a2adf..96d70f82 100644 --- a/tests/test_code_path_audit_phase89.py +++ b/tests/test_code_path_audit_phase89.py @@ -21,10 +21,8 @@ from src.code_path_audit import ( DecompositionCost, OptimizationCandidate, AggregateProfile, - to_dsl_v2, to_markdown, to_tree, - parse_dsl_v2, AGGREGATES_IN_SCOPE, CANDIDATE_AGGREGATES, synthesize_aggregate_profile, @@ -56,14 +54,6 @@ def _make_profile(name: str = "Metadata", kind: str = "typealias") -> AggregateP ) # Phase 8 Tasks 8.2-8.5 tests -def test_to_dsl_v2_includes_aggregate_kind_section() -> None: - """to_dsl_v2 emits the \\ === aggregate_kind === section.""" - profile = _make_profile() - dsl = to_dsl_v2(profile, generated_date="2026-06-22") - assert "\\ === aggregate_kind ===" in dsl - assert '"typealias" kind' in dsl - assert "\\ === memory_dim ===" in dsl - assert '"discussion" mem-dim' in dsl def test_to_markdown_10_sections() -> None: """to_markdown emits the 10 sections per spec section 8.1.""" @@ -87,20 +77,6 @@ def test_to_tree_box_drawing() -> None: assert "Metadata" in tree assert "kind: typealias" in tree -def test_parse_dsl_v2_round_trip_aggregate_kind() -> None: - """parse_dsl_v2(to_dsl_v2(profile)) recovers the aggregate_kind section.""" - profile = _make_profile() - dsl = to_dsl_v2(profile) - parsed = parse_dsl_v2(dsl) - assert isinstance(parsed, Result) - assert "typealias" in str(parsed.data) - -def test_parse_dsl_v2_malformed() -> None: - """parse_dsl_v2 returns Result.ok for empty input (no tagged words).""" - result = parse_dsl_v2("\\ empty comment only\n") - assert result.ok - assert result.data == {"_sections": []} - # Phase 9 Tasks 9.1-9.6 tests def test_aggregates_in_scope_10_real() -> None: """AGGREGATES_IN_SCOPE has 10 real aggregates."""