FORGE-F008 Add unified testing toolkit for generated projects
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"version": 1,
|
||||
"manual": {
|
||||
"kind": "compose",
|
||||
"environment": "development",
|
||||
"file": "docker-compose.yml",
|
||||
"env_file": ".env.example",
|
||||
"project": "__APP_SLUG__",
|
||||
"ports": {"BORTSTACK_API_PORT": 5001, "BORTSTACK_WEB_PORT": 8081},
|
||||
"readiness": ["http://127.0.0.1:5001/api/health/ready", "http://127.0.0.1:8081/"],
|
||||
"urls": ["http://127.0.0.1:8081/"],
|
||||
"authentication": {"required": true, "provision": ["python3", "scripts/provision-test-user.py"]}
|
||||
},
|
||||
"automated": {
|
||||
"default": ["unit"],
|
||||
"suites": {
|
||||
"unit": {"command": ["./scripts/run-unit-tests.sh"], "cwd": "."},
|
||||
"integration": {"command": ["./scripts/run-integration-tests.sh"], "cwd": "."}
|
||||
},
|
||||
"act": []
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,38 @@ Windows PowerShell: create the virtual environment with `py -3 -m venv api/.venv
|
||||
|
||||
## Validation
|
||||
|
||||
The generated testing toolkit is available without Forge at runtime:
|
||||
|
||||
```sh
|
||||
./scripts/testtask.sh --start # Compose development services and local account
|
||||
./scripts/testtask.sh --status
|
||||
./scripts/testtask.sh --stop # stops only this worktree's Compose project
|
||||
./scripts/testrunner.sh --unit
|
||||
./scripts/testrunner.sh --integration
|
||||
```
|
||||
|
||||
The toolkit uses Git worktree metadata. Generate with `--git-init` or initialise
|
||||
Git locally before using the commands; an initial commit is not required for
|
||||
the current worktree. Explicit branch targets require a local branch ref and
|
||||
an existing checkout.
|
||||
|
||||
Configure a private local test account in `~/.config/bortstack/testing.env`
|
||||
with `BORTSTACK_TEST_EMAIL` and `BORTSTACK_TEST_PASSWORD`, then `chmod 600`
|
||||
that file. `testtask.sh` asks before using it and permits a one-session hidden
|
||||
password override. Non-interactive use requires `--use-default-credentials`.
|
||||
The generated development hook creates a verified account only in this
|
||||
worktree's Compose development database; an existing account is accepted only
|
||||
when its password matches. Compose uses ports 5001 and 8081 by default;
|
||||
adjust `.bortstack/testing.json` if they are occupied. Keep the same file's
|
||||
URLs in sync. The toolkit never removes the persistent SQLite volume.
|
||||
|
||||
`testrunner.sh` requires the documented Python virtual environment and
|
||||
`react/node_modules`; it does not install dependencies. `--act` is unavailable
|
||||
until a reviewed local-safe GitHub workflow/job is explicitly allowlisted in
|
||||
`.bortstack/testing.json`. The optional deployment workflow is not allowlisted.
|
||||
See the generated config and Forge's toolkit README for the schema and Windows
|
||||
requirements.
|
||||
|
||||
```sh
|
||||
cd api && .venv/bin/pytest
|
||||
cd react && npm run lint && npm test && npm run build
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Provision only this generated project's local Compose development account."""
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
project = os.environ.get("BORTSTACK_COMPOSE_PROJECT", "")
|
||||
compose_file = Path(os.environ.get("BORTSTACK_COMPOSE_FILE", ""))
|
||||
secret_file = Path(os.environ.get("BORTSTACK_CREDENTIALS_FILE", ""))
|
||||
if not project.startswith("bortstack-") or not compose_file.is_file() or not secret_file.is_file():
|
||||
raise SystemExit("local Compose project and temporary credentials are required")
|
||||
if os.environ.get("APP_ENV", "development") != "development":
|
||||
raise SystemExit("refusing account provisioning outside development")
|
||||
secret = json.loads(secret_file.read_text(encoding="utf-8"))
|
||||
if not secret.get("BORTSTACK_TEST_EMAIL") or not secret.get("BORTSTACK_TEST_PASSWORD"):
|
||||
raise SystemExit("missing local test credentials")
|
||||
base = ["docker", "compose", "--project-name", project, "--file", str(compose_file)]
|
||||
if subprocess.run(base + ["exec", "-T", "api", "flask", "--app", "api.py", "db", "upgrade"], check=False).returncode:
|
||||
raise SystemExit("local development migration failed")
|
||||
code = '''
|
||||
import json, sys
|
||||
from datetime import datetime
|
||||
from sqlalchemy import func
|
||||
from settings import app, db
|
||||
from models.user import User, normalize_email
|
||||
values = json.load(sys.stdin)
|
||||
email = normalize_email(values["BORTSTACK_TEST_EMAIL"])
|
||||
password = values["BORTSTACK_TEST_PASSWORD"]
|
||||
if len(password) < 8:
|
||||
raise SystemExit("test password must have at least eight characters")
|
||||
with app.app_context():
|
||||
existing = User.query.filter(func.lower(User.email) == email).first()
|
||||
if existing:
|
||||
if not existing.check_password(password) or existing.email_verified_at is None:
|
||||
raise SystemExit("test account exists with different credentials or is unverified; no account was changed")
|
||||
else:
|
||||
user = User(email=email, username="Local Test User", email_verified_at=datetime.utcnow())
|
||||
user.set_password(password)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
'''
|
||||
result = subprocess.run(base + ["exec", "-T", "api", "python", "-c", code],
|
||||
input=json.dumps(secret), text=True, check=False)
|
||||
sys.exit(result.returncode)
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
if [ ! -d "$root/react/node_modules" ]; then
|
||||
echo 'integration tests unavailable: install react/node_modules first' >&2
|
||||
exit 3
|
||||
fi
|
||||
(cd "$root/react" && npm run test:e2e)
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
if [ ! -x "$root/api/.venv/bin/python" ] || [ ! -d "$root/react/node_modules" ]; then
|
||||
echo 'unit tests unavailable: install api/.venv and react/node_modules first' >&2
|
||||
exit 3
|
||||
fi
|
||||
(cd "$root/api" && APP_ENV=testing .venv/bin/python -m pytest -c pytest.ini tests)
|
||||
(cd "$root/react" && npm test -- --run)
|
||||
@@ -8,7 +8,9 @@ from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
TOOLKIT = ROOT.parent.parent / "toolkits/testing/scripts"
|
||||
TOKEN_FILES = (".env.example", "docker-compose.yml", "react/index.html",
|
||||
".bortstack/testing.json",
|
||||
"react/src/config/site.js", "react/src/components/Logo/Logo.jsx",
|
||||
"ops/databases/postgres.env.example", "ops/databases/mysql.env.example",
|
||||
"ops/databases/mariadb.env.example")
|
||||
@@ -31,6 +33,8 @@ def generate(name, destination, git_init=False):
|
||||
try:
|
||||
shutil.copytree(ROOT / "source", target, symlinks=False, dirs_exist_ok=True)
|
||||
shutil.copytree(ROOT / "boilerplate", target, dirs_exist_ok=True)
|
||||
for tool_name in ("testtask.sh", "testrunner.sh", "target.py", "toolkit.py"):
|
||||
shutil.copy2(TOOLKIT / tool_name, target / "scripts" / tool_name)
|
||||
values = {"__PROJECT_NAME__": name, "__APP_SLUG__": slug,
|
||||
"__DATABASE_NAME__": slug.replace("-", "_")}
|
||||
for relative in TOKEN_FILES:
|
||||
|
||||
@@ -24,7 +24,7 @@ services:
|
||||
retries: 5
|
||||
start_period: 20s
|
||||
ports:
|
||||
- "127.0.0.1:5001:5000"
|
||||
- "127.0.0.1:${BORTSTACK_API_PORT:-5001}:5000"
|
||||
networks:
|
||||
- internal
|
||||
|
||||
@@ -48,7 +48,7 @@ services:
|
||||
retries: 5
|
||||
start_period: 10s
|
||||
ports:
|
||||
- "127.0.0.1:8081:80"
|
||||
- "127.0.0.1:${BORTSTACK_WEB_PORT:-8081}:80"
|
||||
networks:
|
||||
- internal
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
"development": ["Python 3.12", "Node.js 22", "npm"],
|
||||
"optional": ["Docker Compose", "Chromium/Playwright"]
|
||||
},
|
||||
"development_commands": ["cd api && flask --app api.py run", "cd react && npm run dev"],
|
||||
"validation_commands": ["cd api && pytest", "cd react && npm run lint && npm test && npm run build", "docker compose --env-file .env.example config --quiet"],
|
||||
"development_commands": ["./scripts/testtask.sh", "./scripts/testtask.sh --status", "./scripts/testtask.sh --stop"],
|
||||
"validation_commands": ["./scripts/testrunner.sh", "./scripts/testrunner.sh --all", "cd react && npm run lint && npm run build", "docker compose --env-file .env.example config --quiet"],
|
||||
"database_engines": ["SQLite", "PostgreSQL", "MySQL", "MariaDB"],
|
||||
"optional_capabilities": ["Resend outbound email", "PostgreSQL/MySQL/MariaDB production persistence", "Docker/nginx hosting", "SWAG integration", "GitHub Actions publishing/deployment"],
|
||||
"initial_context": "Fresh AGENTS.md and five docs records are generated; profile selection is delegated to bortstack-context/F007.",
|
||||
|
||||
Reference in New Issue
Block a user