diff --git a/terminal/strata_cli/launcher_heal.py b/terminal/strata_cli/launcher_heal.py index afc8396e5f..ce5b809ec7 100644 --- a/terminal/strata_cli/launcher_heal.py +++ b/terminal/strata_cli/launcher_heal.py @@ -14,9 +14,11 @@ from __future__ import annotations import os import sys +import time HEADER = "# Strata Terminal launcher for PowerShell" RENAMED_TO = "strata-direct.ps1" +LOG_NAME = "launcher-heal.log" # beside the renamed file: one line per rename def installed_bin(): @@ -64,6 +66,12 @@ def heal(path_value: str | None = None, extra: list | None = None, say=None, win except OSError: continue renamed.append(ps1) + try: # for support: when a update's own test start ran this, nobody saw the line below + with open(os.path.join(os.path.dirname(ps1), LOG_NAME), "a", encoding="utf-8") as log: + log.write(f"{time.strftime('%Y-%m-%d %H:%M:%S')} strata.ps1 was renamed to {RENAMED_TO} (a typed `strata` in PowerShell " + "runs a .ps1 before a .cmd, and the default execution policy refuses it)\n") + except OSError: + pass say(f"strata: {ps1} was renamed to {RENAMED_TO}. PowerShell runs a .ps1 file before a .cmd file and refuses it with its " "default settings; now typing strata works there.") except Exception: # noqa: BLE001 - never a reason for a launcher to fail diff --git a/terminal/tests/terminal/test_launcher_heal.py b/terminal/tests/terminal/test_launcher_heal.py index 9272e1e49a..8445d40c8b 100644 --- a/terminal/tests/terminal/test_launcher_heal.py +++ b/terminal/tests/terminal/test_launcher_heal.py @@ -54,6 +54,9 @@ class Heal(unittest.TestCase): self.assertEqual((self.dir / "strata-direct.ps1").read_text(encoding="utf-8"), OLD_PS1) self.assertEqual(len(self.said), 1) self.assertIn("strata-direct.ps1", self.said[0]) + log = (self.dir / launcher_heal.LOG_NAME).read_text(encoding="utf-8") # a line for support, also when nobody saw the one above + self.assertEqual(len(log.splitlines()), 1) + self.assertIn("strata.ps1 was renamed to strata-direct.ps1", log) self.assertEqual(self.run_heal(), []) # once: nothing left to do, nothing said again self.assertEqual(len(self.said), 1)