refactor(config): centralize config/module-type registry (section B1)#3497
Conversation
The numeric AdminMessage config/module enum values and the id→camelCase protobuf-field maps were copy-pasted across server.ts (5 inline maps) and protobufService.ts. They drifted — #3464 (module saveable by the encoder but rejected by a stale route allow-list) was a direct symptom. Add a single canonical registry, src/server/constants/configTypes.ts (CONFIG_TYPES → CONFIG_TYPE_MAP / MODULE_FIELD_BY_ID / DEVICE_FIELD_BY_ID), and derive every site from it: - protobufService.ts module-config encoder field map - server.ts: the local + remote config-type maps and the module/device field lookup maps (5 inline copies removed) Incidental fix: the local-node branch used an INCOMPLETE copy of the config-type map (missing power/display/sessionkey/deviceui/serial/extnotif/storeforward/ rangetest/cannedmsg/audio/remotehardware/ambientlighting/detectionsensor/ paxcounter), so a local-node GET of those configs returned 400 "Unknown config type". Using the full registry resolves that. Left intentionally: protobufService.createSetDeviceConfigMessageGeneric's 5-entry map is a deliberately restricted "generic device encoder" set, not the same as the device lookup map, so it is unchanged. Tests: configTypes.test.ts pins the full enum/field table (protocol contract), asserts derived maps, and guards that VALID_MODULE_CONFIG_TYPES stays consistent with the registry (the #3464 drift class). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: refactor(config): centralize config/module-type registry (section B1)Tasks
This is a clean, well-scoped refactor. The motivation is sound, the implementation is straightforward, and the tests are genuinely useful. A few observations: Correctness
Remaining switch cases in Code quality
TestsThe test file is excellent:
One minor gap: the test asserts SummaryThis is ready to merge. The core goal — eliminating the copy-paste drift that caused #3464 — is achieved, and the drift guard test will catch future recurrences. The residual switch fallthrough blocks in |
First of the section-B refactors from the systemic review. Targets the duplicated module/config-type maps — the #1 "very tractable, high impact" candidate, and the exact drift class behind #3464.
Problem
The numeric AdminMessage config/module enum values and the
id → camelCase protobuf fieldmaps were copy-pasted acrossserver.ts(5 inline maps) andprotobufService.ts. Adding a config/module type meant editing ~6 sites; they drifted (#3464).Change
New canonical registry
src/server/constants/configTypes.ts:CONFIG_TYPES(the one source of truth) → derivedCONFIG_TYPE_MAP,MODULE_FIELD_BY_ID,DEVICE_FIELD_BY_ID.Every duplicated site now derives from it:
protobufService.tsmodule-config encoder field mapserver.ts: local + remote config-type maps, and the module/device field lookup maps (5 inline copies removed)Incidental correctness fix
The local-node branch used an incomplete copy of the config-type map (omitted power/display/sessionkey/deviceui/serial/extnotif/storeforward/rangetest/cannedmsg/audio/remotehardware/ambientlighting/detectionsensor/paxcounter). A local-node GET of those configs returned
400 "Unknown config type". The full registry resolves it. (The remote branch already had the full map.)Deliberately left
protobufService.createSetDeviceConfigMessageGeneric's 5-entry map is a restricted "generic device encoder" allow-list (power/display/bluetooth/sessionkey/deviceui), semantically distinct from the device lookup map — unchanged to avoid widening what that encoder accepts.Tests
configTypes.test.ts:VALID_MODULE_CONFIG_TYPESentry must exist as a module in the registry — links the save allow-list to the encoder so Bug: Invalid module type errors for trafficmanagement and statusmessage configs #3464 can't recur.Validation
tsc --noEmit: cleanNext in section B: B2 (shared
createTestDbhelper to kill the hand-rolled per-backend test DDL).🤖 Generated with Claude Code