Skip to content

Refactor duplicated code into shared utilities - #26

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1784930428-dedupe-shared-utils
Open

Refactor duplicated code into shared utilities#26
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1784930428-dedupe-shared-utils

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Five copy-pasted patterns across src/ are collapsed into shared helpers; net −215 lines with no intended behaviour change (parser output verified byte-identical on real geth/Nethermind/Besu/Reth files, see below).

1. Cached raw-GitHub fetching → new src/github_fetcher.py. SpecFetcher and CodeFetcher each carried their own session/token setup, cache-hit/write dance (4 near-identical copies of "check cache file → GET raw URL → raise_for_status → write cache"), and clear_cache/list_cached_*. Both now subclass CachedGitHubFetcher:

class SpecFetcher(CachedGitHubFetcher):
    DEFAULT_CACHE_DIRNAME = ".spec_cache"

    def fetch_eip(self, eip_number, use_cache=True):
        return self.fetch_raw_file("ethereum", "EIPs", f"EIPS/eip-{eip_number}.md", "master",
                                   cache_key=f"eip-{eip_number}.md", use_cache=use_cache)

Cache-file names, directory defaults, the GitHub Accept header on CodeFetcher, and SpecFetcher.list_cached_specs() are all preserved.

2. Brace-block scanning → _brace_delta / _close_block / _find_block_end in parser.py. The Go, C#/Java and Rust parsers repeated the brace_count += line.count('{') - line.count('}') scan eight times, three of them with the same "opening brace may be on one of the next 3 lines" lookahead. Those call sites are now one line each, e.g. end_line = _find_block_end(lines, i, lookahead=3). The Rust fn case keeps its multi-line-signature scan and only reuses _close_block.

3. Analyzer result construction → BaseAnalyzer._result_from_payload / _error_result. Gemini, OpenAI and Azure each built the same AnalysisResult(status=..., confidence=..., issues=..., summary=...) from the parsed JSON plus the same status="ERROR" fallback. get_analyzer also loses its three identical required-key loops in favour of a _PROVIDERS table.

4. Summary aggregation → new src/summary.py. ReportGenerator._generate_summary and differential.summarize_results were the same severity/confidence/status rollup with different extras; the shared function takes count_verification / count_issue_types flags and both callers keep their existing output shape. One deliberate consequence: an empty results list now summarises as UNCERTAIN rather than COMPLIANT in reports (all([]) == True previously made zero analysed files "compliant"); the differential path already behaved this way.

5. CLI. analyze and diff shared a 12-line except block and a 10-line banner/config-table block → _abort_on_error(e, verbose) and _print_info_panel(title, rows). diff also reimplemented differential.analyze_clients (per-client _run_analysis loop, ClientAnalysis assembly, engine build, LLM synthesis); it now calls that function, which gained an on_client_start callback so the CLI keeps printing per-client progress.

Testing

  • pytest: 165 passed, 2 skipped (16 new tests in tests/test_shared_utils.py cover the cache, brace helpers, summary flags and analyzer result helpers); ruff check src tests clean.
  • Parser equivalence checked against the pre-refactor parser.py on real client sources (state_transition.go, contracts.go, TxValidator.cs, MainnetTransactionProcessor.java, reth validation.rs, lib.rs) — identical CodeBlock output in every case.

Link to Devin session: https://app.devin.ai/sessions/be6024b1467446b8ad89f21886192779
Requested by: @Fosurero

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@Fosurero Fosurero self-assigned this Jul 24, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

2 participants