test(node-js): add unit tests for controller command logic; fix DriveValue.read rounding - #537
Open
Arvin7liu wants to merge 1 commit into
Open
Conversation
…Value.read rounding - Add controller/node-js/test/commands.test.js covering CommandHandler drive mapping, DriveCommandReducer de-duplication, and DriveValue bounds. - Fix DriveValue.read(): Math.round(value, 3) ignored the 2nd argument and returned an integer; use Math.round(value * 1000) / 1000 for 3-decimal precision. Export DriveValue so it is testable. - Add "test": "node --test" script (zero new dependencies, runs on Node 18+).
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
The node-js web controller has no automated tests for its server-side command logic, even though that logic computes the exact left/right motor commands sent to the robot. This PR adds dependency-free unit tests and fixes a latent rounding bug found while writing them.
controller/node-js/test/commands.test.js, run via Node's built-innode:test):CommandHandlerdrive mapping forgoForward/goBackward/forwardLeft/forwardRight/rotateLeft/rotateRight/reset.DriveCommandReducerde-duplication (identical consecutive drive commands are not re-sent).CommandHandler.sendCommandraw-command forwarding.DriveValueclamping to [-1, 1] andread()precision.DriveValue.read()usedMath.round(value, 3).Math.roundonly accepts one argument, so the3was ignored and the method returned an integer instead of a 3-decimal value. Changed toMath.round(value * 1000) / 1000.DriveValueis now exported so the tests can reach it."test": "node --test"script tocontroller/node-js/package.json(zero new dependencies; runs on Node 18+).Why this matters
A regression in the command mapping would silently send wrong motor commands to a physical robot. The new tests lock in the expected behavior and run in CI-friendly, dependency-free fashion.
Test plan
cd controller/node-js && npm test→ 10/10 passing on Node 22 (also verified withnode --checkon allserver/*.jsandclient/*.js).read()fix makes theDriveValuetest fail (proving the test actually guards the fix).Notes
This is unrelated to #447 / PR #514 (the TF/Keras policy-training issue), which is handled separately.
🤖 Generated with WorkBuddy