Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

Machine-read text uses the invariant culture (Fixes #2662) (#2680)

Eyal Golan4217deb855b5
diff --git a/changelog.d/2662.md b/changelog.d/2662.md
new file mode 100644
index 000000000..e1aa8694e
--- /dev/null
+++ b/changelog.d/2662.md
@@ -0,0 +1,3 @@
+### Fixed
+
+- Make collection checks, diagnostic protocols, locality URL checks and CLI preview headings independent of the machine's culture.
diff --git a/sim/Statecraft.Sim.Tests/PreviewTests.cs b/sim/Statecraft.Sim.Tests/PreviewTests.cs
index 2d343ca9b..b93bc0167 100644
--- a/sim/Statecraft.Sim.Tests/PreviewTests.cs
+++ b/sim/Statecraft.Sim.Tests/PreviewTests.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
using System.IO;
using System.Linq;
using Statecraft.Sim;
@@ -39,6 +40,30 @@ public class PreviewTests
Assert.Equal(before, Snapshot());
}
+ [Fact]
+ public void HeadersUseInvariantDatesAndNumbers()
+ {
+ string Headers(CultureInfo culture)
+ {
+ var previous = CultureInfo.CurrentCulture;
+ try
+ {
+ CultureInfo.CurrentCulture = culture;
+ return string.Join("\n",
+ Preview.Run(Root, new DateTime(1949, 1, 1), GoldenRun.Seed,
+ None, Array.Empty<string>(), 8)
+ .Split('\n')
+ .Where(line => line.StartsWith("Preview:", StringComparison.Ordinal)
+ || line.StartsWith("Final state,", StringComparison.Ordinal)));
+ }
+ finally { CultureInfo.CurrentCulture = previous; }
+ }
+
+ Assert.Equal(
+ Headers(CultureInfo.InvariantCulture),
+ Headers(new CultureInfo("ar-SA")));
+ }
+
[Theory]
[InlineData("tax_per_capita_per_yeer=0.1", "no top-level key")]
[InlineData("budget_start=1", "is a block")]
diff --git a/sim/Statecraft.Sim/Preview.cs b/sim/Statecraft.Sim/Preview.cs
index a350820a8..b58397ace 100644
--- a/sim/Statecraft.Sim/Preview.cs
+++ b/sim/Statecraft.Sim/Preview.cs
@@ -85,10 +85,12 @@ namespace Statecraft.Sim
var a = Play(baseContent, seed, until, every);
var b = Play(changed, seed, until, every);
var sb = new StringBuilder();
- sb.AppendLine($"Preview: seed {seed}, until {until:yyyy-MM-dd}, changes: {(sets.Count == 0 ? "(none)" : string.Join(", ", sets))}");
+ sb.AppendLine(FormattableString.Invariant(
+ $"Preview: seed {seed}, until {until:yyyy-MM-dd}, changes: {(sets.Count == 0 ? "(none)" : string.Join(", ", sets))}"));
sb.AppendLine("Nothing is written; content/ is untouched.");
sb.AppendLine();
- sb.AppendLine($"Final state, base {a[a.Count - 1].Date:yyyy-MM-dd} hash {a[a.Count - 1].Hash().Substring(0, 8)} -> changed {b[b.Count - 1].Date:yyyy-MM-dd} hash {b[b.Count - 1].Hash().Substring(0, 8)}");
+ sb.AppendLine(FormattableString.Invariant(
+ $"Final state, base {a[a.Count - 1].Date:yyyy-MM-dd} hash {a[a.Count - 1].Hash().Substring(0, 8)} -> changed {b[b.Count - 1].Date:yyyy-MM-dd} hash {b[b.Count - 1].Hash().Substring(0, 8)}"));
sb.Append(StateDiff.Lines(a[a.Count - 1].Describe(), b[b.Count - 1].Describe()));
if (show.Count > 0)
{
diff --git a/unity/Assets/Scripts/Map/Collection/CollectionCatalog.cs b/unity/Assets/Scripts/Map/Collection/CollectionCatalog.cs
index 03cbb146f..c148879e8 100644
--- a/unity/Assets/Scripts/Map/Collection/CollectionCatalog.cs
+++ b/unity/Assets/Scripts/Map/Collection/CollectionCatalog.cs
@@ -1,6 +1,7 @@
#nullable enable
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
namespace Statecraft.Game.Map.Collection
@@ -32,7 +33,8 @@ namespace Statecraft.Game.Map.Collection
public readonly long Bytes;
public readonly string Sha256;
public BundleCheck(uint crc, long bytes, string sha256) { Crc = crc; Bytes = bytes; Sha256 = sha256; }
- public override string ToString() => $"{Crc} {Bytes} {Sha256}";
+ public override string ToString() =>
+ FormattableString.Invariant($"{Crc} {Bytes} {Sha256}");
}
/// <summary>Reads <see cref="ChecksFile"/>; null when any line is malformed (so a damaged list checks nothing).</summary>
@@ -44,7 +46,10 @@ namespace Statecraft.Game.Map.Collection
var line = raw.Trim();
if (line.Length == 0) continue;
var f = line.Split(' ');
- if (f.Length != 4 || !uint.TryParse(f[1], out var crc) || !long.TryParse(f[2], out var bytes) || f[3].Length != 64)
+ if (f.Length != 4
+ || !uint.TryParse(f[1], NumberStyles.None, CultureInfo.InvariantCulture, out var crc)
+ || !long.TryParse(f[2], NumberStyles.None, CultureInfo.InvariantCulture, out var bytes)
+ || f[3].Length != 64)
return null;
found[f[0]] = new BundleCheck(crc, bytes, f[3]);
}
@@ -56,7 +61,7 @@ namespace Statecraft.Game.Map.Collection
{
using var f = System.IO.File.OpenRead(path);
using var sha = System.Security.Cryptography.SHA256.Create();
- return string.Concat(sha.ComputeHash(f).Select(x => x.ToString("x2")));
+ return string.Concat(sha.ComputeHash(f).Select(x => x.ToString("x2", CultureInfo.InvariantCulture)));
}
public const string People = "collection-people", Vehicles = "collection-vehicles", Animals = "collection-animals",
diff --git a/unity/Assets/Scripts/Map/Kits/Localities.cs b/unity/Assets/Scripts/Map/Kits/Localities.cs
index 7677cd59e..831894771 100644
--- a/unity/Assets/Scripts/Map/Kits/Localities.cs
+++ b/unity/Assets/Scripts/Map/Kits/Localities.cs
@@ -293,7 +293,8 @@ namespace Statecraft.Game.Map.Kits
throw new InvalidDataException($"{at} name_he_review '{p.NameHeReview}' is not agent-checked (delete the line once a native speaker, or an AI-assisted contributor who discloses it, has reviewed the name, #564)");
if (p.NameHeReviewGiven && string.IsNullOrWhiteSpace(p.NameHe)) throw new InvalidDataException($"{at} name_he_review without a name_he");
for (int i = 0; i < p.NameHeSources.Count; i++)
- if (!p.NameHeSources[i].Url.StartsWith("https://") || string.IsNullOrWhiteSpace(p.NameHeSources[i].Checked))
+ if (!p.NameHeSources[i].Url.StartsWith("https://", System.StringComparison.Ordinal)
+ || string.IsNullOrWhiteSpace(p.NameHeSources[i].Checked))
throw new InvalidDataException($"{at} name_he_sources[{i}] needs an https url and a checked date");
doc.Places.Add(new Place
{
@@ -455,7 +456,8 @@ namespace Statecraft.Game.Map.Kits
if (string.IsNullOrWhiteSpace(checkedOn)) throw new InvalidDataException($"{at} has no checked date");
if (count < 1) throw new InvalidDataException($"{at} sources is empty");
for (int i = 0; i < sources.Count; i++)
- if (string.IsNullOrWhiteSpace(sources[i]?.Url) || !sources[i].Url.StartsWith("https://"))
+ if (string.IsNullOrWhiteSpace(sources[i]?.Url)
+ || !sources[i].Url.StartsWith("https://", System.StringComparison.Ordinal))
throw new InvalidDataException($"{at} sources[{i}] is not an https URL");
}
diff --git a/unity/Assets/Scripts/Map/VisualShots.cs b/unity/Assets/Scripts/Map/VisualShots.cs
index e7822e0cf..3792500fd 100644
--- a/unity/Assets/Scripts/Map/VisualShots.cs
+++ b/unity/Assets/Scripts/Map/VisualShots.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Security.Cryptography;
using Statecraft.Game.Boot;
@@ -29,10 +30,12 @@ namespace Statecraft.Game.Map
var b64 = Convert.ToBase64String(png);
int n = Math.Max(1, (b64.Length + ChunkChars - 1) / ChunkChars);
string hash;
- using (var sha = SHA256.Create()) hash = string.Concat(sha.ComputeHash(png).Select(b => b.ToString("x2")));
- yield return $"SHOT {name} begin {n} {hash}";
+ using (var sha = SHA256.Create())
+ hash = string.Concat(sha.ComputeHash(png).Select(b => b.ToString("x2", CultureInfo.InvariantCulture)));
+ yield return FormattableString.Invariant($"SHOT {name} begin {n} {hash}");
for (int i = 0; i < n; i++)
- yield return $"SHOT {name} {i + 1}/{n} {b64.Substring(i * ChunkChars, Math.Min(ChunkChars, b64.Length - i * ChunkChars))}";
+ yield return FormattableString.Invariant(
+ $"SHOT {name} {i + 1}/{n} {b64.Substring(i * ChunkChars, Math.Min(ChunkChars, b64.Length - i * ChunkChars))}");
}
/// <summary>The visual toggles that are off for the close checks, which look at the ground itself (the baked
diff --git a/unity/Assets/Scripts/UI/NavEventLog.cs b/unity/Assets/Scripts/UI/NavEventLog.cs
index 1b373d2d7..9eb492e34 100644
--- a/unity/Assets/Scripts/UI/NavEventLog.cs
+++ b/unity/Assets/Scripts/UI/NavEventLog.cs
@@ -80,7 +80,8 @@ namespace Statecraft.Game.UI
void OnDown(PointerDownEvent e) => DiagLog.NavLine(FormattableString.Invariant($"ui pointerdown id={e.pointerId} at ({e.position.x:0}, {e.position.y:0}) target={Name(e.target)} path={Path(e.target)} modals={Modals()}"));
void OnUp(PointerUpEvent e) => DiagLog.NavLine(FormattableString.Invariant($"ui pointerup id={e.pointerId} at ({e.position.x:0}, {e.position.y:0}) target={Name(e.target)}"));
- void OnClick(ClickEvent e) => DiagLog.NavLine($"ui click count={e.clickCount} target={Name(e.target)}");
+ void OnClick(ClickEvent e) => DiagLog.NavLine(
+ FormattableString.Invariant($"ui click count={e.clickCount} target={Name(e.target)}"));
void OnButtonUp(PointerUpEvent e) => DiagLog.NavLine(FormattableString.Invariant($"button pointerup at ({e.position.x:0}, {e.position.y:0}) on={Name(e.currentTarget)} inside={((VisualElement)e.currentTarget).worldBound.Contains(e.position)}"));
void OnCaptureOut(PointerCaptureOutEvent e) => DiagLog.NavLine($"button capture out on={Name(e.currentTarget)}");
diff --git a/unity/Assets/Tests/EditMode/CollectionImportTests.cs b/unity/Assets/Tests/EditMode/CollectionImportTests.cs
index 02859dd14..044902bab 100644
--- a/unity/Assets/Tests/EditMode/CollectionImportTests.cs
+++ b/unity/Assets/Tests/EditMode/CollectionImportTests.cs
@@ -1,6 +1,7 @@
#nullable enable
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using NUnit.Framework;
using Statecraft.Game.Map.Collection;
@@ -61,6 +62,26 @@ public class CollectionImportTests
}
}
+ [Test]
+ public void ChecksUseUnsignedInvariantMachineFields()
+ {
+ var previous = CultureInfo.CurrentCulture;
+ try
+ {
+ var culture = (CultureInfo)CultureInfo.InvariantCulture.Clone();
+ culture.NumberFormat.PositiveSign = "plus";
+ culture.NumberFormat.NegativeSign = "minus";
+ CultureInfo.CurrentCulture = culture;
+ var hash = new string('a', 64);
+
+ Assert.IsNull(CollectionCatalog.ParseChecks($"bundle plus1 2 {hash}\n"),
+ "the checks format accepts digits only");
+ Assert.AreEqual($"1 -2 {hash}",
+ new CollectionCatalog.BundleCheck(1, -2, hash).ToString());
+ }
+ finally { CultureInfo.CurrentCulture = previous; }
+ }
+
[Test]
public void TheCatalogKeeps73IndependentOriginalsAndTheGeneratedInfantryBundle()
{
diff --git a/unity/Assets/Tests/EditMode/KitTests.cs b/unity/Assets/Tests/EditMode/KitTests.cs
index abe471a43..70a758a45 100644
--- a/unity/Assets/Tests/EditMode/KitTests.cs
+++ b/unity/Assets/Tests/EditMode/KitTests.cs
@@ -591,6 +591,7 @@ public class KitTests
Bad("places:\n" + Place("a").Replace("population: 1200", "population: 0"), "population");
Bad("places:\n" + Place("a").Replace("status: draft", "status: guess"), "status");
Bad("places:\n" + Place("a").Replace("https://example.org/x", "example.org/x"), "URL");
+ Bad("places:\n" + Place("a").Replace("https://example.org/x", "https:\u00ad//example.org/x"), "URL");
Bad("places:\n" + Place("a", " fate: x\n"), "fate");
Bad("places:\n" + Place("a", " today:\n name: Y\n") , "today");
// A person's sign-off (#375): both or neither, a GitHub handle (never an email), a day; on a place or a camp row.
@@ -604,6 +605,9 @@ public class KitTests
// #558: name_he_sources need the name, and each source an https url and a checked date.
Bad("places:\n" + Place("a", " name_he_sources:\n - {url: 'https://he.wikipedia.org/x', checked: '2026-10-14'}\n"), "name_he_sources without a name_he");
Bad("places:\n" + Place("a", " name_he: \"\\u05D0\"\n name_he_sources:\n - {url: 'https://he.wikipedia.org/x'}\n"), "name_he_sources[0]");
+ Bad("places:\n" + Place("a",
+ " name_he: \"\\u05D0\"\n name_he_sources:\n - {url: 'https:\u00ad//he.wikipedia.org/x', checked: '2026-10-14'}\n"),
+ "name_he_sources[0]");
Bad("places:\n" + Place("a", " name_he: \"\\u05D0\"\n name_he_sources:\n - {url: 'https://x', when: y}\n"), "unknown key 'when'");
// The review flag (#564): agent-checked on a named row only, any other value refused.
Bad("places:\n" + Place("a", " name_he_review: agent-checked\n"), "name_he_review without a name_he");