-
Notifications
You must be signed in to change notification settings - Fork 5
AIML-230: Harden coding standards and practices [STACKED] #29
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements comprehensive code quality improvements through automated formatting and modernized coding practices. It introduces Spotless Maven plugin for consistent code formatting, adopts the var keyword for improved readability, converts wildcard imports to explicit imports, and corrects a package naming typo throughout the codebase.
- Added Spotless Maven plugin with Google Java Format for automated code formatting enforcement
- Modernized 549 local variable declarations to use
varkeyword across main and test code - Converted 5 wildcard imports to 30 explicit imports and documented "no wildcard imports" standard
- Fixed package naming: renamed
sdkexstensiontosdkextensionacross 72 files with git history preserved
Reviewed Changes
Copilot reviewed 130 out of 153 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| ADRServiceIntegrationTest.java | Applied var keyword and reformatted with Spotless; updated import from old sdkexstension to sdkextension package |
| PaginationHandler.java | Applied var keyword to local variables and reformatted code with Spotless |
| SessionMetadataResponse.java | New file created in corrected sdkextension package with Spotless formatting |
| MetadataSession.java | Package declaration corrected from sdkexstension to sdkextension |
| MetadataField.java | Package declaration corrected from sdkexstension to sdkextension |
| AgentSession.java | New file created in corrected sdkextension package with Spotless formatting |
| LibraryObservationsResponse.java | New file created in corrected sdkextension package with Spotless formatting |
| LibraryObservation.java | New file created in corrected sdkextension package with Spotless formatting |
| Server.java (routecoverage) | New file created in corrected sdkextension package with Spotless formatting |
| RouteDetailsResponse.java | New file created in corrected sdkextension package with Spotless formatting |
| RouteCoverageResponse.java | New file created in corrected sdkextension package with Spotless formatting |
| RouteCoverageBySessionIDAndMetadataRequestExtended.java | New file created in corrected sdkextension package |
| Route.java | New file created in corrected sdkextension package with Spotless formatting |
| Observation.java | New file created in corrected sdkextension package with Spotless formatting |
| App.java (routecoverage) | New file created in corrected sdkextension package with Spotless formatting |
| Metadata.java | New file created in corrected sdkextension package with Spotless formatting |
| Field.java | New file created in corrected sdkextension package with Spotless formatting |
| ApplicationsResponse.java | New file created in corrected sdkextension package with Spotless formatting |
| Application.java | New file created in corrected sdkextension package with Spotless formatting |
| UserInput.java (adr) | New file created in corrected sdkextension package with Spotless formatting |
| Story.java | Package declaration corrected from sdkexstension to sdkextension |
| StackFrame.java | New file created in corrected sdkextension package with Spotless formatting |
| Server.java (adr) | New file created in corrected sdkextension package with Spotless formatting |
| Request.java | Package declaration corrected from sdkexstension to sdkextension |
| HttpRequest.java | New file created in corrected sdkextension package with Spotless formatting |
| EventSummary.java | New file created in corrected sdkextension package with Spotless formatting |
| EventDetails.java | New file created in corrected sdkextension package with Spotless formatting |
| Event.java | New file created in corrected sdkextension package with Spotless formatting |
| Chapter.java | New file created in corrected sdkextension package with Spotless formatting |
| AttacksResponse.java | New file created in corrected sdkextension package with Spotless formatting |
| AttacksFilterBody.java | New file created in corrected sdkextension package with Spotless formatting |
| AttackEvent.java | New file created in corrected sdkextension package with Spotless formatting |
| Attack.java | New file created in corrected sdkextension package with Spotless formatting |
| Application.java (adr) | New file created in corrected sdkextension package with Spotless formatting |
| Server.java (data) | New file created in corrected sdkextension package with Spotless formatting |
| Rule.java | New file created in corrected sdkextension package with Spotless formatting |
| ProtectData.java | Package declaration corrected from sdkexstension to sdkextension |
| LibraryVulnerabilityExtended.java | Package declaration corrected from sdkexstension to sdkextension |
| LibraryExtended.java | New file created in corrected sdkextension package with Spotless formatting |
| Library.java | New file created in corrected sdkextension package with Spotless formatting |
| LibrariesExtended.java | Package declaration corrected from sdkexstension to sdkextension |
| ImpactStats.java | New file created in corrected sdkextension package with Spotless formatting |
| CvssV3.java | New file created in corrected sdkextension package with Spotless formatting |
| CveData.java | New file created in corrected sdkextension package with Spotless formatting |
| Cve.java | New file created in corrected sdkextension package with Spotless formatting |
| App.java | New file created in corrected sdkextension package with Spotless formatting |
| SessionMetadata.java | New file created in corrected sdkextension package with Spotless formatting |
| SDKHelper.java | New file created in corrected sdkextension package with var keyword applied and Spotless formatting |
| SDKExtension.java | New file created in corrected sdkextension package with var keyword applied and Spotless formatting |
| VulnerabilityContext.java | Updated import from sdkexstension to sdkextension package and applied Spotless formatting |
| HintUtils.java | Applied var keyword to local variables and reformatted with Spotless |
| StackLib.java | Removed unused import and reformatted with Spotless |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d8dc3e3 to
62909a8
Compare
1f197f5 to
92062a4
Compare
Changes two tools to accept appID instead of app_name for consistency with AIML-189 standardization: - list_vulns_by_app_and_metadata: Renamed method to listVulnsByAppIdAndSessionMetadata, removed SDKHelper lookup - list_vulns_by_app_latest_session: Renamed method to listVulnsByAppIdForLatestSession, removed SDKHelper lookup Both tools now: - Accept appID parameter directly - Have updated @tool descriptions mentioning list_applications_with_name - Skip application name lookup for better performance - Are consistent with all other application-level tools Tests updated to use appID. All tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Fixed test plan documentation for list_vulns_by_app tools to use appID parameter instead of app_name, matching the code changes in mcp-6bs. This was causing Copilot to cache the old parameter name and fail when calling these tools. Changes: - test-plan-list_vulns_by_app_and_metadata.md: Updated all references from app_name to appID - test-plan-list_vulns_by_app_latest_session.md: Updated all references from app_name to appID 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
These test plan files are development/testing documentation that should not be committed to the repository. They are now ignored via .gitignore. The files are preserved locally for development use but won't be tracked in version control. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Documents Java coding conventions for the project: - Prefer var for local variables when type is obvious - Use isEmpty() instead of size() comparisons for collections 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Added spotless-maven-plugin 2.43.0 to pom.xml - Configured with Google Java Format 1.26.0 matching aiml-services standards - Enabled automatic enforcement via validate phase - Formatted entire codebase (96 Java files) - Updated CLAUDE.md with Spotless commands and usage notes Configuration: - Google Java Format style with import reordering - Long string reflowing enabled - Javadoc formatting enabled - Runs automatically on every build (mvn compile/test/install) All tests pass: 250 tests, 0 failures, 0 errors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Applied var keyword throughout the codebase where type is obvious from
right-hand side, following CLAUDE.md coding standards.
Changes:
- Service classes: 70 var replacements
- ADRService (9), AssessService (42), RouteCoverageService (7),
SCAService (6), SastService (6)
- Data/mapper/utils: 13 var replacements
- AttackSummary, VulnerabilityMapper, PaginationHandler, hint classes
- SDK extension classes: 29 var replacements
- SDKExtension (13), SDKHelper (16)
- Test classes: 437 var replacements
- Unit tests (386): All *Test.java files
- Integration tests (51): All *IntegrationTest.java files
Total: 549 var replacements across 34 files
Rules applied:
✅ Use var when type is obvious from constructor/method call
✅ Use var for mock objects and ArgumentCaptors
✅ Use var for collections with explicit type parameters
❌ Do NOT use var for numeric literals
❌ Do NOT use var for null assignments
❌ Do NOT use var when type would be ambiguous
All 224 unit tests pass (0 failures, 0 errors)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add coding standard to CLAUDE.md requiring explicit imports only. Wildcard imports (import package.*) are not allowed to improve code clarity and maintainability.
Replace all wildcard imports with explicit imports in main source files per CLAUDE.md coding standards. Static wildcard imports in test files remain unchanged as they follow standard test code conventions. Changes: - SDKExtension.java: 1 wildcard → 5 explicit imports - AssessService.java: 3 wildcards → 19 explicit imports - VulnerabilityFilterParams.java: 1 wildcard → 6 explicit imports Verified: mvn test passes (218 tests, 0 failures)
Correct package name spelling from 'sdkexstension' to 'sdkextension' throughout the codebase. Used git mv to preserve file history. Changes: - Renamed 49 Java files (package directories) - Updated package declarations in all moved files - Updated imports in 23 files that reference the package - Updated documentation (CLAUDE.md, plans) Verified: All 250 tests pass, compilation successful
92062a4 to
ac20aba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated test plans in here are nice, but I'm a little concerned that as more people work on the code, they won't get maintained unless you use claude to generate all tests. It also kinda creates 2 sources of truth. Historically the test code itself is supposed to be the source of truth for what is being tested and expected outcomes. These test plans sort of duplicate that knowledge in two places and appear easy to become out of sync.
The best approach I've seen to creating something more non-developer-friendly for reading what the tests are doing has been test patterns and frameworks like RSpec, which was popularized by Ruby. Is the output of RSpec what you are trying to communicate with these generated test plan documents?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well crap. Those generated plans were supposed to be gitignored. They are how I personally test with copilot with the real mcp server. I will remove them in the next PR. There aren't mean to be used by devs. Its an extra layer of protection for me to make sure the AI is able to understand the tool descriptions, etc. They have been useful as I change these things, but shouldn't be necessary as ongoing tests. Committing them was an accident.
✅ Rebased onto main after PR #28 merged (2025-11-14)
Why: The Problem We're Solving
The mcp-contrast codebase lacked consistent tooling and standards for code formatting, style, and maintainability. This creates several problems:
sdkexstensionpackage had a spelling error that needed correctionThese issues make the code harder to maintain, review, and extend. As the project grows and more developers contribute, consistent standards become critical to velocity and code quality.
What: Changes Made
This PR introduces five key improvements to establish a solid foundation for code quality:
sdkexstension→sdkextension(72 files affected)Impact: 158 files changed, +23,357/-14,075 lines (includes package rename history preservation)
How: Implementation Approach
1. Spotless Integration (Commit a6e5cef)
Added Maven plugin with Google Java Format 1.26.0:
validatephase, fails build if formatting violations existmvn spotless:applyreformats entire codebase2. var Keyword Migration (Commit 5579444)
Systematic refactoring following these rules:
Examples:
Distribution:
3. Explicit Imports Standard (Commits cc85cf9, a7812f6)
Converted all wildcard imports to explicit imports:
4. Package Spelling Correction (Commit 1f197f5)
Fixed
sdkexstension→sdkextension:git mvto preserve file history (49 files)5. Documentation Updates
Added "Coding Standards" section to CLAUDE.md with:
varfor local variables when type is obviousisEmpty()instead ofsize() > 0for collection checksStep-by-Step Walkthrough
Phase 1: Establish Standards
Commit cc85cf9 - Document no wildcard imports standard
Commit 90f699d - Document prefer var for local variables
Phase 2: Add Tooling
Commit a6e5cef - Add Spotless Maven plugin
pom.xml: Added plugin configuration (lines 127-150)Key features:
Phase 3: Apply Standards
Commit 5579444 - Refactor to use var keyword
Commit a7812f6 - Convert wildcard imports
Phase 4: Fix Technical Debt
Commit 1f197f5 - Fix package spelling
sdkexstension→sdkextensiongit mvTesting
Test Results
Verification Performed
Unit Tests (224 tests):
Integration Tests (26 tests via
mvn verify):Code Quality Checks:
mvn spotless:checkManual Verification:
mvn clean packageTest Coverage Notes
Additional Context
Related Work
This PR is Phase 1 of a larger code quality initiative. Future work includes:
Bead Tracking
Completed beads in this PR:
mcp-bxm- Add Spotless Maven pluginmcp-424- Update to use var keywordmcp-68y- Document no wildcard imports standardmcp-i2k- Convert wildcard imports to explicitmcp-unm- Fix package spellingParent epic:
mcp-uuv(AIML-230)Reviewer Checklist
Commands for Reviewers
Related Issues:
🤖 Generated with Claude Code