#if UNITY_EDITOR || DEVELOPMENT_BUILD using System; using System.Collections; using System.IO; using System.Linq; using System.Reflection; using KernelPanic.Combat; using KernelPanic.Core; using KernelPanic.Data; using KernelPanic.Meta; using KernelPanic.UI; using UnityEngine; using UnityEngine.UIElements; namespace KernelPanic.Run { /// Opt-in standalone development-build integration check with an isolated save. public sealed class PlayerSmokeRunner : MonoBehaviour { private string _output; private string _failure; private string _campaignSuccess; private string _stage = "startup"; private float _deadline; [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] private static void Install() { string[] args = Environment.GetCommandLineArgs(); int flag = Array.IndexOf(args, "--kernel-panic-smoke"); if (flag < 0) return; int saveFlag = Array.IndexOf(args, "--kernel-panic-save-path"); if (saveFlag < 0 || saveFlag + 1 >= args.Length || !Path.IsPathRooted(args[saveFlag + 1]) || File.Exists(args[saveFlag + 1]) || File.Exists(args[saveFlag + 1] + ".bak")) { Debug.LogError("Smoke check requires an absolute, unused --kernel-panic-save-path."); Application.Quit(2); return; } // Install before the menu's OnEnable can schedule the animated boot sequence. UIPreferences.ReducedMotion = true; // Session only; never writes preferences. var owner = new GameObject("Player smoke verification"); Application.runInBackground = true; DontDestroyOnLoad(owner); var runner = owner.AddComponent(); runner._output = Path.GetDirectoryName(args[saveFlag + 1]); Directory.CreateDirectory(runner._output); runner._deadline = Time.realtimeSinceStartup + 900; Application.logMessageReceived += runner.ObserveLog; } private void ObserveLog(string message, string trace, LogType type) { if (type == LogType.Exception || type == LogType.Error || type == LogType.Assert) _failure ??= message + "\n" + trace; } private IEnumerator Start() { // Pump manually so an exception writes a useful result and exits instead of hanging CI. var scenario = Scenario(); while (true) { bool next = false; object yielded = null; try { if (_failure != null) throw new InvalidOperationException(_failure); if (Time.realtimeSinceStartup > _deadline) throw new TimeoutException("Smoke check timed out at " + _stage); next = scenario.MoveNext(); if (next) yielded = scenario.Current; } catch (Exception ex) { _failure = ex.ToString(); } if (_failure != null || !next) break; yield return yielded; } Application.logMessageReceived -= ObserveLog; if (_failure == null && _campaignSuccess != null) { File.WriteAllText(Path.Combine(_output, "player-smoke-result.txt"), _campaignSuccess); Debug.Log("PLAYER_SMOKE_PASS"); Application.Quit(0); yield break; } File.WriteAllText(Path.Combine(_output, "player-smoke-result.txt"), _failure == null ? "PASS: starter selection -> configured run -> pile tabs/search/grouping/cost details/keyboard focus -> combat -> repository purchase -> save and exit without payout -> exact repository resume -> next wave -> shutdown -> run archive command/navigation -> original build details/copy seed/load setup -> saved rewards/history -> same-seed retry -> new-seed retry -> natural defeat with attributed damage" : "FAIL at " + _stage + "\n" + _failure); Debug.Log(_failure == null ? "PLAYER_SMOKE_PASS" : "PLAYER_SMOKE_FAIL: " + _failure); Application.Quit(_failure == null ? 0 : 1); } private IEnumerator Scenario() { // Preference loading is also a BeforeSceneLoad callback; reapply the session // override after all such callbacks, regardless of their registration order. UIPreferences.ReducedMotion = true; _stage = "starter selection"; yield return new WaitForSecondsRealtime(2); var menu = FindFirstObjectByType(); Require(menu != null, "Main menu scene did not initialize."); var starter = Field(menu, "starterSelection"); if (!starter.IsActive) { // Exercise the normal "any key" boot skip; hidden windows need not run // the animated panel scheduler at the same cadence as a visible window. var startupRoot = menu.GetComponent().rootVisualElement; using var skipIntro = KeyDownEvent.GetPooled(' ', KeyCode.Space, EventModifiers.None); skipIntro.target = startupRoot; startupRoot.SendEvent(skipIntro); } float starterDeadline = Time.realtimeSinceStartup + 30; while (!starter.IsActive && Time.realtimeSinceStartup < starterDeadline) yield return null; Require(starter.IsActive, $"Fresh profile did not show starter selection; boot elapsed={Field(menu, "_bootIntroElapsed")}, starterChosen={new SaveService().Load().starterChosen}."); var choices = Field>(starter, "_activeStarters"); int ubuntuIndex = choices.ToList().FindIndex(distro => distro.Id == "ubuntu"); Require(ubuntuIndex >= 0, "Ubuntu starter not available."); Call(starter, "Select", ubuntuIndex); using (var key = KeyDownEvent.GetPooled('\n', KeyCode.Return, EventModifiers.None)) starter.HandleKeyDown(key); using (var key = KeyDownEvent.GetPooled('y', KeyCode.Y, EventModifiers.None)) starter.HandleKeyDown(key); yield return null; Require(new SaveService().Load().IsUnitOwned("ubuntu"), "Starter choice was not persisted."); var training = TutorialScenario(); while (training.MoveNext()) yield return training.Current; if (Environment.GetCommandLineArgs().Contains("--kernel-panic-tutorial-smoke")) { _campaignSuccess = "PASS: two-wave guided tutorial, real targeting/revival/queue/stack, full clears, shop purchase, same-run resume, one-time 1000 Bandwidth + 1000 Entropy, clean normal-run workspace."; yield break; } menu = FindFirstObjectByType(); _stage = "run setup"; ConfigureMenu(menu); yield return null; Call(menu, "BootSelectedPackage"); CombatManager combat = null; while (combat == null || !combat.CanSurrenderRun) { yield return null; combat = FindFirstObjectByType(); } Require(combat.RunConfig.RunSeed == 12345, "Run seed was not handed off."); string originalBuild = BuildSignature(combat.RunConfig); var view = FindFirstObjectByType(); var previewRoot = view.GetComponent().rootVisualElement; var executionPreview = previewRoot.Q("ExecutionPreview"); int drawsBeforePreview = RandomRoll.DrawCount; executionPreview.value = true; yield return null; var previewContents = previewRoot.Q("ExecutionPreviewPopup") ?? executionPreview; Require(RandomRoll.DrawCount == drawsBeforePreview && previewContents.Q