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

Updated setup.ts to support docker compose v2 and pass npm run typecheck #2770

Merged

Conversation

Aad1tya27
Copy link

@Aad1tya27 Aad1tya27 commented Dec 18, 2024

What kind of change does this PR introduce?

Changes in setup.ts, src/typedefs/unions.ts
Now the setup.ts is compatible with both docker compose v1 and v2, and the error handling of the
The empty gql which was creating EOF error during npm run typecheck has been removed. Moreover, the module unions.ts exported wasn't being used anywhere in the codebase.
This PR also fixes a unit test which expected wrong volunteered hours(details in the comment below).

Issue Number:

Fixes #2767, #2769

Did you add tests for your changes?
No

Snapshots/Videos:
image
image
image

If relevant, did you update the documentation?
Updation in the documentation is not required.

Summary
Now the docker containers start without facing any error related to outdated Docker Compose version. Also the error faced in the test npm run typecheck is now fixed by removing the empty gql block.

Does this PR introduce a breaking change?
No, the bug only effected npm run setup and npm run typecheck commands.

Have you read the contributing guide?
Yes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a command retrieval function for enhanced Docker Compose management.
  • Bug Fixes

    • Improved error handling for Docker daemon checks, providing clearer user feedback.
    • Enhanced timeout management for Docker Compose operations.
    • Updated test cases for volunteer ranks to reflect accurate expected values.
  • Chores

    • Commented out unused code related to GraphQL imports and exports.

Copy link

coderabbitai bot commented Dec 18, 2024

Walkthrough

The pull request introduces enhancements to the setup.ts file, focusing on Docker management and error handling. A new function, getDockerComposeCommand, is implemented to determine the appropriate command for Docker Compose based on version checks. The runDockerComposeWithLogs function is updated to utilize this new command, and error handling for Docker daemon checks is improved. Additionally, two lines in src/typeDefs/unions.ts are commented out, removing related functionality. Test cases for getVolunteerRanks are adjusted in tests/resolvers/Query/getVolunteerRanks.spec.ts.

Changes

File Change Summary
setup.ts - Added getDockerComposeCommand() function for Docker Compose version detection
- Updated runDockerComposeWithLogs() to use the new command
- Enhanced error handling for Docker daemon checks
- Improved timeout mechanism for Docker Compose operations
src/typeDefs/unions.ts - Commented out gql import
- Commented out unions export
tests/resolvers/Query/getVolunteerRanks.spec.ts - Updated expected value of hoursVolunteered in test case
- Removed console.log statement from test case

Assessment against linked issues

Objective Addressed Explanation
Fix Docker Compose command compatibility [#2767]
Handle different Docker Compose versions [#2767]

Possibly related issues

Possibly related PRs

Suggested reviewers

  • DMills27
  • SiddheshKukade

Poem

🐳 Docker's dance, a version's grace,
Compose commands find their place,
With rabbit's wit, we solve the test,
Making setup run with zest!
Containers rise, no errors near,
Code hops along without a fear! 🐰

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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.

Copy link

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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

🧹 Nitpick comments (5)
setup.ts (5)

8-8: Consider partial imports to reduce overhead.

Importing multiple methods (exec, spawn, execSync) from child_process is fine, but if only a subset is needed for this file, consider a narrower import to optimize usage.


469-485: Double-check error logging for sensitive data.

The catch block simply logs the entire error object using console.log(error). Depending on the environment, this may inadvertently reveal sensitive system or environment details. Consider using a more guarded logging approach.

     } catch (error) {
-      console.log(error);
+      console.error("Error retrieving Docker Compose version:", error instanceof Error ? error.message : String(error));

501-505: Check platform compatibility for Docker daemon error messaging.

While the error message references Docker Desktop, some platforms (e.g., Linux) may not have Docker Desktop but still run Docker daemon. Consider adjusting the messaging to provide platform-appropriate instructions.


520-529: Avoid abrupt termination without cleanup.

Killing the Docker Compose process after the timeout helps prevent hanging. However, consider adding a more graceful cleanup or logs to inform the user about any incomplete jobs (e.g., partially built images).


532-534: Validate concurrency guard for multiple events.

The isCompleted guard is used to prevent double-calling resolve or reject. This approach is correct, but be aware of potential race conditions if other event listeners also set isCompleted. Adding a small comment about why this guard exists could enhance maintainability.

Also applies to: 540-541

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2440e4f and 154e3c8.

📒 Files selected for processing (2)
  • setup.ts (3 hunks)
  • src/typeDefs/unions.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/typeDefs/unions.ts

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 18, 2024
@Aad1tya27
Copy link
Author

@palisadoes
image
I am getting this error in the npm run test job. I think this is a common error which everyone is facing.

Also, the main change which I have done is in setup.ts file to fix the bug. And as it is a sensitive file I have failed another test. How do I proceed further?

@Aad1tya27
Copy link
Author

@palisadoes I got why npm run test was getting the above error.
image
Here the expected volunteer hours are wrong. They should be equal to 6.

image
In the testVolunteer1 (using testUser1 id), the total hours upto a month ago are clearly 2(yesterday) + 4(two weeks ago) = 6

The other 3 unit tests under "resolvers -> Query -> getVolunteerRanks" are correct, only this one had wrong hours written.

I'm changing the getVolunteerRanks.spec.ts file in order to change the hours to 6 and for my PR to pass the TESTING APPLICATION(22.x) job.

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

🧹 Nitpick comments (1)
tests/resolvers/Query/getVolunteerRanks.spec.ts (1)

80-80: Remove debug console.log statement

Debug logging statements should not be committed to test files as they add noise to test output.

-    console.log(volunteerRanks);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 154e3c8 and 08bc758.

📒 Files selected for processing (1)
  • tests/resolvers/Query/getVolunteerRanks.spec.ts (1 hunks)
🔇 Additional comments (1)
tests/resolvers/Query/getVolunteerRanks.spec.ts (1)

81-81: Verify the volunteer hours calculation for monthly timeframe

The change from 2 to 6 hours appears correct based on PR comments, but let's verify the calculation logic.

✅ Verification successful

Based on the search results, I can now verify the volunteer hours calculation for the monthly timeframe. The code shows:

  1. In tests/helpers/volunteers.ts, test data is created with hoursHistory entries at different dates
  2. In src/resolvers/Query/getVolunteerRanks.ts, the calculation logic filters hoursHistory based on timeframe
  3. The test getVolunteerRanks for monthly in tests/resolvers/Query/getVolunteerRanks.spec.ts expects 6 hours, which matches the sum of hours within a month's timeframe from the test data

The 6 hours value is correct for monthly timeframe

The value matches the sum of hours from hoursHistory entries within the monthly period (2 hours from yesterday + 4 hours from two weeks ago = 6 hours total).

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the volunteer hours calculation logic
echo "Searching for volunteer hours calculation..."
rg -A 10 "hoursVolunteered|createVolunteerAndActions" --type ts

# Check the helper function implementation
echo "Checking volunteer creation helper..."
ast-grep --pattern 'export const createVolunteerAndActions = async () => {
  $$$
}'

Length of output: 42302

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 19, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 19, 2024
Copy link

coderabbitai bot commented Dec 20, 2024

Tip

For best results, initiate chat on the files or code changes.

@palisadoes: How can I help you today? Let me know if you have any further instructions or questions about this PR.

@palisadoes
Copy link
Contributor

@coderabbitai full review

Copy link

coderabbitai bot commented Dec 20, 2024

✅ Actions performed

Full review triggered.

@palisadoes
Copy link
Contributor

Please fix:

  1. Any failing tests
  2. Any conflicting files

Make sure CodeRabbit.ai approves your changes

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

🧹 Nitpick comments (3)
setup.ts (3)

8-8: Consider product-level alternatives for Docker/child process management.
While importing "exec", "spawn", and "execSync" from "child_process" may be sufficient for now, consider using higher-level automation tools (e.g., node’s built-in child_process with detailed logging) or libraries (like execa) for better error handling.


469-485: Ensure compatibility checks for Docker Compose are robust.
This function gracefully handles the Docker Compose v1 vs. v2 distinction by trying v2 first and falling back to v1. However, some edge cases might appear if Docker is installed without “docker compose” support or if “docker-compose” is absent. Consider verifying if the user has Docker installed at all and giving a more descriptive message before attempting the version check.


501-505: Validate concurrency handling in process timeout logic.
In "runDockerComposeWithLogs", you handle a 5-minute timeout and kill the Docker Compose process if it’s still running. This is good for preventing hangs, but be mindful of concurrency scenarios where multiple scripts or different processes might also attempt to access Docker. Consider building in a retry mechanism or separate checks for conditions that might trigger transient Docker issues.

Also applies to: 511-515, 520-529, 532-533, 540-541

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2440e4f and 3e9aeb7.

📒 Files selected for processing (3)
  • setup.ts (3 hunks)
  • src/typeDefs/unions.ts (1 hunks)
  • tests/resolvers/Query/getVolunteerRanks.spec.ts (1 hunks)
🔇 Additional comments (2)
src/typeDefs/unions.ts (1)

1-4: Removing unused imports and exports is a good practice.
Commenting out the unused gql import and the unions export helps avoid confusion, reduces dead code, and speeds up build processes.

tests/resolvers/Query/getVolunteerRanks.spec.ts (1)

80-80: Confirm updated volunteer hours with data source.
The test expectation changes from 2 to 6 hours. This likely reflects a corrected fixture or updated data. Be sure the underlying logic or seed data is consistent with this revised expectation to avoid confusion in future merges.

@palisadoes palisadoes merged commit 0ca595e into PalisadoesFoundation:develop Dec 20, 2024
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants