Skip to content

Commit 1960bd4

Browse files
thomhurstclaude
andauthored
refactor: Replace magic numbers with named constants (#1470)
* chore: Add .worktrees/ to .gitignore for parallel development 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: Replace magic numbers with named constants - Create LoggingConstants with SecretMask, CommandMask, and body size constants - Create ConcurrencyConstants with ParallelismMultiplier - Add TestFramework constant to BuildConstants - Update SecretObfuscator to use LoggingConstants.SecretMask - Update CommandLogger to use LoggingConstants.CommandMask - Update HttpLoggingOptions to use LoggingConstants for body size limits - Update ConcurrencyOptions to use ConcurrencyConstants.ParallelismMultiplier - Update RunUnitTestsModule to use BuildConstants.TestFramework Fixes #1457 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 2b4e59a commit 1960bd4

8 files changed

Lines changed: 58 additions & 6 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
namespace ModularPipelines.Build;
22

3+
/// <summary>
4+
/// Constants used for build configuration.
5+
/// </summary>
36
public static class BuildConstants
47
{
58
public const string Owner = "thomhurst";
69
public const string RepositoryName = "ModularPipelines";
10+
11+
/// <summary>
12+
/// The target framework for running tests.
13+
/// </summary>
14+
public const string TestFramework = "net10.0";
715
}

src/ModularPipelines.Build/Modules/RunUnitTestsModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class RunUnitTestsModule : Module<CommandResult[]>, IRetryable<CommandRes
3030
{
3131
Project = unitTestProjectFile.Path,
3232
NoBuild = true,
33-
Framework = "net10.0",
33+
Framework = BuildConstants.TestFramework,
3434
Arguments = ["--coverage", "--coverage-output-format", "cobertura"],
3535
Configuration = Configuration.Release,
3636
EnvironmentVariables = new Dictionary<string, string?>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace ModularPipelines.Constants;
2+
3+
/// <summary>
4+
/// Constants used for concurrency and parallelism configuration.
5+
/// </summary>
6+
internal static class ConcurrencyConstants
7+
{
8+
/// <summary>
9+
/// The multiplier applied to ProcessorCount to calculate default maximum parallelism.
10+
/// </summary>
11+
public const int ParallelismMultiplier = 4;
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace ModularPipelines.Constants;
2+
3+
/// <summary>
4+
/// Constants used for logging and output formatting.
5+
/// </summary>
6+
internal static class LoggingConstants
7+
{
8+
/// <summary>
9+
/// The string used to mask secret values in logs.
10+
/// </summary>
11+
public const string SecretMask = "**********";
12+
13+
/// <summary>
14+
/// The string used to mask command arguments when they should not be displayed.
15+
/// </summary>
16+
public const string CommandMask = "********";
17+
18+
/// <summary>
19+
/// Default maximum body size (4KB) for HTTP logging.
20+
/// </summary>
21+
public const int DefaultMaxBodySizeToLog = 4096;
22+
23+
/// <summary>
24+
/// Full logging maximum body size (64KB) for HTTP logging.
25+
/// </summary>
26+
public const int FullLoggingMaxBodySize = 65536;
27+
}

src/ModularPipelines/Engine/SecretObfuscator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text;
22
using Initialization.Microsoft.Extensions.DependencyInjection;
3+
using ModularPipelines.Constants;
34

45
namespace ModularPipelines.Engine;
56

@@ -30,7 +31,7 @@ public string Obfuscate(string? input, object? optionsObject)
3031
{
3132
if (input.Contains(secret))
3233
{
33-
stringBuilder.Replace(secret, "**********");
34+
stringBuilder.Replace(secret, LoggingConstants.SecretMask);
3435
}
3536
}
3637

src/ModularPipelines/Logging/CommandLogger.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.Logging;
22
using Microsoft.Extensions.Options;
3+
using ModularPipelines.Constants;
34
using ModularPipelines.Engine;
45
using ModularPipelines.Enums;
56
using ModularPipelines.Helpers;
@@ -130,7 +131,7 @@ private void LogCommandInput(CommandLoggingOptions options, CommandLineToolOptio
130131
}
131132
else
132133
{
133-
Logger.LogInformation("{Timestamp}Command: {WorkingDirectory}> ********",
134+
Logger.LogInformation("{Timestamp}Command: {WorkingDirectory}> " + LoggingConstants.CommandMask,
134135
timestamp,
135136
workingDirectory);
136137
}

src/ModularPipelines/Options/ConcurrencyOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using ModularPipelines.Constants;
23

34
namespace ModularPipelines.Options;
45

@@ -22,7 +23,7 @@ public record ConcurrencyOptions
2223
/// options.Concurrency.MaxParallelism = int.MaxValue;
2324
/// </code>
2425
/// </example>
25-
public int MaxParallelism { get; set; } = Environment.ProcessorCount * 4;
26+
public int MaxParallelism { get; set; } = Environment.ProcessorCount * ConcurrencyConstants.ParallelismMultiplier;
2627

2728
/// <summary>
2829
/// Gets or sets the maximum number of CPU-intensive modules that can execute concurrently.

src/ModularPipelines/Options/HttpLoggingOptions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using ModularPipelines.Constants;
2+
13
namespace ModularPipelines.Options;
24

35
/// <summary>
@@ -67,7 +69,7 @@ public record HttpLoggingOptions
6769
/// Bodies larger than this will be truncated with a message indicating the full size.
6870
/// Set to 0 or negative to disable truncation.
6971
/// </summary>
70-
public int MaxBodySizeToLog { get; init; } = 4096;
72+
public int MaxBodySizeToLog { get; init; } = LoggingConstants.DefaultMaxBodySizeToLog;
7173

7274
/// <summary>
7375
/// Default logging options (all logging enabled, 4KB body limit).
@@ -132,6 +134,6 @@ public record HttpLoggingOptions
132134
LogResponseBody = true,
133135
LogStatusCode = true,
134136
LogDuration = true,
135-
MaxBodySizeToLog = 65536,
137+
MaxBodySizeToLog = LoggingConstants.FullLoggingMaxBodySize,
136138
};
137139
}

0 commit comments

Comments
 (0)