// 使用已安装 Python 3.12+、uv 的 Linux agent；UI 项目需要浏览器系统依赖安装权限。
// 连接参数与凭据由 Jenkins 按项目注入 HTTP__BASE_URL / WEB__BASE_URL / DATABASE__*。
// 不预置凭据 ID、业务测试目录、定时任务或报告公开发布。
pipeline {
    agent any
    options {
        timeout(time: 30, unit: 'MINUTES')
        disableConcurrentBuilds()
        timestamps()
    }
    stages {
        stage('准备依赖') {
            steps {
                sh '''
                    uv sync --locked
                    if uv run --no-sync python -c "import playwright" >/dev/null 2>&1; then
                        uv run --no-sync playwright install --with-deps chromium
                    fi
                '''
            }
        }
        stage('代码质量') {
            steps {
                sh 'uv run --no-sync ruff check src/ tests/'
            }
        }
        stage('测试') {
            steps {
                sh 'uv run --no-sync pytest tests/ --cov=src --cov-report=xml --cov-report=html --junitxml=reports/junit.xml'
            }
        }
    }
    post {
        always {
            junit testResults: 'reports/junit.xml', allowEmptyResults: true
            archiveArtifacts artifacts: 'reports/**,htmlcov/**,coverage.xml', allowEmptyArchive: true
        }
    }
}
