Refuse the command line's update while the game runs, as the window's Updates row does.

`launcher.cli update` downloaded the release and switched to it without asking whether the game ran. The new version's continue-update then failed in its rebuild with "the game is running", which left the new launcher with the old build until Rebuild the Game. The window's App.start_update refuses first; the command now does the same before its update check, and ends with exit code 1 and "error: the game is running: close it first, the update rebuilds it".

Not reproduced before the change: found by reading the code. Checks that passed: tests/launcher_test.py (217 tests, a new one in which a running game stops `update` before its check and its download, which fails before the change) and tools/check_content.py --staged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 17:19:54 -05:00
parent 814c10b355
commit 73d6c8ffb8
2 changed files with 23 additions and 0 deletions

View File

@@ -101,6 +101,12 @@ def run(a, ctx, held):
return 0
if a.cmd == 'update':
# The new version rebuilds the game (ContinueUpdateJob), which cannot replace a running exe: refused here
# before anything is downloaded, as the window's Updates row refuses (ui/app.py App.start_update)
gd = s.get('game_dir')
if gd and build.game_running(gd):
print('error: the game is running: close it first, the update rebuilds it', file=sys.stderr)
return 1
check = jobs.CheckJob(ctx).run_inline()
if check.result != 'ok' or not jobs.update_available(ctx, check.release):
print(check.error or f'up to date: {ctx.version}')

View File

@@ -4138,6 +4138,23 @@ class LockTest(Tmp):
self.assertIn(f'error: the launcher window (process {other.pid}', err.getvalue())
self.assertIn('try again', err.getvalue())
def test_the_command_line_update_refuses_while_the_game_runs(self):
"""`update` rebuilds the game after it switched versions: started while the game runs, it would leave the new
version with the old build. It refuses before it downloads anything, as the window's Updates row does."""
import argparse
from launcher import cli
ctx = mock.MagicMock()
ctx.settings = {'game_dir': str(self.tmp / 'game')}
err = io.StringIO()
with mock.patch('launcher.cli.build.game_running', return_value=True) as running, \
mock.patch('launcher.cli.jobs.CheckJob') as check, \
mock.patch('launcher.cli.jobs.UpdateDownloadJob') as download, contextlib.redirect_stderr(err):
self.assertEqual(cli.run(argparse.Namespace(cmd='update'), ctx, mock.MagicMock()), 1)
running.assert_called_once_with(str(self.tmp / 'game'))
check.assert_not_called()
download.assert_not_called()
self.assertIn('error: the game is running', err.getvalue())
# ---------------------------------------------------------------- the icon