typespec-ts-add-spector-test
Skill27 starsChanged 28 days agoMITView on GitHub
Add or update Spector end-to-end tests for the @azure-tools/typespec-ts emitter in packages/typespec-ts. Use when given Spector case paths, links to http-specs or azure-http-specs cases, or pull requests that add or change Spector scenarios and the TypeScript emitter must opt into generation, implement Vitest client tests, regenerate the declaration baseline, and validate against the mock server.
- Installs packages
In this repository10 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- agentic-workflowsSkill
- code-reviewSkill
- create-linter-ruleSkill
- doc-example-generatorSkill
- hotfix-releaseSkill
- tcgc-newsletterSkill
- typespec-go-add-spector-testSkill
- typespec-python-releaseSkill
- update-resolve-arm-resourcesSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
38 rules. About 0 are common, 22 are distinctive, and 16 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈22
Distinctive · estimate
This author's own choices. Worth a look.
16
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Do not work around unsupported behavior by weakening assertions, changing expected requests, omitting required calls, or adding a skipped …
- Very specific: line 44
Ensure the core submodule is initialized at the commit pinned by the repository.
- Distinctive: line 50
Do not overwrite a locally modified or intentionally checked-out submodule.
- Very specific: line 52
If mise is installed, prefix the commands below with mise exec --.
- Distinctive: line 72
Run this once for a batch of cases.
- Very specific: line 78
Check temp/specs/<spec-path> and find its entry point, preferring client.tsp, then main.tsp.
- Distinctive: line 82
If the path or mock API does not exist, stop processing that case and report the invalid path rather than guessing.
- Distinctive: line 84
Read all TypeSpec files used by the case, not only the entry point.
- Very specific: line 90
Search spector.config.yaml for the exact spec key and inspect test/azure-modular-integration for the corresponding hand-written test.
- Distinctive: line 103
If all scenarios are covered and passing, make no change for that case.
- Distinctive: line 105
If coverage is partial, preserve existing behavior and add only the missing scenarios.
- Very specific: line 109
Add a new enabled entry under specs in spector.config.yaml:
- Very specific: line 116
Use options.outputPath only when the spec needs multiple configurations, names an individual .tsp entry point, or the generated folder must …
- Distinctive: line 125
Do not change the shared Spector packages' own selection groups.
- Very specific: line 127
If the case is intentionally unsupported, use false only when requested or when the repository convention requires tracking it, and add a …
- Very specific: line 133
Read references/naming-and-templates.md for the current tspconfig.yaml and .gitignore templates.
- Distinctive: line 135
Start from the minimal template or the nearest current sibling configuration, then keep only options supported by the current emitter and …
- Very specific: line 149
Read generated src/index.ts and the referenced client and model files to determine exact constructors, operation groups, method signatures, …
- Distinctive: line 151
Do not hand-write tests from TypeSpec names alone.
- Distinctive: line 153
If generation fails, determine whether the failure comes from invalid test configuration or unsupported emitter behavior.
- Distinctive: line 159
Search nearby tests by feature and generated path because historical filenames are not mechanically derived from spec paths.
- Distinctive: line 161
Read references/naming-and-templates.md for current naming guidance, test boilerplate, imports, and assertion patterns.
- Very specific: line 165
Use port 3002, allow insecure HTTP, and disable retries where the client options permit it.
- Distinctive: line 167
Write tests that invoke every mock API scenario and assert meaningful response values when a response exists.
- Very specific: line 171
Use generated model and options types rather than casts or any.
- Distinctive: line 173
Follow current nearby patterns for paging, long-running operations, credentials, multipart requests, and error assertions.
- Distinctive: line 175
Do not remove a failing scenario merely to make the file green.
- Distinctive: line 177
Treat a correctly written failing test as unsupported behavior or an emitter/runtime defect to report.
- Distinctive: line 179
Do not add new skipped tests for unsuccessful scenarios.
- Very specific: line 183
Start the server from packages/typespec-ts in a separate process:
- Very specific: line 189
Wait until the server is listening on port 3002, then run only the affected test files:
- Distinctive: line 195
Always stop the server afterward, including after failures:
- Very specific: line 203
Do not run the full spector-test command for focused validation because it regenerates and tests every opted-in case.
- Distinctive: line 207
After focused tests pass, run both generation phases for each changed output:
- Very specific: line 226
If the changes will be submitted in a pull request, add a Chronus change description for @azure-tools/typespec-ts:
- Very specific: line 232
Use the internal change kind for test-only Spector coverage unless the changes have a user-facing impact requiring another kind.
- Distinctive: line 240
Do not propose or implement an emitter fix unless a separate task explicitly requests it.
- Distinctive: line 242
If working on a pull request, keep its implementation-status section accurate.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Add Spector Tests for typespec-ts
Work in packages/typespec-ts and process every requested Spector case.
Scope Boundary
This skill adds Spector tests for behavior already supported by the TypeScript emitter.
Do not modify emitter production code, shared runtime code, TypeSpec specifications, or Spector mock APIs while applying this skill. If a scenario exposes unsupported behavior or a defect, diagnose it only far enough to report a concise, evidence-based blocker. Defer the implementation or fix to a separate issue or pull request.
Do not work around unsupported behavior by weakening assertions, changing expected requests, omitting required calls, or adding a skipped test.
Inputs
Accept one or more of:
- A path relative to a
specsdirectory, such asencode/numericorazure/core/model. - A link under
microsoft/typespec/packages/http-specs/specsorAzure/typespec-azure/packages/azure-http-specs/specs. - A pull request in either repository that adds or changes specs.
For a pull request, inspect changed files under packages/http-specs/specs or packages/azure-http-specs/specs and identify each affected case directory.
Expected Changes
For a new supported case, usually commit:
- An enabled entry in
packages/typespec-ts/spector.config.yaml. packages/typespec-ts/test/azure-modular-integration/generated/<output-path>/tspconfig.yaml.packages/typespec-ts/test/azure-modular-integration/generated/<output-path>/.gitignore.- The generated
packages/typespec-ts/test/azure-modular-integration/generated/<output-path>/src/index.d.ts. - A hand-written
packages/typespec-ts/test/azure-modular-integration/<descriptive-kebab-name>.test.ts.
Generated client implementation files are ignored and must not be force-added.
Workflow
1. Prepare the Package
Ensure the core submodule is initialized at the commit pinned by the repository. If it is missing or uninitialized, run:
git submodule update --init coreDo not overwrite a locally modified or intentionally checked-out submodule; use a clean worktree instead.
If mise is installed, prefix the commands below with mise exec --; otherwise, use pnpm directly.
Install dependencies only when they are missing:
pnpm installBuild the emitter and its dependencies from the repository root:
pnpm -r --filter "@azure-tools/typespec-ts..." buildFrom packages/typespec-ts, stage the current specs:
pnpm copy:typespecRun this once for a batch of cases.
2. Resolve and Validate Each Case
Normalize links to the path beneath specs/.
Check temp/specs/<spec-path> and find its entry point, preferring client.tsp, then main.tsp; a config key may also name a .tsp file directly.
Find and read the applicable mockapi.ts.
If the path or mock API does not exist, stop processing that case and report the invalid path rather than guessing.
Read all TypeSpec files used by the case, not only the entry point.
Extract every Scenarios.<name> assignment and understand the validated HTTP method, URI, parameters, headers, body, response, and status.
3. Inspect Existing Coverage
Search spector.config.yaml for the exact spec key and inspect test/azure-modular-integration for the corresponding hand-written test.
The config is the only opt-in source; do not add a hard-coded spec list.
Resolve config entries as follows:
trueenables a case withoutputPathequal to the spec key.{ options: { outputPath: "..." } }changes the generated folder and the--filtervalue.- A list generates multiple outputs for one spec.
falsedocuments an intentionally disabled case.
Compare the mock API scenarios with existing tests.
If all scenarios are covered and passing, make no change for that case.
If coverage is partial, preserve existing behavior and add only the missing scenarios.
4. Opt Into Generation
Add a new enabled entry under specs in spector.config.yaml:
specs:
encode/numeric: trueUse options.outputPath only when the spec needs multiple configurations, names an individual .tsp entry point, or the generated folder must differ from the key:
specs:
client/naming/enum-conflict: { options: { outputPath: client/naming-enum-conflict } }For multiple configurations, use a list with a unique outputPath for each item.
Do not change the shared Spector packages' own selection groups.
If the case is intentionally unsupported, use false only when requested or when the repository convention requires tracking it, and add a nearby reason with an issue link.
5. Add the Generated-Package Configuration
Create test/azure-modular-integration/generated/<output-path>/tspconfig.yaml.
Read references/naming-and-templates.md for the current tspconfig.yaml and .gitignore templates.
Start from the minimal template or the nearest current sibling configuration, then keep only options supported by the current emitter and required by the case.
6. Generate the Focused Client
From packages/typespec-ts, generate the selected output:
node ./test/commands/gen-spector.js --filter="$outputPath" --phase=clientThe filter matches the resolved outputPath exactly, not necessarily the spec key.
Confirm test/azure-modular-integration/generated/<output-path>/src/index.ts exists and exports a usable client.
Read generated src/index.ts and the referenced client and model files to determine exact constructors, operation groups, method signatures, option bags, and return types.
Do not hand-write tests from TypeSpec names alone.
If generation fails, determine whether the failure comes from invalid test configuration or unsupported emitter behavior. Correct test configuration mistakes. For unsupported behavior or an emitter failure, stop implementing that scenario and report the observed blocker; do not modify emitter production code.
7. Implement the Vitest Test
Choose a descriptive kebab-case filename ending in .test.ts.
Search nearby tests by feature and generated path because historical filenames are not mechanically derived from spec paths.
Read references/naming-and-templates.md for current naming guidance, test boilerplate, imports, and assertion patterns.
Construct clients with the actual generated signature rather than assuming the common constructor shape.
Use port 3002, allow insecure HTTP, and disable retries where the client options permit it.
Write tests that invoke every mock API scenario and assert meaningful response values when a response exists.
Match request values exactly to mockapi.ts.
Use generated model and options types rather than casts or any.
Follow current nearby patterns for paging, long-running operations, credentials, multipart requests, and error assertions.
Do not remove a failing scenario merely to make the file green.
Treat a correctly written failing test as unsupported behavior or an emitter/runtime defect to report. Do not fix that defect as part of this skill.
Do not add new skipped tests for unsuccessful scenarios. Exclude their incomplete test changes and report the failure instead. Preserve existing skipped tests unless their linked issue is resolved and the test now passes.
8. Validate Against Spector
Start the server from packages/typespec-ts in a separate process:
pnpm start-test-serverWait until the server is listening on port 3002, then run only the affected test files:
pnpm exec vitest run --project integration-azure-modular "test/azure-modular-integration/$testFile.test.ts"Always stop the server afterward, including after failures:
pnpm stop-test-serverFor a failure, first correct mistakes in the test by rechecking mockapi.ts, TypeSpec semantics, and generated signatures. If the test is correct and the generated client still cannot satisfy the scenario, report the blocker and remove the incomplete test changes. Do not change production code.
Do not run the full spector-test command for focused validation because it regenerates and tests every opted-in case.
9. Regenerate the Tracked Baseline
After focused tests pass, run both generation phases for each changed output:
node ./test/commands/gen-spector.js --filter="$outputPath"Confirm generated/<output-path>/src/index.d.ts exists.
The client phase removes this tracked rollup and the declaration phase restores it, so do not finish after --phase=client.
Review git status for the expected config, test, .gitignore, tspconfig.yaml, and src/index.d.ts changes.
From the repository root, run the required formatting and lint commands:
pnpm format
pnpm lintIf the changes will be submitted in a pull request, add a Chronus change description for @azure-tools/typespec-ts:
pnpm change addUse the internal change kind for test-only Spector coverage unless the changes have a user-facing impact requiring another kind. Do not add a change description when no implementation pull request will be created.
10. Report
Report each processed spec path and output path, newly covered scenarios, already-covered scenarios, and unsuccessful scenarios.
For each unsuccessful scenario, report the stage that failed (generation, compilation, request validation, or response validation), the observed generated-client behavior, the expected behavior from mockapi.ts, and an existing issue link when one is available.
Do not propose or implement an emitter fix unless a separate task explicitly requests it.
If working on a pull request, keep its implementation-status section accurate.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

