mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(mcp): keep other apps' tables when replacing the Codex/Grok MCP span (#3877)
## Description `CodexRegistrar.unregister_server` deletes everything between `# --- Headroom MCP server ---` and `# --- end Headroom MCP server ---`, although its own comment says user-managed entries are preserved. The span is not always ours alone. The ChatGPT desktop app adds its `[mcp_servers.node_repl]` table (and `[mcp_servers.node_repl.env]`, the browser-use / computer-use server) by appending to `~/.codex/config.toml` before the document's trailing comment. When Headroom's span is the last thing in the file, that trailing comment is our end marker, so the app's tables land inside the span: ```toml # --- Headroom MCP server --- [mcp_servers.headroom] command = "..." [mcp_servers.node_repl] # written by the ChatGPT app command = "..." [mcp_servers.node_repl.env] ... # --- end Headroom MCP server --- ``` `register_server(force=True)` calls `unregister_server` before re-appending our block, so `headroom mcp install --force` (any time the resolved command changes) silently deletes the app's MCP server. `GrokRegistrar` has the same code. Fix: before removing or replacing a span, move every table that is not `[mcp_servers.<name>]` or one of its subtables to just after the end marker, byte for byte and in order. Then the existing span removal runs unchanged. Table headers are parsed with tomllib, so quoted keys (`[mcp_servers."foo#bar"]`) and trailing comments read as TOML reads them. Every rewrite of the span is then fail-closed: the new file must parse to the old one apart from `mcp_servers.<name>`, or nothing is written (unregister returns False with a warning, register returns FAILED). That covers a file that does not parse and a table the line-level move cannot split correctly (for example a multi-line string that happens to contain a `[...]` line), so this can never change what Codex reads beyond Headroom's own entry. ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - `headroom/mcp_registry/codex.py`: new `_evict_foreign_tables()` (headers via `_table_path()`, tomllib-parsed); `unregister_server` and `_write_block` run it before touching the span and check the result with `_only_server_changed()` before writing. - `headroom/mcp_registry/grok.py`: same two call sites, reusing the Codex helper. - `tests/test_mcp_registry/test_codex_registrar.py`: `test_unregister_keeps_app_table_inside_span` and `test_register_force_keeps_app_table_inside_span` reproduce the ChatGPT app's layout. - Both test files: `test_unregister_keeps_quoted_key_table_inside_span` (the review's `foo#bar` repro) and `test_refuses_span_rewrite_that_would_change_other_entries` (unsplittable multi-line string, and an unparseable file: unregister and `register(force=True)` both refuse and leave the file byte-identical). - `tests/test_mcp_registry/test_grok_registrar.py`: `test_unregister_keeps_foreign_table_inside_span`. All new tests fail on `main`ffc6edb4and the review-round tests also fail on the first commit b21b79ca; all pass with this change. ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [x] Type checking passes (`mypy headroom`) - [x] New tests added for new functionality - [x] Manual testing performed ### Test Output ```text $ uv run --frozen --extra dev pytest tests/test_mcp_registry/ tests/test_mcp_registry_grok.py -x -q 173 passed in 0.61s $ uv run --frozen --extra dev pytest <12 tests/test_cli files that use the registrars> -q 347 passed, 4 skipped in 6.68s # same new tests with the headroom/ change stashed (mainffc6edb4): FAILED tests/test_mcp_registry/test_codex_registrar.py::test_unregister_keeps_app_table_inside_span FAILED tests/test_mcp_registry/test_codex_registrar.py::test_register_force_keeps_app_table_inside_span FAILED tests/test_mcp_registry/test_grok_registrar.py::test_unregister_keeps_foreign_table_inside_span 3 failed, 33 passed # review-round tests with the headroom/ change stashed (b21b79ca): FAILED test_codex_registrar.py::test_unregister_keeps_quoted_key_table_inside_span FAILED test_codex_registrar.py::test_refuses_span_rewrite_that_would_change_other_entries[<multi-line string>] FAILED test_codex_registrar.py::test_refuses_span_rewrite_that_would_change_other_entries[broken =] FAILED test_grok_registrar.py::test_unregister_keeps_quoted_key_table_inside_span FAILED test_grok_registrar.py::test_refuses_span_rewrite_that_would_change_other_entries[<multi-line string>] FAILED test_grok_registrar.py::test_refuses_span_rewrite_that_would_change_other_entries[broken =] 6 failed, 36 passed $ uvx ruff@0.16.8 check <4 touched files> All checks passed! $ uvx ruff@0.16.8 format --check <4 touched files> 4 files already formatted $ uv run --frozen --extra dev mypy headroom/mcp_registry/codex.py headroom/mcp_registry/grok.py --ignore-missing-imports Success: no issues found in 2 source files ``` ## Real Behavior Proof - Environment: macOS 15, Python 3.11 worktree venv on upstream mainffc6edb4plus this commit; a temp copy of a real `~/.codex/config.toml` in which the ChatGPT app had appended `[mcp_servers.node_repl]` and `[mcp_servers.node_repl.env]` inside the Headroom span (the live file was not touched). - Exact command / steps: `CodexRegistrar(home_dir=<tmp>).register_server(spec, force=True)` with the registered command changed, i.e. what `headroom mcp install --force` does after the resolved command moves; then compare the parsed `mcp_servers` keys before and after. Run once on main and once with this change. - Observed result: main: `mcp_servers` went from `['headroom', 'node_repl']` to `['headroom']` (the app's server deleted). With this change: `['headroom', 'node_repl']` before and after, `node_repl` (with its env) parsed identical, now sitting after our end marker. - Not tested: the ChatGPT app itself re-reading the rewritten file (the parsed TOML is identical, which is what it reads); Grok with a real third-party writer (covered by the unit test with the same layout). ## Runtime Rollout Safety - Rollout-managed feature(s): None. - Minimum rollout channel: Stable. - Stable/default behavior changed: Yes, only for Codex/Grok configs where a non-Headroom table sits between Headroom's MCP markers: that table is now kept (moved after the end marker) instead of deleted. Every other config is written byte-identically, except that a span rewrite which would change anything but Headroom's own entry (including on a config that does not parse) is now refused instead of written. - Kill switch / disable path: Not needed; revert the commit. Any rewrite that would change the parsed document beyond Headroom's own entry is refused automatically. - Unsafe override required: None. - Qualification impact: None. Config-file registrar only; no proxy, compression or routing path. - Rollback path: Revert this PR. ## Review Readiness - [x] I have performed a self-review - [x] This PR is ready for human review ## Checklist - [x] My code follows the project's style guidelines - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] I did **not** edit `CHANGELOG.md` — it is generated by release-please from my Conventional Commit PR title (a CI guard enforces this) ## Screenshots (if applicable) N/A ## Additional Notes - Documentation: N/A, internal registrar behaviour. - Deliberately left out: `headroom unwrap codex` (`_strip_codex_headroom_blocks(remove_mcp=True)` in `cli/wrap.py`) removes the same span with its own code, and its backup-restore path reverts to a pre-wrap snapshot, which drops anything added since. Both are explicit uninstall paths with their own trade-offs, so they are not changed here; the registrar is what `mcp install --force` runs on every command change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
JerrettDavis
parent
7ff67693be
commit
d0fd56e491
@@ -43,6 +43,81 @@ def _marker_end(server_name: str) -> str:
|
||||
return f"# --- end Headroom MCP server: {server_name} ---"
|
||||
|
||||
|
||||
def _table_path(line: str) -> list[str] | None:
|
||||
"""Key path of a ``[table]`` or ``[[array]]`` header line, else ``None``.
|
||||
|
||||
Parsed by tomllib so quoted keys (``[mcp_servers."foo#bar"]``) and trailing
|
||||
comments are read as TOML reads them. Only a header line starts with ``[``
|
||||
and parses on its own; a continuation line of a multi-line array does not.
|
||||
"""
|
||||
if not line.lstrip().startswith("["):
|
||||
return None
|
||||
try:
|
||||
node: Any = tomllib.loads(line)
|
||||
except tomllib.TOMLDecodeError:
|
||||
return None
|
||||
path: list[str] = []
|
||||
while isinstance(node, dict) and node:
|
||||
key, node = next(iter(node.items()))
|
||||
path.append(key)
|
||||
return path
|
||||
|
||||
|
||||
def _evict_foreign_tables(content: str, server_name: str, start: str, end: str) -> str:
|
||||
"""Move tables Headroom does not own out of its marker span.
|
||||
|
||||
Another app's TOML writer appends a new table before the document's
|
||||
trailing comment, so when our span is last in the file (the ChatGPT app's
|
||||
``[mcp_servers.node_repl]`` in ``~/.codex/config.toml``) the table lands
|
||||
between our markers and deleting the span would delete it too. Every table
|
||||
other than ``mcp_servers.<server_name>`` and its subtables is moved, byte
|
||||
for byte and in order, to just after the end marker. This is a line-level
|
||||
move, so a header-like line inside a multi-line string can split a table
|
||||
wrongly; callers must check the final result with ``_only_server_changed``.
|
||||
"""
|
||||
lines = content.splitlines(keepends=True)
|
||||
try:
|
||||
i = next(n for n, line in enumerate(lines) if line.rstrip("\r\n") == start)
|
||||
j = next(n for n in range(i + 1, len(lines)) if lines[n].rstrip("\r\n") == end)
|
||||
except StopIteration:
|
||||
return content
|
||||
kept: list[str] = []
|
||||
foreign: list[str] = []
|
||||
in_foreign = False
|
||||
for line in lines[i + 1 : j]:
|
||||
path = _table_path(line)
|
||||
if path is not None:
|
||||
in_foreign = path[:2] != ["mcp_servers", server_name]
|
||||
(foreign if in_foreign else kept).append(line)
|
||||
if not foreign:
|
||||
return content
|
||||
end_line = lines[j] if lines[j].endswith("\n") else lines[j] + "\n"
|
||||
return "".join(lines[: i + 1] + kept + [end_line] + foreign + lines[j + 1 :])
|
||||
|
||||
|
||||
def _without_server(data: dict[str, Any], server_name: str) -> dict[str, Any]:
|
||||
servers = data.get("mcp_servers")
|
||||
if not isinstance(servers, dict):
|
||||
return data
|
||||
rest = {k: v for k, v in data.items() if k != "mcp_servers"}
|
||||
others = {k: v for k, v in servers.items() if k != server_name}
|
||||
return {**rest, "mcp_servers": others} if others else rest
|
||||
|
||||
|
||||
def _only_server_changed(old: str, new: str, server_name: str) -> bool:
|
||||
"""True when ``new`` parses to ``old`` apart from ``mcp_servers.<server_name>``.
|
||||
|
||||
The fail-closed guard for every rewrite of the marker span: a foreign table
|
||||
that could not be moved out of the span, or a file that does not parse,
|
||||
makes this False and the rewrite is refused instead of written.
|
||||
"""
|
||||
try:
|
||||
before, after = tomllib.loads(old), tomllib.loads(new)
|
||||
except tomllib.TOMLDecodeError:
|
||||
return False
|
||||
return _without_server(before, server_name) == _without_server(after, server_name)
|
||||
|
||||
|
||||
class CodexRegistrar(MCPRegistrar):
|
||||
"""Register MCP servers with the OpenAI Codex CLI."""
|
||||
|
||||
@@ -132,9 +207,10 @@ class CodexRegistrar(MCPRegistrar):
|
||||
# outside markers are intentionally preserved.
|
||||
if not self._config_file.exists():
|
||||
return False
|
||||
content = self._read_text()
|
||||
marker_start = _marker_start(server_name)
|
||||
marker_end = _marker_end(server_name)
|
||||
original = self._read_text()
|
||||
content = _evict_foreign_tables(original, server_name, marker_start, marker_end)
|
||||
if marker_start not in content or marker_end not in content:
|
||||
return False
|
||||
try:
|
||||
@@ -148,6 +224,14 @@ class CodexRegistrar(MCPRegistrar):
|
||||
new_content = before + "\n\n" + after
|
||||
else:
|
||||
new_content = (before or after).rstrip("\n") + ("\n" if (before or after) else "")
|
||||
if not _only_server_changed(original, new_content, server_name):
|
||||
logger.warning(
|
||||
"Not removing the Headroom block for %s from %s: the file does not parse, "
|
||||
"or the block holds entries Headroom could not move out safely.",
|
||||
server_name,
|
||||
self._config_file,
|
||||
)
|
||||
return False
|
||||
try:
|
||||
fsutil.write_text(self._config_file, new_content)
|
||||
except OSError:
|
||||
@@ -207,9 +291,10 @@ class CodexRegistrar(MCPRegistrar):
|
||||
block = _render_block(spec)
|
||||
try:
|
||||
self._codex_dir.mkdir(parents=True, exist_ok=True)
|
||||
content = self._read_text()
|
||||
marker_start = _marker_start(spec.name)
|
||||
marker_end = _marker_end(spec.name)
|
||||
original = self._read_text()
|
||||
content = _evict_foreign_tables(original, spec.name, marker_start, marker_end)
|
||||
if marker_start in content and marker_end in content:
|
||||
start = content.index(marker_start)
|
||||
end = content.index(marker_end) + len(marker_end)
|
||||
@@ -224,6 +309,12 @@ class CodexRegistrar(MCPRegistrar):
|
||||
content = content.rstrip("\n") + "\n\n" + block + "\n"
|
||||
else:
|
||||
content = block + "\n"
|
||||
if not _only_server_changed(original, content, spec.name):
|
||||
return RegisterResult(
|
||||
RegisterStatus.FAILED,
|
||||
f"{self._config_file} does not parse, or the Headroom block holds "
|
||||
"entries Headroom could not move out safely; refusing to rewrite it.",
|
||||
)
|
||||
fsutil.write_text(self._config_file, content)
|
||||
except OSError as exc:
|
||||
return RegisterResult(
|
||||
|
||||
@@ -18,6 +18,7 @@ from typing import Any
|
||||
from headroom import fsutil
|
||||
|
||||
from .base import MCPRegistrar, RegisterResult, RegisterStatus, ServerSpec
|
||||
from .codex import _evict_foreign_tables, _only_server_changed
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
import tomllib
|
||||
@@ -103,9 +104,10 @@ class GrokRegistrar(MCPRegistrar):
|
||||
def unregister_server(self, server_name: str) -> bool:
|
||||
if not self._config_file.exists():
|
||||
return False
|
||||
content = self._read_text()
|
||||
marker_start = _marker_start(server_name)
|
||||
marker_end = _marker_end(server_name)
|
||||
original = self._read_text()
|
||||
content = _evict_foreign_tables(original, server_name, marker_start, marker_end)
|
||||
if marker_start not in content or marker_end not in content:
|
||||
return False
|
||||
try:
|
||||
@@ -119,6 +121,14 @@ class GrokRegistrar(MCPRegistrar):
|
||||
new_content = before + "\n\n" + after
|
||||
else:
|
||||
new_content = (before or after).rstrip("\n") + ("\n" if (before or after) else "")
|
||||
if not _only_server_changed(original, new_content, server_name):
|
||||
logger.warning(
|
||||
"Not removing the Headroom block for %s from %s: the file does not parse, "
|
||||
"or the block holds entries Headroom could not move out safely.",
|
||||
server_name,
|
||||
self._config_file,
|
||||
)
|
||||
return False
|
||||
try:
|
||||
fsutil.write_text(self._config_file, new_content)
|
||||
except OSError:
|
||||
@@ -141,9 +151,10 @@ class GrokRegistrar(MCPRegistrar):
|
||||
block = _render_block(spec)
|
||||
try:
|
||||
self._grok_dir.mkdir(parents=True, exist_ok=True)
|
||||
content = self._read_text()
|
||||
marker_start = _marker_start(spec.name)
|
||||
marker_end = _marker_end(spec.name)
|
||||
original = self._read_text()
|
||||
content = _evict_foreign_tables(original, spec.name, marker_start, marker_end)
|
||||
if marker_start in content and marker_end in content:
|
||||
start = content.index(marker_start)
|
||||
end = content.index(marker_end) + len(marker_end)
|
||||
@@ -158,6 +169,12 @@ class GrokRegistrar(MCPRegistrar):
|
||||
content = content.rstrip("\n") + "\n\n" + block + "\n"
|
||||
else:
|
||||
content = block + "\n"
|
||||
if not _only_server_changed(original, content, spec.name):
|
||||
return RegisterResult(
|
||||
RegisterStatus.FAILED,
|
||||
f"{self._config_file} does not parse, or the Headroom block holds "
|
||||
"entries Headroom could not move out safely; refusing to rewrite it.",
|
||||
)
|
||||
fsutil.write_text(self._config_file, content)
|
||||
except OSError as exc:
|
||||
return RegisterResult(
|
||||
|
||||
@@ -440,3 +440,87 @@ def test_register_preserves_non_ascii_values(tmp_path: Path) -> None:
|
||||
data = tomllib.loads(cfg.read_text(encoding="utf-8"))
|
||||
assert data["project"] == "比赛/机器人"
|
||||
assert "headroom" in data.get("mcp_servers", {})
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# Tables another app appended inside our marker span
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
# The ChatGPT app's TOML writer appends its tables before the document's
|
||||
# trailing comment, which is our end marker when our span is last.
|
||||
_APP_TABLES = (
|
||||
"\n[mcp_servers.node_repl]\n"
|
||||
'command = "/Applications/ChatGPT.app/Contents/Resources/node_repl"\n'
|
||||
"\n[mcp_servers.node_repl.env]\n"
|
||||
'NODE_REPL_MODE = "browser"\n'
|
||||
)
|
||||
|
||||
|
||||
def _app_appends_inside_span(cfg: Path, tables: str = _APP_TABLES.lstrip("\n")) -> None:
|
||||
end = "# --- end Headroom MCP server ---"
|
||||
cfg.write_text(cfg.read_text().replace(end, tables + end))
|
||||
|
||||
|
||||
# A foreign multi-line string holding a line that reads as our header: the
|
||||
# line-level move splits the table wrongly, so the rewrite must be refused.
|
||||
_UNSPLITTABLE = '[notes]\ntext = """\n[mcp_servers.headroom.env]\n"""\n'
|
||||
|
||||
|
||||
def test_unregister_keeps_app_table_inside_span(tmp_path: Path) -> None:
|
||||
reg = _make_registrar(tmp_path)
|
||||
cfg = _config_path(tmp_path)
|
||||
cfg.parent.mkdir()
|
||||
cfg.write_text('model = "gpt-5"\n')
|
||||
reg.register_server(_spec())
|
||||
_app_appends_inside_span(cfg)
|
||||
|
||||
assert reg.unregister_server("headroom") is True
|
||||
|
||||
data = tomllib.loads(cfg.read_text())
|
||||
assert "headroom" not in data["mcp_servers"]
|
||||
assert data["mcp_servers"]["node_repl"]["env"] == {"NODE_REPL_MODE": "browser"}
|
||||
assert data["model"] == "gpt-5"
|
||||
|
||||
|
||||
def test_register_force_keeps_app_table_inside_span(tmp_path: Path) -> None:
|
||||
reg = _make_registrar(tmp_path)
|
||||
cfg = _config_path(tmp_path)
|
||||
reg.register_server(_spec(env={"HEADROOM_PROXY_URL": "http://127.0.0.1:9999"}))
|
||||
_app_appends_inside_span(cfg)
|
||||
|
||||
assert reg.register_server(_spec(), force=True).status == RegisterStatus.REGISTERED
|
||||
|
||||
data = tomllib.loads(cfg.read_text())
|
||||
assert data["mcp_servers"]["headroom"].get("env") is None
|
||||
assert data["mcp_servers"]["node_repl"]["env"] == {"NODE_REPL_MODE": "browser"}
|
||||
# The app's table now sits outside our span, so the next unregister keeps it too.
|
||||
assert reg.unregister_server("headroom") is True
|
||||
assert "node_repl" in tomllib.loads(cfg.read_text())["mcp_servers"]
|
||||
|
||||
|
||||
def test_unregister_keeps_quoted_key_table_inside_span(tmp_path: Path) -> None:
|
||||
# The `#` in a quoted key is not a comment.
|
||||
reg = _make_registrar(tmp_path)
|
||||
cfg = _config_path(tmp_path)
|
||||
reg.register_server(_spec())
|
||||
_app_appends_inside_span(cfg, '[mcp_servers."foo#bar"]\ncommand = "foreign"\n')
|
||||
assert set(tomllib.loads(cfg.read_text())["mcp_servers"]) == {"headroom", "foo#bar"}
|
||||
|
||||
assert reg.unregister_server("headroom") is True
|
||||
|
||||
assert tomllib.loads(cfg.read_text())["mcp_servers"] == {"foo#bar": {"command": "foreign"}}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("inside_span", [_UNSPLITTABLE, "broken =\n"])
|
||||
def test_refuses_span_rewrite_that_would_change_other_entries(
|
||||
tmp_path: Path, inside_span: str
|
||||
) -> None:
|
||||
reg = _make_registrar(tmp_path)
|
||||
cfg = _config_path(tmp_path)
|
||||
reg.register_server(_spec(env={"HEADROOM_PROXY_URL": "http://127.0.0.1:9999"}))
|
||||
_app_appends_inside_span(cfg, inside_span)
|
||||
before = cfg.read_text()
|
||||
|
||||
assert reg.unregister_server("headroom") is False
|
||||
assert reg.register_server(_spec(), force=True).status == RegisterStatus.FAILED
|
||||
assert cfg.read_text() == before
|
||||
|
||||
@@ -41,3 +41,55 @@ def test_register_uses_grok_home_env(monkeypatch: pytest.MonkeyPatch, tmp_path:
|
||||
config = grok_home / "config.toml"
|
||||
assert config.exists()
|
||||
assert "[mcp_servers.headroom]" in config.read_text()
|
||||
|
||||
|
||||
def test_unregister_keeps_foreign_table_inside_span(tmp_path: Path) -> None:
|
||||
"""A table another writer appended before our end marker survives unregister."""
|
||||
import tomllib
|
||||
|
||||
reg = _make_registrar(tmp_path)
|
||||
reg.register_server(_spec())
|
||||
cfg = tmp_path / ".grok" / "config.toml"
|
||||
end = "# --- end Headroom MCP server ---"
|
||||
cfg.write_text(cfg.read_text().replace(end, '[mcp_servers.other]\ncommand = "other"\n' + end))
|
||||
|
||||
assert reg.unregister_server("headroom") is True
|
||||
|
||||
assert tomllib.loads(cfg.read_text())["mcp_servers"] == {"other": {"command": "other"}}
|
||||
|
||||
|
||||
def _insert_before_end(cfg: Path, text: str) -> None:
|
||||
end = "# --- end Headroom MCP server ---"
|
||||
cfg.write_text(cfg.read_text().replace(end, text + end))
|
||||
|
||||
|
||||
def test_unregister_keeps_quoted_key_table_inside_span(tmp_path: Path) -> None:
|
||||
import tomllib
|
||||
|
||||
reg = _make_registrar(tmp_path)
|
||||
reg.register_server(_spec())
|
||||
cfg = tmp_path / ".grok" / "config.toml"
|
||||
_insert_before_end(cfg, '[mcp_servers."foo#bar"]\ncommand = "foreign"\n')
|
||||
|
||||
assert reg.unregister_server("headroom") is True
|
||||
|
||||
assert tomllib.loads(cfg.read_text())["mcp_servers"] == {"foo#bar": {"command": "foreign"}}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"inside_span",
|
||||
['[notes]\ntext = """\n[mcp_servers.headroom.env]\n"""\n', "broken =\n"],
|
||||
)
|
||||
def test_refuses_span_rewrite_that_would_change_other_entries(
|
||||
tmp_path: Path, inside_span: str
|
||||
) -> None:
|
||||
reg = _make_registrar(tmp_path)
|
||||
reg.register_server(_spec())
|
||||
cfg = tmp_path / ".grok" / "config.toml"
|
||||
_insert_before_end(cfg, inside_span)
|
||||
before = cfg.read_text()
|
||||
|
||||
assert reg.unregister_server("headroom") is False
|
||||
moved = ServerSpec(name="headroom", command="/opt/python", args=_spec().args)
|
||||
assert reg.register_server(moved, force=True).status == RegisterStatus.FAILED
|
||||
assert cfg.read_text() == before
|
||||
|
||||
Reference in New Issue
Block a user