Skip to content

fix(rig-bridge): tests no longer overwrite the real rig-bridge config - #1271

Merged
accius merged 1 commit into
accius:Stagingfrom
KoenVdH:fix/rig-bridge-tests-config-write
Nov 9, 2026
Merged

accius merged 1 commit into
accius:Stagingfrom
KoenVdH:fix/rig-bridge-tests-config-write

Conversation

@KoenVdH

@KoenVdH KoenVdH commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Problem

Running the test suite (npx vitest run) overwrote the developer's real ~/.config/openhamclock/rig-bridge-config.json with defaults: radio none, empty API token, serial port gone.

The cause is that plugins/brightness.js and plugins/aprs-tnc.js saved settings with require('../core/config').saveConfig(). That always writes the core config object to the real config path, whatever config the plugin was created with. The brightness tests in hardware-plugins.test.js create the plugin with their own config and change a setting, so each run replaced the user's file with the core defaults.

Fix

  • Plugins: brightness and aprs-tnc now use the saveConfig the core already passes to every plugin (services.saveConfig, rig-bridge.js), like gpio does. Without it they skip saving instead of falling back to the real file. Production behaviour is unchanged.
  • core/config.js: a new RIG_BRIDGE_CONFIG_DIR environment variable overrides the config location outright, with no legacy lookup or migration.
  • src/test/setup.js: sets RIG_BRIDGE_CONFIG_DIR to a temp dir for every test run, so even a future test that saves config can't reach the real file.

Tests

  • brightness: saves through the injected saveConfig only when a setting changes, and works without it.
  • aprs-tnc: setBeaconEnabled writes through to the config and saves through the injected saveConfig, and doesn't throw without it.
  • core/config.test.js: under test, CONFIG_DIR/CONFIG_PATH point at the temp dir, not ~/.config/openhamclock.

Verified

Full suite run with a scratch HOME: 310 files and 3,776 tests passed. Nothing was written to the scratch HOME, where the brightness test used to write. The real config file's checksum and modification time were unchanged. eslint and prettier are clean.

🤖 Generated with Claude Code

The brightness and APRS-TNC plugins saved settings with
require('../core/config').saveConfig(), which always writes the core config
object to ~/.config/openhamclock/rig-bridge-config.json. A test that created
the brightness plugin with its own config and changed a setting therefore
overwrote the user's real file with the defaults (radio none, empty token).

- brightness and aprs-tnc use the saveConfig the core passes to plugins
  (services.saveConfig), like gpio already does, and skip saving without it.
- core/config.js: RIG_BRIDGE_CONFIG_DIR overrides the config location
  outright (no legacy lookup or migration).
- src/test/setup.js points RIG_BRIDGE_CONFIG_DIR at a temp dir, so no test
  can reach the real file.
- Tests for the injected saves and the test config location.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@accius accius left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Koen. Good diagnosis: require('../core/config').saveConfig() always writes the core config object, so any plugin created with its own config overwrote the real file. Using the saveConfig the core already passes to plugins (rig-bridge.js line 86), and skipping the save without it, is the right fix. The RIG_BRIDGE_CONFIG_DIR setup guard is a nice extra layer.

I verified it on a machine that had been bitten. Test-merged onto current Staging, I ran the full suite including hardware-plugins.test.js (310 files, 3,775 tests pass). The real ~/.config/openhamclock/rig-bridge-config.json had the same modification time and SHA-1 before and after. Approving.

@accius
accius merged commit b45b9ff into accius:Staging Nov 9, 2026
8 checks passed
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.

2 participants