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

xtask: generate katana test db #2271

Merged
merged 9 commits into from
Aug 9, 2024
Merged

xtask: generate katana test db #2271

merged 9 commits into from
Aug 9, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Aug 6, 2024

run cargo generate-test-db to generate the test db

TODO: build the project before migrating

/~https://github.com/matklad/cargo-xtask

Summary by CodeRabbit

  • New Features

    • Introduced a new command alias for generating test databases, simplifying the workflow.
    • Expanded the scope of the workspace to manage additional modules for test database generation.
    • Added an asynchronous program for migrating test databases, enhancing testing capabilities.
    • Improved configuration options for the KatanaRunner, allowing for more flexible database directory management.
  • Bug Fixes

    • Enhanced handling of database directories in test configurations to ensure proper initialization.
  • Documentation

    • Updated documentation to reflect new migration functions and configurations.
  • Chores

    • Enhanced CI workflow to ensure test databases are available for testing.
    • Updated .gitignore to exclude temporary test database files.

Copy link

coderabbitai bot commented Aug 6, 2024

Walkthrough

Ohayo, sensei! This update enhances our Rust project workflow by introducing a new alias for generating test databases, adding configuration flexibility for specifying database directories, and establishing a module for managing database migrations. These changes streamline development, improve testing resource management, and optimize the testing environment, making it easier for everyone to work efficiently.

Changes

File Change Summary
.cargo/config.toml Added generate-test-db alias for streamlined test database generation command.
Cargo.toml Included "xtask/generate-test-db" in workspace members.
xtask/generate-test-db/Cargo.toml Defined metadata and dependencies for the new xtask-generate-test-db package.
xtask/generate-test-db/src/main.rs Created an async program for migrating a test database using the Katana runner framework.
bin/sozo/... Updated test files to utilize KatanaRunnerConfig and adjusted migration logic for improved flexibility.
crates/dojo-test-utils/src/... Added utility functions for managing test databases and enhanced migration setups.
crates/dojo-world/src/... Refactored test functions for better modularity and clarity, focusing on migration and world setups.
scripts/rebuild_test_artifacts.sh Improved database generation process, ensuring a clean setup before tests.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3c2eda9 and cdadb53.

Files ignored due to path filters (2)
  • spawn-and-move-db.tar.gz is excluded by !**/*.gz
  • types-test-db.tar.gz is excluded by !**/*.gz
Files selected for processing (3)
  • bin/sozo/src/commands/clean.rs (3 hunks)
  • scripts/rebuild_test_artifacts.sh (1 hunks)
  • xtask/generate-test-db/src/main.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • bin/sozo/src/commands/clean.rs
Files skipped from review as they are similar to previous changes (2)
  • scripts/rebuild_test_artifacts.sh
  • xtask/generate-test-db/src/main.rs

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.
    • @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 as 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.

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

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.

@kariy kariy changed the title test: generate katana test db xtask: generate katana test db Aug 6, 2024
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: 4

xtask/generate-test-db/src/main.rs Outdated Show resolved Hide resolved
xtask/generate-test-db/src/main.rs Outdated Show resolved Hide resolved
crates/katana/runner/src/lib.rs Show resolved Hide resolved
crates/katana/runner/src/lib.rs Show resolved Hide resolved
Copy link

codecov bot commented Aug 6, 2024

Codecov Report

Attention: Patch coverage is 67.84141% with 73 lines in your changes missing coverage. Please review.

Project coverage is 69.78%. Comparing base (f1c5214) to head (cdadb53).
Report is 4 commits behind head on main.

Files Patch % Lines
xtask/generate-test-db/src/main.rs 0.00% 70 Missing ⚠️
bin/sozo/src/commands/clean.rs 50.00% 2 Missing ⚠️
crates/sozo/ops/src/test_utils/setup.rs 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2271      +/-   ##
==========================================
- Coverage   70.29%   69.78%   -0.51%     
==========================================
  Files         342      342              
  Lines       45094    45116      +22     
==========================================
- Hits        31698    31484     -214     
- Misses      13396    13632     +236     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Outside diff range, codebase verification and nitpick comments (1)
.github/workflows/ci.yml (1)

43-44: Ohayo, sensei! Missing test database file detected.

The file spawn-and-move-test-db.tar.gz is not present in the repository, which could cause failures in the CI workflow during the extraction step. Please ensure this file is added to the repository.

  • Missing file: spawn-and-move-test-db.tar.gz
Analysis chain

Verify test database file availability.

Ensure that the files spawn-and-move-test-db.tar.gz and types-test-db.tar.gz are available in the expected location before extraction.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of the test database files in the repository.

# Test: Search for the test database files. Expect: Files should be present.
fd 'spawn-and-move-test-db.tar.gz' -t f
fd 'types-test-db.tar.gz' -t f

Length of output: 91

Comment on lines 92 to 98
/// Compresses the given db-path to a .tar.gz file.
fn compress_db(db_path: &PathBuf, compressed_path: &str) {
Command::new("tar")
.args(["-czf", compressed_path, "-C", ".", &db_path.to_string_lossy().to_string()])
.status()
.expect("Failed to compress test-db directory");
}
Copy link

Choose a reason for hiding this comment

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

Ensure error handling in compression.

The compress_db function uses Command::new("tar") without checking for errors. Consider adding error handling to ensure the compression process is robust.

fn compress_db(db_path: &PathBuf, compressed_path: &str) -> Result<()> {
    let status = Command::new("tar")
        .args(["-czf", compressed_path, "-C", ".", &db_path.to_string_lossy().to_string()])
        .status()
        .expect("Failed to compress test-db directory");

    if !status.success() {
        return Err(Box::new(std::io::Error::new(
            std::io::ErrorKind::Other,
            "Compression failed",
        )));
    }
    Ok(())
}

Comment on lines +71 to +104
/// Copies a directory into a temporary directory.
///
/// # Returns
///
/// A [`Utf8PathBuf`] object pointing to the copied directory.
pub fn copy_tmp_dir(source_dir: &Utf8PathBuf) -> Utf8PathBuf {
let temp_project_dir = Utf8PathBuf::from(
assert_fs::TempDir::new().unwrap().to_path_buf().to_string_lossy().to_string(),
);

fn copy_dir_recursively(src: &PathBuf, dst: &PathBuf) -> io::Result<()> {
if src.is_dir() {
fs::create_dir_all(dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;
let path = entry.path();
let dst_path = dst.join(path.file_name().unwrap());
if path.is_dir() {
copy_dir_recursively(&path, &dst_path)?;
} else {
fs::copy(&path, &dst_path)?;
}
}
} else {
fs::copy(src, dst)?;
}
Ok(())
}

copy_dir_recursively(&source_dir.to_path_buf().into(), &temp_project_dir.to_path_buf().into())
.unwrap_or_else(|e| panic!("Failed to copy directory: {}", e));

temp_project_dir
}
Copy link

Choose a reason for hiding this comment

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

New utility function copy_tmp_dir for directory copying.

The copy_tmp_dir function provides a utility for copying directories to a temporary location. This is useful for setting up test environments. Ensure the error handling is robust, as the function currently panics on failure. Consider using Result for error handling to provide more flexibility in managing errors.

pub fn copy_tmp_dir(source_dir: &Utf8PathBuf) -> Result<Utf8PathBuf, io::Error> {
    let temp_project_dir = Utf8PathBuf::from(
        assert_fs::TempDir::new().unwrap().to_path_buf().to_string_lossy().to_string(),
    );

    fn copy_dir_recursively(src: &PathBuf, dst: &PathBuf) -> io::Result<()> {
        if src.is_dir() {
            fs::create_dir_all(dst)?;
            for entry in fs::read_dir(src)? {
                let entry = entry?;
                let path = entry.path();
                let dst_path = dst.join(path.file_name().unwrap());
                if path.is_dir() {
                    copy_dir_recursively(&path, &dst_path)?;
                } else {
                    fs::copy(&path, &dst_path)?;
                }
            }
        } else {
            fs::copy(src, dst)?;
        }
        Ok(())
    }

    copy_dir_recursively(&source_dir.to_path_buf().into(), &temp_project_dir.to_path_buf().into())?;

    Ok(temp_project_dir)
}

Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

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

Thanks @kariy for this. 🙏

@glihm glihm merged commit c6a41ac into main Aug 9, 2024
13 of 15 checks passed
@glihm glihm deleted the test/db branch August 9, 2024 18:36
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