Skip to content

fix: try extensions for dotted basenames#155

Open
vibhor-aggr wants to merge 2 commits into
koajs:masterfrom
vibhor-aggr:fix/dotted-extension-fallback
Open

fix: try extensions for dotted basenames#155
vibhor-aggr wants to merge 2 commits into
koajs:masterfrom
vibhor-aggr:fix/dotted-extension-fallback

Conversation

@vibhor-aggr

@vibhor-aggr vibhor-aggr commented Jul 12, 2026

Copy link
Copy Markdown

Summary

  • try configured extensions when the exact requested path does not exist, including dotted basenames such as hello.world
  • add a regression fixture and test for dotted-basename extension fallback

Verification

  • npx jest test/index.test.ts --runInBand --testNamePattern='extensions option'
  • npm test
  • npm run lint
  • npm run build
  • git diff --check

Refs #143.

Summary by Sourcery

Handle extension fallback for files whose basenames contain dots and add regression coverage for this behavior.

Bug Fixes:

  • Fallback to configured extensions when the requested file path does not exist, including for dotted basenames like 'hello.world'.

Tests:

  • Add a regression test and fixture to verify extension fallback works for files with dotted basenames.

Summary by CodeRabbit

  • Bug Fixes
    • Improved extension-resolution when serving files: the decision to try filePath + ext now depends on whether the original path exists.
    • Fixed filesystem existence checking so missing files only return “not found” for ENOENT, while other access errors are surfaced.
  • Tests
    • Added/updated test cases covering extensions behavior for filenames containing dots (e.g., hello.world) and verified successful responses.
    • Updated test fixture content to support the new assertions.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e97da9ed-91ef-4f29-be94-10f5f471e12f

📥 Commits

Reviewing files that changed from the base of the PR and between a690ee7 and b502083.

📒 Files selected for processing (2)
  • src/send.utils.ts
  • test/index.test.ts

📝 Walkthrough

Walkthrough

Updated send() extension resolution to check whether the requested path exists before searching for configured extensions. Updated isPathExists to rethrow non-ENOENT errors, and added unit and integration coverage for error handling and dotted basenames.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the new extension fallback behavior for dotted basenames.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Extends the send() middleware's extension resolution logic to try configured extensions whenever the requested path doesn't exist (including dotted basenames), and adds a regression test plus fixture for this behavior.

Sequence diagram for updated send extension resolution

sequenceDiagram
  participant Client
  participant SendMiddleware as send
  participant FileSystem as isPathExists

  Client->>SendMiddleware: send(req, res, next)
  SendMiddleware->>FileSystem: isPathExists(filePath)
  FileSystem-->>SendMiddleware: exists / not exists
  alt [filePath does not exist]
    SendMiddleware->>SendMiddleware: for ext in extensions
    SendMiddleware->>FileSystem: isPathExists(filePath + ext)
    FileSystem-->>SendMiddleware: exists / not exists
  else [filePath exists]
    SendMiddleware->>SendMiddleware: skip extension fallback
  end
Loading

File-Level Changes

Change Details Files
Update extension resolution logic in send() to try extensions whenever the original path does not exist, including for dotted basenames.
  • Replace the basename-has-no-dot check with an existence check on the requested file path before applying extensions.
  • Iterate configured extensions when the original file path is missing, preserving existing behavior for type validation and resolution.
src/send.ts
Add regression test and fixture file to cover extension fallback for dotted basenames like hello.world.
  • Add a Jest test case to request a file path without an extension that maps to a dotted-basename fixture via the extensions option.
  • Introduce a new fixture file hello.world.txt to be served when the extension fallback is applied.
test/index.test.ts
test/fixtures/hello.world.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/index.test.ts (1)

693-707: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test correctly covers the dotted-basename fallback; minor grammar nitpick.

The test properly exercises the new behavior — requesting hello.world (which doesn't exist) with extensions: ['txt'] should resolve to hello.world.txt. The assertion matches the fixture content.

Minor: the describe text uses "sufficed" where "suffixed" is intended.

📝 Grammar fix
-    describe('when trying to get a file without extension with matching .extensions sufficed with a dot in the basename', () => {
+    describe('when trying to get a file without extension with matching .extensions suffixed with a dot in the basename', () => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/index.test.ts` around lines 693 - 707, Update the describe text in the
test covering the dotted-basename extension fallback to replace “sufficed” with
“suffixed”; leave the test setup and assertions unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/send.ts`:
- Line 82: Update isPathExists in send.utils.ts to return false only when
fs.access fails with ENOENT, and re-throw all other errors such as EACCES.
Preserve the existing extension-check flow in send.ts for genuinely missing
paths.

---

Nitpick comments:
In `@test/index.test.ts`:
- Around line 693-707: Update the describe text in the test covering the
dotted-basename extension fallback to replace “sufficed” with “suffixed”; leave
the test setup and assertions unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8623f851-3f11-44b3-9e85-965a01292d1f

📥 Commits

Reviewing files that changed from the base of the PR and between 09657fc and a690ee7.

📒 Files selected for processing (3)
  • src/send.ts
  • test/fixtures/hello.world.txt
  • test/index.test.ts

Comment thread src/send.ts
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