Repository navigation
ACOMMONS-243 chore: Improve repository setup and agent instructions #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
erwan-leforestier-sonarsource
wants to merge
9
commits into
master
Choose a base branch
from
chore/ai-experiment-agent-readiness
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,404
−320
Draft
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
743e300
chore: Add verified agent development tools and guidance
erwan-leforestier-sonarsource 30ab20c
ACOMMONS-243 Preserve existing tool version policy
erwan-leforestier-sonarsource cb64d80
ACOMMONS-243 Use native Maven development commands
erwan-leforestier-sonarsource 908e5d5
ACOMMONS-243 Remove local commit hooks
erwan-leforestier-sonarsource 31e95ea
ACOMMONS-243 Replace Python checks with shared Java formatter
erwan-leforestier-sonarsource fe54820
ACOMMONS-243 Enforce native Java formatting in CI
erwan-leforestier-sonarsource 9060f06
ACOMMONS-243 Fix supported CI and container setup
erwan-leforestier-sonarsource da1e5e7
chore: Route development and CI commands through Mise
erwan-leforestier-sonarsource bc10516
Add Codex and Claude Code push and PR hooks (#620)
romainbrenguier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| FROM maven:3-eclipse-temurin-21 | ||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends python3 git \ | ||
| && rm -rf /var/lib/apt/lists/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "Analyzer commons (JDK 21, Maven 3)", | ||
| "build": {"dockerfile": "Dockerfile"}, | ||
| "postCreateCommand": "python3 scripts/dev.py doctor --resolve", | ||
| "remoteUser": "root" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| charset = utf-8 | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
| indent_style = space | ||
| indent_size = 2 | ||
|
|
||
| [*.py] | ||
| indent_size = 4 | ||
|
|
||
| # Test resources can contain intentional whitespace and invalid source. | ||
| [{*.py,*.yml,*.yaml,*.md}] | ||
| trim_trailing_whitespace = true | ||
|
|
||
| [**/src/test/resources/**] | ||
| charset = unset | ||
| end_of_line = unset | ||
| insert_final_newline = unset | ||
| indent_style = unset | ||
| indent_size = unset | ||
| trim_trailing_whitespace = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/sh | ||
| exec python3 scripts/dev.py check --base HEAD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Read [AGENTS.md](../AGENTS.md) before work. Follow the relevant module's | ||
| `AGENTS.md` for its code paths, test conventions, and generated data. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: Repository checks | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened, edited, labeled, unlabeled] | ||
| push: | ||
| branches: [master, 'branch-*'] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| local-checks: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
|
gitar-bot[bot] marked this conversation as resolved.
Resolved
|
||
| with: | ||
| fetch-depth: 0 | ||
| - name: Check source boundaries, added credentials, and tooling tests | ||
| env: | ||
| BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before || github.sha }} | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| ALLOW_LARGE: ${{ contains(github.event.pull_request.labels.*.name, 'large-change-reviewed') }} | ||
| run: | | ||
| if ! git cat-file -e "$BASE_SHA^{commit}" 2>/dev/null; then | ||
| BASE_SHA="$(git rev-list --max-parents=0 HEAD | head -n 1)" | ||
| fi | ||
| python3 scripts/dev.py check --base "$BASE_SHA" | ||
| if [ -n "$PR_TITLE" ]; then | ||
| if [ "$ALLOW_LARGE" = true ]; then | ||
| python3 scripts/repository_checks.py --base "$BASE_SHA" --title "$PR_TITLE" --allow-large | ||
| else | ||
| python3 scripts/repository_checks.py --base "$BASE_SHA" --title "$PR_TITLE" | ||
| fi | ||
| fi | ||
|
|
||
| dependency-review: | ||
| if: github.event_name == 'pull_request' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| - name: Reject new high and critical dependency advisories | ||
| uses: actions/dependency-review-action@v5 | ||
| with: | ||
| fail-on-severity: high | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,3 +33,7 @@ Desktop.ini | |
|
|
||
| # ---- Claude Code | ||
| .mcp.json | ||
|
|
||
| # Python command-tool bytecode | ||
| __pycache__/ | ||
| *.pyc | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "recommendations": [ | ||
| "editorconfig.editorconfig", | ||
| "sonarsource.sonarlint-vscode" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| # Work in this repository | ||
|
|
||
| This repository contains eight shared Java libraries. It does not contain a | ||
| standalone analyzer or a SonarQube server. Start with the module table in | ||
| [README.md](README.md). Read only the module instructions that apply to the task. | ||
|
|
||
| ## Prepare and check | ||
|
|
||
| Use Python 3.9 or later, Git, JDK 21 or later, and Maven 3.9 or later. | ||
| `mise.toml` selects the existing Java 21.0 and Maven 3.9 release lines. From the | ||
| repository root, run: | ||
|
|
||
| ```sh | ||
| mise trust | ||
| mise install | ||
| python3 scripts/dev.py doctor --resolve | ||
| python3 scripts/dev.py test recognizers | ||
| ``` | ||
|
|
||
| `doctor` checks the JVM used by Maven. That JVM can differ from `java` on PATH. | ||
| The parent POM is `org.sonarsource.parent:parent`. Local tests do not require | ||
| Vault, a SonarQube server, npm, NuGet, or publishing credentials. If an artifact | ||
| returns HTTP 401 or 403, check your Maven mirror and server settings. Keep those | ||
| settings outside Git. Do not print tokens or copy CI deployer credentials. | ||
| The optional `.devcontainer` uses the Maven 3 image with JDK 21. It installs Git | ||
| and Python from Debian packages. The image and packages can receive updates. | ||
|
|
||
| ## Select work and tests | ||
|
|
||
| ```sh | ||
| python3 scripts/dev.py affected origin/master | ||
| python3 scripts/dev.py test commons --test TokenLocationTest | ||
| python3 scripts/dev.py test regex-parsing --test EmptyGroupFinderTest | ||
| python3 scripts/dev.py repeat recognizers --test CodeRecognizerTest | ||
| python3 scripts/dev.py verify | ||
| python3 scripts/dev.py build | ||
| python3 scripts/dev.py sbom | ||
| python3 scripts/dev.py reproduce recognizers | ||
| python3 scripts/dev.py quality recognizers | ||
| ``` | ||
|
|
||
| `affected` includes local edits and reverse dependencies, including test | ||
| dependencies. It gives a conservative module list. It cannot identify external | ||
| analyzer consumers. Module names are directory names. The Maven commands include | ||
| `-pl` and `-am` for selected modules. A class selector uses | ||
| `-Dsurefire.failIfNoSpecifiedTests=false` so upstream modules can have no matching | ||
| class. Always run the module suite after a focused test. | ||
| The tool also requires a fresh report with executed tests in the selected | ||
| module. A misspelled class or method fails instead of passing silently. | ||
|
|
||
| `test` runs unit tests. `verify` also runs the offline repository checks and | ||
| Maven verification, including the existing JAR size limits. `build` installs | ||
| artifacts in the local Maven cache. None of these commands deploys artifacts. | ||
| They keep `target/` for incremental builds. Use `mvn clean` only when stale | ||
| outputs are a possible cause. Cold dependency downloads take longer than a warm | ||
| build. No fixed build duration is guaranteed. | ||
|
|
||
| `sbom` records the resolved dependency graph in CycloneDX files under `target/`. | ||
| CI retains these files with the build output. Maven uses strict checksum checks, | ||
| but this is not a content lock for every transitive artifact. Dependency review | ||
| rejects new high and critical advisories when GitHub dependency review is enabled. | ||
| `reproduce` makes two clean packages of one module and compares their bytes. It | ||
| uses the commit time for archive timestamps and the inherited `Build-Time` | ||
| manifest field. It skips tests, so run tests separately first. A local match does | ||
| not guarantee that signing or publishing produces identical bytes. | ||
|
|
||
| The command writes its duration, exit status, and command to `target/agent/`. | ||
| It fails if Maven changes a tracked file. Read the first Maven `ERROR` and the | ||
| module's `target/surefire-reports/` after a test failure. Preserve the failing | ||
| sample, exact command, JDK, and revision. Do not rerun until green without | ||
| recording and correcting the cause. `repeat` runs a selected suite twice and | ||
| stops at the first failure. It is a local flake check, not proof of determinism. | ||
|
|
||
| ## Follow the source contracts | ||
|
|
||
| Use two spaces in Java and XML, and four spaces in Python. Use the existing | ||
| package names and `*Test` class names. Keep imports explicit. Match package | ||
| directories. `scripts/dev.py check` rejects reactor cycles, undeclared local | ||
| source imports, package-directory errors, and added whitespace errors. It also | ||
| runs the command-tool tests. `.editorconfig` gives editor defaults. Test resources | ||
| can contain deliberate invalid source and whitespace; do not format them. | ||
| Use `check --base <ref>` to include committed changes in whitespace and | ||
| credential checks. CI supplies the PR base explicitly. With no base, the tool | ||
| checks local changes from `HEAD`. | ||
| To run these fast checks before a commit, opt in with | ||
| `git config --local core.hooksPath .githooks`. This is a repository-local setting; | ||
| the setup command does not change global Git configuration. The same checks run | ||
| in CI even when the local hook is not enabled. | ||
|
|
||
| New public APIs affect many analyzers. Prefer the existing API and a small | ||
| implementation change. Keep `internal` implementation classes behind their | ||
| public entry points. Preserve package null contracts from `package-info.java`. | ||
| Do not add a dependency to a shared library without checking its consumers and | ||
| JAR size. Compiler checks and tests check types; NEXT analysis supplies broader | ||
| null, dead-code, duplication, and size feedback. Do not claim that the local | ||
| checks replace this analysis. | ||
|
|
||
| `quality` produces local PMD and duplicate-code reports under each selected | ||
| module's `target/site/`. It supplies feedback for unused private code, class | ||
| names, large classes/methods, and duplicated token blocks. These reports are | ||
| not a new merge gate, and they do not prove null safety or API compatibility. | ||
| The VS Code extension recommendations enable EditorConfig and SonarQube for IDE | ||
| when installed. CI's `coverage` profile also checks a 60% line-coverage floor in | ||
| each module with measured code. A coverage floor does not prove that assertions | ||
| are useful; keep behavior assertions and counterexamples in the tests. | ||
|
|
||
| Start a new Java test from a small adjacent test. `CodeRecognizerTest` is a | ||
| simple JUnit 4 example. `EmptyGroupFinderTest` and its YAML file show the regex | ||
| finder pattern. Some modules use JUnit 4 and others use JUnit Jupiter; preserve | ||
| the module's dependency choice. Include a positive case, a negative case, and | ||
| relevant boundaries. Assert actual output and locations. Do not weaken expected | ||
| results to obtain a passing test. No generated test scaffold is required. | ||
|
|
||
| ## Keep changes bounded | ||
|
|
||
| Work on a side branch. Use `fix/`, `feat/`, or `chore/` with a short description. | ||
| Use an `ACOMMONS-<number>` prefix in the commit and PR title when a ticket exists; | ||
| otherwise use a conventional title such as `chore: Improve local checks`. | ||
| Separate behavior changes from broad formatting or dependency updates. Keep | ||
| each PR small enough to explain and test. The readiness workflow checks the | ||
| title and reports changed line counts. Its size limit requires a maintainer's | ||
| `large-change-reviewed` label for an exceptional PR. | ||
|
|
||
| Before completion, run the affected module suites, `python3 scripts/dev.py | ||
| verify`, and inspect the full diff. Required CI and NEXT checks must pass before | ||
| merge. A local pass does not establish downstream compatibility or a green CI | ||
| result. If an API or common parser changes, identify affected consumers in the | ||
| PR. Do not merge, tag, sign, release, promote, publish, or force-push unless the | ||
| user explicitly requests that operation. CI performs those operations under its | ||
| own permissions. Never use release credentials for local tests. | ||
|
|
||
| ## Edit the source of generated data | ||
|
|
||
| Do not commit `target/`, `dependency-reduced-pom.xml`, generated configuration | ||
| JSON, or generated npm/NuGet archives. Configuration JSON comes from | ||
| `SecretClassifier` and the exporter classes. Change those sources, then run | ||
| configuration-module tests and package verification. Packaging templates under | ||
| `sonar-analyzer-commons-configurations/src/main/packaging/` are source files; | ||
| their filtered copies under `target/packaging/` are generated. | ||
|
|
||
| The verifier corpus under `test-commons/src/test/resources/`, and regex finder | ||
| YAML files, are deliberate test data. Edit them only to test a stated behavior. | ||
| Rule JSON and HTML under `commons/src/test/resources/` are loader test fixtures, | ||
| not production rule descriptions. Do not regenerate all expected data for an | ||
| unrelated change. Marketing owns the marked root README section and logo URLs. | ||
|
|
||
| Use network access for required dependency resolution and source references. | ||
| Do not send repository source, test corpora, credentials, or build logs to an | ||
| external service unless the task authorizes that service. Repository checks | ||
| scan added lines for selected credential formats; they cannot detect every | ||
| secret. Stop and remove a real credential if one is found, then follow the | ||
| organization's credential-rotation process. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @AGENTS.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Common analyzer utilities | ||
|
|
||
| Production code is under `src/main/java/org/sonarsource/analyzer/commons/`. | ||
| Tests mirror that package under `src/test/java/`. Start with `TokenLocation` | ||
| and `TokenLocationTest` for a small utility and its output assertions. | ||
|
|
||
| `RuleMetadataLoader` combines annotations with JSON/HTML rule resources. | ||
| `BuiltInQualityProfileJsonLoader` loads profile definitions. Their test resources | ||
| contain deliberately invalid and historical data. Change a resource only when | ||
| the loader behavior under test requires it. | ||
|
|
||
| `appsec/` contains IP, protocol, key-size, test-file, and secret classification. | ||
| Secret configuration exports consume `SecretClassifier` from the configurations | ||
| module. A classifier change therefore requires both module suites and a package | ||
| verification. `collections/` contains persistent collection helpers. Preserve | ||
| their immutability and iterator contracts. | ||
|
|
||
| The POM relocates `org.json.simple` into an internal namespace during shading. | ||
| Do not expose that shaded package in a public API. `verify` checks the existing | ||
| JAR size limit. New dependencies increase the size of many analyzers. | ||
|
|
||
| From the root, run `python3 scripts/dev.py test commons`. A change to a public | ||
| utility also needs a check of affected analyzer callers outside this repository. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <ruleset name="Local source feedback" | ||
| xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"> | ||
| <description>Local feedback for unused code, naming, and source reading size.</description> | ||
| <rule ref="category/java/bestpractices.xml/UnusedPrivateMethod"/> | ||
| <rule ref="category/java/bestpractices.xml/UnusedPrivateField"/> | ||
| <rule ref="category/java/bestpractices.xml/UnusedLocalVariable"/> | ||
| <rule ref="category/java/codestyle.xml/ClassNamingConventions"/> | ||
| <rule ref="category/java/design.xml/NcssCount"> | ||
| <properties> | ||
| <property name="classReportLevel" value="1000"/> | ||
| <property name="methodReportLevel" value="100"/> | ||
| </properties> | ||
| </rule> | ||
| </ruleset> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Performance measurements | ||
|
|
||
| `PerformanceMeasure` starts and stops nested duration measurements. | ||
| `DurationMeasure` stores the hierarchy. `DurationMeasureFiles` reads and writes | ||
| reports. `DurationMeasureMerger` combines measurements. `log/` adapts logging. | ||
| The README shows the sensor and report flow. | ||
|
|
||
| Preserve disabled-mode behavior, nesting, thread behavior, and report format. | ||
| Do not make correctness tests depend on a fixed wall-clock duration. Use the | ||
| adjacent measurement and merger tests for the behavior under change. | ||
|
|
||
| Run `python3 scripts/dev.py test performance-measure` from the root. No running | ||
| SonarQube service is needed for these unit tests. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.