Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ test-template-with-components: ## Test template with scheduler component include

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

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

# Enhanced template testing with specific component combinations
test-template-database: ## Test template with database component
@echo "🗄️ Testing database component template..."
@chmod -R +w ../test-database-stack 2>/dev/null || true
@rm -rf ../test-database-stack
@env -u VIRTUAL_ENV uv run aegis init test-database-stack --components database --output-dir .. --no-interactive --force --yes
@echo "📦 Installing dependencies and CLI..."
@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
@cd ../test-database-stack && env -u VIRTUAL_ENV uv pip install -e .
@echo "🔍 Running validation checks..."
@cd ../test-database-stack && env -u VIRTUAL_ENV make check
@echo "🧪 Testing CLI script installation..."
@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"
@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"
@echo "✅ Database template test completed successfully!"
@echo " Test project available in ../test-database-stack/"

test-template-worker: ## Test template with worker component
@echo "🔧 Testing worker component template..."
@chmod -R +w ../test-worker-stack 2>/dev/null || true
Expand All @@ -246,11 +262,11 @@ test-template-worker: ## Test template with worker component
@echo "✅ Worker template test completed successfully!"
@echo " Test project available in ../test-worker-stack/"

test-template-full: ## Test template with all components (worker + scheduler)
test-template-full: ## Test template with all components (worker + scheduler + database)
@echo "🌟 Testing full component template..."
@chmod -R +w ../test-full-stack 2>/dev/null || true
@rm -rf ../test-full-stack
@env -u VIRTUAL_ENV uv run aegis init test-full-stack --components worker,scheduler --output-dir .. --no-interactive --force --yes
@env -u VIRTUAL_ENV uv run aegis init test-full-stack --components worker,scheduler,database --output-dir .. --no-interactive --force --yes
@echo "📦 Installing dependencies and CLI..."
@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
@cd ../test-full-stack && env -u VIRTUAL_ENV uv pip install -e .
Expand All @@ -261,7 +277,7 @@ test-template-full: ## Test template with all components (worker + scheduler)
@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"
@echo "✅ Full stack template test completed successfully!"
@echo " Test project available in ../test-full-stack/"
@echo " Includes: backend, frontend, worker queues, scheduler, Redis"
@echo " Includes: backend, frontend, worker queues, scheduler, Redis, database"

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

.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
.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

# Default target
.DEFAULT_GOAL := help
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,9 @@ async def check_database_health() -> ComponentStatus:
except Exception as e:
# If any enhanced metadata collection fails, log but don't break
# health check
logger.debug("Failed to collect enhanced database metadata", exc_info=True)
logger.debug(
"Failed to collect enhanced database metadata", exc_info=True
)

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

except Exception as e:
# PRAGMA queries can fail in some SQLite configurations
logger.debug("Failed to collect SQLite PRAGMA settings", exc_info=True)
logger.debug(
"Failed to collect SQLite PRAGMA settings", exc_info=True
)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ known-first-party = ["app"]
[tool.mypy]
python_version = "{{ cookiecutter.python_version }}"
strict = true
plugins = ["pydantic.mypy"]

[[tool.mypy.overrides]]
module = "flet.*"
Expand Down

This file was deleted.

17 changes: 15 additions & 2 deletions tests/cli/test_database_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
No string-based test scripts!
"""

from collections.abc import Generator
from typing import Any

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

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

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

# Run the test
yield

# Clean up after test - drop all tables to ensure clean state
# This ensures test isolation without breaking the database connection
sql_model.metadata.drop_all(engine)

# Recreate tables for next test (they'll be empty)
sql_model.metadata.create_all(engine)

@pytest.mark.slow
def test_db_session_commits_on_success(
self, db_module: dict[str, Any], models: dict[str, Any]
Expand Down
24 changes: 23 additions & 1 deletion tests/cli/test_stack_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ def project_name(self) -> str:
],
expected_pyproject_deps=["fastapi", "flet", "arq", "apscheduler", "redis"],
),
StackCombination(
name="database",
components=["database"],
description="Base stack with SQLite database",
expected_files=[
"app/components/backend/",
"app/components/frontend/",
"app/core/db.py", # Database-specific file
"app/entrypoints/webserver.py",
"docker-compose.yml",
"pyproject.toml",
"Makefile",
],
expected_docker_services=["webserver"], # No database service for SQLite
expected_pyproject_deps=[
"fastapi",
"flet",
"sqlmodel",
"sqlalchemy",
"aiosqlite",
],
),
]


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

expected_combinations = {"base", "redis", "scheduler", "worker", "full"}
expected_combinations = {"base", "redis", "scheduler", "worker", "full", "database"}
assert combination_names == expected_combinations, (
f"Missing expected combinations. "
f"Expected: {expected_combinations}, "
Expand Down