test: isolate shared-state test suites for CI stability

- add dependency injection to export-command, binary-manager,
  codex-plan-compatibility, config-command, and usage-syncer
- override process.exit in api-export test to prevent silent
  termination in Bun's parallel test runner
- harden test-environment bootstrap with process.env isolation
- fix auth middleware to avoid config upgrade during checks
This commit is contained in:
Tam Nhu Tran committed 2026-03-25 16:41:41 -04:00
1 parent 58891d368d
commit 3af554275e
24 files changed
+764 -614

No files matched your search

@@ -1,62 +1,33 @@
import { afterEach, describe, expect, it, mock } from 'bun:test';
import { describe, expect, it } from 'bun:test';
import { CLIPROXY_DEFAULT_PORT } from '../../../src/cliproxy/config/port-manager';
type MockUnifiedConfig = {
cliproxy_server?: {
local?: {
port?: number;
};
};
};
function mockUnifiedConfig(config: MockUnifiedConfig): void {
mock.module('../../../src/config/unified-config-loader', () => ({
loadOrCreateUnifiedConfig: () => config,
}));
}
async function loadResolveLifecyclePort() {
const mod = await import(
`../../../src/commands/cliproxy/resolve-lifecycle-port?proxy-lifecycle-port=${Date.now()}-${Math.random()}`
);
return mod.resolveLifecyclePort;
}
import { resolveLifecyclePort } from '../../../src/commands/cliproxy/resolve-lifecycle-port';
describe('resolveLifecyclePort', () => {
afterEach(() => {
mock.restore();
});
it('uses configured cliproxy_server.local.port', async () => {
mockUnifiedConfig({
cliproxy_server: {
local: {
port: 9456,
it('uses configured cliproxy_server.local.port', () => {
expect(
resolveLifecyclePort({
cliproxy_server: {
local: {
port: 9456,
},
},
},
});
const resolveLifecyclePort = await loadResolveLifecyclePort();
expect(resolveLifecyclePort()).toBe(9456);
})
).toBe(9456);
});
it('falls back to default port when configured local port is invalid', async () => {
mockUnifiedConfig({
cliproxy_server: {
local: {
port: 70000,
it('falls back to default port when configured local port is invalid', () => {
expect(
resolveLifecyclePort({
cliproxy_server: {
local: {
port: 70000,
},
},
},
});
const resolveLifecyclePort = await loadResolveLifecyclePort();
expect(resolveLifecyclePort()).toBe(CLIPROXY_DEFAULT_PORT);
})
).toBe(CLIPROXY_DEFAULT_PORT);
});
it('falls back to default port when config file is missing', async () => {
mockUnifiedConfig({});
const resolveLifecyclePort = await loadResolveLifecyclePort();
expect(resolveLifecyclePort()).toBe(CLIPROXY_DEFAULT_PORT);
it('falls back to default port when config file is missing', () => {
expect(resolveLifecyclePort({})).toBe(CLIPROXY_DEFAULT_PORT);
});
});