Skip to content

chore: add tests, prettier, pathalias #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2025
Merged

chore: add tests, prettier, pathalias #8

merged 2 commits into from
Jun 29, 2025

Conversation

DaxServer
Copy link
Contributor

@DaxServer DaxServer commented Jun 29, 2025

Summary by CodeRabbit

  • New Features

    • Added comprehensive unit tests for geocoding and reverse geocoding tools, as well as response handling logic.
    • Introduced a new script for code formatting and a Prettier configuration for consistent code style.
  • Chores

    • Updated CI workflows to use a fixed version of the Bun runtime for improved reliability.
    • Added a new workflow to automatically run tests on pull requests.
  • Style

    • Standardized import paths and quote usage across the codebase.
    • Reformatted schema definitions and configuration files for improved readability.
  • Documentation

    • Added JSON schema validation to Prettier configuration for clarity.

Copy link

coderabbitai bot commented Jun 29, 2025

"""

Walkthrough

This update introduces new and revised GitHub Actions workflows, pins the Bun runtime to version 1.2.17, and adds comprehensive test suites for geocoding tools. It establishes Prettier formatting with configuration and scripts, adopts path aliasing in TypeScript, and standardizes import styles and string delimiters throughout the codebase.

Changes

Files/Groups Change Summary
.github/workflows/lint.yml, release.yml Pin Bun setup to version 1.2.17 instead of "latest" for consistent CI environments; update lint job commands and dependency install flags.
.github/workflows/test.yml Add new workflow to run tests on pull requests using Bun 1.2.17, including steps for checkout, dependency install with frozen lockfile, and executing test suite.
package.json, prettier.config.ts Add Prettier as a dev dependency and formatting script; introduce Prettier config specifying formatting rules and schema validation.
tsconfig.json Add TypeScript path aliases (@/) for simplified absolute imports from src/.
src/clients/nominatimClient.ts, src/tools/geocode.ts, src/tools/reverseGeocode.ts, src/index.ts Refactor import paths to use path aliases and single quotes; update string literals to single quotes for consistency; minor formatting adjustments including console method changes.
src/types/commonTypes.ts, src/types/geocodeTypes.ts, src/types/reverseGeocodeTypes.ts Reformat schema definitions for readability; switch to single quotes in imports and code; update import paths to use aliases.
src/tools/prepareResponse.ts Standardize string delimiters to single quotes; reformat return object for clarity.
src/clients/tests/nominatimClient.test.ts Add new test file with skipped tests for axios-based functions and a working test for User-Agent string formation.
src/tools/tests/geocode.test.ts, src/tools/tests/reverseGeocode.test.ts Add comprehensive unit tests for geocode and reverse geocode tool registration, handler logic, and error propagation using mocked dependencies.
src/tools/tests/prepareResponse.test.ts Add tests for handleGeocodeResult, verifying correct responses for various input scenarios and error handling.
eslint.config.js Reformat ESLint config export to single-line object and array syntax; convert quoted rule keys to unquoted identifiers without changing configuration content.
src/clients/nominatimClient.ts Change import paths to aliases; reformat condenseOutput function to multi-line arrow function with same logic.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub Actions
    participant Bun
    participant Test Suite

    Developer->>GitHub Actions: Push or PR triggers workflows
    GitHub Actions->>Bun: Setup Bun v1.2.17
    GitHub Actions->>GitHub Actions: Checkout code
    GitHub Actions->>GitHub Actions: Install dependencies (bun install --frozen-lockfile)
    GitHub Actions->>Test Suite: Run tests (bun test)
    Test Suite-->>GitHub Actions: Report results
    GitHub Actions-->>Developer: Show CI status
Loading

Possibly related PRs

  • geocoding-ai/mcp#1: Both PRs modify GitHub Actions workflows, but this PR focuses on initializing the server and workflows, while the main PR here fixes Bun versions and adds formatting and testing setup.

Poem

A rabbit hops with Bun in tow,
Pinning versions—steady flow!
Prettier scripts now keep things neat,
Path aliases make imports sweet.
With tests that check each tool and type,
This codebase shines—oh, what a sight!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32c81df and 9ba8f68.

📒 Files selected for processing (6)
  • .github/workflows/lint.yml (1 hunks)
  • .github/workflows/test.yml (1 hunks)
  • eslint.config.js (1 hunks)
  • src/clients/__tests__/nominatimClient.test.ts (1 hunks)
  • src/clients/nominatimClient.ts (2 hunks)
  • src/index.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • eslint.config.js
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/index.ts
  • .github/workflows/lint.yml
  • src/clients/nominatimClient.ts
  • src/clients/tests/nominatimClient.test.ts
  • .github/workflows/test.yml
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (8)
.github/workflows/test.yml (1)

14-23: Optional: add dependency caching to speed up CI

bun install re-downloads the store on every run. A small actions/cache step (keyed by bun.lockb) shaves ~30-40 s off each PR run.

      - name: Setup Bun
        uses: oven-sh/setup-bun@v2
        with:
          bun-version: 1.2.17
+
+     - name: Cache Bun dependencies
+       uses: actions/cache@v4
+       with:
+         path: ~/.bun/install/cache
+         key: bun-${{ hashFiles('bun.lockb') }}
+         restore-keys: |
+           bun-

[nice_to_have]

.github/workflows/lint.yml (1)

14-20: Keep the Bun setup action consistent & freeze the lock-file

Two tiny inconsistencies with the other workflows:

  1. oven-sh/setup-bun is still on v1 here.
  2. bun install runs without --frozen-lockfile, so CI could silently mutate bun.lockb.
-      - name: Setup Bun
-        uses: oven-sh/setup-bun@v1
+      - name: Setup Bun
+        uses: oven-sh/setup-bun@v2
...
-      - name: Install dependencies
-        run: bun install
+      - name: Install dependencies
+        run: bun install --frozen-lockfile
package.json (1)

37-47: Formatting script: broaden the glob or run prettier on staged files

"prettier --write \"**/*.ts\"" skips .tsx, .js, .json, etc.
If you intend full-repo formatting, consider:

-    "format": "prettier --write \"**/*.ts\"",
+    "format": "prettier --write .",

or add a separate format:check script for CI (--check).

src/index.ts (1)

21-21: Consider downgrading this to informational logging

console.error is generally reserved for errors; here it’s used for a healthy startup message.
Using console.log (or a dedicated logger at “info” level) keeps stderr clean for real failures, which matters when other processes consume stdout/stderr separately.

src/clients/__tests__/nominatimClient.test.ts (3)

2-2: Consider using a more conventional path for package.json import.

The import path @/../package.json is unusual. Consider using a direct relative path ../../package.json or configuring the path alias to point directly to the project root.

-import packageJson from '@/../package.json' with { type: 'json' }
+import packageJson from '../../package.json' with { type: 'json' }

14-32: Document the testing strategy for skipped axios-dependent tests.

The skipped tests are well documented, but consider adding a TODO or issue reference to track when these tests should be re-enabled once axios mocking is resolved.

Would you like me to help create an issue to track implementing these skipped tests or explore alternative mocking strategies for axios with Bun?


35-44: Enhance User-Agent test to verify actual usage.

The current test only verifies string construction but doesn't test that the User-Agent header is actually set in HTTP requests. Consider testing the integration with axios configuration.

Consider adding a test that verifies the User-Agent is properly configured in the axios instance:

 describe('User-Agent', () => {
   it('should correctly form User-Agent string based on package.json', () => {
     const expectedUserAgent = `GeocodingMCP github.com/geocoding-ai/mcp ${packageJson.version}`
-    // This test primarily verifies the construction of the USER_AGENT string itself.
-    // The actual header being set by axios relies on axios's internal mechanisms.
     expect(expectedUserAgent).toContain(
       'GeocodingMCP github.com/geocoding-ai/mcp',
     )
     expect(expectedUserAgent).toContain(packageJson.version)
   })
+
+  // TODO: Add test to verify User-Agent header is set in axios requests
+  // when axios mocking is resolved
 })
src/tools/__tests__/reverseGeocode.test.ts (1)

27-39: Consider removing unnecessary geocodeAddress mock.

The mock for geocodeAddress on lines 29-31 appears to be precautionary but may not be necessary since this test file only focuses on reverse geocoding functionality.

 // Mock only nominatimClient
 mock.module('@/clients/nominatimClient.js', () => ({
-  // Also mock geocodeAddress to avoid interference if it's imported by other modules under test
-  geocodeAddress: mock(async (params: any) => [
-    { place_id: 999, display_name: `Geocode mock for ${params.query}` },
-  ]),
   reverseGeocode: mock(async (params: ReverseGeocodeParams) => {
     // Default successful mock implementation
     return {
       place_id: 456,
       display_name: `Address for ${params.lat},${params.lon}`,
     }
   }),
 }))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d39b60d and 32c81df.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • .github/workflows/lint.yml (1 hunks)
  • .github/workflows/release.yml (1 hunks)
  • .github/workflows/test.yml (1 hunks)
  • package.json (2 hunks)
  • prettier.config.ts (1 hunks)
  • src/clients/__tests__/nominatimClient.test.ts (1 hunks)
  • src/clients/nominatimClient.ts (2 hunks)
  • src/index.ts (2 hunks)
  • src/tools/__tests__/geocode.test.ts (1 hunks)
  • src/tools/__tests__/prepareResponse.test.ts (1 hunks)
  • src/tools/__tests__/reverseGeocode.test.ts (1 hunks)
  • src/tools/geocode.ts (1 hunks)
  • src/tools/prepareResponse.ts (2 hunks)
  • src/tools/reverseGeocode.ts (1 hunks)
  • src/types/commonTypes.ts (1 hunks)
  • src/types/geocodeTypes.ts (2 hunks)
  • src/types/reverseGeocodeTypes.ts (2 hunks)
  • tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/tools/__tests__/prepareResponse.test.ts (1)
src/tools/prepareResponse.ts (1)
  • handleGeocodeResult (3-24)
src/tools/__tests__/geocode.test.ts (3)
src/types/geocodeTypes.ts (1)
  • GeocodeParams (12-12)
src/tools/geocode.ts (1)
  • registerGeocodeTool (9-54)
src/tools/prepareResponse.ts (1)
  • handleGeocodeResult (3-24)
🔇 Additional comments (18)
.github/workflows/release.yml (1)

19-23: Bun version pin is 👍 — consider aligning the action major version across all workflows

You’re using oven-sh/setup-bun@v2 here, while .github/workflows/lint.yml is still on @v1. Keeping the same major tag everywhere avoids surprises when v1/v2 diverge in behaviour or cache keys.
[ suggest_nitpick ]

tsconfig.json (1)

27-32: Path-alias config looks good

baseUrl + @/* mapping is correct and plays nicely with moduleResolution: "NodeNext". No issues spotted.

src/index.ts (1)

3-6: Ensure runtime resolver knows the @/ alias

The switch from relative paths to @/… relies on a custom path-mapping in tsconfig.json.
Make sure the same mapping is honoured at runtime (e.g. ts-node with tsconfig-paths, Bun’s loader, or a bundler). Otherwise Node will fail to resolve these *.js imports after transpilation.

src/types/geocodeTypes.ts (1)

1-2: Alias import looks good

Imports align with the new path-alias convention and compile-time schema typing remains intact.

src/types/reverseGeocodeTypes.ts (1)

1-2: Consistent alias usage acknowledged

Change mirrors the pattern in geocodeTypes.ts; no issues spotted.

src/tools/reverseGeocode.ts (1)

1-7: Double-check tree-shaking & circular-import safety

Moving to absolute aliases is fine, but keep an eye on possible circular references between @/tools/* and @/types/* once everything compiles to dist.
If you hit odd runtime undefined values, a quick madge --circular dist can confirm.

src/tools/geocode.ts (1)

1-7: No functional change – implementation remains sound

The alias/import refactor compiles cleanly, and the handler logic is untouched.

src/tools/prepareResponse.ts (1)

1-24: LGTM! Formatting improvements align with Prettier configuration.

The consistent use of single quotes and multi-line object formatting enhances readability while maintaining the same functionality.

src/clients/nominatimClient.ts (2)

2-4: Excellent adoption of path aliases for cleaner imports.

The transition from relative paths to @/ aliases improves maintainability and makes the import structure more consistent across the codebase.


15-16: Good formatting improvement for readability.

The multi-line arrow function format enhances readability while preserving the same destructuring and mapping logic.

src/types/commonTypes.ts (1)

1-37: Excellent formatting improvements for complex schema readability.

The multi-line formatting of the Zod schema significantly improves readability and makes individual field configurations easier to understand and maintain.

prettier.config.ts (1)

1-19: Well-configured Prettier setup with sensible defaults.

The configuration appropriately enforces consistent formatting across the codebase with TypeScript-specific settings and a practical override for declaration files.

src/tools/__tests__/prepareResponse.test.ts (1)

1-106: Excellent comprehensive test coverage with clear understanding of implementation behavior.

The test suite thoroughly covers all major scenarios including edge cases. The circular reference test (lines 60-79) demonstrates good understanding of the implementation logic - correctly identifying that non-array objects hit the validation check before JSON serialization.

src/tools/__tests__/geocode.test.ts (3)

12-26: Well-structured mocking approach for McpServer.

The mock implementation correctly captures the handler function for testing while maintaining the expected interface.


65-85: Excellent integration test using actual handleGeocodeResult.

This test effectively verifies the integration between the tool handler and the response processing function while maintaining proper isolation through mocking.


108-128: Correct error handling test implementation.

The test properly verifies that errors from the geocoding client propagate through the handler, which aligns with the expected behavior where handleGeocodeResult is not called when geocodeAddress throws an error.

src/tools/__tests__/reverseGeocode.test.ts (2)

67-89: Excellent test coverage for successful reverse geocoding.

The test properly verifies the integration between the tool handler and the actual handleGeocodeResult function while ensuring the client is called with correct parameters.


112-128: Consistent error handling pattern with geocode tests.

The error propagation test correctly follows the same pattern as the geocode tests, ensuring consistent behavior across both tools.

@DaxServer DaxServer merged commit 5920191 into main Jun 29, 2025
3 checks passed
@DaxServer DaxServer deleted the tests-pathaliases branch June 29, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant