Add module scaffolding script and test infrastructure - #12
Merged
Conversation
Automates new module creation, eliminating the need to manually create 14+ files and update config. The script generates the full module structure (pyproject.toml, module class, models, service, schemas, contracts, endpoints, deps, tests) and registers the module in host/pyproject.toml and root pyproject.toml. Also updates conftest.py to auto-discover module Base classes via entry points, so new modules' tables are automatically created in the test database. https://claude.ai/code/session_01G5HHXJfxAQ53grAwiyUzyj
- conftest.py: reuse framework's discover_modules() + all_module_bases instead of reimplementing entry point discovery; cache with lru_cache; batch create_all into single run_sync; extract _create_all_tables helper - new_module.py: replace hardcoded anchor strings with last-entry insertion via _insert_before_last(); add warnings on missing anchors - test_new_module.py: extract repeated setup into module_root fixture https://claude.ai/code/session_01G5HHXJfxAQ53grAwiyUzyj
Updates the scaffolding to match PR #8's layout change that removed the src/ directory from all workspace packages: - Generate files at modules/<name>/sm_<name>/ instead of modules/<name>/src/sm_<name>/ - Update root pyproject.toml to insert modules/<name> in ty paths (no /src suffix) - Rewrite insertion helpers with cleaner regex-based approach that correctly handles the new host/pyproject.toml structure with multiple sm-* dependencies https://claude.ai/code/session_01G5HHXJfxAQ53grAwiyUzyj
Adds coverage for previously untested code paths and behaviors: - _insert_after_last_match helper: 4 direct unit tests - create_file utility: 3 tests (content, parent dir creation, dedent) - main() CLI entry point: 2 tests (happy path + invalid name) - End-to-end subprocess test: verifies script runs standalone New TestUpdateRootPyproject cases: - Realistic multi-module pyproject.toml matching real repo - Skips when already present - Warns to stderr when no insertion point found New TestGeneratedFilesSyntaxValidity: - All generated Python files parse with ast.parse - Generated pyproject.toml parses with tomllib - Compound names (blog_posts) produce valid TOML New TestGeneratedTemplateContent covers: - service.py has full CRUD methods - endpoints/api.py has all REST endpoints with correct status codes - endpoints/views.py uses Inertia properly - deps.py provides DI function - contracts/service.py defines Protocol - contracts/__init__.py exports public API - module.py registers routes and permissions - models.py uses AuditMixin with correct tablename - test_<name>.py contains all expected test classes https://claude.ai/code/session_01G5HHXJfxAQ53grAwiyUzyj
- Add scaffolded_orders fixture: scaffold_module() now runs once per test rather than 10x in TestGeneratedTemplateContent - Add workspace fixture: deduplicates the host/pyproject + root pyproject setup between TestMainCLI tests - Extract MINIMAL_HOST_PYPROJECT and MINIMAL_ROOT_PYPROJECT constants - TestCreateFile: replace inline monkeypatch with the existing module_root fixture (3 tests collapsed to clean one-liners) - TestScaffoldModule: use scaffolded_orders fixture; eliminate repeated `module_root / "modules" / "orders" / "sm_orders"` path strings - TestGeneratedFilesSyntaxValidity: reuse scaffolded_orders for the orders-based tests - Drop TestCLIAsSubprocess: TestMainCLI::test_main_invokes_full_pipeline with capsys covers the same ground without a subprocess fork - Move `import new_module` to module level (reused by all fixtures) - Strip narrative comments 49 tests → 48 tests, suite time 0.58s → 0.42s https://claude.ai/code/session_01G5HHXJfxAQ53grAwiyUzyj
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 freeto 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
Add a comprehensive module scaffolding system that enables developers to quickly generate new modules for the Simple Module Python framework with a single command. This includes a production-ready
new_module.pyscript, extensive test coverage, and updates to the test infrastructure to support dynamically discovered modules.Key Changes
New Module Scaffolding Script (
scripts/new_module.py)802-line scaffolding tool that generates complete module structure with:
modules/<name>/pyproject.tomlwith entry points and dependenciesSmart naming conventions:
orders→Order)Automatic project file updates:
host/pyproject.tomldependenciespyproject.tomlfor type-checking and testsComprehensive Test Suite (
scripts/tests/test_new_module.py)Test Infrastructure Updates (
conftest.py)_ensure_models_imported()to import all discovered module models_create_all_tables()function creates tables for all module bases in a single transaction@lru_cacheto avoid redundant module discovery during test runsBuild System Updates (
Makefile)new-moduletarget for convenient scaffolding viamake new-module name=<module_name>Notable Implementation Details
_insert_after_last_match()helper finds the last matching line in TOML files to insert new entries in the correct location, handling edge cases like multiple existing modulesmodule_root,workspace,scaffolded_orders) enable isolated testing of scaffolding logicUsage
python scripts/new_module.py orders # or make new-module name=ordersThis generates a fully functional module with models, services, API endpoints, views, and tests ready for customization.
https://claude.ai/code/session_01G5HHXJfxAQ53grAwiyUzyj