Skip to content

Commit 866eb33

Browse files
committed
test: Fix server error type and add explicit test typing
1 parent 87198fe commit 866eb33

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/lib/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ export async function startProxyServer(
16901690
// const tempServerForPortCheck = http.createServer(); // Not needed if findFreePort creates its own
16911691
proxyListenPort = await findFreePort(initialPortForProxySearch); // findFreePort internally creates server for checks
16921692
logger.info(`[PROXY_DEBUG] startProxyServer: Found free port ${proxyListenPort} for proxy.`);
1693-
} catch (error: unknown) { // Explicitly type error as unknown
1693+
} catch (error) { // Revert to 'any' or keep 'unknown' if preferred, but ensure catch block handles it.
16941694
const err = error instanceof Error ? error : new Error(String(error));
16951695
logger.error(`[ProxyServer] Failed to find free port for proxy: ${err.message}`, { errorDetails: err });
16961696
return null; // Return null if findFreePort fails

src/tests/index.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,6 @@ describe('CLI with yargs (index.ts)', () => {
568568
mockConsoleError.mockClear(); // Clear before run
569569

570570
await expect(runMainWithArgs(['agent_query', '{"query": "test"'])).rejects.toThrowError(
571-
// This error is thrown by handleClientCommand and then re-thrown by yargs.fail()
572571
new Error("Invalid JSON parameters: Expected ',' or '}' after property value in JSON at position 16")
573572
);
574573

@@ -661,7 +660,7 @@ describe('CLI with yargs (index.ts)', () => {
661660

662661
// Check if the SUT's yargs middleware logged the port being observed.
663662
const portLogFound = currentMockLoggerInstance.info.mock.calls.some(
664-
call => typeof call[0] === 'string' && call[0].includes(`[SUT_INDEX_TS_YARGS_MW] --port option value at middleware: ${customPort}`)
663+
(call: any) => typeof call[0] === 'string' && call[0].includes(`[SUT_INDEX_TS_YARGS_MW] --port option value at middleware: ${customPort}`)
665664
);
666665
expect(portLogFound, `Expected SUT log for --port middleware. Calls: ${JSON.stringify(currentMockLoggerInstance.info.mock.calls)}`).toBe(true);
667666

@@ -781,7 +780,7 @@ describe('CLI with yargs (index.ts)', () => {
781780
const expectedErrorPattern = /Unknown command: unknowncommand|You must provide a command to run|Not enough non-option arguments|Unknown argument: unknowncommand/;
782781
await expect(runMainWithArgs(['unknowncommand'])).rejects.toThrowError(expectedErrorPattern);
783782

784-
const consoleErrorCalls = mockConsoleError.mock.calls.map(call => call.join(' ')).join('\n');
783+
const consoleErrorCalls = mockConsoleError.mock.calls.map((call: any) => call.join(' ')).join('\n');
785784
// Check that help output was logged
786785
expect(consoleErrorCalls).toMatch(/Usage: codecompass <command> \[options\]/);
787786
// Check that the specific error message from yargs was logged by the .fail() handler's test mode path
@@ -800,7 +799,7 @@ describe('CLI with yargs (index.ts)', () => {
800799
const expectedErrorMsgPattern = /Unknown argument: --unknown-option|Unknown arguments: unknown-option, unknownOption/;
801800
await expect(runMainWithArgs(['start', '--unknown-option'])).rejects.toThrowError(expectedErrorMsgPattern);
802801

803-
const consoleErrorCalls = mockConsoleError.mock.calls.map(call => call.join(' ')).join('\n');
802+
const consoleErrorCalls = mockConsoleError.mock.calls.map((call: any) => call.join(' ')).join('\n');
804803
expect(consoleErrorCalls).toMatch(/Usage: codecompass <command> \[options\]/);
805804
// Check that the specific error message from yargs was logged by the .fail() handler's test mode path
806805
expect(consoleErrorCalls).toMatch(/YARGS_FAIL_TEST_MODE_ERROR_OUTPUT:.*(Unknown argument: --unknown-option|Unknown arguments: unknown-option, unknownOption)/s);
@@ -882,9 +881,6 @@ describe('CLI with yargs (index.ts)', () => {
882881
process.env.VITEST_TESTING_FAIL_HANDLER = "true";
883882
await expect(runMainWithArgs(['agent_query', '{"query":"test_json_rpc_error"}', '--json']))
884883
.rejects.toThrow(
885-
// The error thrown by yargs.fail() will be an Error instance.
886-
// If handleClientCommand throws an error with a jsonRpcError property,
887-
// yargs.fail() should re-throw that error object.
888884
expect.objectContaining({
889885
message: `Tool 'agent_query' failed: ${rpcErrorObject.message}`,
890886
jsonRpcError: rpcErrorObject,
@@ -907,7 +903,7 @@ describe('CLI with yargs (index.ts)', () => {
907903
)).toBe(true);
908904

909905
// yargs .fail() handler also logs
910-
const yargsFailOutputLogged = mockConsoleError.mock.calls.some(call =>
906+
const yargsFailOutputLogged = mockConsoleError.mock.calls.some((call: any) =>
911907
call[0] === 'YARGS_FAIL_TEST_MODE_ERROR_OUTPUT:' &&
912908
typeof call[1] === 'string' && call[1].includes(`Tool 'agent_query' failed: ${rpcErrorObject.message}`)
913909
);
@@ -936,7 +932,7 @@ describe('CLI with yargs (index.ts)', () => {
936932
expect(genericErrorJsonLogged, `Expected console.error to be called with: ${expectedJsonErrorLog}. Calls: ${JSON.stringify(mockConsoleError.mock.calls)}`).toBe(true);
937933

938934
// yargs .fail() handler also logs
939-
const yargsFailOutputLogged = mockConsoleError.mock.calls.some(call =>
935+
const yargsFailOutputLogged = mockConsoleError.mock.calls.some((call: any) =>
940936
call[0] === 'YARGS_FAIL_TEST_MODE_ERROR_OUTPUT:' &&
941937
typeof call[1] === 'string' && call[1] === genericError.message
942938
);

0 commit comments

Comments
 (0)