Newutils cleanup#1006
Conversation
…te should gracefully reset - duplicate of same removed
accius
left a comment
There was a problem hiding this comment.
Reviewed the changes. Small, well-targeted cleanup and it looks good.
statemachine.js — the require path fix from ../utils/mutex to ./mutex is correct; both files live in server/utils/ so the redundant directory hop wasn't wrong, just confusing. Cleaner this way.
statemachine.test.js — good catch on the old should throw if invalid state index is provided test. It referenced a sm variable that was never assigned, so it was only "passing" because the undefined reference threw a ReferenceError — not because the state machine actually threw. Since SAFETY 3 in run() only logs and resets on an invalid next state (it never throws outside the constructor), rewriting it as should gracefully reset if invalid state index is provided and asserting the reset-to-'A' behavior matches what the code actually does.
Dropping should reset if next state is invalid is fine since the rewritten test already exercises the invalid-next-state path; no coverage lost.
One minor note, not blocking: the rewritten test is marked async and awaits sm.currentState(), but sm.run() itself is not awaited. It works here because the handler is synchronous, but awaiting run() would be more consistent with the other tests in the file and more robust if the handler ever becomes async.
CI is green on both Node 20.x and 22.x, and tests pass locally. Approving in spirit — clean fix.
— K0CJH
What does this PR do?
Type of change
Checklist
server.js: caches have TTLs and size caps (we serve 2,000+ concurrent users)var(--accent-cyan), etc.).bak,.old,console.logdebug lines, or test scripts included