Skip to content

fix(config): accept statusmessage/trafficmanagement in module config save (#3464)#3465

Merged
Yeraze merged 1 commit into
mainfrom
fix/3464-module-type-validation
Jun 15, 2026
Merged

fix(config): accept statusmessage/trafficmanagement in module config save (#3464)#3465
Yeraze merged 1 commit into
mainfrom
fix/3464-module-type-validation

Conversation

@Yeraze

@Yeraze Yeraze commented Jun 15, 2026

Copy link
Copy Markdown
Owner

Fixes #3464.

Problem

On v4.10.3, saving Traffic Management or Status Message module config fails server-side:

Failed to save Traffic Management config: Invalid module type: trafficmanagement
Failed to save Status Message config: Invalid module type: statusmessage

Root cause

#3457 made these two module configs editable (gated on firmware version), and the protobuf encoder (createSetModuleConfigMessageGeneric's configFieldMap) already supports both. But the generic save route POST /api/config/module/:moduleType validates 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

  • Extract the allow-list into an import-safe shared constant VALID_MODULE_CONFIG_TYPES + isValidModuleConfigType() in src/server/constants/moduleConfig.ts, now including statusmessage and trafficmanagement.
  • Use it in the route in place of the inline array.
  • Add moduleConfig.test.ts asserting both new types are accepted, unknown types are rejected, and telemetry/neighborinfo (which use dedicated routes) stay excluded — guarding against this allow-list/encoder drift recurring.

Validation

  • New test: 4/4 pass
  • tsc --noEmit: clean
  • Full Vitest suite: 6446 pass, 0 fail, 0 suite failures

🤖 Generated with Claude Code

…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>
@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

Claude finished @Yeraze's task —— View job


Code Review Complete ✅

Reviewing PR #3465: fix(config): accept statusmessage/trafficmanagement in module config save

Todo List

  • Read and analyze all changed files
  • Review code quality and best practices
  • Check for potential bugs or issues
  • Assess performance considerations
  • Evaluate security concerns
  • Review test coverage
  • Provide comprehensive feedback

Review Feedback

This is a well-crafted fix for a straightforward validation bug. The implementation follows excellent practices and demonstrates good software engineering principles.

Strengths

Code Quality & Best Practices:

  • Excellent separation of concerns: Extracting the hardcoded array into a shared constant eliminates the root cause of this type of drift
  • Strong typing: Use of as const and proper TypeScript type inference (ModuleConfigType) provides compile-time safety
  • Comprehensive documentation: Both the constant file and test file have detailed comments explaining the context and constraints
  • Clear naming conventions: VALID_MODULE_CONFIG_TYPES and isValidModuleConfigType() are self-documenting

Bug Prevention:

  • Future-proof design: The shared constant ensures the allow-list and protobuf encoder can't drift apart again
  • Explicit exclusions documented: Comments clearly explain why telemetry and neighborinfo are intentionally absent
  • Type safety: The type guard function prevents runtime type errors

Test Coverage:

🔍 Code Analysis

src/server/constants/moduleConfig.ts (moduleConfig.ts:35-37):

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 includes() on const arrays needs this pattern for type guards.

src/server/server.ts (server.ts:7503):

if (!isValidModuleConfigType(moduleType)) {
  res.status(400).json({ error: `Invalid module type: ${moduleType}` });
  return;
}

Clean integration with existing error handling patterns.

Security, Performance & Maintainability

  • Security: No concerns - this is input validation that makes the system more secure by preventing invalid requests
  • Performance: Negligible impact - single array lookup is O(1) with small constant factor
  • Maintainability: Significantly improved - future module additions only need to update one location

📋 Minor Suggestions (Optional)

  1. Consider alphabetical ordering: The array could be sorted alphabetically for easier visual scanning, though the current grouping may reflect logical relationships.

  2. Future enhancement opportunity: Consider adding a build-time check to ensure the allow-list stays in sync with the protobuf configFieldMap, though this isn't necessary for the current fix.

🎯 Verdict

This PR excellently demonstrates:

  • Root cause analysis: Identified the exact source of the validation drift
  • Minimal, targeted fix: Only changes what's necessary to solve the problem
  • Defensive programming: Prevents the same category of bug from recurring
  • Thorough testing: Complete coverage of the fix and edge cases

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.


@Yeraze Yeraze merged commit 86fdc59 into main Jun 15, 2026
19 checks passed
@Yeraze Yeraze deleted the fix/3464-module-type-validation branch June 15, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Invalid module type errors for trafficmanagement and statusmessage configs

1 participant