From bd01ba9bf90e590cd8903b07e2e8155efc3f4127 Mon Sep 17 00:00:00 2001 From: luo jiyin Date: Fri, 14 Aug 2026 23:30:03 +0800 Subject: [PATCH] test(extensions): isolate temporary Git hooks (#4813) --- .../harness/deerflow/extensions/AGENTS.md | 6 +++++ backend/tests/test_extension_manager.py | 26 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/backend/packages/harness/deerflow/extensions/AGENTS.md b/backend/packages/harness/deerflow/extensions/AGENTS.md index 055fcf61f..229ebe7e9 100644 --- a/backend/packages/harness/deerflow/extensions/AGENTS.md +++ b/backend/packages/harness/deerflow/extensions/AGENTS.md @@ -273,3 +273,9 @@ canonical live diagnostics list. Changing `plugins` requires a restart. Any future contribution kind must be added to the public contract and host runtime in the same slice; never accept a registration method that the current host silently ignores. + +### Extension Manager Test Repositories + +`test_extension_manager.py` creates temporary Git repositories for local extension sources. +Temporary commits use an empty repository-local hook directory. They must not run developer or CI Git hooks. +Tests for hook behavior must create and invoke their own hook fixtures. diff --git a/backend/tests/test_extension_manager.py b/backend/tests/test_extension_manager.py index b3fd0bc05..7dcd0c692 100644 --- a/backend/tests/test_extension_manager.py +++ b/backend/tests/test_extension_manager.py @@ -95,10 +95,16 @@ default-groups = ["extensions"] def _commit_local_extension(source: Path) -> str: subprocess.run(["git", "init", "-q"], cwd=source, check=True) + test_hooks = source / ".git" / "test-hooks" + test_hooks.mkdir() subprocess.run(["git", "config", "user.name", "Extension Test"], cwd=source, check=True) subprocess.run(["git", "config", "user.email", "extension-test@example.com"], cwd=source, check=True) subprocess.run(["git", "add", "."], cwd=source, check=True) - subprocess.run(["git", "commit", "-qm", "initial extension"], cwd=source, check=True) + subprocess.run( + ["git", "-c", f"core.hooksPath={test_hooks}", "commit", "-qm", "initial extension"], + cwd=source, + check=True, + ) return subprocess.run( ["git", "rev-parse", "HEAD"], cwd=source, @@ -108,6 +114,24 @@ def _commit_local_extension(source: Path) -> str: ).stdout.strip() +def test_commit_local_extension_ignores_inherited_git_hooks(tmp_path: Path, monkeypatch) -> None: + source = tmp_path / "extension" + source.mkdir() + _write_local_extension(source) + inherited_hooks = tmp_path / "inherited-hooks" + inherited_hooks.mkdir() + commit_hook = inherited_hooks / "commit-msg" + commit_hook.write_text("#!/bin/sh\nexit 1\n", encoding="utf-8") + commit_hook.chmod(0o755) + monkeypatch.setenv("GIT_CONFIG_COUNT", "1") + monkeypatch.setenv("GIT_CONFIG_KEY_0", "core.hooksPath") + monkeypatch.setenv("GIT_CONFIG_VALUE_0", str(inherited_hooks)) + + revision = _commit_local_extension(source) + + assert revision + + class _QuietFileHandler(http.server.SimpleHTTPRequestHandler): def log_message(self, _format: str, *args: object) -> None: return