Skip to content

fix: handle http.FS() and import naming conflicts in filesystem migration#268

Merged
ReneWerner87 merged 1 commit intogofiber:masterfrom
CybotTM:fix/filesystem-migration-bugs
Feb 5, 2026
Merged

fix: handle http.FS() and import naming conflicts in filesystem migration#268
ReneWerner87 merged 1 commit intogofiber:masterfrom
CybotTM:fix/filesystem-migration-bugs

Conversation

@CybotTM
Copy link
Contributor

@CybotTM CybotTM commented Feb 5, 2026

Summary

Fixes two bugs in the filesystem middleware migration to static middleware:

  • Bug 1: http.FS() not handled correctly - When Root: http.FS(embedFS) was used, it fell through to the generic Root: pattern and got wrapped with os.DirFS(), producing invalid code like os.DirFS(http.FS(embedFS)). Now http.FS() is recognized and the inner value is extracted directly since embed.FS already implements fs.FS.

  • Bug 2: Import naming conflict - When users had their own package named "static" (e.g., internal/web/static), the migration would add the middleware import without aliasing, causing a naming conflict. Now the migration detects existing "static" imports and aliases the middleware import to staticmw when needed.

Fixes #267

Test plan

  • Added Test_MigrateFilesystemMiddleware_WithHTTPFS - verifies http.FS(embedFS) produces FS: embedFS
  • Added Test_MigrateFilesystemMiddleware_WithStaticPackageConflict - verifies middleware import is aliased when there's a conflicting static package
  • Added Test_MigrateFilesystemMiddleware_WithAliasedStaticImport - verifies no aliasing needed when user's import is already aliased
  • Added Test_MigrateFilesystemMiddleware_IssueExample - tests the exact scenario from the issue
  • All existing tests still pass

Summary by CodeRabbit

  • Bug Fixes

    • Prevent import-name collisions during filesystem migration by dynamically aliasing middleware imports.
    • Correctly convert various filesystem configurations (http.Dir / http.FS) to the new FS forms and avoid unnecessary os.DirFS wrappers.
    • Defer NotFoundFile migration with a TODO note.
  • Tests

    • Added comprehensive tests covering embedded filesystems, aliased/non-aliased imports, conflict scenarios, and combined regressions.

@CybotTM CybotTM requested a review from a team as a code owner February 5, 2026 07:54
@CybotTM CybotTM requested review from ReneWerner87, efectn, gaby and sixcolors and removed request for a team February 5, 2026 07:54
@ReneWerner87 ReneWerner87 added the ☢️ Bug Something isn't working label Feb 5, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @CybotTM, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses two critical bugs in the filesystem middleware migration to the new static middleware. It ensures that http.FS() configurations are correctly translated without redundant wrapping and resolves potential import naming conflicts when users have their own packages named "static". These fixes enhance the reliability and correctness of the migration process for Fiber applications.

Highlights

  • http.FS() Migration: The migration now correctly handles Root: http.FS(embedFS) by directly extracting embedFS as the FS value, avoiding incorrect wrapping with os.DirFS().
  • Import Naming Conflict Resolution: The migration tool now detects existing user packages named "static" and automatically aliases the fiber/v3/middleware/static import to staticmw to prevent naming conflicts.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • cmd/internal/migrations/v3/filesystem_middleware.go
    • Introduced new regular expressions (reFilesystemRootHTTPFS, reStaticImport) to specifically match http.FS() usage and conflicting "static" imports.
    • Added a staticMiddlewarePkg function to dynamically determine the appropriate package name for the static middleware import, applying an alias (staticmw) if a conflict is detected.
    • Updated the import replacement logic to conditionally use the determined package name or its alias.
    • Modified the filesystem.New and filesystem.Config replacements to use the dynamically determined package name.
    • Implemented dedicated logic to correctly extract the inner fs.FS value from http.FS() expressions.
    • Adjusted the order of Root pattern matching to ensure http.FS() and http.Dir() are handled before the generic Root pattern.
  • cmd/internal/migrations/v3/filesystem_middleware_test.go
    • Added Test_MigrateFilesystemMiddleware_WithHTTPFS to verify the correct migration of http.FS() configurations.
    • Added Test_MigrateFilesystemMiddleware_WithStaticPackageConflict to confirm that the static middleware import is aliased when a user-defined "static" package exists.
    • Added Test_MigrateFilesystemMiddleware_WithAliasedStaticImport to ensure the migration behaves correctly when the user's "static" import is already aliased.
    • Added Test_MigrateFilesystemMiddleware_IssueExample to validate the fixes against the specific scenario reported in issue 🐛 fiber migrate produces invalid code for filesystem middleware migration #267, covering both bug types.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses two bugs in the filesystem middleware migration: incorrect handling of http.FS() and import naming conflicts with user packages named static. The introduction of new regexes and logic to handle these cases, along with comprehensive new tests, significantly improves the robustness of the migration script. I have a few suggestions to further improve the robustness by handling an edge case with dot imports and ensuring consistency in the import path replacement logic.

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

Warning

Rate limit exceeded

@CybotTM has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 43 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4fcab83 and aefabda.

📒 Files selected for processing (2)
  • cmd/internal/migrations/v3/filesystem_middleware.go
  • cmd/internal/migrations/v3/filesystem_middleware_test.go

Walkthrough

Adds dynamic import-alias detection and transforms for migrating v2 filesystem middleware to v3 static middleware, converting Root: usages to appropriate FS: forms and updating import/constructor references; expands tests covering alias conflicts and embed/fs handling.

Changes

Cohort / File(s) Summary
Filesystem middleware migration logic
cmd/internal/migrations/v3/filesystem_middleware.go
Chooses middleware package alias (static or staticmw) based on existing imports; adds regexes to convert Root: http.Dir(...)FS: os.DirFS(...), Root: http.FS(...)FS: <inner>, and a fallback Root→FS conversion; rewrites imports/constructors to use chosen alias; comments out NotFoundFile migration with TODO.
Filesystem middleware tests
cmd/internal/migrations/v3/filesystem_middleware_test.go
Adds tests validating: embed fs.FS is used directly (no os.DirFS(http.FS(...))), import-name conflict handling (aliasing middleware import), aliased/non-aliased user imports, and an issue-267 reproduction covering combined fixes and expected migration output and status messages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • gaby
  • sixcolors
  • efectn

Poem

🐰 Hopping through code with a careful glance,
I alias and patch so your imports can dance,
I swap Root for FS with a tidy cheer,
Tests stamp the path so no bugs reappear,
A cheerful nibble — migration's clear! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the two main bugs being fixed: handling http.FS() and addressing import naming conflicts in the filesystem migration.
Description check ✅ Passed The PR description thoroughly explains both bugs, provides detailed examples, includes test plan with four new tests, and references the linked issue #267.
Linked Issues check ✅ Passed The code changes directly address all requirements from issue #267: recognizing http.FS() and extracting inner values, detecting import naming conflicts and aliasing appropriately.
Out of Scope Changes check ✅ Passed All changes are focused on the filesystem middleware migration bugs. The modifications to handle http.FS() and import conflicts are directly aligned with issue #267 requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

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: 1

🤖 Fix all issues with AI agents
In `@cmd/internal/migrations/v3/filesystem_middleware.go`:
- Around line 21-37: The static import conflict detection in staticMiddlewarePkg
currently treats any import path ending with /static as conflicting (using
reStaticImport), which incorrectly flags Fiber's own middleware (e.g.,
github.com/gofiber/fiber/.../middleware/static) and can force a new alias;
update staticMiddlewarePkg to ignore Fiber static middleware paths by refining
the regex or adding a path check against known Fiber import prefixes (e.g.,
"github.com/gofiber/fiber") and, when an alias is present in the match (m[1]),
return that alias instead of forcing "staticmw" so existing aliases are reused;
ensure reStaticImport or the post-match logic excludes Fiber middleware and
prefers the detected alias when available.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fce83cd and e10e60b.

📒 Files selected for processing (2)
  • cmd/internal/migrations/v3/filesystem_middleware.go
  • cmd/internal/migrations/v3/filesystem_middleware_test.go
🧰 Additional context used
🧬 Code graph analysis (2)
cmd/internal/migrations/v3/filesystem_middleware.go (1)
cmd/internal/helpers.go (1)
  • ChangeFileContent (54-110)
cmd/internal/migrations/v3/filesystem_middleware_test.go (1)
cmd/internal/migrations/v3/filesystem_middleware.go (1)
  • MigrateFilesystemMiddleware (42-98)
🔇 Additional comments (2)
cmd/internal/migrations/v3/filesystem_middleware.go (1)

44-75: Migration rewrite flow looks consistent.

Alias-aware import swaps combined with the http.Dir/http.FS Root conversions are well-aligned with the new v3 static middleware shape.

cmd/internal/migrations/v3/filesystem_middleware_test.go (1)

121-302: Test coverage for issue #267 scenarios is solid.

The new cases exercise both the http.FS unwrapping and import conflict aliasing paths, including the combined scenario.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

…tion

Fixes two bugs in the filesystem middleware migration to static middleware:

Bug 1: http.FS() not handled correctly
- Added regex to match Root: http.FS(...) patterns
- Extract inner value directly since embed.FS implements fs.FS
- Prevents invalid code like os.DirFS(http.FS(embedFS))

Bug 2: Import naming conflict not handled
- Detect existing imports ending with /static
- Exclude Fiber's own middleware paths from conflict detection
- Handle dot imports (import . "path/to/static")
- Alias middleware import to staticmw when conflict exists
- Use quotes in import replacement for safety

Added tests:
- Test_MigrateFilesystemMiddleware_WithHTTPFS
- Test_MigrateFilesystemMiddleware_WithStaticPackageConflict
- Test_MigrateFilesystemMiddleware_WithAliasedStaticImport
- Test_MigrateFilesystemMiddleware_FiberStaticNotConflict
- Test_MigrateFilesystemMiddleware_IssueExample

Fixes gofiber#267
@CybotTM CybotTM force-pushed the fix/filesystem-migration-bugs branch from a3d75e2 to aefabda Compare February 5, 2026 08:10
@CybotTM
Copy link
Contributor Author

CybotTM commented Feb 5, 2026

All review feedback has been addressed and commits have been squashed into a single commit.

Ready for review

Changes:

  • Handle http.FS() correctly (extract inner value directly)
  • Detect import naming conflicts with user packages named static
  • Exclude Fiber's own middleware from conflict detection
  • Handle dot imports
  • Use quotes in import replacement for safety
  • Added 5 new test cases

All 8 filesystem migration tests pass.

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: 1

🤖 Fix all issues with AI agents
In `@cmd/internal/migrations/v3/filesystem_middleware.go`:
- Around line 16-18: The current regexes reFilesystemRootHTTPDir and
reFilesystemRootHTTPFS fail on nested parentheses (they use [^)]+); replace the
regex-based extraction for http.Dir(...) and http.FS(...) with a
parenthesis-matching extractor: find the index of "http.Dir(" or "http.FS(" in
the input, then iterate characters from the opening '(' keeping a depth counter
to locate the matching closing ')' (handling nested parens) and return the full
inner argument; update the code paths that previously used
reFilesystemRootHTTPDir/reFilesystemRootHTTPFS to call this new helper (keep
reFilesystemRoot for simpler non-paren cases) and ensure trimming/whitespace
handling matches existing behavior.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e10e60b and 4fcab83.

📒 Files selected for processing (1)
  • cmd/internal/migrations/v3/filesystem_middleware.go
🧰 Additional context used
🧬 Code graph analysis (1)
cmd/internal/migrations/v3/filesystem_middleware.go (1)
cmd/internal/helpers.go (1)
  • ChangeFileContent (54-110)

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@ReneWerner87
Copy link
Member

thx for the PR @CybotTM
can you check coderabbit last comment

@ReneWerner87 ReneWerner87 merged commit 1991105 into gofiber:master Feb 5, 2026
12 of 13 checks passed
@welcome
Copy link

welcome bot commented Feb 5, 2026

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

CybotTM added a commit to netresearch/ldap-selfservice-password-changer that referenced this pull request Feb 5, 2026
## Summary

Upgrades the web framework from Fiber v2 to Fiber v3.

## Changes

- Update imports from `fiber/v2` to `fiber/v3`
- Change handler signatures from `*fiber.Ctx` to `fiber.Ctx` (interface,
not pointer)
- Update body parser: `c.BodyParser()` → `c.Bind().Body()`
- Migrate `filesystem` middleware to `static` middleware
- Use helmet from `fiber/v3/middleware/helmet` (now bundled)
- Alias internal static package as `webstatic` to avoid naming conflict

## Breaking Changes Handled

| v2 | v3 |
|----|----|
| `*fiber.Ctx` | `fiber.Ctx` (interface) |
| `c.BodyParser(&body)` | `c.Bind().Body(&body)` |
| `filesystem.New()` | `static.New()` |
| `helmet/v2` | `fiber/v3/middleware/helmet` |

## Test Plan

- [x] All existing tests pass
- [x] Build succeeds
- [ ] Manual testing of password change flow
- [ ] Manual testing of password reset flow (if enabled)

## Related

- [Fiber v3 Migration Guide](https://docs.gofiber.io/next/whats_new)
- Found and reported bugs in `fiber migrate` tool:
gofiber/cli#267
- Submitted fix PR: gofiber/cli#268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 fiber migrate produces invalid code for filesystem middleware migration

2 participants