Commit fe81867
authored
Switch context by test (#204)
# Summary
This PR helps in switching to a proper context/variant by specifying a
test mark or full task's evergreen url.
It solves a source of friction in our day-to-day workflows, which is
finding which context to switch to in order to run a particular test.
And by being able to switch context by specifying evergreen task's url
we're a step closer to having automation that reruns a failed script
locally.
## Current workflow
To find a context to run the test locally we often start from two
places:
1. Starting from Evergreen UI (easier): look at the evergreen variant in
the evergreen UI, copy it and run `make switch context=<copied variant>`
or use interactive fzf-powered `make switch` (without args), paste or
type the variant and press enter.
2. Starting from an e2e test file (harder): find a `@pytest.mark` in the
file, copy it, go to evergreen.yml, find a task group containing that
file, copy its name, then find a variant where that task group is used,
copy variant name, run `make switch context=<copied variant>`...
## Proposed workflow
`make switcht` is a new tool which is a supercharged `make switch`. It's
named similarly (typing `make switch` is kind of a muscle memory now)
and works in two modes:
1. With explicit test mark/url on `test=` argument:
- `make switcht test=<test>`, where `<test>` is a pytest mark (e.g.
`e2e_replica_set`) - it will list all the variants that this test is
running in to be picked with `fzf`
- `make switcht test=<task url>`, where `<task url>` is a full url to
the evergreen test - it will switch directly to the variant from that
test
2. Without specifying test argument, which works in a similar
interactive way like `make switch`, but lists first all test files with
their marks to fuzzy-find the test, which then is used to list pick its
variants: `make switcht`
## Requirements
It requires:
- [fzf](https://github.com/junegunn/fzf) - for the interactive fuzzy
finder (we already use it for `make switch`)
- [ripgrep](https://github.com/BurntSushi/ripgrep) - to *quickly* list
all the pytest marks in all e2e test files
- Having evg credentials in env vars, e.g. in your
`scripts/dev/contexts/private-context`
```
EVERGREEN_USER=$(cat ~/.evergreen.yml | yq .user)
EVERGREEN_API_KEY=$(cat ~/.evergreen.yml | yq .api_key)
```
## Changes
Majority of the implementation is in two places:
- `scripts/dev/switch_context_by_test.sh` - it's mostly for `fzf`,
finding pytest marks using `rg`. It calls
scripts/python/find_test_variants.py
- scripts/python/find_test_variants.py - a new python script that lists
all the variants of a pytest's mark (`--task-name`) or a variant from a
full evg task url (`--task-url`)
- introduced scripts/python directory, to limit proliferation of python
scripts in random directories. Having them in one place makes it easier
to import/run them as modules
- refactored some evergreen API helpers into
scripts/python/evergreen_api.py
- some minor, random changes improving debuggability of bash scripts
## Proof of Work
Here are some examples for the most common use cases:
**With explicit test= parameter**
- Switch to one of test's context by pytest mark: `make switcht
test=e2e_replica_set`

- Switch to context by test's url: `make switcht
test='https://spruce.mongodb.com/task/[...]/logs?execution=0'`

**Without any parameters (fully interactive)**
- Switch to context by fuzzy-searching a test first: `make switcht`

- Switch to context by pasting full file path into test picker: `make
switcht`

- Switch to context by pasting full url into fzf picker: `make switcht`

Afterwards, if the context needs to be regenerated again just run `make
switch` (without t) + enter - it will remember last switched context and
be selected first.
## Checklist
- [ ] Have you linked a jira ticket and/or is the ticket in the title?
- [ ] Have you checked whether your jira ticket required DOCSP changes?
- [ ] Have you checked for release_note changes?
## Reminder (Please remove this when merging)
- Please try to Approve or Reject Changes the PR, keep PRs in review as
short as possible
- Our Short Guide for PRs:
[Link](https://docs.google.com/document/d/1T93KUtdvONq43vfTfUt8l92uo4e4SEEvFbIEKOxGr44/edit?tab=t.0)
- Remember the following Communication Standards - use comment prefixes
for clarity:
* **blocking**: Must be addressed before approval.
* **follow-up**: Can be addressed in a later PR or ticket.
* **q**: Clarifying question.
* **nit**: Non-blocking suggestions.
* **note**: Side-note, non-actionable. Example: Praise
* --> no prefix is considered a question1 parent 789b071 commit fe81867
File tree
13 files changed
+300
-27
lines changed- scripts
- dev
- contexts
- evergreen
- funcs
- python
13 files changed
+300
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | | - | |
53 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
Lines changed: 5 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 21 | + | |
25 | 22 | | |
26 | | - | |
| 23 | + | |
27 | 24 | | |
28 | 25 | | |
| 26 | + | |
29 | 27 | | |
30 | | - | |
31 | 28 | | |
32 | 29 | | |
33 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 3 | | |
10 | 4 | | |
11 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
15 | 8 | | |
16 | 9 | | |
17 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments