From d5693a6804aa220339e29512fc74ce4423492da8 Mon Sep 17 00:00:00 2001 From: Julien Bureau Date: Wed, 20 May 2026 09:55:00 +0200 Subject: [PATCH 1/3] fix: Refactor project guidelines and scripts for integration tests - Updated project structure and checklist in copilot.instructions.md for clarity and consistency. - Modified review_pr.bat and review_pr.sh to provide clearer instructions for running integration tests. - Introduced new run_it.bat and run_it.sh scripts to streamline the execution of integration tests with options for rule filtering and build skipping. - Enhanced error handling and reporting in the new scripts to improve user experience and debugging. Co-authored-by: Copilot --- .../agents/creedengo-java-reviewer.agent.md | 608 +++++++++++++ .github/instructions/copilot.instructions.md | 41 + .github/scripts/review_pr.bat | 598 +++++++++++++ .github/scripts/review_pr.sh | 840 ++++++++++++++++++ .github/scripts/run_it.bat | 195 ++++ .github/scripts/run_it.sh | 237 +++++ 6 files changed, 2519 insertions(+) create mode 100644 .github/agents/creedengo-java-reviewer.agent.md create mode 100644 .github/instructions/copilot.instructions.md create mode 100644 .github/scripts/review_pr.bat create mode 100644 .github/scripts/review_pr.sh create mode 100644 .github/scripts/run_it.bat create mode 100644 .github/scripts/run_it.sh diff --git a/.github/agents/creedengo-java-reviewer.agent.md b/.github/agents/creedengo-java-reviewer.agent.md new file mode 100644 index 00000000..b3778bed --- /dev/null +++ b/.github/agents/creedengo-java-reviewer.agent.md @@ -0,0 +1,608 @@ +--- +description: "Specialized agent for in-depth Pull Request reviews on the creedengo-java repository. Used to analyze the quality, compliance and completeness of PRs adding or modifying SonarQube rules for sustainable software development. Generates a structured Markdown report." +tools: [read, search, web, agent, todo, execute, edit] +argument-hint: "GitHub PR URL or description of the changes to analyze" +--- + +# Agent creedengo-java PR Reviewer + +You are an expert reviewer specialized in Pull Requests for the **creedengo-java** project, a SonarQube plugin of eco-design rules for Java. + +## Project context + +- Package: `org.greencodeinitiative.creedengo.java.checks` +- Each rule extends `IssuableSubscriptionVisitor`, annotated with `@Rule(key = "GCI{N}")` +- Registration: `JavaCheckRegistrar.ANNOTATED_RULE_CLASSES` + `creedengo_way_profile.json` +- Unit tests: `CheckVerifier` with `// Noncompliant {{message}}` markers +- Integration tests: `GCIRulesIT.java` (format `"creedengo-java:GCI{N}"`) +- Test files: `src/it/test-projects/.../checks/GCI{N}/` (NOT `src/test/files/`) +- Specifications: https://github.com/green-code-initiative/creedengo-rules-specifications/blob/main/RULES.md +- Definition of done: https://github.com/green-code-initiative/ecoCode-common/blob/main/doc/starter-pack.md#check-definition-of-done-for-new-rule-implementation +- PR is not necessarily linked to an issue (can be upgrade of documentation, refactoring, rule check improvement...), but if it is, the issue must be mentioned in the description and closed by the PR (e.g. "Closes #123") + +## Review methodology + +### Phase 0: Preparation + +```bash +git clone https://github.com/green-code-initiative/creedengo-java.git pr-{N}-workdir +cd pr-{N}-workdir +git fetch origin pull/{N}/head:pr-{N} +git checkout pr-{N} +``` + +> **Important — git diff**: Always use the three-dot syntax `git diff origin/main...pr-{N}` (or equivalently `git diff $(git merge-base origin/main pr-{N})..pr-{N}`) to compare the PR against its divergence point from `main`. The two-dot syntax `origin/main..pr-{N}` would include changes made on `main` after the branch diverged and surface them as deletions, producing a misleading diff. + +> **Important — definition of done**: You MUST read the official and up to date definition of done before reviewing the PR. + +### Phase 1: Automated checks (script) + +#### Maven invocation strategy (important for performance) + +The review process uses two scripts sequentially, with a single Maven build: + +1. **`review_pr.{sh|bat}`** — runs `mvnw verify -DskipITs=true`: + - Compiles the project + - Runs unit tests (Surefire) + - Packages the plugin JAR (shade) + - Generates JaCoCo coverage report + - Skips integration tests (ITs require SonarQube download, ~5min) + - Output: `target/` directory with JAR + coverage + test reports + +2. **`run_it.{sh|bat} --skip-build`** — runs `mvnw verify -DskipTests=true`: + - Detects that classes are already compiled (incremental, ~1s) + - Repackages the JAR (shade, ~3s) + - Runs integration tests via Failsafe (downloads SonarQube if not cached) + - The `--skip-build` flag skips the `clean` phase so target/ is reused + +**Why two separate invocations?** +- Unit tests are fast (~5s) and give quick feedback on compilation + logic errors +- IT tests are slow (~3-5min) because they download/start SonarQube +- If unit tests fail, there's no point running ITs +- The agent can start Phase 2 analysis while ITs run in background + +**Why NOT use standalone Maven goals?** +- `failsafe:integration-test` and `failsafe:verify` as standalone goals do NOT inject the `systemPropertyVariables` from the pom.xml `` configuration +- This causes errors like "System property `test-it.orchestrator.artifactory.url` must be defined" +- Always use the lifecycle (`verify`) to ensure proper property injection + +#### Step 1.1: Run the automated review script + +**Linux/macOS/WSL:** +```bash +bash .github/scripts/review_pr.sh --pr-number {N} --base-branch main +``` + +**Windows (CMD — NOT PowerShell directly):** +```cmd +cmd /c "cd /d && .github\scripts\review_pr.bat --pr-number {N} --base-branch main" +``` + +> **IMPORTANT — Windows execution**: All `.bat` scripts MUST be invoked through `cmd /c "..."` when the agent runs in PowerShell. PowerShell does not correctly parse batch `if/else` blocks, `for /f` loops, and delayed expansion (`!var!`). Always wrap in `cmd /c "cd /d && .github\scripts\