Refactor duplicated code into shared utilities - #26
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Refactor duplicated code into shared utilities#26devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.SpecFetcherandCodeFetchereach 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"), andclear_cache/list_cached_*. Both now subclassCachedGitHubFetcher:Cache-file names, directory defaults, the GitHub
Acceptheader onCodeFetcher, andSpecFetcher.list_cached_specs()are all preserved.2. Brace-block scanning →
_brace_delta/_close_block/_find_block_endinparser.py. The Go, C#/Java and Rust parsers repeated thebrace_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 Rustfncase 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 sameAnalysisResult(status=..., confidence=..., issues=..., summary=...)from the parsed JSON plus the samestatus="ERROR"fallback.get_analyzeralso loses its three identicalrequired-key loops in favour of a_PROVIDERStable.4. Summary aggregation → new
src/summary.py.ReportGenerator._generate_summaryanddifferential.summarize_resultswere the same severity/confidence/status rollup with different extras; the shared function takescount_verification/count_issue_typesflags and both callers keep their existing output shape. One deliberate consequence: an empty results list now summarises asUNCERTAINrather thanCOMPLIANTin reports (all([]) == Truepreviously made zero analysed files "compliant"); the differential path already behaved this way.5. CLI.
analyzeanddiffshared a 12-lineexceptblock and a 10-line banner/config-table block →_abort_on_error(e, verbose)and_print_info_panel(title, rows).diffalso reimplementeddifferential.analyze_clients(per-client_run_analysisloop,ClientAnalysisassembly, engine build, LLM synthesis); it now calls that function, which gained anon_client_startcallback so the CLI keeps printing per-client progress.Testing
pytest: 165 passed, 2 skipped (16 new tests intests/test_shared_utils.pycover the cache, brace helpers, summary flags and analyzer result helpers);ruff check src testsclean.parser.pyon real client sources (state_transition.go,contracts.go,TxValidator.cs,MainnetTransactionProcessor.java, rethvalidation.rs,lib.rs) — identicalCodeBlockoutput in every case.Link to Devin session: https://app.devin.ai/sessions/be6024b1467446b8ad89f21886192779
Requested by: @Fosurero