mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-03 04:17:54 +00:00
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:
@@ -63,9 +63,6 @@ describe('config-loader-facade', () => {
|
|||||||
|
|
||||||
expect(typeof facade.loadUnifiedConfig).toBe('function');
|
expect(typeof facade.loadUnifiedConfig).toBe('function');
|
||||||
expect(typeof facade.loadOrCreateUnifiedConfig).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 () => {
|
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', () => {
|
describe('memoization', () => {
|
||||||
it('getCachedConfig returns equivalent config on repeated calls', async () => {
|
it('getCachedConfig returns equivalent config on repeated calls', async () => {
|
||||||
const facade = await importFacade();
|
const facade = await importFacade();
|
||||||
|
|||||||
@@ -2,21 +2,23 @@
|
|||||||
* Config Loader Facade
|
* Config Loader Facade
|
||||||
*
|
*
|
||||||
* Single import path for all config loading operations.
|
* Single import path for all config loading operations.
|
||||||
* Re-exports everything from unified-config-loader and config-manager,
|
* Re-exports read-only functions from unified-config-loader and config-manager,
|
||||||
* and adds memoization for loadOrCreateUnifiedConfig to reduce file I/O.
|
* 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:
|
* Usage:
|
||||||
* import { getCachedConfig, saveConfig, mutateConfig } from '../config/config-loader-facade';
|
* import { getCachedConfig, saveConfig, mutateConfig } from '../config/config-loader-facade';
|
||||||
* import { getCcsDir, loadSettings } 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 {
|
export {
|
||||||
loadUnifiedConfig,
|
loadUnifiedConfig,
|
||||||
loadOrCreateUnifiedConfig,
|
loadOrCreateUnifiedConfig,
|
||||||
saveUnifiedConfig,
|
|
||||||
mutateUnifiedConfig,
|
|
||||||
updateUnifiedConfig,
|
|
||||||
getConfigYamlPath,
|
getConfigYamlPath,
|
||||||
getConfigJsonPath,
|
getConfigJsonPath,
|
||||||
hasUnifiedConfig,
|
hasUnifiedConfig,
|
||||||
|
|||||||
Reference in New Issue
Block a user