Skip to content

Conversation

dsarno
Copy link
Owner

@dsarno dsarno commented Aug 18, 2025

Summary

  • replace regex scan with AST for print/sys.stdout detection
  • flip skipped tests to xfail placeholders in resource and script editing suites
  • harden transport framing tests and reject zero-length frames

Testing

  • pytest tests/test_logging_stdout.py tests/test_resources_api.py tests/test_script_editing.py tests/test_transport_framing.py

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

Copy link

coderabbitai bot commented Aug 18, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/convert-skips-to-xfail-for-tests

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

@dsarno
Copy link
Owner Author

dsarno commented Aug 18, 2025

@greptileai what do you think pal?

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR focuses on test infrastructure improvements and protocol hardening for the Unity MCP Bridge project. The changes span across multiple test files and the core Unity connection module, implementing three main improvements:

AST-based Code Analysis: The stdout detection logic in test_logging_stdout.py has been completely rewritten to use Python's Abstract Syntax Tree (AST) parsing instead of regex pattern matching. This change provides more accurate detection of print statements and sys.stdout.write() calls by understanding Python syntax rather than relying on text patterns that could produce false positives from comments or strings.

Test Placeholder Standardization: Multiple test files (test_script_editing.py and test_resources_api.py) have had their @pytest.mark.skip decorators converted to @pytest.mark.xfail(strict=False). This semantic change transforms completely skipped placeholder tests into expected-to-fail tests that can still be discovered and potentially pass if implemented. The reason strings have also been updated from 'TODO:' prefixes to more descriptive 'pending:' descriptions.

Transport Protocol Hardening: The framing tests in test_transport_framing.py have been enhanced with more robust error handling, timeout management, and frame reading logic. Additionally, the core Unity connection module now validates and rejects zero-length frames in the MCP protocol, adding defensive programming measures to prevent potential edge cases in the communication protocol.

These changes collectively improve the reliability of the test suite, provide better visibility into unimplemented functionality, and strengthen the underlying MCP transport protocol without affecting the core application logic.

Important Files Changed

Click to expand file changes
Filename Score Overview
UnityMcpBridge/UnityMcpServer~/src/unity_connection.py 4/5 Added validation to reject zero-length frames in MCP protocol framing
tests/test_logging_stdout.py 4/5 Replaced regex-based detection with AST parsing for stdout usage analysis
tests/test_script_editing.py 5/5 Converted skip decorators to xfail for 7 placeholder test functions
tests/test_resources_api.py 5/5 Converted skip decorators to xfail for 2 placeholder test functions
tests/test_transport_framing.py 4/5 Hardened framing tests with improved timeout handling and error management

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it focuses on test infrastructure improvements and defensive protocol validation
  • Score reflects solid implementation of test hardening and protocol validation with minimal impact on core functionality
  • Pay close attention to unity_connection.py to ensure zero-length frame rejection doesn't break legitimate protocol usage

Sequence Diagram

sequenceDiagram
    participant User
    participant TestFramework as "Test Framework (pytest)"
    participant UnityConnection as "UnityConnection"
    participant DummyServer as "Dummy Server"
    participant Socket as "TCP Socket"

    User->>TestFramework: "Run transport framing tests"
    TestFramework->>TestFramework: "Locate Unity MCP server source"
    TestFramework->>DummyServer: "start_dummy_server(greeting, respond_ping)"
    DummyServer->>Socket: "bind() and listen() on random port"
    DummyServer->>TestFramework: "Return port number"
    
    TestFramework->>UnityConnection: "Create connection with test port"
    UnityConnection->>Socket: "connect(host, port)"
    Socket->>DummyServer: "Accept connection"
    DummyServer->>UnityConnection: "Send greeting (FRAMING=1 or not)"
    
    UnityConnection->>UnityConnection: "Check greeting for FRAMING=1"
    alt Greeting contains FRAMING=1
        UnityConnection->>UnityConnection: "Set use_framing = True"
        UnityConnection->>TestFramework: "Return success"
    else No FRAMING=1
        UnityConnection->>Socket: "Send error message with framed header"
        UnityConnection->>Socket: "close()"
        UnityConnection->>TestFramework: "Return connection failure"
    end
    
    opt Ping-pong test
        TestFramework->>UnityConnection: "Send framed ping command"
        UnityConnection->>Socket: "sendall(header + payload)"
        Socket->>DummyServer: "Receive framed data"
        DummyServer->>DummyServer: "Parse frame and validate ping"
        DummyServer->>Socket: "Send framed pong response"
        Socket->>UnityConnection: "receive_full_response()"
        UnityConnection->>UnityConnection: "_read_exact() for header and payload"
        UnityConnection->>TestFramework: "Return parsed response"
    end
    
    TestFramework->>UnityConnection: "disconnect()"
    UnityConnection->>Socket: "close()"
    TestFramework->>User: "Test results"
Loading

5 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

Comment on lines 39 to 40
offenders.append(py_file.relative_to(SRC))
assert not offenders, (
"stdout writes found in: " + ", ".join(str(o) for o in offenders)
)
continue
Copy link

Choose a reason for hiding this comment

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

logic: Files with syntax errors are added to offenders list, but the test assertion message suggests they contain stdout writes rather than syntax issues

@dsarno dsarno merged commit acd5e0c into protocol-framing Aug 18, 2025
2 checks passed
@dsarno dsarno deleted the codex/convert-skips-to-xfail-for-tests branch August 18, 2025 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant