## Re-runs for or8n

### The idea

1. on rerun`npx currents api get-run` loads failing test ids for all known specs and writes them to `test-results/.last-run.json`
2. orchestration discovery reporters runs playwright with `--last-failed` flag and uses `.last.run.json` files
3. the orchestration is created, the tasks are added to queue
4. for each task
   1. obtain test ids for the current or8n task:
      - get from full test suite only the test ids the specs + group included in the task
      - it will be only failed test ids because the full test suite was created from "last run" file generated by the api request.
   2. re-write the "last run" file using the filtered test ids
   3. execute the pw test command for the task with `-last-failed` flag, so it will use the filtered test ids not the entire spec
5. restore the original `.last-run.json` file

### Testing locally

1. run `cd currents-playwright` and `npm run dev`
2. in another tab:
   1. run `cd e2e-examples/or8n-results`
   2. run `pwc` command to generate the initial `.last-run.json` with all test ids - `CURRENTS_API_URL=https://cy-staging.currents.dev npx pwc --key xxx --project-id yyy --ci-build-id date +%s` . This will result in the same output as running the `npx currents api get-run` command
   3. run `pwc-p` command with `--last-failed` - `CURRENTS_API_URL=https://cy-staging.currents.dev npx pwc-p --key xxx --project-id yyy --ci-build-id date +%s --last-failed`.
3. analyze:
   - how `.last-run.json` is changing
   - what tests are executed for each or8n task
   - what test records are created
