Skip to content

[npm] Randomize advisory id to avoid cache collisions across tests#5875

Merged
mctofu merged 1 commit intomainfrom
mctofu/npm-flake-fix
Oct 12, 2022
Merged

[npm] Randomize advisory id to avoid cache collisions across tests#5875
mctofu merged 1 commit intomainfrom
mctofu/npm-flake-fix

Conversation

@mctofu
Copy link
Copy Markdown
Contributor

@mctofu mctofu commented Oct 12, 2022

🤞 This fixes test failures seen when the tests are run in a particular order. Details of the advisories are being cached in the npm cache and shared across test runs. This can lead to faulty analysis of vulnerabilities in the tests because we were using the same advisory ids in each evaluation.

I didn't track down exactly where it goes wrong in the arborist code but I found that once I reproduced the failures locally with a particular test seed I could then reliably reproduce the failure on an individual test. After observing that the audit report didn't completely match up with the advisory I tried changing the advisory id and the test passed.

@mctofu mctofu marked this pull request as ready for review October 12, 2022 16:06
@mctofu mctofu requested a review from a team as a code owner October 12, 2022 16:06
Copy link
Copy Markdown
Contributor

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

Wow, must've been hard to figure out 😅. So this initially reproduced by running tests with some fixed seed, and then you reduced that to running just the failing test in isolation twice, and it would fail the second time, right?

In general, I find that order dependent failures are best fixed by fixing the state leak between them. In this case, I guess clearing the npm cache of the specs that leak it?

But this may not be possible/desirable here, not sure.

In any case, it's great to finally get rid of these flakes! 🎉 🎉

@mctofu
Copy link
Copy Markdown
Contributor Author

mctofu commented Oct 12, 2022

In general, I find that order dependent failures are best fixed by fixing the state leak between them. In this case, I guess clearing the npm cache of the specs that leak it?

Yeah, I considered that as well but was worried that it would slow down the tests since the npm cache also helps re-downloading common packages across the tests.

This fixes test failures seen when the tests are run in a particular
order. Details of the advisories are being cached in the npm cache
and shared across test runs which could lead to faulty analysis
of vulnerabilities in the tests because we used the same advisory ids
in each evaluation.
@mctofu mctofu force-pushed the mctofu/npm-flake-fix branch from 1ae6411 to 352fe7f Compare October 12, 2022 18:59
@mctofu
Copy link
Copy Markdown
Contributor Author

mctofu commented Oct 12, 2022

One more note: this only affected the tests and manual/local usage of Dependabot. On github.com we use a fresh sandbox for each security update we create so the npm cache doesn't persist between vulnerabilities.

@mctofu mctofu merged commit 7b19233 into main Oct 12, 2022
@mctofu mctofu deleted the mctofu/npm-flake-fix branch October 12, 2022 19:42
Copy link
Copy Markdown
Member

@jeffwidman jeffwidman left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

@pavera pavera mentioned this pull request Oct 31, 2022
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.

3 participants