Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BellAssertion for terminal bell events #109

Merged
merged 6 commits into from
Jan 31, 2025
Merged

Conversation

ryan-gang
Copy link
Collaborator

@ryan-gang ryan-gang commented Jan 31, 2025

Introduce a new BellAssertion to verify terminal bell events and refactor existing test cases to utilize this assertion, simplifying the handling of bell checks in command autocomplete and multiple completions scenarios.

Summary by CodeRabbit

  • New Features

    • Introduced a new BellAssertion package for handling bell signal assertions in test cases.
    • Improved bell assertion logic in command autocomplete and multiple completions test cases.
  • Refactor

    • Streamlined bell assertion handling in test case methods.
    • Removed redundant bell assertion functions.
    • Integrated bell assertion more directly into test case execution.
  • Bug Fixes

    • Enhanced timeout and error handling for bell signal detection.

@ryan-gang ryan-gang self-assigned this Jan 31, 2025
Copy link

coderabbitai bot commented Jan 31, 2025

Walkthrough

A new assertions package has been introduced with a BellAssertion struct to handle bell signal assertions in shell-related test cases. The changes refactor the bell assertion logic across multiple test case files, moving from direct function calls to a more structured assertion mechanism. The new implementation provides a standardized way to check for bell signals, enhancing the clarity and maintainability of the code.

Changes

File Change Summary
internal/assertions/bell_assertion.go Added new BellAssertion struct with Inspect() and Run() methods for bell signal assertions. Introduced checkIfBellReceived function.
internal/test_cases/command_autocomplete_test_case.go Removed RunBellAssertion and checkIfBellReceived functions, integrated BellAssertion directly into Run method.
internal/test_cases/command_multiple_completions_test_case.go Updated bell assertion logic to use new BellAssertion with AssertWithoutPrompt.

Sequence Diagram

sequenceDiagram
    participant TestCase as Test Case
    participant Shell as Shell
    participant Asserter as Asserter
    participant BellAssertion as Bell Assertion

    TestCase->>Shell: Get VTBellChannel
    TestCase->>Asserter: Add BellAssertion
    Asserter->>BellAssertion: Run()
    BellAssertion->>Shell: Check Bell Channel
    alt Bell Received
        BellAssertion-->>Asserter: Return Success
    else Timeout
        BellAssertion-->>Asserter: Return AssertionError
    end
Loading

Poem

🔔 Ding dong, a bell assertion's song!
In test cases, where signals belong
A channel waits, with timeout's might
Checking signals, making tests just right
CodeRabbit's hop of testing delight! 🐰


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04f24b4 and cf6c251.

📒 Files selected for processing (1)
  • internal/assertions/bell_assertion.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/assertions/bell_assertion.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test-flakiness

🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

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

@ryan-gang ryan-gang changed the title Add BellAssertion for terminal bell events Add BellAssertion for terminal bell events Jan 31, 2025
Base automatically changed from debugging-setup to main January 31, 2025 10:13
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: 0

🧹 Nitpick comments (3)
internal/assertions/bell_assertion.go (3)

7-11: Complete the documentation comment.

The documentation comment for BellAssertion is incomplete. Please complete it to describe the purpose and behavior of this assertion type.

-// BellAssertion asserts that ...
+// BellAssertion asserts that a bell signal is received within a specified timeout.

Also, consider removing the commented out Vt field if it's not needed.


17-27: Simplify the conditional logic.

The current implementation uses an if-else block that can be simplified.

 func (a BellAssertion) Run(screenState [][]string, startRowIndex int) (processedRowCount int, err *AssertionError) {
-	if !checkIfBellReceived(a.BellChannel) {
-		return 0, &AssertionError{
-			StartRowIndex: startRowIndex,
-			ErrorRowIndex: startRowIndex,
-			Message:       "Expected bell to ring, but it didn't",
-		}
-	} else {
-		return 0, nil
-	}
+	if checkIfBellReceived(a.BellChannel) {
+		return 0, nil
+	}
+	return 0, &AssertionError{
+		StartRowIndex: startRowIndex,
+		ErrorRowIndex: startRowIndex,
+		Message:       "Expected bell to ring, but it didn't",
+	}
 }

29-36: Make timeout configurable and add documentation.

The function lacks documentation and uses a hardcoded timeout value.

  1. Add documentation:
+// checkIfBellReceived waits for a bell signal on the provided channel with a timeout.
+// Returns true if a signal is received, false if the timeout is reached.
 func checkIfBellReceived(bellChannel chan bool) bool {
  1. Make timeout configurable:
+// defaultBellTimeout is the default duration to wait for a bell signal.
+const defaultBellTimeout = 100 * time.Millisecond
+
 func checkIfBellReceived(bellChannel chan bool) bool {
 	select {
 	case <-bellChannel:
 		return true
-	case <-time.After(100 * time.Millisecond): // Add reasonable timeout
+	case <-time.After(defaultBellTimeout):
 		return false
 	}
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a97cefe and 6f0c84f.

📒 Files selected for processing (3)
  • internal/assertions/bell_assertion.go (1 hunks)
  • internal/test_cases/command_autocomplete_test_case.go (1 hunks)
  • internal/test_cases/command_multiple_completions_test_case.go (1 hunks)
🔇 Additional comments (3)
internal/assertions/bell_assertion.go (1)

13-15: LGTM!

The Inspect method provides a clear string representation of the assertion type.

internal/test_cases/command_autocomplete_test_case.go (1)

84-100: LGTM! Clean integration of BellAssertion.

The integration of BellAssertion is well-structured:

  1. Retrieves bell channel from shell
  2. Creates and adds assertion
  3. Runs assertion
  4. Logs success
  5. Cleans up by popping assertion

The implementation maintains a clear flow and proper error handling.

internal/test_cases/command_multiple_completions_test_case.go (1)

76-87: LGTM! Consistent implementation of BellAssertion.

The bell assertion integration follows the same pattern as in command_autocomplete_test_case.go, maintaining consistency across test cases.

@ryan-gang ryan-gang requested a review from rohitpaulk January 31, 2025 10:26
@ryan-gang ryan-gang merged commit 46e813f into main Jan 31, 2025
5 checks passed
@ryan-gang ryan-gang deleted the fix-bell-assertions branch January 31, 2025 17:43
@ryan-gang ryan-gang added the bug Something isn't working label Jan 31, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants