Repository navigation
Fix/req.on fail() are not persisted issue - #8873
vijayh-bruno merged 11 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Changesreq.onFail variable propagation
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant RequestExecution
participant ScriptRuntime
participant executeRequestOnFailHandler
participant sendVariableUpdates
RequestExecution->>ScriptRuntime: Run request onFail handler
ScriptRuntime-->>executeRequestOnFailHandler: Return script result
executeRequestOnFailHandler->>sendVariableUpdates: Forward variable updates
sendVariableUpdates-->>RequestExecution: Complete failure handling
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
tests/utils/page/actions.ts (1)
1065-1071: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winStore the locators in named variables.
Create named locators for the More Actions button, Variables menu item, and Variables tab before
test.step. This improves page-module readability and follows the E2E locator convention.Proposed refactor
const openVariablesTab = async (page: Page) => { + const moreActionsButton = page.getByTestId('more-actions'); + const variablesMenuItem = page.getByTestId('more-actions-variables'); + const variablesTab = page + .locator('.request-tab') + .filter({ has: page.getByText('Variables', { exact: true }) }); + await test.step('Open the Variables tab', async () => { - await page.getByTestId('more-actions').click(); - await page.getByTestId('more-actions-variables').click(); - await expect( - page.locator('.request-tab').filter({ has: page.getByText('Variables', { exact: true }) }) - ).toBeVisible(); + await moreActionsButton.click(); + await variablesMenuItem.click(); + await expect(variablesTab).toBeVisible(); }); };As per path instructions, use locator variables for locators in E2E code.
🤖 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 `@tests/utils/page/actions.ts` around lines 1065 - 1071, Create named locators in openVariablesTab for the More Actions button, Variables menu item, and Variables tab before entering test.step, then use those variables for the clicks and visibility assertion while preserving the existing behavior.Source: Path instructions
🤖 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 1069-1071: The oauth2CredentialsToReset field from
onFailScriptResult is being discarded in both failure callback paths, preventing
OAuth2 credentials from being reset even when the onFail handler requests it. At
packages/bruno-electron/src/ipc/network/index.js#L1069-L1071, add a call to
resetOauth2Credentials with onFailScriptResult.oauth2CredentialsToReset after
the sendVariableUpdates call in the callback passed to
executeRequestOnFailHandler. At
packages/bruno-electron/src/ipc/network/index.js#L1948-L1950, apply the same
resetOauth2Credentials call with oauth2CredentialsToReset after
sendVariableUpdates in the collection-run failure callback.
In `@packages/bruno-js/tests/runtime.spec.js`:
- Around line 124-145: Extend the req.onFail variable-update test to also
instantiate ScriptRuntime with the QuickJS runtime, execute the same script,
invoke request.onFailHandler, and assert the updated runtime, environment, and
global environment variables. Preserve the existing NodeVM coverage while
ensuring the QuickJS wrapper returns all three updates.
In `@tests/scripting/req-api/onfail/fixtures/collection/onFail.bru`:
- Line 8: Update the request URL fixture used by the onFail test to target a
test-owned, per-test endpoint with deterministic failure behavior instead of the
shared port 9999. Ensure the endpoint remains unreachable or otherwise
guaranteed to fail, so req.onFail always executes safely during parallel test
runs.
---
Nitpick comments:
In `@tests/utils/page/actions.ts`:
- Around line 1065-1071: Create named locators in openVariablesTab for the More
Actions button, Variables menu item, and Variables tab before entering
test.step, then use those variables for the clicks and visibility assertion
while preserving the existing behavior.
🪄 Autofix
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 Plus
Run ID: 4bed7db0-2ae6-4d2e-8364-9ee028aa8eb1
📒 Files selected for processing (12)
packages/bruno-app/src/components/VariablesEditor/index.jspackages/bruno-electron/src/ipc/network/index.jspackages/bruno-electron/tests/network/execute-request-error-handler.spec.jspackages/bruno-js/src/runtime/script-runtime.jspackages/bruno-js/tests/runtime.spec.jstests/scripting/req-api/onfail/fixtures/collection/bruno.jsontests/scripting/req-api/onfail/fixtures/collection/environments/Test.brutests/scripting/req-api/onfail/fixtures/collection/onFail.brutests/scripting/req-api/onfail/init-user-data/collection-security.jsontests/scripting/req-api/onfail/init-user-data/preferences.jsontests/scripting/req-api/onfail/req-onfail-env-variable-persistent.spec.tstests/utils/page/actions.ts
5d49d18 to
a92ea79
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@tests/scripting/req-api/onfail/fixtures/collection/onFail.yml`:
- Line 8: Update the failing request URL in the onFail fixture to use a
test-owned or runner-controlled endpoint rather than the fixed port 9999. Ensure
the endpoint is guaranteed to refuse or fail the connection during the test so
req.onFail is invoked deterministically, while preserving the existing request
path and failure scenario.
🪄 Autofix
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 Plus
Run ID: b178f5d6-445c-4565-a538-091f5439315f
📒 Files selected for processing (8)
packages/bruno-app/src/components/VariablesEditor/index.jspackages/bruno-js/src/runtime/script-runtime.jstests/scripting/req-api/onfail/fixtures/collection/environments/Test.ymltests/scripting/req-api/onfail/fixtures/collection/onFail.ymltests/scripting/req-api/onfail/fixtures/collection/opencollection.ymltests/scripting/req-api/onfail/init-user-data/global-environments.jsontests/scripting/req-api/onfail/req-onfail-env-variable-persistent.spec.tstests/utils/page/locators.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/bruno-js/src/runtime/script-runtime.js
- packages/bruno-app/src/components/VariablesEditor/index.js
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/scripting/req-api/onfail/req-onfail-env-variable-persistent.spec.ts (1)
7-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep E2E fixtures under the test fixture directory.
FIXTURE_DIRpoints topackages/bruno-tests/workspaces/onfail, nottests/scripting/req-api/onfail/fixtures. Move the workspace fixture under the test'sfixturesdirectory and update the path reference.As per path instructions, fixtures used by
tests/**should be nested under the matchingfixturesdirectory.🤖 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 `@tests/scripting/req-api/onfail/req-onfail-env-variable-persistent.spec.ts` around lines 7 - 12, Move the onfail workspace fixture from packages/bruno-tests/workspaces/onfail into tests/scripting/req-api/onfail/fixtures, then update FIXTURE_DIR to reference the relocated fixture while preserving the existing workspaceFixturePath setup.Source: Path instructions
🤖 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-tests/workspaces/onfail/onfail-collection/onFail.yml`:
- Around line 6-8: Replace the fixed port in the onFail test setup with a
dynamically allocated loopback port by starting a test-owned server via
server.listen(0, '127.0.0.1'), then inject the assigned port into the request
URL in onFail.yml while preserving the intentionally unreachable-path behavior.
---
Nitpick comments:
In `@tests/scripting/req-api/onfail/req-onfail-env-variable-persistent.spec.ts`:
- Around line 7-12: Move the onfail workspace fixture from
packages/bruno-tests/workspaces/onfail into
tests/scripting/req-api/onfail/fixtures, then update FIXTURE_DIR to reference
the relocated fixture while preserving the existing workspaceFixturePath setup.
🪄 Autofix
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 Plus
Run ID: c779d6b7-7cf2-4d03-a93e-2b6fc6e0fda1
📒 Files selected for processing (11)
packages/bruno-cli/src/runner/run-single-request.jspackages/bruno-cli/tests/integration/run-onfail-persistence.spec.jspackages/bruno-tests/workspaces/onfail/environments/Global.ymlpackages/bruno-tests/workspaces/onfail/onfail-collection/bruno.jsonpackages/bruno-tests/workspaces/onfail/onfail-collection/environments/Test.ymlpackages/bruno-tests/workspaces/onfail/onfail-collection/onFail.ymlpackages/bruno-tests/workspaces/onfail/onfail-collection/opencollection.ymlpackages/bruno-tests/workspaces/onfail/workspace.ymltests/scripting/req-api/onfail/init-user-data/collection-security.jsontests/scripting/req-api/onfail/init-user-data/preferences.jsontests/scripting/req-api/onfail/req-onfail-env-variable-persistent.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/scripting/req-api/onfail/init-user-data/collection-security.json
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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-cli/tests/integration/helpers/tmp-dir.js`:
- Around line 19-21: Update the temporary-directory setup helper around
createTmpDir and fs.cpSync to catch copy failures, remove tmpDir synchronously,
and rethrow the original error. Preserve the existing successful return path and
ensure cleanup occurs before the error propagates.
In `@packages/bruno-cli/tests/integration/run-onfail-persistence.spec.js`:
- Around line 37-40: Capture the result returned by runCli in the run-onfail
persistence test and assert its exit code matches the documented status for the
handled connection failure before validating persisted files. Make the assertion
clearly identify the CLI execution behavior under test.
In
`@tests/scripting/req-api/onfail/fixtures/workspace/onfail-collection/onFail.yml`:
- Around line 6-8: Update the onFail fixture’s request URL to use a
deterministic, test-controlled failure endpoint rather than the hardcoded
127.0.0.1:59999 address. Ensure the endpoint is explicitly unreachable or served
by a disposable test server under harness control so the request consistently
exercises req.onFail.
🪄 Autofix
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 Plus
Run ID: 3659dad3-2081-42bd-a93d-ba3ec084d884
📒 Files selected for processing (13)
packages/bruno-cli/src/runner/run-single-request.jspackages/bruno-cli/tests/integration/helpers/tmp-dir.jspackages/bruno-cli/tests/integration/run-onfail-persistence.spec.jstests/scripting/req-api/onfail/fixtures/workspace/environments/Global.ymltests/scripting/req-api/onfail/fixtures/workspace/onfail-collection/bruno.jsontests/scripting/req-api/onfail/fixtures/workspace/onfail-collection/environments/Test.ymltests/scripting/req-api/onfail/fixtures/workspace/onfail-collection/onFail.ymltests/scripting/req-api/onfail/fixtures/workspace/onfail-collection/opencollection.ymltests/scripting/req-api/onfail/fixtures/workspace/workspace.ymltests/scripting/req-api/onfail/req-onfail-env-variable-persistent.spec.tstests/utils/page/actions.tstests/utils/page/collection/collection-header.tstests/utils/page/locators.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/bruno-cli/src/runner/run-single-request.js
- tests/utils/page/actions.ts
- tests/utils/page/locators.ts
* fix(scripting): preserve variables set in onFail * test(scripting): cover onFail variable propagation --------- Co-authored-by: Elon <[email protected]>
… utilities for tests and addressed review comments
…e runCli results in onFail persistence tests
7cffdf0 to
2079224
Compare
… remove redundant openVariablesTab function
…r error message visibility
BRU-3948
Description
Worked on top of #8575. Verified the implementation there — it works as expected and the changes look good. Only the E2E coverage was missing, so this PR adds it.
Problem
When a request fails at the connection level (wrong URL, unreachable host, etc.), the
req.onFailhandler did run, but the variables it set were never applied — they were computed and dropped. #8575 fixed that, but there were no E2E tests guarding the behaviour, so a regression would go unnoticed.Fix
The fix in #8575 propagates the handler's result through:
This PR adds an E2E test for exactly that path: a fixture collection whose request points at an unreachable port, with a pre-request script that seeds
var/envVar/globalEnvVarin the main body and overwrites them inside the handler. After sending, the Variables tab is checked to confirm the runtime and environment values were actually updated. Two supporting changes were needed to assert on them —VariablesEditorhad nodata-testids, so its sections and rows are now addressable, and a sharedopenVariablesTabaction was added to the page helpers.Screenshots
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
Bug Fixes
onFailhandlers so variable updates persist after failed requests.onFailresults are correctly returned and applied.Tests