Skip to content

Honor force option when migrating with hash#189

Merged
ReneWerner87 merged 2 commits into
masterfrom
codex/2025-08-24-13-21-54
Aug 24, 2025
Merged

Honor force option when migrating with hash#189
ReneWerner87 merged 2 commits into
masterfrom
codex/2025-08-24-13-21-54

Conversation

@ReneWerner87
Copy link
Copy Markdown
Member

@ReneWerner87 ReneWerner87 commented Aug 24, 2025

Summary

  • fix go.mod Fiber version replacement when using require blocks
  • ensure --force uses provided hash or version and keeps newer version when not forced
  • add tests covering force and hash downgrade scenarios

Testing

  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_68ab0983d58483268b6f36178d84b57c

Summary by CodeRabbit

  • New Features

    • Improved migration handling of go.mod entries, including require blocks and pseudo-versions.
    • Better support for migrations using commit hashes, resolving to appropriate versions.
  • Bug Fixes

    • Migrating to the same or an older version now performs a no-op with a clear message instead of failing.
  • Tests

    • Expanded coverage for v2→v3 migrations, force behavior, commit-hash flows, and require-block scenarios.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Aug 24, 2025

Walkthrough

Updates migration regex to consolidate whitespace/require capture. Alters CLI migrate behavior to no-op with a message when target version is not greater and force is false. Tests updated for Fiber v3 imports, hash/pseudo-version handling, and new no-op behavior. Minor lint cleanup in a test stub.

Changes

Cohort / File(s) Summary
Go package regex update
cmd/internal/migrations/common.go
Adjusted pkgRegex to combine leading whitespace and optional require into one capturing group; replacement pattern unchanged.
Migration behavior: non-increasing version
cmd/migrate.go
Changed from error on non-increasing target to early return with message: "Fiber already at " when not forced.
Tests: migrate CLI behavior and versions
cmd/migrate_test.go
Added/updated tests for no-op behavior without force, forced resets, commit-hash pseudo-versions, and require-block handling; introduced hashABC constant; added setup/teardown wrappers.
Tests: Go package migration imports
cmd/internal/migrations/common_test.go
Updated embedded main.go to use Fiber v3 import paths and assertions reflecting v3.
Tests: exec helper lint
cmd/internal/migrations/exec_stub_test.go
Removed nolint directive; preserved intentional exit comment.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant CLI as migrate cmd
  participant MV as Migrate Logic
  U->>CLI: run migrate [--force] [--hash]
  CLI->>MV: determine current & target versions
  alt !force AND target ≤ current
    MV-->>CLI: print "Fiber already at <version>"
    CLI-->>U: exit 0
  else Force OR target > current
    MV->>MV: perform migration (imports, go.mod, hash/pseudo-version)
    MV-->>CLI: success/failure
    CLI-->>U: result
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

☢️ Bug

Poem

I nibbled the mods with gentle care,
Hop to v3, the imports square.
If you’re there already—no alarm,
I twitch my nose and do no harm.
Hashes bloom like clover bright,
Force me? I’ll leap with all my might. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5cecc53 and b05032e.

⛔ Files ignored due to path filters (1)
  • .golangci.yml is excluded by !**/*.yml
📒 Files selected for processing (5)
  • cmd/internal/migrations/common.go (1 hunks)
  • cmd/internal/migrations/common_test.go (1 hunks)
  • cmd/internal/migrations/exec_stub_test.go (1 hunks)
  • cmd/migrate.go (1 hunks)
  • cmd/migrate_test.go (6 hunks)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2024-11-15T07:56:21.623Z
Learnt from: ReneWerner87
PR: gofiber/fiber#3161
File: app.go:923-932
Timestamp: 2024-11-15T07:56:21.623Z
Learning: In the Fiber framework, breaking changes are acceptable when moving from version 2 to version 3, including modifications to method signatures such as in the `Test` method in `app.go`.

Applied to files:

  • cmd/internal/migrations/common_test.go
  • cmd/migrate_test.go
  • cmd/migrate.go
📚 Learning: 2024-11-10T23:44:13.704Z
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.

Applied to files:

  • cmd/internal/migrations/common_test.go
📚 Learning: 2024-11-23T19:50:41.765Z
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/server.go:14-16
Timestamp: 2024-11-23T19:50:41.765Z
Learning: In the `clean-code` example at `clean-code/app/server/server.go` using the Go Fiber framework, it's acceptable to omit production-level features like context usage and graceful shutdown handling to keep the example simple.

Applied to files:

  • cmd/internal/migrations/common_test.go
📚 Learning: 2024-11-23T19:35:36.767Z
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/main.go:0-0
Timestamp: 2024-11-23T19:35:36.767Z
Learning: In the Go `clean-code` example (`clean-code/app/main.go`) in the `gofiber/recipes` repository, it's acceptable to omit graceful shutdown handling, as the example code prioritizes simplicity over production-level practices.

Applied to files:

  • cmd/internal/migrations/common_test.go
📚 Learning: 2025-02-12T11:24:31.153Z
Learnt from: ReneWerner87
PR: gofiber/storage#0
File: :0-0
Timestamp: 2025-02-12T11:24:31.153Z
Learning: The storage package in gofiber/storage repository can be used independently of the Fiber web framework.

Applied to files:

  • cmd/internal/migrations/common_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build (1.25.x, windows-latest)
  • GitHub Check: Build (1.25.x, macos-13)
🔇 Additional comments (11)
cmd/internal/migrations/exec_stub_test.go (1)

39-39: LGTM! Improved code quality.

The removal of the nolint directive makes the code cleaner while maintaining the same functionality. The comment clearly explains the intentional exit behavior.

cmd/internal/migrations/common.go (1)

17-17: Regex update verified as handling all tested go.mod variations correctly

I ran the new pattern against representative go.mod entries—including unindented, tab-indented, space-indented lines, and with/without the require keyword—and it successfully matches each variant. No further adjustments are needed here.

cmd/internal/migrations/common_test.go (1)

23-24: LGTM! Tests updated for Fiber v3 migration.

The test content has been correctly updated from v2 to v3 imports, including both the main fiber package and the middleware adaptor path. This aligns with the PR objective to test v3 migration scenarios.

cmd/migrate.go (1)

97-100: LGTM! Improved user experience for non-forced migrations.

The behavior change from returning an error to printing an informational message and exiting gracefully is a good UX improvement. When a user attempts to migrate to a version that's not greater than the current version without the --force flag, they now get a clear, non-error message instead of an error.

The logic !opts.Force && !targetVersion.GreaterThan(currentVersion) correctly implements the intended behavior.

cmd/migrate_test.go (7)

68-68: LGTM! Good practice using a constant for repeated hash values.

The hashABC constant eliminates magic strings and makes the tests more maintainable.


256-261: LGTM! Test updated to reflect new behavior.

The test correctly validates the new non-error behavior when attempting to migrate without force to a version that's not greater than the current version. The setup and teardown wrappers ensure proper test isolation.


362-362: LGTM! Consistent use of the hash constant.

Good refactoring to use the hashABC constant instead of a magic string.


429-429: LGTM! Consistent hash constant usage.

Another good example of using the centralized hashABC constant.


441-445: LGTM! Test updated for new non-error behavior.

The test correctly expects success instead of an error when not forcing a downgrade, and verifies the go.mod remains unchanged with the original hash.


460-498: LGTM! Comprehensive test for force reset behavior.

This new test thoroughly validates both scenarios:

  1. Without force: Should show "already at" message and preserve existing pseudo-version
  2. With force: Should reset to the target version and remove the old hash

The test structure with subtests and proper setup/teardown is well-organized.


500-533: LGTM! Excellent test coverage for require block scenarios.

This test fills an important gap by testing hash-based migration when the go.mod uses require blocks instead of inline requires. The test verifies that the regex changes in common.go work correctly with indented require statements within blocks.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/2025-08-24-13-21-54

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

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

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 or @coderabbitai title 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
Copy Markdown
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.

Summary of Changes

Hello @ReneWerner87, 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 enhances the migration tool by improving its handling of the --force option and version hashes, particularly when processing go.mod files that utilize require blocks. It ensures that migrations can be forced even when the target version is not strictly newer, and includes comprehensive new tests to cover these updated behaviors and downgrade scenarios.

Highlights

  • Improved go.mod Parsing: The regular expression used for parsing go.mod files has been updated to correctly identify and replace Fiber versions within require blocks, ensuring more robust module file manipulation.
  • Refined --force Option Logic: The migration command now correctly honors the --force flag, allowing users to proceed with a migration even if the target version is not strictly greater than the current installed version. Without --force, it will now inform the user that Fiber is already at the target version instead of returning an error.
  • Expanded Test Coverage: New test cases have been added to validate the behavior of the --force option, test scenarios involving hash-based version migrations, and confirm correct handling of go.mod files with require blocks, including downgrade scenarios.
  • Linter Configuration Update: The .golangci.yml configuration has been updated to include the revive linter, improving code quality checks.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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
Copy Markdown
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 significantly improves the migration command's behavior, particularly concerning the --force option with version hashes. The logic to gracefully handle migrations to an older or same version without forcing is a great enhancement to the user experience. The update to the go.mod parsing regular expression to support require blocks is a crucial fix for broader project compatibility. Furthermore, the new tests are comprehensive, covering various downgrade and force scenarios, which adds a lot of confidence in the changes. Overall, this is a well-executed and valuable improvement to the CLI tool.

@ReneWerner87 ReneWerner87 merged commit d3ea633 into master Aug 24, 2025
13 checks passed
@ReneWerner87 ReneWerner87 deleted the codex/2025-08-24-13-21-54 branch August 24, 2025 13:31
@ReneWerner87 ReneWerner87 added the ☢️ Bug Something isn't working label Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant