fix(config): accept statusmessage/trafficmanagement in module config save (#3464)#3465
Conversation
…save (#3464) #3457 made the Status Message and Traffic Management module configs editable (gated on firmware version), and the protobuf encoder's configFieldMap already supported both. But the generic save route POST /api/config/module/:moduleType validates against a separate hardcoded allow-list that was never updated, so saving either one returned HTTP 400 "Invalid module type: statusmessage" / "...: trafficmanagement" (#3464). Extract the allow-list into an import-safe shared constant (VALID_MODULE_CONFIG_TYPES + isValidModuleConfigType) that includes both new types, and use it in the route. Add a unit test asserting the two types are accepted and that telemetry/neighborinfo (dedicated routes) stay excluded — so this allow-list / encoder drift can't silently recur. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job Code Review Complete ✅Reviewing PR #3465: fix(config): accept statusmessage/trafficmanagement in module config save Todo List
Review FeedbackThis is a well-crafted fix for a straightforward validation bug. The implementation follows excellent practices and demonstrates good software engineering principles. ✅ StrengthsCode Quality & Best Practices:
Bug Prevention:
Test Coverage:
🔍 Code Analysissrc/server/constants/moduleConfig.ts ( export function isValidModuleConfigType(moduleType: string): moduleType is ModuleConfigType {
return (VALID_MODULE_CONFIG_TYPES as readonly string[]).includes(moduleType);
}The type casting is necessary and safe here since src/server/server.ts ( if (!isValidModuleConfigType(moduleType)) {
res.status(400).json({ error: `Invalid module type: ${moduleType}` });
return;
}Clean integration with existing error handling patterns. ✅ Security, Performance & Maintainability
📋 Minor Suggestions (Optional)
🎯 VerdictThis PR excellently demonstrates:
Recommendation: ✅ APPROVE This is exactly the type of fix that makes codebases more robust. The shared constant approach eliminates the category of bug entirely, while the comprehensive tests prevent regressions. |
Fixes #3464.
Problem
On v4.10.3, saving Traffic Management or Status Message module config fails server-side:
Root cause
#3457 made these two module configs editable (gated on firmware version), and the protobuf encoder (
createSetModuleConfigMessageGeneric'sconfigFieldMap) already supports both. But the generic save routePOST /api/config/module/:moduleTypevalidates the module type against a separate, hardcoded allow-list (validModuleTypes) that was never updated — so both saves were rejected with HTTP 400 before ever reaching the (working) encoder.Single missing entry in one allow-list; no protobuf/manager/frontend changes needed.
Fix
VALID_MODULE_CONFIG_TYPES+isValidModuleConfigType()insrc/server/constants/moduleConfig.ts, now includingstatusmessageandtrafficmanagement.moduleConfig.test.tsasserting both new types are accepted, unknown types are rejected, andtelemetry/neighborinfo(which use dedicated routes) stay excluded — guarding against this allow-list/encoder drift recurring.Validation
tsc --noEmit: clean🤖 Generated with Claude Code