Communitygithub.com

Quarkus 验证循环

Quarkus 项目的验证循环:构建、静态分析、覆盖率测试、安全扫描、原生编译和差异审查,适用于发布前或 PR 前。

Quarkus 验证循环 是什么?

此技能为 Quarkus 项目提供了一套完整的验证循环流程,覆盖从构建到部署的十个阶段。它指导用户或 AI 代理在 PR 提交前、重大重构后或预部署时运行此流程,以确保代码质量、测试覆盖率和安全性。适用平台包括本地终端、GitHub Actions 等 CI/CD 环境。工作流程包括 Maven/Gradle 构建、Checkstyle/PMD/SonarQube 静态分析、JUnit 测试与 JaCoCo 覆盖率检查(目标 80%+)、OWASP 依赖安全扫描、GraalVM 原生编译测试、K6 性能测试、健康检查、容器构建与安全扫描,以及配置和文档验证。每个阶段都提供了具体的命令、Java 代码示例和检查清单,支持自动化和手动审查,帮助团队在早期发现并修复问题,避免技术债务累积。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/quarkus-verification

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Quarkus 验证循环 是做什么的?

在 PR 前、重大变更后和预部署时运行。

何时激活

  • 在打开 Quarkus 服务的 Pull Request 之前
  • 在重大重构或依赖项升级之后
  • 针对预发或生产环境的预部署验证
  • 运行完整的构建 → 代码检查 → 测试 → 安全扫描 → 原生编译管道
  • 验证测试覆盖率是否达到阈值 (80%+)
  • 测试原生镜像兼容性

阶段 1:构建

# Maven
mvn clean verify -DskipTests

# Gradle
./gradlew clean assemble -x test

如果构建失败,请停止并修复编译错误。

阶段 2:静态分析

Checkstyle, PMD, SpotBugs (Maven)

mvn checkstyle:check pmd:check spotbugs:check

SonarQube (如果已配置)

mvn sonar:sonar \
  -Dsonar.projectKey=my-quarkus-project \
  -Dsonar.host.url=http://localhost:9000 \
  -Dsonar.login=${SONAR_TOKEN}

需要处理的常见问题

  • 未使用的导入或变量
  • 复杂的方法 (高圈复杂度)
  • 潜在的空指针解引用
  • SpotBugs 标记的安全问题

阶段 3:测试 + 覆盖率

# 运行所有测试
mvn clean test

# 生成覆盖率报告
mvn jacoco:report

# 强制覆盖率阈值 (80%)
mvn jacoco:check

# 或者使用 Gradle
./gradlew test jacocoTestReport jacocoTestCoverageVerification

测试类别

单元测试

使用 mocked 依赖项测试服务逻辑:

@ExtendWith(MockitoExtension.class)
class UserServiceTest {
  @Mock UserRepository userRepository;
  @InjectMocks UserService userService;

  @Test
  void createUser_validInput_returnsUser() {
    var dto = new CreateUserDto("Alice", "[email protected]");

    // Panache persist() 是 void — 使用 doNothing + verify
    doNothing().when(userRepository).persist(any(User.class));

    User result = userService.create(dto);

    assertThat(result.name).isEqualTo("Alice");
    verify(userRepository).persist(any(User.class));
  }
}

集成测试

使用真实数据库 (Testcontainers) 测试:

@QuarkusTest
@QuarkusTestResource(PostgresTestResource.class)
class UserRepositoryIntegrationTest {

  @Inject
  UserRepository userRepository;

  @Test
  @Transactional
  void findByEmail_existingUser_returnsUser() {
    User user = new User();
    user.name = "Alice";
    user.email = "[email protected]";
    userRepository.persist(user);

    Optional<User> found = userRepository.findByEmail("[email protected]");

    assertThat(found).isPresent();
    assertThat(found.get().name).isEqualTo("Alice");
  }
}

API 测试

使用 REST Assured 测试 REST 端点:

@QuarkusTest
class UserResourceTest {

  @Test
  void createUser_validInput_returns201() {
    given()
        .contentType(ContentType.JSON)
        .body("""
            {"name": "Alice", "email": "[email protected]"}
            """)
        .when().post("/api/users")
        .then()
        .statusCode(201)
        .body("name", equalTo("Alice"));
  }

  @Test
  void createUser_invalidEmail_returns400() {
    given()
        .contentType(ContentType.JSON)
        .body("""
            {"name": "Alice", "email": "invalid"}
            """)
        .when().post("/api/users")
        .then()
        .statusCode(400);
  }
}

覆盖率报告

查看 target/site/jacoco/index.html 获取详细覆盖率:

  • 总体行覆盖率 (目标: 80%+)
  • 分支覆盖率 (目标: 70%+)
  • 识别未覆盖的关键路径

阶段 4:安全扫描

依赖项漏洞 (Maven)

mvn org.owasp:dependency-check-maven:check

在 target/dependency-check-report.html 中查看 CVE。

Quarkus 安全审计

# 检查存在漏洞的扩展
mvn quarkus:audit

# 列出所有扩展
mvn quarkus:list-extensions

OWASP ZAP (API 安全测试)

docker run -t ghcr.io/zaproxy/zaproxy:stable zap-api-scan.py \
  -t http://localhost:8080/q/openapi \
  -f openapi

常见安全检查

  • 所有密钥均使用环境变量 (不在代码中)
  • 所有端点都已进行输入验证
  • 已配置身份验证/授权
  • CORS 配置正确
  • 已设置安全头
  • 密码使用 BCrypt 哈希处理
  • SQL 注入保护 (参数化查询)
  • 公共端点已限流

阶段 5:原生编译

测试 GraalVM 原生镜像兼容性:

# 构建原生可执行文件
mvn package -Dnative

# 或使用容器
mvn package -Dnative -Dquarkus.native.container-build=true

# 测试原生可执行文件
./target/*-runner

# 运行基本冒烟测试
curl http://localhost:8080/q/health/live
curl http://localhost:8080/q/health/ready

原生镜像故障排除

常见问题:

  • 反射: 为动态类添加反射配置
  • 资源: 使用 quarkus.native.resources.includes 包含资源
  • JNI: 如果使用原生库,注册 JNI 类

反射配置示例:

@RegisterForReflection(targets = {MyDynamicClass.class})
public class ReflectionConfiguration {}

阶段 6:性能测试

使用 K6 进行负载测试

// load-test.js
import http from 'k6/http';
import { check } from 'k6';

export const options = {
  stages: [
    { duration: '30s', target: 50 },
    { duration: '1m', target: 100 },
    { duration: '30s', target: 0 },
  ],
};

export default function () {
  const res = http.get('http://localhost:8080/api/markets');
  check(res, {
    'status is 200': (r) => r.status === 200,
    'response time < 200ms': (r) => r.timings.duration < 200,
  });
}

运行:

k6 run load-test.js

需要监控的指标

  • 响应时间 (p50, p95, p99)
  • 吞吐量 (请求数/秒)
  • 错误率
  • 内存使用量
  • CPU 使用量

阶段 7:健康检查

# 存活检查
curl http://localhost:8080/q/health/live

# 就绪检查
curl http://localhost:8080/q/health/ready

# 所有健康检查
curl http://localhost:8080/q/health

# 指标 (如果启用)
curl http://localhost:8080/q/metrics

预期响应:

{
  "status": "UP",
  "checks": [
    {
      "name": "Database connection",
      "status": "UP"
    }
  ]
}

阶段 8:容器镜像构建

# 构建容器镜像
mvn package -Dquarkus.container-image.build=true

# 或使用特定仓库
mvn package \
  -Dquarkus.container-image.build=true \
  -Dquarkus.container-image.registry=docker.io \
  -Dquarkus.container-image.group=myorg \
  -Dquarkus.container-image.tag=1.0.0

# 测试容器
docker run -p 8080:8080 myorg/my-quarkus-app:1.0.0

容器安全扫描

# Trivy
trivy image myorg/my-quarkus-app:1.0.0

# Grype
grype myorg/my-quarkus-app:1.0.0

阶段 9:配置验证

# 检查所有配置属性
mvn quarkus:info

# 列出所有配置源
curl http://localhost:8080/q/dev/io.quarkus.quarkus-vertx-http/config

环境特定检查

  • 数据库 URL 按环境配置
  • 密钥已外部化 (Vault, 环境变量)
  • 日志级别适当
  • CORS 来源设置正确
  • 已配置限流
  • 已启用监控/追踪

阶段 10:文档审查

  • OpenAPI/Swagger 文档是最新的 (/q/swagger-ui)
  • README 包含设置说明
  • API 变更已记录
  • 破坏性变更的迁移指南
  • 配置属性已记录

生成 OpenAPI 规范:

curl http://localhost:8080/q/openapi -o openapi.json

验证检查清单

代码质量

  • 构建成功,无警告
  • 静态分析干净 (无高/中优先级问题)
  • 代码遵循团队规范
  • PR 中没有注释掉的代码或 TODO

测试

  • 所有测试通过
  • 代码覆盖率 ≥ 80%
  • 使用真实数据库的集成测试
  • 安全测试通过
  • 性能在可接受范围内

安全性

  • 无依赖漏洞
  • 已测试身份验证/授权
  • 输入验证完整
  • 密钥不在源代码中
  • 已配置安全头

部署

  • 原生编译成功
  • 容器镜像构建成功
  • 健康检查响应正确
  • 配置对目标环境有效

原生镜像

  • 原生可执行文件构建成功
  • 原生测试通过
  • 启动时间 < 100ms
  • 内存占用可接受

自动验证脚本

#!/bin/bash
set -e

echo "=== 阶段 1:构建 ==="
mvn clean verify -DskipTests

echo "=== 阶段 2:静态分析 ==="
mvn checkstyle:check pmd:check spotbugs:check

echo "=== 阶段 3:测试 + 覆盖率 ==="
mvn test jacoco:report jacoco:check

echo "=== 阶段 4:安全扫描 ==="
mvn org.owasp:dependency-check-maven:check

echo "=== 阶段 5:原生编译 ==="
mvn package -Dnative -Dquarkus.native.container-build=true

echo "=== 所有阶段完成 ==="
echo "审查报告:"
echo "  - 覆盖率报告:target/site/jacoco/index.html"
echo "  - 安全报告:target/dependency-check-report.html"
echo "  - 原生可执行文件:target/*-runner"

CI/CD 集成

GitHub Actions 示例

name: Verification

on: [push, pull_request]

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7

      - name: Set up JDK 21
        uses: actions/setup-java@v5
        with:
          java-version: '21'
          distribution: 'temurin'

      - name: Cache Maven packages
        uses: actions/cache@v6
        with:
          path: ~/.m2
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

      - name: Build
        run: mvn clean verify -DskipTests

      - name: Test with Coverage
        run: mvn test jacoco:report jacoco:check

      - name: Security Scan
        run: mvn org.owasp:dependency-check-maven:check

      - name: Upload Coverage
        uses: codecov/codecov-action@v7
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: target/site/jacoco/jacoco.xml

最佳实践

  • 在每个 PR 前运行验证循环
  • 在 CI/CD 管道中自动化
  • 立即修复问题;不要累积技术债务
  • 保持覆盖率高于 80%
  • 定期更新依赖项
  • 定期测试原生编译
  • 监控性能趋势
  • 记录破坏性变更
  • 审查安全扫描结果
  • 为每个环境验证配置

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能