Expose plugin settings through the CommonJS Settings API - #8113
Expose plugin settings through the CommonJS Settings API#8113AkprasadoP wants to merge 1 commit into
Conversation
PR Summary by QodoResync CommonJS Settings exports after reload to expose ep_* plugin settings
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
Code Review by Qodo
1. Test leaks settings state
|
| } finally { | ||
| delete process.env[envKey]; | ||
| if (saved === undefined) { | ||
| delete settingsMod.ep_test_plugin; | ||
| } else { | ||
| settingsMod.ep_test_plugin = saved; |
There was a problem hiding this comment.
1. Test leaks settings state 🐞 Bug ☼ Reliability
The new regression test attempts to clean up by deleting settingsMod.ep_test_plugin, but that deletes the export property rather than reliably removing the backing settings key created by reloadSettings(). Because reloadSettings()/storeSettings() never clears keys absent from the loaded sources, ep_test_plugin can persist and contaminate subsequent tests; additionally, the env var is not restored if it previously existed.
Agent Prompt
### Issue description
The new test mutates `process.env` and the Settings singleton, but its cleanup is incomplete:
- It unconditionally `delete`s the env var instead of restoring any previous value.
- It `delete`s `settingsMod.ep_test_plugin` (an export property), which does not reliably restore the underlying `settings` object state created by `reloadSettings()`. Because `storeSettings()` never deletes missing keys, the plugin key can persist across the rest of the suite.
### Issue Context
`reloadSettings()` calls `storeSettings(settingsParsed)`/`storeSettings(credentials)` and those functions only iterate over keys present in the parsed objects; they do not remove old keys.
### Fix Focus Areas
- src/tests/backend/specs/settings.ts[154-187]
- src/node/utils/Settings.ts[962-990]
- src/node/utils/Settings.ts[1190-1195]
### Suggested fix pattern
- Save the original env value: `const originalEnv = process.env[envKey]; const hadEnv = Object.prototype.hasOwnProperty.call(process.env, envKey);`
- In `finally`, restore it: if (hadEnv) process.env[envKey] = originalEnv; else delete process.env[envKey];
- Restore/remove the backing key on the actual settings object (likely `settingsMod.default ?? settingsMod`):
- If it previously existed, set it back.
- If it didn’t, `delete (settingsMod.default ?? settingsMod).ep_test_plugin;`
- Then call `reloadSettings()`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Synchronize CommonJS Settings getters after each settings reload so plugin-specific ep_* hashes loaded from configuration are accessible directly to plugins.
232dccd to
e825afc
Compare
What
Synchronize the CommonJS Settings compatibility getters after settings are loaded or reloaded.
Why
Plugin-specific
ep_*settings hashes are added after the original one-time CJS mirror is created. Plugins using the documentedrequire('ep_etherpad-lite/node/utils/Settings')API therefore receiveundefinedfor their own configuration.Changes
reloadSettings().ep_*settings hash loaded through environment configuration.Fixes #8109
Tests
NODE_ENV=production npx mocha --import=tsx --timeout 120000 --extension ts tests/backend/specs/settings.tstsc --noEmitNote: ESLint could not be run locally due to the existing ESLint/package compatibility mismatch.