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.

EditMode: isolate Input System state in the camera input fixtures (Fixes #1903) (#1957)

Beri6c225ca04326
diff --git a/unity/Assets/Tests/EditMode/CameraInputTests.cs b/unity/Assets/Tests/EditMode/CameraInputTests.cs
index 093cbda9e..13b957c12 100644
--- a/unity/Assets/Tests/EditMode/CameraInputTests.cs
+++ b/unity/Assets/Tests/EditMode/CameraInputTests.cs
@@ -6,6 +6,29 @@ using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
+/// <summary>Base for every fixture that enables the Camera map of the shared Assets/InputSystem_Actions.inputactions asset
+/// (#1903). The asset is one object for the whole editor session and keeps its resolved state across the Input System's
+/// save, reset and restore, so a fixture could enable the map against controls of devices it does not have (an
+/// IndexOutOfRangeException inside the Input System) or against another fixture's recycled device indices. Each fixture
+/// therefore starts with the asset's state dropped (code outside these fixtures, such as the editor's own input system,
+/// can have resolved it) and ends the same way. NUnit runs this SetUp after InputTestFixture's (the fixture's own input
+/// system is in place) and this TearDown before it (the fixture's devices still exist).</summary>
+public abstract class SharedCameraActionsFixture : InputTestFixture
+{
+ static void DropTheResolvedState()
+ {
+ var actions = AssetDatabase.LoadAssetAtPath<InputActionAsset>("Assets/InputSystem_Actions.inputactions");
+ Assert.IsNotNull(actions, "the shipped input asset must exist");
+ actions.Disable();
+ // Dispose drops the state all the maps share, so the next enable resolves from scratch against the live devices.
+ foreach (var map in actions.actionMaps) map.Dispose();
+ }
+
+ [SetUp] public void StartWithoutResolvedCameraActions() => DropTheResolvedState();
+
+ [TearDown] public void EndWithoutResolvedCameraActions() => DropTheResolvedState();
+}
+
public class CameraInputTests
{
static CameraRig NewRig()
@@ -661,7 +684,7 @@ public class CameraInputTests
/// test fixture, the project-wide Camera actions, and CameraController's frame (Tick, which Update calls), so a key that
/// stops being read or a modifier that stops being passed on goes red. Edit mode sends no Awake/OnEnable/OnDisable, so
/// the test sends them.</summary>
-public class CameraZoomKeysThroughTheInputSystemTests : InputTestFixture
+public class CameraZoomKeysThroughTheInputSystemTests : SharedCameraActionsFixture
{
static void Send(CameraController c, string message) =>
typeof(CameraController).GetMethod(message, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
@@ -760,7 +783,7 @@ public class CameraZoomKeysThroughTheInputSystemTests : InputTestFixture
}
// #1661 B1/S1/N1: real actions, independent of Ella's pointer fixture.
-public class PressOriginCameraInputTests : InputTestFixture
+public class PressOriginCameraInputTests : SharedCameraActionsFixture
{
static void Send(Object o, string method) => o.GetType().GetMethod(method,
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.Invoke(o, null);
@@ -908,7 +931,7 @@ public class PressOriginCameraInputTests : InputTestFixture
/// in the macOS player, a stand-in here, since an edit-mode test cannot make a Cocoa magnify event). The owner found
/// on 27 Oct 2026 that zooming did nothing in the macOS player: the wheel, a two-finger scroll and the keys did zoom
/// there, but a pinch never reached the Input System at all.</summary>
-public class CameraPointerZoomThroughTheFrameTests : InputTestFixture
+public class CameraPointerZoomThroughTheFrameTests : SharedCameraActionsFixture
{
static void Send(Object o, string message) =>
o.GetType().GetMethod(message, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
diff --git a/unity/Assets/Tests/EditMode/FixedNorthCameraTests.cs b/unity/Assets/Tests/EditMode/FixedNorthCameraTests.cs
index b21251ecb..85524cfab 100644
--- a/unity/Assets/Tests/EditMode/FixedNorthCameraTests.cs
+++ b/unity/Assets/Tests/EditMode/FixedNorthCameraTests.cs
@@ -8,7 +8,7 @@ using UnityEngine;
using UnityEngine.InputSystem;
// R-CAMERA-001: owner ruling, 27 October 2026, #1720.
-public class FixedNorthCameraTests : InputTestFixture
+public class FixedNorthCameraTests : SharedCameraActionsFixture
{
GameObject go = null!;
CameraRig rig = null!;
diff --git a/unity/Assets/Tests/EditMode/MapFocusTests.cs b/unity/Assets/Tests/EditMode/MapFocusTests.cs
index 3954dc758..452a32b18 100644
--- a/unity/Assets/Tests/EditMode/MapFocusTests.cs
+++ b/unity/Assets/Tests/EditMode/MapFocusTests.cs
@@ -382,7 +382,7 @@ public class MapFocusTests
/// <summary>#41 B1b: the camera keys through the Input System's own path (a virtual keyboard from its test fixture and the
/// project-wide Camera actions), with the map stop focused and its presenter listening: the same keys reach the stop as
/// UI key events, the camera still pans, the focus stays on the stop and nothing is picked. Synchronous, as InputTestFixture allows in edit mode.</summary>
-public class MapFocusCameraKeysTests : InputTestFixture
+public class MapFocusCameraKeysTests : SharedCameraActionsFixture
{
static void Send(MonoBehaviour c, string message) =>
c.GetType().GetMethod(message, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.Invoke(c, null);
@@ -393,9 +393,6 @@ public class MapFocusCameraKeysTests : InputTestFixture
var actions = AssetDatabase.LoadAssetAtPath<InputActionAsset>("Assets/InputSystem_Actions.inputactions");
InputSystem.actions = actions;
var keyboard = InputSystem.AddDevice<Keyboard>();
- // Resolve the shared asset against this fixture's own keyboard only. Earlier tests can leave it resolved against
- // devices this fixture does not have, and enabling the Camera map then fails (a test isolation issue).
- actions.devices = new InputDevice[] { keyboard };
using var kit = new UiTestKit();
kit.Q<VisualElement>("root").RemoveFromClassList("loading");
var stop = kit.Q<VisualElement>("map-focus");
@@ -427,6 +424,6 @@ public class MapFocusCameraKeysTests : InputTestFixture
Assert.AreSame(stop, kit.Root.panel.focusController.focusedElement, "the focus stays on the stop");
Assert.AreEqual(0, picked, "a pan picks nothing");
}
- finally { presenter.Dispose(); Send(c, "OnDisable"); Object.DestroyImmediate(go); actions.devices = null; }
+ finally { presenter.Dispose(); Send(c, "OnDisable"); Object.DestroyImmediate(go); }
}
}
diff --git a/unity/Assets/Tests/EditMode/MapPointerTickTests.cs b/unity/Assets/Tests/EditMode/MapPointerTickTests.cs
index 705c7b930..45c351431 100644
--- a/unity/Assets/Tests/EditMode/MapPointerTickTests.cs
+++ b/unity/Assets/Tests/EditMode/MapPointerTickTests.cs
@@ -13,7 +13,7 @@ using UnityEngine.InputSystem;
/// default to <c>queueEventOnly: false</c>, so each call runs its own <c>InputSystem.Update</c>. A gesture written as
/// three plain calls therefore spans three input updates, and the press edge is gone before <c>Tick</c> runs. To put a
/// whole gesture inside one input update, every call but the last passes <c>queueEventOnly: true</c>.</para></summary>
-public class MapPointerTickTests : InputTestFixture
+public class MapPointerTickTests : SharedCameraActionsFixture
{
static void Send(Object o, string message) =>
o.GetType().GetMethod(message, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.Invoke(o, null);
diff --git a/unity/Assets/Tests/EditMode/MapPressTests.cs b/unity/Assets/Tests/EditMode/MapPressTests.cs
index a60611afe..fd38129e6 100644
--- a/unity/Assets/Tests/EditMode/MapPressTests.cs
+++ b/unity/Assets/Tests/EditMode/MapPressTests.cs
@@ -100,7 +100,7 @@ public class MapPressTests
/// CameraController.Tick, wired as GameRoot wires them (HoldsMouseDrag = RightTapCandidate || LeftTapCandidate). The UI
/// recorder stands in for the map: it is asked once per click or order. Edit mode sends no OnEnable, so the test sends
/// it.</summary>
-public class RightClickOrPanTests : InputTestFixture
+public class RightClickOrPanTests : SharedCameraActionsFixture
{
static void Send(Object o, string message) =>
o.GetType().GetMethod(message, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.Invoke(o, null);