Conversation
lib/fs/promises.js
Outdated
There was a problem hiding this comment.
Is it possible to add a test for this?
There was a problem hiding this comment.
@mscdex In general, fs/promises has poor coverage and this is not the only method that lacks it completely. In the current state, I view that as a separate task. I mentioned that in the PR.
This is not some edge case — the whole public method (among with several others) completely lacks tests and they need to be written.
Ref: https://coverage.nodejs.org/coverage-b55a11d1b17b3e4b/root/fs/promises.js.html
davisjam
left a comment
There was a problem hiding this comment.
Nice catch on fchmod vs fchown.
I think it's appropriate to improve things as you go along, so I think adding a TC for lchown would be good as part of this PR.
I don't think it's fair to require this here (requesting is fine though) as this PR is an improvement and a bug fix as is. Plus tests for it could be great for a code & learn. |
|
@davisjam @mscdex I opened issue #20435 for tests. If there were tests present and this fixed a corner case, I would have included a test for that corner case, but there are just no tests for those functions at all currently (and testing just the patched one won't even improve the situation much). E.g. #20435 (comment) could be a good approach, but again — out of scope here. |
|
@ChALkeR Clearly I overestimated the state of tests. I retract my objection. |
|
I don't understand why tests have to be added separately? I was under the impression that bug fixes should generally come with test(s) to ensure the bug doesn't happen again? To be clear, I wasn't asking for tests for the entire set of fs/promise APIs, just the one being affected in this PR. |
|
I personally think it would still be best to land it with tests. I know we work on getting something else going but until then, the extra test would help. Nevertheless, I am not going to block this without a test either. So if it is only about me: go ahead and land it. |
|
I am going to merge this as it is tomorrow if there would be no explicit concerns. I still strongly believe that lack of tests for |
|
|
That code expects the last argument to be a callback. When it's not a callback, it shifts arguments, defaulting encoding to 'utf-8', which is clearly broken. Old signature: (fd, string[, position[, encoding]], callback) New signature: (fd, string[, position[, encoding]]) PR-URL: nodejs#20407 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jamie Davis <davisjam@vt.edu> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This was a clear error. chown should do chown, not chmod. PR-URL: nodejs#20407 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jamie Davis <davisjam@vt.edu> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
|
Landed in dd03709...15f7431. |
That code expects the last argument to be a callback. When it's not a callback, it shifts arguments, defaulting encoding to 'utf-8', which is clearly broken. Old signature: (fd, string[, position[, encoding]], callback) New signature: (fd, string[, position[, encoding]]) PR-URL: #20407 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jamie Davis <davisjam@vt.edu> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This was a clear error. chown should do chown, not chmod. PR-URL: #20407 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jamie Davis <davisjam@vt.edu> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
That code expects the last argument to be a callback. When it's not a callback, it shifts arguments, defaulting encoding to 'utf-8', which is clearly broken. Old signature: (fd, string[, position[, encoding]], callback) New signature: (fd, string[, position[, encoding]]) PR-URL: #20407 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jamie Davis <davisjam@vt.edu> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This was a clear error. chown should do chown, not chmod. PR-URL: #20407 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jamie Davis <davisjam@vt.edu> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
That code expects the last argument to be a callback. When it's not a callback, it shifts arguments, defaulting encoding to 'utf-8', which is clearly broken. Old signature: (fd, string[, position[, encoding]], callback) New signature: (fd, string[, position[, encoding]]) PR-URL: #20407 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jamie Davis <davisjam@vt.edu> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This was a clear error. chown should do chown, not chmod. PR-URL: #20407 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jamie Davis <davisjam@vt.edu> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesThis fixes two errors in
fs/promises:write(fd, string[, position[, encoding]], callback)signature arg-shifting to findcallback— that variable was unused and that logic was corruptingencoding.chownshould do chown, not chmod.Sorry, this doesn't include tests — I would appreciate some help there. In general,
fs/promisestest coverage is poor, and this PR isn't aimed at that (yet). Also, #19811 aims to increase the test covereage forfs/promises.Perhaps #20406 need to be resolved first — the first patch fixes technically undocumented behavior and I am not sure we should be testing it or removing it.