From ab260ad0a626de97b691836355529857d0446242 Mon Sep 17 00:00:00 2001 From: mika kuns Date: Thu, 4 Jun 2026 19:09:49 +0200 Subject: [PATCH] feat(logging): runtime Debug-build detection via DebuggableAttribute --- src/ClaudeDo.Logging/BuildConfig.cs | 14 ++++++++++++++ .../Logging/BuildConfigTests.cs | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/ClaudeDo.Logging/BuildConfig.cs create mode 100644 tests/ClaudeDo.Worker.Tests/Logging/BuildConfigTests.cs diff --git a/src/ClaudeDo.Logging/BuildConfig.cs b/src/ClaudeDo.Logging/BuildConfig.cs new file mode 100644 index 0000000..2e13542 --- /dev/null +++ b/src/ClaudeDo.Logging/BuildConfig.cs @@ -0,0 +1,14 @@ +using System.Diagnostics; +using System.Reflection; + +namespace ClaudeDo.Logging; + +/// Runtime build-configuration detection — the replacement for #if DEBUG. +/// Debug builds compile with the JIT optimizer disabled; Release builds enable it. +public static class BuildConfig +{ + public static bool IsDebug { get; } = + Assembly.GetEntryAssembly() + ?.GetCustomAttribute() + ?.IsJITOptimizerDisabled ?? false; +} diff --git a/tests/ClaudeDo.Worker.Tests/Logging/BuildConfigTests.cs b/tests/ClaudeDo.Worker.Tests/Logging/BuildConfigTests.cs new file mode 100644 index 0000000..76d9293 --- /dev/null +++ b/tests/ClaudeDo.Worker.Tests/Logging/BuildConfigTests.cs @@ -0,0 +1,19 @@ +using System.Diagnostics; +using System.Reflection; +using ClaudeDo.Logging; + +namespace ClaudeDo.Worker.Tests.Logging; + +public sealed class BuildConfigTests +{ + [Fact] + public void IsDebug_MatchesEntryAssemblyDebuggableAttribute() + { + var entry = Assembly.GetEntryAssembly(); + var expected = entry? + .GetCustomAttribute() + ?.IsJITOptimizerDisabled ?? false; + + Assert.Equal(expected, BuildConfig.IsDebug); + } +}