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

(fix) handle case if examples are included above the working directory #67

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tphoney
Copy link

@tphoney tphoney commented May 15, 2023

Found an example when examples were included outside of the working dir pathing broke, and rspec-tracer would fail. Note below how file name is relative, for some examples, but absolute for the other example.

 {:example_group=>"RSpec::ExampleGroups::DependabotGoModulesUpdateChecker::LatestResolvableVersion",
     :description=>"doesn't update Git SHAs not on master to newer commits to master",
     :full_description=>"Dependabot::GoModules::UpdateChecker#latest_resolvable_version doesn't update Git SHAs not on master to newer commits to master",
     :shared_group=>[],
     :file_name=>"/spec/dependabot/go_modules/update_checker_spec.rb",
     :line_number=>79,
     :rerun_file_name=>"/spec/dependabot/go_modules/update_checker_spec.rb",
     :rerun_line_number=>79,
     :example_id=>"093821c51eb8c901f38019b8db52fa6f",
     :run_reason=>"Pending previously",
     :execution_result=>{:started_at=>2023-05-15 14:40:34.499527201 UTC, :finished_at=>2023-05-15 14:40:34.499547501 UTC, :run_time=>2.03e-05, :status=>"pending"}},
   "a27831f36d29bcf387b66b4a86c5199e"=>
    {:example_group=>"RSpec::ExampleGroups::DependabotGoModules::BehavesLikeItRegistersTheRequiredClasses",
     :description=>"registers a file fetcher",
     :full_description=>"Dependabot::GoModules behaves like it registers the required classes registers a file fetcher",
     :shared_group=>["./spec/dependabot/go_modules_spec.rb:8"],
     :file_name=>"/home/tp/workspace/ruby_rspec_demos/dependabot-core/common/spec/dependabot/shared_examples_for_autoloading.rb",
     :line_number=>15,
     :rerun_file_name=>"/spec/dependabot/go_modules_spec.rb",
     :rerun_line_number=>8,
     :example_id=>"a27831f36d29bcf387b66b4a86c5199e",
     :run_reason=>"No cache",
     :execution_result=>{:started_at=>2023-05-15 14:40:34.5325042 UTC, :finished_at=>2023-05-15 14:40:34.5330069 UTC, :run_time=>0.0005027, :status=>"passed"}},
   "b8b4659322ee849a324f99e11550fb3c"=>

Any guidance or a tip on how to test would be great

Summary by CodeRabbit

  • Refactor
    • Improved handling of absolute file paths in source file processing.

@avmnu-sng avmnu-sng closed this Mar 10, 2024
@avmnu-sng avmnu-sng reopened this Mar 10, 2024
@avmnu-sng
Copy link
Owner

@coderabbitai review

Copy link

coderabbitai bot commented Mar 10, 2024

Walkthrough

The recent update introduces a nuanced adjustment specifically targeting the handling of absolute file paths within the source_file.rb method named file_path. This modification ensures that absolute paths are recognized and treated distinctly by directly returning the file name, streamlining the process and potentially enhancing the method's efficiency and accuracy in file manipulation scenarios.

Changes

File Change Summary
lib/.../source_file.rb Added a conditional check in the file_path method to directly return the file name for absolute paths.

🐇✨
In the realm of code where paths intertwine,
A rabbit hopped in, making changes so fine.
"No more confusion," it said with a cheer,
"For absolute paths, clarity is here!"
With every hop, it left behind,
A trail of code, more refined.
🌟📁🐾

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-tests 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 568c5e7 and 984b721.
Files selected for processing (1)
  • lib/rspec_tracer/source_file.rb (1 hunks)
Additional comments: 1
lib/rspec_tracer/source_file.rb (1)
  • 28-30: The comment on line 28 suggests that the method returns if the path is absolute, but the actual condition on line 29 checks if the file exists, regardless of whether it's an absolute path. This could lead to confusion. Consider clarifying the comment to reflect the actual check performed, which is whether the file exists at the given path.

Additionally, ensure that this logic correctly addresses the issue of handling examples located outside the working directory, as intended in the PR objectives.

Comment on lines 25 to 33
end

def file_path(file_name)
# return if an absolute path, eg included examples above working directory
return file_name if File.file?(file_name)
# otherwise append root, to get an absolute path.
File.expand_path(file_name.sub(%r{^/}, ''), RSpecTracer.root)
end
end
Copy link

@coderabbitai coderabbitai bot Mar 10, 2024

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [15-15]

The use of MD5 for generating file digests is noted. While MD5 is sufficient for non-security-related purposes, it's generally recommended to use more secure hashing functions like SHA256, especially to future-proof the code against potential vulnerabilities. Consider replacing MD5 with SHA256 for hashing file contents, which can be done with minimal changes:

- digest: Digest::MD5.hexdigest(File.read(file_path))
+ digest: Digest::SHA256.hexdigest(File.read(file_path))

Copy link
Owner

Choose a reason for hiding this comment

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

@coderabbitai let's stick to changes in the PR.

Copy link

Choose a reason for hiding this comment

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

@avmnu-sng, understood. I'll focus on the changes made in this PR. If there's anything specific within the PR's scope you'd like me to review or provide feedback on, please let me know.

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.

None yet

2 participants