fix: convert webhook timeout from seconds to milliseconds before comparison#2974
fix: convert webhook timeout from seconds to milliseconds before comparison#2974joonas wants to merge 2 commits intodefenseunicorns:mainfrom
Conversation
…arison `MeasureWebhookTimeout.start()` stored `config.webhookTimeout` as-is (seconds, 1-30), but `stop()` computed elapsed time via `performance.now()` (milliseconds). The comparison `elapsedTime > this.timeout` therefore treated a 10-second timeout as 10ms. Multiply the timeout by 1000 on entry so both sides of the comparison are in milliseconds. Update existing tests to use realistic units (timeout in seconds, elapsed time in milliseconds) instead of abstract values that accidentally passed despite the bug. Add a boundary test for the exact-equals case. Signed-off-by: Joonas Bergius <joonas@defenseunicorns.com>
Greptile SummaryThis PR fixes a unit mismatch bug in Confidence Score: 5/5Safe to merge — minimal, targeted fix with correct logic and well-updated tests. Single-line production change multiplying by 1000 in the right place; callers in mutate-processor and validate-processor already pass seconds so no call-site changes needed. Test coverage correctly exercises under, over, and exact-equals boundary. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Processor as mutate/validate-processor
participant MWT as MeasureWebhookTimeout
participant perf as performance.now()
participant metrics as metricsCollector
Processor->>MWT: start(config.webhookTimeout) [seconds, e.g. 10]
Note over MWT: this.timeout = 10 * 1000 = 10000ms
MWT->>perf: getNow()
perf-->>MWT: startTime (ms)
Note over Processor: webhook processing...
Processor->>MWT: stop()
MWT->>perf: getNow()
perf-->>MWT: endTime (ms)
Note over MWT: elapsedTime = endTime - startTime (ms)
alt elapsedTime > this.timeout (both in ms)
MWT->>metrics: incCounter("mutate_timeouts")
else within budget
Note over MWT: no counter increment
end
Reviews (1): Last reviewed commit: "Merge branch 'main' into fix/webhook-tim..." | Re-trigger Greptile |
Description
MeasureWebhookTimeout.start()storedconfig.webhookTimeoutas-is (seconds, 1-30), butstop()computed elapsed time viaperformance.now()(milliseconds). The comparisonelapsedTime > this.timeouttherefore treated a 10-second timeout as 10ms.Multiply the timeout by 1000 on entry so both sides of the comparison are in milliseconds.
Update existing tests to use realistic units (timeout in seconds, elapsed time in milliseconds) instead of abstract values that accidentally passed despite the bug. Add a boundary test for the exact-equals case.
End to End Test:
(See Pepr Excellent Examples)
Type of change
Checklist before merging