Skip to content
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

chore: Moved git auth creation and updation to generified artifactservice #38312

Merged
merged 4 commits into from
Dec 24, 2024

Conversation

nidhi-nair
Copy link
Contributor

@nidhi-nair nidhi-nair commented Dec 23, 2024

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Git"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12479630221
Commit: bc85f78
Cypress dashboard.
Tags: @tag.Git
Spec:


Tue, 24 Dec 2024 10:09:28 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced artifact management capabilities, enhancing how applications and their associated artifacts are handled.
    • Added new interfaces and classes for managing artifacts and permissions, including ArtifactService, ArtifactBasedService, and ArtifactPermission.
  • Bug Fixes

    • Updated method calls for SSH key pair generation to utilize the new artifact service, improving functionality.
  • Documentation

    • Minor updates to documentation for clarity regarding new methods and interfaces.
  • Chores

    • Refactored imports to reflect new package structures for artifact permissions.

@nidhi-nair nidhi-nair requested a review from a team as a code owner December 23, 2024 09:52
Copy link
Contributor

coderabbitai bot commented Dec 23, 2024

Walkthrough

The pull request introduces significant modifications to the application's artifact and service management architecture. Key changes include the introduction of a new ArtifactService and related interfaces, as well as updates to method signatures to accommodate the handling of Artifact instead of Application. The restructuring also involves moving permission-related classes to a new package and enhancing the handling of SSH key pair generation and service interactions.

Changes

File Path Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/... - Updated ApplicationServiceCE and ApplicationServiceCEImpl to work with Artifact instead of Application
- Removed createOrUpdateSshKeyPair method
app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/... - Added new interfaces and implementations for ArtifactService
- Introduced ArtifactBasedService and related classes
app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/permissions/... - Moved ArtifactPermission to new package
- Added getEditPermission() method
app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/... - Updated ApplicationControllerCE to use ArtifactService
- Modified SSH key pair generation method

Possibly related PRs

  • chore: package refactors and left over changes for git autocommit pr #33768: The changes in this PR involve updates to the ApplicationServiceCEImpl class, specifically related to handling application IDs and SSH key management, which aligns with the changes in the main PR that also modifies methods in the ApplicationServiceCEImpl class.
  • chore: Converging git refactor changes #33971: This PR includes updates to the ApplicationServiceCEImpl class that involve changing references from application IDs to artifact IDs, which is relevant to the main PR's focus on handling artifacts and their associated methods.
  • chore: autocommit feature branch #34062: The changes in this PR enhance the Git synchronization features, which may relate to the overall context of managing artifacts and their states, similar to the changes in the main PR.
  • chore: Google sheet shared drive support added behind a flag #37776: This PR introduces feature flag handling for Google Sheets integration, which may connect to the broader context of managing artifacts and their configurations, relevant to the main PR's focus on artifact handling.
  • feat: added commit changes #37922: The modifications in this PR enhance the commit functionality within the Git context, which is directly related to the changes in the main PR that also focus on artifact management and Git operations.
  • test: CGS connect negative tests #38120: This PR introduces tests for Git connection functionalities, which are relevant to the changes in the main PR that involve managing artifacts and their connections to Git.
  • chore: Added changes for discard #38152: The changes in this PR introduce discard functionality for artifacts, which is closely related to the main PR's focus on managing artifacts and their states.
  • test: CGS discard tests #38206: This PR adds tests for the discard functionality, which is relevant to the changes in the main PR that also focus on managing artifacts and their states.
  • test: Git integration tests #38237: The changes in this PR enhance the Git integration tests, which are relevant to the main PR's focus on managing artifacts and their interactions with Git.
  • chore: reference lifecycle #38174: This PR introduces new methods for handling Git references, which aligns with the main PR's focus on managing artifacts and their associated operations.

Suggested Labels

Task, Git Product, ok-to-test, Enhancement

Suggested Reviewers

  • sondermanish

Poem

🚀 Artifacts dance, services sing,
Code refactored on a digital wing,
SSH keys flutter, permissions take flight,
Appsmith's architecture shines bright!
Elegance coded with passionate might 🌟


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92a1738 and bc85f78.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceUnitTest.java (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceUnitTest.java

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Dec 23, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (10)
app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceImpl.java (1)

11-14: Constructor clarity
The constructor is straightforward and properly calls the parent class constructor with the correct parameters. In future, consider adding a brief Javadoc comment if additional context is needed.

app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/permissions/ArtifactPermissionCE.java (1)

7-7: Great addition for artifact edit operations.

Adding a dedicated method for edit permission enhances clarity and allows for more granular control. Consider documenting the intended usage, especially if new implementers need guidance.

app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceCEImpl.java (3)

39-40: Question the one-size-fits-all return of applicationService
Currently, getArtifactBasedService always returns applicationService, regardless of the ArtifactType. If more artifact types are introduced, consider either introducing a switch case or a mapping structure to handle future expansions.


57-71: Consider unifying root artifact logic
Lines 57–60 handle a root artifact that already has git data, and lines 65–71 handle a root artifact that has no git data. These branches are logically similar. Combining them or creating a helper function could make the code more concise.


107-112: Confirm acceptable fallback on analytics failure
The code logs a warning and proceeds if analyticsService.sendObjectEvent fails. Ensure this silent fallback is appropriate and doesn’t obscure significant errors that might require remediation.

app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java (2)

170-172: Clearer Documentation
The doc comment is informative. Consider adding explicit mention of the rationale for filtering out non-default branches.


959-962: Doc Clarification
The doc lines introduce mode-based retrieval. Consider making it easier to see how “branchName” and “defaultApplicationId” interplay in different environments.

app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/artifactbased/ArtifactBasedServiceCE.java (1)

12-12: save Method
Accepts a generic Artifact, which is convenient. Again, confirm type safety for specialized artifacts.

app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceCE.java (1)

9-24: ArtifactServiceCE Overview
• The factory method getArtifactBasedService can improve extensibility.
• createOrUpdateSshKeyPair centralizes SSH key logic. Verify usage in all relevant places.

app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java (1)

3552-3553: Generating SSH key pair in chained flow.
When chaining multiple .flatMap calls, ensure that any errors are caught. Consider adding negative tests for coverage.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d52490c and 13d772a.

📒 Files selected for processing (17)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCE.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java (6 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceImpl.java (2 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactService.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceCEImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceImpl.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/artifactbased/ArtifactBasedService.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/artifactbased/ArtifactBasedServiceCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/permissions/ArtifactPermission.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/permissions/ArtifactPermissionCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ApplicationControllerCE.java (3 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ImportArtifactPermissionProvider.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ImportArtifactPermissionProviderCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ArtifactPermission.java (0 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationPermissionCE.java (1 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java (5 hunks)
💤 Files with no reviewable changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ArtifactPermission.java
✅ Files skipped from review due to trivial changes (3)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactService.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/permissions/ArtifactPermission.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ApplicationPermissionCE.java
🔇 Additional comments (24)
app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceImpl.java (3)

1-1: Package structure alignment
The package declaration follows a logical structure. No issues here.


3-7: Imports and annotations
The imports and the @service annotation are well-organized.


9-9: Class naming and hierarchy
This class name is clear, extends the correct parent, and implements the needed interface.

app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/permissions/ArtifactPermissionCE.java (1)

1-1: Package move aligns with the new artifact-based architecture.

Renaming the package from “solutions.ce” to “artifacts.permissions” is consistent with placing all artifact permission interfaces under a dedicated package. Ensure that references in the codebase have been updated accordingly.

✅ Verification successful

Let me verify the package move and its references by searching through the codebase.


Let me check the actual content and references of the ArtifactPermissionCE file to verify the package move.


Let me check if this is a new file or moved from the solutions package.


Package move is part of a new artifact-based architecture implementation

Based on the evidence:

  • This is a new interface in the artifacts.permissions package, not moved from solutions
  • It serves as a base interface for permission-related functionality in the new artifact-based architecture
  • Other permission interfaces still exist in solutions.ce package, suggesting a gradual transition
  • The interface is properly referenced by ArtifactPermission as its parent interface
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for references to the old package name "solutions.ce"
rg -l "solutions\.ce"

# Search for references to the new package name "artifacts.permissions"
rg -l "artifacts\.permissions"

# Find all Java files that might be importing or using ArtifactPermissionCE
rg -l "ArtifactPermissionCE"

# Check git history for the file to understand the package move
git log --oneline -- app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/permissions/ArtifactPermissionCE.java

Length of output: 11323


Script:

#!/bin/bash
# Check the content of ArtifactPermissionCE
cat app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/permissions/ArtifactPermissionCE.java

# Find references to ArtifactPermissionCE with context
rg -A 2 "ArtifactPermissionCE" --type java

Length of output: 1053


Script:

#!/bin/bash
# Check git history to see if this was moved from solutions package
git log --follow --name-status app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/permissions/ArtifactPermissionCE.java

# Search for any similar interface in solutions package
rg -l "interface.*Permission.*CE.*\{" --type java app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/

Length of output: 1892

app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ImportArtifactPermissionProvider.java (2)

4-4: Refactored import to new package is aligned with artifact-centric architecture.
This change cleanly transitions the reference to “ArtifactPermission” into the dedicated “artifacts.permissions” package, reflecting the broader reorganization of permission handling for artifacts.


Line range hint 28-28: Add coverage for the new “requiredPermissionOnTargetArtifact” field in unit tests.
This extra permission field in the builder is crucial for artifact-related operations. Ensure all relevant test cases cover scenarios requiring this permission to avoid regressions.

app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/ImportArtifactPermissionProviderCE.java (1)

6-6: Confirm artifact permission import consistency.

This line changes the import location of ArtifactPermission to a new package, aligning with the refactoring towards a dedicated artifacts namespace. Please verify that all references and usages of ArtifactPermission in related classes and packages are updated accordingly.

Run this script to ensure no leftover references to the old import exist:

✅ Verification successful

The previous search didn't find old imports, but let's verify all current imports and usages to ensure consistency. This will help us confirm if the new import path is being used correctly across the codebase.


Import change verified and consistent across codebase

All imports of ArtifactPermission consistently use the new package path com.appsmith.server.artifacts.permissions.ArtifactPermission. No references to the old import path remain in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for residual references to the old ArtifactPermission import
rg "import com\.appsmith\.server\.solutions\.ArtifactPermission"

Length of output: 66


Script:

#!/bin/bash
# Search for any imports of ArtifactPermission to verify consistency
rg "import.*ArtifactPermission"

# Search for usage of ArtifactPermission class to ensure all references are properly imported
ast-grep --pattern 'ArtifactPermission'

Length of output: 5855

app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java (4)

6-6: New Import for Artifact Service
No immediate issues. Nice to see the artifact-based approach being modularized.


234-238: New Method getPermissionService
Method returns the correct artifact permission object. Good alignment with the new artifact-based structure.


79-79: Implements New Interface
Looks consistent with the new artifact-based interface. Remember to confirm that all method contracts are correctly implemented.

✅ Verification successful

Let me verify the implementation of the interface methods by searching through the codebase.


Let me try a different approach to find the interface and implementation details.


Let me check the implementation of the required methods from the interface.


Interface Implementation Verified Successfully
The ApplicationServiceCEImpl correctly implements both required methods from ArtifactBasedServiceCE interface: findById(String id, AclPermission aclPermission) and save(Artifact artifact) with proper type parameters and signatures.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# First, let's find the ArtifactBasedServiceCE interface definition
ast-grep --pattern 'interface ArtifactBasedServiceCE<$_> {
  $$$
}'

# Then, let's check the implementation in ApplicationServiceCEImpl
ast-grep --pattern 'class ApplicationServiceCEImpl $$$implements ApplicationServiceCE, ArtifactBasedServiceCE<Application> {
  $$$
}'

Length of output: 205


Script:

#!/bin/bash
# Search for files containing ArtifactBasedServiceCE
fd -e java | xargs rg "ArtifactBasedServiceCE" -B 2 -A 5

# Search for method implementations in ApplicationServiceCEImpl
fd "ApplicationServiceCEImpl.java" | xargs rg "public.*implements.*ArtifactBasedServiceCE" -A 10

Length of output: 4385


Script:

#!/bin/bash
# Search for the required method implementations in ApplicationServiceCEImpl
fd "ApplicationServiceCEImpl.java" | xargs rg "public.*Mono<Application>.*findById|public.*Mono<Application>.*save" -B 1 -A 5

Length of output: 2104


218-219: Type Safety Check
Casting from Artifact to Application might cause runtime errors if non-Application artifacts are passed. Consider validating the type or using generics with safer constraints.

app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/artifactbased/ArtifactBasedService.java (1)

1-5: New Interface
This interface is succinct and clearly extends the CE version with minimal overhead. Good layering.

app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/artifactbased/ArtifactBasedServiceCE.java (2)

14-14: getPermissionService Method
This is a clean way to retrieve permissions for the artifact.


10-10: findById Method
Ensure that all permissions checks are correctly enforced.

✅ Verification successful

Let me search for the implementation and usage of this findById method to verify the permissions checks.


Let me search for the implementation details of the permission checks.


Let me search for the query builder implementation to understand how permissions are enforced.


Let me try a different search pattern to find the permission enforcement implementation.


Based on the code analysis, I can now provide a definitive response about the permission checks.

Permission Checks are Properly Enforced
The findById method correctly enforces permissions through the repository layer. The implementation in BaseAppsmithRepositoryCEImpl uses a query builder that validates the provided AclPermission against the permission groups in the policy map, ensuring proper access control.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for the implementation of findById method in ArtifactBasedServiceCE
ast-grep --pattern 'public Mono<$_> findById(String $_, AclPermission $_) {
  $$$
}'

# Search for all usages of findById method to check permission enforcement
rg "findById\(" -A 3

Length of output: 74093


Script:

#!/bin/bash
# Search for the base repository implementation to see how permissions are enforced
ast-grep --pattern 'class BaseAppsmithRepositoryCEImpl {
  $$$
  findById($_, $_, $_) {
    $$$
  }
  $$$
}'

# Search for permission checks in query builder
rg "permission\(" -A 3 -B 3

Length of output: 118013


Script:

#!/bin/bash
# Search for the query builder implementation
ast-grep --pattern 'class $_ implements QueryBuilder {
  $$$
  permission($_, $_) {
    $$$
  }
  $$$
}'

# Search for permission checks in repository implementation
ast-grep --pattern 'class BaseAppsmithRepositoryCEImpl {
  $$$
  queryBuilder() {
    $$$
  }
  $$$
}'

Length of output: 211


Script:

#!/bin/bash
# Search for repository implementation with permission checks
rg "findById.*permission" -A 5 -B 5

# Search for query builder permission implementation
rg "permission\(.*\)" -A 5 -B 5 --type java

Length of output: 68920

app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceImpl.java (2)

3-3: Artifact Service Import
Importing artifact-based service is consistent with broader refactoring.


25-26: Implements ArtifactBasedService
The extension harmonizes with the new structure, providing full artifact-based features for ApplicationServiceImpl.

app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCE.java (2)

6-6: Import for Artifact domain appears consistent.
No issues with importing this domain class. Please ensure any additional fields or references within the Artifact object are documented for all callers.


32-32: Ensure usage alignment with the new parameter type.
Changing the parameter from Application to Artifact impacts callers. Verify that all consumers of this save method correctly build or convert their Application objects into an Artifact object.

✅ Verification successful

Let me search for usages of this save method to verify the parameter type change impact.


Let me try a different search pattern to find usages of this save method and its implementations.


Parameter type change is properly aligned with inheritance hierarchy

The search results show that the save(Artifact application) method is part of a proper inheritance chain:

  • ArtifactBasedServiceCE defines the base contract with save(Artifact artifact)
  • ApplicationServiceCE inherits and maintains the same signature
  • ApplicationServiceCEImpl implements it with proper type casting from Artifact to Application

No issues found with the parameter type change as it follows proper OOP principles and maintains type safety.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for save method calls with Application/Artifact parameter
ast-grep --pattern 'save($_)'

# Search for direct references to ApplicationServiceCE
rg "ApplicationServiceCE" -A 2

# Search for implementations of save method
ast-grep --pattern 'save(Artifact $_) {
  $$$
}'

Length of output: 65972


Script:

#!/bin/bash
# Search for ApplicationServiceCE class and its save method
ast-grep --pattern 'class ApplicationServiceCE {
  $$$
  save($_) {
    $$$
  }
  $$$
}'

# Search for calls to save method with Application/Artifact parameter
rg "save\((Application|Artifact)" -A 2

Length of output: 1548

app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ApplicationControllerCE.java (2)

67-67: Field injection appears fine.
The ArtifactService dependency is clearly declared. Ensure consistent usage and confirm no cyclical dependencies exist.


254-255: Using ArtifactService for SSH key pair creation.
This change centralizes SSH key operations. Confirm that error scenarios (e.g., invalid branchedApplicationId) are handled robustly within the artifact service.

✅ Verification successful

Let me search for the error handling implementation in the artifact service.


Let me try a different search pattern to find the implementation.


Let me check the implementation and error handling in these identified files.


Error handling for SSH key pair creation is robust and well-implemented.
The implementation in ArtifactServiceCEImpl handles various error scenarios appropriately:

  • Invalid branchedArtifactId throws NO_RESOURCE_FOUND exception
  • Missing root artifact throws INVALID_GIT_CONFIGURATION exception
  • Permission checks are enforced through artifactPermission.getEditPermission()
  • Global exception handler properly formats and returns these errors to the client
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for ArtifactService implementation and error handling
ast-grep --pattern 'class $_ implements ArtifactService {
  $$$
  createOrUpdateSshKeyPair($$$) {
    $$$
  }
  $$$
}'

# Also search for the interface definition
ast-grep --pattern 'interface ArtifactService {
  $$$
  createOrUpdateSshKeyPair($$$);
  $$$
}'

# Look for any exception handling related to SSH keys
rg -A 5 "createOrUpdateSshKeyPair|SshKey" --type java

Length of output: 120


Script:

#!/bin/bash
# Search for ArtifactService class files
fd -e java "ArtifactService"

# Search for SSH key pair related code
rg -l "createOrUpdateSshKeyPair" --type java

# Look for exception handling patterns in artifact-related files
rg "throw\s+\w+Exception|@ExceptionHandler" --type java -l | xargs rg "Artifact|SSH|Key" -l

Length of output: 1077


Script:

#!/bin/bash
# Check the implementation in ArtifactServiceCEImpl
cat app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceCEImpl.java

# Check the interface definition
cat app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceCE.java

# Check exception handling
cat app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java

Length of output: 23992

app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationServiceCETest.java (4)

17-18: New imports for ArtifactService and ArtifactType.
These imports align with the refactored SSH key creation flow. Ensure that these references don't break older tests relying on removed GitAuth calls.


181-183: Injecting ArtifactService in test class.
Confirm usage of this bean across test scenarios related to artifact-based functionalities. Avoid mixing older calls to applicationService for SSH key creation.


3563-3564: Creating SSH key pair for child application.
Keys remain null in child apps, which is the intended behavior. The test coverage looks appropriate. Keep verifying that business logic is consistent with the new artifact-based approach.


3522-3523: Creating or updating SSH key pair for newly saved application.
The test logic is sound. Validate that any test failures around key creation fail gracefully rather than silently passing.

✅ Verification successful

Let me gather information about the SSH key pair creation and error handling in the test.


Let me check how the SSH key pair creation is handled in the test and its error cases.


Let me try a different approach to find the test implementation and error handling.


Let me check the implementation of the SSH key pair creation method to understand the error handling.


Let me try one more search to find the implementation and error handling.


SSH key pair creation test has proper error handling and validation

The implementation in ArtifactServiceCEImpl already includes comprehensive error handling:

  • Throws AppsmithException if artifact is not found
  • Validates root artifact existence
  • Handles invalid git configuration cases
  • Includes error handling for analytics events

The test in ApplicationServiceCETest verifies the success path with proper assertions on the generated keys and timestamps. The error cases are handled at the service layer with specific exceptions that would fail the test if thrown.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for SSH key pair related test cases and error handling
rg -l "createOrUpdateSshKeyPair" --type java

# Look for test assertions and error handling around SSH key creation
ast-grep --pattern 'artifactService.createOrUpdateSshKeyPair($$$)'

# Find related error handling test cases
rg "createOrUpdateSshKeyPair.*error|exception" --type java -A 3

Length of output: 70305


Script:

#!/bin/bash
# Look for the test method containing the SSH key pair creation
rg -A 10 "createOrUpdateSshKeyPair.*test" --type java

# Find the test assertions around SSH key pair creation
rg -B 5 -A 10 "artifactService.*createOrUpdateSshKeyPair.*assert" --type java

Length of output: 135


Script:

#!/bin/bash
# Find the test class and surrounding context
rg -B 10 -A 10 "createOrUpdateSshKeyPair.*savedApplication" --type java

# Look for error handling in the artifact service implementation
rg -B 5 -A 10 "class.*ArtifactServiceCEImpl.*implements.*ArtifactServiceCE" --type java
rg -B 5 -A 10 "createOrUpdateSshKeyPair.*throw" --type java

Length of output: 9043


Script:

#!/bin/bash
# Find the implementation of createOrUpdateSshKeyPair
rg -B 5 -A 15 "createOrUpdateSshKeyPair.*\{" --type java

# Look for error handling in the artifact service
rg -B 2 -A 5 "ArtifactServiceCE.*createOrUpdateSshKeyPair" --type java

Length of output: 131


Script:

#!/bin/bash
# Search for the method implementation in ArtifactServiceCEImpl
cat app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/base/ArtifactServiceCEImpl.java

# Look for test assertions and error cases
rg -B 2 -A 5 "StepVerifier.*createOrUpdateSshKeyPair" --type java

Length of output: 6514

Comment on lines +73 to +92
// Fetch root application and then make updates. We are storing the git metadata only in root
// application
if (!StringUtils.hasLength(gitData.getDefaultArtifactId())) {
return Mono.error(new AppsmithException(
AppsmithError.INVALID_GIT_CONFIGURATION,
"Unable to find root " + artifactTypeName + ", please connect your " + artifactTypeName
+ " to remote repo to resolve this issue."));
}
gitAuth.setRegeneratedKey(true);

return artifactBasedService
.findById(gitData.getDefaultArtifactId(), artifactPermission.getEditPermission())
.flatMap(baseApplication -> {
GitArtifactMetadata gitArtifactMetadata = baseApplication.getGitArtifactMetadata();
gitArtifactMetadata.setDefaultApplicationId(baseApplication.getId());
gitArtifactMetadata.setGitAuth(gitAuth);
baseApplication.setGitArtifactMetadata(gitArtifactMetadata);
return artifactBasedService.save(baseApplication);
});
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the code analysis, I can now provide a final response:

Add optimistic locking to prevent concurrent SSH key updates
Add @Version field to GitAuth entity and use Spring's optimistic locking to handle concurrent modifications. This will ensure that if two processes try to update the SSH key simultaneously, one will fail with an OptimisticLockingFailureException rather than silently overwriting each other's changes.

Example locations that need attention:

  • GitAuth.java - Add version field
  • ArtifactServiceCEImpl.createOrUpdateSshKeyPair() - Handle the optimistic locking exception and retry if needed
🔗 Analysis chain

Flag potential concurrency scenario
If multiple clients simultaneously call this function for the same artifact, two processes might generate different SSH keys in rapid succession. Consider adding steps (e.g., optimistic locking or more robust concurrency control) to avoid inconsistent or lost updates.


Let me search for relevant code to verify the concurrency concerns.

Let me also check for any transaction or version control mechanisms in the artifact service:

This will help us understand if there are any existing concurrency controls and the full context of the SSH key generation flow.


Let me try a different search pattern to find the relevant code:


Let me check the underlying service implementation to understand if there are any concurrency controls:


Let me try one more search to find the Application entity and service implementation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for the class and method definition to understand the context
ast-grep --pattern 'class $_ {
  $$$
  generateSSHKeyPair($$$) {
    $$$
  }
  $$$
}'

# Search for any existing concurrency control mechanisms
rg -i "lock|synchronized|atomic|concurrent" app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/

Length of output: 205


Script:

# Search for transaction annotations or version fields
rg -i "@transaction|@version|optimisticlock" app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/

# Check the entity/model class for version fields
ast-grep --pattern 'class $_ {
  $$$
  @Version
  private $_ version;
  $$$
}'

Length of output: 199


Script:

#!/bin/bash
# Search for the artifact service implementation
rg -l "class.*ArtifactService.*Impl" app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/ | xargs cat

# Search for the entity class that might contain version field
fd "Artifact.*\.java" app/server/appsmith-server/src/main/java/com/appsmith/server/ -x cat {}

# Look for any save operations in the service
rg -A 5 "save\(" app/server/appsmith-server/src/main/java/com/appsmith/server/artifacts/

Length of output: 65961


Script:

# Search for the ArtifactBasedService implementation
fd "ArtifactBasedService.*Impl\.java" app/server/appsmith-server/src/main/java/ -x cat {}

# Search for any MongoDB optimistic locking annotations
rg -i "@version|@optimisticlock" app/server/appsmith-server/src/main/java/com/appsmith/server/domains/

Length of output: 198


Script:

# Search for Application entity class
rg -l "class Application" app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ | xargs cat

# Search for ApplicationService implementation
fd "ApplicationService.*Impl\.java" app/server/appsmith-server/src/main/java/ -x cat {}

# Look for any transaction or locking mechanisms in the service layer
rg -i "@transactional|@lock|synchronized" app/server/appsmith-server/src/main/java/com/appsmith/server/services/

Length of output: 77806

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ApplicationController.java (1)

Line range hint 26-38: Constructor injection
Including ArtifactService at the beginning of the parameter list clarifies its importance. Ensure any relevant usage is explained or documented so future maintainers understand why it’s now part of the constructor.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13d772a and 74bba57.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ApplicationController.java (3 hunks)
🔇 Additional comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ApplicationController.java (1)

4-4: Import looks good
These changes properly import the new ArtifactService.

Copy link

Failed server tests

  • com.appsmith.server.controllers.ApplicationControllerTest#whenFileUploadedWithLongHeader_thenVerifyErrorStatus
  • com.appsmith.server.controllers.ApplicationControllerTest#whenFileUploadedWithShortHeader_thenVerifySuccessStatus
  • com.appsmith.server.git.autocommit.AutoCommitServiceTest#testAutoCommit_whenAutoCommitAlreadyInProgressOnAnotherBranch_returnsLocked
  • com.appsmith.server.git.autocommit.AutoCommitServiceTest#testAutoCommit_whenAutoCommitAlreadyInProgressOnSameBranch_returnsInProgress
  • com.appsmith.server.git.autocommit.AutoCommitServiceTest#testAutoCommit_whenAutoCommitEligibleButPrerequisiteNotComplete_returnsRequired
  • com.appsmith.server.git.autocommit.AutoCommitServiceTest#testAutoCommit_whenAutoCommitNotEligible_returnsFalse
  • com.appsmith.server.git.autocommit.AutoCommitServiceTest#testAutoCommit_whenNoGitMetadata_returnsNonGitApp
  • com.appsmith.server.git.autocommit.AutoCommitServiceTest#testAutoCommit_whenOnlyClientIsEligibleForMigration_commitSuccess
  • com.appsmith.server.git.autocommit.AutoCommitServiceTest#testAutoCommit_whenOnlyServerIsEligibleForMigration_commitSuccess
  • com.appsmith.server.git.autocommit.AutoCommitServiceTest#testAutoCommit_whenServerIsRunningMigrationCallsAutocommitAgainOnDiffBranch_ReturnsAutoCommitLocked
  • com.appsmith.server.git.autocommit.AutoCommitServiceTest#testAutoCommit_whenServerIsRunningMigrationCallsAutocommitAgainOnSameBranch_ReturnsAutoCommitInProgress
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#autoCommitApplication_WhenAllConditionsMatched_AutoCommitTriggered
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#autoCommitApplication_WhenAnotherCommitIsRunning_AutoCommitNotTriggered
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#autoCommitApplication_WhenAutoCommitDisabled_AutoCommitNotTriggered
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#autoCommitApplication_WhenBranchIsProtected_AutoCommitNotTriggered
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#autoCommitApplication_WhenRemoteAhead_AutoCommitNotTriggered
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#autoCommitApplication_WhenServerDoesNotRequireMigration_returnFalse
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#autoCommitApplication_WhenServerRequiresMigration_successIfEverythingIsRight
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#getAutoCommitProgress_WhenAutoCommitRunning_ReturnsValidResponse
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#getAutoCommitProgress_WhenNoAutoCommitFinished_ReturnsValidResponse
  • com.appsmith.server.git.autocommit.helpers.GitAutoCommitHelperImplTest#getAutoCommitProgress_WhenNoAutoCommitRunning_ReturnsValidResponse
  • com.appsmith.server.refactors.ce.RefactoringServiceCEImplTest#testRefactorCollectionName_withActions_returnsValidLayout
  • com.appsmith.server.refactors.ce.RefactoringServiceCEImplTest#testRefactorCollectionName_withDuplicateName_throwsError
  • com.appsmith.server.refactors.ce.RefactoringServiceCEImplTest#testRefactorCollectionName_withEmptyActions_returnsValidLayout
  • com.appsmith.server.services.ce.ApplicationSnapshotServiceUnitTest#createApplicationSnapshot_WhenApplicationTooLarge_SnapshotCreatedSuccessfully
  • com.appsmith.server.services.ce.ApplicationSnapshotServiceUnitTest#restoreSnapshot_WhenSnapshotHasMultipleChunks_RestoredSuccessfully
  • com.appsmith.server.services.ce.ApplicationSnapshotServiceUnitTest#test
  • com.appsmith.server.solutions.ce.ActionExecutionSolutionCEImplTest#testEnrichExecutionParams_withBlobReference_performsSubstitutionCorrectly
  • com.appsmith.server.solutions.ce.ActionExecutionSolutionCEImplTest#testExecuteAPIWithParameterMapAsLastPart
  • com.appsmith.server.solutions.ce.ActionExecutionSolutionCEImplTest#testExecuteAPIWithUsualOrderingOfTheParts
  • com.appsmith.server.solutions.ce.ActionExecutionSolutionCEImplTest#testExecuteAction_withMalformedExecuteActionDTO_failsValidation
  • com.appsmith.server.solutions.ce.ActionExecutionSolutionCEImplTest#testExecuteAction_withoutActionId_failsValidation
  • com.appsmith.server.solutions.ce.ActionExecutionSolutionCEImplTest#testExecuteAction_withoutExecuteActionDTOPart_failsValidation
  • com.appsmith.server.solutions.ce.ActionExecutionSolutionCEImplTest#testParsePartsAndGetParamsFlux_withBlobIdentifiers_replacesValueInParam

subrata71
subrata71 previously approved these changes Dec 23, 2024
Copy link
Contributor

@subrata71 subrata71 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

return artifactBasedService
.findById(branchedArtifactId, artifactPermission.getEditPermission())
.switchIfEmpty(Mono.error(
new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, artifactTypeName, branchedArtifactId)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: ACL_NO_RESOURCE_FOUND is a preferred one

Edit: It's fine to leave as is, since it's not aligned with the intent of the PR

@@ -248,7 +251,8 @@ public Mono<ResponseDTO<ArtifactImportDTO>> importApplicationFromFile(
@PostMapping("/ssh-keypair/{branchedApplicationId}")
public Mono<ResponseDTO<GitAuth>> generateSSHKeyPair(
@PathVariable String branchedApplicationId, @RequestParam(required = false) String keyType) {
return service.createOrUpdateSshKeyPair(branchedApplicationId, keyType)
return artifactService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ: What's the plan for the controller endpoints? Are we considering introducing dedicated endpoints for each artifact type when handling Git-related operations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the url path will be differentiated by artifact. This is to not introduce too many changes to the code base in one go. We're already in flux with feature based packages and the producer consumer patterns for features. We'll keep this in mind and think about moving to a single controller if it makes sense in the long run.

This is especially because as of today, feature parity need not exist between artifacts and the controller layer is our line of control.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/ce/RefactoringServiceCEImplTest.java (1)

290-290: Repeated stubbing.
You’re using doReturn() for the same method again. If multiple tests require the same stubbing, consider extracting a shared utility or a dedicated setup method to ensure consistency across tests.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74bba57 and 92a1738.

📒 Files selected for processing (6)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/controllers/ApplicationControllerTest.java (0 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java (4 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImplTest.java (8 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/ce/RefactoringServiceCEImplTest.java (3 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceUnitTest.java (4 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java (1 hunks)
💤 Files with no reviewable changes (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/controllers/ApplicationControllerTest.java
🔇 Additional comments (28)
app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/ce/RefactoringServiceCEImplTest.java (2)

164-164: Stubbing approach is consistent.
Using doReturn() when() is appropriate here to avoid side effects. Confirm that your test remains encapsulated without relying on the real applicationService for unmocked methods.


69-69: Confirm that partial mocking is indeed needed.
Switching from @MockBean to @SpyBean for the ApplicationService will now preserve real method behavior, only overriding stubs where specified. Verify you truly require partial mocking for correct test coverage.

✅ Verification successful

Let me gather information about the test class and its usage of @SpyBean to verify if partial mocking is necessary.


@SpyBean usage is justified for ApplicationService

The partial mocking is necessary here as the test class uses applicationService in conjunction with findById method where real behavior is needed, while still allowing for potential stubbing of other methods. This is evident from the test setup where applicationService.findById is used to return an application with specific evaluation version for test scenarios.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Check the test file content to understand the usage of @SpyBean
cat "app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/ce/RefactoringServiceCEImplTest.java"

# Search for any mock/stub method calls on ApplicationService in the test file
rg "applicationService\." "app/server/appsmith-server/src/test/java/com/appsmith/server/refactors/ce/RefactoringServiceCEImplTest.java" -B 2 -A 2

Length of output: 14872

app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitServiceTest.java (6)

81-81: Switching to @SpyBean looks good.
Using a spy instead of a mock is suitable for partial mocking. Ensure that you selectively mock critical methods to avoid unexpected interactions with real logic.


204-206: Stubbing with doReturn is appropriate.
This pattern is a good fit for partial mocking, ensuring synchronous returns from a reactive source. Continue to confirm actual method behaviors align with test expectations.


208-210: Consistent approach for partial mocking.
Again, stubbing the reactive call is properly done. Just double-check that the real methods aren’t unintentionally triggered.


228-230: Repeated stub usage is acceptable.
Ensuring consistent stubbing fosters reliable tests. Keep verifying that real methods only run where needed.


485-487: Maintaining uniformity in doReturn stubs.
This is in line with the partial mocking approach. Validate the underlying logic for your test scenario.


489-491: Reiterating the same stubbing strategy on findByBranchNameAndBaseApplicationId.
Continue to ensure that these calls are essential and that actual method calls are well tested.

app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/helpers/GitAutoCommitHelperImplTest.java (15)

47-47: Switched from @MockBean to @SpyBean

This update allows partial mocking of real methods, ensuring more realistic test coverage. Good improvement!


84-86: Using doReturn for stubbing is appropriate

The switch to "doReturn(...).when()" matches the use of a spy object rather than a pure mock. This is the correct approach for partial mocks.


89-91: Consistent usage of doReturn for partial mocks

Repeated usage of doReturn for stubbing aligns well with the @SpyBean approach. This helps maintain clarity in test behavior.


109-111: Partial mock stubbing technique

Again, good job utilizing doReturn when stubbing methods on the spied service.


112-114: Uniform approach across multiple stubs

Maintaining consistency in the stubbing approach helps in readability and reduces confusion. This is well-aligned with @SpyBean usage.


131-133: Use of doReturn ensures correct invocation

This helps prevent calling the real method unintentionally, especially if the method might produce side effects. Nicely done!


136-138: Clarity in partial mocking logic

Continuing the same method stubbing pattern fosters test maintainability and better clarity.


164-166: Appropriate doReturn usage for real application service instance

The approach ensures minimal reliance on real dependencies, making tests more robust.


167-169: Consistent stubbing in test method

Repeated usage of the same doReturn pattern across methods is commendable, ensuring consistent testing practices.


263-265: Protecting real method calls

Using doReturn helps prevent unintended real method invocations that might affect test results. Looks good.


266-268: Ensuring consistent stubbing across application calls

Maintaining the uniform stubbing approach reduces confusion across tests.


299-301: SpyBean stubbing remains correct

Sustaining the doReturn approach allows a predictable, test-friendly environment.


303-305: Consistent mocking in server migration test

The uniform pattern assures consistency across multiple migration scenarios.


344-346: Reused partial mock approach for findById

Ensuring consistent test designs across the suite is a best practice. Good job maintaining it.


348-350: Stubbing matches the earlier lines

Continuing the same partial mock pattern cements a reliable testing methodology.

app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java (1)

110-111: Verify test coverage with @SpyBean

The change from @MockBean to @SpyBean for ApplicationService is appropriate for allowing real method calls. However, ensure that the test suite adequately covers the ApplicationService methods that will now be executed.

Run the following script to check test coverage for ApplicationService methods used in these tests:

✅ Verification successful

Change from @MockBean to @SpyBean is appropriate

The change from @MockBean to @SpyBean for ApplicationService is correct and doesn't introduce any risks. The test class doesn't directly verify ApplicationService behavior, and the service is only injected as a dependency in ActionExecutionSolutionCEImpl. The real methods from ApplicationService are only used for analytics tracking, which is non-critical for the core test scenarios.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check test coverage for ApplicationService methods
# Look for ApplicationService method calls in the test file
rg "applicationService\." app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java -A 2

# Look for test methods that might be affected by this change
ast-grep --pattern 'void test$_() {
  $$$
  applicationService.$_($$$)
  $$$
}'

Length of output: 227


Script:

#!/bin/bash
# Let's try a broader search to understand the usage context
# First, check if applicationService is used in any test methods
rg "applicationService" app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java -B 2 -A 2

# Also check the implementation class to understand expected interactions
rg "ApplicationService" app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java -B 2 -A 2

# Look for any verify/when calls on applicationService in the test file
rg "(verify|when)\(applicationService" app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java

Length of output: 1527


Script:

#!/bin/bash
# Let's check the test class implementation to understand how ApplicationService is used
cat app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImplTest.java

# Also check the implementation class to see what methods of ApplicationService are actually used
cat app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/ActionExecutionSolutionCEImpl.java

Length of output: 81358

app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceUnitTest.java (4)

86-88: Mocking the findBranchedApplicationId method
Good use of doReturn for partial mocks to replace only targeted behavior.


27-27: Adopting partial mocking strategy
Adding the SpyBean import indicates partial mocking. Ensure that this approach is necessary and that services aren't unintentionally invoked.

✅ Verification successful

Let me verify the usage of @SpyBean in the test class and related files to understand the mocking strategy.


After analyzing the test file and the usage of @SpyBean across the codebase, I can provide a final response:

Partial mocking strategy is appropriate here
The use of @SpyBean for ApplicationService is justified as the test needs to selectively mock findBranchedApplicationId while allowing other methods to execute normally for snapshot creation and restoration tests.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Check the test file content to understand the spy usage
cat "app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceUnitTest.java"

# Find other usages of SpyBean in test files
rg "@SpyBean" --type java -A 2

Length of output: 52080


45-45: Using a spy bean for ApplicationService
This allows real method calls except stubs for specific methods. Verify there's no undesired behaviour from calling real code.

✅ Verification successful

Let me gather information about the usage of spy beans in the test class to verify if there are any potential issues.


Let me check the test class implementation to understand how the spy bean is being used.


Let me check the ApplicationService implementation to understand what real methods might be called.


Let me check the CE compatible service implementation.


Let me check the base CE implementation to understand the actual methods.


Based on the analysis of the test class and the ApplicationService implementation, I can now provide the final response.

@SpyBean usage is appropriate here
The spy bean for ApplicationService is used correctly in the test class. The test methods only mock specific methods (findBranchedApplicationId and findById) while allowing other real methods to be called. The mocked methods are well-defined and the test assertions verify the expected behavior without any undesired side effects.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# First, let's look at the test class implementation to understand the context
rg -A 10 -B 10 "@SpyBean" "app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceUnitTest.java"

# Let's also check if there are any mocked methods or verifications on the spy
rg "when\(.*ApplicationService" "app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceUnitTest.java"
rg "verify\(.*ApplicationService" "app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceUnitTest.java"

Length of output: 961


Script:

#!/bin/bash
# Let's look at the full test class to understand the usage of applicationService spy
cat "app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/ApplicationSnapshotServiceUnitTest.java"

# Also check the ApplicationService class to understand what methods might be called
fd -e java -E "test" ApplicationService.java

Length of output: 9111


Script:

#!/bin/bash
# Check the ApplicationService implementation
cat "app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationService.java"

Length of output: 317


Script:

#!/bin/bash
# Find and check the CE compatible service implementation
fd -e java ApplicationServiceCECompatible
cat $(fd -e java ApplicationServiceCECompatible | head -n 1)

Length of output: 2797


Script:

#!/bin/bash
# Check the base CE implementation
fd -e java ApplicationServiceCEImpl
cat $(fd -e java ApplicationServiceCEImpl | head -n 1)

Length of output: 50872


123-125: Mocking the findById call
Check if additional validations are needed to ensure the real method’s side effects don’t carry over in tests.

Copy link

Failed server tests

  • com.appsmith.server.services.ce.ApplicationSnapshotServiceUnitTest#restoreSnapshot_WhenSnapshotHasMultipleChunks_RestoredSuccessfully

@nidhi-nair nidhi-nair added the ok-to-test Required label for CI label Dec 24, 2024
@nidhi-nair nidhi-nair merged commit d9a3253 into release Dec 24, 2024
51 checks passed
@nidhi-nair nidhi-nair deleted the chore/generify-ssh-gen branch December 24, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants