Compare commits

..

No commits in common. "main" and "feat/dynamic-content-counts" have entirely different histories.

5 changed files with 1 additions and 248 deletions

View File

@ -1,182 +0,0 @@
name: AcuPedia API CI
on:
push:
branches:
- main
- master
- develop
- 'release/**'
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install project and test dependencies
run: python -m pip install --upgrade pip && python -m pip install -e '.[dev]'
- name: Run test suite
run: python -m pytest
env:
ENVIRONMENT: test
JWT_SECRET: ci-only-test-secret-key-at-least-32-chars
REDIS_CACHE_ENABLED: "false"
coverage:
name: Test coverage
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install project and test dependencies
run: python -m pip install --upgrade pip && python -m pip install -e '.[dev]'
- name: Run tests with coverage
run: >-
python -m pytest
--cov=app
--cov-report=term-missing
--cov-report=xml:coverage.xml
--cov-report=html:htmlcov
env:
ENVIRONMENT: test
JWT_SECRET: ci-only-test-secret-key-at-least-32-chars
REDIS_CACHE_ENABLED: "false"
- name: Add coverage summary
if: always()
run: |
if [ -f coverage.xml ]; then
python -c 'import xml.etree.ElementTree as ET; r=ET.parse("coverage.xml").getroot(); rate=float(r.attrib.get("line-rate", 0))*100; print("## Coverage\n\nLine coverage: **{:.2f}%**".format(rate))' >> "$GITHUB_STEP_SUMMARY"
fi
deployment-test:
name: Build, deploy, and smoke test
runs-on: ci-docker
needs:
- tests
- coverage
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install project and runtime dependencies
run: python -m pip install --upgrade pip && python -m pip install -e .
- name: Start isolated PostgreSQL for container deployment
run: |
docker network create acupedia-ci || true
docker rm -f acupedia-postgres-ci >/dev/null 2>&1 || true
docker run -d --name acupedia-postgres-ci --network acupedia-ci \
-p 127.0.0.1:15432:5432 \
-e POSTGRES_DB=acupedia_ci \
-e POSTGRES_USER=acupedia \
-e POSTGRES_PASSWORD=ci-password \
postgres:16
for attempt in $(seq 1 30); do
if docker exec acupedia-postgres-ci pg_isready -U acupedia -d acupedia_ci; then
exit 0
fi
sleep 2
done
docker logs acupedia-postgres-ci
exit 1
- name: Apply database migrations
run: python -m alembic upgrade head
env:
DATABASE_URL: postgresql+asyncpg://acupedia:ci-password@127.0.0.1:15432/acupedia_ci
- name: Seed auth and commerce
run: |
acupedia-bootstrap auth
acupedia-bootstrap commerce
env:
DATABASE_URL: postgresql+asyncpg://acupedia:ci-password@127.0.0.1:15432/acupedia_ci
- name: Validate seeded database
run: acupedia-bootstrap validate
env:
DATABASE_URL: postgresql+asyncpg://acupedia:ci-password@127.0.0.1:15432/acupedia_ci
- name: Build API image
run: docker build --pull -t "$CI_IMAGE" .
env:
CI_IMAGE: acupedia-api:${{ github.sha }}
- name: Deploy API container for acceptance checks
run: |
docker rm -f acupedia-api-ci >/dev/null 2>&1 || true
docker run -d --name acupedia-api-ci --network acupedia-ci -p 127.0.0.1:18000:8000 \
-e DATABASE_URL=postgresql+asyncpg://acupedia:ci-password@acupedia-postgres-ci:5432/acupedia_ci \
-e CACHE_ENABLED=false \
-e ENVIRONMENT=test \
-e JWT_SECRET=ci-only-test-secret-key-at-least-32-chars \
"$CI_IMAGE"
env:
CI_IMAGE: acupedia-api:${{ github.sha }}
- name: Run HTTP smoke tests against deployed container
run: |
if ! python scripts/smoke_deployed_api.py; then
docker logs acupedia-api-ci
exit 1
fi
env:
ACUPEDIA_BASE_URL: http://127.0.0.1:18000
- name: Install isolated AWS CLI
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/'))
run: |
python -m venv .artifact-venv
.artifact-venv/bin/pip install --disable-pip-version-check awscli
- name: Package and publish immutable S3 artifact
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/'))
run: bash scripts/publish_s3_artifact.sh
env:
AWS_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.S3_REGION || 'us-east-1' }}
AWS_EC2_METADATA_DISABLED: "true"
S3_ENDPOINT_URL: ${{ secrets.S3_ENDPOINT_URL }}
S3_BUCKET: ${{ secrets.S3_BUCKET }}
CI_IMAGE: acupedia-api:${{ github.sha }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_REF_NAME: ${{ github.ref_name }}
GITHUB_RUN_ID: ${{ github.run_id }}
- name: Stop CI containers and network
if: always()
run: |
docker rm -f acupedia-api-ci acupedia-postgres-ci >/dev/null 2>&1 || true
docker network rm acupedia-ci >/dev/null 2>&1 || true

View File

@ -20,7 +20,6 @@ class Settings(BaseSettings):
app_env: Literal["local", "dev", "test", "stage", "prod"] = "local"
debug: bool = False
content_preview_enabled: bool = False
enable_module_repo_sync: bool = False
api_prefix: str = "/api/v1"
cors_origins: str = "http://localhost:3000,http://localhost:8000"

View File

@ -2,7 +2,6 @@ from __future__ import annotations
import io
from fastapi import APIRouter, Depends, HTTPException, Query, status
from fastapi.responses import HTMLResponse, StreamingResponse
from app.core.config import get_settings
from app.db.models import AppUser
from app.features.payments import get_razorpay_service
from .deps import get_admin_service, get_current_admin
@ -546,13 +545,6 @@ async def export_report_csv(
# MODULE BUILDER ENDPOINTS
# =============================================================================
@router.get("/module-builder/config")
async def get_builder_config(
admin: AppUser = Depends(get_current_admin),
):
return {"sync_repo_enabled": get_settings().enable_module_repo_sync}
@router.get("/module-builder/modules", response_model=list[BuilderModuleSummary])
async def list_builder_modules(
admin: AppUser = Depends(get_current_admin),
@ -793,11 +785,6 @@ async def sync_builder_module_to_repo(
admin: AppUser = Depends(get_current_admin),
service: AdminService = Depends(get_admin_service),
):
if not get_settings().enable_module_repo_sync:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Server repository sync is disabled in this environment.",
)
try:
return await service.builder.sync_content_repo(module_code)
except HTTPException:

View File

@ -75,7 +75,7 @@ class PatternClinicalData(BaseModel):
clinical_manifestations: list[str] = Field(default_factory=list)
tongue: str = ""
pulse: str = ""
treatment_principle: list[str] | str = ""
treatment_principle: str = ""
acupuncture: AcupunctureDetails = Field(default_factory=AcupunctureDetails)
explanation: list[str] = Field(default_factory=list)

View File

@ -1,51 +0,0 @@
from __future__ import annotations
from types import SimpleNamespace
from unittest.mock import AsyncMock, MagicMock
import pytest
from fastapi import HTTPException
from app.core.config import Settings
from app.features.admin import api as admin_api
def test_enable_module_repo_sync_defaults_to_false(monkeypatch):
monkeypatch.delenv("ENABLE_MODULE_REPO_SYNC", raising=False)
s = Settings(_env_file=None)
assert s.enable_module_repo_sync is False
@pytest.mark.asyncio
async def test_get_builder_config_reflects_setting(monkeypatch):
monkeypatch.setattr(admin_api, "get_settings", lambda: SimpleNamespace(enable_module_repo_sync=False))
res_off = await admin_api.get_builder_config(admin=MagicMock())
assert res_off == {"sync_repo_enabled": False}
monkeypatch.setattr(admin_api, "get_settings", lambda: SimpleNamespace(enable_module_repo_sync=True))
res_on = await admin_api.get_builder_config(admin=MagicMock())
assert res_on == {"sync_repo_enabled": True}
@pytest.mark.asyncio
async def test_sync_builder_module_to_repo_blocked_when_disabled(monkeypatch):
monkeypatch.setattr(admin_api, "get_settings", lambda: SimpleNamespace(enable_module_repo_sync=False))
service = SimpleNamespace(builder=SimpleNamespace(sync_content_repo=AsyncMock()))
with pytest.raises(HTTPException) as exc_info:
await admin_api.sync_builder_module_to_repo("m0042", admin=MagicMock(), service=service)
assert exc_info.value.status_code == 403
service.builder.sync_content_repo.assert_not_awaited()
@pytest.mark.asyncio
async def test_sync_builder_module_to_repo_allowed_when_enabled(monkeypatch):
monkeypatch.setattr(admin_api, "get_settings", lambda: SimpleNamespace(enable_module_repo_sync=True))
service = SimpleNamespace(
builder=SimpleNamespace(sync_content_repo=AsyncMock(return_value={"status": "synced"}))
)
res = await admin_api.sync_builder_module_to_repo("m0042", admin=MagicMock(), service=service)
assert res == {"status": "synced"}
service.builder.sync_content_repo.assert_awaited_once_with("m0042")