using System.Reflection;
using AcDream.Core.Physics;
using AcDream.Headless.Configuration;
using AcDream.Headless.Diagnostics;
namespace AcDream.Headless.Hosting;
///
/// Rejects process-global physics probes whose mutable capture cursors and
/// last-hit fields cannot be attributed safely when several Runtime roots
/// share one process. Ordinary diagnostics remain session-labelled through
/// .
///
///
/// #365 Step 1: the refusal's rationale is multi-root attribution ambiguity
/// — it does not hold for a process that owns exactly ONE session, since
/// there is no second root to confuse a probe's cursor/last-hit fields
/// with. Refusing anyway made the exact probe built to diagnose the #365
/// hydration stall (ACDREAM_PROBE_PARK=1) impossible to run against
/// the single-session repro that needed it. A
/// of 1 now logs the enabled probes loudly and proceeds; anything else
/// keeps the original hard refusal, naming every enabled probe.
///
internal static class HeadlessStaticStateAudit
{
///
/// Consolidated-review round (2026-08-10), NIT (a):
/// is the SAME structured writer every other headless diagnostic uses
/// ('s _diagnostics field, now
/// constructed before this call rather than after it) — the raw
/// Console.WriteLine this replaced bypassed the session-labelled
/// JSON stream every other producer writes into.
///
internal static void ValidateProcessIsolation(
int sessionCount, HeadlessDiagnosticWriter diagnostics)
{
ArgumentNullException.ThrowIfNull(diagnostics);
var enabled = new List();
foreach (PropertyInfo property in typeof(PhysicsDiagnostics)
.GetProperties(BindingFlags.Public | BindingFlags.Static)
.OrderBy(static property => property.Name, StringComparer.Ordinal))
{
if (property.PropertyType != typeof(bool)
|| property.GetMethod is null
|| (!property.Name.StartsWith(
"Probe",
StringComparison.Ordinal)
&& !property.Name.StartsWith(
"Dump",
StringComparison.Ordinal)))
{
continue;
}
if (property.GetValue(null) is true)
enabled.Add(property.Name);
}
if (PhysicsDiagnostics.CollisionShadowSampleEvery > 0)
enabled.Add(nameof(PhysicsDiagnostics.CollisionShadowSampleEvery));
if (PhysicsResolveCapture.IsEnabled)
enabled.Add(nameof(PhysicsResolveCapture));
if (enabled.Count == 0)
return;
if (sessionCount == 1)
{
diagnostics.Message(
sessionId: "process",
eventName: FormattableString.Invariant(
$"headless-audit: single-session process — process-global physics probes enabled: {string.Join(", ", enabled)}"));
return;
}
throw new HeadlessConfigurationException(
"Multi-session headless mode cannot use process-global "
+ "physics probes. Disable: "
+ string.Join(", ", enabled));
}
}