fix: apply specific environment when sending requests in the template - #8780
Conversation
…est-uses-environment
There was a problem hiding this comment.
Pull Request Overview
This PR resolves an environment rendering error by ensuring that the proper environment is applied when sending requests from templates. Key changes include unifying the request data fetching functions, adding an optional environmentId parameter to the network request calls, and updating related type definitions and tests.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/insomnia/src/ui/components/templating/local-template-tags.ts | Passes environmentId when sending requests from templates to fix environment render errors. |
| packages/insomnia/src/templating/types.ts | Updates type definitions for sendRequest to include an optional environmentId. |
| packages/insomnia/src/plugins/context/network.ts | Updates the sendRequest method to forward the environmentId parameter. |
| packages/insomnia/src/network/network.ts | Modifies fetchRequestData to utilize the overrideEnvironmentId parameter and adjust the returned activeEnvironmentId. |
| packages/insomnia/src/common/send-request.ts | Refactors to use fetchRequestData instead of the outdated fetchInsoRequestData. |
| packages/insomnia-inso/* | Minor updates and additions to tests and fixtures ensuring consistency with the environment changes. |
Comments suppressed due to low confidence (2)
packages/insomnia/src/ui/components/templating/local-template-tags.ts:668
- Ensure that the variable 'environmentId' is defined in this scope before being used in the sendRequest call (it is referenced on lines 670-672) to avoid potential runtime errors.
response = await context.network.sendRequest(request, { requestChain });
packages/insomnia/src/network/network.ts:227
- Consider returning the calculated activeEnvironmentId (derived from overrideEnvironmentId or workspaceMeta) instead of always using environment._id to preserve the intended override behavior.
activeEnvironmentId: environment._id,
jackkav
left a comment
There was a problem hiding this comment.
I worry a bit about creating a new way to set an environmentId, as I feel there might be another but I could be wrong. Nice job cutting down the fetchRequestData drift.
Yeah, good point. I think maybe we can set the environmentId into the workspace and override the one in the workspace meta in the database, then we don't need to carry the environmentId across the entire process. Not sure about the effort and risk, maybe we can consider it when we meet another related issue/requirement. |
…est-uses-environment
Background
INS-5180
When running tests via the Inso CLI, users need to specify the environment. The request sent from the test via
insomnia.sendrespects the specific environment, but the request sent from the template doesn't. Which leads to theenvironment render error.Changes
fetchInsoRequestDataandfetchRequestDatato avoid inconsistent issuesenvironmentIdwhen sending requests in the template