Skip to content

refactor(config): centralize config/module-type registry (section B1)#3497

Merged
Yeraze merged 1 commit into
mainfrom
refactor/b1-module-type-registry
Jun 16, 2026
Merged

refactor(config): centralize config/module-type registry (section B1)#3497
Yeraze merged 1 commit into
mainfrom
refactor/b1-module-type-registry

Conversation

@Yeraze

@Yeraze Yeraze commented Jun 16, 2026

Copy link
Copy Markdown
Owner

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 field maps were copy-pasted across server.ts (5 inline maps) and protobufService.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) → derived CONFIG_TYPE_MAP, MODULE_FIELD_BY_ID, DEVICE_FIELD_BY_ID.

Every duplicated site now derives from it:

  • protobufService.ts module-config encoder field map
  • server.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:

Validation

Next in section B: B2 (shared createTestDb helper to kill the hand-rolled per-backend test DDL).

🤖 Generated with Claude Code

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

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

Claude finished @Yeraze's task —— View job


PR Review: refactor(config): centralize config/module-type registry (section B1)

Tasks

  • Gather context and read changed files
  • Review code quality and best practices
  • Check for potential bugs or issues
  • Assess test coverage
  • Provide final feedback

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

statusmessage field inconsistency (configTypes.ts:62): The statusmessage module entry has field: 'statusmessage' (lowercase, no camelCase), while every other multi-word field uses camelCase (storeForward, cannedMessage, trafficManagement, etc.). If the protobuf field is actually statusMessage (camelCase), this would silently mismatch. Worth verifying against the protobuf definition — but this would be a pre-existing issue if so, not introduced by this PR.

Remaining switch cases in server.ts: The local-node and remote-node GET handlers still have large switch blocks with hardcoded case lists (case 'serial': case 'extnotif': ... at lines 7785–7806 and 7930–7944). The registry is now used for the lookup/validation step, but the fallthrough cases listing every module id are still duplicated. This is not a regression — those cases just fall through to a common config = remoteConfig or config = finalConfig.moduleConfig[moduleKey] — but it means adding a new config type still requires editing those switch blocks in addition to configTypes.ts. Could be a follow-up: replace the fallthrough switch with a registry-driven branch (since the MODULE_FIELD_BY_ID lookup is already happening above the switch in the local-node path at line 7799).

Code quality

CONFIG_TYPES is missing mqtt in the switch fallthrough at line 7785 of server.ts: The local-node module switch covers serial through trafficmanagement but omits mqtt. Since mqtt has its own dedicated handling earlier in the switch (line 7770ish), this is likely intentional, but it's worth confirming the mqtt case is actually handled before the fallthrough block.

DEVICE_FIELD_BY_ID is imported but barely used in server.ts: It's used once at line 7617 for the needsRequest check, but the large switch block below doesn't use it (it hardcodes the field names). Not a bug, but indicates the consolidation is partial for the GET path.

Tests

The test file is excellent:

One minor gap: the test asserts CONFIG_TYPE_MAP has correct values for a couple of spot-checks, but doesn't iterate all entries to verify the derived map is complete. Given the snapshot test covers CONFIG_TYPES exhaustively, this is a low-priority gap.

Summary

This 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 server.ts are pre-existing and out of scope for this PR. The one item worth double-checking before merge is the statusmessage field casing.


@Yeraze Yeraze merged commit cb03abe into main Jun 16, 2026
19 checks passed
@Yeraze Yeraze deleted the refactor/b1-module-type-registry branch June 16, 2026 19:11
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.

1 participant