fix(vitest): prevent negative test durations#9380
Conversation
Clamp short failed-test durations at zero and cover the regression through a real Vitest integration run. Co-authored-by: Ruben Bridgewater <[email protected]>
Overall package sizeSelf size: 6.77 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.1 | 122.62 kB | 438.86 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
|
@codex review |
There was a problem hiding this comment.
More details
The duration-clamping fix is arithmetically correct and the condition change from if (duration) to if (Number.isFinite(duration) && duration >= 0) is strictly safer — it now also falls back to clock time for Infinity and negative raw durations from Vitest, both of which the old truthy check silently accepted and could produce bad spans. The integration test correctly exercises the fix: the custom runner sets task.result.duration = 1 before the startTests post-processing loop reads it, and the assert.strictEqual(Number(tests[0].duration), 0) assertion matches the clamped result of Math.max(1−5, 0)=0.
📊 Validated against 16 scenarios · Open Bits AI session
🤖 Datadog Autotest · Commit f60bc1b · What is Autotest? · Any feedback? Reach out in #autotest
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
BenchmarksBenchmark execution time: 2026-07-15 13:23:41 Comparing candidate commit f60bc1b in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2311 metrics, 47 unstable metrics.
|
🎉 All green!🧪 All tests passed 🔄 Datadog auto-retried 1 job - 1 passed on retry 🎯 Code Coverage (details) 🔗 Commit SHA: f60bc1b | Docs | Datadog PR Page | Give us feedback! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9380 +/- ##
==========================================
- Coverage 96.65% 96.30% -0.35%
==========================================
Files 923 923
Lines 122862 122946 +84
Branches 21061 21024 -37
==========================================
- Hits 118749 118403 -346
- Misses 4113 4543 +430 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Clamp short failed-test durations at zero and cover the regression through a real Vitest integration run. Co-authored-by: Ruben Bridgewater <[email protected]>
Clamp short failed-test durations at zero and cover the regression through a real Vitest integration run. Co-authored-by: Ruben Bridgewater <[email protected]>
Clamp short failed-test durations at zero and cover the regression through a real Vitest integration run. Co-authored-by: Ruben Bridgewater <[email protected]>
Clamp short failed-test durations at zero and cover the regression through a real Vitest integration run. Co-authored-by: Ruben Bridgewater <[email protected]>
What does this PR do?
Prevents failed Vitest tests shorter than five milliseconds from producing negative test span durations.
The duration adjustment is now clamped at zero. A Vitest core integration test runs a real failing test through the worker instrumentation, plugin, serialization, and fake intake paths with a deterministic one-millisecond framework duration.
Motivation
Vitest reports the failed task duration to the plugin, which subtracts five milliseconds to avoid overlap with suite spans. Durations below that threshold previously finished before their start time.
The direct diagnostic-channel test in #9342 only exercised the arithmetic with a fabricated span. This version incorporates Ruben's production fix and verifies the original failure at the integration boundary instead.
Additional Notes
Before the production change, the regression test reported
-4,000,000 nswith both Vitest 1.6.0 and the latest supported version.Validation:
SPEC=vitest.core npm run test:integration:vitest -- --grep "does not report negative durations"— 2 passinggit diff --check