Skip to content

Commit 41177b0

Browse files
committed
fix: Update EADDRINUSE non-CC server log test assertion
1 parent 735a447 commit 41177b0

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
## [Unreleased]
1515
### Fixed
16-
- **Unit Test Fix (server.test.ts - EADDRINUSE Non-CodeCompass Server Log Assertions) (Git Commit ID: 2c47648):**
17-
- Corrected failing assertions in `src/tests/server.test.ts` for the test case "should handle EADDRINUSE, detect a non-CodeCompass server, log error, and exit with 1".
18-
- Updated `ml.error` (mocked logger error method) assertions to use `toHaveBeenNthCalledWith` and match the precise sequence and content of the three distinct error messages logged in this scenario, resolving the `AssertionError: expected "spy" to be called with arguments: [ StringContaining{…} ]` failure.
16+
- **Unit Test Fix (server.test.ts - EADDRINUSE Non-CodeCompass Server Log Assertions) (Git Commit ID: [GIT_COMMIT_ID_PLACEHOLDER]):**
17+
- Corrected a failing assertion in `src/tests/server.test.ts` for the test case "should handle EADDRINUSE, detect a non-CodeCompass server, log error, and exit with 1".
18+
- The first call to `ml.error` (mocked logger error method) was updated to `expect.stringContaining(\`Port \${mcs.HTTP_PORT} is in use by non-CodeCompass server. Response: {"service":"OtherService"}\`)` to precisely match the actual logged message. This resolved the `AssertionError: expected 1st "spy" call to have been called with [ StringContaining{…} ]` failure.
19+
- This fix supersedes parts of the previous fix under Git Commit ID `2c47648` related to this specific log message.
1920
- **Server Logic Restoration & Linting (Git Commit ID: [GIT_COMMIT_ID_PLACEHOLDER]):**
2021
- Resolved ESLint warnings (`@typescript-eslint/no-unused-vars`) for `StreamableHTTPServerTransport`, `randomUUID`, `isInitializeRequest`, and `configureMcpServerInstance` in `src/lib/server.ts`.
2122
- The fix involved restoring the complete and correct implementation of the `startServer` function, ensuring it properly sets up the Express HTTP server and MCP routes, thereby utilizing these previously flagged components. This addresses an issue where essential logic might have been inadvertently removed or disconnected during prior refactoring.

RETROSPECTION.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
# Retrospection for Unit Test Fix (server.test.ts - EADDRINUSE Non-CodeCompass Server Log Assertions) (Git Commit ID: [GIT_COMMIT_ID_PLACEHOLDER])
2222

2323
## What went well?
24-
- The detailed failure output from Vitest, showing all calls to the mocked `ml.error` function, was instrumental in understanding the discrepancy and formulating the correct assertions.
25-
- The fix involved making the test assertions more precise, which improves test reliability.
24+
- The detailed failure output from Vitest, showing the exact string received by the mocked `ml.error` function, made it straightforward to identify the mismatch in the assertion.
25+
- The fix was a minor but crucial adjustment to the expected substring in `expect.stringContaining`.
2626

2727
## What could be improved?
28-
- **Initial Assertion Granularity:** The original assertion for `ml.error` was too broad. When a function is expected to be called multiple times with different arguments, assertions should ideally verify each call specifically or use matchers that accommodate the variations if a single assertion is intended to cover multiple calls (though the latter is less precise).
29-
- **Log Message Stability:** While not an issue here, if log messages change frequently, tests asserting their exact content can become brittle. Using `expect.stringContaining` for key phrases is a good balance, but the overall sequence of logs still needs to be stable for `toHaveBeenNthCalledWith`.
28+
- **Log Message Precision in Tests:** When asserting parts of log messages, especially error messages that might have specific phrasing, ensuring the test expectation exactly matches a portion of the actual log is critical. A slight wording difference can cause test failures.
29+
- **Review of Log Messages:** The log message itself ("Port ... is in use by non-CodeCompass server...") is clear. The test just needed to align with it.
3030

3131
## What did we learn?
32-
- When testing functions that log multiple distinct messages (especially error messages in different phases of handling an error), it's important to assert each log call accurately.
33-
- Vitest's `toHaveBeenNthCalledWith` is very useful for verifying the arguments of specific calls in a sequence.
34-
- Detailed mock call reporting in test runner output is invaluable for debugging assertion failures.
32+
- `expect.stringContaining` is a powerful tool, but the substring provided must accurately reflect a part of the actual string.
33+
- Even minor phrasing differences between expected and actual log messages will cause assertion failures.
34+
- Test output that shows the "Received" value is essential for debugging such discrepancies.
3535

3636
## Action Items / Follow-ups
37-
- When writing tests that assert log outputs, if multiple log calls are expected, use specific assertions for each call (e.g., `toHaveBeenNthCalledWith`) rather than a single, broad assertion, to improve test precision and debuggability.
38-
- Review other tests that assert multiple log calls to ensure they are using precise assertions.
37+
- When a test asserting a log message with `stringContaining` fails, carefully compare the expected substring with the actual logged message provided in the test runner's output to find the exact point of divergence.
38+
- This fix supersedes the previous attempt (Git Commit ID `2c47648`) for this specific log message assertion, highlighting the iterative nature of test refinement.
3939

4040
---
4141
# Retrospection for Unit Test Fix (server.test.ts - Incorrect Assertion) (Git Commit ID: [GIT_COMMIT_ID_PLACEHOLDER])

src/tests/server.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ describe('Server Startup and Port Handling', () => {
567567
);
568568

569569
// Verify the specific error log calls in order
570-
expect(ml.error).toHaveBeenNthCalledWith(1, expect.stringContaining(`Port ${mcs.HTTP_PORT} is in use, but it does not appear to be a CodeCompass server. Response: {"service":"OtherService"}`));
570+
expect(ml.error).toHaveBeenNthCalledWith(1, expect.stringContaining(`Port ${mcs.HTTP_PORT} is in use by non-CodeCompass server. Response: {"service":"OtherService"}`));
571571
expect(ml.error).toHaveBeenNthCalledWith(2, expect.stringContaining('Please free the port or configure a different one'));
572572
expect(ml.error).toHaveBeenNthCalledWith(3, "Failed to start CodeCompass", expect.objectContaining({ message: `Port ${mcs.HTTP_PORT} in use by non-CodeCompass server.` }));
573573

0 commit comments

Comments
 (0)