Skip to content

Fall back to project root when file resolver cannot find file#2325

Merged
holyfuchs merged 1 commit intomasterfrom
holyfuchs/file-resolver-project-root-fallback
Apr 15, 2026
Merged

Fall back to project root when file resolver cannot find file#2325
holyfuchs merged 1 commit intomasterfrom
holyfuchs/file-resolver-project-root-fallback

Conversation

@holyfuchs
Copy link
Copy Markdown
Member

The fileResolver always resolved file paths relative to the test file that triggered the import. This breaks when a helper script is shared across test files in different directories.

For example, given this layout:

tests/some_test.cdc -> imports "test_helpers" -> reads some_contract.cdc -> resolves to tests/some_contract.cdc
tests/mocks/some_test.cdc -> imports "../test_helpers" -> reads some_contract.cdc -> resolves to tests/mocks/some_contract.cdc

This essentially forces having all test files in a single directory.

The fix adds a fallback: if a file isn't found at the path relative to the test file, it retries the path relative to the project root (the working directory where flow.json lives).
The original error is returned only if both lookups fail, so existing behavior is fully preserved.
Any test that already works continues to work unchanged.

@github-actions
Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA df4a9d8.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/test/test.go 80.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

tests.SomeFile.Source,
os.ModeTemporary,
)
t.Parallel()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you move this to the top of the function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure but all of the tests have same setup, I just copied it, would rather leave this consistent.

@holyfuchs holyfuchs merged commit 8a0ec60 into master Apr 15, 2026
9 checks passed
@holyfuchs holyfuchs deleted the holyfuchs/file-resolver-project-root-fallback branch April 15, 2026 21:53
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