Skip to content

Commit f34dd95

Browse files
committed
Template Testing
1 parent 3973bf9 commit f34dd95

6 files changed

Lines changed: 67 additions & 151 deletions

File tree

Makefile

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ test-template-with-components: ## Test template with scheduler component include
185185

186186
clean-test-projects: ## Remove all generated test project directories
187187
@echo "🧹 Cleaning up test projects..."
188-
@chmod -R +w ../test-basic-stack ../test-component-stack ../test-worker-stack ../test-full-stack 2>/dev/null || true
189-
@rm -rf ../test-basic-stack ../test-component-stack ../test-worker-stack ../test-full-stack 2>/dev/null || true
188+
@chmod -R +w ../test-basic-stack ../test-component-stack ../test-worker-stack ../test-database-stack ../test-full-stack 2>/dev/null || true
189+
@rm -rf ../test-basic-stack ../test-component-stack ../test-worker-stack ../test-database-stack ../test-full-stack 2>/dev/null || true
190190
@echo "✅ Test projects cleaned up"
191191

192192
# ============================================================================
@@ -230,6 +230,22 @@ test-stacks-full: ## Full stack matrix testing pipeline (comprehensive but slow)
230230
@echo " All component combinations can generate, build, and pass quality checks"
231231

232232
# Enhanced template testing with specific component combinations
233+
test-template-database: ## Test template with database component
234+
@echo "🗄️ Testing database component template..."
235+
@chmod -R +w ../test-database-stack 2>/dev/null || true
236+
@rm -rf ../test-database-stack
237+
@env -u VIRTUAL_ENV uv run aegis init test-database-stack --components database --output-dir .. --no-interactive --force --yes
238+
@echo "📦 Installing dependencies and CLI..."
239+
@cd ../test-database-stack && chmod -R +w .venv 2>/dev/null || true && rm -rf .venv && env -u VIRTUAL_ENV uv sync --extra dev --extra docs
240+
@cd ../test-database-stack && env -u VIRTUAL_ENV uv pip install -e .
241+
@echo "🔍 Running validation checks..."
242+
@cd ../test-database-stack && env -u VIRTUAL_ENV make check
243+
@echo "🧪 Testing CLI script installation..."
244+
@cd ../test-database-stack && env -u VIRTUAL_ENV uv run test-database-stack --help >/dev/null && echo "✅ CLI script 'test-database-stack --help' works" || echo "⚠️ CLI script test failed"
245+
@cd ../test-database-stack && env -u VIRTUAL_ENV uv run test-database-stack health status --help >/dev/null && echo "✅ Health commands available" || echo "⚠️ Health command test failed"
246+
@echo "✅ Database template test completed successfully!"
247+
@echo " Test project available in ../test-database-stack/"
248+
233249
test-template-worker: ## Test template with worker component
234250
@echo "🔧 Testing worker component template..."
235251
@chmod -R +w ../test-worker-stack 2>/dev/null || true
@@ -246,11 +262,11 @@ test-template-worker: ## Test template with worker component
246262
@echo "✅ Worker template test completed successfully!"
247263
@echo " Test project available in ../test-worker-stack/"
248264

249-
test-template-full: ## Test template with all components (worker + scheduler)
265+
test-template-full: ## Test template with all components (worker + scheduler + database)
250266
@echo "🌟 Testing full component template..."
251267
@chmod -R +w ../test-full-stack 2>/dev/null || true
252268
@rm -rf ../test-full-stack
253-
@env -u VIRTUAL_ENV uv run aegis init test-full-stack --components worker,scheduler --output-dir .. --no-interactive --force --yes
269+
@env -u VIRTUAL_ENV uv run aegis init test-full-stack --components worker,scheduler,database --output-dir .. --no-interactive --force --yes
254270
@echo "📦 Installing dependencies and CLI..."
255271
@cd ../test-full-stack && chmod -R +w .venv 2>/dev/null || true && rm -rf .venv && env -u VIRTUAL_ENV uv sync --extra dev --extra docs
256272
@cd ../test-full-stack && env -u VIRTUAL_ENV uv pip install -e .
@@ -261,7 +277,7 @@ test-template-full: ## Test template with all components (worker + scheduler)
261277
@cd ../test-full-stack && env -u VIRTUAL_ENV uv run test-full-stack health status --help >/dev/null && echo "✅ Health commands available" || echo "⚠️ Health command test failed"
262278
@echo "✅ Full stack template test completed successfully!"
263279
@echo " Test project available in ../test-full-stack/"
264-
@echo " Includes: backend, frontend, worker queues, scheduler, Redis"
280+
@echo " Includes: backend, frontend, worker queues, scheduler, Redis, database"
265281

266282
# Quick component testing for development workflow
267283
test-component-quick: ## Quick test of specific component (set COMPONENT=worker|scheduler)
@@ -277,7 +293,7 @@ endif
277293
@echo "✅ $(COMPONENT) component generated successfully in ../test-$(COMPONENT)-quick/"
278294
@echo " Run 'cd ../test-$(COMPONENT)-quick && make check' to validate"
279295

280-
.PHONY: test lint fix format typecheck check install clean docs-serve docs-build cli-test redis-start redis-stop redis-cli redis-logs redis-stats redis-reset redis-queues redis-workers redis-failed redis-monitor redis-info test-template-quick test-template test-template-with-components test-template-worker test-template-full test-component-quick test-stacks test-stacks-build test-stacks-runtime test-stacks-full clean-test-projects help
296+
.PHONY: test lint fix format typecheck check install clean docs-serve docs-build cli-test redis-start redis-stop redis-cli redis-logs redis-stats redis-reset redis-queues redis-workers redis-failed redis-monitor redis-info test-template-quick test-template test-template-with-components test-template-database test-template-worker test-template-full test-component-quick test-stacks test-stacks-build test-stacks-runtime test-stacks-full clean-test-projects help
281297

282298
# Default target
283299
.DEFAULT_GOAL := help

aegis/templates/cookiecutter-aegis-project/{{cookiecutter.project_slug}}/app/services/system/health.py.j2

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,9 @@ async def check_database_health() -> ComponentStatus:
648648
except Exception as e:
649649
# If any enhanced metadata collection fails, log but don't break
650650
# health check
651-
logger.debug("Failed to collect enhanced database metadata", exc_info=True)
651+
logger.debug(
652+
"Failed to collect enhanced database metadata", exc_info=True
653+
)
652654

653655
# Test database connection and collect PRAGMA settings
654656
with db_session(autocommit=False) as session:
@@ -682,7 +684,9 @@ async def check_database_health() -> ComponentStatus:
682684

683685
except Exception as e:
684686
# PRAGMA queries can fail in some SQLite configurations
685-
logger.debug("Failed to collect SQLite PRAGMA settings", exc_info=True)
687+
logger.debug(
688+
"Failed to collect SQLite PRAGMA settings", exc_info=True
689+
)
686690

687691
# No need to commit since we're just testing connectivity
688692

aegis/templates/cookiecutter-aegis-project/{{cookiecutter.project_slug}}/pyproject.toml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ known-first-party = ["app"]
9898
[tool.mypy]
9999
python_version = "{{ cookiecutter.python_version }}"
100100
strict = true
101+
plugins = ["pydantic.mypy"]
101102

102103
[[tool.mypy.overrides]]
103104
module = "flet.*"

aegis/templates/cookiecutter-aegis-project/{{cookiecutter.project_slug}}/test_redis.py

Lines changed: 0 additions & 140 deletions
This file was deleted.

tests/cli/test_database_runtime.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
No string-based test scripts!
77
"""
88

9+
from collections.abc import Generator
910
from typing import Any
1011

1112
import pytest
@@ -22,8 +23,10 @@ def models(self, db_module: dict[str, Any]) -> dict[str, Any]:
2223
return result
2324

2425
@pytest.fixture(autouse=True)
25-
def setup_tables(self, db_module: dict[str, Any], models: dict[str, Any]) -> None:
26-
"""Create test tables before each test."""
26+
def setup_tables(
27+
self, db_module: dict[str, Any], models: dict[str, Any]
28+
) -> Generator[None, None, None]:
29+
"""Create test tables before each test and clean up after."""
2730
# Create data directory for database if it doesn't exist
2831
import os
2932

@@ -34,6 +37,16 @@ def setup_tables(self, db_module: dict[str, Any], models: dict[str, Any]) -> Non
3437
sql_model = db_module["SQLModel"]
3538
sql_model.metadata.create_all(engine)
3639

40+
# Run the test
41+
yield
42+
43+
# Clean up after test - drop all tables to ensure clean state
44+
# This ensures test isolation without breaking the database connection
45+
sql_model.metadata.drop_all(engine)
46+
47+
# Recreate tables for next test (they'll be empty)
48+
sql_model.metadata.create_all(engine)
49+
3750
@pytest.mark.slow
3851
def test_db_session_commits_on_success(
3952
self, db_module: dict[str, Any], models: dict[str, Any]

tests/cli/test_stack_generation.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,28 @@ def project_name(self) -> str:
146146
],
147147
expected_pyproject_deps=["fastapi", "flet", "arq", "apscheduler", "redis"],
148148
),
149+
StackCombination(
150+
name="database",
151+
components=["database"],
152+
description="Base stack with SQLite database",
153+
expected_files=[
154+
"app/components/backend/",
155+
"app/components/frontend/",
156+
"app/core/db.py", # Database-specific file
157+
"app/entrypoints/webserver.py",
158+
"docker-compose.yml",
159+
"pyproject.toml",
160+
"Makefile",
161+
],
162+
expected_docker_services=["webserver"], # No database service for SQLite
163+
expected_pyproject_deps=[
164+
"fastapi",
165+
"flet",
166+
"sqlmodel",
167+
"sqlalchemy",
168+
"aiosqlite",
169+
],
170+
),
149171
]
150172

151173

@@ -239,7 +261,7 @@ def test_stack_combinations_comprehensive() -> None:
239261
# Verify we have tests for basic patterns
240262
combination_names = {combo.name for combo in STACK_COMBINATIONS}
241263

242-
expected_combinations = {"base", "redis", "scheduler", "worker", "full"}
264+
expected_combinations = {"base", "redis", "scheduler", "worker", "full", "database"}
243265
assert combination_names == expected_combinations, (
244266
f"Missing expected combinations. "
245267
f"Expected: {expected_combinations}, "

0 commit comments

Comments
 (0)