fix: remove raw write re-exports from facade (cache bypass)

PR-Agent #1150 review flagged that re-exporting
saveUnifiedConfig/mutateUnifiedConfig/updateUnifiedConfig
allows callers to bypass the cache. Only export the
cache-coherent wrappers (saveConfig/mutateConfig/updateConfig).
Raw functions still available via direct import from
unified-config-loader if needed.

- Remove raw write re-exports from facade
- Add test verifying raw writes are NOT exported
- Add test verifying cache-coherent wrappers ARE exported
This commit is contained in:
Tam Nhu Tran
2026-04-30 15:37:17 -04:00
parent b8ed36e370
commit 6d266fc7e8
2 changed files with 26 additions and 9 deletions
@@ -63,9 +63,6 @@ describe('config-loader-facade', () => {
expect(typeof facade.loadUnifiedConfig).toBe('function');
expect(typeof facade.loadOrCreateUnifiedConfig).toBe('function');
expect(typeof facade.saveUnifiedConfig).toBe('function');
expect(typeof facade.mutateUnifiedConfig).toBe('function');
expect(typeof facade.updateUnifiedConfig).toBe('function');
});
it('should export all path/format utilities', async () => {
@@ -115,6 +112,24 @@ describe('config-loader-facade', () => {
});
});
describe('cache coherence', () => {
it('should NOT export raw write functions that bypass cache', async () => {
const facade = (await importFacade()) as Record<string, unknown>;
expect(facade.saveUnifiedConfig).toBeUndefined();
expect(facade.mutateUnifiedConfig).toBeUndefined();
expect(facade.updateUnifiedConfig).toBeUndefined();
});
it('should export cache-coherent write wrappers instead', async () => {
const facade = await importFacade();
expect(typeof facade.saveConfig).toBe('function');
expect(typeof facade.mutateConfig).toBe('function');
expect(typeof facade.updateConfig).toBe('function');
});
});
describe('memoization', () => {
it('getCachedConfig returns equivalent config on repeated calls', async () => {
const facade = await importFacade();
+8 -6
View File
@@ -2,21 +2,23 @@
* Config Loader Facade
*
* Single import path for all config loading operations.
* Re-exports everything from unified-config-loader and config-manager,
* and adds memoization for loadOrCreateUnifiedConfig to reduce file I/O.
* Re-exports read-only functions from unified-config-loader and config-manager,
* and provides cache-coherent write wrappers that keep the memoization cache in sync.
*
* IMPORTANT: Raw write functions (saveUnifiedConfig, mutateUnifiedConfig,
* updateUnifiedConfig) are NOT re-exported here. Use the cache-coherent
* wrappers (saveConfig, mutateConfig, updateConfig) instead. If you need
* the raw functions, import directly from './unified-config-loader'.
*
* Usage:
* import { getCachedConfig, saveConfig, mutateConfig } from '../config/config-loader-facade';
* import { getCcsDir, loadSettings } from '../config/config-loader-facade';
*/
// Re-export all functions from unified-config-loader
// Re-export read-only functions from unified-config-loader
export {
loadUnifiedConfig,
loadOrCreateUnifiedConfig,
saveUnifiedConfig,
mutateUnifiedConfig,
updateUnifiedConfig,
getConfigYamlPath,
getConfigJsonPath,
hasUnifiedConfig,