You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
97
97
+- Resolved runtime error `TypeError: vi.mocked(...).mockReturnValue is not a function` in `src/tests/server.test.ts` by directly casting `http.createServer` to `vi.Mock` and calling `mockReturnValue` on it, bypassing issues with `vi.mocked()`.
98
98
+- Fixed TypeScript error `TS2345` for `process.exit` mock in `src/tests/server.test.ts` by casting `vi.fn()` to the expected `(code?: number) => never` signature.
99
99
- Addressed TypeScript error `TS2345` concerning `http.Server` type compatibility in `src/tests/server.test.ts` by enhancing the `mockHttpServer` object with more properties common to `http.Server` and using a type assertion (`as unknown as http.Server`).
- Resolved ESLint warning `@typescript-eslint/no-empty-function` in `src/lib/server.ts` for `httpServerSetupReject` initialization by adding an `eslint-disable-next-line` comment, as this is a valid pattern for initializing promise reject functions.
102
+
- Addressed ESLint errors `@typescript-eslint/no-unsafe-assignment` and `@typescript-eslint/no-unsafe-member-access` related to `req.body.id` access in MCP error responses. Introduced a `RequestBodyWithId` interface and type-safe checks before accessing `req.body.id` to ensure `req.body` is an object and contains the `id` property.
- Resolved all ESLint errors in `src/tests/server.test.ts`.
102
105
- The primary fix involved ensuring that `eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion` directives are present and preserved before all `await importOriginal() as typeof import(...)` type assertions in mock factories. These assertions are essential for ESLint's subsequent type-checking rules (`no-unsafe-return`, `no-unsafe-assignment`) to function correctly, even if `tsc` alone might not strictly require the disable.
Copy file name to clipboardExpand all lines: RETROSPECTION.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -767,3 +767,24 @@
767
767
- Continue to use `eslint-disable-next-line @typescript-eslint/require-await` with justification for functions that are intentionally `async` without current `await` expressions for API consistency or future-proofing.
768
768
769
769
---
770
+
# Retrospection for ESLint Fixes (server.ts - Empty Function & Unsafe Access) (Git Commit ID: [GIT_COMMIT_ID_PLACEHOLDER])
771
+
772
+
## What went well?
773
+
- ESLint clearly identified the specific lines and rules causing the warnings and errors.
774
+
- The `no-empty-function` warning was correctly identified as a case where disabling the rule for a specific pattern (promise rejector initialization) is appropriate.
775
+
- The `no-unsafe-assignment` and `no-unsafe-member-access` errors highlighted a genuine type safety concern with accessing `req.body.id` without proper checks.
776
+
777
+
## What could be improved?
778
+
-**Type Safety for `req.body`:** While `express.json()` middleware parses the body, its type remains `any` by default. Consistently applying type guards or casting to a known interface (like `RequestBodyWithId`) for `req.body` access improves type safety throughout the Express route handlers.
779
+
-**ESLint Rule Configuration:** For `no-empty-function`, if this pattern of initializing promise rejectors is common, a more global ESLint configuration (e.g., allowing empty functions with specific names or in specific contexts) could be considered, though targeted disables are also fine.
780
+
781
+
## What did we learn?
782
+
-**`no-empty-function`:** This rule is generally useful but has valid exceptions, such as initializing placeholder functions that will be reassigned. `eslint-disable` is appropriate here.
783
+
-**`no-unsafe-assignment` / `no-unsafe-member-access`:** These rules are crucial for maintaining type safety when dealing with `any` types. Accessing properties on `req.body` (which is often `any` after middleware parsing) requires careful type checking or casting to a more specific type.
784
+
-**Type Guards/Checks for `req.body`:** Before accessing properties like `id` on `req.body`, it's important to verify that `req.body` is an object and actually contains the property. This prevents runtime errors and satisfies ESLint's safety rules.
785
+
786
+
## Action Items / Follow-ups
787
+
- Review other instances of `req.body` access in Express route handlers to ensure similar type safety measures (type guards or casting with checks) are applied.
788
+
- Consider if a project-wide helper type or type guard for Express request bodies that might contain an `id` would be beneficial for consistency.
0 commit comments