fix(cliproxy): fix discoverExistingAccounts test failures

- Skip saving registry when no new accounts discovered (prevents empty
  accounts.json creation for invalid files)
- Skip merging empty provider sections to prevent empty provider entries
- Update test module cache clearing to include new modular submodules
  (accounts/registry, accounts/index) for proper test isolation
This commit is contained in:
kaitranntt committed 2026-02-05 15:09:47 -05:00
1 parent b149e252eb
commit 759f289119
2 files changed
+29 -3

No files matched your search

@@ -28,10 +28,18 @@ describe('Account Manager - discoverExistingAccounts', () => {
originalCcsHome = process.env.CCS_HOME;
process.env.CCS_HOME = testDir;
// Clear cache and reload
// Clear cache and reload - must clear all modular submodules too
delete require.cache[require.resolve('../../../dist/cliproxy/account-manager')];
delete require.cache[require.resolve('../../../dist/cliproxy/config-generator')];
delete require.cache[require.resolve('../../../dist/utils/config-manager')];
// Clear new modular structure (accounts/ and config/ submodules)
delete require.cache[require.resolve('../../../dist/cliproxy/accounts/index')];
delete require.cache[require.resolve('../../../dist/cliproxy/accounts/registry')];
delete require.cache[require.resolve('../../../dist/cliproxy/accounts/token-file-ops')];
delete require.cache[require.resolve('../../../dist/cliproxy/accounts/query')];
delete require.cache[require.resolve('../../../dist/cliproxy/accounts/types')];
delete require.cache[require.resolve('../../../dist/cliproxy/config/index')];
delete require.cache[require.resolve('../../../dist/cliproxy/config/path-resolver')];
accountManager = require('../../../dist/cliproxy/account-manager');
});
@@ -247,8 +255,10 @@ describe('Account Manager - discoverExistingAccounts', () => {
email: '',
});
// Reload module to clear in-memory cache
// Reload module to clear in-memory cache (including all submodules)
delete require.cache[require.resolve('../../../dist/cliproxy/account-manager')];
delete require.cache[require.resolve('../../../dist/cliproxy/accounts/index')];
delete require.cache[require.resolve('../../../dist/cliproxy/accounts/registry')];
accountManager = require('../../../dist/cliproxy/account-manager');
accountManager.discoverExistingAccounts();
@@ -329,8 +339,10 @@ describe('Account Manager - discoverExistingAccounts', () => {
email: '',
});
// Reload module to pick up pre-existing accounts.json
// Reload module to pick up pre-existing accounts.json (including all submodules)
delete require.cache[require.resolve('../../../dist/cliproxy/account-manager')];
delete require.cache[require.resolve('../../../dist/cliproxy/accounts/index')];
delete require.cache[require.resolve('../../../dist/cliproxy/accounts/registry')];
accountManager = require('../../../dist/cliproxy/account-manager');
accountManager.discoverExistingAccounts();