feat: Test generation for modular SDK clients#3809
Conversation
Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
|
@copilot Run |
Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
Done in f271277. Ran |
|
@copilot one issue found in our CI
|
…ilures Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
Fixed in f513619. The root cause was that
All tests now pass: 152 test-next, 860 unit tests, 559 RLC integration, 576 modular integration. |
|
@copilot pls fix format issue |
Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com>
|
@copilot please update the PR description with design proposal |
…nder.ts (reverts 34c79d6) Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
|
Is it possible to enable one smoke test (e.g. NetworkAnalytics.Management) to be generated with tests? |
0504e76 to
2f33bdc
Compare
…ration-conflicts # Conflicts: # packages/typespec-ts/src/index.ts # packages/typespec-ts/test/util/testUtil.ts
I checked this is impossible in our smoke test since this is not in our SDK repo environment and enabling test would lead to build failure and JiaoDi has a test in SDK repo manually and see comment #3809 (comment) |
|
@copilot we met an issue seems this issue is from this feature, analyze the root cause |
* Initial plan * feat: implement test generation for modular SDK clients Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com> * fix: run pnpm format and smoke-test to update generated code Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com> * fix: make test helpers loading conditional to fix integration test failures Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com> * fix: run prettier to fix formatting in load-static-helpers.ts Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com> * Update packages/typespec-ts/test/modularUnit/scenarios/test/operations/dpgOperationsTest.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/typespec-ts/test/modularUnit/scenarios/test/operations/clientParameterTest.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/typespec-ts/src/framework/hooks/binder.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/typespec-ts/src/index.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/typespec-ts/src/modular/helpers/exampleValueHelpers.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: compute relative src/index.js import path dynamically in emitTests for multi-client support Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com> * chore: run pnpm smoke-test to regenerate platform-specific browser helper variants Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com> * revert: remove platform-specific browser helper variant logic from binder.ts (reverts 34c79d6) Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com> * fix and update case * Fix the build issues * Remove the azure package condition since this is un-necessary * Add unit test for test value assertion * Fix the browser file missing issue * Fxi wrong import issue --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MaryGao <9943211+MaryGao@users.noreply.github.com> Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com> Co-authored-by: Mary Gao <yanmeigao1210@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jiao Di (MSFT) <v-jiaodi@microsoft.com> Co-authored-by: Mary Gao <marygao@microsoft.com>

Here is the design proposal for the PR description:
Design Proposal: Test Generation for Modular SDK Clients
Overview
This feature adds automatic
.spec.tstest file generation for modular SDK clients from TypeSpec examples (x-ms-examples). It mirrors the existing samples generation infrastructure but targets recorded integration tests using@azure-tools/test-recorder.Architecture
New Files
src/modular/emitTests.tssrc/modular/helpers/exampleValueHelpers.tsstatic/test-helpers/recordedClient.tscreateRecorder()copied totest/generated/util/Modified Files
src/modular/external-dependencies.tsAzureTestDependencies(Recorder, createTestCredential, assert, vitest hooks, env)src/modular/static-helpers-metadata.tsCreateRecorderHelpers.createRecorderrefkeysrc/framework/load-static-helpers.tsstatic/test-helpers/→test/generated/util/whenloadTestHelpersis setsrc/framework/hooks/binder.tsgetImportDeclarations()to avoid name conflictssrc/index.tsemitTests()whengenerateTest && isAzurePackageGeneration Flow
Generated Test Structure
Each generated test file follows this pattern:
Key Design Decisions
Conditional loading: Test helpers (
static/test-helpers/) are only copied whengenerateTest && isAzurePackage(production) orloadTestHelpers: true(unit tests). This avoids breaking theload-static-filesintegration test.Shared utilities:
exampleValueHelpers.tsis shared between samples and tests. The key difference is that tests do NOT convertplainDatestrings toDateobjects — they stay as strings.Credential handling: For ARM/Azure services, tests use
createTestCredential()from@azure-tools/test-credentialto support both live and playback modes. Non-Azure services fall back to stub values.Response assertions: Simple scalar fields from the example response body generate
assert.equal()statements. Complex/nested objects are skipped to keep tests maintainable.Binder import conflict resolution: The binder's
generateLocallyUniqueImportNamechecks both tracked imports andsourceFile.getImportDeclarations()to handle the manualaddImportDeclarationcall for the client class.