Files
ccs/tests/unit/cliproxy/proxy-detector-port.test.ts
T
kaitranntt e0a1f8f312 fix(cliproxy): add comprehensive port validation across proxy system
- Export validatePort() from config-generator with full edge case handling
- Add YAML port validation in proxy-config-resolver before use
- Add final port validation in cliproxy-executor after config merge
- Add default port parameter and validation to proxy-detector
- Add 38 new tests covering all port validation edge cases

Fixes undefined port bug when upgrading from 7.11.1 to 7.12.0
2026-01-01 02:00:30 -05:00

68 lines
2.4 KiB
TypeScript

/**
* Proxy Detector Port Validation Tests
*
* Tests for detectRunningProxy with invalid port inputs.
* Verifies the fix handles undefined, null, and invalid ports gracefully.
*/
import { describe, it, expect } from 'bun:test';
import { detectRunningProxy } from '../../../dist/cliproxy/proxy-detector';
import { CLIPROXY_DEFAULT_PORT } from '../../../dist/cliproxy/config-generator';
describe('Proxy Detector Port Validation', () => {
describe('detectRunningProxy with invalid ports', () => {
it('handles undefined port (uses default)', async () => {
// TypeScript allows this at runtime via any/unknown
const result = await detectRunningProxy(undefined as unknown as number);
// Should not throw, should use default port
expect(result).toBeDefined();
expect(typeof result.running).toBe('boolean');
});
it('handles NaN port (uses default)', async () => {
const result = await detectRunningProxy(NaN);
expect(result).toBeDefined();
expect(typeof result.running).toBe('boolean');
});
it('handles negative port (uses default)', async () => {
const result = await detectRunningProxy(-1);
expect(result).toBeDefined();
expect(typeof result.running).toBe('boolean');
});
it('handles zero port (uses default)', async () => {
const result = await detectRunningProxy(0);
expect(result).toBeDefined();
expect(typeof result.running).toBe('boolean');
});
it('handles port > 65535 (uses default)', async () => {
const result = await detectRunningProxy(70000);
expect(result).toBeDefined();
expect(typeof result.running).toBe('boolean');
});
it('handles valid port correctly', async () => {
const result = await detectRunningProxy(CLIPROXY_DEFAULT_PORT);
expect(result).toBeDefined();
expect(typeof result.running).toBe('boolean');
expect(typeof result.verified).toBe('boolean');
});
it('handles variant port correctly', async () => {
const result = await detectRunningProxy(8318);
expect(result).toBeDefined();
expect(typeof result.running).toBe('boolean');
});
});
describe('detectRunningProxy default parameter', () => {
it('works without port argument (uses default)', async () => {
const result = await detectRunningProxy();
expect(result).toBeDefined();
expect(typeof result.running).toBe('boolean');
});
});
});