Skip to content

Refactor CLI and runner into modular subcomponents#15

Merged
luisggc merged 4 commits into
mainfrom
refactor-sqlcheck-for-modularity-and-simplicity
Jan 2, 2026
Merged

Refactor CLI and runner into modular subcomponents#15
luisggc merged 4 commits into
mainfrom
refactor-sqlcheck-for-modularity-and-simplicity

Conversation

@luisggc
Copy link
Copy Markdown
Owner

@luisggc luisggc commented Jan 2, 2026

Motivation

  • Improve separation of concerns by extracting discovery and execution logic out of sqlcheck.runner into dedicated modules.
  • Make CLI helper responsibilities explicit by splitting connection resolution, discovery, and output formatting into separate modules.
  • Preserve backwards compatibility for existing imports by keeping re-export shims where appropriate.
  • Clarify connector naming in the CLI flow (build_connector while keeping build_adapter as an alias).

Description

  • Added sqlcheck/discovery.py with discover_files and build_test_case, and sqlcheck/execution.py with run_test_case and run_cases, and re-exported those from sqlcheck/runner.py via __all__.
  • Introduced CLI helper modules sqlcheck/cli/connections.py, sqlcheck/cli/discovery.py, and sqlcheck/cli/output.py, and updated sqlcheck/cli/common.py to re-export the new helpers for compatibility.
  • Updated CLI commands to use the new helpers (replaced direct build_adapter usage with build_connector/build_adapter alias and moved discover_cases/print_results to the new modules).
  • Kept connector implementation organized under sqlcheck.connectors and adjusted sqlcheck/db_connector.py to import and re-export SQLAlchemyConnector while leaving the public API intact.

Testing

  • Ran uv run pytest and all tests completed successfully.
  • Test suite collected and ran 35 tests and reported 35 passed.
  • No automated tests failed during the change set execution.
  • The change preserves existing CLI behavior while improving module organization.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) from runner.py into discovery.py
  • Extracted execution functions (run_test_case, run_cases) from runner.py into execution.py
  • Moved SQLAlchemyConnector from db_connector.py into a new connectors/ package
  • Split CLI helpers into separate modules: connections.py, discovery.py, and output.py
  • Updated CLI commands to use the new module structure with build_connector (aliased as build_adapter for 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.

Comment thread sqlcheck/execution.py Outdated
from sqlcheck.models import FunctionResult, TestCase, TestResult


def run_test_case(case: TestCase, adapter: DBConnector, registry: FunctionRegistry) -> TestResult:
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread sqlcheck/execution.py Outdated

def run_cases(
cases: Iterable[TestCase],
adapter: DBConnector,
Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@luisggc luisggc merged commit 0fd6a46 into main Jan 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants