Skip to content

The agent that grows with you

fix(update): a stash with no Python is never rejected by the import probe (#130101)

Teknium6f48dbc6642b
diff --git a/hermes_cli/update_cmd_stash.py b/hermes_cli/update_cmd_stash.py
index 591a32de525..2994ec07137 100644
--- a/hermes_cli/update_cmd_stash.py
+++ b/hermes_cli/update_cmd_stash.py
@@ -492,7 +492,11 @@ def _restore_stashed_changes(
syntax_ok, failing_path, syntax_error = _validate_python_files_syntax(cwd, restored_python)
if not syntax_ok:
reject(failing_path or "restored Python source", syntax_error)
- for module, error in _critical_module_import_failures(cwd, report_runtime_errors=True).items():
+ # Only restored Python can be blamed for an import failure. Probe outcomes also move with
+ # install state between the two runs (launch preparation, dependency sync), so a restore
+ # that touched no Python source must not be rejected on that difference (#130101).
+ for module, error in (_critical_module_import_failures(cwd, report_runtime_errors=True).items()
+ if restored_python else ()):
if clean_import_failures.get(module) != error:
reject(f"agent import {module or 'unknown'}", error[1])
break
diff --git a/tests/hermes_cli/test_update_autostash.py b/tests/hermes_cli/test_update_autostash.py
index 11a5bfac562..9b30d0fc17b 100644
--- a/tests/hermes_cli/test_update_autostash.py
+++ b/tests/hermes_cli/test_update_autostash.py
@@ -149,6 +149,29 @@ def test_restore_validates_real_stash_and_each_import(probe_root, monkeypatch, c
assert f'git stash apply {ref}' in output
+def test_restore_without_python_is_not_judged_by_install_state_imports(probe_root, monkeypatch):
+ """#130101: a docs-only stash cannot break an import. The probe's outcome may still change
+ between its two runs for install reasons (launch preparation relaunching under the live
+ update: ``SystemExit(0)``), and that difference must not reject the restore."""
+ git(probe_root, 'init', '-q', '-b', 'main')
+ (probe_root / 'consumer.py').write_text(
+ "import pathlib\nflag = pathlib.Path(__file__).with_name('prepared')\n"
+ "if flag.exists():\n raise SystemExit(0)\nflag.touch()\n", encoding='utf-8')
+ (probe_root / '.gitignore').write_text('prepared\n', encoding='utf-8')
+ notes = probe_root / 'notes.md'
+ notes.write_text('upstream\n', encoding='utf-8')
+ git(probe_root, 'add', '.')
+ git(probe_root, '-c', 'user.name=Fixture', '-c', '[email protected]',
+ '-c', 'commit.gpgsign=false', 'commit', '-qm', 'base')
+ notes.write_text('my local docs edit\n', encoding='utf-8')
+ ref = hermes_main._stash_local_changes_if_needed(['git'], probe_root)
+ monkeypatch.setattr(update_cmd, '_UPDATE_CRITICAL_MODULES', ('consumer',))
+
+ assert hermes_main._restore_stashed_changes(['git'], probe_root, ref, prompt_user=False)
+ assert notes.read_text(encoding='utf-8') == 'my local docs edit\n'
+ assert not git(probe_root, 'stash', 'list')
+
+
@pytest.mark.parametrize('error', [EOFError(), UnicodeDecodeError('utf-8', b'\xff', 0, 1, 'invalid')])
def test_unreadable_stash_prompt_keeps_work(tmp_path, monkeypatch, capsys, error):
def unreadable(*_):