Run 170's Windows gate went red on 37 tests across four assemblies while the same commit passed 14,370/0 locally. The failures were all one family: Expected: "You have 1 500p" <- built with the machine's culture Actual: "You have 1,500p" <- production, correctly invariant The runner is Swedish; this dev box is not. These tests had been passing on CI only because that machine's registry locale had been pinned by hand — machine state, which came undone (almost certainly the reboot after today's hang). Re-pinning it would be a workaround on one machine for a defect in the repo, so this fixes the repo instead. Two genuinely different bugs were hiding in that one symptom. 1. TESTS that build an expected string with the ambient culture and compare it to invariant production output, and test-side recording sinks whose traces are compared against literal golden strings. Those only ever passed on a machine that happens to format like the invariant culture. Pinned to InvariantCulture: the vendor purse/cost expectations, and the motion-funnel, animation-sequencer, framebuffer-resize, resource-slot, and runtime-attack trace sinks. 2. PRODUCTION that formats player-visible retail text with the ambient culture. This one matters beyond CI: retail is a US client, so it shows "2.50", "1,500p" and "(-20)" to everyone. On a Swedish machine acdream was showing "2,50", "1 500p" and "(-20)" with U+2212 MINUS SIGN — the audience for this alpha is literally Swedish. Converted 76 sites to InvariantCulture across the item/creature appraisal formatters, the character stat panel's buff and vitae parentheticals, the appraisal and link-status controllers, the chat /framerate and /location output, the camera sensitivity toast, the time-override toast, the F3 dump, the sky diagnostics, and the world-frame invariant-failure message. DATES are deliberately left on the current culture (CharacterController's birth/login stamp, RuntimeHouseState's purchase expiry). Retail has no answer for a non-US player's date format, and forcing "08/19/2026 7:00:00 PM" on them is a UX decision, not a retail-fidelity one. Apparatus, so the next occurrence is reproducible instead of mysterious: tests/TestCultureInitializer.cs adds an opt-in ACDREAM_TEST_CULTURE knob to every test assembly, linked in through a new tests/Directory.Build.props. Unset — what CI and everyone runs — it changes nothing. ACDREAM_TEST_CULTURE=sv-SE dotnet test ... reproduced all 37 CI failures on this machine plus 6 more the runner's own locale does not surface (the Unicode-minus family), and drove the fix. Verified both ways on the full solution under the release-gate filter: default culture 14,370 passed / 0 failed, and ACDREAM_TEST_CULTURE=sv-SE 14,370 passed / 0 failed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
54 lines
2.1 KiB
C#
54 lines
2.1 KiB
C#
using System.Globalization;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace AcDream.Tests;
|
|
|
|
/// <summary>
|
|
/// Lets a test run pin the ambient culture, so a locale-dependent failure can
|
|
/// be reproduced on any machine instead of only on one with the right Windows
|
|
/// locale.
|
|
///
|
|
/// <para><b>Why this exists.</b> On 2026-08-19 the Windows CI runner went red on
|
|
/// 37 tests across four assemblies with failures like
|
|
/// <c>Expected: "You have 1 500p" / Actual: "You have 1,500p"</c>. The
|
|
/// production code was right — it formats retail text with
|
|
/// <see cref="CultureInfo.InvariantCulture"/>, so every player sees retail's
|
|
/// comma. The TESTS were wrong: they built their expected strings with
|
|
/// <c>$"{value:N0}"</c>, which uses the machine's current culture, so they only
|
|
/// passed on a machine that happens to format like the invariant culture. The
|
|
/// runner is Swedish (space as the group separator), and the tests had been
|
|
/// passing there only because its registry locale had been pinned by hand —
|
|
/// a machine-state fix that silently came undone.</para>
|
|
///
|
|
/// <para>The expectations are fixed to be invariant. This knob is the
|
|
/// apparatus that makes such a break reproducible next time:
|
|
/// <c>ACDREAM_TEST_CULTURE=sv-SE dotnet test ...</c> runs the suite as the
|
|
/// Swedish runner sees it. Unset (the default, and what CI runs) changes
|
|
/// nothing at all.</para>
|
|
/// </summary>
|
|
internal static class TestCultureInitializer
|
|
{
|
|
internal const string CultureVariable = "ACDREAM_TEST_CULTURE";
|
|
|
|
[ModuleInitializer]
|
|
internal static void Initialize()
|
|
{
|
|
string? requested = Environment.GetEnvironmentVariable(CultureVariable);
|
|
if (string.IsNullOrWhiteSpace(requested))
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
var culture = CultureInfo.GetCultureInfo(requested);
|
|
CultureInfo.DefaultThreadCurrentCulture = culture;
|
|
CultureInfo.DefaultThreadCurrentUICulture = culture;
|
|
}
|
|
catch (CultureNotFoundException)
|
|
{
|
|
// A typo in an opt-in diagnostic must not fail an unrelated suite;
|
|
// the run simply keeps the machine's own culture.
|
|
}
|
|
}
|
|
}
|