Skip to content

[http-client-csharp] Add SSE protocol Spector scenarios - #11921

Open
JoshLove-msft wants to merge 8 commits into
microsoft:mainfrom
JoshLove-msft:joshlove-msft-csharp-sse-protocol-tests
Open

[http-client-csharp] Add SSE protocol Spector scenarios#11921
JoshLove-msft wants to merge 8 commits into
microsoft:mainfrom
JoshLove-msft:joshlove-msft-csharp-sse-protocol-tests

Conversation

@JoshLove-msft

Copy link
Copy Markdown
Contributor

Summary

Depends on #11918.

Add the seven missing SSE protocol Spector tests: WithEnvelope, WithoutEnvelope, Id, InvalidId, Retry, InvalidRetry, and Reconnect. Assert exact event counts, types, and payloads, valid metadata preserved, and invalid ID/retry metadata ignored. Reconnect is explicit using RequestOptions: send Last-Event-ID from the first event, then assert resumed event 2.

The incremental diff over #11918 is only SseTests.cs (+109 lines). Existing JSONL and basic SSE tests are unchanged. This branch retains the lower PR's reproducible pinned toolchain and C# customization; it adds no generator or TypeSpec customization. The shared model-name fix in #11920 is independent and can replace the lower workaround after publication and adoption.

Validation

All 12 Streaming runtime tests and 12 coverage entries pass, with 0 skipped. Regenerated back to stubs with no generated diff from the lower PR. The final stubbed test-project build, formatting, lint, and Cop checks passed.

This fork-dependent PR targets Microsoft main, so the lower ancestry remains until #11918 merges.

JoshLove-msft and others added 8 commits September 9, 2026 17:04
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Upgrade all TypeSpec and Azure toolchain dependencies and matching peer declarations to the stable September releases. Keep SSE customizations and scenario generation out of the dependency PR.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Support namespace-qualified CodeGenType mappings, preserve used customization attributes in stubs, and regenerate fixtures for the full TypeSpec upgrade. Keep streaming scenario tests in their separate PR.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Revert 422b45e from this branch; the shared model rename is maintained independently in microsoft#11920.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Merge approved dependency baseline 3d9a081 from microsoft#11918.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Sep 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@11921

commit: 6470563

@github-actions

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new stub-library “used customization attribute” detection compares minimally-qualified Roslyn names against fully-qualified provider names, which can cause required attributes to be incorrectly dropped.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the http-client-csharp TypeSpec dependency set and expands Spector coverage for SSE “protocol” scenarios, while also enhancing the generator’s customization handling (qualified-name matching) and stub-library pruning of unused customization attributes.

Changes:

  • Bump TypeSpec/Azure Tools dependencies for http-client-csharp and refresh Spector fixture outputs accordingly.
  • Add seven missing SSE protocol Spector tests (envelope/no-envelope, id/retry validation, and reconnect via Last-Event-ID).
  • Prefer qualified CodeGenType names during customization lookups and add tests for qualified-name model/enum customization; refine stub generation to drop unused customization attribute definitions.
File summaries
File Description
packages/http-client-csharp/package.json Updates peer/dev dependency versions for the emitter toolchain.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/tspCodeModel.json Regenerated SSE Spector code model reflecting new protocol surface.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/StreamingSseModelFactory.cs Regenerated model factory with protocol model support.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/SseClient.cs Regenerated client to expose GetProtocolClient().
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/ProtocolData.cs New generated protocol data client for envelope/no-envelope scenarios.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Protocol.cs New generated protocol client for id/retry/reconnect scenarios.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Models/StreamingSseContext.cs Registers ProtocolInfo for MRW buildable context.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Models/ProtocolInfo.Serialization.cs New generated serialization for ProtocolInfo.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Models/ProtocolInfo.cs New generated model type for protocol event payloads.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Generated/Internal/CodeGenTypeAttribute.cs Generated customization attribute definition for fixture compilation.
packages/http-client-csharp/generator/TestProjects/Spector/http/streaming/sse/src/Custom/ProtocolInfo.cs Customization to rename protocol Info to ProtocolInfo.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/tspCodeModel.json New/updated Spector code model for response “body or no content” fixture.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/src/Response.BodyOrNoContent.csproj Adds new Spector fixture project definition.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/src/Generated/schema/ConfigurationSchema.json Adds generated configuration schema for the new fixture.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/src/Generated/ResponseBodyOrNoContentModelFactory.cs Adds generated model factory for the new fixture.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/src/Generated/Models/ResponseBodyOrNoContentContext.cs Adds MRW context for fixture models.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/src/Generated/Models/BlobLayout.Serialization.cs Adds generated serialization for BlobLayout.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/src/Generated/Models/BlobLayout.cs Adds generated model BlobLayout.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/src/Generated/BodyOrNoContentClientSettings.cs Adds generated settings type for the new fixture client.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/src/Generated/BodyOrNoContentClientOptions.cs Adds generated options type for the new fixture client.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/src/Generated/BodyOrNoContentClient.cs Adds generated client for “body or no content” operations.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/Response.BodyOrNoContent.slnx Adds solution entry for the new fixture.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/Response.BodyOrNoContent.NuGet.targets Adds targets for configuration schema packing/consumption.
packages/http-client-csharp/generator/TestProjects/Spector/http/response/body-or-no-content/Configuration.json Adds generator configuration for the new fixture.
packages/http-client-csharp/generator/TestProjects/Spector.Tests/Http/Streaming/Sse/SseTests.cs Adds seven SSE protocol Spector scenarios and a single-event reader helper.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/QualifiedNameOverridesSimpleName/CustomModels.cs Test data for qualified vs simple customization precedence.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanRenameModelsByQualifiedNames/CustomModels.cs Test data for renaming multiple same-named models by qualified names.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanRenameModelByQualifiedName/ProtocolInfo.cs Test data for single qualified-name rename.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/TestData/ModelCustomizationTests/CanRenameEnumByQualifiedName/FirstStatus.cs Test data for qualified-name enum rename.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/ModelProviders/ModelCustomizationTests.cs Adds unit tests validating qualified-name customization behavior.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/SourceInput/SourceInputModel.cs Prefers qualified CodeGenType names when resolving customization types.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Properties/launchSettings.json Adds a launch profile for the new Spector fixture.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestData/InputLibraryVisitorTests/StubKeepsUsedCustomizationAttributes/Model.cs Test data to ensure stub keeps attributes when directly used.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/TestData/InputLibraryVisitorTests/StubKeepsInheritedCustomizationAttributes/Model.cs Test data to ensure stub keeps base attributes for derived usage.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj Adds stub-library project reference needed by new tests.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/InputLibraryVisitorTests.cs Adds tests verifying unused customization attributes are dropped/kept appropriately.
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel.StubLibrary/src/StubLibraryVisitor.cs Implements detection of which customization attributes are used by custom code.
Review details
  • Files reviewed: 21/38 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +34 to +50
for (var type = semanticModel.GetTypeInfo(attribute).Type as INamedTypeSymbol;
type is not null;
type = type.BaseType)
{
names.Add(type.ToDisplayString());
}
}
}
}

return names;
}

protected override TypeProvider? VisitType(TypeProvider type)
{
var isUsedCustomizationAttribute = type is CustomCodeAttributeDefinition &&
_usedCustomizationAttributes.Value.Contains($"{type.Type.Namespace}.{type.Name}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants