Skip to content

chore(file checker): separate resolving and checking for easier testing#1830

Merged
mre merged 5 commits intolycheeverse:masterfrom
rina-forks:refactor-filechecker
Aug 30, 2025
Merged

chore(file checker): separate resolving and checking for easier testing#1830
mre merged 5 commits intolycheeverse:masterfrom
rina-forks:refactor-filechecker

Conversation

@katrinafyi
Copy link
Member

@katrinafyi katrinafyi commented Aug 29, 2025

this does a simple refactor to break up the check_path function. previously, this had the responsibility of resolving index files/fallback extensions and checking fragments. this was done in one step which made it hard to test - in order to test the resolving, we had to test it indirectly by checking fragments in certain files.

this introduces a new resolve_local_path function which only applies the index file + extensions, so we can use this in unit tests and make assertions about the resolved path.

this should have no changes to any behaviour.

please note perf bug. also, idk if I go overboard with the macros ;-;

this does a simple refactor to break up the `check_path` function.
previously, this had the responsibility of resolving index
files/fallback extensions _and_ checking fragments. this was done in one
step which made it hard to test - in order to test the resolving, we had
to test it indirectly by checking fragments in certain files.

this introduces a new `resolve_local_path` function which only applies
the index file + extensions, so we can use this in unit tests and make
assertions about the resolved path.

this should have no changes to any behaviour.
this makes the meaning of the tests a bit clearer. rather than going
through fragments, we can directly make assertions about the resolved
file path.
Ok(meta) if meta.is_dir() => self.apply_index_files(path).map(Cow::Owned),
Ok(meta) if meta.is_dir() => self.apply_index_files(path),

// otherwise, path is an existing file - just return the path
Copy link
Member

Choose a reason for hiding this comment

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

Have you tried to return a Path (with a lifetime)? This would technically be a breaking change, but that should be fine if we can avoid the copy.

Copy link
Member Author

Choose a reason for hiding this comment

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

Return a &Path with lifetime from resolve_local_path? I haven't tried, but my intuition was it wouldn't work because we can't return a reference to locally owned data. The owned data would get deallocated upon leaving the function.

Previously, Cow was used to hold either a owned or borrowed value, but I got rid of Cow because it was somewhat inconvenient to work with. I could add it back if you think that's a reasonable solution.

Copy link
Member

Choose a reason for hiding this comment

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

Silly me, you're right.

I played around with it and created rina-forks#1. Can you take a look? I can see advantages and disadvantages on both sides, so I'm okay with keeping your version as well. 😉 If you decide to merge my PR, this PR should automatically get updated. 🪄

Copy link
Member Author

Choose a reason for hiding this comment

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

It is merged, thanks for your help!

@mre mre merged commit be26d02 into lycheeverse:master Aug 30, 2025
6 checks passed
@mre
Copy link
Member

mre commented Aug 30, 2025

Yay, that's a solid improvement. Thanks @katrinafyi. 🙏

@mre mre mentioned this pull request Aug 30, 2025
This was referenced Oct 21, 2025
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.

2 participants