Emitter 生成代码与上游基线对比
diff-upstream
重新生成本地 emitter,并将生成的代码与已检入 autorest.python 的上游基线进行对比。当用户想查看其 emitter 变更对生成代码的影响(相较于当前生产环境的差异),或说出类似“diff upstream”(与上游对比)、“compare to baseline”(与基线比较)、“what changed vs production”(相较生产环境有哪些变化)、“show me the diff”(给我看差异)、“how does this affect generated code”(这如何影响生成代码)等表述,或希望验证其变更能产生预期的输出差异时使用。
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 5.9k
- Forks
- 423
01 前言 Front Matter
- name
- diff-upstream
- description
- Regenerate the local emitter and diff the generated code against the upstream baseline checked into autorest.python. Use this skill when the user wants to see how their emitter changes affect generated code compared to what's currently in production, says things like "diff upstream", "compare to baseline", "what changed vs production", "show me the diff", "how does this affect generated code", or wants to validate their changes produce the expected output differences.
02 资源文件 58
- 参考文档docx-js.md16.1 KB
- 许可证LICENSE.txt1.4 KB
- 参考文档ooxml.md23.0 KB
- 参考文档ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsd1.9 KB
- 参考文档ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsd2.5 KB
- 参考文档ooxml/schemas/ecma/fouth-edition/opc-digSig.xsd2.8 KB
- 参考文档ooxml/schemas/ecma/fouth-edition/opc-relationships.xsd1.3 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsd73.2 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd6.8 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd50.1 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd624 B
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsd148.5 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsd1.2 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd8.7 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd14.4 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/pml.xsd81.7 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd1.2 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd7.2 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd6.2 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd1.2 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd880 B
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd2.5 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd3.4 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd7.3 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsd22.8 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd1.3 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/sml.xsd236.6 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsd25.5 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd24.7 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd535 B
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd5.6 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd3.9 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/wml.xsd167.4 KB
- 参考文档ooxml/schemas/ISO-IEC29500-4_2016/xml.xsd4.5 KB
- 参考文档ooxml/schemas/mce/mc.xsd3.1 KB
- 参考文档ooxml/schemas/microsoft/wml-2010.xsd25.9 KB
- 参考文档ooxml/schemas/microsoft/wml-2012.xsd3.7 KB
- 参考文档ooxml/schemas/microsoft/wml-2018.xsd901 B
- 参考文档ooxml/schemas/microsoft/wml-cex-2018.xsd1.7 KB
- 参考文档ooxml/schemas/microsoft/wml-cid-2016.xsd1002 B
- 参考文档ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsd600 B
- 参考文档ooxml/schemas/microsoft/wml-symex-2015.xsd745 B
- 脚本ooxml/scripts/pack.py5.5 KB
- 脚本ooxml/scripts/unpack.py1.0 KB
- 脚本ooxml/scripts/validate.py1.9 KB
- 脚本ooxml/scripts/validation/__init__.py336 B
- 脚本ooxml/scripts/validation/base.py39.0 KB
- 脚本ooxml/scripts/validation/docx.py9.8 KB
- 脚本ooxml/scripts/validation/pptx.py12.0 KB
- 脚本ooxml/scripts/validation/redlining.py10.9 KB
- 脚本scripts/__init__.py65 B
- 脚本scripts/document.py49.2 KB
- 脚本scripts/templates/comments.xml2.6 KB
- 脚本scripts/templates/commentsExtended.xml2.6 KB
- 脚本scripts/templates/commentsExtensible.xml2.7 KB
- 脚本scripts/templates/commentsIds.xml2.6 KB
- 脚本scripts/templates/people.xml147 B
- 脚本scripts/utilities.py13.4 KB
03 SKILL.md 正文
Diff Upstream Skill
Regenerates local emitter output and compares it against the baseline generated code checked into the autorest.python repository. Shows exactly what would change if the current emitter changes were shipped.
Optimized for local development with cached baseline and editor integration.
Paths
All paths are relative to the http-client-python package root.
| Item | Path |
|---|---|
| Package root | ~/Desktop/github/typespec/packages/http-client-python |
| Local generated (unbranded) | generator/test/unbranded/generated |
| Local generated (azure) | generator/test/azure/generated |
| Baseline cache (unbranded) | generator/test/unbranded/.baseline (gitignored) |
| Baseline cache (azure) | generator/test/azure/.baseline (gitignored) |
| Diff summary output | generator/test/.diff-summary.md (gitignored) |
| Regenerate marker | .last-regenerate |
| Upstream repo | https://github.com/Azure/autorest.python |
Workflow
Step 1: Build and regenerate
Always regenerate to see current changes:
cd ~/Desktop/github/typespec/packages/http-client-python
npm run build
npm run regenerate
touch .last-regenerate
If build or regenerate fails, report errors and stop.
Step 2: Fetch or update baseline
Fetch baseline files directly into the test folders using sparse checkout:
cd ~/Desktop/github/typespec/packages/http-client-python
BASELINE_UNBRANDED="generator/test/unbranded/.baseline"
BASELINE_AZURE="generator/test/azure/.baseline"
TEMP_CLONE="/tmp/autorest-python-baseline-$$"
# Check if we need to fetch/update
if [ ! -d "$BASELINE_UNBRANDED" ] || [ ! -d "$BASELINE_AZURE" ]; then
echo "Fetching upstream baseline..."
# Clone with sparse checkout to temp location
git clone --depth 1 --filter=blob:none --sparse \
https://github.com/Azure/autorest.python.git "$TEMP_CLONE"
cd "$TEMP_CLONE"
git sparse-checkout set \
packages/typespec-python/test/unbranded/generated \
packages/typespec-python/test/azure/generated
cd ~/Desktop/github/typespec/packages/http-client-python
# Copy to baseline locations
rm -rf "$BASELINE_UNBRANDED" "$BASELINE_AZURE"
cp -r "$TEMP_CLONE/packages/typespec-python/test/unbranded/generated" "$BASELINE_UNBRANDED"
cp -r "$TEMP_CLONE/packages/typespec-python/test/azure/generated" "$BASELINE_AZURE"
# Cleanup temp clone
rm -rf "$TEMP_CLONE"
echo "Baseline cached in generator/test/*/.baseline/"
else
echo "Using cached baseline (delete generator/test/*/.baseline to refresh)"
fi
Step 3: Generate diff summary
Create a markdown summary file with package-level comparison:
cd ~/Desktop/github/typespec/packages/http-client-python
LOCAL_UNBRANDED="generator/test/unbranded/generated"
LOCAL_AZURE="generator/test/azure/generated"
BASELINE_UNBRANDED="generator/test/unbranded/.baseline"
BASELINE_AZURE="generator/test/azure/.baseline"
cat > generator/test/.diff-summary.md << EOF
# Diff Summary: Local vs Upstream (autorest.python)
Generated: $(date)
## Unbranded Packages
| Metric | Count |
|--------|-------|
| Local | $(ls "$LOCAL_UNBRANDED" 2> /dev/null | wc -l | tr -d ' ') |
| Upstream | $(ls "$BASELINE_UNBRANDED" 2> /dev/null | wc -l | tr -d ' ') |
### Missing locally (in upstream only):
$(comm -13 <(ls "$LOCAL_UNBRANDED" 2> /dev/null | sort) <(ls "$BASELINE_UNBRANDED" 2> /dev/null | sort) | sed 's/^/- /' || echo "- (none)")
### New locally (not in upstream):
$(comm -23 <(ls "$LOCAL_UNBRANDED" 2> /dev/null | sort) <(ls "$BASELINE_UNBRANDED" 2> /dev/null | sort) | sed 's/^/- /' || echo "- (none)")
## Azure Packages
| Metric | Count |
|--------|-------|
| Local | $(ls "$LOCAL_AZURE" 2> /dev/null | wc -l | tr -d ' ') |
| Upstream | $(ls "$BASELINE_AZURE" 2> /dev/null | wc -l | tr -d ' ') |
### Missing locally (in upstream only):
$(comm -13 <(ls "$LOCAL_AZURE" 2> /dev/null | sort) <(ls "$BASELINE_AZURE" 2> /dev/null | sort) | sed 's/^/- /' || echo "- (none)")
### New locally (not in upstream):
$(comm -23 <(ls "$LOCAL_AZURE" 2> /dev/null | sort) <(ls "$BASELINE_AZURE" 2> /dev/null | sort) | sed 's/^/- /' || echo "- (none)")
---
## Viewing Detailed Diffs
### List changed files in a package:
\`\`\`bash
diff -rq generator/test/unbranded/generated/PACKAGE generator/test/unbranded/.baseline/PACKAGE
\`\`\`
### View full diff for a package:
\`\`\`bash
diff -r generator/test/unbranded/generated/PACKAGE generator/test/unbranded/.baseline/PACKAGE
\`\`\`
### Open side-by-side diff in VS Code:
\`\`\`bash
code --diff generator/test/unbranded/.baseline/PACKAGE/path/to/file.py generator/test/unbranded/generated/PACKAGE/path/to/file.py
\`\`\`
EOF
Step 4: Open in editor
Open the summary file in the user's preferred editor:
cd ~/Desktop/github/typespec/packages/http-client-python
# Try common editors in order of preference
if command -v code &> /dev/null; then
code generator/test/.diff-summary.md
elif [ -n "$VISUAL" ]; then
$VISUAL generator/test/.diff-summary.md
elif [ -n "$EDITOR" ]; then
$EDITOR generator/test/.diff-summary.md
elif command -v vim &> /dev/null; then
vim generator/test/.diff-summary.md
else
cat generator/test/.diff-summary.md
fi
Step 5: Report to user
Tell the user:
- Summary file is open at
generator/test/.diff-summary.md - Baseline is cached alongside generated code in
generator/test/*/.baseline/ - How to view detailed diffs (commands are in the summary file)
- How to refresh baseline:
rm -rf generator/test/*/.baseline
Viewing Detailed File Diffs
After showing the summary, if the user wants to see specific file changes:
Find changed files in a package:
cd ~/Desktop/github/typespec/packages/http-client-python
diff -rq \
generator/test/unbranded/generated/typetest-array \
generator/test/unbranded/.baseline/typetest-array
Show inline diff for a file:
diff -u \
generator/test/unbranded/.baseline/typetest-array/typetest/array/_client.py \
generator/test/unbranded/generated/typetest-array/typetest/array/_client.py
VS Code side-by-side (if user has VS Code):
code --diff \
generator/test/unbranded/.baseline/typetest-array/typetest/array/_client.py \
generator/test/unbranded/generated/typetest-array/typetest/array/_client.py
Integration with test-unbranded-emitter
After running diff-upstream, you can immediately run tests:
- The
.last-regeneratemarker is updated test-unbranded-emitterwill skip regeneration since it's fresh
Cleanup
The baseline is cached for fast subsequent runs. To refresh:
# Remove baseline (will re-fetch on next run)
rm -rf generator/test/unbranded/.baseline generator/test/azure/.baseline
# Remove summary file
rm generator/test/.diff-summary.md
Gitignore
These patterns should be in .gitignore:
generator/test/unbranded/.baseline/
generator/test/azure/.baseline/
generator/test/.diff-summary.md
.last-regenerate
Interpreting Diffs
After generating the diff, analyze what changed and report to the user whether the diffs are expected.
Step 1: Check what code changes were made on the branch
First, understand what emitter changes were made:
# Show commits on this branch
git log main..HEAD --oneline -- "emitter/src/*.ts"
# Show the actual changes
git diff main..HEAD -- emitter/src/
Step 2: Correlate code changes with expected generated output changes
Based on the emitter changes, determine what generated code SHOULD change:
| Emitter change type | Expected generated code impact |
|---|---|
| Namespace logic refactor (behavior-preserving) | No generated code changes |
| New decorator support | Changes in files using that decorator |
| Serialization changes | Changes in _serialization.py, model files |
| Client initialization changes | Changes in _client.py, _configuration.py |
| Operation changes | Changes in _operations/*.py |
Step 3: Compare expected vs actual diffs
-
If actual diffs match expected: Tell user "The diffs are expected based on your emitter changes to [describe changes]. The generated code correctly reflects your modifications."
-
If no diffs but expected some: Tell user "No generated code changes detected. If you expected changes, verify your emitter modifications are being triggered by the test specs, or there may be more development needed. Should I investigate further?"
-
If unexpected diffs appear: Tell user "Found unexpected changes in [files]. These don't appear to match your emitter modifications. There may be unintended side effects - would you like me to investigate?"
Pre-existing repo differences (always present, not caused by your changes)
These diffs exist between typespec and autorest.python repos regardless of emitter changes. They should be ignored when evaluating your changes:
| File type | Typical diff | Cause |
|---|---|---|
_patch.py |
List[str] → list[str] |
Type hint modernization (Python 3.9+ style) |
CHANGELOG.md |
Formatting differences | Template differences |
README.md |
Service display names | Template/config differences |
pyproject.toml / setup.py |
Different packaging | Tooling preferences |
If only these files differ: "The only diffs are pre-existing repo differences (type hints, config files), not caused by your emitter changes. Your changes are behavior-preserving."
Unexpected diffs (actual code changes)
If you see differences in these files, the emitter changes ARE affecting generated code:
_client.py- Client class definitions_operations/*.py- Operation implementationsmodels/*.py- Model definitions (excluding_patch.py)_serialization.py- Serialization logicaio/*.py- Async client code
If these files differ: First check if the changes match what the emitter modifications should produce. If they match, say "The generated code changes are expected based on your emitter changes." If they don't match or are unexpected, say "Found changes that don't appear to match your emitter modifications. There may be more development needed - would you like me to investigate?"
Quick diff analysis command
To check if there are actual code changes (excluding expected differences):
diff -rq generator/test/unbranded/generated generator/test/unbranded/.baseline 2> /dev/null | grep "\.py differ" | grep -v "_patch.py"
If this returns nothing, only expected diffs exist.
Notes
Diff direction
The diff shows changes from upstream (baseline) to local (your changes):
-lines: removed from upstream (or changed)+lines: added in your local version
Why packages might be missing locally
Some upstream packages may not generate locally due to:
- TypeSpec version incompatibilities in the monorepo
- Specs that require specific dependencies not installed
- Test configurations that differ between repos
This is expected for ARM/azure-resource-manager specs if there are version conflicts.
Performance
- First run: ~30-60s (fetch baseline)
- Subsequent runs: instant (uses cached baseline)
- Regenerate: ~2-3 minutes (always runs for diff)
04 同仓库更多 Skills
http-client-python Emitter 构建与测试
test-unbranded-emitter
构建并测试 @typespec/http-client-python emitter。当用户想要测试其对 emitter 的本地变更、运行生成器测试套件、检查其 http-client-python 变更是否通过,或验证某项修复时使用。触发短语包括“test the emitter”(测试 emitter)、“run tests”(运行测试)、“check if my changes pass”(检查我的变更是否通过)、“run test:generator”(运行 test:generator)、“run CI”(运行 CI),或在 emitter 包中提及任何测试/验证变更的表述。
TypeSpec 生成 Python SDK 代码
generate-from-typespec
使用本地 emitter 从 TypeSpec 规范生成 Python SDK 代码。当用户想要从 TypeSpec 规范生成或重新生成 Python 客户端,提供了 TypeSpec 项目的 GitHub URL 或本地路径,或说出类似“generate from this spec”(从此规范生成)、“emit Python from this tsp”(从此 tsp 生成 Python)、“regenerate the SDK”(重新生成 SDK)、“compile this TypeSpec for Python”(将此 TypeSpec 编译为 Python)等表述时使用。
Python SDK Spector 模拟 API 测试编写
writing-python-sdk-spector-mock-api-tests
根据 Spector 用例编写 TypeSpec http-client-python generator 的模拟 API 测试(azure/unbranded/shared)。当给定 Spector 用例链接,或修改 http-specs/azure-http-specs 下 Spector 用例的 PR 链接时使用。
pnpm 代码格式化
pnpm-format
使用 pnpm 格式化代码库,并从常见的格式化失败中恢复。
TypeSpec Bug 最小复现构建
minimal-repro
帮助创建 TypeSpec 编译器或 emitter bug 的最小复现。当用户提供 TypeSpec 源码(粘贴的代码或 GitHub URL)并描述问题时使用。在本地复现并缩减为单文件复现。
http-client-python 依赖升级与发布
http-client-python-bump-and-release
创建 PR 以升级 TypeSpec/Azure Tools 依赖、更新 peer 依赖,或发布 http-client-python 包的新版本。