Skip to content

Commit 03bee13

Browse files
timovvazure-sdk
authored andcommitted
Live and recorded tests skill
1 parent dc4e893 commit 03bee13

10 files changed

Lines changed: 289 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
name: azsdk-common-live-and-recorded-tests
3+
license: MIT
4+
metadata:
5+
version: "0.1.0"
6+
distribution: shared
7+
description: "Deploy test resources and run Azure SDK tests in live, record, or playback mode. WHEN: \"run live tests\", \"run recorded tests\", \"deploy test resources\", \"record tests\", \"run tests in record mode\", \"clean up test resources\", \"run tests against live resources\". DO NOT USE FOR: writing new tests, authoring Bicep templates, playback-only test runs without resource deployment. INVOKES: azure-sdk-mcp:azsdk_package_run_tests."
8+
compatibility:
9+
requires: "azure-sdk-mcp server, Azure PowerShell (Az module), local azure-sdk-for-{language} clone"
10+
---
11+
12+
# Live and Recorded Tests
13+
14+
## MCP Tools
15+
16+
| Tool | Purpose |
17+
|------|---------|
18+
| `azure-sdk-mcp:azsdk_package_run_tests` | Run tests in playback, record, or live mode |
19+
20+
## Prerequisites
21+
22+
- azure-sdk-mcp server must be running
23+
- Azure PowerShell module (`Az`) installed
24+
- For live/record modes: an Azure subscription with permissions to create resources
25+
- Use the Azure SDK Test Resources - TME (id: 4d042dc6-fe17-4698-a23f-ec6a8d1e98f4) subscription if not already authenticated and no other subscription is specified.
26+
27+
## Steps
28+
29+
1. **Identify service directory** — Determine the service directory for the package under test (e.g., `keyvault`, `storage`). This is required by the test resource deployment script.
30+
2. **Check for existing deployment** — Look for a `.env` file at the service directory level (next to `test-resources.bicep`). If one exists, inform the user that a previous deployment appears to be available and ask whether to **reuse the existing deployment** or **redeploy test resources**. If reusing, skip to step 7.
31+
3. **Verify Azure context** — Run `Get-AzContext` to check for an active Azure PowerShell session. If no context exists, guide the user through `Connect-AzAccount`. Confirm the correct subscription is selected.
32+
4. **Confirm deployment** — Even if no existing `.env` file is found, confirm with the user before proceeding to deploy test resources. Deployment creates Azure resources that may incur costs.
33+
5. **Deploy test resources** — Run `eng/common/TestResources/New-TestResources.ps1` with the service directory and any user-provided parameters. See [deployment parameters](references/test-resource-deployment.md) for details. The script outputs environment variables needed for live/record test runs.
34+
6. **Save environment** — Capture the environment variables output by the deployment script. If the script writes a `.env` file, note its path. Otherwise, collect the environment variables from the script output.
35+
7. **Run tests** — Run `azure-sdk-mcp:azsdk_package_run_tests` with the appropriate test mode (`record`, `live`, or `playback`) and the path to the `.env` file containing test environment variables. When tests run in record mode and all tests pass, the tool automatically pushes recorded test assets to the assets repo.
36+
8. **Clean up** — Ask the user whether to clean up test resources. If yes, run `eng/common/TestResources/Remove-TestResources.ps1`. If no, inform the user that resources remain deployed for subsequent test runs. See [cleanup details](references/test-resource-cleanup.md).
37+
38+
## Examples
39+
40+
- "Deploy test resources and run live tests for this package"
41+
- "Run the tests in record mode using the live test deployment specified in .env"
42+
- "Clean up my test resources for keyvault"
43+
- "Run tests in record mode against my existing deployment"
44+
- "Set up live test resources for storage and run all tests"
45+
46+
## Troubleshooting
47+
48+
- **No Azure context:** Run `Connect-AzAccount` and select the target subscription with `Set-AzContext -SubscriptionId <id>`.
49+
- **Deployment fails with auth error:** Verify that the signed-in account has Contributor or Owner role on the target subscription. Check `Get-AzContext` output.
50+
- **Deployment fails with resource conflict:** A previous deployment may still exist. Try running `Remove-TestResources.ps1` first, or use a different `BaseName`.
51+
- **Tests fail in record mode:** Check that all environment variables from the deployment are being passed correctly. Verify the `.env` file path is correct.
52+
- **Assets push fails after recording:** Ensure the assets repo is configured and accessible. Check git authentication.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: azsdk-common-live-and-recorded-tests-eval
2+
description: Evaluation suite for live and recorded tests skill.
3+
skill: azsdk-common-live-and-recorded-tests
4+
version: '1.0'
5+
config:
6+
model: gpt-4o
7+
executor: mock
8+
trials_per_task: 1
9+
timeout_seconds: 600
10+
parallel: false
11+
metrics:
12+
- name: task_completion
13+
weight: 0.7
14+
threshold: 0.8
15+
description: Did the skill complete trigger and anti-trigger checks?
16+
- name: efficiency
17+
weight: 0.3
18+
threshold: 0.7
19+
description: Did the skill stay within behavior limits?
20+
graders:
21+
- type: text
22+
name: no_fatal_errors
23+
config:
24+
regex_not_match:
25+
- (?i)error occurred
26+
- (?i)failed
27+
- (?i)re-run the tool
28+
tasks:
29+
- "tasks/*.yaml"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Test Modes
2+
3+
## Overview
4+
5+
| Mode | Description | Requires Azure Resources | Records Traffic |
6+
|------|-------------|--------------------------|-----------------|
7+
| **Playback** | Runs against previously recorded HTTP interactions | No | No |
8+
| **Record** | Runs against real Azure resources and records HTTP interactions | Yes | Yes |
9+
| **Live** | Runs against real Azure resources without recording | Yes | No |
10+
11+
## Default Behavior
12+
13+
When no test mode is specified, **Playback** is the default. Playback mode does not require test resource deployment or environment variables.
14+
15+
## Record Mode
16+
17+
- Requires deployed test resources and environment variables passed via a `.env` file.
18+
- When all tests pass in record mode, the tool automatically pushes recorded test assets to the assets repo.
19+
- This is the standard workflow for creating or updating test recordings.
20+
21+
## Live Mode
22+
23+
- Requires deployed test resources and environment variables passed via a `.env` file.
24+
- Tests run against real Azure resources without recording HTTP traffic.
25+
- Useful for validating that tests work against real services without updating recordings.
26+
27+
## Playback Mode
28+
29+
- Does not require deployed Azure resources.
30+
- Tests replay previously recorded HTTP interactions via the test proxy.
31+
- This is the default mode and the fastest way to run tests locally.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Test Resource Cleanup
2+
3+
## Script Location
4+
5+
`eng/common/TestResources/Remove-TestResources.ps1`
6+
7+
## Common Parameters
8+
9+
| Parameter | Required | Description |
10+
|-----------|----------|-------------|
11+
| `ServiceDirectory` | Yes* | Service directory name (e.g., `keyvault`). Required if `ResourceGroupName` not provided. |
12+
| `-ResourceGroupName` | No | Explicit resource group name to delete |
13+
| `-Force` | No | Skip confirmation prompt |
14+
15+
*Either `ServiceDirectory` or `-ResourceGroupName` must be provided. If the test resources were deployed to the TME tenant, you must use the resource group name, which should include the `SSS3PT_` prefix as output by the test resource creation script.
16+
17+
## Usage Examples
18+
19+
### Basic cleanup
20+
21+
```powershell
22+
eng/common/TestResources/Remove-TestResources.ps1 keyvault -Force
23+
```
24+
25+
### Cleanup by resource group name
26+
27+
```powershell
28+
eng/common/TestResources/Remove-TestResources.ps1 `
29+
-ResourceGroupName 'rg-mytest' `
30+
-Force
31+
```
32+
33+
## Notes
34+
35+
- The script also purges purgeable resources (e.g., Key Vault soft-deleted vaults).
36+
- Any `.env` files created by `New-TestResources.ps1` are also removed.
37+
- Always ask the user before cleaning up — they may want to reuse resources for additional test runs.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Test Resource Deployment
2+
3+
## Script Location
4+
5+
`eng/common/TestResources/New-TestResources.ps1`
6+
7+
## Common Parameters
8+
9+
| Parameter | Required | Description |
10+
|-----------|----------|-------------|
11+
| `ServiceDirectory` | Yes | Service directory name under `sdk/` (e.g., `keyvault`, `storage`) |
12+
| `-OutFile` | Yes | Required for a .env file to be output. |
13+
| `-BaseName` | No | Base name for resource group (default: auto-generated) |
14+
| `-Location` | No | Azure region for deployment (default: script default) |
15+
| `-SubscriptionId` | No | Target subscription (uses current Az context if omitted) |
16+
| `-ResourceGroupName` | No | Custom resource group name |
17+
18+
## Usage Examples
19+
20+
### Basic deployment (interactive, uses current Az context)
21+
22+
```powershell
23+
Connect-AzAccount -Subscription 'SUBSCRIPTION_ID'
24+
eng/common/TestResources/New-TestResources.ps1 keyvault -OutFile
25+
```
26+
27+
### Deployment with custom parameters
28+
29+
```powershell
30+
Connect-AzAccount -Subscription 'SUBSCRIPTION_ID'
31+
eng/common/TestResources/New-TestResources.ps1 `
32+
-BaseName 'azsdk' `
33+
-ServiceDirectory 'keyvault' `
34+
-SubscriptionId 'SUBSCRIPTION_ID' `
35+
-ResourceGroupName 'rg-mytest' `
36+
-Location 'eastus'
37+
-OutFile
38+
```
39+
40+
## Output
41+
42+
The script outputs environment variables needed for live and record test runs. If `$SupportsTestResourcesDotenv=$true` in the language repo's `LanguageSettings.ps1`, a `.env` file is written next to the `test-resources.bicep` file.
43+
44+
Environment variables typically include credentials and resource endpoints needed by test frameworks.
45+
46+
## Additional Parameters
47+
48+
Some services require extra parameters (e.g., `-AdditionalParameters @{enableHsm=$true}` for Key Vault HSM tests). Check the service's `test-resources.bicep` or `test-resources.json` for required parameters.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
id: live-tests-negative-002
2+
name: Anti-Trigger - Write New Tests
3+
description: |
4+
Test that the skill does NOT activate when the user wants to
5+
author new test cases rather than run existing tests.
6+
tags:
7+
- negative-test
8+
- anti-trigger
9+
inputs:
10+
prompt: "Help me write unit tests for my new Azure SDK client"
11+
expected:
12+
output_not_contains:
13+
- "New-TestResources"
14+
- "azsdk_package_run_tests"
15+
- "Connect-AzAccount"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
id: live-tests-negative-001
2+
name: Anti-Trigger - Playback Only Test Run
3+
description: |
4+
Test that the skill does NOT activate for playback-only test runs
5+
that don't need resource deployment.
6+
tags:
7+
- negative-test
8+
- anti-trigger
9+
inputs:
10+
prompt: "Run the tests for this package in playback mode"
11+
expected:
12+
output_not_contains:
13+
- "New-TestResources"
14+
- "Connect-AzAccount"
15+
- "Get-AzContext"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
id: cleanup-resources-001
2+
name: Clean Up Test Resources
3+
description: |
4+
Test that the skill offers and performs cleanup of test resources
5+
after a test run.
6+
tags:
7+
- basic
8+
- happy-path
9+
- cleanup
10+
inputs:
11+
prompt: "Clean up the test resources I deployed for keyvault"
12+
expected:
13+
output_contains:
14+
- "Remove-TestResources"
15+
outcomes: []
16+
behavior:
17+
max_tool_calls: 5
18+
max_response_time_ms: 60000
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
id: live-tests-basic-001
2+
name: Deploy Test Resources and Run Live Tests
3+
description: |
4+
Test that the skill guides through deploying test resources and
5+
running tests in live mode for a package.
6+
tags:
7+
- basic
8+
- happy-path
9+
- live-mode
10+
inputs:
11+
prompt: "Deploy test resources and run live tests for the keyvault package at ~/repos/azure-sdk-for-python/sdk/keyvault/azure-keyvault-keys"
12+
expected:
13+
output_contains:
14+
- "Get-AzContext"
15+
- "New-TestResources"
16+
- "live"
17+
outcomes:
18+
- type: tool_called
19+
tool_name: azsdk_package_run_tests
20+
behavior:
21+
max_tool_calls: 10
22+
max_response_time_ms: 60000
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
id: record-tests-with-env-001
2+
name: Run Tests in Record Mode with Existing Environment
3+
description: |
4+
Test that the skill runs tests in record mode when a .env file
5+
is already provided, skipping resource deployment.
6+
tags:
7+
- basic
8+
- happy-path
9+
- record-mode
10+
inputs:
11+
prompt: "Run the tests in record mode using the live test deployment specified in sdk/keyvault/azure-keyvault-keys/.env"
12+
expected:
13+
output_contains:
14+
- "record"
15+
output_not_contains:
16+
- "New-TestResources"
17+
outcomes:
18+
- type: tool_called
19+
tool_name: azsdk_package_run_tests
20+
behavior:
21+
max_tool_calls: 5
22+
max_response_time_ms: 60000

0 commit comments

Comments
 (0)