From 6910d564a157e2d83fae88dbfd1dc1a0d63881c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 11 Sep 2026 17:42:50 +0000 Subject: [PATCH] fix: relax validation of autorefs settings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Timothée Mazzucotelli --- python/tests/unit/test_config.py | 8 +++++++- python/tests/unit/test_plugin_config.py | 14 ++++++++++++++ python/zensical/config.py | 10 +++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/python/tests/unit/test_config.py b/python/tests/unit/test_config.py index f771422..0e479ee 100644 --- a/python/tests/unit/test_config.py +++ b/python/tests/unit/test_config.py @@ -572,8 +572,14 @@ class TestPluginShimming: ) def test_autorefs_standalone(self, tmp_path: Path) -> None: - config = self._parse_yaml(tmp_path, plugins={"autorefs": {}}) + options = { + "resolve_closest": True, + "link_titles": "external", + "strip_title_tags": False, + } + config = self._parse_yaml(tmp_path, plugins={"autorefs": options}) assert AutorefsExtension.name in config["markdown_extensions"] + assert config["plugins"]["autorefs"]["config"] == {} def test_autorefs_disabled_not_added( self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path diff --git a/python/tests/unit/test_plugin_config.py b/python/tests/unit/test_plugin_config.py index ce0af88..bede3bb 100644 --- a/python/tests/unit/test_plugin_config.py +++ b/python/tests/unit/test_plugin_config.py @@ -265,6 +265,20 @@ def test_accepts_supported_shim_options( assert plugins[name]["config"] == config +@pytest.mark.parametrize( + "option", ["resolve_closest", "link_titles", "strip_title_tags"] +) +@pytest.mark.parametrize( + "value", [True, False, "auto", "external", 42, [], {}, None] +) +def test_silently_discards_unsupported_autorefs_options( + option: str, value: Any, capsys: pytest.CaptureFixture[str] +) -> None: + plugins = _convert_plugins({"autorefs": {"enabled": True, option: value}}) + assert plugins["autorefs"]["config"] == {"enabled": True} + assert capsys.readouterr().err == "" + + @pytest.mark.parametrize( ("name", "config", "message"), [ diff --git a/python/zensical/config.py b/python/zensical/config.py index b77e5b1..2679aec 100644 --- a/python/zensical/config.py +++ b/python/zensical/config.py @@ -1695,8 +1695,16 @@ def _convert_plugins(value: Any, config: dict) -> dict: # Validate settings forwarded by the plugin-to-extension shims. if "autorefs" in plugins: autorefs = plugins["autorefs"] - _reject_unknown_options("autorefs", autorefs, {"enabled"}) + _reject_unknown_options( + "autorefs", + autorefs, + {"enabled", "resolve_closest", "link_titles", "strip_title_tags"}, + ) _validate_boolean_options("autorefs", autorefs, ("enabled",)) + # Ignore these upstream settings: the Rust resolver currently uses + # fixed resolution and title behavior. + for name in ("resolve_closest", "link_titles", "strip_title_tags"): + autorefs.pop(name, None) if "markdown-exec" in plugins: markdown_exec = plugins["markdown-exec"]