Skip to content

chore: use more fitting ignore case method#5980

Merged
LesnyRumcajs merged 1 commit intomainfrom
cheaper-compares
Aug 25, 2025
Merged

chore: use more fitting ignore case method#5980
LesnyRumcajs merged 1 commit intomainfrom
cheaper-compares

Conversation

@LesnyRumcajs
Copy link
Copy Markdown
Member

@LesnyRumcajs LesnyRumcajs commented Aug 25, 2025

Summary of changes

Changes introduced in this pull request:

  • a completely meaningless improvement that saves maybe two allocations in the tests that are seldom invoked. Totally worth it.

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Summary by CodeRabbit

  • Tests
    • Improved case-insensitive matching in API comparison tests by switching to ASCII-only comparison, reducing false positives/negatives when evaluating identical error messages that differ only by case. Enhances reliability and performance of test outcomes. No changes to public interfaces or user workflows, and no impact on runtime behavior—only test evaluation is affected.

@LesnyRumcajs LesnyRumcajs requested a review from a team as a code owner August 25, 2025 08:29
@LesnyRumcajs LesnyRumcajs requested review from elmattic and hanabi1224 and removed request for a team August 25, 2025 08:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 25, 2025

Walkthrough

Replaced Unicode lowercasing string comparison with ASCII-only case-insensitive comparison in evaluate_test_success for the PassWithIdenticalErrorCaseInsensitive path. No other logic, control flow, or public interfaces were modified.

Changes

Cohort / File(s) Summary
Case-insensitive comparison change
src/tool/subcommands/api_cmd/api_compare_tests.rs
Switched from to_lowercase() equality to eq_ignore_ascii_case(...) for comparing error reasons in the PassWithIdenticalErrorCaseInsensitive path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cheaper-compares

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

@LesnyRumcajs LesnyRumcajs enabled auto-merge August 25, 2025 08:29
Copy link
Copy Markdown
Contributor

@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 (4)
src/tool/subcommands/api_cmd/api_compare_tests.rs (4)

3086-3088: Switch to eq_ignore_ascii_case removes allocations; confirm ASCII-only semantics are acceptable.

This change avoids two temporary String allocations and is the right tool for ASCII-only case-insensitive comparison. It does change semantics vs Unicode lowercasing. Given our error texts appear to be English/ASCII (example at Lines 1181-1190), this looks safe. Consider adding a short code comment to prevent future regressions back to Unicode lowercasing.

Apply this diff to document the intent inline:

                 PolicyOnRejected::PassWithIdenticalErrorCaseInsensitive => {
-                    reason_forest.eq_ignore_ascii_case(reason_lotus)
+                    // ASCII-only case-insensitive compare avoids allocations from to_lowercase
+                    // and is sufficient for our error strings (English / hex / base64).
+                    // If non-ASCII ever shows up, revisit with Unicode casefolding.
+                    reason_forest.eq_ignore_ascii_case(reason_lotus)
                 }

200-208: Clarify variant semantics: explicitly note ASCII-only case-insensitivity.

The name is generic, but the new implementation is ASCII-specific. A brief doc comment on the enum variant will help readers and keep tests aligned.

 pub(super) enum PolicyOnRejected {
     Fail,
     Pass,
     PassWithIdenticalError,
-    PassWithIdenticalErrorCaseInsensitive,
+    /// Case-insensitive comparison using ASCII rules (no Unicode casefolding).
+    /// Chosen to avoid temporary allocations in hot paths.
+    PassWithIdenticalErrorCaseInsensitive,
     /// If Forest reason is a subset of Lotus reason, the test passes.
     /// We don't always bubble up errors and format the error chain like Lotus.
     PassWithQuasiIdenticalError,
 }

396-405: Align TestDump behavior with its documentation (only produce dump when invalid).

Doc at Lines 188-198 says the dump is “Optional … if either status was invalid,” but here we always set Some. If not intentional, gate it on success to reduce disk I/O and noise.

         TestResult {
             forest_status,
             lotus_status,
-            test_dump: Some(TestDump {
-                request: self.request.clone(),
-                forest_response,
-                lotus_response,
-            }),
+            test_dump: if !(matches!(forest_status, TestSummary::Valid)
+                && matches!(lotus_status, TestSummary::Valid))
+            {
+                Some(TestDump {
+                    request: self.request.clone(),
+                    forest_response,
+                    lotus_response,
+                })
+            } else {
+                None
+            },
             duration: start.elapsed(),
         }

1181-1188: Typo: “invocking” → “invoking”.

Minor editorial fix in a user-facing comment.

-            // Both Forest and Lotus should fail miserably at invocking Cthulhu's name
+            // Both Forest and Lotus should fail miserably at invoking Cthulhu's name
📜 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 344f9d0 and fad6096.

📒 Files selected for processing (1)
  • src/tool/subcommands/api_cmd/api_compare_tests.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: LesnyRumcajs
PR: ChainSafe/forest#5907
File: src/rpc/methods/state.rs:523-570
Timestamp: 2025-08-06T15:44:33.467Z
Learning: LesnyRumcajs prefers to rely on BufWriter's Drop implementation for automatic flushing rather than explicit flush() calls in Forest codebase.

@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Aug 25, 2025
Merged via the queue into main with commit 7346190 Aug 25, 2025
44 checks passed
@LesnyRumcajs LesnyRumcajs deleted the cheaper-compares branch August 25, 2025 09:18
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.

3 participants