NEW @W-22393672@ Expose ApexGuru engine in CLI with --target-org flag#2051
NEW @W-22393672@ Expose ApexGuru engine in CLI with --target-org flag#2051nikhil-mittal-165 wants to merge 7 commits into
Conversation
Add --target-org/-o flag to code-analyzer run command to specify target Salesforce org for remote analysis engines like ApexGuru. Changes: - Add target-org flag to RunCommand with char 'o' - Update RunInput type to include optional target-org field - Add ApexGuru engine dependency from feature branch - Register ApexGuru engine in EnginePluginsFactory - Wire target-org through CliOverrides to engine config - Add unit tests for flag parsing and config wiring The flag value is passed to the ApexGuru engine via engine_overrides config as target_org field, following the engine's config schema.
Add E2E tests verifying --target-org and -o shorthand are accepted and parsed without errors. Tests use try-catch since ApexGuru may fail in test environment without authenticated org.
Test stubs were missing getInsights and getEngineInsights methods added to RunResults interface in core. Also disable lint warning for target-org -o shorthand which is the correct convention.
aruntyagiTutu
left a comment
There was a problem hiding this comment.
APPROVE WITH COMMENTS
Good implementation overall, but has one pre-merge requirement.
13-Point Review: Mostly PASS, one requirement before merge.
The GitHub SHA dependency must be updated to a published version before merge:
// CURRENT (temporary)
"@salesforce/code-analyzer-apexguru-engine": "github:forcedotcom/code-analyzer-core#feature/W-22393676-sfap-workspace-scan:packages/apexguru-engine"
// REQUIRED (published version)
"@salesforce/code-analyzer-apexguru-engine": "^0.39.0"Action Required: Update to published version once PRs #468 and #472 are merged and released.
Non-Blocking Suggestions:
- Add early org validation for clearer error messages at CLI boundary
- E2E tests should assert specific error types rather than swallowing all exceptions
Otherwise, well-structured implementation with clean architecture.
aruntyagiTutu
left a comment
There was a problem hiding this comment.
New commits detected. The PR now includes the ApexGuru engine integration with the --target-org flag, which is a significant addition. Based on the diff:
Changes observed:
✅ New --target-org flag added with proper documentation in messages/run-command.md
✅ @salesforce/code-analyzer-apexguru-engine dependency added (0.39.0)
✅ Dependency updates: @jsforce/jsforce-node upgraded to 3.10.17
✅ New transitive dependencies added for ApexGuru engine support
Remaining review areas (per Code Analyzer PR Review guidelines):
- Performance (#1 priority): Need to verify ApexGuru engine doesn't block on sync I/O operations. Remote connectivity should be async throughout.
- Validation: --target-org flag should validate org authentication upfront (before expensive processing) and provide distinct error messages for auth failures
- Logging: Verify proper log levels for remote engine operations (Debug for internal state, Info for user-facing progress, Error for auth/connection failures)
- Error handling: Remote engine failures should provide actionable error messages guiding users to fix auth/connectivity issues
Recommended verification before merge:
- Test on a large project to ensure remote engine doesn't degrade overall CLI performance
- Verify --target-org validation provides clear errors when org is not authenticated
- Check logging doesn't spam console with debug-level remote engine details
- Confirm error messages guide users to solve auth/connection issues
Still marked as dependent on another PR merge. Will re-review once implementation code is visible.
92a8fcc to
232062f
Compare
aruntyagiTutu
left a comment
There was a problem hiding this comment.
Implementation code is now visible. Reviewing against Code Analyzer PR Review guidelines:
Positive observations:
✅ Flag properly added with short option -o and documentation
✅ Target org passed through RunInput → RunAction → ConfigFactory → config object
✅ Config factory properly handles CLI override merging with YAML config
Issues to address:
1. Validation (#3 - CRITICAL)
- ❌ No upfront validation of
target-orgparameter. Per guidelines: "Token/credential validation upfront. If the workflow requires a GitHub token or org connection, validate it exists and has correct permissions before proceeding." - Missing: Check if org is authenticated before expensive file processing
- Missing: Distinct error messages for different failure cases (org not found, not authenticated, connection failed)
2. Error Messages (#3)
- Need actionable guidance when org validation fails
- Should tell users to run
sf org loginor similar
3. Config Logic Complexity (#2 - Naming & Consistency)
- ConfigFactory.mergeConfigAndOverrides() has complex branching logic that's hard to follow
- Line 66:
if (disableSuppressionExplicitlySet && !cliOverrides.targetOrg)- why does targetOrg presence affect suppressions precedence? This coupling is unexpected. - Consider: separate concerns - handle suppressions override independently from targetOrg override
4. Performance (#1 - Most Critical)
- Remote engine operations must be async throughout (can't verify without seeing ApexGuru engine implementation)
- If target org validation involves network calls, ensure they don't block
Recommended changes:
// In RunAction.execute(), add validation before expensive operations:
if (input['target-org']) {
await this.validateTargetOrg(input['target-org']); // throws with actionable message
}Request changes to add target org validation upfront.
aruntyagiTutu
left a comment
There was a problem hiding this comment.
Latest commit reviewed. The requested validation changes were not addressed.
Issue still present:
❌ No upfront validation of target-org in RunAction.execute()
- The target org is passed straight through to config without checking if it exists or is authenticated
- This violates guideline #3: "Token/credential validation upfront. If the workflow requires a GitHub token or org connection, validate it exists and has correct permissions before proceeding."
Current flow:
- User provides
--target-org myorg - Flag parsed → RunAction → ConfigFactory → config object → ApexGuru engine
- Only when ApexGuru engine runs will org validation happen (deep in execution)
Required change:
Add validation at the boundary (RunAction.execute) before expensive processing:
public async execute(input: RunInput): Promise<void> {
// Validate org upfront if provided
if (input['target-org']) {
await this.validateTargetOrg(input['target-org']);
}
const cliOverrides = // ... rest of existing codeWhere validateTargetOrg throws with actionable error like:
- "Org 'myorg' not found. Run 'sf org list' to see available orgs."
- "Org 'myorg' not authenticated. Run 'sf org login web --alias myorg'."
Test observation:
Test at line 89 explicitly catches and ignores validation failures with "ApexGuru may fail if org is not authenticated, which is expected". This confirms validation happens too late (in the engine) rather than upfront.
Request still stands: add upfront validation per Code Analyzer guidelines.
a55f920 to
92a8fcc
Compare
Summary
Integrates the ApexGuru engine into the Code Analyzer CLI. Adds a
--target-orgflag tosf code-analyzer runso users can run Apex anti-pattern analysis against an authenticated org.GUS Ticket
W-22393672 — code-analyzer | Expose ApexGuru engine in CLI with --target-org flag
Changes
--target-orgflag tosf code-analyzer runcommand (standard SF CLI org flag pattern)EnginePluginsFactory@salesforce/core)--target-orgflaggetInsightsandgetEngineInsightsTest Evidence
sf code-analyzer runfinds 1224 violations on dreamhouseTest Status: PASS
Findings Doc
https://docs.google.com/document/d/1zNU-LaHOZIEfGDVHlk5-9MpuCucKEEAseQglyF0bDWk/edit