refactor: update Blazor testing guidelines and improve regex for hostname parsing in Caddy configuration
All checks were successful
Caddy Manager CI build / docker (push) Successful in 45s

This commit is contained in:
2025-07-23 15:33:18 +07:00
parent 063ed041b0
commit 0beb3800b5
3 changed files with 8 additions and 11 deletions

View File

@@ -32,7 +32,7 @@ alwaysApply: true
## Testing and Debugging ## Testing and Debugging
- All unit testing and integration testing should be done in Cursor ide - All unit testing and integration testing should be done in Cursor ide
- Test Blazor components and services using xUnit - Test services, unit and integration, using xUnit
- Use Moq for mocking dependencies during tests - Use Moq for mocking dependencies during tests
- Debug Blazor UI issues using browser developer tools and Cursor ide's debugging tools for backend and server-side issues - Debug Blazor UI issues using browser developer tools and Cursor ide's debugging tools for backend and server-side issues
- For performance profiling and optimization, rely on Cursor ide's diagnostics tools - For performance profiling and optimization, rely on Cursor ide's diagnostics tools

View File

@@ -8,9 +8,11 @@ public partial class CaddyConfigurationParsingService: ICaddyConfigurationParsin
{ {
/// <summary> /// <summary>
/// Regex to help parse hostnames from a Caddyfile. /// Regex to help parse hostnames from a Caddyfile.
/// This regex only matches hostname declarations at the beginning of lines (column 1 after optional whitespace)
/// and excludes nested directives like "reverse_proxy target {".
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[GeneratedRegex(@"(?m)^\s*([^\{\r\n]+?)\s*\{", RegexOptions.Multiline)] [GeneratedRegex(@"(?m)^([^\s\{\r\n][^\{\r\n]*?)\s*\{", RegexOptions.Multiline)]
private static partial Regex HostnamesRegex(); private static partial Regex HostnamesRegex();
/// <summary> /// <summary>
@@ -67,8 +69,8 @@ public partial class CaddyConfigurationParsingService: ICaddyConfigurationParsin
foreach (Match match in matches) foreach (Match match in matches)
{ {
var parts = match.Value.TrimEnd('}').Trim().Split(' '); // Use the captured group which contains the target (e.g., pikachu:3011)
var targetPart = parts.LastOrDefault(string.Empty); var targetPart = match.Groups[1].Value.Trim();
if (string.IsNullOrEmpty(targetPart)) continue; if (string.IsNullOrEmpty(targetPart)) continue;
var targetComponents = targetPart.Split(':'); var targetComponents = targetPart.Split(':');

View File

@@ -74,11 +74,9 @@ public class CaddyConfigurationParsingServiceTests
// Assert // Assert
result.Should().NotBeNull(); result.Should().NotBeNull();
result.Should().HaveCount(4); // Updated to reflect correct parsing of labels before blocks result.Should().HaveCount(2); // Should only return outermost hostname declarations
result.Should().Contain("api.example.com"); result.Should().Contain("api.example.com");
result.Should().Contain("app.example.com"); result.Should().Contain("app.example.com");
result.Should().Contain("route /v1/*");
result.Should().Contain("route /v2/*");
} }
/// <summary> /// <summary>
@@ -522,12 +520,9 @@ app.example.com {
// Assert // Assert
result.Should().NotBeNull(); result.Should().NotBeNull();
result.Should().HaveCount(5); result.Should().HaveCount(2); // Should only return outermost hostname declarations
result.Should().Contain("api.example.com"); result.Should().Contain("api.example.com");
result.Should().Contain("app.example.com"); result.Should().Contain("app.example.com");
result.Should().Contain("header");
result.Should().Contain("@cors");
result.Should().Contain("tls");
} }
/// <summary> /// <summary>