fix: reject NaN sensitivityThreshold in AnomalyDetector (#1008) - #1014
neverm1ndthat wants to merge 1 commit into
Conversation
NaN <= 0 and NaN > 1 are both false, so the existing range check silently accepted NaN and classified every finite score as normal. Add Number.isFinite() guard before the range check and add a regression test covering both NaN rejection and upper-boundary acceptance. Fixes Stellar-split#1008
|
Hi team ?? I submitted this PR for issue #1008 (the NaN sensitivityThreshold bug). The fix adds a Number.isFinite() guard plus regression tests. Let me know if you need me to adjust anything or if there are existing conventions I missed - happy to iterate! |
|
Hi @Kingsman-99! Just wanted to follow up on this PR. It's been about 8 days since I submitted it for issue #1008. The fix adds a simple Number.isFinite() guard to sensitivityThreshold plus regression tests. Let me know if there's anything else I should adjust or if you need more context! |
|
Hi @Kingsman-99! This PR fixes the NaN sensitivityThreshold bug in anomalyDetector - when sensitivityThreshold is NaN, the anomaly check was silently disabled. Added Number.isFinite guard and a test case. PTAL when you have a moment! |
Problem
AnomalyDetectordocumentssensitivityThresholdin(0, 1], but the validationif (threshold <= 0 || threshold > 1)silently accepts NaN because bothNaN <= 0andNaN > 1arefalse. When NaN is passed, every finite score is classified as "normal" — anomaly detection is effectively disabled with no error.Solution
!Number.isFinite(this.sensitivityThreshold)guard before the existing range check insrc/anomalyDetector.ts. NaN, Infinity, and -Infinity all throwRangeErrornow.test/anomalyDetector.nan.test.tscovering NaN rejection and upper-boundary acceptance (1is valid).Testing
Number.NaNwithRangeError1npx vitest run test/anomalyDetector.test.ts test/anomalyDetector.nan.test.ts— (Node 24 not installed locally; the issue body confirms both pass against current main)Closes #1008