Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(tooling): 拒绝 --source 与 --swap-from 同用

longmeidaoda1cd74b45c1
diff --git a/scripts/restart_windows_tray.py b/scripts/restart_windows_tray.py
index b63a6f273..aea4235f3 100644
--- a/scripts/restart_windows_tray.py
+++ b/scripts/restart_windows_tray.py
@@ -32,6 +32,10 @@ def main(argv: list[str] | None = None) -> int:
parser.add_argument("--swap-from", type=Path, default=None,
help="旧托盘退出后把这个暂存包换上生产入口,失败自动回退")
args = parser.parse_args(argv)
+ # 源码托盘没有生产入口可换,`--swap-from` 在这条路上无处可去。默默忽略它的话,
+ # 命令照样退出 0、照样打印 ok,而那个包根本没换上——换包失败最不能是静默的。
+ if args.source and args.swap_from:
+ parser.error("--source 不能与 --swap-from 同用:源码托盘没有可换的生产入口")
if not args.source and find_tray_windows(args.target):
result = restart_tray(args.target, timeout=max(1.0, args.timeout),
diff --git a/tests/test_restart_windows_tray.py b/tests/test_restart_windows_tray.py
index 81c0c9800..f0a129b59 100644
--- a/tests/test_restart_windows_tray.py
+++ b/tests/test_restart_windows_tray.py
@@ -262,6 +262,24 @@ class RestartEntryTests(unittest.TestCase):
self.assertEqual(entry.main(["--source"]), 0)
ghost.assert_not_called()
+ def test_asking_to_swap_a_package_into_the_source_tray_is_refused(self):
+ """源码托盘没有生产入口可换,这两个开关同用是笔误。
+
+ 放行的话命令照样退出 0、照样打印重启成功,而那个暂存包一动没动——
+ 下一次开机跑起来的还是旧代码,而部署这一步看上去是成功的。
+ """
+ entry = load_entry()
+ with (
+ mock.patch.object(entry, "restart_source_tray") as source,
+ mock.patch.object(entry, "restart_tray") as packaged,
+ contextlib.redirect_stderr(io.StringIO()) as complaint,
+ ):
+ with self.assertRaises(SystemExit):
+ entry.main(["--source", "--swap-from", "staged.exe"])
+ source.assert_not_called()
+ packaged.assert_not_called()
+ self.assertIn("--source 不能与 --swap-from 同用", complaint.getvalue())
+
if __name__ == "__main__":
unittest.main()