[PR #5858] fix(cli): persist cookies across sequential requests in collection runner #5384

Open
opened 2026-03-17 02:50:09 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5858
Author: @FerreiraAdrien
Created: 2/10/2026
Status: 🔄 Open

Base: mainHead: fix/cli-cookie-persistence


📝 Commits (2)

  • 95de811 fix(cli): persist cookies across sequential requests in collection runner
  • 088d498 fix(cli): merge cookie jar with user-specified Cookie header instead of overwriting

📊 Changes

7 files changed (+76 additions, -15 deletions)

View changed files

📝 packages/hoppscotch-cli/src/interfaces/response.ts (+2 -0)
📝 packages/hoppscotch-cli/src/types/request.ts (+2 -0)
📝 packages/hoppscotch-cli/src/utils/collections.ts (+11 -3)
📝 packages/hoppscotch-cli/src/utils/hopp-fetch.ts (+2 -2)
📝 packages/hoppscotch-cli/src/utils/pre-request.ts (+4 -2)
📝 packages/hoppscotch-cli/src/utils/request.ts (+49 -5)
📝 packages/hoppscotch-cli/src/utils/test.ts (+6 -3)

📄 Description

What's changed

When running hopp test on a collection, Set-Cookie headers received from responses (e.g. after a login request) were neither stored nor sent with subsequent requests. This caused endpoints requiring cookie-based authentication to fail with 401.

Root cause requestRunner used bare axios() without a cookie jar, and each createHoppFetchHook() call (for pre-request/test scripts) created its own ephemeral CookieJar.

Fix A shared CookieJar (tough-cookie, already a dependency) is created per iteration in collectionsRunner and propagated through the entire execution chain:

  • collectionsRunnerprocessCollectionprocessRequest{preRequestScriptRunner, requestRunner, getTestScriptParams}createHoppFetchHook

Changes:

  • utils/hopp-fetch.ts — Accept an optional external CookieJar
  • types/request.ts — Add cookieJar? to ProcessRequestParams
  • interfaces/response.ts — Add cookieJar? to TestScriptParams
  • utils/request.ts — Inject cookies before requests, store Set-Cookie after responses (success & error paths), pass jar through processRequest
  • utils/pre-request.ts — Propagate jar to createHoppFetchHook
  • utils/test.ts — Propagate jar to createHoppFetchHook
  • utils/collections.ts — Create one CookieJar per iteration, pass it down

Notes to reviewers

  • All new parameters are optional (?) and appended at the end of signatures — no breaking changes.
  • The jar is scoped per iteration (reset alongside envs), which is consistent with existing iteration semantics.
  • When no jar is provided (e.g., external callers), behavior is identical to before (externalJar ?? new CookieJar() fallback in hopp-fetch.ts, if (cookieJar) guards in requestRunner).
  • All 140 existing tests pass with no modifications needed.

Summary by cubic

Fixes cookie persistence in the CLI collection runner so cookies set by earlier requests are sent with later ones. This enables cookie-based auth flows to work within each collection iteration.

  • Bug Fixes
    • Use one shared CookieJar per iteration; pass it through pre-request, request, and test runners.
    • requestRunner injects cookies before requests, merging with any user-specified Cookie header; stores Set-Cookie from success and error responses.
    • createHoppFetchHook accepts an optional external CookieJar for pre-request and test sandboxes.
    • All new params are optional; no breaking changes when no jar is provided.

Written for commit 088d498ddb. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5858 **Author:** [@FerreiraAdrien](https://github.com/FerreiraAdrien) **Created:** 2/10/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/cli-cookie-persistence` --- ### 📝 Commits (2) - [`95de811`](https://github.com/hoppscotch/hoppscotch/commit/95de8111704e777df468b801593f4a727fd81fe9) fix(cli): persist cookies across sequential requests in collection runner - [`088d498`](https://github.com/hoppscotch/hoppscotch/commit/088d498ddbbe9536f7fea211945da07b39b429b0) fix(cli): merge cookie jar with user-specified Cookie header instead of overwriting ### 📊 Changes **7 files changed** (+76 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-cli/src/interfaces/response.ts` (+2 -0) 📝 `packages/hoppscotch-cli/src/types/request.ts` (+2 -0) 📝 `packages/hoppscotch-cli/src/utils/collections.ts` (+11 -3) 📝 `packages/hoppscotch-cli/src/utils/hopp-fetch.ts` (+2 -2) 📝 `packages/hoppscotch-cli/src/utils/pre-request.ts` (+4 -2) 📝 `packages/hoppscotch-cli/src/utils/request.ts` (+49 -5) 📝 `packages/hoppscotch-cli/src/utils/test.ts` (+6 -3) </details> ### 📄 Description ### What's changed When running `hopp test` on a collection, `Set-Cookie` headers received from responses (e.g. after a login request) were neither stored nor sent with subsequent requests. This caused endpoints requiring cookie-based authentication to fail with 401. **Root cause** `requestRunner` used bare `axios()` without a cookie jar, and each `createHoppFetchHook()` call (for pre-request/test scripts) created its own ephemeral `CookieJar`. **Fix** A shared `CookieJar` (tough-cookie, already a dependency) is created per iteration in `collectionsRunner` and propagated through the entire execution chain: - `collectionsRunner` → `processCollection` → `processRequest` → `{preRequestScriptRunner, requestRunner, getTestScriptParams}` → `createHoppFetchHook` Changes: - [x] `utils/hopp-fetch.ts` — Accept an optional external `CookieJar` - [x] `types/request.ts` — Add `cookieJar?` to `ProcessRequestParams` - [x] `interfaces/response.ts` — Add `cookieJar?` to `TestScriptParams` - [x] `utils/request.ts` — Inject cookies before requests, store `Set-Cookie` after responses (success & error paths), pass jar through `processRequest` - [x] `utils/pre-request.ts` — Propagate jar to `createHoppFetchHook` - [x] `utils/test.ts` — Propagate jar to `createHoppFetchHook` - [x] `utils/collections.ts` — Create one `CookieJar` per iteration, pass it down ### Notes to reviewers - All new parameters are **optional** (`?`) and appended at the end of signatures — no breaking changes. - The jar is scoped per iteration (reset alongside envs), which is consistent with existing iteration semantics. - When no jar is provided (e.g., external callers), behavior is identical to before (`externalJar ?? new CookieJar()` fallback in `hopp-fetch.ts`, `if (cookieJar)` guards in `requestRunner`). - All 140 existing tests pass with no modifications needed. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes cookie persistence in the CLI collection runner so cookies set by earlier requests are sent with later ones. This enables cookie-based auth flows to work within each collection iteration. - **Bug Fixes** - Use one shared CookieJar per iteration; pass it through pre-request, request, and test runners. - requestRunner injects cookies before requests, merging with any user-specified Cookie header; stores Set-Cookie from success and error responses. - createHoppFetchHook accepts an optional external CookieJar for pre-request and test sandboxes. - All new params are optional; no breaking changes when no jar is provided. <sup>Written for commit 088d498ddbbe9536f7fea211945da07b39b429b0. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5384
No description provided.