from __future__ import annotations import json from pathlib import Path from testing.ci.quality_gate import ( _js_node_issues, _python_node_issues, check_coverage, check_file_sizes, ) def test_check_file_sizes_flags_overlong_files(tmp_path: Path) -> None: path = tmp_path / "tool.py" path.write_text("\n".join(f"line {idx}" for idx in range(7))) issues = check_file_sizes([path], max_lines=5) assert issues and issues[0].check == "loc" assert "exceeds 5" in issues[0].message def test_docstring_helpers_accept_contract_comments_and_docstrings(tmp_path: Path) -> None: py_path = tmp_path / "sample.py" py_path.write_text( '"""module docs"""\n\n' 'def documented():\n' ' """Explain what the helper does."""\n' ' return 1\n\n' 'def missing():\n' ' return 2\n' ) js_path = tmp_path / "sample.js" js_path.write_text( '/**\n' ' * WHY: the helper needs a contract for the gate.\n' ' * @param {string} name - service name.\n' ' * @returns {string} icon label.\n' ' */\n' 'function pickIcon(name) {\n' ' return name;\n' '}\n' ) py_issues = _python_node_issues(py_path) js_issues = _js_node_issues(js_path) assert any(issue.message.endswith("missing") for issue in py_issues) assert js_issues == [] def test_check_coverage_reads_backend_and_frontend_reports(tmp_path: Path) -> None: backend_report = tmp_path / "backend.xml" backend_report.write_text( '' '' '' ) frontend_report = tmp_path / "frontend.json" frontend_report.write_text( json.dumps( { "src/auth.js": { "lines": {"pct": 100}, "statements": {"pct": 100}, "branches": {"pct": 100}, "functions": {"pct": 100}, } } ) ) issues = check_coverage( [Path("backend/atlas_portal/app_factory.py"), Path("frontend/src/auth.js")], backend_report=backend_report, frontend_report=frontend_report, threshold=95, ) assert issues == []