address greptile review feedback (greploop iteration 1)

- Make validation constants internal and expose via InternalsVisibleTo so tests reference single source of truth
- Add empty-string guard to IsValidConfiguredInstanceName to prevent IndexOutOfRangeException
- Add ClusteringFeature_UsesConfiguredInstanceNameProvider test for Features.ClusteringFeature to match existing ShellFeatures coverage

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Sipke Schoorstra 2026-06-20 00:13:33 +02:00
parent 55284aa1c1
commit b08b10132c
No known key found for this signature in database
GPG key ID: 5C10502B28A4268F
3 changed files with 38 additions and 6 deletions

View file

@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Elsa.Hosting.Management.UnitTests")]

View file

@ -21,9 +21,9 @@ namespace Elsa.Hosting.Management.Services;
/// </remarks>
public class ConfiguredApplicationInstanceNameProvider : IApplicationInstanceNameProvider
{
private const int AzureServiceBusSubscriptionNameMaxLength = 50;
private const string TriggerChangeTokenSignalEndpointNameSuffix = "-elsa-trigger-change-token-signal";
private static readonly int ConfiguredInstanceNameMaxLength = AzureServiceBusSubscriptionNameMaxLength - TriggerChangeTokenSignalEndpointNameSuffix.Length;
internal const int AzureServiceBusSubscriptionNameMaxLength = 50;
internal const string TriggerChangeTokenSignalEndpointNameSuffix = "-elsa-trigger-change-token-signal";
internal static readonly int ConfiguredInstanceNameMaxLength = AzureServiceBusSubscriptionNameMaxLength - TriggerChangeTokenSignalEndpointNameSuffix.Length;
private readonly string _instanceName;
@ -89,6 +89,9 @@ public class ConfiguredApplicationInstanceNameProvider : IApplicationInstanceNam
private static bool IsValidConfiguredInstanceName(string instanceName)
{
if (instanceName.Length == 0)
return false;
return IsAsciiLetterOrDigit(instanceName[0])
&& IsAsciiLetterOrDigit(instanceName[^1])
&& instanceName.All(c => IsAsciiLetterOrDigit(c) || c is '.' or '-' or '_');

View file

@ -1,17 +1,20 @@
using Elsa.Features.Services;
using Elsa.Hosting.Management.Contracts;
using Elsa.Hosting.Management.Options;
using Elsa.Hosting.Management.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute;
using ClusteringFeature = Elsa.Hosting.Management.Features.ClusteringFeature;
using ShellClusteringFeature = Elsa.Hosting.Management.ShellFeatures.ClusteringFeature;
namespace Elsa.Hosting.Management.UnitTests.Services;
public class ConfiguredApplicationInstanceNameProviderTests
{
private const int AzureServiceBusSubscriptionNameMaxLength = 50;
private const string TriggerChangeTokenSignalEndpointNameSuffix = "-elsa-trigger-change-token-signal";
private static readonly int ConfiguredInstanceNameMaxLength = AzureServiceBusSubscriptionNameMaxLength - TriggerChangeTokenSignalEndpointNameSuffix.Length;
private static int AzureServiceBusSubscriptionNameMaxLength => ConfiguredApplicationInstanceNameProvider.AzureServiceBusSubscriptionNameMaxLength;
private static string TriggerChangeTokenSignalEndpointNameSuffix => ConfiguredApplicationInstanceNameProvider.TriggerChangeTokenSignalEndpointNameSuffix;
private static int ConfiguredInstanceNameMaxLength => ConfiguredApplicationInstanceNameProvider.ConfiguredInstanceNameMaxLength;
[Fact]
public void ExplicitInstanceName_IsUsedDirectly()
@ -217,6 +220,29 @@ public class ConfiguredApplicationInstanceNameProviderTests
Assert.Equal("pod-0", provider.GetName());
}
[Fact]
public void ClusteringFeature_UsesConfiguredInstanceNameProvider()
{
var services = new ServiceCollection();
var module = Substitute.For<IModule>();
module.Services.Returns(services);
var feature = new ClusteringFeature(module)
{
ApplicationInstanceOptions = options => options.InstanceName = "pod-0"
};
services.AddLogging();
feature.Apply();
using var serviceProvider = services.BuildServiceProvider();
var provider = serviceProvider.GetRequiredService<IApplicationInstanceNameProvider>();
Assert.IsType<ConfiguredApplicationInstanceNameProvider>(provider);
Assert.Equal("pod-0", provider.GetName());
}
private static ConfiguredApplicationInstanceNameProvider CreateProvider(ApplicationInstanceOptions options)
{
return new ConfiguredApplicationInstanceNameProvider(