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

Update exec_cfg_check to use config source path relative to the hub root #142

Merged
merged 13 commits into from
Oct 31, 2024

Conversation

zkamvar
Copy link
Member

@zkamvar zkamvar commented Oct 29, 2024

There was a problem with exec_cfg_check where it was assuming that the working directory was the same directory as the hub directory. This PR fixes that issue by pulling hub_path from the caller's environment and using that to create a valid path.

With this fix, however I had to also rewrite the tests because a lot of them were written in a way that worked very well to test that the execution order would be respected when the custom checks were called, but they did not test that the checks actually lived inside of the hub, which did pose a bit of a security concern because you effectively would end up with a situation where you could set an arbitrary URL as the source for the script:

source: https://example.com/check.R

I added an extra test helper to do the following:

  1. create a copy of a test hub
  2. copy a check script to src/validations/R in the copy of the hub
  3. create the validations.yml file with the correct parameters

This will fix #141

Copy link

github-actions bot commented Oct 29, 2024

@zkamvar zkamvar marked this pull request as ready for review October 29, 2024 22:16
@zkamvar zkamvar requested a review from annakrystalli October 30, 2024 18:01
Copy link
Member

@annakrystalli annakrystalli 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 catching and fixing this!

In all honesty I'm finding it harder to follow what's going on in the tests though. I prefer having tangible config files that can be inspected easily online without having to pick through and figure out what the stand up code is doing.

For me it would have been quicker and easier to follow if the deleted test yaml files were being used to configure each test instead of programmatically generating validations.yml files and the stand up function just took an argument that specified which .yml file to copy into the test hub. Then, once all contents of testthat::test_path("testdata/src/R/") were copied into the test hubs src/validations/R/) directory, the validations.yml file could be used to configure which file to source (as we do in real hubs).

I think at least some comments to explain what going is needed in the stand up function.

})
})

expect_snapshot(print(res))
Copy link
Member

Choose a reason for hiding this comment

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

It's not that informative to take a snapshot of a generically named object as in the snapshot, it's not clear what the snapshot refers to. I'd prefer if the snapshot were of either:

  • more complete code generating the snapshot
  • a more descriptive name for the contents of the object being snapshotted

tests/testthat/_snaps/execute_custom_checks.md Outdated Show resolved Hide resolved
@zkamvar
Copy link
Member Author

zkamvar commented Oct 31, 2024

For me it would have been quicker and easier to follow if the deleted test yaml files were being used to configure each test instead of programmatically generating validations.yml files and the stand up function just took an argument that specified which .yml file to copy into the test hub. Then, once all contents of testthat::test_path("testdata/src/R/") were copied into the test hubs src/validations/R/) directory, the validations.yml file could be used to configure which file to source (as we do in real hubs).

Understood. I was having a bear of a time with this. In short, I got confused and hurt myself in my confusion. I'll rejig.

Using the dynamic test path meant that we could not test these files as
they existed in a hub. With this pattern, we can copy the test files
over instead of having to do the cumbersome programmatic generation.

Less code == better code
@annakrystalli
Copy link
Member

No worries! BTW, could you add a note in NEWS.md too about the bug fix?

@zkamvar
Copy link
Member Author

zkamvar commented Oct 31, 2024

No worries! BTW, could you add a note in NEWS.md too about the bug fix?

Done! It's ready for another pass, @annakrystalli 😃

@zkamvar zkamvar requested a review from annakrystalli October 31, 2024 15:27
Copy link
Member

@annakrystalli annakrystalli left a comment

Choose a reason for hiding this comment

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

Yeyy! Looks awesome and feels much easier to parse. Also ⚡️⚡️⚡️!

@zkamvar zkamvar merged commit bf7e6e8 into main Oct 31, 2024
8 checks passed
@zkamvar zkamvar deleted the znk/custom-check-path/141 branch October 31, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Custom checks fail if working directory is not hub root
2 participants