Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Fix/files get #499

Merged
merged 4 commits into from
Sep 30, 2016
Merged

Fix/files get #499

merged 4 commits into from
Sep 30, 2016

Conversation

dignifiedquire
Copy link
Member

@dignifiedquire dignifiedquire commented Sep 16, 2016

  • Refactor cli tests to reduce code duplication and increase covered test cases. Also better failure mode, showing stderr and stdin when a cli tests fails.
  • Fix bugs revealed due to better cli tests in
    • files get
    • files cat
    • block stat
    • bootstrap add
    • bootstrap rm

Ref #498

@dignifiedquire
Copy link
Member Author

This can be reviewed for now, no need to wait until we fix the bitswap issues.

@daviddias
Copy link
Member

daviddias commented Sep 22, 2016

@dignifiedquire can you add more description. It says that it fixes files.get. What was found, what was achieved? Looks like there is some solid progress though, 👍

@dignifiedquire
Copy link
Member Author

@diasdavid added a description on what happened^^

@daviddias
Copy link
Member

thank you @dignifiedquire, left a bunch of comments :)

@dignifiedquire dignifiedquire changed the title [WIP] Fix/files get Fix/files get Sep 23, 2016
@dignifiedquire
Copy link
Member Author

thank you @dignifiedquire, left a bunch of comments :)

not seeing any in this PR

@@ -43,6 +43,7 @@
"aegir": "^8.0.1",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"execa": "^0.4.0",
Copy link
Member

Choose a reason for hiding this comment

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

what's this for?

Copy link
Member Author

Choose a reason for hiding this comment

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

To spawn the cli in a consistent and nice way.

@@ -23,8 +23,7 @@ module.exports = {
stats.Wantlist = stats.Wantlist || []
stats.Peers = stats.Peers || []

console.log(`
bitswap status
console.log(`bitswap status
Copy link
Member

Choose a reason for hiding this comment

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

Are we happy with the new "Printer" by @victorbjelkholm? Wanna use that?

Copy link
Member Author

Choose a reason for hiding this comment

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

As I mentioned in another PR I would rather do that change as a single PR on its own, there are already too many things mixed in here.

@@ -24,7 +23,7 @@ module.exports = {
throw err
}

console.log('Key:', bs58.encode(stats.key).toString())
console.log('Key:', stats.key)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this a multihash?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not currently

Copy link
Member

Choose a reason for hiding this comment

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

if (err) {
throw err
}

ipfs.files.cat(path, onFile)
file.pipe(process.stdout)
Copy link
Member

Choose a reason for hiding this comment

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

These are not changes to get

  • I believe we have agreed during a js-ipfs sprint call that we would start settling on async, since not is is modular, more battle tested and the documentation is just great. If we bring on new deps like run-waterfall, better just do the async/waterfall

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't remember making that decision, but happy to move all these run-* to modular async.

Copy link
Member Author

Choose a reason for hiding this comment

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

These are not changes to get

As mentioned in the description, fixes all over including files cat ;)

const dirPath = path.join(dir, file.path)
// Check to see if the result is a directory
if (file.dir === false) {
if (file.content) {
Copy link
Member

Choose a reason for hiding this comment

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

👍

query: {
arg: Joi.string().required(), // multiaddr to add
default: Joi.boolean()
}
Copy link
Member

Choose a reason for hiding this comment

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

Why remove the Joi validation?

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 the only place in the http api where we have validation.
  • It was incorrect as it threw errors on the global stream header.

Copy link
Member

Choose a reason for hiding this comment

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

It is the only place in the http api where we have validation

It was a start, a good practice introduced by @xicombd.

It was incorrect as it threw errors on the global stream header.

Why exactly? That sounds like a Joi bug, this is only checking the query param

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know why, but it wouldn't allow for any additional query parameters to be passed along except for the ones that were part of this validation.

Copy link
Member

Choose a reason for hiding this comment

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

IRC log

11:04 <@daviddias> I don't believe we can break the user API in multihashing, have been thinking about it and the best option ( given that having both API would multiply deps) is to have multihashing-async module
11:04 <@daviddias> And recommend devs to use it in multihashing, explaining why
11:14 <@daviddias> On the first PR, my last comment is to Lee Joi validation, if there are more optional Args, then so be it :)
11:14 <@daviddias> s/Lee/lets keep
11:17 <@daviddias> @dignifiedquire: ^ :)
11:18 <dignifiedquire> so you mean creating a new module for multihashing?
11:20 <dignifiedquire> if we recommend devs to use the new version, we can just do a major version bump, with a changelog, that way everyone who wants to not refactor their code can stay on the old version, and we don't have to maintain to different versions
11:21 <dignifiedquire> daviddias: re Joi validation as I said in my comment I wasn't able to get that working, Joi would always throw if js-ipfs-api passed it something it didn't know
11:26 <dignifiedquire> daviddias: ^^
12:17 <@daviddias> dignifiedquire: ACK, what I meant is: the args that will be passed are defined on the spec
12:18 <@daviddias> so we can list them 

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, the offending parameter is not documented in the HTTP API: http://docs.ipfs.apiary.io/#reference/bootstrap/add/add does not list stream-channels, which is always set to true by js-ipfs-api: https://github.com/ipfs/js-ipfs-api/blob/master/src/request-api.js#L92

Copy link
Member

Choose a reason for hiding this comment

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

Let's add that as an issue in the http spec and add that rule here

arg: Joi.string().required(), // multiaddr to rm
all: Joi.boolean()
}
}
Copy link
Member

Choose a reason for hiding this comment

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

same as above

const bs58 = require('bs58')

const HttpAPI = require('../../src/http-api')
const createTempNode = require('../utils/temp-node')
const repoPath = require('./index').repoPath
const ipfs = require('../utils/ipfs')(repoPath)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a better name for that ipfs file?

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't come up with one, happy to hear suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

ipfs-exec or ipfs-run?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like ipfs-exec

Copy link
Member Author

Choose a reason for hiding this comment

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

done

})
return ipfs('bitswap wantlist').then((out) => {
expect(out).to.be.eql(key)
})
Copy link
Member

Choose a reason for hiding this comment

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

This should be happening inside of the callback of the .inject

Copy link
Member Author

Choose a reason for hiding this comment

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

Look closely, the inject call is just so we get the right response, but the actual command shouldn't happen inside, otherwise it would hang forever.

done()
})
it('stat', () => {
return ipfs('bitswap stat').then((out) => {
Copy link
Member

Choose a reason for hiding this comment

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

In this new CLI library, if an exit code is different than 0, where do we get that error? Also, where is stderr?

Copy link
Member Author

@dignifiedquire dignifiedquire Sep 24, 2016

Choose a reason for hiding this comment

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

If you look into test/utils/ipfs.js you see it asserts that the exitcode is 0 and that stderr is ''. It returns a promise and will reject that promise when an error happens which will in turn display the failed things like exitcode and stderr.

Copy link
Member

Choose a reason for hiding this comment

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

stderr might not always be ''.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we want the command to success it will, for when you want it to fail, there is ipfs.fail('my cmd') which expects failure and allows you to assert agains stderr

Copy link
Member

@daviddias daviddias Sep 28, 2016

Choose a reason for hiding this comment

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

sweet!

Can you document all of that in that ipfs-exec module? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@daviddias
Copy link
Member

@dignifiedquire, my bad, I used the review tool and forgot to click submit

@daviddias
Copy link
Member

daviddias commented Sep 30, 2016

Seems that Joi is the last bit fo make this happen:

Also, want to squash commits?

@dignifiedquire
Copy link
Member Author

Also, want to squash commits?

When CI is green and you gave your thumbs up

@daviddias
Copy link
Member

daviddias commented Sep 30, 2016

@dignifiedquire rebased, tests pass on CI, but fail locally:

  1) HTTP API ## interface-ipfs-core tests over ipfs-api .files callback API .add add a nested dir as array:

      Uncaught AssertionError: expected 'test-folder/files' to equal 'test-folder'
      + expected - actual

      -test-folder/files
      +test-folder

      at node_modules/interface-ipfs-core/lib/files.js:152:34

Does it work on your machine?

@dignifiedquire
Copy link
Member Author

@diasdavid try running them again, they pass for me

@daviddias
Copy link
Member

Got them running (had to do 2 fresh npm installs)

@daviddias daviddias merged commit c8dbf6b into master Sep 30, 2016
@daviddias daviddias deleted the fix/files-get branch September 30, 2016 13:46
@daviddias daviddias removed the status/in-progress In progress label Sep 30, 2016
MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this pull request May 22, 2020
- Change bullet formatting to make it possible to use the markdown headers to link specifically to the MFS portion of this document. 
- Link out from MFS section to the ProtoSchool tutorial as part of Q3 IPFS Docs initiative (see issue ProtoSchool/protoschool.github.io#260)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants