refactor(qa): conservative QARunner decomposition (E2)#58
Merged
Conversation
Relocate the already-standalone RerankerGate / RerankerGateContext / RerankerGateResult (no QARunner coupling) from runner.py to app/qa/reranker_gate.py, re-exported from runner.py so existing imports keep working (app/qa/gate_metrics.py and the bare RerankerGate call in run()). Pure relocation, zero logic change. Adds tests/qa/test_reranker_gate.py (should_rerank decision matrix + re-export identity) since this logic had NO prior test coverage. Full default suite: 319 passed. Refs #21
Move the three pure db-only helpers (_get_doc_total_pages, _get_doc_collection_version, _get_nodes_metadata) from QARunner into app/qa/metadata_queries.py as functions taking db; QARunner keeps thin delegating wrappers (signatures/call sites unchanged). Pure relocation. Adds tests/qa/test_metadata_queries.py (incl. the None/empty short-circuits that avoid a DB hit). Full suite: 325 passed. Refs #21
Move the pure regex _detect_structured_targets + its 4 patterns from QARunner into app/qa/structured_targets.py; QARunner aliases the patterns (back-compat) and delegates the method. MAX_INJECTED_SEEDS stays on QARunner (used by inject_structured_seeds, not extracted). Pure relocation. Adds tests/qa/test_structured_targets.py (figure/table/ appendix/section detection + delegation parity). Full suite: 330 passed. Refs #21
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.
E2 — conservative, behavior-preserving QARunner decomposition
Part of the remediation (
#25). Designed and adversarially reviewed by a workflow that deliberately scoped this small and safe — not a rewrite. Three commits, suite green after each; each extraction is a pure relocation/delegation, and because the audit foundQARunnerinternals are barely covered by the default suite, each ships a new focused characterization test.Extractions (runner.py: 2899 → 2677 lines)
RerankerGatetrio →app/qa/reranker_gate.py— already-standalone classes; re-exported fromrunner.pysofrom app.qa.runner import RerankerGate, RerankerGateContext(used bygate_metrics.py) and the bareRerankerGate.should_rerank()call keep working. +test_reranker_gate.py(full decision matrix).app/qa/metadata_queries.py— three pure db-only functions; QARunner keeps delegating wrappers. +test_metadata_queries.py(incl. the None/empty short-circuits)._detect_structured_targets+ patterns →app/qa/structured_targets.py— pure regex; QARunner aliases patterns + delegates. +test_structured_targets.py(detection + delegation parity).MAX_INJECTED_SEEDSstays on QARunner.Behavior-preserving
Every change is a verbatim move + delegation; method names/signatures/call sites and all constants/thresholds are unchanged; public imports preserved via re-exports. Default suite stayed green after each commit (330 passed).
Deferred (by design — need characterization tests / more entangled)
_call_llm_reranker, fallback search, node-by-label/section queries,inject_structured_seeds, expansion audit,_hydrate_citations, therun()/propagation orchestration. Noted for a future pass.Closes #21