Refactor CLI and runner into modular subcomponents#15
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the codebase to improve separation of concerns by extracting discovery and execution logic into dedicated modules, and splitting CLI helpers into focused submodules. The refactoring maintains backwards compatibility through re-exports.
Key changes:
- Extracted discovery functions (
discover_files,build_test_case) fromrunner.pyintodiscovery.py - Extracted execution functions (
run_test_case,run_cases) fromrunner.pyintoexecution.py - Moved
SQLAlchemyConnectorfromdb_connector.pyinto a newconnectors/package - Split CLI helpers into separate modules:
connections.py,discovery.py, andoutput.py - Updated CLI commands to use the new module structure with
build_connector(aliased asbuild_adapterfor compatibility)
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sqlcheck/runner.py | Converted to a re-export shim that maintains backwards compatibility for existing imports |
| sqlcheck/execution.py | New module containing test execution logic (run_test_case, run_cases) extracted from runner |
| sqlcheck/discovery.py | New module containing file discovery and test case building logic extracted from runner |
| sqlcheck/db_connector.py | Refactored to import and re-export SQLAlchemyConnector from the connectors package |
| sqlcheck/connectors/sqlalchemy.py | New module containing the SQLAlchemyConnector implementation moved from db_connector |
| sqlcheck/connectors/init.py | New package initialization that exports SQLAlchemyConnector |
| sqlcheck/cli/output.py | New module containing print_results function extracted from common.py |
| sqlcheck/cli/discovery.py | New module containing discover_cases function extracted from common.py |
| sqlcheck/cli/connections.py | New module containing connection resolution and connector building functions extracted from common.py |
| sqlcheck/cli/common.py | Converted to a re-export module for backwards compatibility with existing CLI imports |
| sqlcheck/cli/commands/run.py | Updated to import from new modular CLI helpers instead of common.py |
| sqlcheck/cli/commands/plan.py | Updated to import from new CLI discovery module instead of common.py |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from sqlcheck.models import FunctionResult, TestCase, TestResult | ||
|
|
||
|
|
||
| def run_test_case(case: TestCase, adapter: DBConnector, registry: FunctionRegistry) -> TestResult: |
There was a problem hiding this comment.
The parameter name 'adapter' is inconsistent with the refactoring goal of using 'connector' terminology. The CLI now uses 'connector' (via build_connector), but this function still uses 'adapter'. Consider renaming the parameter to 'connector' for consistency throughout the codebase.
|
|
||
| def run_cases( | ||
| cases: Iterable[TestCase], | ||
| adapter: DBConnector, |
There was a problem hiding this comment.
The parameter name 'adapter' is inconsistent with the refactoring goal of using 'connector' terminology. Consider renaming the parameter to 'connector' for consistency with the CLI layer and the renamed build_connector function.
Motivation
sqlcheck.runnerinto dedicated modules.build_connectorwhile keepingbuild_adapteras an alias).Description
sqlcheck/discovery.pywithdiscover_filesandbuild_test_case, andsqlcheck/execution.pywithrun_test_caseandrun_cases, and re-exported those fromsqlcheck/runner.pyvia__all__.sqlcheck/cli/connections.py,sqlcheck/cli/discovery.py, andsqlcheck/cli/output.py, and updatedsqlcheck/cli/common.pyto re-export the new helpers for compatibility.build_adapterusage withbuild_connector/build_adapteralias and moveddiscover_cases/print_resultsto the new modules).sqlcheck.connectorsand adjustedsqlcheck/db_connector.pyto import and re-exportSQLAlchemyConnectorwhile leaving the public API intact.Testing
uv run pytestand all tests completed successfully.35tests and reported35 passed.