Skip to content

Added the fix for bru.runner.stopExecution() while running collection run from tests#8720

Open
ravindra-bruno wants to merge 2 commits into
usebruno:mainfrom
ravindra-bruno:fix/BRU-3342
Open

Added the fix for bru.runner.stopExecution() while running collection run from tests#8720
ravindra-bruno wants to merge 2 commits into
usebruno:mainfrom
ravindra-bruno:fix/BRU-3342

Conversation

@ravindra-bruno

@ravindra-bruno ravindra-bruno commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

JIRA: BRU-3342

Fixes : #7928

Problem

The Issue: The built-in scripting method bru.runner.stopExecution() is failing to halt a Bruno collection run when it is invoked specifically within the Tests block of a request.

The Discrepancy: The method works exactly as expected (immediately halting the execution) when called inside either the Pre-Request or Post-Response script blocks. However, in the Tests block, the runner ignores the stop command and incorrectly continues running subsequent lines of code and moving on to the next requests in the collection.

Impact: Automation workflows and test suites cannot be aborted dynamically from the test stage when an unrecoverable assertion or validation failure occurs.

Solution

The Fix: A programmatic fix was introduced to ensure that the collection runner monitors and respects the execution stop signal triggered during the Tests evaluation phase, aligning it with the pre-request and post-response lifecycle hooks.

Contribution Checklist:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes

Summary by CodeRabbit

  • New Features

    • Test scripts can now request an immediate stop to an ongoing collection run via the runner controls.
    • Stop requests are applied consistently across supported runtimes.
  • Bug Fixes

    • Run termination handling is now more reliable, including correct “run ended” signaling when a stop is requested.
    • Stop status is surfaced in test execution results for clearer stop behavior.
  • Tests

    • Added runtime tests validating stopExecution behavior for both NodeVM and QuickJS, including normal completion when not stopped.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e407d7f6-3f06-4aee-a144-2682c1ee0738

📥 Commits

Reviewing files that changed from the base of the PR and between 6118892 and 0618e50.

📒 Files selected for processing (1)
  • packages/bruno-electron/src/ipc/network/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/bruno-electron/src/ipc/network/index.js

Walkthrough

Test execution results now expose whether a test requested execution to stop. The Electron runner consumes this flag to terminate the collection run and avoids emitting the normal completion event afterward, with coverage across NodeVM and QuickJS runtimes.

Changes

Test stop-execution propagation

Layer / File(s) Summary
Expose and validate test stop state
packages/bruno-js/src/runtime/test-runtime.js, packages/bruno-js/tests/runtime.spec.js
runTests returns stopExecution for empty and normal test paths, with tests covering NodeVM, QuickJS, and the unset state.
Halt runner execution
packages/bruno-electron/src/ipc/network/index.js
The runner sets stopRunnerExecution when test results request execution to stop and guards the normal testrun-ended event.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • usebruno/bruno#7928 — Addresses propagation of bru.runner.stopExecution() from test runtime results to the collection runner.

Suggested reviewers: helloanoop, lohit-bruno

Sequence Diagram(s)

sequenceDiagram
  participant TestRuntime
  participant ElectronRunner
  participant WebContents
  TestRuntime->>ElectronRunner: return stopExecution
  ElectronRunner->>ElectronRunner: set stopRunnerExecution
  ElectronRunner->>WebContents: use termination-specific testrun-ended path
Loading

Poem

A test raises a flag,
The runner pauses its track,
Node and QuickJS agree,
The normal end stays back.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is clearly related to the main change: stopExecution now halts collection runs during test execution.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit 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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/bruno-electron/src/ipc/network/index.js (1)

2072-2074: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Add runner-level regression coverage.

The current tests validate the runtime payload but not that the Electron collection loop stops before executing later requests. Add a behavior-driven runner test that asserts the stop request halts the collection and emits one terminal event. As per coding guidelines, meaningful code changes should add or update high-value behavior-driven tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bruno-electron/src/ipc/network/index.js` around lines 2072 - 2074,
Add runner-level behavior-driven coverage for the collection loop around
stopRunnerExecution: simulate a request returning testResults.stopExecution,
assert later requests are not executed, and verify exactly one terminal event is
emitted. Update the existing runner test suite rather than only testing the
runtime payload.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bruno-electron/src/ipc/network/index.js`:
- Around line 2072-2074: Update the stopExecution handling around the test-run
loop and the later testrun-ended emission so a terminated run emits exactly one
event. Make the termination branch the sole owner of that event, and prevent the
post-loop path from emitting another testrun-ended event when
stopRunnerExecution is set.

---

Nitpick comments:
In `@packages/bruno-electron/src/ipc/network/index.js`:
- Around line 2072-2074: Add runner-level behavior-driven coverage for the
collection loop around stopRunnerExecution: simulate a request returning
testResults.stopExecution, assert later requests are not executed, and verify
exactly one terminal event is emitted. Update the existing runner test suite
rather than only testing the runtime payload.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8dab5603-9443-4a7e-bf5c-d26ef6cad05f

📥 Commits

Reviewing files that changed from the base of the PR and between eaf62ee and 6118892.

📒 Files selected for processing (3)
  • packages/bruno-electron/src/ipc/network/index.js
  • packages/bruno-js/src/runtime/test-runtime.js
  • packages/bruno-js/tests/runtime.spec.js

Comment thread packages/bruno-electron/src/ipc/network/index.js
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.

bru.runner.stopExecution() didn' work on test script

2 participants