~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
"""
Tests for the check-changelog-fragments pre-commit hook.
Covers the #5023 regression: a fragment named `<id>.refactor.md` used an
undeclared towncrier category, every gate stayed green (the advisory
reminder hook only warned), and towncrier would have silently dropped
the entry from the rendered release notes. The blocking hook must exit
non-zero for any fragment whose name doesn't match the grammar or whose
category isn't declared in [[tool.towncrier.type]].
"""
import subprocess
import sys
from pathlib import Path
# Add the pre-commit hooks directory to path for the shared module
HOOKS_DIR = Path(__file__).parent.parent.parent / ".pre-commit-hooks"
sys.path.insert(0, str(HOOKS_DIR))
from _changelog_fragments import ( # noqa: E402
classify_fragment,
load_categories,
)
HOOK_SCRIPT = HOOKS_DIR / "check-changelog-fragments.py"
REPO_PYPROJECT = HOOKS_DIR.parent / "pyproject.toml"
DECLARED = ("breaking", "security", "feature", "bugfix", "removal", "misc")
def _run_hook(tmp_path, filenames, pyproject=None):
"""Create *filenames* in a changelog dir under tmp_path and run the
hook script against it."""
changelog = tmp_path / "changelog.d"
changelog.mkdir(exist_ok=True)
for name in filenames:
(changelog / name).write_text("A change.\n")
return subprocess.run(
[
sys.executable,
str(HOOK_SCRIPT),
str(changelog),
"--pyproject",
str(pyproject or REPO_PYPROJECT),
],
capture_output=True,
text=True,
)
# =========================================================================
# load_categories
# =========================================================================
class TestLoadCategories:
def test_reads_declared_categories_from_repo_pyproject(self):
cats = load_categories(REPO_PYPROJECT)
assert set(DECLARED) <= set(cats)
def test_refactor_is_not_a_declared_category(self):
# The #5023 regression relied on exactly this: `refactor` looks
# plausible but is not declared, so towncrier drops it.
assert "refactor" not in load_categories(REPO_PYPROJECT)
def test_missing_pyproject_raises_instead_of_falling_back(self, tmp_path):
try:
load_categories(tmp_path / "nope.toml")
except OSError:
pass
else:
raise AssertionError("expected OSError for missing pyproject")
# =========================================================================
# classify_fragment
# =========================================================================
class TestClassifyFragment:
def test_numbered_fragment_ok(self):
assert classify_fragment("5023.bugfix.md", DECLARED) == (
"ok",
"bugfix",
)
def test_orphan_fragment_ok(self):
assert classify_fragment("+lazy-imports.misc.md", DECLARED) == (
"ok",
"misc",
)
def test_counter_suffix_ok(self):
assert classify_fragment("3094.security.2.md", DECLARED) == (
"ok",
"security",
)
def test_undeclared_category_flagged(self):
assert classify_fragment("5023.refactor.md", DECLARED) == (
"bad-category",
"refactor",
)
def test_uppercase_category_is_bad_name(self):
# Category grammar is [a-z]+; towncrier matches case-sensitively.
assert classify_fragment("5023.Bugfix.md", DECLARED) == (
"bad-name",
None,
)
def test_missing_category_is_bad_name(self):
assert classify_fragment("notes.md", DECLARED) == ("bad-name", None)
# =========================================================================
# Hook end-to-end (subprocess, like the other check-* hook tests)
# =========================================================================
class TestHookEndToEnd:
def test_valid_fragments_pass(self, tmp_path):
result = _run_hook(
tmp_path,
[
"5023.bugfix.md",
"+lazy-imports.misc.md",
"3094.security.2.md",
"README.md", # always exempt
],
)
assert result.returncode == 0, (
f"stdout={result.stdout!r} stderr={result.stderr!r}"
)
def test_undeclared_category_fails(self, tmp_path):
# THE #5023 regression case.
result = _run_hook(tmp_path, ["5023.refactor.md"])
assert result.returncode == 1
assert "refactor" in result.stdout
assert "unknown category" in result.stdout
def test_orphan_with_undeclared_category_fails(self, tmp_path):
result = _run_hook(tmp_path, ["+some-slug.refactor.md"])
assert result.returncode == 1
assert "unknown category" in result.stdout
def test_unparseable_name_fails(self, tmp_path):
result = _run_hook(tmp_path, ["release-notes-draft.md"])
assert result.returncode == 1
assert "does not match" in result.stdout
def test_one_bad_fragment_among_valid_ones_fails(self, tmp_path):
result = _run_hook(
tmp_path, ["5023.bugfix.md", "5024.refactor.md", "5025.misc.md"]
)
assert result.returncode == 1
assert "5024.refactor.md" in result.stdout
assert "5023.bugfix.md" not in result.stdout
def test_dotfiles_are_ignored(self, tmp_path):
result = _run_hook(tmp_path, [".DS_Store", "5023.misc.md"])
assert result.returncode == 0, (
f"stdout={result.stdout!r} stderr={result.stderr!r}"
)
def test_towncrier_ignored_dotfiles_pass(self, tmp_path):
result = _run_hook(tmp_path, [".gitkeep", ".keep", ".gitignore"])
assert result.returncode == 0, (
f"stdout={result.stdout!r} stderr={result.stderr!r}"
)
def test_dot_prefixed_fragment_towncrier_renders_fails(self, tmp_path):
# towncrier parses `.123.breaking.md` as issue `.123`, category
# `breaking`, and publishes it; shell globs never see it, so the
# release-type selector could not either.
result = _run_hook(tmp_path, [".123.breaking.md", "5023.misc.md"])
assert result.returncode == 1
assert ".123.breaking.md" in result.stdout
assert "dot-prefixed" in result.stdout
def test_dot_prefixed_counter_fragment_fails(self, tmp_path):
result = _run_hook(tmp_path, [".+slug.security.2.md"])
assert result.returncode == 1
assert "dot-prefixed" in result.stdout
def test_empty_changelog_dir_passes(self, tmp_path):
result = _run_hook(tmp_path, ["README.md"])
assert result.returncode == 0
def test_broken_pyproject_fails_loud_not_silent(self, tmp_path):
# No category fallback in the blocking hook: a missing/broken
# towncrier config must fail the hook, not validate against a
# guessed list.
result = _run_hook(
tmp_path,
["5023.bugfix.md"],
pyproject=tmp_path / "missing.toml",
)
assert result.returncode != 0
def test_current_repo_changelog_dir_is_valid(self):
# The real changelog.d/ must always pass — if this fails, an
# invalid fragment reached the tree and the next release build
# would silently drop it.
result = subprocess.run(
[sys.executable, str(HOOK_SCRIPT)],
capture_output=True,
text=True,
)
assert result.returncode == 0, (
f"stdout={result.stdout!r} stderr={result.stderr!r}"
)