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

feat/test-codeql. test codeql #146

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

feat/test-codeql. test codeql #146

wants to merge 7 commits into from

Conversation

SeUkKim
Copy link
Collaborator

@SeUkKim SeUkKim commented Oct 18, 2024

Description

testing codeql failed.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced a new target to ensure the necessary libraries are available before running tests.
    • Enhanced the .gitignore file to improve management of build artifacts and shared libraries.
  • Bug Fixes

    • Improved the testing workflow by integrating library checks into the testing process.

@SeUkKim SeUkKim requested a review from a team as a code owner October 18, 2024 06:31
Copy link

coderabbitai bot commented Oct 18, 2024

Walkthrough

The pull request modifies the Makefile to enhance the testing process by introducing a new target called check-libs, which checks for the existence of shared library files api/libmovevm.so and api/libcompiler.so. If these files are missing, symbolic links to their corresponding destination files are created. The test target is updated to depend on check-libs, ensuring that library checks are performed before executing tests. Additionally, the .gitignore file is updated to include entries for these shared libraries and other build artifacts. The main.rs file is also updated to improve type tracing using the serde_reflection library.

Changes

File Change Summary
Makefile Added target check-libs to check for api/libmovevm.so and api/libcompiler.so; modified test to depend on check-libs; updated clean to remove symbolic links.
.gitignore Added entries for api/libmovevm.so and api/libcompiler.so; reinforced exclusions for **/target and **/Cargo.lock; modified **/build to track !types/compiler/build.
tools/generate-bcs-go/src/main.rs Updated import for serde_reflection to include Samples; replaced trace_simple_type with trace_type for improved type tracing.

Possibly related PRs

  • Fix/ci #127: The modifications to the Makefile in the main PR are related to the changes in the Makefile within PR Fix/ci #127, specifically regarding the handling of shared library files, which is crucial for the Go testing workflow.

🐇 In the garden where I hop and play,
A new target's here to save the day!
check-libs checks with glee,
Ensuring our tests run smoothly, you see.
With every build, we leap and bound,
In the world of code, joy is found! 🌼


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 anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

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)
Makefile (2)

49-52: LGTM! Consider enhancing error handling.

The new check-libmovevm target is a good addition to ensure the presence of the required shared library file. This can prevent potential runtime errors due to missing libraries.

Consider adding error handling in case api/libmovevm.x86_64.so doesn't exist. For example:

check-libmovevm:
	@if [ ! -f api/libmovevm.so ]; then \
		if [ -f api/libmovevm.x86_64.so ]; then \
			cp api/libmovevm.x86_64.so api/libmovevm.so; \
		else \
			echo "Error: api/libmovevm.x86_64.so not found"; \
			exit 1; \
		fi; \
	fi

This will provide a clear error message if the source file is missing, making debugging easier.


Line range hint 1-55: Overall, these changes enhance the build and test process.

The additions to the Makefile improve the reliability of the build and test process by ensuring that necessary library files are present before running tests. This is a good practice that can prevent potential issues during testing and deployment.

Consider applying similar checks for other critical files in the project to further improve robustness. Also, ensure that the error handling suggestion for the check-libmovevm target is implemented to make debugging easier in case of missing files.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between eee9b52 and 829bda3.

📒 Files selected for processing (1)
  • Makefile (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
Makefile (1)

54-55: LGTM! Good improvement to test reliability.

The modification to the test-go target, making it depend on check-libmovevm, is a good improvement. This ensures that the required library file is present before running Go tests, which can prevent potential test failures due to missing dependencies.

@Vritra4
Copy link
Contributor

Vritra4 commented Oct 18, 2024

@beer-1 similar problem with test workflow is the cause

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)
Makefile (2)

49-51: Consider updating the TODO comment with more context.

The comment indicates this is a workaround for CodeQL, but it would be helpful to:

  1. Add more context about why this symlink is necessary
  2. Document any potential risks or limitations of this approach
  3. Add a link to any internal tracking issue

47-58: Consider investigating root cause of CodeQL symlink requirement.

While the current implementation works as a workaround, consider:

  1. Investigating why CodeQL requires these specific library names
  2. Exploring if the build process can be updated to generate libraries with the expected names directly
  3. Documenting the findings to help future maintenance

This could help eliminate the need for symlinks and provide a more robust long-term solution.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f010718 and 6c6cfd5.

📒 Files selected for processing (2)
  • .gitignore (1 hunks)
  • Makefile (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
🔇 Additional comments (3)
Makefile (3)

47-47: LGTM: Good dependency ordering in test target.

The addition of check-libs as a prerequisite ensures that necessary library symlinks exist before running tests, preventing potential test failures.


140-142: LGTM: Proper cleanup in clean target.

The addition of symlink removal commands ensures proper cleanup, and the use of '@-rm' correctly handles cases where files don't exist.


51-58: 🛠️ Refactor suggestion

Verify target files exist before creating symlinks.

The current implementation creates symlinks without verifying if the target files exist. This could lead to broken symlinks if the build process fails or files are missing.

Consider adding error handling:

 check-libs:
-	@if [ ! -f api/$(SHARED_LIB_SRC) ]; then \
+	@if [ ! -f api/$(SHARED_LIB_DST) ]; then \
+		echo "Error: Target file api/$(SHARED_LIB_DST) does not exist" >&2; \
+		exit 1; \
+	fi
+	@if [ ! -f api/$(SHARED_LIB_SRC) ]; then \
 		ln -s api/$(SHARED_LIB_DST) api/$(SHARED_LIB_SRC); \
 	fi

-	@if [ ! -f api/$(COMPILER_SHARED_LIB_SRC) ]; then \
+	@if [ ! -f api/$(COMPILER_SHARED_LIB_DST) ]; then \
+		echo "Error: Target file api/$(COMPILER_SHARED_LIB_DST) does not exist" >&2; \
+		exit 1; \
+	fi
+	@if [ ! -f api/$(COMPILER_SHARED_LIB_SRC) ]; then \
 		ln -s api/$(COMPILER_SHARED_LIB_DST) api/$(COMPILER_SHARED_LIB_SRC); \
 	fi

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: 1

🧹 Outside diff range and nitpick comments (2)
tools/generate-bcs-go/src/main.rs (2)

32-35: Consider adding error handling for tracer initialization.

While the setup is clear and well-documented, consider adding error handling for the tracer initialization to make the code more robust.

-    let mut tracer = Tracer::new(TracerConfig::default());
+    let mut tracer = Tracer::new(TracerConfig::default())
+        .map_err(|e| format!("Failed to initialize tracer: {}", e))
+        .expect("Tracer initialization failed");

36-55: Consider organizing type tracing calls into logical groups.

While the implementation is correct, consider grouping related types together with comments to improve readability. For example:

     // 2. Trace the main entry point(s) + every enum separately.
+    // Core types
     tracer.trace_type::<Identifier>(&samples).unwrap();
     tracer.trace_type::<TypeTag>(&samples).unwrap();
     tracer.trace_type::<ModuleId>(&samples).unwrap();
     tracer.trace_type::<ResourceKey>(&samples).unwrap();
+
+    // Transaction and execution types
     tracer.trace_type::<StakingDelta>(&samples).unwrap();
     tracer.trace_type::<CosmosMessage>(&samples).unwrap();
     // ... rest of the types
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between af7443c and cd34b81.

📒 Files selected for processing (1)
  • tools/generate-bcs-go/src/main.rs (2 hunks)
🔇 Additional comments (2)
tools/generate-bcs-go/src/main.rs (2)

4-4: LGTM: Import change aligns with new tracing implementation.

The addition of Samples to the imports is necessary for the updated type tracing mechanism.


36-66: Verify type coverage completeness.

Let's verify that all necessary types are being traced by checking for any imported but untraced types.

✅ Verification successful

Let me verify if these untraced types actually need tracing by checking their usage context.


All necessary types are being traced correctly

The untraced types found in the imports are utility types used for code generation and tracing infrastructure, not data types that need BCS serialization:

  • current_dir, File: Standard Rust I/O utilities
  • CodeGenerator, CodeGeneratorConfig, Encoding: Code generation configuration
  • Samples, Tracer, TracerConfig: Reflection infrastructure

The code correctly traces all the actual Move types that require BCS serialization.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any imported types that aren't being traced

# Get all imported types
echo "Checking for imported but untraced types..."
rg -o "use .+::\{.*\}" tools/generate-bcs-go/src/main.rs | \
  sed 's/use //g; s/{//g; s/}//g; s/,/\n/g' | \
  sed 's/^[ \t]*//' | \
  grep -v "^$" > /tmp/imported_types

# Get all traced types
rg "trace_type::<(\w+)>" tools/generate-bcs-go/src/main.rs | \
  sed 's/.*trace_type::<\([^>]*\)>.*/\1/' > /tmp/traced_types

# Compare
echo "Types in imports but not traced:"
grep -v -f /tmp/traced_types /tmp/imported_types || true

Length of output: 607


Script:

#!/bin/bash
# Check how these types are used in the code
echo "Checking usage context of potentially untraced types..."
rg -A 2 -B 2 "std::env::current_dir|fs::File|CodeGenerator|CodeGeneratorConfig|Encoding|Samples|Tracer|TracerConfig" tools/generate-bcs-go/src/main.rs

Length of output: 1162

Comment on lines 37 to 66
tracer.trace_type::<Identifier>(&samples).unwrap();
tracer.trace_type::<TypeTag>(&samples).unwrap();
tracer.trace_type::<ModuleId>(&samples).unwrap();
tracer.trace_type::<ResourceKey>(&samples).unwrap();
tracer.trace_type::<StakingDelta>(&samples).unwrap();
tracer.trace_type::<CosmosMessage>(&samples).unwrap();
tracer.trace_type::<Account>(&samples).unwrap();
tracer.trace_type::<GasUsage>(&samples).unwrap();
tracer.trace_type::<ExecutionResult>(&samples).unwrap();
tracer.trace_type::<EntryFunction>(&samples).unwrap();
tracer.trace_type::<ViewFunction>(&samples).unwrap();
tracer.trace_type::<ViewOutput>(&samples).unwrap();
tracer.trace_type::<ModuleBundle>(&samples).unwrap();
tracer.trace_type::<Script>(&samples).unwrap();
tracer.trace_type::<Env>(&samples).unwrap();
tracer.trace_type::<TableInfo>(&samples).unwrap();
tracer.trace_type::<InitiaVMConfig>(&samples).unwrap();
tracer.trace_type::<CompilerArguments>(&samples).unwrap();
tracer.trace_type::<CompilerBuildConfig>(&samples).unwrap();
tracer
.trace_simple_type::<CompilerCoverageBytecodeOptions>()
.trace_type::<CompilerCoverageBytecodeOptions>(&samples)
.unwrap();
tracer
.trace_simple_type::<CompilerCoverageSourceOptions>()
.trace_type::<CompilerCoverageSourceOptions>(&samples)
.unwrap();
tracer
.trace_simple_type::<CompilerCoverageSummaryOptions>()
.trace_type::<CompilerCoverageSummaryOptions>(&samples)
.unwrap();
tracer.trace_simple_type::<CompilerDocgenOptions>().unwrap();
tracer.trace_simple_type::<CompilerTestOptions>().unwrap();
tracer.trace_type::<CompilerDocgenOptions>(&samples).unwrap();
tracer.trace_type::<CompilerTestOptions>(&samples).unwrap();
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling in type tracing.

The current implementation uses unwrap() for error handling. Consider using a more robust error handling approach:

-    tracer.trace_type::<Identifier>(&samples).unwrap();
+    tracer.trace_type::<Identifier>(&samples)
+        .map_err(|e| format!("Failed to trace Identifier: {}", e))?;

Also, consider adding a helper function to reduce repetition:

fn trace_type_with_error<T: serde::Serialize + for<'de> serde::Deserialize<'de>>(
    tracer: &mut Tracer,
    samples: &Samples,
    type_name: &str,
) -> Result<(), String> {
    tracer
        .trace_type::<T>(samples)
        .map_err(|e| format!("Failed to trace {}: {}", type_name, e))
}

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)
tools/generate-bcs-go/src/main.rs (2)

30-31: Add documentation for the samples initialization.

While the comment explains that samples are for types with custom deserializers, it would be helpful to add more context about how these samples are used in the type tracing process.

 // 1. Record samples for types with custom deserializers.
+// Samples provide type information to the tracer for proper serialization format detection.
+// This is especially important for types that implement custom serialization.
 let samples = Samples::new();

34-64: Consider grouping related types for better organization.

The type tracing calls could be organized into logical groups with comments explaining each group's purpose. For example:

 // 2. Trace the main entry point(s) + every enum separately.
+// Core types
 tracer.trace_type::<TypeTag>(&samples).unwrap();
 tracer.trace_type::<ModuleId>(&samples).unwrap();
 tracer.trace_type::<ResourceKey>(&samples).unwrap();
+
+// Transaction and execution types
 tracer.trace_type::<StakingDelta>(&samples).unwrap();
 tracer.trace_type::<CosmosMessage>(&samples).unwrap();
 tracer.trace_type::<Account>(&samples).unwrap();
 // ... continue grouping other types ...
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cd34b81 and 5f92c6e.

📒 Files selected for processing (1)
  • tools/generate-bcs-go/src/main.rs (2 hunks)
🔇 Additional comments (2)
tools/generate-bcs-go/src/main.rs (2)

4-4: LGTM: Import change aligns with new implementation.

The addition of Samples to the imports is necessary for the updated type tracing implementation.


34-64: Previous error handling comment is still applicable.

The previous review comment about improving error handling and reducing repetition through a helper function remains valid.

@beer-1 beer-1 marked this pull request as draft November 18, 2024 04:18
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.

3 participants