Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions dotnet/src/webdriver/BiDi/EventStreamExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// <copyright file="EventStreamExtensions.cs" company="Selenium Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// </copyright>

using System.Runtime.CompilerServices;

namespace OpenQA.Selenium.BiDi;

public static class EventStreamExtensions
{
Comment on lines +22 to +25

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.

Action required

1. Public eventstreamextensions lacks

📘 Rule violation ✧ Quality

The new public type EventStreamExtensions is introduced without an XML documentation comment
containing a non-empty <summary>, which violates the requirement for documenting all public API
members. Missing docs reduce API discoverability and can break documentation generation pipelines.
Agent Prompt
## Issue description
A new public API type `EventStreamExtensions` is missing an XML doc comment with a non-empty `<summary>` immediately preceding the declaration.

## Issue Context
The compliance checklist requires XML documentation with `<summary>` for all public types and members introduced or modified in the diff.

## Fix Focus Areas
- dotnet/src/webdriver/BiDi/EventStreamExtensions.cs[22-25]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

/// <summary>
/// Configures how awaits on the tasks returned from an iteration of the event stream are performed.
/// </summary>
/// <remarks>
/// <para>
/// <see cref="IEventStream{TEventArgs}"/> implements both <see cref="IAsyncEnumerable{T}"/> and
/// <see cref="IAsyncDisposable"/>, which makes a plain <c>.ConfigureAwait(bool)</c> call ambiguous
/// (CS0121) because <c>TaskAsyncEnumerableExtensions</c> provides an overload for each interface.
/// This extension method resolves the ambiguity by explicitly routing to the
/// <see cref="IAsyncEnumerable{T}"/> overload, which is the behavior callers need when using
/// <c>await foreach</c>.
/// </para>
/// </remarks>
/// <typeparam name="TEventArgs">The event-args type produced by the stream.</typeparam>
/// <param name="stream">The event stream to configure.</param>
/// <param name="continueOnCapturedContext">
/// <see langword="true"/> to capture and marshal continuation back to the original context;
/// <see langword="false"/> to continue on a thread-pool thread.
/// </param>
/// <returns>A configured enumerable that applies the specified context-capture behavior.</returns>
public static ConfiguredCancelableAsyncEnumerable<TEventArgs> ConfigureAwait<TEventArgs>(
this IEventStream<TEventArgs> stream,
bool continueOnCapturedContext)
where TEventArgs : EventArgs
=> ((IAsyncEnumerable<TEventArgs>)stream).ConfigureAwait(continueOnCapturedContext);
}
84 changes: 84 additions & 0 deletions dotnet/test/webdriver/BiDi/EventStreamExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// <copyright file="EventStreamExtensionsTests.cs" company="Selenium Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// </copyright>

using System.Runtime.CompilerServices;
using OpenQA.Selenium.BiDi;

namespace OpenQA.Selenium.Tests.BiDi;

[Parallelizable(ParallelScope.All)]
[FixtureLifeCycle(LifeCycle.InstancePerTestCase)]
class EventStreamExtensionsTests
{
private IBiDi _bidi;
private FakeTransport _transport;

[SetUp]
public async Task SetUp()
{
_transport = new FakeTransport();
_bidi = await Selenium.BiDi.BiDi.ConnectAsync(new Uri("ws://fake"), opts => opts.UseTransport(() => _transport));
}

[TearDown]
public async Task TearDown()
{
await _bidi.DisposeAsync();
}

[Test]
public async Task ConfigureAwait_ReturnsConfiguredCancelableAsyncEnumerable()
{
var stream = await _bidi.Script.RealmDestroyed.StreamAsync()
.WithResponse(_transport, """{"subscription":"sub-1"}""");

// This line previously failed to compile (CS0121) because IEventStream<T> implements
// both IAsyncEnumerable<T> and IAsyncDisposable and both have a matching ConfigureAwait overload.
// EventStreamExtensions.ConfigureAwait disambiguates toward IAsyncEnumerable<T>.
var configured = stream.ConfigureAwait(false);

Assert.That(configured, Is.InstanceOf<ConfiguredCancelableAsyncEnumerable<BiDi.Script.RealmDestroyedEventArgs>>());

await stream.DisposeAsync().WithResponse(_transport);
}

[Test]
public async Task ConfigureAwait_DeliverEventsThroughConfiguredEnumerable()
{
var stream = await _bidi.Script.RealmDestroyed.StreamAsync()
.WithResponse(_transport, """{"subscription":"sub-1"}""");

_transport.EnqueueEvent("script.realmDestroyed", """{"realm":"r-1"}""");

var received = new List<BiDi.Script.RealmDestroyedEventArgs>();

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));

await foreach (var e in stream.ConfigureAwait(false).WithCancellation(cts.Token))
{
received.Add(e);
break;
}

Assert.That(received, Has.Count.EqualTo(1));
Assert.That(received[0].Realm.Id, Is.EqualTo("r-1"));

await stream.DisposeAsync().WithResponse(_transport);
}
}
Loading