feat: hide pipelines internals from stack trace
Some checks failed
default / dotnet-default-workflow (pull_request) Failing after 3m2s

This commit is contained in:
Louis Seubert 2026-05-29 22:53:58 +02:00
commit 5c2911ea6c
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
5 changed files with 85 additions and 4 deletions

View file

@ -0,0 +1,73 @@
// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
using Microsoft.Extensions.DependencyInjection;
namespace Geekeey.Request.Dispatcher.Tests;
internal sealed class StackTraceTests
{
[Test]
public async Task I_can_not_see_pipeline_internals_are_hidden_from_stack_trace_scalar()
{
// Arrange
var sc = new ServiceCollection();
sc.AddSingleton<ScalarTestTracker>();
sc.AddRequestDispatcher(builder => builder
.Add(typeof(FailingScalarHandler))
.Add(typeof(ScalarOpenBehavior<,>)));
var provider = sc.BuildServiceProvider();
var dispatcher = provider.GetRequiredService<IRequestDispatcher>();
var request = new FailingScalarRequest();
// Act
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() =>
dispatcher.DispatchAsync(request));
// Assert
await Assert.That(exception).IsNotNull();
var stackTrace = await Assert.That(exception.StackTrace).IsNotNull();
await Assert.That(stackTrace).Contains(nameof(FailingScalarHandler));
await Assert.That(stackTrace).Contains(nameof(ScalarOpenBehavior<,>));
// 3. Verify that the internal lambda from ScalarRequestInvoker.Chain is HIDDEN.
// In C#, these lambdas usually appear as "ScalarRequestInvoker`2.<>c__DisplayClass..." or similar.
// Since we added [StackTraceHidden], this frame should be omitted.
await Assert.That(stackTrace).DoesNotContain("ScalarRequestInvoker+<>");
}
[Test]
public async Task I_can_not_see_pipeline_internals_are_hidden_from_stack_trace_stream()
{
// Arrange
var sc = new ServiceCollection();
sc.AddSingleton<StreamTestTracker>();
sc.AddRequestDispatcher(builder => builder
.Add(typeof(FailingStreamHandler))
.Add(typeof(StreamOpenBehavior<,>)));
var provider = sc.BuildServiceProvider();
var dispatcher = provider.GetRequiredService<IRequestDispatcher>();
var request = new FailingStreamRequest();
// Act
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() =>
dispatcher.DispatchAsync(request).ToListAsync().AsTask());
// Assert
await Assert.That(exception).IsNotNull();
var stackTrace = await Assert.That(exception.StackTrace).IsNotNull();
await Assert.That(stackTrace).Contains(nameof(FailingStreamHandler));
await Assert.That(stackTrace).Contains(nameof(StreamOpenBehavior<,>));
// 3. Verify that the internal lambda from ScalarRequestInvoker.Chain is HIDDEN.
// In C#, these lambdas usually appear as "ScalarRequestInvoker`2.<>c__DisplayClass..." or similar.
// Since we added [StackTraceHidden], this frame should be omitted.
await Assert.That(stackTrace).DoesNotContain("StreamRequestInvoker+<>");
}
}