Files
learningcircuit--local-deep…/tests/hooks/test_check_deprecated_settings_wrapper.py
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

109 lines
3.3 KiB
Python

"""
Tests for the check-deprecated-settings-wrapper pre-commit hook.
Covers regressions:
- Previously, every call site of the deprecated wrapper produced *two*
errors: one from the per-line string scan and another from the AST
walk. Verify a single call site now produces exactly one error.
- Comments and docstrings mentioning the deprecated name must not fire.
Note: DEP is built at runtime to avoid embedding the literal deprecated
name in this test file (the hook under test would otherwise flag its
own test file).
"""
import subprocess
import sys
import tempfile
from pathlib import Path
HOOK_SCRIPT = (
Path(__file__).parent.parent.parent
/ ".pre-commit-hooks"
/ "check-deprecated-settings-wrapper.py"
)
DEP = "get_setting_from" + "_db_main_thread"
def _run_hook(
content: str, filename: str = "service.py"
) -> subprocess.CompletedProcess:
with tempfile.TemporaryDirectory() as d:
path = Path(d) / filename
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content)
return subprocess.run(
[sys.executable, str(HOOK_SCRIPT), str(path)],
capture_output=True,
text=True,
)
def _count_line_errors(stdout: str) -> int:
"""Count lines of the form ' Line N: <message>'."""
return sum(
1 for line in stdout.splitlines() if line.lstrip().startswith("Line ")
)
class TestSingleErrorPerCallSite:
"""Regression: each call site must produce exactly one error, not two."""
def test_single_call_single_error(self):
result = _run_hook(f"value = {DEP}('key')\n")
assert result.returncode == 1
assert _count_line_errors(result.stdout) == 1
def test_single_import_single_error(self):
result = _run_hook(
f"from local_deep_research.utilities.db_utils import {DEP}\n"
)
assert result.returncode == 1
assert _count_line_errors(result.stdout) == 1
def test_two_call_sites_two_errors(self):
content = f"x = {DEP}('a')\ny = {DEP}('b')\n"
result = _run_hook(content)
assert result.returncode == 1
assert _count_line_errors(result.stdout) == 2
class TestCommentAndDocstringSkip:
"""Comments and docstring lines must not be flagged."""
def test_comment_not_flagged(self):
result = _run_hook(f"# {DEP} is deprecated\n")
assert result.returncode == 0
def test_docstring_line_not_flagged(self):
result = _run_hook(f'"""{DEP} is deprecated."""\n')
assert result.returncode == 0
def test_single_quote_docstring_not_flagged(self):
result = _run_hook(f"'''{DEP} is deprecated.'''\n")
assert result.returncode == 0
class TestFilesExempted:
"""db_utils.py and the hook itself must remain exempt."""
def test_db_utils_exempted(self):
result = _run_hook(f"value = {DEP}('key')\n", filename="db_utils.py")
assert result.returncode == 0
def test_test_file_exempted(self):
result = _run_hook(
f"value = {DEP}('key')\n", filename="test_db_utils.py"
)
assert result.returncode == 0
class TestNoMentionShortCircuits:
"""Files that never mention the name must pass cleanly."""
def test_clean_file_passes(self):
result = _run_hook("def hello(): return 'world'\n")
assert result.returncode == 0