* Avoid null endpoint DTO metadata in tests * Enforce console logs hub read permission * Remove unused console logs hub import * Support mapped endpoint metadata in auth tests * Reduce console log capture throughput impact * Address Copilot console logs review * Refactor task scheduling to support tenant-level background work and enhance logging functionality. * Introduce ConsoleStreamHook for stdout/stderr tee and enhance logging validation. Adjust test cases and startup warnings for distributed lock provider usage. * Refactor console logging pipeline with capture optimization and new ConsoleLogsHost; update tests accordingly. * Add Ansi SGR parser for console logs and associated unit tests * Remove ANSI color renderings and parsers; integrate ConsoleLogScopeAccessor for improved logging context with workflow instance ID support. * Address console logs code quality feedback * Address PR review feedback * Preserve console logs extension points * Stabilize console logs host lifecycle * Address final automated review comments * Tighten console log capture shutdown * Address console log review feedback * Address follow-up review feedback * Cover final review feedback * Avoid recursive console provider initialization * Guard console host lease shutdown * Preserve console log scope and provider lifetime * Correlate console log scope fallback * Tighten console scope correlation * Expose host services during provider construction * Redact ANSI-normalized console lines * Add OpenTelemetry diagnostics backend foundation * Add OTLP HTTP ingestion parsing * Document OpenTelemetry diagnostics setup * Enforce OpenTelemetry hub permissions * Remove `ConsoleCaptureTee` and related services and tests * Add OpenTelemetry HTTP ingestion integration test * Use pipeline contributors for console log context * Update CShells package versions to 0.0.24-preview.132 * Add OpenTelemetry ingestion security tests * Add OpenTelemetry API authorization tests * Filter live console logs by workflow instance * Add OpenTelemetry hub tests * Add OpenTelemetry gRPC metadata hook * Assert OpenTelemetry workflow tags survive ingestion * Mark OpenTelemetry core build verified * Enhance console logging with activity execution metadata and extend test coverage. * Address console logs stream consumption comment * Wire OpenTelemetry diagnostics into core sample * Address Core diagnostics review feedback * Address Core Copilot follow-up feedback * Add OpenTelemetry metric instrument names * Address Core Copilot provider feedback * Address Core Copilot diagnostics follow-up * Address Core Copilot live feed feedback * Address Core Copilot store feedback * Integrate OpenTelemetry for logging, tracing, and metrics in ModularServer and update launch settings and docker-compose configuration. * Refactor to replace `ConsoleLogStream.Core` with `ConsoleLogStreaming.Core` across codebase and update `ConsoleStreamHook` installation. * Add diagnostics OpenTelemetry backend * Fix OpenTelemetry live hub subscription * Fix modular OpenTelemetry exporter endpoints * Add CShells logging configuration in appsettings.json * Remove obsolete unit tests and helper classes * Restore default activity exception handling * Simplify type serialization and alias management This commit refactors the internal type serialization and alias management system to reduce boilerplate, improve robustness, and simplify the developer experience: - Removed numerous explicit `ExpressionOptions` type alias registrations across various modules. - Updated `TypeJsonConverter` and polymorphic serialization to reliably handle types using assembly-qualified names when a short alias is not explicitly registered. - Streamlined `ExcludeFromHashConverter` to strictly adhere to `ExcludeFromHashAttribute` for hash calculations, removing complex `JsonIgnoreCondition` logic. - Eliminated several helper classes (`WorkflowJsonTypeResolver`, `WorkflowTypeValidator`, `IWorkflowTypeRegistry`, `WorkflowFactoryDictionary`, `JavaScriptExceptionTypeAliasRegistrar`, `WorkflowRuntimeTypeAliasRegistrar`) and their associated unit tests, simplifying the codebase. Additionally, this commit introduces a comprehensive markdown document (`product-website-feature-source.md`) outlining Elsa's core features, Studio capabilities, extension ecosystem, and architectural selling points, intended as source material for the product website. * Refine type serialization for improved robustness and alias handling This commit further enhances the type serialization and deserialization mechanisms: * Centralizes type resolution and alias management through `IWellKnownTypeRegistry` and `WorkflowJsonTypeResolver`. * Prioritizes registered type aliases when serializing type metadata in `PolymorphicObjectConverter`, resulting in more concise JSON output. * Enhances deserialization in `PolymorphicObjectConverter` and `VariableMapper` to gracefully handle unknown or non-instantiable types, providing fallbacks and logging warnings. * Simplifies `TypeJsonConverter` by delegating complex type resolution logic to the `WorkflowJsonTypeResolver`. * Adds `JsonArray` to the well-known type aliases for direct recognition. * Fix console logs packaging and workflow type resolution * Fix console log metadata and type resolution * Address Copilot review feedback * Enhance type resolution, improve console log handling, and update tests - Streamlined `WorkflowDictionaryExtensions` for better workflow registration validation. - Refined `ConsoleLogsAuthorizationTests` with the new `SetJsonRequest` helper to improve test requests handling. - Updated `OrderDefinition` to ignore JSON serialization for `KeySelector`. - Enhanced `WorkflowRuntimeFeature` for improved workflow registration and type alias configuration. - Added tests to ensure `ConsoleLogProvider` metadata filtration in various scenarios. - Improved type serialization logic in `WorkflowJsonTypeResolver`. - Updated README to fix references related to diagnostics. - Optimized `ExcludeFromHashConverter` for property serialization conditions. - Modified `TriggerIndexer` for streamlined trigger management. - Tested payload checks in `PublishEventTests`. - Adjusted `Endpoint` in `ConsoleLogs` for automatic JSON request handling. - Ensured registration of workflow type aliases in `WorkflowsFeature`. * Restore CLR workflow registration compatibility * Align JSON island serialization fixtures * Add Console Logs Services and Enhance Endpoint Handling - Introduced `ActivityExecutionsEndpointTests` to validate route exposure. - Added `ConsoleLogCaptureHostedService` for console log streaming. - Implemented `ConsoleStreamJsonConverter` for JSON conversion of console streams. - Developed `ElsaConsoleLogRecentBuffer` to handle recent log buffering. - Updated `ConsoleLogsAuthorizationTests` with new test cases for stream filter mapping. - Consolidated console log provider dependencies and registration, including recent buffering. - Enhanced `ElsaConsoleLogProvider` to use recent buffer for filtering. - Adjusted `Program.cs` for streamlined logging service setup. * Enhance type resolution and test coverage; streamline console log integration - Added `ConsoleStreamHook` for streamlined log streaming. - Updated `WorkflowJsonTypeResolverTests` to improve type resolution and test new scenarios. - Simplified type resolution by removing trusted assembly checks. * Fix CI smoke and package restore failures * Fix Docker smoke image project paths * Fix Docker Python runtime packages * Fix Docker CA smoke teardown * Refresh Elsa roadmap * Implement background processors and mediation coordination - Added `BackgroundCommandProcessor`, `BackgroundJobProcessor`, and `BackgroundNotificationProcessor` classes for handling commands, jobs, and notifications, respectively. - Introduced `MediatorBackgroundProcessingCoordinator` to coordinate the execution of all background processors. - Implemented `MediatorBackgroundTask` for wrapping `MediatorBackgroundProcessingCoordinator` in `BackgroundTask`. - Added unit tests for `MediatorBackgroundTask` to ensure proper start and stop behavior. - Refactored `BackgroundCommandSenderHostedService` to utilize `BackgroundCommandProcessor`. - Introduced 'elsa-roadmap-refresh' skill configuration for roadmap updates. * Address workflow type resolution review feedback * Address follow-up review feedback * Restore recent console logs execute path * Address Copilot follow-up review * Decouple workflow JSON aliases from expressions * Fix workflow management unit test setup * Fix console logs recent endpoint handler shape * Respect workflow JSON strict type aliases * Remove unused console log contracts reference * Address Copilot review feedback * Address Copilot follow-up comments * Synchronize ring buffer dropped count * Address background processor strategy replay * Fix diagnostics live feed regressions
398 lines
17 KiB
C#
398 lines
17 KiB
C#
using System.Reflection;
|
|
using System.Security.Claims;
|
|
using System.Text;
|
|
using ConsoleLogStreaming.Core.Models;
|
|
using ConsoleLogStreaming.Core;
|
|
using Elsa.Diagnostics.ConsoleLogs.Contracts;
|
|
using Elsa.Diagnostics.ConsoleLogs.Features;
|
|
using Elsa.Diagnostics.ConsoleLogs.Permissions;
|
|
using Elsa.Diagnostics.ConsoleLogs.RealTime;
|
|
using Elsa.Diagnostics.ConsoleLogs.Services;
|
|
using FastEndpoints;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http.Features;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
namespace Elsa.Diagnostics.ConsoleLogs.IntegrationTests;
|
|
|
|
public class ConsoleLogsAuthorizationTests
|
|
{
|
|
[Fact]
|
|
public async Task HubSubscribe_WithoutConsoleLogsPermission_DeniesAccess()
|
|
{
|
|
var hub = CreateHub("write:diagnostics:console-logs");
|
|
|
|
await Assert.ThrowsAsync<HubException>(() => hub.SubscribeAsync(new()));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task HubUpdateFilter_WithoutConsoleLogsPermission_DeniesAccess()
|
|
{
|
|
var hub = CreateHub("write:diagnostics:console-logs");
|
|
|
|
await Assert.ThrowsAsync<HubException>(() => hub.UpdateFilterAsync(new()));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(ConsoleLogsPermissions.Read)]
|
|
[InlineData(PermissionNames.All)]
|
|
[InlineData("read:*")]
|
|
public async Task HubSubscribe_WithConsoleLogsPermission_AllowsAccess(string permission)
|
|
{
|
|
var hub = CreateHub(permission);
|
|
|
|
await hub.SubscribeAsync(new());
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Elsa.Diagnostics.ConsoleLogs.Endpoints.ConsoleLogs.Recent.Endpoint")]
|
|
[InlineData("Elsa.Diagnostics.ConsoleLogs.Endpoints.ConsoleLogs.Sources.Endpoint")]
|
|
public void RestEndpoints_RequireConsoleLogsPermission(string endpointTypeName)
|
|
{
|
|
var permissions = GetConfiguredPermissions(endpointTypeName);
|
|
|
|
Assert.Contains(ConsoleLogsPermissions.Read, permissions);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RecentEndpoint_MapsWorkflowInstanceIdToMetadataFilter()
|
|
{
|
|
var endpointType = typeof(ConsoleLogsFeature).Assembly.GetType("Elsa.Diagnostics.ConsoleLogs.Endpoints.ConsoleLogs.Recent.Endpoint", throwOnError: true)!;
|
|
var provider = new TestConsoleLogProvider();
|
|
var endpoint = Activator.CreateInstance(endpointType, provider)!;
|
|
SetJsonRequest(endpointType, endpoint,
|
|
"""
|
|
{
|
|
"workflowInstanceId": "workflow-instance-a"
|
|
}
|
|
""");
|
|
|
|
var result = endpointType.GetMethod("ExecuteAsync", [typeof(CancellationToken)])!.Invoke(endpoint, [CancellationToken.None]);
|
|
await Assert.IsAssignableFrom<Task>(result);
|
|
|
|
Assert.NotNull(provider.LastFilter);
|
|
var metadata = provider.LastFilter.Metadata;
|
|
Assert.True(metadata.TryGetValue(ConsoleLogMetadataKeys.WorkflowInstanceId, out var workflowInstanceId));
|
|
Assert.Equal("workflow-instance-a", workflowInstanceId);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("stdout", ConsoleStream.Stdout)]
|
|
[InlineData("stderr", ConsoleStream.Stderr)]
|
|
public async Task RecentEndpoint_MapsLowercaseStreamFilter(string stream, ConsoleStream expected)
|
|
{
|
|
var endpointType = typeof(ConsoleLogsFeature).Assembly.GetType("Elsa.Diagnostics.ConsoleLogs.Endpoints.ConsoleLogs.Recent.Endpoint", throwOnError: true)!;
|
|
var provider = new TestConsoleLogProvider();
|
|
var endpoint = Activator.CreateInstance(endpointType, provider)!;
|
|
SetJsonRequest(endpointType, endpoint,
|
|
$$"""
|
|
{
|
|
"stream": "{{stream}}"
|
|
}
|
|
""");
|
|
|
|
var result = endpointType.GetMethod("ExecuteAsync", [typeof(CancellationToken)])!.Invoke(endpoint, [CancellationToken.None]);
|
|
await Assert.IsAssignableFrom<Task>(result);
|
|
|
|
Assert.NotNull(provider.LastFilter);
|
|
Assert.Equal(expected, provider.LastFilter.Stream);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData("all")]
|
|
public async Task RecentEndpoint_MapsAllStreamFilterToNull(string? stream)
|
|
{
|
|
var endpointType = typeof(ConsoleLogsFeature).Assembly.GetType("Elsa.Diagnostics.ConsoleLogs.Endpoints.ConsoleLogs.Recent.Endpoint", throwOnError: true)!;
|
|
var provider = new TestConsoleLogProvider();
|
|
var endpoint = Activator.CreateInstance(endpointType, provider)!;
|
|
var streamJson = stream == null ? "null" : $"\"{stream}\"";
|
|
SetJsonRequest(endpointType, endpoint,
|
|
$$"""
|
|
{
|
|
"stream": {{streamJson}}
|
|
}
|
|
""");
|
|
|
|
var result = endpointType.GetMethod("ExecuteAsync", [typeof(CancellationToken)])!.Invoke(endpoint, [CancellationToken.None]);
|
|
await Assert.IsAssignableFrom<Task>(result);
|
|
|
|
Assert.NotNull(provider.LastFilter);
|
|
Assert.Null(provider.LastFilter.Stream);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RecentEndpoint_MapsActivityFiltersToMetadataFilter()
|
|
{
|
|
var endpointType = typeof(ConsoleLogsFeature).Assembly.GetType("Elsa.Diagnostics.ConsoleLogs.Endpoints.ConsoleLogs.Recent.Endpoint", throwOnError: true)!;
|
|
var provider = new TestConsoleLogProvider();
|
|
var endpoint = Activator.CreateInstance(endpointType, provider)!;
|
|
SetJsonRequest(endpointType, endpoint,
|
|
"""
|
|
{
|
|
"workflowInstanceId": "workflow-instance-a",
|
|
"activityInstanceId": "activity-instance-a",
|
|
"activityId": "activity-a",
|
|
"activityNodeId": "node-a"
|
|
}
|
|
""");
|
|
|
|
var result = endpointType.GetMethod("ExecuteAsync", [typeof(CancellationToken)])!.Invoke(endpoint, [CancellationToken.None]);
|
|
await Assert.IsAssignableFrom<Task>(result);
|
|
|
|
Assert.NotNull(provider.LastFilter);
|
|
AssertActivityMetadata(provider.LastFilter.Metadata);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RecentEndpoint_WhenJsonRequestHasUnknownEmptyBody_UsesEmptyFilter()
|
|
{
|
|
var endpointType = typeof(ConsoleLogsFeature).Assembly.GetType("Elsa.Diagnostics.ConsoleLogs.Endpoints.ConsoleLogs.Recent.Endpoint", throwOnError: true)!;
|
|
var provider = new TestConsoleLogProvider();
|
|
var endpoint = Activator.CreateInstance(endpointType, provider)!;
|
|
SetJsonRequest(endpointType, endpoint, "", includeContentLength: false);
|
|
|
|
var result = endpointType.GetMethod("ExecuteAsync", [typeof(CancellationToken)])!.Invoke(endpoint, [CancellationToken.None]);
|
|
await Assert.IsAssignableFrom<Task>(result);
|
|
|
|
Assert.NotNull(provider.LastFilter);
|
|
Assert.Empty(provider.LastFilter.Metadata);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task HubStream_MapsWorkflowInstanceIdToMetadataFilter()
|
|
{
|
|
var provider = new TestConsoleLogProvider();
|
|
var hub = CreateHub(provider, ConsoleLogsPermissions.Read);
|
|
|
|
await foreach (var _ in hub.StreamAsync(new ElsaConsoleLogFilter { WorkflowInstanceId = "workflow-instance-a" }, CancellationToken.None))
|
|
{
|
|
// Intentionally consume the stream to trigger provider subscription/filter mapping side effects.
|
|
}
|
|
|
|
Assert.NotNull(provider.LastSubscriptionFilter);
|
|
var metadata = provider.LastSubscriptionFilter.Metadata;
|
|
Assert.True(metadata.TryGetValue(ConsoleLogMetadataKeys.WorkflowInstanceId, out var workflowInstanceId));
|
|
Assert.Equal("workflow-instance-a", workflowInstanceId);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task HubStream_MapsActivityFiltersToMetadataFilter()
|
|
{
|
|
var provider = new TestConsoleLogProvider();
|
|
var hub = CreateHub(provider, ConsoleLogsPermissions.Read);
|
|
|
|
await foreach (var _ in hub.StreamAsync(new ElsaConsoleLogFilter
|
|
{
|
|
WorkflowInstanceId = "workflow-instance-a",
|
|
ActivityInstanceId = "activity-instance-a",
|
|
ActivityId = "activity-a",
|
|
ActivityNodeId = "node-a"
|
|
}, CancellationToken.None))
|
|
{
|
|
}
|
|
|
|
Assert.NotNull(provider.LastSubscriptionFilter);
|
|
AssertActivityMetadata(provider.LastSubscriptionFilter.Metadata);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task HubSubscribe_MapsWorkflowInstanceIdToMetadataFilter()
|
|
{
|
|
var provider = new TestConsoleLogProvider();
|
|
var hub = CreateHub(provider, ConsoleLogsPermissions.Read);
|
|
|
|
await hub.SubscribeAsync(new ElsaConsoleLogFilter { WorkflowInstanceId = "workflow-instance-a" });
|
|
var filter = await provider.WaitForSubscriptionFilterAsync();
|
|
|
|
var metadata = filter.Metadata;
|
|
Assert.True(metadata.TryGetValue(ConsoleLogMetadataKeys.WorkflowInstanceId, out var workflowInstanceId));
|
|
Assert.Equal("workflow-instance-a", workflowInstanceId);
|
|
|
|
await hub.UnsubscribeAsync();
|
|
}
|
|
|
|
private static void AssertActivityMetadata(IReadOnlyDictionary<string, string> metadata)
|
|
{
|
|
Assert.Equal("workflow-instance-a", metadata[ConsoleLogMetadataKeys.WorkflowInstanceId]);
|
|
Assert.Equal("activity-instance-a", metadata[ConsoleLogMetadataKeys.ActivityInstanceId]);
|
|
Assert.Equal("activity-a", metadata[ConsoleLogMetadataKeys.ActivityId]);
|
|
Assert.Equal("node-a", metadata[ConsoleLogMetadataKeys.ActivityNodeId]);
|
|
}
|
|
|
|
private static void SetJsonRequest(Type endpointType, object endpoint, string json, bool includeContentLength = true)
|
|
{
|
|
var bytes = Encoding.UTF8.GetBytes(json);
|
|
var context = new DefaultHttpContext();
|
|
context.Request.Body = new MemoryStream(bytes);
|
|
if (includeContentLength)
|
|
context.Request.ContentLength = bytes.Length;
|
|
context.Request.ContentType = "application/json";
|
|
|
|
endpointType
|
|
.GetProperty("HttpContext", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)!
|
|
.SetValue(endpoint, context);
|
|
}
|
|
|
|
private static IReadOnlyCollection<string> GetConfiguredPermissions(string endpointTypeName)
|
|
{
|
|
var endpointType = typeof(ConsoleLogsFeature).Assembly.GetType(endpointTypeName, throwOnError: true)!;
|
|
var endpoint = Activator.CreateInstance(endpointType, new TestConsoleLogProvider())!;
|
|
var (requestDtoType, responseDtoType) = GetEndpointDtoTypes(endpointType);
|
|
var definition = new EndpointDefinition(endpointType, requestDtoType, responseDtoType);
|
|
|
|
endpointType
|
|
.GetProperty("Definition", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)!
|
|
.SetValue(endpoint, definition);
|
|
|
|
endpointType.GetMethod("Configure")!.Invoke(endpoint, null);
|
|
|
|
var permissions = definition
|
|
.GetType()
|
|
.GetProperty("AllowedPermissions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)!
|
|
.GetValue(definition);
|
|
|
|
return Assert.IsAssignableFrom<IEnumerable<string>>(permissions).ToArray();
|
|
}
|
|
|
|
private static (Type RequestDtoType, Type ResponseDtoType) GetEndpointDtoTypes(Type endpointType)
|
|
{
|
|
var type = endpointType;
|
|
|
|
while (type.BaseType != null)
|
|
{
|
|
type = type.BaseType;
|
|
|
|
if (!type.IsGenericType)
|
|
continue;
|
|
|
|
var genericTypeDefinition = type.GetGenericTypeDefinition();
|
|
var genericArguments = type.GetGenericArguments();
|
|
|
|
if (genericTypeDefinition == typeof(Abstractions.ElsaEndpoint<,>))
|
|
return (genericArguments[0], genericArguments[1]);
|
|
|
|
if (genericTypeDefinition == typeof(Abstractions.ElsaEndpoint<,,>))
|
|
return (genericArguments[0], genericArguments[1]);
|
|
|
|
if (genericTypeDefinition == typeof(Abstractions.ElsaEndpointWithoutRequest<>))
|
|
return (typeof(EmptyRequest), genericArguments[0]);
|
|
}
|
|
|
|
throw new InvalidOperationException($"Unsupported endpoint type '{endpointType.FullName}'.");
|
|
}
|
|
|
|
private static ElsaConsoleLogsHub CreateHub(params string[] permissions)
|
|
{
|
|
return CreateHub(new TestConsoleLogProvider(), permissions);
|
|
}
|
|
|
|
private static ElsaConsoleLogsHub CreateHub(TestConsoleLogProvider provider, params string[] permissions)
|
|
{
|
|
var hubContext = new TestHubContext();
|
|
var subscriptionManager = new ElsaConsoleLogSubscriptionManager(provider, new TestConsoleLogSourceRegistry(), hubContext, NullLogger<ElsaConsoleLogSubscriptionManager>.Instance);
|
|
var authorizer = new ElsaConsoleLogStreamHubAuthorizer();
|
|
|
|
return new ElsaConsoleLogsHub(provider, authorizer, subscriptionManager)
|
|
{
|
|
Context = new TestHubCallerContext(CreateUser(permissions))
|
|
};
|
|
}
|
|
|
|
private static ClaimsPrincipal CreateUser(params string[] permissions)
|
|
{
|
|
var permissionClaimType = (string)typeof(SecurityOptions)
|
|
.GetProperty(nameof(SecurityOptions.PermissionsClaimType))!
|
|
.GetValue(new Config().Security)!;
|
|
var claims = permissions.Select(x => new Claim(permissionClaimType, x));
|
|
var identity = new ClaimsIdentity(claims, "Test");
|
|
|
|
return new ClaimsPrincipal(identity);
|
|
}
|
|
|
|
private class TestConsoleLogProvider : IConsoleLogProvider
|
|
{
|
|
private readonly TaskCompletionSource<ConsoleLogFilter> _subscriptionFilterSet = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
|
|
public ConsoleLogFilter? LastFilter { get; private set; }
|
|
public ConsoleLogFilter? LastSubscriptionFilter { get; private set; }
|
|
|
|
public Task<ConsoleLogFilter> WaitForSubscriptionFilterAsync() =>
|
|
_subscriptionFilterSet.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
|
|
|
public ValueTask PublishAsync(ConsoleLogLine line, CancellationToken cancellationToken = default)
|
|
{
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
|
|
public ValueTask<RecentConsoleLogsResult> GetRecentAsync(ConsoleLogFilter filter, CancellationToken cancellationToken = default)
|
|
{
|
|
LastFilter = filter;
|
|
return ValueTask.FromResult(new RecentConsoleLogsResult());
|
|
}
|
|
|
|
public IAsyncEnumerable<ConsoleLogStreamingItem> SubscribeAsync(
|
|
ConsoleLogFilter filter,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
LastSubscriptionFilter = filter;
|
|
_subscriptionFilterSet.TrySetResult(filter);
|
|
return AsyncEnumerable.Empty<ConsoleLogStreamingItem>();
|
|
}
|
|
|
|
public ValueTask<IReadOnlyCollection<ConsoleLogSource>> ListSourcesAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
return ValueTask.FromResult<IReadOnlyCollection<ConsoleLogSource>>([]);
|
|
}
|
|
}
|
|
|
|
private class TestHubContext : IHubContext<ElsaConsoleLogsHub, IElsaConsoleLogsClient>
|
|
{
|
|
public IHubClients<IElsaConsoleLogsClient> Clients { get; } = new TestHubClients();
|
|
|
|
public IGroupManager Groups { get; } = new TestGroupManager();
|
|
}
|
|
|
|
private class TestHubClients : IHubClients<IElsaConsoleLogsClient>
|
|
{
|
|
public IElsaConsoleLogsClient All => throw new NotSupportedException();
|
|
public IElsaConsoleLogsClient AllExcept(IReadOnlyList<string> excludedConnectionIds) => throw new NotSupportedException();
|
|
public IElsaConsoleLogsClient Client(string connectionId) => throw new NotSupportedException();
|
|
public IElsaConsoleLogsClient Clients(IReadOnlyList<string> connectionIds) => throw new NotSupportedException();
|
|
public IElsaConsoleLogsClient Group(string groupName) => throw new NotSupportedException();
|
|
public IElsaConsoleLogsClient GroupExcept(string groupName, IReadOnlyList<string> excludedConnectionIds) => throw new NotSupportedException();
|
|
public IElsaConsoleLogsClient Groups(IReadOnlyList<string> groupNames) => throw new NotSupportedException();
|
|
public IElsaConsoleLogsClient User(string userId) => throw new NotSupportedException();
|
|
public IElsaConsoleLogsClient Users(IReadOnlyList<string> userIds) => throw new NotSupportedException();
|
|
}
|
|
|
|
private class TestGroupManager : IGroupManager
|
|
{
|
|
public Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task RemoveFromGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
private class TestHubCallerContext(ClaimsPrincipal user) : HubCallerContext
|
|
{
|
|
public override string ConnectionId { get; } = "connection-1";
|
|
public override string? UserIdentifier { get; } = "user-1";
|
|
public override ClaimsPrincipal? User { get; } = user;
|
|
public override IDictionary<object, object?> Items { get; } = new Dictionary<object, object?>();
|
|
public override IFeatureCollection Features { get; } = new FeatureCollection();
|
|
public override CancellationToken ConnectionAborted { get; } = CancellationToken.None;
|
|
|
|
public override void Abort()
|
|
{
|
|
}
|
|
}
|
|
}
|