Communitygithub.com

Quarkus 驗證循環

針對 Quarkus 專案的完整驗證循環:包含建置、靜態分析、測試與涵蓋率、安全掃描、原生編譯,以及發佈前或 PR 前的差異審查。

Quarkus 驗證循環 是什麼?

這個技能定義了一個全面的驗證流程,專為 Quarkus 專案在 Pull Request 前、重大重構後或部署前執行。它涵蓋從專案建置、靜態分析(Checkstyle、PMD、SpotBugs、SonarQube)、單元測試、整合測試(Testcontainers)與 API 測試(REST Assured)到程式碼涵蓋率檢查(目標 80%+),並包含依賴漏洞掃描、Quarkus 安全審計與 OWASP ZAP API 安全測試。此外,還支援 GraalVM 原生編譯測試、K6 效能測試、健康檢查、容器映像建置與安全掃描(Trivy/Grype),以及組態驗證與文件審查。此技能可在 Claude Code、Codex 等支援技能定義的 AI 編碼代理平台上使用。它提供詳細的指令碼範例、CI/CD 整合範例(GitHub Actions)與自動化驗證腳本,幫助開發團隊確保 Quarkus 服務的品質與安全性。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Quarkus 驗證循環 是做什麼的?

在 Pull Request 前、重大變更後與部署前執行。

何時啟用

  • 在為 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}

需要處理的常見問題

  • 未使用的 import 或變數
  • 複雜的方法(高循環複雜度)
  • 潛在的空指標解參考
  • SpotBugs 標記的安全性問題

階段 3:測試 + 涵蓋率

# 執行所有測試
mvn clean test

# 產生涵蓋率報告
mvn jacoco:report

# 強制檢查涵蓋率門檻(80%)
mvn jacoco:check

# 或使用 Gradle
./gradlew test jacocoTestReport jacocoTestCoverageVerification

測試類別

單元測試

使用模擬依賴項測試服務邏輯:

@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

# 或指定 Registry
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/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

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.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相關技能