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

Development: Fix the broken git programming submission e2e tests #9546

Merged

Conversation

SimonEntholzer
Copy link
Contributor

@SimonEntholzer SimonEntholzer commented Oct 21, 2024

Checklist

General

Server

  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I documented the Java code using JavaDoc style.

Motivation and Context

The MySQL, Local e2e tests have 6 failing tests at the moment. This is caused by a change in the authentication of users. Previously a repository was fetched by using the user name and the exercise id. In #9425 I changed this method, to use less database calls, and to fetch the repository directly by its repositoryURL from the database. It seems in the e2e tests is a misconfiguration somewhere, as the URLs requested to be fetched, do not seem to be in the database.

Description

To fix the tests, until we have found the problem in the e2e tests themselves, I reverted the change to use the old and more complex repository retrieval method.

Steps for Testing

  1. Clone a programming exercise repository

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Performance Review

Code Review

  • Code Review 1
  • Code Review 2

Test Coverage

Screenshots

@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) programming Pull requests that affect the corresponding module labels Oct 21, 2024
@SimonEntholzer SimonEntholzer marked this pull request as ready for review October 22, 2024 06:01
@SimonEntholzer SimonEntholzer requested a review from a team as a code owner October 22, 2024 06:01
Copy link

coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request modifies the retrieveParticipationForRepository method in the ProgrammingExerciseParticipationService class to enhance error handling when a student participation cannot be found. If an empty optional is returned, the method now retrieves all student participations and throws an EntityNotFoundException with detailed information about available repository URIs. Additionally, changes in the LocalVCServletService class update the method signature to include a ProgrammingExercise object, altering the authorization flow to improve context-awareness when retrieving participations.

Changes

File Change Summary
src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseParticipationService.java Modified retrieveParticipationForRepository to handle cases where participation is not found, enhancing error reporting by including available repository URIs in the exception message.
src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java Updated authorizeUser method to call the modified retrieveParticipationForRepository with an additional ProgrammingExercise parameter, changing the method's logic flow for participation retrieval. Minor comment adjustments made.

Possibly related PRs

Suggested labels

tests, ready for review, bugfix

Suggested reviewers

  • JohannesStoehr
  • coolchock
  • krusche
  • BBesrour

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 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 or @coderabbitai title 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.

Copy link

@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

🧹 Outside diff range and nitpick comments (2)
src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseParticipationService.java (1)

Line range hint 1-590: Summary and Recommendations

The changes to the retrieveParticipationForRepository method improve error handling when a student participation cannot be found. However, there are opportunities for further enhancements:

  1. Improve the error handling by using more efficient logging and avoiding exposure of sensitive information in exception messages.
  2. Consider refactoring the class to improve modularity, testability, and adherence to the Single Responsibility Principle.
  3. Standardize dependency injection by using constructor injection consistently throughout the class.

These changes will lead to a more maintainable and robust service class. Please review the suggested improvements and consider implementing them in future iterations.

src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java (1)

439-443: LGTM! Method signature update improves context awareness.

The updated retrieveParticipationForRepository method call now includes additional parameters (exercise, isPracticeRepository, includeInactive), which aligns with the changes mentioned in the AI-generated summary. This update provides more context and flexibility when retrieving participations.

Consider creating a separate GitHub issue to track the TODO item regarding the playwright configuration. This will help ensure it's not forgotten and can be addressed in future updates.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f3eaf6d and 6259b32.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseParticipationService.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseParticipationService.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

src/main/java/de/tum/cit/aet/artemis/programming/service/localvc/LocalVCServletService.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

🔇 Additional comments (2)
src/main/java/de/tum/cit/aet/artemis/programming/service/ProgrammingExerciseParticipationService.java (2)

Line range hint 1-590: Consider refactoring for improved modularity and testability.

While the changes are focused on a specific method, there are some general improvements that could be made to enhance the overall quality of the class:

  1. The class has many responsibilities and is quite large. Consider breaking it down into smaller, more focused classes.
  2. Some methods are quite long and complex. Consider extracting some logic into private helper methods for better readability and testability.
  3. The class uses a mix of constructor injection and field injection. Consider using constructor injection consistently for all dependencies.

Here are some suggestions for refactoring:

  1. Extract repository-related operations into a separate ProgrammingExerciseRepositoryService class.
  2. Create a ParticipationFactory class to handle the creation and setup of different types of participations.
  3. Use constructor injection for all dependencies:
@Service
public class ProgrammingExerciseParticipationService {
    private final ProgrammingExerciseStudentParticipationRepository studentParticipationRepository;
    private final SolutionProgrammingExerciseParticipationRepository solutionParticipationRepository;
    // ... other repositories

    private final VersionControlService versionControlService;
    private final GitService gitService;
    private final AuthorizationCheckService authorizationCheckService;
    private final UserRepository userRepository;
    private final AuxiliaryRepositoryService auxiliaryRepositoryService;

    public ProgrammingExerciseParticipationService(
            ProgrammingExerciseStudentParticipationRepository studentParticipationRepository,
            SolutionProgrammingExerciseParticipationRepository solutionParticipationRepository,
            // ... other repositories
            VersionControlService versionControlService,
            GitService gitService,
            AuthorizationCheckService authorizationCheckService,
            UserRepository userRepository,
            AuxiliaryRepositoryService auxiliaryRepositoryService) {
        this.studentParticipationRepository = studentParticipationRepository;
        this.solutionParticipationRepository = solutionParticipationRepository;
        // ... initialize other repositories
        this.versionControlService = versionControlService;
        this.gitService = gitService;
        this.authorizationCheckService = authorizationCheckService;
        this.userRepository = userRepository;
        this.auxiliaryRepositoryService = auxiliaryRepositoryService;
    }
    // ... rest of the class
}

To ensure these refactoring suggestions are applicable, let's check the usage of this service:

#!/bin/bash
# Search for usages of ProgrammingExerciseParticipationService
rg "ProgrammingExerciseParticipationService" -t java

523-530: ⚠️ Potential issue

Improve error handling and logging for repository retrieval.

The changes introduce more detailed error handling when a student participation cannot be found by its repository URI. However, there are some areas for improvement:

  1. The error message construction could be more efficient.
  2. The exception message contains sensitive information that shouldn't be exposed in production.
  3. The code could benefit from better logging.

Consider the following improvements:

 var opt = studentParticipationRepository.findByRepositoryUri(repositoryURI);
 if (opt.isEmpty()) {
-    var all = studentParticipationRepository.findAll();
-    var li = all.stream().map(ProgrammingExerciseStudentParticipation::getRepositoryUri).toList();
-    String listString = String.join(", ", li);
-    throw new EntityNotFoundException(listString + "\nrepori:: " + repositoryURI);
+    log.error("Could not find student participation for repository URI: {}", repositoryURI);
+    throw new EntityNotFoundException("Student participation not found for the given repository URI");
 }

To ensure this change doesn't break existing functionality, let's verify the usage of this method:

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 22, 2024
@SimonEntholzer SimonEntholzer changed the title Development: Fix broken git submission e2e tests Development: Fix the broken git programming submission e2e tests = Oct 22, 2024
Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

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

I tried cloning the newProgrammingExercise in your test course on TS5. I still had the authentication problem. Could you take a look into it?
Screenshot 2024-10-23 152013
Screenshot 2024-10-23 152153

Copy link

⚠️ Unable to deploy to test servers ⚠️

Testserver "artemis-test5.artemis.cit.tum.de" is already in use by PR #9571.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Oct 23, 2024
@SimonEntholzer
Copy link
Contributor Author

SimonEntholzer commented Oct 23, 2024

I tried cloning the newProgrammingExercise in your test course on TS5. I still had the authentication problem. Could you take a look into it?

This fix does not fix any authentication issue. The problem you noticed is only an issue on Ts5, and happens on all branches. Ts5 not use the integrated code lifecycle but GitlabCI. The problem is with authentication in general, to https://gitlab.artemis.cit.tum.de/users/sign_in

@github-actions github-actions bot removed the deployment-error Added by deployment workflows if an error occured label Oct 23, 2024
@Feras797 Feras797 temporarily deployed to artemis-test3.artemis.cit.tum.de October 23, 2024 21:24 — with GitHub Actions Inactive
Copy link

@Feras797 Feras797 left a comment

Choose a reason for hiding this comment

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

I tested on TS3 and was able to clone an exercise without any issues.

@krusche krusche changed the title Development: Fix the broken git programming submission e2e tests = Development: Fix the broken git programming submission e2e tests Oct 24, 2024
@krusche krusche added this to the 7.6.2 milestone Oct 24, 2024
@krusche krusche merged commit e5def32 into develop Oct 24, 2024
73 of 81 checks passed
@krusche krusche deleted the chore/bugfix/playwright/fix-failing-git-submission-tests branch October 24, 2024 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
programming Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants