Inso CLI fails to render a request triggered by Request Chaining which uses an environment variable only present in sub environment
- Dominant language
- TypeScript
- Stars
- 40k
- Forks
- 2.4k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 61
Description
### Expected Behavior
The Inso CLI should behave the same as the Insomia client and successfully run dependent requests which use environment variables only present in a selected sub environment.
I have set up a repository for reproducing the issue: https://github.com/finlaycurran/inso-env-bug
It sets up two requests, an environment, and test suite as follows:
```
POST https://petstore.swagger.io/{{_.version}}/pet
GET https://petstore.swagger.io/{{_.version}}/pet/{% response 'body', 'req_6758d4d7e56b445485d0832034d613f7', 'b64::JC5pZA==::46b', 'no-history', 60 %}
(where the request referenced from the GET is the POST request)
```
Base Env:
```
{}
```
Test Sub Env:
```
{
"version": "v2"
}
```
A single test suite with one test calling the GET request above, and checking for 200 response.
I would expect that calling `inso run test inso-env-bug.yaml --env "Test Sub Env"` would:
1. Try to call the GET request
2. Detect the use of `response` and therefore trigger a call to the POST, correctly using "v2" for "version", as specified in the sub environment.
3. This call to POST succeeding
4. The GET request then running as successfully using the "id" value from the preceding POST call.
### Actual Behavior
Inso CLI gives an error:
```
➜ inso-env-bug git:(main) inso run test inso-env-bug.yaml --env "Test Sub Env"
No workspace parentId found for wrk_a2965cc67d854a459dbe992a313ad01b setting default proj_default-project
Get Pet Test
1) Get Added Pet
0 passing (57ms)
1 failing
1) Get Pet Test
Get Added Pet:
Error: Failed to render request: req_334743dcff54449b92a1d3fd6f5e0ca2
at tryToInterpolateRequest (/snapshot/insomnia/packages/insomnia-send-request/dist/index.js)
at async Insomnia.sendRequest (/snapshot/insomnia/packages/insomnia-send-request/dist/index.js)
at async Insomnia.send (/snapshot/insomnia/packages/insomnia-testing/dist/run/insomnia.js)
at async Context. (/private/var/folders/0p/dr_g40153lzbdph_lq0m4llc0000gn/T/insomnia-testing/0.7311933535869273-test.ts:10:23)
```
In Insomnia 2023.2.0 the test suite runs as expected, correctly calling the POST request and then the GET request.
I have looked into this in a little more detail and it appears the issue is that the POST request, which is triggered by the GET request, is failing to be rendered because when it tries to resolve `_.version` it returns null or undefined. This appears to be because it is only using values from the base environment, not the specified sub environment.
If I add `{ "version": "v2" }` to the base environment, the CLI call completes with no errors.
### Reproduction Steps
1. Clone the repository at https://github.com/finlaycurran/inso-env-bug
2. `cd` into it
3. Run `inso run test inso-env-bug.yaml --env "Test Sub Env"`
### Is there an existing issue for this?
- [X] I have searched the [issue tracker](https://www.github.com/Kong/insomnia/issues) for this problem.
### Additional Information
_No response_
### Insomnia Version
3.14.0 and 2023.2.0
### What operating system are you using?
macOS
### Operating System Version
macOS Ventura Version 13.1 (22C65)
### Installation method
homebrew. Also tried building inso from source.
### Last Known Working Insomnia version
_No response_
Contributor guide
Research direction
Clone the linked reproduction repository and run `inso run test inso-env-bug.yaml --env "Test Sub Env"`; start by tracing the Inso CLI request-rendering path for the chained POST request and selected environment resolution. Done means the POST resolves `version` from `Test Sub Env`, the dependent GET runs, and the test reports 200 with no rendering error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100