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: propagate build error and check if js files exist #297

Merged
merged 7 commits into from
Jan 19, 2025

Conversation

LeNei
Copy link
Contributor

@LeNei LeNei commented Jan 12, 2025

Context & Description

This PR aims to fix the command tuono build not propagating errors. It also adds checks for commands executing scripts if said script exists.

Closes: #278

@LeNei LeNei requested a review from Valerioageno as a code owner January 12, 2025 13:48
@Valerioageno Valerioageno added the enhancement New feature or request label Jan 12, 2025
@marcalexiei marcalexiei added the rust Requires rust knowledge label Jan 12, 2025
Copy link
Member

@Valerioageno Valerioageno left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Changes look perfect!

I'd like to ask you also to introduce two test cases for checking that the scripts exist (checking the vite failure is too complex right now; same for the tuono dev command).

To do it, I'd like to ask you to:

  1. rename crates/tuono/tests/cli_tests.rs in crates/tuono/tests/cli_build.rs
  2. Add a test case for testing that the BUILD_JS_SCRIPT does not exist
  3. Add a test case for testing that the BUILD_TUONO_CONFIG does not exist

Let me know if I can support you in any way!

@Valerioageno
Copy link
Member

Hey @LeNei, I noticed that you added an empty commit. Is that what you meant?

@LeNei
Copy link
Contributor Author

LeNei commented Jan 18, 2025

@Valerioageno the empty commit was a mistake when i updated my fork. I've added a test for running the cli without installed scripts but the separate cases are a bit tricky to tackle since the BUILD_TUONO_CONFIG script would have to run successfully before BUILD_JS_SCRIPT would run. Testing the functions would fail since currently std::process:exit is used to terminate the process. This leads to the test terminating if the function using it is called directly. Maybe it could be a good idea to create a common error Struct to handle errors or use a crate like anyhow for error handling?

@Valerioageno
Copy link
Member

Definitely a great idea adding a better error handling!
How about adding a function in the TempTuonoProject struct - maybe something similar to add_route (tests/utils.rs) - to enable the test to programmatically add a mock file in node_modules/.bin/.. and then check if they exist?

@LeNei
Copy link
Contributor Author

LeNei commented Jan 18, 2025

I've added a test using add_route since it is sufficient for creating the mock file. Feel free to have a lock. I've used a comparison on the output to check if the cli check on the file existing was successful since it directly checks if the cli is still working as expected.

@Valerioageno
Copy link
Member

  1. I'd rename then the method add_route into add_file since it doesn't make sense in this case the method meaning.
  2. I'd check that without the files you get the expected error.

i.e.

fn it_fails_without_installed_build_scritp() {
    TempTuonoProject::new();

    let mut test_tuono_build = Command::cargo_bin("tuono").unwrap();
    test_tuono_build
        .arg("build")
        .assert()
        .failure()
        .stderr("Failed to find the build script. Please run `npm install`\n");
}

fn it_fails_without_installed_build_config_script() {
    TempTuonoProject::new();

    let mut test_tuono_build = Command::cargo_bin("tuono").unwrap();
    temp_tuono_project.add_route("./node_modules/.bin/tuono-build-prod");
    test_tuono_build
        .arg("build")
        .assert()
        .failure()
        .stderr("Failed to find the build script. Please run `npm install`\n");
}
  1. I think there is no need of predicates in this case

@LeNei
Copy link
Contributor Author

LeNei commented Jan 18, 2025

I've updated the tests. It was required to make the mock file executable for the first script check to pass but now it should be good.

@Valerioageno
Copy link
Member

The PR looks good to me!
Please fix the pipelines so we can merge!

Thanks for your improvement

@Valerioageno Valerioageno self-requested a review January 19, 2025 08:34
@Valerioageno Valerioageno merged commit 5efcc86 into tuono-labs:main Jan 19, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rust Requires rust knowledge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: tuono build can succeed on build failure
3 participants