Skip to content

The agent that grows with you

fix(update): a requires-python bump never admits a merge-conflict marker (review N15)

Tekniume557016d7f0a
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 8610af87647..509bfc7c17f 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -910,8 +910,14 @@ def _rollback_if_pulled_syntax_error(git_cmd, pre_pull_sha, *, rollback_branch=N
file no longer compiles (a bad admin-merge past CI must not brick the CLI)."""
pyproject = Path(_m().PROJECT_ROOT) / "pyproject.toml"
if pyproject.is_file() and _commit.requires_other_python(pyproject.read_bytes()):
- return # a newer Python's syntax: this interpreter's compile() cannot judge it
- syntax_ok, failing_path, syntax_error = _validate_critical_files_syntax(_m().PROJECT_ROOT)
+ # A newer Python's syntax: this interpreter's compile() cannot judge it; a conflict marker
+ # is broken under every Python.
+ marked = [(rel, reason) for rel in _UPDATE_CRITICAL_FILES
+ if (path := Path(_m().PROJECT_ROOT) / rel).is_file()
+ and (reason := _commit.conflict_marker(path.read_bytes()))]
+ syntax_ok, failing_path, syntax_error = (not marked, *(marked[0] if marked else (None, None)))
+ else:
+ syntax_ok, failing_path, syntax_error = _validate_critical_files_syntax(_m().PROJECT_ROOT)
if syntax_ok:
return
print()
diff --git a/hermes_cli/update_cmd_commit.py b/hermes_cli/update_cmd_commit.py
index 431abbed7d3..b9ad1715786 100644
--- a/hermes_cli/update_cmd_commit.py
+++ b/hermes_cli/update_cmd_commit.py
@@ -330,22 +330,36 @@ def requires_other_python(pyproject: bytes | str | None) -> bool:
return False
+def conflict_marker(data: bytes) -> str | None:
+ """Why ``data`` is broken under EVERY Python (a merge-conflict marker line), else None: no
+ ``requires-python`` bump excuses it. Only git's ``<<<<<<< ``/``>>>>>>> `` lines: a bare
+ ``=======`` is also a reST heading in a docstring."""
+ for number, line in enumerate(data.splitlines(), 1):
+ if line.startswith((b"<<<<<<< ", b">>>>>>> ")):
+ return f"unresolved merge-conflict marker at line {number}"
+ return None
+
+
def target_syntax_error(git_cmd, root: Path, target_ref: str, relpaths) -> tuple[str, str] | None:
"""``(path, error)`` for the first startup-critical file that does not compile at ``target_ref``.
Read from the object store, never written to the tree: this runs BEFORE HEAD moves, so a broken
release is refused with the install untouched (the post-pull rollback stays as the backstop).
- Skipped for a target that requires a Python this interpreter is not (``requires_other_python``).
+ A target that requires a Python this interpreter is not (``requires_other_python``) is held only
+ to ``conflict_marker``: its syntax may be a newer Python's.
"""
pyproject = run_git(git_cmd, ["show", f"{target_ref}:pyproject.toml"], cwd=str(root),
capture_output=True, stdin=subprocess.DEVNULL, timeout=120)
- if pyproject.returncode == 0 and requires_other_python(pyproject.stdout):
- return None
+ other_python = pyproject.returncode == 0 and requires_other_python(pyproject.stdout)
for rel in relpaths:
shown = run_git(git_cmd, ["show", f"{target_ref}:{rel}"], cwd=str(root), capture_output=True,
stdin=subprocess.DEVNULL, timeout=120)
if shown.returncode != 0:
continue # absent at the target (or unreadable): the post-pull guard has the last word
+ if other_python:
+ if reason := conflict_marker(shown.stdout or b""):
+ return rel, reason
+ continue
try:
compile(shown.stdout, rel, "exec", dont_inherit=True)
except (SyntaxError, ValueError) as exc:
diff --git a/tests/hermes_cli/test_update_post_pull_syntax_guard.py b/tests/hermes_cli/test_update_post_pull_syntax_guard.py
index c72c5ca66a9..4308c122671 100644
--- a/tests/hermes_cli/test_update_post_pull_syntax_guard.py
+++ b/tests/hermes_cli/test_update_post_pull_syntax_guard.py
@@ -144,3 +144,31 @@ def test_the_tree_move_marker_records_the_absolute_git_the_repair_reruns(tmp_pat
monkeypatch.setattr(_early_recovery, "_is_git", lambda path: path == str(fake))
assert _early_recovery._git_executable(fields["git"]) == str(fake)
assert _early_recovery._git_executable(str(tmp_path / "gone")) != str(tmp_path / "gone")
+
+
+def test_a_python_bump_never_admits_a_conflict_marker(tmp_path, monkeypatch):
+ """A release that raises requires-python past this interpreter is excused only syntax a newer
+ Python may parse: a merge-conflict marker breaks every Python, before and after the move (N15)."""
+ from hermes_cli import update_cmd_commit as commit
+
+ def git(*args):
+ return subprocess.run(["git", *args], cwd=tmp_path, check=True, capture_output=True, text=True, encoding="utf-8").stdout.strip()
+
+ git("init", "-b", "main")
+ git("config", "user.email", "[email protected]")
+ git("config", "user.name", "Test")
+ (tmp_path / "hermes_constants.py").write_text("good = True\n", encoding="utf-8")
+ (tmp_path / "pyproject.toml").write_text('[project]\nname = "x"\nrequires-python = ">=3.8"\n', encoding="utf-8")
+ git("add", ".")
+ git("commit", "-m", "pre")
+ pre = git("rev-parse", "HEAD")
+ (tmp_path / "hermes_constants.py").write_text("<<<<<<< HEAD\na = 1\n=======\na = 2\n>>>>>>> topic\n", encoding="utf-8")
+ (tmp_path / "pyproject.toml").write_text('[project]\nname = "x"\nrequires-python = ">=3.99"\n', encoding="utf-8")
+ git("commit", "-am", "conflicted, and bumps python")
+ broken = git("rev-parse", "HEAD")
+
+ assert commit.target_syntax_error(["git"], tmp_path, broken, ["hermes_constants.py"]) is not None
+ monkeypatch.setattr(main, "PROJECT_ROOT", tmp_path)
+ with pytest.raises(SystemExit):
+ update_cmd._rollback_if_pulled_syntax_error(["git"], pre)
+ assert git("rev-parse", "HEAD") == pre