test: fail fast on missing VCR cassettes by converting errors to 404#2816
Conversation
b15ead4 to
7ab4e88
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2816 +/- ##
==========================================
+ Coverage 79.14% 79.16% +0.01%
==========================================
Files 121 121
Lines 8185 8191 +6
==========================================
+ Hits 6478 6484 +6
Misses 1324 1324
Partials 383 383 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7ab4e88 to
78c17de
Compare
| if maxNetworkQueryAttempts > 0 { | ||
| // osvdev.Config.MaxRetryAttempts actually controls the maximum number of attempts, | ||
| // where 1 means 1 attempt (0 retries). | ||
| config.MaxRetryAttempts = maxNetworkQueryAttempts |
There was a problem hiding this comment.
I am a bit confused about how this config will be propagated through? is the config defined in osv-scalibr?
There was a problem hiding this comment.
It's not needed for scalibr, we have not switched to use the osv-scalibr osvdev enrichers yet.
There was a problem hiding this comment.
But I think I'll rework this a bit, I'm not sure we want to have this as a config in general.
78c17de to
9d7170c
Compare
|
|
||
| func (t *vcrErrorWrappingTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
| resp, err := t.wrapper.RoundTrip(req) | ||
| if err != nil && strings.Contains(err.Error(), "requested interaction not found") { |
There was a problem hiding this comment.
use errors.Is to check the error?
There was a problem hiding this comment.
the error is defined here: https://github.com/dnaeon/go-vcr/blob/v4/pkg/cassette/cassette.go#L50
There was a problem hiding this comment.
Good idea, done.
If a VCR cassette or a specific interaction is missing, the OSV client would previously retry the request 4 times with exponential backoff, causing significant delays in test execution (over 20 seconds). This change wraps the VCR client transport in tests to intercept the "requested interaction not found" error (using errors.Is with cassette.ErrInteractionNotFound) and convert it to a "404 Not Found" response. Since the OSV client does not retry on 404 status codes, this allows tests to fail immediately (~0.02s) on missing cassettes/interactions while still preserving retry behavior for genuine transient network errors. - Implemented vcrErrorWrappingTransport in internal/testcmd/vcr.go - Wrapped the VCR client transport in InsertCassette - Used errors.Is with cassette.ErrInteractionNotFound for robust error matching
9d7170c to
f4df75a
Compare
If a VCR cassette or a specific interaction is missing, the OSV client would previously retry the request 4 times with exponential backoff, causing significant delays in test execution (over 20 seconds).
This change wraps the VCR client transport in tests to intercept the "requested interaction not found" error (using
errors.Iswithcassette.ErrInteractionNotFoundfor robust matching) and convert it to a "404 Not Found" response. Since the OSV client does not retry on 404 status codes, this allows tests to fail immediately (~0.02s) when a cassette or interaction is missing while still preserving retry behavior for genuine transient network errors.This approach avoids modifying the core
osvscannerlibrary API or adding new CLI flags.vcrErrorWrappingTransportininternal/testcmd/vcr.goInsertCassetteerrors.Iswithcassette.ErrInteractionNotFoundfor robust error matching