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

chore: add bad reference error [gh-800] #829

Closed
wants to merge 5 commits into from

Conversation

nahuelon
Copy link
Contributor

I hereby confirm that I followed the code guidelines found at engineering guidelines

Affected Components

  • CLI
  • Create CLI
  • Test
  • Docs
  • Examples
  • Other

Notes for the Reviewer

This PRs catches dependency file paths that are above the project CWD and show a user-friendly error.
The check is done for API and Browser checks, because both checks could have not permitted paths for their dependencies.

image

Resolves #[issue-number]

New Dependency Submission

@umutuzgur
Copy link
Member

Please fix the test so I can review it

@@ -356,8 +356,12 @@ export class ApiCheck extends Check {

const deps: ScriptDependency[] = []
for (const { filePath, content } of parsed.dependencies) {
const relativePath = pathToPosix(path.relative(Session.basePath!, filePath))
if (relativePath.startsWith('..')) {
throw new Error(`You cannot reference a dependency file above the Checkly config location folder. Please, modify "${relativePath}" path.`)
Copy link
Contributor

Choose a reason for hiding this comment

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

The same error message is used in browser-check.ts. I think that we should move it to a helper file.

@@ -356,8 +356,12 @@ export class ApiCheck extends Check {

const deps: ScriptDependency[] = []
for (const { filePath, content } of parsed.dependencies) {
const relativePath = pathToPosix(path.relative(Session.basePath!, filePath))
if (relativePath.startsWith('..')) {
throw new Error(`You cannot reference a dependency file above the Checkly config location folder. Please, modify "${relativePath}" path.`)
Copy link
Contributor

Choose a reason for hiding this comment

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

For the error message, what do you think about:

Failed to parse dependencies for check ${checkLogicalId} "${checkName}". All check dependencies must be contained in the project directory, which is the directory containing the Checkly config file. Checks cannot reference files which are outside of this directory.

Project directory: ${Session.basePath}
Dependency: ${filePath}

I tried to add the check logicalId/name to give a hint where the issue is coming from. I also think logging the project directory could let the user know where they're allowed to put files.

I think that it could make sense to use the absolute path rather than relativePath. I'm not sure if we need to call path.resolve on filePath.

@@ -111,8 +111,12 @@ export class BrowserCheck extends Check {

const deps: CheckDependency[] = []
for (const { filePath, content } of parsed.dependencies) {
const relativePath = pathToPosix(path.relative(Session.basePath!, filePath))
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the main browser check script or setup/teardown scripts are outside of the Session.basePath? I'm not sure if checkly-runners supports that, or if we should add an error in that case as well.

@umutuzgur umutuzgur removed their request for review September 21, 2023 09:01
@tnolet
Copy link
Member

tnolet commented Nov 28, 2023

@umutuzgur @clample can we update this issue?

@clample
Copy link
Contributor

clample commented Nov 28, 2023

I'm going to close this one for now

@clample clample closed this Nov 28, 2023
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.

4 participants