|
| 1 | +"""Integration tests that run real commands (cdk, uv, git). |
| 2 | +
|
| 3 | +These tests require: |
| 4 | +- cdk installed (npm install -g aws-cdk) |
| 5 | +- uv installed |
| 6 | +- git installed |
| 7 | +- Network access to GitHub (for private deps) |
| 8 | +
|
| 9 | +Run with: uv run pytest -m integration |
| 10 | +Skip with: uv run pytest -m "not integration" |
| 11 | +""" |
| 12 | + |
| 13 | +import os |
| 14 | +import subprocess |
| 15 | +import tomllib |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | +from gds_idea_app_kit.init import run_init |
| 20 | +from gds_idea_app_kit.manifest import read_manifest |
| 21 | + |
| 22 | + |
| 23 | +@pytest.mark.integration |
| 24 | +def test_init_streamlit_end_to_end(tmp_path): |
| 25 | + """Full init creates a working streamlit project with all deps resolved.""" |
| 26 | + os.chdir(tmp_path) |
| 27 | + run_init(framework="streamlit", app_name="integ-test", python_version="3.13") |
| 28 | + |
| 29 | + project = tmp_path / "gds-idea-app-integ-test" |
| 30 | + |
| 31 | + # ---- Project structure ---- |
| 32 | + |
| 33 | + assert project.is_dir(), "Project directory should be created" |
| 34 | + |
| 35 | + # CDK files |
| 36 | + assert (project / "app.py").exists(), "CDK entry point should exist" |
| 37 | + assert (project / "cdk.json").exists(), "cdk.json should exist" |
| 38 | + |
| 39 | + # App source |
| 40 | + assert (project / "app_src" / "Dockerfile").exists() |
| 41 | + assert (project / "app_src" / "streamlit_app.py").exists() |
| 42 | + assert (project / "app_src" / "pyproject.toml").exists() |
| 43 | + |
| 44 | + # Dev container |
| 45 | + assert (project / ".devcontainer" / "devcontainer.json").exists() |
| 46 | + assert (project / ".devcontainer" / "docker-compose.yml").exists() |
| 47 | + |
| 48 | + # Dev mocks |
| 49 | + assert (project / "dev_mocks" / "dev_mock_authoriser.json").exists() |
| 50 | + assert (project / "dev_mocks" / "dev_mock_user.json").exists() |
| 51 | + |
| 52 | + # ---- Template variables substituted ---- |
| 53 | + |
| 54 | + dockerfile = (project / "app_src" / "Dockerfile").read_text() |
| 55 | + assert "python:3.13" in dockerfile, "Python version should be substituted in Dockerfile" |
| 56 | + assert "{{python_version}}" not in dockerfile, "Template placeholder should not remain" |
| 57 | + |
| 58 | + app_pyproject = (project / "app_src" / "pyproject.toml").read_text() |
| 59 | + assert "integ-test" in app_pyproject, "App name should be substituted in pyproject.toml" |
| 60 | + assert "{{app_name}}" not in app_pyproject, "Template placeholder should not remain" |
| 61 | + |
| 62 | + # ---- Root pyproject.toml config ---- |
| 63 | + |
| 64 | + with open(project / "pyproject.toml", "rb") as f: |
| 65 | + root_config = tomllib.load(f) |
| 66 | + |
| 67 | + webapp = root_config.get("tool", {}).get("webapp", {}) |
| 68 | + assert webapp.get("framework") == "streamlit" |
| 69 | + assert webapp.get("app_name") == "integ-test" |
| 70 | + |
| 71 | + # ---- Manifest ---- |
| 72 | + |
| 73 | + manifest = read_manifest(project) |
| 74 | + assert manifest, "Manifest should be written" |
| 75 | + assert manifest["framework"] == "streamlit" |
| 76 | + assert manifest["app_name"] == "integ-test" |
| 77 | + assert "files" in manifest, "Manifest should contain file hashes" |
| 78 | + assert len(manifest["files"]) > 0, "Manifest should track at least one file" |
| 79 | + |
| 80 | + # ---- Dependencies resolved ---- |
| 81 | + |
| 82 | + assert (project / "uv.lock").exists(), "uv.lock should be created by uv sync" |
| 83 | + assert (project / ".venv").is_dir(), ".venv should be created by uv sync" |
| 84 | + |
| 85 | + # ---- Git history ---- |
| 86 | + |
| 87 | + result = subprocess.run( |
| 88 | + ["git", "log", "--oneline"], |
| 89 | + cwd=project, |
| 90 | + capture_output=True, |
| 91 | + text=True, |
| 92 | + check=True, |
| 93 | + ) |
| 94 | + assert "Initial scaffold" in result.stdout, "Initial commit should exist" |
| 95 | + assert "streamlit" in result.stdout, "Commit message should mention the framework" |
| 96 | + |
| 97 | + # ---- .gitignore ---- |
| 98 | + |
| 99 | + gitignore = (project / ".gitignore").read_text() |
| 100 | + assert ".aws-dev" in gitignore, ".aws-dev should be in gitignore" |
| 101 | + assert "*.new" in gitignore, "*.new files should be in gitignore" |
0 commit comments