feat: CLI get command improvements#331
Conversation
378543c to
54659e6
Compare
|
Hm, This test checks that Oddly enough I have a very similar test that does work in CI; Update: that's odd, for some reason the directories don't show up in git, as if they're ignored somehow. Wow. It's because I named the directory I resolved it by renaming the said things away from |
|
One thing I realized is that the fixture stream I created may not actually reflect a real world stream; I'm unclear how it works when directories are wrapped or not. I'm going to experiment a bit with real-world streams. |
|
Okay, after some manual testing I see I definitely broke the correct behavior. Withdrawing this from review until I fix it. I tried to convert to draft but currently that button is causing a 404 on the github API for me, so let's just consider it a draft. :) |
|
Okay, I have resolved the underlying issues; it turns out that the stream was not returning what I expected. I've adjusted it so it does. I've also written tests for the single unwrapped file scenario. |
|
Just for FYI: it's now ready for review again. |
e603a38 to
d3fb9b4
Compare
Start work on a streaming get API
Turns out we can use async_trait for the ApiExt trait
This fixes the bug I introduced by my wrong assumption what about get_stream produces
git doesn't actually add them, and we're not testing as much as we should
get_stream should just do the right thing and only deliver those paths we asked for Unfortunately this code isn't under test. Ideally the resolver itself should fulfill this contract, because we give it the full ipfs path after all, and it could potentially do optimizations we can't do at this level.
601b765 to
671d10c
Compare
|
@ramfox can you have another look to see whether it does the right thing? I went for a slightly different approach than you did to handle the ipfs tail paths, but it appears to work. |
Also fix a few tests surrounding get failures due to bad paths
ramfox
left a comment
There was a problem hiding this comment.
just come request for changes around comments!
This PR focuses on creating tests for the
iroh getCLI command. The Iroh API is also improved along the way.This required more work in the underlying API to make it more testable. What's tested here is everything except the actual IPFS behavior -- the focus is on the behavior of the CLI and API and its interactions with the filesystem.
trycmd tests
In
iroh/tests/cmdyou can see now quite a few.trycmdfiles. These describes the command-line interaction. Stuff behind$ is a command, there's a special? failed` indicator if the command is considered to have failed, and the output of the command is shown.New are the
.outand.indirectories with the same names as the.trycmdfiles. These describe the filesystem before the command runs (may be missing), and the filesystem after the command has run. This way we can describe the effects of theiroh getcommand - directories and files are supposed to be created. We can also test failure scenarios where we refuse to overwrite a directory that already exists. n0-computer/beetle#180 tracks various test cases.@b5 is probably most interested in this bit
get_streamThe
gethigh level CLI method has been removed from the mockableApitrait (read on to see where it went). Instead, a more low level but still useful API methodget_streamhas been added to theApitrait. This gets a stream of relative paths andOutType, describing the directories and files you can create.This is a refactored version of the code @ramfox originally wrote and was in
getadd.rspreviously. The big difference is that it returns relative paths and doesn't calculate final destination paths -- that's up to the user of the API.No
async_traitmacro forApitraitThe interactions between the
Apitrait,mockallmacro andasync_traitwere getting so hairy I couldn't figure out how to express things anymore once I wanted to addget_stream. For my sanity and also to learn better how this really works underneath, I've rewritten theApitrait to describe itself explicitly in terms of(Local)BoxFutureand(Local)_BoxStream. It's more verbose but functionally equivalent and I could express what I wanted.ApiExttraitThe
ApiExttrait is a trait that implements the high levelgetcommand. It puts everything together: it handles various error conditions, accesses the stream and then writes the stream to the filesystem. It's basicallyiroh get.The
ApiExttrait is solely intended to contain default trait methods, and is automatically available when theApicontract is fulfilled (if youuseit).I factored out
save_get_streamfromgetadd.rsto be solely concerned with turning a stream into files and directories on the files system. That makes it possible to test its behavior in isolation.test fixture
The
gettest fixture now mocksget_streamand returns a fake stream made from aVec. This defines the actual stuff that the CLI writes to disk.relative_path
I now depend on the
relative-pathcrate because what the get stream returns are clearly relative paths, and I want to force the user to do something with them for being able to actually write stuff. I want to expand the use of relative paths in the CLI where it makes sense in the future, as the use is now only minimal. It should help make it really explicit where the CLI is going to read and write.