|
| 1 | +--- |
| 2 | +name: copying-typespec-test-changes |
| 3 | +description: Copies test file changes from Microsoft/typespec repo PRs to Azure/autorest.python repo. Use when user provides a Microsoft/typespec PR link and asks to sync test changes from http-client-python/generator/test to packages/typespec-python/test folder. |
| 4 | +--- |
| 5 | + |
| 6 | +# Copying TypeSpec Test Changes to autorest.python |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +The `packages/typespec-python/test` folder in Azure/autorest.python mirrors the `packages/http-client-python/generator/test` folder in Microsoft/typespec. When test changes are made in typespec, they need to be copied to autorest.python. |
| 11 | + |
| 12 | +## Workflow |
| 13 | + |
| 14 | +Copy this checklist and track your progress: |
| 15 | + |
| 16 | +``` |
| 17 | +Task Progress: |
| 18 | +- [ ] Step 1: Extract changed files from typespec PR |
| 19 | +- [ ] Step 2: Identify test file changes in http-client-python/generator/test |
| 20 | +- [ ] Step 3: Copy changes to packages/typespec-python/test |
| 21 | +- [ ] Step 4: Format files with black |
| 22 | +- [ ] Step 5: Verify changes |
| 23 | +``` |
| 24 | + |
| 25 | +### Step 1: Extract changed files from typespec PR |
| 26 | + |
| 27 | +Use the GitHub tool to fetch the PR details from Microsoft/typespec |
| 28 | + |
| 29 | +### Step 2: Identify test file changes |
| 30 | + |
| 31 | +Filter the changed files list to only include files under: |
| 32 | +- `packages/http-client-python/generator/test/` |
| 33 | + |
| 34 | +Ignore changes outside this path. |
| 35 | + |
| 36 | +### Step 3: Copy changes to autorest.python |
| 37 | + |
| 38 | +For each changed test file: |
| 39 | + |
| 40 | +1. **Map the path**: Replace `packages/http-client-python/generator/test/` with `packages/typespec-python/test/` |
| 41 | + |
| 42 | + Example: |
| 43 | + - Source: `packages/http-client-python/generator/test/azure/sample_test.py` |
| 44 | + - Target: `packages/typespec-python/test/azure/sample_test.py` |
| 45 | + |
| 46 | +2. **Fetch the new content**: Get the file content from the typespec PR branch |
| 47 | + |
| 48 | +3. **Apply the change**: |
| 49 | + - For new files: Create the file in autorest.python |
| 50 | + - For modified files: Update the existing file to match |
| 51 | + - For deleted files: Delete the corresponding file |
| 52 | + |
| 53 | +### Step 4: Format with black |
| 54 | + |
| 55 | +**MUST run after all file changes:** |
| 56 | + |
| 57 | +```bash |
| 58 | +python -m black <changed_file_path> -l 120 |
| 59 | +``` |
| 60 | + |
| 61 | +Run this command for each Python file that was created or modified. |
| 62 | + |
| 63 | +### Step 5: Verify changes |
| 64 | + |
| 65 | +1. Check that all target files exist and match source content |
| 66 | +2. Confirm black formatting was applied (no formatting errors) |
| 67 | +3. List all changes made for user review |
| 68 | + |
| 69 | +## Path mapping reference |
| 70 | + |
| 71 | +| TypeSpec repo path | autorest.python path | |
| 72 | +|---|---| |
| 73 | +| `packages/http-client-python/generator/test/` | `packages/typespec-python/test/` | |
| 74 | + |
| 75 | +## Important notes |
| 76 | + |
| 77 | +- **Consistency**: Copy content exactly to maintain consistency between repos |
| 78 | +- **Formatting**: Always run `python -m black <file> -l 120` on changed Python files |
| 79 | +- **Scope**: Only copy files from the `generator/test` folder, ignore other changes |
| 80 | +- **Verify**: After copying, the test files should be identical between repos (after formatting) |
| 81 | +- **requirements.txt**: When updating `requirements.txt` files, only update dependencies with the `-e XXX` pattern (editable installs). Do NOT modify other dependencies in the file. |
| 82 | + |
| 83 | +## Example usage |
| 84 | + |
| 85 | +### Basic usage (local changes only) |
| 86 | + |
| 87 | +User prompt: "Copy test changes from https://github.com/microsoft/typespec/pull/1234 to this repo" |
| 88 | + |
| 89 | +1. Extract PR number: 1234 |
| 90 | +2. Fetch PR #1234 from microsoft/typespec |
| 91 | +3. Find files changed under `packages/http-client-python/generator/test/` |
| 92 | +4. For each file, copy to corresponding path under `packages/typespec-python/test/` |
| 93 | +5. Run black formatter on each changed Python file |
| 94 | +6. Report summary of changes |
| 95 | + |
| 96 | +### Classic scenario (commit to autorest.python PR) |
| 97 | + |
| 98 | +In most cases, users will provide both: |
| 99 | +- A **typespec PR link** (source of changes) |
| 100 | +- An **autorest.python PR link** (destination to commit changes) |
| 101 | + |
| 102 | +User prompt: "Copy test changes from https://github.com/microsoft/typespec/pull/1234 to https://github.com/Azure/autorest.python/pull/5678" |
| 103 | + |
| 104 | +**Workflow:** |
| 105 | + |
| 106 | +1. Extract both PR numbers: typespec PR #1234, autorest.python PR #5678 |
| 107 | +2. Fetch the autorest.python PR #5678 to get the target branch name |
| 108 | +3. Checkout the target branch locally: |
| 109 | + ```bash |
| 110 | + git fetch origin |
| 111 | + git checkout <pr-branch-name> |
| 112 | + ``` |
| 113 | +4. Fetch typespec PR #1234 from microsoft/typespec |
| 114 | +5. Find files changed under `packages/http-client-python/generator/test/` |
| 115 | +6. For each file, copy to corresponding path under `packages/typespec-python/test/` |
| 116 | +7. Run black formatter on each changed Python file |
| 117 | +8. Stage, commit, and push changes to the PR branch: |
| 118 | + ```bash |
| 119 | + git add packages/typespec-python/test/ |
| 120 | + git commit -m "Sync test changes from microsoft/typespec#1234" |
| 121 | + git push origin <pr-branch-name> |
| 122 | + ``` |
| 123 | +9. Report summary of changes committed to the PR |
| 124 | + |
| 125 | +**Important for PR commits:** |
| 126 | +- Always fetch and checkout the PR branch before making changes |
| 127 | +- Use a descriptive commit message referencing the source typespec PR |
| 128 | +- Push to the same branch to update the existing autorest.python PR |
0 commit comments