pipeline {
    agent { label 'python-browser' }
    options {
        skipDefaultCheckout(true)
        disableConcurrentBuilds()
        timeout(time: 15, unit: 'MINUTES')
    }
    stages {
        stage('Checkout') {
            steps {
                deleteDir()
                checkout scm
            }
        }
        stage('Environment') {
            steps {
                sh '''
                    python3 -m venv .venv
                    .venv/bin/python -m pip install -r requirements.txt
                    .venv/bin/python -m playwright install chromium
                '''
            }
        }
        stage('Test web') {
            steps {
                sh '.venv/bin/python -m pytest tests/web --browser chromium --junitxml=reports/web.xml --tracing=retain-on-failure --screenshot=only-on-failure'
            }
        }
    }
    post {
        always {
            junit testResults: 'reports/*.xml', allowEmptyResults: false
            archiveArtifacts artifacts: 'test-results/**/*', allowEmptyArchive: true
        }
    }
}
