Skip to content

Commit afc84cf

Browse files
authored
[recorder] Asset sync migration guide (Azure#24750)
1 parent bc2030f commit afc84cf

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Migrating recordings to the `azure-sdk-assets` repository
2+
3+
## Some background
4+
5+
Recordings take up a large amount of space in our repository and generate a lot of churn. The asset sync project, owned by our Engineering System team, is a solution to this problem. Leveraging and extending the existing test proxy, the asset sync extension adds support for moving the recordings outside of the main azure-sdk-for-js repo.
6+
7+
## Performing the migration
8+
9+
The package you are migrating needs to be using the new version of the recorder that uses the test proxy (`@azure-tools/test-recorder@^2.0.0`). Most packages are using the new recorder already; if yours is not you should migrate as soon as possible. More detail on migrating to the new recorder can be found in the [recorder 2.0 migration guide]. To run the migration script, you will need both [Powershell] and [`dev-tool`] installed. If you haven't installed `dev-tool` yet, you can install it as follows:
10+
11+
```bash
12+
$ cd common/tools/dev-tool # (from your azure-sdk-for-js repo root)
13+
$ npm install -g
14+
```
15+
16+
```bash
17+
$ npx dev-tool test-proxy migrate --initial-push
18+
```
19+
20+
Once this is done, validate that your recorded tests still pass, and create a PR with the changes. That's it!
21+
22+
## Workflow with asset sync enabled
23+
24+
With asset sync enabled, there is one extra step that must be taken before you create a PR with changes to recorded tests: you must push the new recordings to the assets repo. This is done with the following command:
25+
26+
```bash
27+
$ npx dev-tool test-proxy push
28+
```
29+
30+
This command will:
31+
32+
1. Push your local recordings to a tag in the `Azure/azure-sdk-assets` repo, and
33+
1. Update the `assets.json` in your package root to reference the newly created tag.
34+
35+
You should stage and commit the `assets.json` update as part of your PR. If you don't run the `push` command before creating a PR, the CI (and anyone else who tries to run your recorded tests) will use the old recordings, which will cause failures.
36+
37+
This diagram describes the new workflow (new steps highlighted):
38+
39+
```mermaid
40+
graph TD
41+
record[Record tests<pre>TEST_MODE=record rushx test</pre>] -->
42+
playback[Inspect recordings and test in playback<pre>TEST_MODE=playback rushx test</pre>]
43+
44+
playback -- Tests don't work, re-record --> record
45+
playback -- Tests pass in playback\nand are properly sanitized --> push
46+
47+
subgraph New steps
48+
push[Push recordings to asset sync repo<pre>npx dev-tool test-proxy push</pre>] -->
49+
assets[Commit <code>assets.json</code> change]
50+
end
51+
52+
assets --> pr[Push branch and\ncreate PR]
53+
```
54+
55+
### Inspecting recordings with asset sync enabled
56+
57+
Often, when re-recording tests, you will want to inspect the recordings that have been made, either to debug something or to make sure secrets have been sanitized properly. With asset sync enabled, the recordings are no longer stored in the same place as your SDK. You'll need to follow the following process to find them:
58+
59+
1. Navigate to the root of the `azure-sdk-for-js` repo.
60+
1. Go into the `.assets` directory. This will contain a file called `.breadcrumb`; open it and find the entry that matches your SDK. This will give you the name of the directory within `.assets` that your recordings are located in.
61+
1. Once in that directory, you can do a `git status` to see what uncommitted changes you have made to the recordings, and you can inspect the recordings in whatever way you'd like.
62+
63+
There is an [open issue](https://github.com/Azure/azure-sdk-tools/issues/4652) to streamline this process by providing tooling to get you to the right directory without you having to look inside the `.breadcrumb` file. Watch this space.
64+
65+
For more information on this topic, see the [asset sync reference documentation][asset-sync-reference].
66+
67+
### Other `test-proxy` commands
68+
69+
A few commands have been added to `dev-tool` to facilitate pushing and fetching the recordings to and from your local:
70+
71+
- `dev-tool test-proxy push`: use this command to push recordings to the assets repo when you have finished re-recording. This command will push your changes to the assets repo and update the tag in `assets.json` to reference the newly pushed recordings. The change to `assets.json` must be checked in for the test proxy to use the new recordings outside of your local environment.
72+
- `dev-tool test-proxy restore`: this command will pull the recordings from the assets repo that are referenced in your `assets.json`. Typically this will be done automatically when you first run recorded tests if the recordings haven't been downloaded already, but you can run this command in advance if you'd like to download them earlier, for example for offline work.
73+
- `dev-tool test-proxy reset`: if you've made any changes to the recordings locally, you can use this to revert those local changes and reset to what is currently checked in to the assets repo. This is a destructive operation and if you have local changes it will prompt you before removing your work.
74+
- `dev-tool test-proxy migrate`: used for migrating existing recordings to the assets repo as described above.
75+
76+
### Working offline
77+
78+
Offline work is supported out-of-the-box. Of course, however, you won't be able to push or pull from the assets repo while offline. You can fetch recordings from the assets repo by running `npx dev-tool test-proxy restore`. This will download the recordings (and the test proxy executable, if you haven't got that already), making them ready for you to run tests with.
79+
80+
## Further reading
81+
82+
- [Asset Sync reference in azure-sdk-tools][asset-sync-reference]
83+
- [Recorder 2.0 migration guide]
84+
85+
[recorder 2.0 migration guide]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/test-utils/recorder/MIGRATION.md
86+
[asset-sync-reference]: https://github.com/Azure/azure-sdk-tools/tree/main/tools/test-proxy/documentation/asset-sync
87+
[powershell]: https://github.com/PowerShell/PowerShell
88+
[`dev-tool`]: https://github.com/Azure/azure-sdk-for-js/tree/main/common/tools/dev-tool#installation

0 commit comments

Comments
 (0)