Clarify how to work with VCR

This commit is contained in:
Jorge Manrubia
2025-07-25 14:56:03 +02:00
parent 539f83eaee
commit 8b2ecfcec2
+18
View File
@@ -41,10 +41,28 @@ Comment.find_each(&:refresh_search_embedding)
### Tests ### Tests
#### AI Requests
For testing OpenAI API requests, we use [VCR](https://github.com/vcr/vcr). If you want to test AI features exercising the API, you need to place the `config/credentials/test.key` For testing OpenAI API requests, we use [VCR](https://github.com/vcr/vcr). If you want to test AI features exercising the API, you need to place the `config/credentials/test.key`
that you can get from 1Password in "Fizzy - test.key". Then, when running tests that use Open AI API, you must either set the env variable `VCR_RECORD=1` that you can get from 1Password in "Fizzy - test.key". Then, when running tests that use Open AI API, you must either set the env variable `VCR_RECORD=1`
or to add `vcr_record!` to the test. See `VcrTestHelper`. Due to Open AI quotas, you may need to limit the parallelization. E.g: `PARALLEL_WORKERS=2` or to add `vcr_record!` to the test. See `VcrTestHelper`. Due to Open AI quotas, you may need to limit the parallelization. E.g: `PARALLEL_WORKERS=2`
You can regenerate all the VCR fixtures with:
```bash
VCR_RECORD=1 PARALLEL_WORKERS=2 bin/rails test
```
A typical scenario is making modifications LLM prompts. You need to:
1. Make the prompt changes.
2. Run the test with `VCR_RECORD=1` set.
3. Make sure that the test passes by running the test normally (without setting VCR_RECORD=1).
4. Commit the YML fixtures that VCR has generated. That way, the next time you run the test, it will run fast without performing any request.
Notice that if you pass changing data to the prompt, this mechanism won't work. E.g: if you pass data timestamps.
You need to make sure those timestamps are always the same across executions.
## Environments ## Environments
Fizzy is deployed with Kamal. You'll need to have the 1Password CLI set up in order to access the secrets that are used when deploying. Provided you have that, it should be as simple as `bin/kamal deploy` to the correct environment. Fizzy is deployed with Kamal. You'll need to have the 1Password CLI set up in order to access the secrets that are used when deploying. Provided you have that, it should be as simple as `bin/kamal deploy` to the correct environment.