Skip to content

Commit 2395c51

Browse files
Merge branch 'main' of https://github.com/Microsoft/typespec into dependency-audit
2 parents 1190956 + 755fe9a commit 2395c51

282 files changed

Lines changed: 2958 additions & 2245 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: dependencies
3+
packages:
4+
- "@typespec/http-client-java"
5+
---
6+
7+
Update @azure-tools/typespec-client-generator-core to 0.67.1 and other dev dependencies to latest
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
Enable previously skipped client structure and client operation group mock API tests after TCGC 0.67.0 upgrade; remove obsolete `test_spread_record_discriminated_union` tests whose Spector scenario was removed.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
fix import for _validation.py/_types.py when "generation-subdir" is configured
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-python"
5+
- "@typespec/bundle-uploader"
6+
---
7+
8+
Extend publish pipeline to upload emitter bundles to Playground storage account. Update Python emitter to be browser-compatible for use in the TypeSpec playground.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
Add mock API tests for `service/multiple-services` scenario (multiple services without explicit `@client`).

.github/instructions/http-client-java.instructions.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ Steps:
2222

2323
Steps:
2424

25-
1. Bump the minor or patch version of `@typespec/http-client-java` in the three `package.json` files.
26-
2. Save the files and run `npm install` in the root so that `package-lock.json` is updated.
25+
1. Checkout "main" branch, pull the latest changes.
26+
2. Create a new branch. The name must follow the pattern "publish/http-client-java-<version>". Remind user that this branch must be pushed to remote upstream.
27+
3. Invoke `pnpm prepare-publish --only @typespec/http-client-java` in repository root. Commit the changes.
28+
4. Invoke `npm install` in the root to update `package-lock.json`. Commit the changes.
29+
5. Update the two `package.json` files in `generator/http-client-generator-clientcore-test` and `generator/http-client-generator-test` to match the new version in the root `package.json`. Commit the changes.
2730

2831
The publish workflow (to NPM) will be automatically triggered after the PR is merged: https://dev.azure.com/azure-sdk/internal/_build?definitionId=7294
2932

.github/skills/python-sdk-spector-mock-api-tests/SKILL.md

Lines changed: 72 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: writing-python-sdk-spector-mock-api-tests
3-
description: Writes TypeSpec http-client-python generator mock API tests (azure/unbranded/generic) from a Spector case. Use when given a Spector case link or a PR link that modifies Spector cases under http-specs/azure-http-specs.
3+
description: Writes TypeSpec http-client-python generator mock API tests (azure/unbranded/shared) from a Spector case. Use when given a Spector case link or a PR link that modifies Spector cases under http-specs/azure-http-specs.
44
---
55

66
# Writing python SDK tests from a Spector case
@@ -20,15 +20,15 @@ Spector cases define the **expected request + response**. The goal is to add/ext
2020

2121
A python pytest test (sync) added to one of:
2222

23-
- `packages/http-client-python/generator/test/azure/mock_api_tests`
24-
- `packages/http-client-python/generator/test/unbranded/mock_api_tests`
25-
- `packages/http-client-python/generator/test/generic_mock_api_tests`
23+
- `packages/http-client-python/tests/mock_api/azure`
24+
- `packages/http-client-python/tests/mock_api/unbranded`
25+
- `packages/http-client-python/tests/mock_api/shared`
2626

2727
And a corresponding async pytest test added under the matching `asynctests/` folder:
2828

29-
- `packages/http-client-python/generator/test/azure/mock_api_tests/asynctests`
30-
- `packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests`
31-
- `packages/http-client-python/generator/test/generic_mock_api_tests/asynctests`
29+
- `packages/http-client-python/tests/mock_api/azure/asynctests`
30+
- `packages/http-client-python/tests/mock_api/unbranded/asynctests`
31+
- `packages/http-client-python/tests/mock_api/shared/asynctests`
3232

3333
## Workflow (copy as checklist)
3434

@@ -37,12 +37,12 @@ Test-writing progress:
3737
- [ ] Ensure prerequisites are met (pnpm install, package build)
3838
- [ ] Identify the Spector case link (directly, or extracted from PR)
3939
- [ ] Update spec dependency version if the case is from an unreleased PR
40-
- [ ] Decide the destination folder(s): azure vs unbranded vs generic
40+
- [ ] Decide the destination folder(s): azure vs unbranded vs shared
4141
- [ ] Regenerate the specific generated client (do NOT run full regeneration)
4242
- [ ] Find existing test file to extend (or create a new one)
4343
- [ ] Implement sync + async test(s) that match the case’s request/response expectations
4444
- [ ] Update test requirements only if a new dependency is introduced
45-
- [ ] Format changed python files with Black (`python -m black <paths> -l 120`)
45+
- [ ] Format changed python files with Black (`python -m black <paths> --config ./eng/scripts/ci/config/pyproject.toml`)
4646
- [ ] Validate test locally (start Spector mock server + run pytest)
4747
- [ ] Add a changelog entry under `.chronus/changes`
4848

@@ -123,42 +123,45 @@ After bumping, run `npm run install` under `packages/http-client-python` to upda
123123

124124
Write the python test in:
125125

126-
- `packages/http-client-python/generator/test/azure/mock_api_tests`
126+
- `packages/http-client-python/tests/mock_api/azure`
127127

128128
### Rule B: Spector in microsoft/typespec
129129

130130
You may need either:
131131

132-
- **Option (a) generic only**: `.../generic_mock_api_tests`
133-
- **Option (b) both flavors**: `.../azure/mock_api_tests` AND `.../unbranded/mock_api_tests`
132+
- **Option (a) shared only**: `.../mock_api/shared`
133+
- **Option (b) both flavors**: `.../mock_api/azure` AND `.../mock_api/unbranded`
134134

135135
Decide with this concrete check:
136136

137137
1. Locate the generated python package/module for the scenario in BOTH:
138-
- `packages/http-client-python/generator/test/azure/generated`
139-
- `packages/http-client-python/generator/test/unbranded/generated`
140-
2. If the import root and client/model API surface you need are the same (same module path + same client entrypoint), write ONE shared test in `generic_mock_api_tests`.
141-
3. If import paths differ (or one flavor lacks the needed client), write separate tests under both `azure/mock_api_tests` and `unbranded/mock_api_tests`.
138+
- `packages/http-client-python/tests/generated/azure`
139+
- `packages/http-client-python/tests/generated/unbranded`
140+
2. If the import root and client/model API surface you need are the same (same module path + same client entrypoint), write ONE shared test in `mock_api/shared`.
141+
3. If import paths differ (or one flavor lacks the needed client), write separate tests under both `mock_api/azure` and `mock_api/unbranded`.
142142

143-
Why: both azure and unbranded tox runs include `../generic_mock_api_tests`, so shared tests are preferred when they can import the same generated package.
143+
Why: both azure and unbranded tox runs include `mock_api/shared`, so shared tests are preferred when they can import the same generated package.
144144

145145
## Step 4 — Regenerate the specific generated client
146146

147-
Generated code is gitignored (`packages/http-client-python/generator/test/**/generated/`). You must regenerate the specific spec before writing tests.
147+
Generated code is gitignored (`packages/http-client-python/tests/generated/`). You must regenerate the specific spec before writing tests.
148148

149149
**Compile only the single spec you need** (example for azure-core-page):
150150

151151
```bash
152152
cd packages/http-client-python
153-
npm run regenerate -- --name=azure/core/page
153+
npx tsx ./eng/scripts/ci/regenerate.ts --flavor azure --name azure/core/page
154154
```
155155

156-
> ⚠️ Do NOT run `npm run regenerate` — it compiles ALL specs and takes 40+ minutes. Only regenerate the specific spec you need.
156+
The `--flavor` flag selects `azure` or `unbranded`. The `--name` flag is a case-insensitive substring match on the package name.
157+
158+
> ⚠️ Do NOT run `npx tsx ./eng/scripts/ci/regenerate.ts` without `--name` — it compiles ALL specs and takes 40+ minutes. Only regenerate the specific spec you need.
159+
> ⚠️ Do NOT use `npm run regenerate -- --flavor ...` — npm may strip the flags. Use `npx tsx` directly.
157160
158161
**Verify** the generated client has the expected method:
159162

160163
```bash
161-
grep -r "method_name" generator/test/azure/generated/ < name > /
164+
grep -r "method_name" tests/generated/azure/ < package-name > /
162165
```
163166

164167
## Step 5 — Find existing test file (or create one)
@@ -167,8 +170,9 @@ grep -r "method_name" generator/test/azure/generated/ < name > /
167170
- Prefer extending an existing `test_*.py` when it already imports the same generated module.
168171
2. In parallel, find the matching async test in `asynctests/`.
169172

170-
- If you extend `mock_api_tests/test_<area>.py`, also extend `mock_api_tests/asynctests/test_<area>_async.py` (or create it if missing).
171-
- If you extend `generic_mock_api_tests/test_<area>.py`, also extend `generic_mock_api_tests/asynctests/test_<area>_async.py`.
173+
- If you extend `mock_api/azure/test_<area>.py`, also extend `mock_api/azure/asynctests/test_<area>_async.py` (or create it if missing).
174+
- If you extend `mock_api/shared/test_<area>.py`, also extend `mock_api/shared/asynctests/test_<area>_async.py`.
175+
- If you extend `mock_api/unbranded/test_<area>.py`, also extend `mock_api/unbranded/asynctests/test_<area>_async.py`.
172176

173177
3. If no sync test exists, create a new `test_<area>.py` and also create the async counterpart under `asynctests/`.
174178

@@ -203,84 +207,93 @@ Practical guidance:
203207
Async client import patterns (match the folder you’re writing to):
204208

205209
- Azure: import `aio` submodule alongside models, e.g. `from specs.<...> import models, aio`, then `async with aio.<Client>()` and `await client.<op>(...)`.
206-
- Generic/unbranded generated clients often expose `.aio` modules, e.g. `from <pkg>.aio import <Client>`.
210+
- Shared/unbranded generated clients often expose `.aio` modules, e.g. `from <pkg>.aio import <Client>`.
207211

208212
## Step 7 — Dependencies (only when needed)
209213

210214
Default: do NOT add new dependencies.
211215

212216
Only if your new/extended test imports a package not already available:
213217

214-
- Add it to the appropriate requirements file:
215-
- `packages/http-client-python/generator/test/azure/requirements.txt`
216-
- `packages/http-client-python/generator/test/unbranded/requirements.txt`
218+
- Add it to the appropriate requirements file under `packages/http-client-python/tests/requirements/`:
219+
- `base.txt` — shared dependencies (pytest, pytest-asyncio, etc.)
220+
- `azure.txt` — Azure-specific dependencies (azure-core, azure-mgmt-core)
221+
- `unbranded.txt` — unbranded-specific dependencies (corehttp)
217222

218223
Avoid adding dependencies unless strictly required by the test.
219224

220225
## Step 8 — Format changed files
221226

222-
Install Black if not already available, then format any python files you changed with a 120 character line length:
227+
Format any python files you changed using Black with the project's shared config:
223228

224229
```bash
225-
pip install black # if not already installed
226-
python -m black 120 < paths > -l
230+
cd packages/http-client-python
231+
python -m black ./eng/scripts/ci/config/pyproject.toml < paths > --config
227232
```
228233

229-
Replace `<paths>` with the specific files and/or folders you modified.
234+
Replace `<paths>` with the specific files and/or folders you modified (relative to the `http-client-python` root).
235+
236+
Alternatively, you can format all test files via the npm script:
237+
238+
```bash
239+
npm run format -- --generator
240+
```
230241

231242
## Step 9 — Validate your test locally
232243

233-
Before opening a PR, run your new or updated test inside a virtual environment with the Spector mock API server running.
244+
Before opening a PR, run your new or updated test. You will need two terminals: one to run the Spector mock API server, and another to run pytest.
245+
246+
1. **Determine the test flavor.** Pick the flavor that matches the test you changed:
247+
- Azure tests → `azure`
248+
- Unbranded tests → `unbranded`
234249

235-
1. **Determine the test root.** Pick the directory that matches the test you changed:
236-
- Azure tests → `packages/http-client-python/generator/test/azure`
237-
- Unbranded tests → `packages/http-client-python/generator/test/unbranded`
250+
2. **Regenerate and install packages** (if not already done):
238251

239-
2. **Create and activate a virtual environment** (if one does not already exist):
252+
```bash
253+
cd packages/http-client-python
254+
npx tsx ./eng/scripts/ci/regenerate.ts --flavor <azure|unbranded> --name <spec-name>
255+
```
256+
257+
3. **Create and activate a virtual environment** (if one does not already exist):
240258

241259
```bash
242-
cd packages/http-client-python/generator/test/<azure|unbranded>
260+
cd packages/http-client-python/tests
243261
python -m venv .venv
262+
# Windows:
263+
.venv\Scripts\activate
264+
# Linux/Mac:
244265
source .venv/bin/activate
245266
```
246267

247-
3. **Install only the dependencies you need.**
248-
Installing the full `requirements.txt` is slow because it includes every generated SDK. Instead, extract and install only the non-editable dependencies, then install the specific SDK(s) you need:
268+
4. **Install dependencies and the generated SDK:**
249269

250270
```bash
251-
# Install dependencies from requirements.txt, excluding generated SDKs:
252-
grep -v '^-e ./generated/' requirements.txt > _requirements.txt
253-
pip install -r _requirements.txt
254-
rm _requirements.txt
271+
pip install -r requirements/base.txt
272+
pip install -r requirements/<azure|unbranded>.txt
255273

256-
# Install the specific generated SDK(s) your test imports:
257-
pip install -e ./generated/<sdk-folder-name>
274+
# install only a single generated SDK:
275+
pip install --no-deps -e generated/<flavor>/<sdk-folder-name>
258276
```
259277

260-
Replace `<sdk-folder-name>` with the folder that matches the SDK under test (e.g., `azure-encode-duration`, `encode-duration`).
261-
262-
4. **Start the Spector mock API server.**
263-
The mock API tests make real HTTP requests, so the Spector server must be running before you execute pytest. Create another terminal, step into the spec package directory, and run the serve command (it runs in the foreground):
278+
5. **Start the Spector mock API server** in a separate terminal:
264279

265280
```bash
266-
# For azure-http-specs scenarios:
267-
cd packages/http-client-python/node_modules/@azure-tools/azure-http-specs/
268-
npm run serve
269-
270-
# For http-specs (microsoft/typespec) scenarios:
271-
cd packages/http-client-python/node_modules/@typespec/http-specs/
272-
npm run serve
281+
cd packages/http-client-python
282+
npx tsp-spector serve node_modules/@azure-tools/azure-http-specs/specs/ node_modules/@typespec/http-specs/specs/
273283
```
274284

275285
Wait until you see the server listening message before running tests.
276286

277-
5. **Run the test:**
287+
6. **Run the test** in the original terminal (with venv activated):
278288

279289
```bash
280-
pytest mock_api_tests/ -v < test_file > .py
290+
cd packages/http-client-python/tests
291+
pytest mock_api/ < azure | unbranded | shared > / < test_file > .py -v
281292
```
282293

283-
Replace `<test_file>` with the file you added or modified. Verify that all tests pass before proceeding.
294+
Verify that all tests pass before proceeding.
295+
296+
> **Important:** If you only added or changed test files, confirming the changed test passes is sufficient. However, if you modified emitter source code (under `generator/` or `emitter/`), you **must** run the full test suite for the affected flavor(s) to catch regressions before proceeding.
284297
285298
## Step 10 — Add a changelog entry
286299

0 commit comments

Comments
 (0)