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: test cases with real file-system operations #33668

Merged

Conversation

sondermanish
Copy link
Contributor

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=""

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

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

  • Yes
  • No

@sondermanish sondermanish self-assigned this May 22, 2024
@sondermanish sondermanish requested a review from a team as a code owner May 22, 2024 17:37
Copy link
Contributor

coderabbitai bot commented May 22, 2024

Walkthrough

The update introduces a new feature flag for enabling Git server auto-commit functionality. It includes enhancements to the Git auto-commit process, schema migrations, and methods for handling repository paths. Significant refactoring was done to improve code maintainability and test coverage, particularly concerning JSON schema migrations and auto-commit logic for client and server-side events.

Changes

Files Change Summary
.../FeatureFlagEnum.java Added new feature flag release_git_server_autocommit_feature_enabled.
.../ApplicationGitFileUtilsCEImpl.java Added JsonSchemaMigration dependency, new methods for handling application resources and repository paths.
.../ApplicationGitFileUtilsImpl.java Injected JsonSchemaMigration in the constructor.
.../FieldNameCE.java Added new constant REPO_NAME.
.../AutoCommitEvent.java Added new constructor and flags for server-side and client-side events.
.../ArtifactGitFileUtilsCE.java Added @NonNull annotation and method for repository suffix paths.
.../CommonGitFileUtilsCE.java Modified reconstructMetadataFromRepo method and added local variable baseRepoSuffix.
.../GitAutoCommitHelper.java Updated method signatures for auto-commit functionality.
.../GitAutoCommitHelperCECompatible.java Introduced interface for auto-committing client and server migrations.
.../GitAutoCommitHelperCECompatibleImpl.java Implemented methods for Git auto-commit functionality.
.../GitAutoCommitHelperImpl.java Added methods for client and server migrations and a check for server-side auto-commit necessity.
.../ImportServiceCEImpl.java Replaced ArtifactSchemaMigration with JsonSchemaMigration for artifact schemas.
.../JsonSchemaMigration.java Renamed method and added new methods for schema compatibility checks.
.../ApplicationPageServiceImpl.java Removed an empty line in the constructor.
.../ApplicationPageServiceCEImpl.java Added logic for auto-commit checks based on client and server flags.
.../CommonGitServiceCE.java Added method getMetadataServerSchemaMigrationVersion.
.../CommonGitServiceCEImpl.java Various method modifications and imports.
.../GitServiceCEImpl.java Updated autoCommitApplication to call autoCommitClientMigration.
.../AutoCommitEventHandlerImpl.java Added import and constructor parameter for CommonGitFileUtils.
.../AutoCommitEventHandlerCE.java Added method autoCommitServerMigration.
.../AutoCommitEventHandlerCEImpl.java Added new methods and refactored existing methods.
.../CreateDBTablePageSolutionCEImpl.java Updated method to use JsonSchemaMigration.migrateArtifactToLatestSchema.
.../GitServiceCETest.java Modified createAppJson method and added new test methods for server migration scenarios.
.../GitFileUtilsTest.java Modified createAppJson method to use migrateArtifactToLatestSchema.
.../GitAutoCommitHelperImplTest.java Added new test methods and updated existing ones for server-side migration checks.
.../ImportServiceTests.java Updated methods to use migrateArtifactToLatestSchema and added assertions for imported artifacts.
.../ApplicationPageServiceAutoCommitTest.java Added test cases for auto-commit functionality related to Git operations.
.../GitFileSystemTestHelper.java Provided methods for setting up and interacting with a Git repository for testing.
.../ImportApplicationTransactionServiceTest.java Updated schema migration calls in the map function.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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 May 22, 2024
@sondermanish sondermanish changed the base branch from release to chore/server-autocommit May 22, 2024 17:37
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: 31

Outside diff range and nitpick comments (5)
app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/AutoCommitEventHandlerImpl.java (1)

[!TIP]
Codebase Verification

The dependencies CommonGitFileUtils and GitExecutor are included in the constructor of AutoCommitEventHandlerImpl but are not utilized within the class. This indicates that these dependencies might be unnecessary.

  • CommonGitFileUtils and GitExecutor are only present in the constructor and not used in any methods.
Analysis chain

Line range hint 22-31: Constructor updated to include CommonGitFileUtils and GitExecutor. Ensure that these dependencies are properly integrated and utilized within the class.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of CommonGitFileUtils and GitExecutor in AutoCommitEventHandlerImpl.

# Test: Search for the usage of CommonGitFileUtils and GitExecutor in AutoCommitEventHandlerImpl.
ast-grep --lang java --pattern $'class AutoCommitEventHandlerImpl {
  $$$
  CommonGitFileUtils($_);
  GitExecutor($_);
  $$$
}'

Length of output: 128



Script:

#!/bin/bash
# Description: Verify the integration of CommonGitFileUtils and GitExecutor in AutoCommitEventHandlerImpl.

# Test: Search for the usage of CommonGitFileUtils in AutoCommitEventHandlerImpl.
rg 'CommonGitFileUtils' --glob '**/AutoCommitEventHandlerImpl.java'

# Test: Search for the usage of GitExecutor in AutoCommitEventHandlerImpl.
rg 'GitExecutor' --glob '**/AutoCommitEventHandlerImpl.java'

Length of output: 729



Script:

#!/bin/bash
# Description: Verify the usage of CommonGitFileUtils and GitExecutor in methods of AutoCommitEventHandlerImpl.

# Test: Search for method implementations in AutoCommitEventHandlerImpl.
ast-grep --lang java --pattern $'class AutoCommitEventHandlerImpl {
  $$$
  $_($_) {
    $$$
  }
  $$$
}' --json

# Test: Search for the usage of CommonGitFileUtils in methods of AutoCommitEventHandlerImpl.
rg 'commonGitFileUtils' --glob '**/AutoCommitEventHandlerImpl.java'

# Test: Search for the usage of GitExecutor in methods of AutoCommitEventHandlerImpl.
rg 'gitExecutor' --glob '**/AutoCommitEventHandlerImpl.java'

Length of output: 810

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

3-3: Consider organizing imports for better readability.

Also applies to: 6-6, 15-15, 27-29

app/server/appsmith-server/src/test/java/com/appsmith/server/git/autocommit/AutoCommitEventHandlerImplTest.java (1)

380-567: Ensure proper resource management in tests.

Consider using try-with-resources or ensuring that all resources are closed properly in tests to prevent resource leaks, especially when dealing with file operations or external connections.

app/server/appsmith-server/src/test/java/com/appsmith/server/git/GitServiceCETest.java (1)

300-301: Refactor to use more descriptive test method names.

The test method names like connectApplicationToGit_WhenUserDoesNotHaveRequiredPermission_OperationFails are quite descriptive, which is good. However, for consistency and clarity, consider using this descriptive naming convention across all test methods. For example, toggleAutoCommit could be renamed to something more descriptive based on what specific condition or scenario it is testing.

app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (1)

999-999: Ensure the comment about backward compatibility is not redundant with previous explanations.

@Slf4j
@Component
@RequiredArgsConstructor
public class GitFileSystemTestHelper {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great job on creating a utility out of this

gitExecutor.createAndCheckoutToBranch(suffix, branchName).block();

// save the files from into repo from json
// This would later be replaced by the files in resources
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create a task for this please

@sondermanish sondermanish changed the base branch from chore/server-autocommit to chore/server-autocommit-refactor May 23, 2024 13:27
@sondermanish sondermanish merged commit 3a8854d into chore/server-autocommit-refactor May 23, 2024
4 of 5 checks passed
@sondermanish sondermanish deleted the chore/autocommit-testcases branch May 23, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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