From cb1d78bd9d5c157b3e27ab15631260fa515f527f Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Tue, 14 Apr 2026 13:58:30 -0400 Subject: [PATCH] test(tokens): isolate auth rotation from mocked handlers --- .../tokens-command-auth-rotation.test.ts | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/unit/commands/tokens-command-auth-rotation.test.ts b/tests/unit/commands/tokens-command-auth-rotation.test.ts index 8cb4679b..4c3e95aa 100644 --- a/tests/unit/commands/tokens-command-auth-rotation.test.ts +++ b/tests/unit/commands/tokens-command-auth-rotation.test.ts @@ -2,9 +2,22 @@ import { afterEach, beforeEach, describe, expect, it } from 'bun:test'; import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { getCliproxyConfigPath } from '../../../src/cliproxy'; -import { handleTokensCommand } from '../../../src/commands/tokens-command'; -import { getConfigYamlPath, loadUnifiedConfig } from '../../../src/config/unified-config-loader'; + +async function loadTokensCommand() { + return await import( + `../../../src/commands/tokens-command?test=${Date.now()}-${Math.random()}` + ); +} + +async function loadCliproxyModule() { + return await import(`../../../src/cliproxy?test=${Date.now()}-${Math.random()}`); +} + +async function loadUnifiedConfigModule() { + return await import( + `../../../src/config/unified-config-loader?test=${Date.now()}-${Math.random()}` + ); +} describe('tokens command auth rotation', () => { let tempHome = ''; @@ -47,6 +60,10 @@ describe('tokens command auth rotation', () => { }); it('applies api-key and regenerated secret in a single invocation', async () => { + const { handleTokensCommand } = await loadTokensCommand(); + const { getCliproxyConfigPath } = await loadCliproxyModule(); + const { loadUnifiedConfig } = await loadUnifiedConfigModule(); + const exitCode = await handleTokensCommand([ '--api-key', 'ccs-custom-key-123', @@ -70,6 +87,9 @@ describe('tokens command auth rotation', () => { }); it('rejects conflicting manual and generated secret flags', async () => { + const { handleTokensCommand } = await loadTokensCommand(); + const { getConfigYamlPath } = await loadUnifiedConfigModule(); + const exitCode = await handleTokensCommand([ '--secret', 'manual-secret',