Skip to content

Conversation

@fridrik01
Copy link
Contributor

@fridrik01 fridrik01 commented Dec 18, 2025

This PR adds a python script to run hive tests locally using the same scenario configuration as have configured to run in our CI. When running this script it parses scenarios directly from .github/workflows/hive.yml, takes care of building a new bera-reth docker container (unless --skip-build is set), runs the hive command against selected scenarios, parses the generated json results and compares it against the expected_failures.yaml and ignored_tests.yaml.

Test plan

~/workspace/bera-reth % ./scripts/run-hive-local.py --skip-build smoke/network                                     
==> Checking prerequisites...

==> Running: smoke/network
Dec 18 10:50:23.255 INF building image image=hive/hiveproxy nocache=false pull=false
Dec 18 10:50:23.362 INF building 1 clients...
Dec 18 10:50:23.362 INF building image image=hive/clients/bera-reth:latest dir=clients/bera-reth nocache=false pull=false
Dec 18 10:50:23.619 INF building 1 simulators...
Dec 18 10:50:23.619 INF building image image=hive/simulators/smoke/network:latest dir=simulators/smoke/network nocache=false pull=false
Dec 18 10:50:23.940 INF running simulation: smoke/network
Dec 18 10:50:24.053 INF hiveproxy started container=2a9a184945a2 addr=172.17.0.6:8081
Dec 18 10:50:24.186 INF API: suite started suite=0 name=network
Dec 18 10:50:24.188 INF API: test started suite=0 test=1 name="connection on network1"
Dec 18 10:50:24.454 INF API: client bera-reth started suite=0 test=1 container=de9627cf
Dec 18 10:50:24.471 INF API: network created name=network1
Dec 18 10:50:24.504 INF API: container connected to network network=network1 container=de9627cf
Dec 18 10:50:24.533 INF API: container connected to network network=network1 container=simulation
Dec 18 10:50:24.537 INF API: container IP requested network=network1 container=de9627cf ip=172.18.0.2
Dec 18 10:50:24.541 INF API: container IP requested network=network1 container=simulation ip=172.18.0.3
Dec 18 10:50:24.546 INF API: container IP requested network=bridge container=de9627cf ip=172.17.0.9
Dec 18 10:50:24.590 INF API: container disconnected network=network1 container=de9627cf
Dec 18 10:50:24.633 INF API: container disconnected network=network1 container=simulation
Dec 18 10:50:24.812 INF API: docker network removed network=network1
Dec 18 10:50:24.923 INF API: test ended suite=0 test=1 pass=true
Dec 18 10:50:24.925 INF API: test started suite=0 test=2 name="initial networks"
Dec 18 10:50:24.939 INF API: network created name=network2
Dec 18 10:50:25.193 INF API: client bera-reth started suite=0 test=2 container=7cb1e83b
Dec 18 10:50:25.196 INF API: container IP requested network=network2 container=7cb1e83b ip=172.18.0.2
Dec 18 10:50:25.386 INF API: test ended suite=0 test=2 pass=true
Dec 18 10:50:25.420 INF removing docker network name=network2
Dec 18 10:50:25.569 INF API: suite ended suite=0
Dec 18 10:50:25.835 INF simulation smoke/network finished suites=1 tests=2 failed=0
Validating: 1766055025-fcabac2a7a18b3894eec6a29c0d3e2b7.json
Success.

==> All scenarios passed!

Summary by CodeRabbit

Release Notes

  • New Features
    • Introduced a local script for running and managing Hive test scenarios with customizable execution options
    • Supports listing available scenarios, running all scenarios, or targeting specific ones with filtering capabilities
    • Includes comprehensive result validation and robust error detection with clear status messages
    • Ensures sequential execution to prevent race conditions and provides Docker image building options

✏️ Tip: You can customize this high-level summary in your review settings.

@fridrik01 fridrik01 self-assigned this Dec 18, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 18, 2025

Walkthrough

A new local runner script is added that executes Hive test scenarios from the GitHub Actions workflow locally. It loads scenario definitions, validates prerequisites, optionally builds the Hive binary and Docker image, runs scenarios sequentially, validates results against expected outcomes, and reports status.

Changes

Cohort / File(s) Summary
Local Hive Test Runner
scripts/run-hive-local.py
New executable script providing CLI interface to run Hive test scenarios locally. Includes scenario discovery, prerequisite validation, conditional building of Hive binary and Docker images, scenario execution with result validation, and comprehensive error handling. Supports options: --skip-build, --all, and positional arguments for scenario name and limit filter.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant CLI as run-hive-local.py
    participant FS as File System
    participant Build as Build System
    participant Hive as Hive Binary
    participant Parser as Parse Tool
    participant Output as Output/Report

    User->>CLI: Run script (scenario, options)
    CLI->>FS: Load hive.yml scenarios
    FS-->>CLI: Scenario definitions
    
    alt scenario specified
        CLI->>CLI: Find matching scenario
    else --all flag
        CLI->>CLI: Use all scenarios
    end
    
    CLI->>FS: Check prerequisites (hive.go exists)
    
    alt build required & not --skip-build
        CLI->>Build: Build Hive binary
        Build-->>CLI: Build complete
        
        alt Docker image needed
            CLI->>Build: Build Docker image
            Build-->>CLI: Image ready
        end
    end
    
    loop for each scenario
        CLI->>CLI: Compute scenario filters
        CLI->>Hive: Execute scenario with filters
        Hive->>FS: Generate results JSON
        FS-->>CLI: Results file located
        
        CLI->>Parser: Validate results (check failures/ignores)
        Parser-->>CLI: Validation status
        
        alt validation passed
            CLI->>Output: Print ✓ status
        else validation failed
            CLI->>Output: Print ✗ status
        end
    end
    
    CLI->>Output: Report summary (pass/fail)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Specific areas requiring attention:
    • Logic for scenario loading and filtering from hive.yml matrix structure
    • Prerequisites validation and conditional build logic (Hive binary and Docker image)
    • Result file location and parsing integration with external validation tool
    • Error handling for hive crashes, missing results, and process exit codes
    • CLI argument parsing and option precedence (--skip-build, --all, positional args)

Poem

🐰 A runner swift, both fleet and keen,
Now tests scenarios, local scene!
Build, run, and validate with care,
Hive fuzzing made simple—no despair!
Sequential flows, no races here,
Local testing, crystal clear! 🧪✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a local hive test runner script as a new executable Python script.
✨ 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 run-hive-local

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.

@fridrik01 fridrik01 requested a review from calbera December 18, 2025 10:54
@fridrik01 fridrik01 changed the title Add local hive test runner script feat: add local hive test runner script Dec 18, 2025
@fridrik01 fridrik01 marked this pull request as ready for review December 18, 2025 11:01
@fridrik01 fridrik01 requested a review from rezzmah as a code owner December 18, 2025 11:01
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 (5)
scripts/run-hive-local.py (5)

18-18: Document the PyYAML dependency.

The script requires PyYAML but this dependency isn't documented. Consider adding installation instructions in the docstring or a comment, e.g., pip install PyYAML.


22-22: Consider making HIVE_DIR configurable via environment variable.

The script assumes the hive repository is at ../hive. While line 132 checks for its existence, the error message at line 134 mentions "Set HIVE_DIR" but the script doesn't actually support this. Consider allowing users to override via an environment variable.

🔎 Apply this diff to support HIVE_DIR environment variable:
-HIVE_DIR = BERA_RETH_DIR.parent / "hive"
+HIVE_DIR = Path(os.environ.get("HIVE_DIR", BERA_RETH_DIR.parent / "hive"))

25-28: Add error handling for file and YAML parsing failures.

The function will raise unhandled exceptions if the workflow file is missing or has an unexpected structure. This would produce cryptic errors for users.

🔎 Apply this diff to add error handling:
 def load_scenarios():
-    with open(HIVE_WORKFLOW) as f:
-        workflow = yaml.safe_load(f)
-    return workflow["jobs"]["test"]["strategy"]["matrix"]["scenario"]
+    try:
+        with open(HIVE_WORKFLOW) as f:
+            workflow = yaml.safe_load(f)
+        return workflow["jobs"]["test"]["strategy"]["matrix"]["scenario"]
+    except FileNotFoundError:
+        print(f"Error: Workflow file not found at {HIVE_WORKFLOW}")
+        sys.exit(1)
+    except (KeyError, TypeError) as e:
+        print(f"Error: Unexpected workflow structure in {HIVE_WORKFLOW}: {e}")
+        sys.exit(1)

72-76: Avoid global side effect with os.chdir.

Using os.chdir changes the working directory for the entire process. Consider passing cwd to subprocess.run instead to keep the side effect local.

🔎 Apply this diff to use cwd parameter:
     print()
     print(f"==> Running: {sim}" + (f" (filter: {filter_str})" if filter_str else ""))
 
-    os.chdir(HIVE_DIR)
     args = ["./hive", "--sim", sim, "--client", "bera-reth", "--sim.parallelism", "8"]
     if filter_str:
         args.extend(["--sim.limit", filter_str])
 
     start_time = time.time()
 
     # The hive process returns non-zero exit code when tests fail, even on expected
     # failures so we need to parse the JSON to check if failures are expected
-    result = subprocess.run(args)
+    result = subprocess.run(args, cwd=HIVE_DIR)

137-140: Fix typo in comment.

Line 138 has a typo: "exst" should be "exist".

🔎 Apply this diff to fix the typo:
-    # Build hive if the binary does not exst
+    # Build hive if the binary does not exist
     if not (HIVE_DIR / "hive").exists():
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4ec98f and f8d404d.

📒 Files selected for processing (1)
  • scripts/run-hive-local.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.14.8)
scripts/run-hive-local.py

81-81: subprocess call: check for execution of untrusted input

(S603)


101-101: subprocess call: check for execution of untrusted input

(S603)


102-110: Starting a process with a partial executable path

(S607)


140-140: Starting a process with a partial executable path

(S607)


145-145: subprocess call: check for execution of untrusted input

(S603)


146-158: Starting a process with a partial executable path

(S607)

⏰ 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: Security audit
  • GitHub Check: Clippy lint
  • GitHub Check: Run tests
  • GitHub Check: Check documentation
🔇 Additional comments (6)
scripts/run-hive-local.py (6)

31-52: LGTM!

The filter construction logic correctly handles all combinations of limit and include parameters. The list function provides clear output for users.


55-65: LGTM!

The scenario matching logic correctly handles both exact sim matches and optional limit filtering.


84-97: JSON file selection approach is acceptable for sequential execution.

The modification-time-based approach for finding result files works well for the intended sequential use case. The comment at line 96 appropriately warns users about the limitation.


143-160: LGTM!

The Docker build command is correctly structured with appropriate error handling via check=True.


162-188: LGTM!

The scenario execution logic correctly handles both single and multiple scenario modes, tracks failures appropriately, and returns proper exit codes.


81-81: Static analysis security warnings are false positives.

The static analysis tools flag subprocess calls as potential security issues (S603, S607). However, these are false positives in this context:

  • All paths are constructed from controlled Path objects or repository-relative paths
  • Commands (go, docker, python3) are standard system tools
  • No user input is passed unsanitized to subprocess calls
  • This is a developer tool running in a trusted environment

These warnings can be safely ignored for this script.

Also applies to: 101-111, 140-140, 145-160

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.

2 participants