10000 Resolve root directory if symlinked by caleb-fringer · Pull Request #742 · air-verse/air · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Resolve root directory if symlinked #742

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

caleb-fringer
Copy link
@caleb-fringer caleb-fringer commented Feb 19, 2025

While the follow_symlink option allows for dereferencing symlinked directories in the project, it does not resolve the root directory to a real directory if it is symbolically linked. This becomes an issue if you are accessing a project directory from a symlink, as filepath.Walk ignores symbolic links.

By adding an additional de-referencing step to Config.preprocess(), this PR resolves Config.Root directories that are themselves symbolic links to their target path so that Engine.watching() will correctly walk the root path.

Closes #531

@caleb-fringer caleb-fringer marked this pull request as draft February 19, 2025 18:22
@caleb-fringer
Copy link
Author

Tested on 5.15.167.4-microsoft-standard-WSL2 running Ubuntu 22.04.5 LTS.

@caleb-fringer caleb-fringer marked this pull request as ready for review February 19, 2025 22:30
@xiantang
Copy link
Collaborator
xiantang commented Mar 5, 2025

can i have any unit test coverage?

@caleb-fringer caleb-fringer marked this pull request as draft March 6, 2025 05:39
@caleb-fringer caleb-fringer force-pushed the resolve-symlinks branch 3 times, most recently from 4857771 to 315c7c1 Compare March 14, 2025 02:20
Add symlink dereferencing step to runner/config.go:preprocess().

Implement runner/utils.go:isSymlink() w/ unit testing.

Refactor runner/utils.go:expandPath() to always return an absolute path.

Add unit test for expandPath with relative path (no dot paths)

Set c.Root to "." after cd'ing to "air_wd"
@caleb-fringer
Copy link
Author
caleb-fringer commented Mar 16, 2025

After adding unit tests for the isSymlink function and expandPath, I am observing perplexing behavior with some of the runner unit tests.

If I cd into runner/ and run go test . -v, then the following unit tests fail:
image

However, if run individually, all except TestCheckRunEnv passes:

image

I suspect this is due to some discrepancy between how the current path is set when unit testing a module versus individual tests, or perhaps some state issue with TestCheckRunEnv. I could use some help understanding this test in particular. I tried clearing the test cache with go clean -testcache but still they succeed individually.

Attached is the output of: go test . -v, which contains logs for the failing tests:
failing-tests.txt

@xiantang
Copy link
Collaborator

lets see if its work in CI

@xiantang
Copy link
Collaborator
xiantang commented Mar 17, 2025
Error calling Lstat on root directory: lstat /home/runner/work/air/air/runner/_testdata/toml/toml_root: no such file or directory
    engine_test.go:43: Should not be fail: lstat /home/runner/work/air/air/runner/_testdata/toml/toml_root: no such file or directory.

i think you should handle this err

@caleb-fringer
Copy link
Author
caleb-fringer commented Mar 17, 2025

I was able to fix the unit tests I broke by adding an explicit check to see if the path passed to derefLink has exists. However, this function is only ever called on config.Root, and in the failing test cases (for instance, TestNewEngine) this was set to toml_root. toml_root does not exist while running the whole test suite. I assumed that this path must already exist by time the test is run, which is what caused Lstat to return an error.

Furthermore, I added a unit test for calling expandPath on relative paths, and I am observing the same issue as before: when I use go test . it fails at os.Getwd() because the path no longer exists. This only occurs when running test on the package, not when individually running the test with go run test . -run TestExpandPathWithRelPath

It really seems like some of the test cases are modifying the runtime environment that other tests depend upon. Can you provide any insight to how the test environment is constructed and modified by other tests?

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.

air not working when project directory is a symlink
2 participants
0