Skip to content

Commit 0cd852f

Browse files
wraithgarfritzy
authored andcommitted
fix: mitigate doctor test race condition
cacache appears to not write everything to the cache by the time doctor is checking permissions. This limits the permissions error to a single directory that we know exists by the time the checks run.
1 parent 71ab00a commit 0cd852f

File tree

2 files changed

+5
-99
lines changed

2 files changed

+5
-99
lines changed

tap-snapshots/test/lib/commands/doctor.js.test.cjs

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ node -v ok current: v1.0.0, recommended: v1.0.0
467467
npm config get registry ok using default registry (https://registry.npmjs.org/)
468468
which git ok /path/to/git
469469
Perms check on cached files not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache (should be owned by current user)
470-
Perms check on local node_modules not ok Check the permissions of files in {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/prefix/node_modules (should be owned by current user)
470+
Perms check on local node_modules ok
471471
Perms check on global node_modules ok
472472
Perms check on local bin folder ok
473473
Perms check on global bin folder ok
@@ -514,106 +514,10 @@ Object {
514514
],
515515
],
516516
"warn": Array [
517-
Array [
518-
"checkFilesPermission",
519-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache",
520-
],
521517
Array [
522518
"checkFilesPermission",
523519
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache",
524520
],
525-
Array [
526-
"checkFilesPermission",
527-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_logs",
528-
],
529-
Array [
530-
"checkFilesPermission",
531-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/content-v2",
532-
],
533-
Array [
534-
"checkFilesPermission",
535-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/index-v5",
536-
],
537-
Array [
538-
"checkFilesPermission",
539-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/tmp",
540-
],
541-
Array [
542-
"checkFilesPermission",
543-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_logs/{DATE}-debug-0.log",
544-
],
545-
Array [
546-
"checkFilesPermission",
547-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/content-v2/sha512",
548-
],
549-
Array [
550-
"checkFilesPermission",
551-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/index-v5/5e",
552-
],
553-
Array [
554-
"checkFilesPermission",
555-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/index-v5/af",
556-
],
557-
Array [
558-
"checkFilesPermission",
559-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/content-v2/sha512/{sha}",
560-
],
561-
Array [
562-
"checkFilesPermission",
563-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/content-v2/sha512/{sha}",
564-
],
565-
Array [
566-
"checkFilesPermission",
567-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/index-v5/5e/be",
568-
],
569-
Array [
570-
"checkFilesPermission",
571-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/index-v5/af/03",
572-
],
573-
Array [
574-
"checkFilesPermission",
575-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/content-v2/sha512/{sha}",
576-
],
577-
Array [
578-
"checkFilesPermission",
579-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/content-v2/sha512/{sha}",
580-
],
581-
Array [
582-
"checkFilesPermission",
583-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/index-v5/5e/be/ccdeeea0a01ebb0e365e566161f7c68ddcbbe04206d8542742d98875f03f",
584-
],
585-
Array [
586-
"checkFilesPermission",
587-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/index-v5/af/03/5c781820370e585dc2323edbbc80669bf714da5b47d56510c7d0bd7521ee",
588-
],
589-
Array [
590-
"checkFilesPermission",
591-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/content-v2/sha512/{sha}",
592-
],
593-
Array [
594-
"checkFilesPermission",
595-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/cache/_cacache/content-v2/sha512/{sha}",
596-
],
597-
Array [
598-
"checkFilesPermission",
599-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/prefix/node_modules",
600-
],
601-
Array [
602-
"checkFilesPermission",
603-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/prefix/node_modules/.bin",
604-
],
605-
Array [
606-
"checkFilesPermission",
607-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/prefix/node_modules/testDir",
608-
],
609-
Array [
610-
"checkFilesPermission",
611-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/prefix/node_modules/testLink",
612-
],
613-
Array [
614-
"checkFilesPermission",
615-
"should be owner of {CWD}/test/lib/commands/tap-testdir-doctor-incorrect-owner/prefix/node_modules/testDir/testFile",
616-
],
617521
],
618522
}
619523
`

test/lib/commands/doctor.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,10 @@ t.test('incorrect owner', async t => {
359359
...fs,
360360
lstat: (p, cb) => {
361361
const stat = fs.lstatSync(p)
362-
stat.uid += 1
363-
stat.gid += 1
362+
if (p.endsWith('_cacache')) {
363+
stat.uid += 1
364+
stat.gid += 1
365+
}
364366
return cb(null, stat)
365367
},
366368
},

0 commit comments

Comments
 (0)