fix: extract score/direction from MQTT, strip units, fix type safety issues#371
Merged
fix: extract score/direction from MQTT, strip units, fix type safety issues#371
Conversation
… bare type assertions Fixes #353: - Add Score/Direction fields to PacketData and MQTTPacketMessage structs - Extract score/direction (with case fallback) in all three MQTT handlers - Pass score/direction through to DB observation insert - Strip common unit suffixes (dBm, dB, mW, km, mi, m) in toFloat64 - Change firstSeen/lastSeen from interface{} to string in store.go - Change distHopRecord.SNR from interface{} to *float64
a532570 to
9eca0b7
Compare
Owner
Author
Final independent reviewI rebased this PR onto master, resolved the conflict in Verdict: Approve ✅The changes are correct, well-tested, and solve the stated problem cleanly. What's good
Observations (non-blocking)
No correctness issues, no edge case gaps, no test coverage holes. Ship it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #353 — addresses all 5 findings from the CoreScope code analysis.
Changes
Finding 1 (Major):
scorefield never extracted from MQTTScore *float64field toPacketDataandMQTTPacketMessagestructsmsg["score"]withmsg["Score"]case fallback viatoFloat64in all three MQTT handlers (raw packet, channel message, direct message)nilFinding 2 (Major):
directionfield never extracted from MQTTDirection *stringfield toPacketDataandMQTTPacketMessagestructsmsg["direction"]withmsg["Direction"]case fallback as string in all three MQTT handlersnilFinding 3 (Minor):
toFloat64doesn't strip unitsstripUnitSuffix()that removes common RF/signal unit suffixes (dBm, dB, mW, km, mi, m) case-insensitively beforeParseFloat"-110dBm"or"5.5dB"now parse correctlyFinding 4 (Minor): Bare type assertions in store.go
firstSeenandlastSeenfrominterface{}to typedstringvariables atstore.go:5020.(string)type assertions in comparisonsFinding 5 (Minor):
distHopRecord.SNRtyped asinterface{}distHopRecord.SNRfrominterface{}to*float64snrValvariable, passtx.SNRdirectly)floatPtrOrNil(h.SNR)for consistent JSON outputTests Added
TestBuildPacketDataScoreAndDirection— verifies Score/Direction flow through BuildPacketDataTestBuildPacketDataNilScoreDirection— verifies nil handling when fields absentTestInsertTransmissionWithScoreAndDirection— end-to-end: inserts with score/direction, verifies DB valuesTestStripUnitSuffix— covers all supported suffixes, case insensitivity, and passthroughTestToFloat64WithUnits— verifies unit-bearing strings parse correctlyAll existing tests pass.