fix(progress): clamp loaded to total for computable upload/download events#7458
Conversation
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 4/5
- Only a moderate test gap:
test/unit/helpers/progressEventReducer.jshas an ineffective assertion for negative byte deltas, so out-of-order events aren’t being validated and a regression could slip through. - Overall risk is limited to test coverage rather than runtime behavior, so this looks safe to merge with minor follow-up.
- Pay close attention to
test/unit/helpers/progressEventReducer.js- strengthen the negative delta/out-of-order event test to catch regressions.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="test/unit/helpers/progressEventReducer.js">
<violation number="1" location="test/unit/helpers/progressEventReducer.js:22">
P2: Ineffective test assertion for negative byte deltas; misses out-of-order event simulation</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
Follow-up: addressed test coverage concern by adding an explicit out-of-order event case in (with decreasing between events) to assert non-negative byte deltas and clamped progress behavior. |
|
Correction: I pushed a follow-up test update covering an out-of-order progress event (loaded decreases between events) and asserting non-negative byte deltas with clamped progress. |
|
Maintainer note on scope vs prior attempt:
If maintainers prefer, I can also add a narrow adapter-level assertion on top of the reducer test, but I kept this patch focused to minimize risk. |
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="test/unit/helpers/progressEventReducer.js">
<violation number="1" location="test/unit/helpers/progressEventReducer.js:25">
P2: Test assertion for `last.bytes` is too permissive. Using `assert.ok(last.bytes >= 0)` passes for both buggy (40 bytes) and correct (20 bytes) implementations. Should use `assert.strictEqual(last.bytes, 20)` to verify the fix for inflated progress byte deltas.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
Addressed: I tightened the test assertion (expected bytes delta is now exact, not permissive) and updated reducer bookkeeping so bytesNotified remains monotonic across out-of-order events. This keeps clamped progress correct and avoids inflated byte deltas after loaded decreases. |
|
Quick follow-up: this is ready from my side and includes regression coverage for out-of-order progress events. If you want any scope adjustment, I can update immediately. |
4f351b7 to
8627bee
Compare
|
Rebased onto latest v1.x and force-pushed after the recent follow-up fixes. This should clear the branch-behind state; ready for maintainer review. |
|
Thanks @aviu16 this looks good to me 🔥 |
Summary
loadedtototalinprogressEventReducerwhenlengthComputableis trueloaded > total) and out-of-order progress eventsWhy
Issue #7232 reports
onUploadProgress.progressvalues above 100% in React Native. This happens when progress events reportloadedlarger thantotal.Testing
npm run test:mocha -- test/unit/helpers/progressEventReducer.jsFixes #7232