style: format Python files for CI

This commit is contained in:
Xiaoxia AI
2026-06-24 19:54:36 +08:00
parent 1c883ec704
commit f85e389ced
19 changed files with 583 additions and 354 deletions
+26 -25
View File
@@ -32,23 +32,23 @@ def test_deploy_production_uses_production_infra_and_project():
assert "Skipping production API/worker image builds" in script
assert "RELEASE_VERSION" in script
assert "RUNTIME_IMAGE_TAR" in script
assert "docker load -i \"$RUNTIME_IMAGE_TAR\"" in script
assert 'docker load -i "$RUNTIME_IMAGE_TAR"' in script
assert 'export APP_VERSION="$RELEASE_VERSION"' in script
assert 'export WORKER_CONCURRENCY="${WORKER_CONCURRENCY:-1}"' in script
assert 'export WORKER_MAX_TASKS_PER_CHILD="${WORKER_MAX_TASKS_PER_CHILD:-100}"' in script
assert "docker image inspect \"${API_IMAGE:-xiaoxia-saas-api:dev}\"" in script
assert "docker image inspect \"${WORKER_IMAGE:-xiaoxia-saas-worker:dev}\"" in script
assert 'docker image inspect "${API_IMAGE:-xiaoxia-saas-api:dev}"' in script
assert 'docker image inspect "${WORKER_IMAGE:-xiaoxia-saas-worker:dev}"' in script
assert "ALLOW_PRODUCTION_BUILDS=true" in script
assert "xiaoxia-postgres-production" in script
assert "xiaoxia-redis-production" in script
assert "xiaoxia-postgres\n" not in script
assert "xiaoxia-redis\n" not in script
assert "COMPOSE_PROJECT_NAME=xiaoxia-production-app" in script
assert "--env-file \"$ENV_FILE\"" in script
assert '--env-file "$ENV_FILE"' in script
assert "python /app/scripts/validate_release_env.py --from-environ --strict-external" in script
assert "alembic upgrade head" in script
assert "docker compose --env-file \"$ENV_FILE\" up -d api worker" in script
assert "docker compose --env-file \"$ENV_FILE\" up -d --force-recreate web" in script
assert 'docker compose --env-file "$ENV_FILE" up -d api worker' in script
assert 'docker compose --env-file "$ENV_FILE" up -d --force-recreate web' in script
assert "nginx resolves the current API container IP" in script
assert "/etc/cron.d/xiaoxia-production-resource-check" in script
assert "EXPECTED_VERSION=$RELEASE_VERSION" in script
@@ -58,10 +58,10 @@ def test_production_workflow_preserves_previous_web_assets():
workflow = Path(".gitea/workflows/deploy.yml").read_text(encoding="utf-8")
production_section = workflow.split("deploy-production:", 1)[1]
assert "old_assets_dir=\"/tmp/xiaoxia-previous-web-assets-${RELEASE_VERSION}\"" in production_section
assert "docker cp xiaoxia-web-production:/usr/share/nginx/html/assets/. \"$old_assets_dir\"/" in production_section
assert "cp -a /var/lib/xiaoxia-saas-production/repo/apps/web/dist/assets/. \"$old_assets_dir\"/" in production_section
assert "if [ ! -e \"/var/lib/xiaoxia-saas-production/repo/apps/web/dist/assets/$name\" ]; then" in production_section
assert 'old_assets_dir="/tmp/xiaoxia-previous-web-assets-${RELEASE_VERSION}"' in production_section
assert 'docker cp xiaoxia-web-production:/usr/share/nginx/html/assets/. "$old_assets_dir"/' in production_section
assert 'cp -a /var/lib/xiaoxia-saas-production/repo/apps/web/dist/assets/. "$old_assets_dir"/' in production_section
assert 'if [ ! -e "/var/lib/xiaoxia-saas-production/repo/apps/web/dist/assets/$name" ]; then' in production_section
def test_production_deploy_recreates_web_after_api_for_nginx_dns():
@@ -82,7 +82,7 @@ def test_production_nginx_static_upstream_requires_web_recreate():
assert "client_max_body_size 800m;" in config
assert "proxy_read_timeout 300s;" in config
assert "proxy_request_buffering off;" in config
assert 'location = /index.html' in config
assert "location = /index.html" in config
assert 'Cache-Control "no-store, no-cache, must-revalidate" always' in config
assert "--force-recreate web" in script
@@ -128,7 +128,7 @@ def test_deploy_scripts_build_web_image_explicitly():
compose = Path("infra/docker/compose.yml").read_text(encoding="utf-8")
assert "docker compose build --pull=false web" in staging_script
assert "docker compose --env-file \"$ENV_FILE\" build --pull=false web" in production_script
assert 'docker compose --env-file "$ENV_FILE" build --pull=false web' in production_script
assert "dockerfile: ${WEB_DOCKERFILE:-infra/docker/web.Dockerfile}" in compose
assert "NGINX_CONF: ${WEB_NGINX_CONF:-infra/docker/nginx.conf}" in compose
assert "APP_VERSION: ${APP_VERSION:-0.1.0}" in compose
@@ -139,8 +139,8 @@ def test_production_deploy_prunes_old_unused_docker_artifacts():
script = Path("infra/docker/deploy-production.sh").read_text(encoding="utf-8")
assert "PRUNE_UNUSED_DOCKER_AFTER_DEPLOY" in script
assert "docker image prune -af --filter \"until=168h\"" in script
assert "docker builder prune -af --filter \"until=168h\"" in script
assert 'docker image prune -af --filter "until=168h"' in script
assert 'docker builder prune -af --filter "until=168h"' in script
def test_worker_runtime_is_constrained_by_environment():
@@ -149,6 +149,7 @@ def test_worker_runtime_is_constrained_by_environment():
assert "--concurrency=${WORKER_CONCURRENCY:-1}" in dockerfile
assert "--max-tasks-per-child=${WORKER_MAX_TASKS_PER_CHILD:-100}" in dockerfile
def test_production_nginx_proxies_to_production_api_container():
config = Path("infra/docker/nginx-production.conf").read_text(encoding="utf-8")
@@ -218,7 +219,7 @@ def test_gitea_production_deploy_requires_runtime_builder_job():
production_section = workflow.split("deploy-production:", 1)[1]
assert "runs-on: runtime-builder" in build_section
assert "scripts/build_release_images.sh \"${GITHUB_REF_NAME}\"" in build_section
assert 'scripts/build_release_images.sh "${GITHUB_REF_NAME}"' in build_section
assert "GITHUB_TOKEN: ${{ github.token }}" in build_section
assert "docker.m.daocloud.io/library/node:20" in build_section
assert "npm ci && npm run build" in build_section
@@ -234,10 +235,12 @@ def test_gitea_production_deploy_requires_runtime_builder_job():
assert "needs: build-production-runtime-images" in production_section
assert "runs-on: runtime-builder" in production_section
assert "Deploy production over SSH" in production_section
assert "release_tar=\"/var/lib/xiaoxia-saas-production/release-${RELEASE_VERSION}.tar.gz\"" in production_section
assert 'release_tar="/var/lib/xiaoxia-saas-production/release-${RELEASE_VERSION}.tar.gz"' in production_section
assert "runtime-images-${RELEASE_VERSION}.tar" in production_section
assert "apps/web/dist/index.html" in production_section
assert "HOST_PREFIX= sh /var/lib/xiaoxia-saas-production/repo/infra/docker/deploy-production.sh" in production_section
assert (
"HOST_PREFIX= sh /var/lib/xiaoxia-saas-production/repo/infra/docker/deploy-production.sh" in production_section
)
def test_build_host_runbook_requires_off_production_runtime_builds():
@@ -283,12 +286,12 @@ def test_runtime_image_release_scripts_keep_builds_off_production():
assert "Refusing to build runtime images on a host that is running production services." in build_script
assert "ALLOW_SHARED_PRODUCTION_BUILD_HOST=true" in build_script
assert "docker load -i" in deploy_script
assert "API_IMAGE=\"xiaoxia-saas-api:$VERSION\"" in deploy_script
assert "WORKER_IMAGE=\"xiaoxia-saas-worker:$VERSION\"" in deploy_script
assert 'API_IMAGE="xiaoxia-saas-api:$VERSION"' in deploy_script
assert 'WORKER_IMAGE="xiaoxia-saas-worker:$VERSION"' in deploy_script
assert "ALLOW_PRODUCTION_BUILDS=false" in deploy_script
assert "docker compose --env-file \"$ENV_FILE\" build --pull=false web" in deploy_script
assert "docker compose --env-file \"$ENV_FILE\" build --pull=false api" not in deploy_script
assert "docker compose --env-file \"$ENV_FILE\" build --pull=false worker" not in deploy_script
assert 'docker compose --env-file "$ENV_FILE" build --pull=false web' in deploy_script
assert 'docker compose --env-file "$ENV_FILE" build --pull=false api' not in deploy_script
assert 'docker compose --env-file "$ENV_FILE" build --pull=false worker' not in deploy_script
def test_production_release_checklist_matches_automatic_release_contract():
@@ -306,9 +309,7 @@ def test_production_release_checklist_matches_automatic_release_contract():
def test_release_automation_retrospective_records_failed_probe_tags():
retrospective = Path("docs/RELEASE-AUTOMATION-RETROSPECTIVE-2026-06-22.md").read_text(
encoding="utf-8"
)
retrospective = Path("docs/RELEASE-AUTOMATION-RETROSPECTIVE-2026-06-22.md").read_text(encoding="utf-8")
assert "v0.1.9" in retrospective
assert "first verified end-to-end automatic production release" in retrospective