Skip to content

Add regression test for encryptcookie migrator idempotency#215

Merged
ReneWerner87 merged 1 commit into
masterfrom
codex/2025-10-08-06-33-00
Oct 8, 2025
Merged

Add regression test for encryptcookie migrator idempotency#215
ReneWerner87 merged 1 commit into
masterfrom
codex/2025-10-08-06-33-00

Conversation

@ReneWerner87
Copy link
Copy Markdown
Member

@ReneWerner87 ReneWerner87 commented Oct 8, 2025

Summary

  • add a unit test ensuring MigrateEncryptcookieConfig leaves Encryptor and Decryptor signatures unchanged once migrated
  • verify the migrator does not emit console output when no changes are necessary

Testing

  • make lint
  • make test

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

Summary by CodeRabbit

  • Tests
    • Added test coverage to confirm encrypt-cookie configuration migrations are idempotent: when configs already use the migrated format, running the migration leaves files unchanged and emits no output. This improves confidence in upgrade paths and guards against regressions. Ensures consistent behavior across environments and supports safer, repeatable runs during upgrades and rollbacks. No user-facing changes.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

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 introduces a new regression test to ensure the encryptcookie migrator (MigrateEncryptcookieConfig) is idempotent. Specifically, it verifies that the migrator does not alter Encryptor and Decryptor function signatures if they are already present and correctly formatted, and that it produces no console output when no changes are required.

Highlights

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.

@github-actions github-actions Bot added ✏️ Feature New feature or request 🧹 Updates labels Oct 8, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 8, 2025

Walkthrough

Adds a new idempotency test to verify that migrating an encryptcookie config does not alter files when Encryptor/Decryptor already use the migrated signatures.

Changes

Cohort / File(s) Summary
Tests: encryptcookie migration
cmd/internal/migrations/v3/encryptcookie_config_test.go
Adds Test_MigrateEncryptcookieConfig_EncryptorDecryptorMigrated to ensure migration is a no-op when signatures are already in the migrated form, asserting unchanged file content and no command output.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

I thump my foot—tests neatly aligned,
A cookie embraced, no bytes redefined.
Idempotent winds, quiet as night,
Migrate, then pause—everything right.
In burrows of code, I nibble and grin,
No diff today—consistency wins. 🐇

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description outlines the summary of added tests and the testing commands but does not follow the repository’s template headings, omitting the required “## Commit formatting” section and using a “## Summary” header instead of the expected explanation section. Please add the “## Commit formatting” section with the emoji usage guidelines for commit messages and update the “## Summary” heading to match the template’s explanation section that describes the details and purpose of the change.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely summarizes the primary change by stating that a regression test is being added to verify the idempotency of the encryptcookie migrator, directly reflecting the core purpose of the pull request.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/2025-10-08-06-33-00

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

I've reviewed your pull request. The new test case is well-written and effectively verifies the idempotency of the MigrateEncryptcookieConfig migrator, especially for the case where Encryptor and Decryptor have already been migrated. This is a valuable addition to ensure the migration script is robust.

I have one suggestion regarding the naming of the new test function to improve consistency within the test suite. Please see the detailed comment.

assert.Equal(t, first, second)
}

func Test_MigrateEncryptcookieConfig_EncryptorDecryptorMigrated(t *testing.T) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The test function name Test_MigrateEncryptcookieConfig_EncryptorDecryptorMigrated is a bit inconsistent with the existing Test_MigrateEncryptcookieConfig_Idempotent test. Since this test also verifies idempotency, but for a more specific case, consider renaming it to better reflect its purpose and align with existing test names. A more consistent name could be Test_MigrateEncryptcookieConfig_Idempotent_EncryptorDecryptor. This improves consistency and makes the test suite easier to understand.

Suggested change
func Test_MigrateEncryptcookieConfig_EncryptorDecryptorMigrated(t *testing.T) {
func Test_MigrateEncryptcookieConfig_Idempotent_EncryptorDecryptor(t *testing.T) {

Copy link
Copy Markdown

@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 (1)
cmd/internal/migrations/v3/encryptcookie_config_test.go (1)

103-104: Minor style inconsistency in parameter declarations.

Line 103 uses shared type annotation (value, key string) while line 104 uses explicit type annotations (value string, key string). Both are valid Go syntax, but for consistency, you could use the same style for both lines.

Apply this diff for consistency:

-    Encryptor: func(_ string, value, key string) (string, error) { return "", nil },
+    Encryptor: func(_ string, value string, key string) (string, error) { return "", nil },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 677633b and 7d05aaf.

📒 Files selected for processing (1)
  • cmd/internal/migrations/v3/encryptcookie_config_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-07-01T03:33:22.283Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:51-54
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests for key length enforcement in `DecryptCookie` have been added to ensure consistency and security in the encryption processes.
📚 Learning: 2024-07-02T13:29:56.992Z
Learnt from: gaby
PR: gofiber/fiber#3056
File: middleware/encryptcookie/utils.go:22-25
Timestamp: 2024-07-02T13:29:56.992Z
Learning: The `encryptcookie_test.go` file contains unit tests that validate key lengths for both `EncryptCookie` and `DecryptCookie` functions, ensuring that invalid key lengths raise appropriate errors.

Applied to files:

  • cmd/internal/migrations/v3/encryptcookie_config_test.go
🧬 Code graph analysis (1)
cmd/internal/migrations/v3/encryptcookie_config_test.go (1)
cmd/internal/migrations/v3/encryptcookie_config.go (1)
  • MigrateEncryptcookieConfig (14-56)
⏰ 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). (4)
  • GitHub Check: Build (1.25.x, ubuntu-latest)
  • GitHub Check: Build (1.25.x, macos-latest)
  • GitHub Check: Build (1.25.x, windows-latest)
  • GitHub Check: Build (1.25.x, macos-13)
🔇 Additional comments (1)
cmd/internal/migrations/v3/encryptcookie_config_test.go (1)

91-116: Excellent test coverage for the already-migrated scenario!

This test effectively verifies that the migrator is idempotent when Encryptor and Decryptor already use the migrated signatures. It complements the existing Test_MigrateEncryptcookieConfig_Idempotent by testing a different angle: starting with already-migrated code rather than running migration twice on unmigrated code.

The assertions correctly verify:

  • File content remains unchanged (line 114)
  • No console output is generated (line 115)

@ReneWerner87 ReneWerner87 merged commit 5663dee into master Oct 8, 2025
13 checks passed
@ReneWerner87 ReneWerner87 deleted the codex/2025-10-08-06-33-00 branch October 8, 2025 06:36
@ReneWerner87 ReneWerner87 removed the ✏️ Feature New feature or request label Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant