Fix normalizer sidecar log and coverage test (#4)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
minsung
2026-04-07 14:17:22 +09:00
parent 7920de15b3
commit 05c7a3f388
6 changed files with 251 additions and 31 deletions

View File

@@ -163,6 +163,66 @@ public static class Rules
return false;
}
/// <summary>
/// Allowlist of field names whose values are known to be volatile boolean/scalar
/// settings (per docs/sut-catalog/json-configs.json). The values are replaced with
/// a deterministic placeholder so golden-file comparisons stay stable while still
/// preserving the field's presence and key order.
/// </summary>
public static readonly HashSet<string> VolatileSettingFieldNames = new(StringComparer.Ordinal)
{
"CanOverrideWireColorWithFace",
"IsSidePanelVisible",
"OverrideFaceColor",
"Solar_IsLocalTime",
"VisibleGrid",
"GridSnap",
"MidpointOsnap",
"GridSpacing",
"GridColor.ALPHA",
"GridColor.BLUE",
"GridColor.GREEN",
"GridColor.RED",
"MajorGridColor.ALPHA",
"MajorGridColor.BLUE",
"MajorGridColor.GREEN",
"MajorGridColor.RED",
};
public static (JsonNode? node, int count) MaskVolatileSettings(JsonNode? node)
{
int count = 0;
if (node is null) return (null, 0);
Walk(node);
return (node, count);
void Walk(JsonNode n)
{
if (n is JsonObject obj)
{
foreach (var kv in obj.ToList())
{
if (VolatileSettingFieldNames.Contains(kv.Key))
{
obj[kv.Key] = JsonValue.Create("<VOLATILE>");
count++;
}
else if (kv.Value is JsonObject || kv.Value is JsonArray)
{
Walk(kv.Value);
}
}
}
else if (n is JsonArray arr)
{
foreach (var item in arr)
{
if (item is JsonObject || item is JsonArray) Walk(item);
}
}
}
}
/// <summary>
/// Returns a new JsonNode with object keys sorted recursively. Counts the number of objects sorted.
/// </summary>