From 0dedc45e71793eb950b3dc11056ecc99f96a516f Mon Sep 17 00:00:00 2001 From: nvaldez Date: Sun, 27 Sep 2026 20:28:07 +0200 Subject: [PATCH] feat: add pycustomlint check to sanity runner with unified linter report - Wire PythonCustomLinter into run_sanity as the pycustomlint check (imports directly from the customlinter package; MAX_WORKERS 4 -> 5) - Use BaseLinter.format_violations_report so every sanity linter (markdownlint, frontmatter_lint, pycustomlint) prints the same TARGET/DEFINITIONS/FILE/SUMMARY format; align summary line order in base.py with the fmlint and mdoctor reports - Remove dead backward-compat shims (src/mdoctor/fmlint.py, src/python_ruff/pycustomlint.py); nothing imported them - Hoist all 45 inline imports in src to module level per the python-tdd skill, fixing the one test mock that relied on the lazy import - Sync SPEC: 4.2/4.4 covers, new 4.9.3 Linter Report Format section, frontmatter version 0.27.9 -> 0.28.0 Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- SPEC.md | 44 ++++++++++++-- src/customlinter/base.py | 2 +- src/customlinter/fmlint.py | 20 +++---- src/customlinter/pycustomlint.py | 12 ++-- src/mdoctor/fmlint.py | 38 ------------ src/python_ruff/pycustomlint.py | 33 ---------- src/python_ruff/python_ruff.py | 3 +- src/run_sanity.py | 40 ++++++++++++- src/tests/test_fmlint.py | 10 ++-- src/tests/test_mdoctor.py | 2 +- src/tests/test_pycustomlint.py | 35 ++--------- src/tests/test_run_sanity.py | 100 ++++++++++++++++++++++++++++++- src/wiki/update_manager.py | 12 ++-- 13 files changed, 207 insertions(+), 144 deletions(-) delete mode 100644 src/mdoctor/fmlint.py delete mode 100644 src/python_ruff/pycustomlint.py diff --git a/SPEC.md b/SPEC.md index c069895..941fa7f 100644 --- a/SPEC.md +++ b/SPEC.md @@ -1,6 +1,6 @@ --- name: Fiona-Assistant Specification -version: 0.27.9 +version: 0.28.0 title: Project Spec Sheet created: 2026-09-23 updated: 2026-09-27 @@ -46,6 +46,7 @@ type: summary - [4.9. Test and Sanity Runners](#49-test-and-sanity-runners) - [4.9.1. Failure Reporting](#491-failure-reporting) - [4.9.2. Coverage Gate](#492-coverage-gate) + - [4.9.3. Linter Report Format](#493-linter-report-format) - [4.10. toc-generator (Table of Contents)](#410-toc-generator-table-of-contents) - [4.10.1. MD Frontmatter Tagging](#4101-md-frontmatter-tagging) - [4.10.2. Per-File TOC Generation (`librarian toc file`)](#4102-per-file-toc-generation-librarian-toc-file) @@ -488,7 +489,7 @@ Acceptance criteria: > Status: Planned > -> Covers: `src/mdoctor/fmlint.py`. A custom linter specifically for +> Covers: `src/customlinter/fmlint.py`. A custom linter specifically for > validating markdown file frontmatter against project requirements. > This ensures all md files have the required `name` and `version` fields > for source control and version tracking (see project agent rule 10.1). @@ -675,8 +676,7 @@ Acceptance criteria: > Status: Implemented > -> Covers: `src/customlinter/pycustomlint.py` and backward compat -> `src/python_ruff/pycustomlint.py`. A custom linter for enforcing Python code rules, +> Covers: `src/customlinter/pycustomlint.py`. A custom linter for enforcing Python code rules, > including inline import detection as per python-tdd skill requirements. > Extends the Custom Linter Framework (4.3). @@ -695,6 +695,7 @@ Acceptance criteria: reported with `PYC001` violation. - A Python file with all imports at module level reports no violations. - The linter integrates with the Custom Linter Framework for shared functionality. +- The linter runs as the `pycustomlint` check in the sanity runner (4.9). --- @@ -791,8 +792,8 @@ decision; do not implement until the tagging format is specified. > Status: Implemented > > Covers: `src/run_tests.py` (TestRunner) and `src/run_sanity.py` -> (parallel pytests with a coverage gate, markdownlint, and ruff -> checks; see 4.9.1 and 4.9.2). +> (parallel pytests with a coverage gate, markdownlint, frontmatter, +> ruff, and pycustomlint checks; see 4.9.1 to 4.9.3). #### 4.9.1. Failure Reporting @@ -861,6 +862,37 @@ Acceptance criteria: --- +#### 4.9.3. Linter Report Format + +> Status: Implemented +> +> Every linter check in the sanity runner (markdownlint, frontmatter_lint, +> pycustomlint) prints the same AI-friendly report structure so the +> reports are diffable across linters. + +Requirements: + +- The report starts with a ` Violations` header followed + by `TARGET: `. +- A `- DEFINITIONS:` section lists each violated rule as + `: , `. +- A `- FILE:` entry per violating file nests one line per violation as + ` `. +- A `- SUMMARY:` section closes the report with + `Total files with violations: ` and + `Total violations: `. +- Clean runs print no report; the `Results:` table reports the violation + count instead. + +Acceptance criteria: + +- The markdownlint, frontmatter_lint, and pycustomlint reports all carry + the same sections in the same order. +- A new linter check reuses the shared format + (`BaseLinter.format_violations_report`, 4.3) instead of a bespoke one. + +--- + ### 4.10. toc-generator (Table of Contents) > Status: Implemented diff --git a/src/customlinter/base.py b/src/customlinter/base.py index 0e19a21..37d2a54 100644 --- a/src/customlinter/base.py +++ b/src/customlinter/base.py @@ -431,8 +431,8 @@ class BaseLinter(ABC): # Add summary lines.append("- SUMMARY:") - lines.append(f" - Total violations: {len(violations)}") lines.append(f" - Total files with violations: {len(files_violations) if violations else 0}") + lines.append(f" - Total violations: {len(violations)}") lines.append("") return "\n".join(lines) diff --git a/src/customlinter/fmlint.py b/src/customlinter/fmlint.py index c19f7fd..8fbbb75 100644 --- a/src/customlinter/fmlint.py +++ b/src/customlinter/fmlint.py @@ -18,13 +18,21 @@ The module provides functionality to: from __future__ import annotations +import argparse import fnmatch import logging import os import pathlib import re +import sys -from customlinter.base import BaseLinter, LintViolation +from customlinter.base import ( + BaseLinter, + FrontmatterLintError, + LintViolation, +) +from fiona.logging_config import setup_logging +from librarian.md_frontmatter import FrontmatterError, parse_frontmatter logger = logging.getLogger(__name__) @@ -181,8 +189,6 @@ def validate_file_frontmatter( or has malformed YAML. """ # pragma: no cover - backward compatibility function - from customlinter.base import FrontmatterLintError - from librarian.md_frontmatter import FrontmatterError, parse_frontmatter if required_fields is None: required_fields = DEFAULT_REQUIRED_FIELDS @@ -303,7 +309,6 @@ class FrontmatterLinter(BaseLinter): Returns: List of LintViolation objects. """ - from librarian.md_frontmatter import FrontmatterError, parse_frontmatter violations: list[LintViolation] = [] @@ -551,7 +556,6 @@ class FrontmatterLinter(BaseLinter): """ violations = self.lint_file(filepath) if violations: - from customlinter.base import FrontmatterLintError messages = [f"{v.code}: {v.message}" for v in violations] raise FrontmatterLintError( f"Missing required frontmatter fields: {', '.join(messages)}", @@ -600,7 +604,6 @@ class FrontmatterLinter(BaseLinter): # Try to parse frontmatter try: content = filepath.read_text(encoding='utf-8-sig') - from librarian.md_frontmatter import FrontmatterError, parse_frontmatter frontmatter = parse_frontmatter(content) results[filepath]["frontmatter"] = frontmatter except (FrontmatterError, OSError) as e: @@ -638,7 +641,6 @@ class FrontmatterLinter(BaseLinter): Returns: True if the file should be ignored according to .gitignore. """ - import re try: relative_path = filepath.relative_to(base_dir) @@ -784,10 +786,6 @@ class FrontmatterLinter(BaseLinter): def main(): """Command-line interface for the frontmatter linter.""" - import argparse - import sys - - from fiona.logging_config import setup_logging setup_logging() diff --git a/src/customlinter/pycustomlint.py b/src/customlinter/pycustomlint.py index 7b98af9..7389cec 100644 --- a/src/customlinter/pycustomlint.py +++ b/src/customlinter/pycustomlint.py @@ -18,13 +18,19 @@ added in the future. from __future__ import annotations +import argparse import ast import logging import pathlib import sys from typing import ClassVar -from customlinter.base import BaseLinter, LintViolation +from customlinter.base import ( + BaseLinter, + CustomLintError, + LintViolation, +) +from fiona.logging_config import setup_logging logger = logging.getLogger(__name__) @@ -174,7 +180,6 @@ class PythonCustomLinter(BaseLinter): Raises: CustomLintError: If the directory does not exist. """ - from customlinter.base import CustomLintError directory = pathlib.Path(directory) violations: list[LintViolation] = [] @@ -202,9 +207,6 @@ class PythonCustomLinter(BaseLinter): def main(): """Command-line interface for the Python custom linter.""" - import argparse - - from fiona.logging_config import setup_logging setup_logging() logger.debug("Python custom linter starting") diff --git a/src/mdoctor/fmlint.py b/src/mdoctor/fmlint.py deleted file mode 100644 index ac61eec..0000000 --- a/src/mdoctor/fmlint.py +++ /dev/null @@ -1,38 +0,0 @@ -"""Frontmatter Linter - Backward compatibility module. - -This module provides backward compatibility by re-exporting from the new -customlinter package. -""" - -import os -import sys - -from customlinter.base import READONLY_ZONES, FrontmatterLintError -from customlinter.fmlint import ( - DEFAULT_REQUIRED_FIELDS, - VIOLATION_CODES, - FrontmatterLinter, - get_violation_message, - is_skill_file, - main, - validate_file_frontmatter, - validate_skill_name, -) - -# Fix imports for when this module is used directly -src_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) -if src_path not in sys.path: - sys.path.insert(0, src_path) - -__all__ = [ - "DEFAULT_REQUIRED_FIELDS", - "READONLY_ZONES", - "VIOLATION_CODES", - "FrontmatterLintError", - "FrontmatterLinter", - "get_violation_message", - "is_skill_file", - "main", - "validate_file_frontmatter", - "validate_skill_name", -] diff --git a/src/python_ruff/pycustomlint.py b/src/python_ruff/pycustomlint.py deleted file mode 100644 index 2ff9356..0000000 --- a/src/python_ruff/pycustomlint.py +++ /dev/null @@ -1,33 +0,0 @@ -"""Python Custom Linter - Backward compatibility module. - -This module provides backward compatibility by re-exporting from the new -customlinter package. -""" - -import os -import sys - -from customlinter.base import CustomLintError -from customlinter.pycustomlint import ( - READONLY_ZONES, - VIOLATION_CODES, - InlineImportVisitor, - LintViolation, - PythonCustomLinter, - main, -) - -# Fix imports for when this module is used directly -src_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) -if src_path not in sys.path: - sys.path.insert(0, src_path) - -__all__ = [ - "READONLY_ZONES", - "VIOLATION_CODES", - "CustomLintError", - "InlineImportVisitor", - "LintViolation", - "PythonCustomLinter", - "main", -] diff --git a/src/python_ruff/python_ruff.py b/src/python_ruff/python_ruff.py index 72b7cf4..e48b669 100644 --- a/src/python_ruff/python_ruff.py +++ b/src/python_ruff/python_ruff.py @@ -7,6 +7,8 @@ import subprocess import ruff +from fiona.logging_config import setup_logging + class PythonRuff: @@ -137,7 +139,6 @@ def main(): args = parser.parse_args() - from fiona.logging_config import setup_logging setup_logging() diff --git a/src/run_sanity.py b/src/run_sanity.py index 1d3df86..76c58af 100644 --- a/src/run_sanity.py +++ b/src/run_sanity.py @@ -11,6 +11,7 @@ from concurrent import futures from pathlib import Path from customlinter.fmlint import FrontmatterLinter +from customlinter.pycustomlint import PythonCustomLinter from mdoctor.mdoctor import MDoctor from python_ruff.python_ruff import PythonRuff from run_tests import TestRunner @@ -18,7 +19,7 @@ from run_tests import TestRunner # Configure logging logger = logging.getLogger(__name__) -MAX_WORKERS = 4 +MAX_WORKERS = 5 SETTINGS_FILE = Path(__file__).resolve().parent / "settings_dev.json" @@ -205,6 +206,36 @@ def run_ruff(): } +def run_pycustomlint(): + """Run the Python custom linter programmatically using PythonCustomLinter. + + Scans Python files in the src tree for custom rule violations, + currently inline imports (project agent rule 4.1, python-tdd skill). + + Returns: + dict: A dictionary containing the lint results with: + - result: 0 if all files passed, 1 if any violations found + - violation_count: number of violations found + - stdout: AI-friendly report in the unified linter format + (Violations header, TARGET, DEFINITIONS, FILE, SUMMARY; + see SPEC 4.9.3) + """ + linter = PythonCustomLinter() + + # Lint all Python files in src directory + violations = linter.lint_directory("src") + + formated_violations = linter.format_violations_report( + violations, target="src", linter_name="Python Custom Lint" + ) + + return { + "result": 0 if not violations else 1, + "violation_count": len(violations), + "stdout": formated_violations + } + + def run_frontmatter_lint(): """Run frontmatter linter programmatically using FrontmatterLinter. @@ -245,6 +276,7 @@ def run_all(): future_markdownlint = executor.submit(run_markdownlint) future_ruff = executor.submit(run_ruff) future_frontmatter_lint = executor.submit(run_frontmatter_lint) + future_pycustomlint = executor.submit(run_pycustomlint) # Track futures with their names futures_map = { @@ -252,6 +284,7 @@ def run_all(): "markdownlint": future_markdownlint, "ruff": future_ruff, "frontmatter_lint": future_frontmatter_lint, + "pycustomlint": future_pycustomlint, } # Wait for all tasks to complete and get results @@ -364,6 +397,11 @@ def main(): if frontmatter_lint_result.get("result") == 1: print(frontmatter_lint_result.get("stdout", "")) + # Print the pycustomlint AI report before the result summary + pycustomlint_result = results.get("pycustomlint", {}) + if pycustomlint_result.get("result") == 1: + print(pycustomlint_result.get("stdout", "")) + # Print the pytests report before the result summary; unlike the lint # violation reports it also shows on clean runs so the test files and # coverage are always visible diff --git a/src/tests/test_fmlint.py b/src/tests/test_fmlint.py index 14a82e7..8342338 100644 --- a/src/tests/test_fmlint.py +++ b/src/tests/test_fmlint.py @@ -15,12 +15,13 @@ import tempfile import pytest -from customlinter.base import FrontmatterLintError +from customlinter.base import FrontmatterLintError, LintViolation from customlinter.fmlint import ( FrontmatterLinter, main, validate_file_frontmatter, ) +from librarian.md_frontmatter import FrontmatterError # ============================================================================= # Fixtures @@ -1201,16 +1202,16 @@ class TestLintFileDirect: def test_lint_file_with_parse_error(self, tmp_path, mocker): """Test lint_file handles FrontmatterError when parsing.""" - from librarian.md_frontmatter import FrontmatterError linter = FrontmatterLinter() # Create a file with invalid frontmatter test_file = tmp_path / "test.md" test_file.write_text("---\nname: Test\nversion: 1.0.0\n") # Missing closing --- - # Mock parse_frontmatter to raise error + # Mock parse_frontmatter to raise error; patch the binding that + # lint_file actually uses (module-level, see python-tdd rule 0) mocker.patch( - "librarian.md_frontmatter.parse_frontmatter", + "customlinter.fmlint.parse_frontmatter", side_effect=FrontmatterError("Invalid frontmatter") ) @@ -1293,7 +1294,6 @@ class TestLintFileDirect: def test_format_violations_report(self, tmp_path): """Test format_violations_report method.""" - from customlinter.base import LintViolation linter = FrontmatterLinter() # Create a violation diff --git a/src/tests/test_mdoctor.py b/src/tests/test_mdoctor.py index b55f9c5..a2f1eae 100644 --- a/src/tests/test_mdoctor.py +++ b/src/tests/test_mdoctor.py @@ -3,6 +3,7 @@ import json import os import pathlib +import subprocess import tempfile from unittest.mock import patch @@ -438,7 +439,6 @@ class TestMDoctorGitignore: def _make_git_repo(self, tmp_path): """Turn the temp directory into a git repo so .gitignore applies.""" - import subprocess subprocess.run(["git", "init", "-q", str(tmp_path)], check=False) (tmp_path / ".gitignore").write_text("ignored/\n", encoding="utf-8") ignored_dir = tmp_path / "ignored" diff --git a/src/tests/test_pycustomlint.py b/src/tests/test_pycustomlint.py index 7de0283..5b4b068 100644 --- a/src/tests/test_pycustomlint.py +++ b/src/tests/test_pycustomlint.py @@ -1,7 +1,10 @@ """Tests for the Python Custom Linter module.""" import json +import os import pathlib +import sys +import tempfile import pytest @@ -12,6 +15,7 @@ from customlinter.pycustomlint import ( InlineImportVisitor, LintViolation, PythonCustomLinter, + main, ) # ============================================================================= @@ -465,7 +469,6 @@ class TestEdgeCases: }""", encoding="utf-8") # Create a linter with custom settings - from customlinter.pycustomlint import PythonCustomLinter custom_linter = PythonCustomLinter(settings_file=settings_file) # Check that settings were loaded @@ -541,11 +544,8 @@ class TestCliIntegration: bad_file.write_text("def foo():\n import os\n", encoding="utf-8") # Run the CLI - import sys sys.argv = ["pycustomlint", "chklint", str(bad_file)] - from customlinter.pycustomlint import main - with pytest.raises(SystemExit) as exc_info: main() @@ -561,11 +561,8 @@ class TestCliIntegration: clean_file.write_text("import os\nimport sys\n\ndef foo():\n pass\n", encoding="utf-8") # Run the CLI - import sys sys.argv = ["pycustomlint", "chklint", str(clean_file)] - from customlinter.pycustomlint import main - with pytest.raises(SystemExit) as exc_info: main() @@ -580,11 +577,8 @@ class TestCliIntegration: bad_file.write_text("def foo():\n import os\n", encoding="utf-8") # Run the CLI with directory - import sys sys.argv = ["pycustomlint", "chklint", str(tmp_path)] - from customlinter.pycustomlint import main - with pytest.raises(SystemExit) as exc_info: main() @@ -594,11 +588,8 @@ class TestCliIntegration: def test_cli_invalid_path(self, capsys): """Test CLI with invalid path.""" - import sys sys.argv = ["pycustomlint", "chklint", "/nonexistent/path"] - from customlinter.pycustomlint import main - with pytest.raises(SystemExit) as exc_info: main() @@ -613,12 +604,8 @@ class TestCliIntegration: bad_file.write_text("def foo():\n import os\n", encoding="utf-8") # Run the CLI with --json flag - import json - import sys sys.argv = ["pycustomlint", "chklint", str(bad_file), "--json"] - from customlinter.pycustomlint import main - with pytest.raises(SystemExit) as exc_info: main() @@ -634,11 +621,8 @@ class TestCliIntegration: def test_cli_chklint_nonexistent_directory(self, capsys): """Test CLI chklint with non-existent directory.""" - import sys sys.argv = ["pycustomlint", "chklint", "/nonexistent/directory"] - from customlinter.pycustomlint import main - with pytest.raises(SystemExit) as exc_info: main() @@ -648,9 +632,6 @@ class TestCliIntegration: def test_cli_no_subcommand_default(self, capsys): """Test CLI with no subcommand defaults to chklint.""" - import os - import sys - import tempfile # Create a temp directory with a clean file with tempfile.TemporaryDirectory() as tmp_path: clean_file = pathlib.Path(tmp_path) / "clean.py" @@ -660,7 +641,6 @@ class TestCliIntegration: old_argv = sys.argv try: sys.argv = ["pycustomlint"] - from customlinter.pycustomlint import main with pytest.raises(SystemExit) as exc_info: main() @@ -674,13 +654,10 @@ class TestCliIntegration: def test_cli_help(self, capsys): """Test CLI with help or invalid subcommand shows help.""" - import sys old_argv = sys.argv try: sys.argv = ["pycustomlint", "invalid"] - from customlinter.pycustomlint import main - with pytest.raises(SystemExit) as exc_info: main() @@ -729,7 +706,6 @@ class TestCliIntegration: } }""", encoding="utf-8") - from customlinter.pycustomlint import PythonCustomLinter custom_linter = PythonCustomLinter(settings_file=settings_file) # Test that files matching patterns are skipped @@ -775,11 +751,8 @@ def foo(): clean_file.write_text("import os\nimport sys\n", encoding="utf-8") # Run the CLI with file path - import sys sys.argv = ["pycustomlint", "chklint", str(clean_file)] - from customlinter.pycustomlint import main - with pytest.raises(SystemExit) as exc_info: main() diff --git a/src/tests/test_run_sanity.py b/src/tests/test_run_sanity.py index 19b12b6..2d48660 100644 --- a/src/tests/test_run_sanity.py +++ b/src/tests/test_run_sanity.py @@ -1,12 +1,15 @@ """Tests for the run_sanity.py sanity check runner.""" import logging +import pathlib import re from unittest.mock import patch import pytest import run_sanity +from customlinter.base import LintViolation +from customlinter.pycustomlint import PythonCustomLinter from mdoctor.mdoctor import MDoctor from python_ruff.python_ruff import PythonRuff from run_tests import TestRunner @@ -387,6 +390,76 @@ class TestRunRuff: assert "stdout" in result +def _make_pyc_violation(filename, line=205, column=4, code="PYC001", + message="Inline import: import argparse"): + """Build a PythonCustomLinter LintViolation for testing.""" + return LintViolation( + filepath=pathlib.Path(filename), + line=line, + column=column, + code=code, + message=message, + rule_id="inline-import", + ) + + +@pytest.fixture +def mock_python_custom_linter(): + """Patch PythonCustomLinter inside run_sanity, keeping the real formatting.""" + real_linter = PythonCustomLinter() + with patch("run_sanity.PythonCustomLinter") as linter_class: + instance = linter_class.return_value + instance.format_violations_report.side_effect = ( + real_linter.format_violations_report + ) + yield linter_class + + +class TestRunPycustomlint: + """Tests for run_sanity.run_pycustomlint.""" + + def test_stdout_uses_unified_report_format(self, mock_python_custom_linter): + """Test stdout follows the shared linter report format (SPEC 4.9.3). + + Like the markdownlint and frontmatter_lint reports, the + pycustomlint report carries the Violations header, TARGET, + DEFINITIONS, FILE, and SUMMARY sections. + """ + filename = str(run_sanity.SETTINGS_FILE.parent / "customlinter" / "pycustomlint.py") + mock_python_custom_linter.return_value.lint_directory.return_value = [ + _make_pyc_violation(filename, line=205, column=4, code="PYC001"), + ] + result = run_sanity.run_pycustomlint() + assert result["result"] == 1 + assert result["violation_count"] == 1 + stdout = result["stdout"] + assert "Python Custom Lint Violations" in stdout + assert "TARGET: src" in stdout + assert "- DEFINITIONS:" in stdout + assert "- PYC001: Inline Import, Import statement found inside function" \ + " or block (inline import)" in stdout + assert f"- FILE: {filename}" in stdout + assert " - PYC001 Inline import: import argparse" in stdout + assert "- SUMMARY:" in stdout + # file count first, matching the fmlint and markdownlint reports + assert stdout.index("- Total files with violations: 1") < \ + stdout.index("- Total violations: 1") + + def test_no_violations_pass(self, mock_python_custom_linter): + """Test result is 0 and stdout is present when no violations are found.""" + mock_python_custom_linter.return_value.lint_directory.return_value = [] + result = run_sanity.run_pycustomlint() + assert result["result"] == 0 + assert result["violation_count"] == 0 + assert "stdout" in result + + def test_scans_src_directory(self, mock_python_custom_linter): + """Test the whole src tree is scanned.""" + mock_python_custom_linter.return_value.lint_directory.return_value = [] + run_sanity.run_pycustomlint() + mock_python_custom_linter.return_value.lint_directory.assert_called_once_with("src") + + class TestRunMarkdownlint: """Tests for run_sanity.run_markdownlint.""" @@ -452,6 +525,22 @@ class TestMain: assert out.index("AI-RUFF-REPORT") < out.index("Results:") assert out.count("AI-RUFF-REPORT") == 1 + def test_prints_pycustomlint_stdout_before_summary(self, capsys): + """Test the pycustomlint AI report is printed before the result summary, once.""" + results = { + "pycustomlint": { + "result": 1, + "violation_count": 3, + "stdout": "AI-PYCUSTOMLINT-REPORT", + }, + } + with patch("run_sanity.run_all", return_value=results): + run_sanity.main() + out = capsys.readouterr().out + assert out.index("AI-PYCUSTOMLINT-REPORT") < out.index("Results:") + assert out.count("AI-PYCUSTOMLINT-REPORT") == 1 + assert "Sanity Failed" in out + def test_prints_pytests_stdout_before_summary(self, capsys): """Test the pytests AI report is printed before the result summary.""" results = { @@ -615,22 +704,27 @@ class TestRunAllFunction: """Tests for run_sanity.run_all.""" def test_run_all_runs_all_checks(self, capsys): - """Test run_all executes all four checks and returns their results.""" + """Test run_all executes all five checks and returns their results.""" with patch("run_sanity.run_pytests", return_value={"result": 0}) as mock_p, \ patch("run_sanity.run_markdownlint", return_value={"result": 0, "violation_count": 0}) as mock_m, \ patch("run_sanity.run_ruff", return_value={"result": 0, "violation_count": 0}) as mock_r, \ patch("run_sanity.run_frontmatter_lint", - return_value={"result": 0, "violation_count": 0}) as mock_f: + return_value={"result": 0, "violation_count": 0}) as mock_f, \ + patch("run_sanity.run_pycustomlint", + return_value={"result": 0, "violation_count": 0}) as mock_c: results = run_sanity.run_all() - assert set(results) == {"pytests", "markdownlint", "ruff", "frontmatter_lint"} + assert set(results) == { + "pytests", "markdownlint", "ruff", "frontmatter_lint", "pycustomlint" + } assert all(r["result"] == 0 for r in results.values()) mock_p.assert_called_once() mock_m.assert_called_once() mock_r.assert_called_once() mock_f.assert_called_once() + mock_c.assert_called_once() class TestVerdict: diff --git a/src/wiki/update_manager.py b/src/wiki/update_manager.py index 895c22f..d19a17e 100644 --- a/src/wiki/update_manager.py +++ b/src/wiki/update_manager.py @@ -14,9 +14,13 @@ The module handles: from __future__ import annotations import hashlib +import json +import sys from dataclasses import dataclass, field from pathlib import Path +from fiona.logging_config import setup_logging + # ============================================================================= # Data Classes # ============================================================================= @@ -533,10 +537,6 @@ def check_update_main(directory: str = ".", json_output: bool = False) -> int: Note: This function is a stub and will be implemented later. """ - import json - import sys - - from fiona.logging_config import setup_logging setup_logging() @@ -585,10 +585,6 @@ def update_main( Note: This function is a stub and will be implemented later. """ - import json - import sys - - from fiona.logging_config import setup_logging setup_logging()