From 1ee7278b52863576f57b5ce59f7fde065d4b2190 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sun, 9 Aug 2026 09:32:49 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20[testing=20improvement]=20Add=20?= =?UTF-8?q?missing=20tests=20for=20check=5Fsummary=20in=20pr=5Freview=5Fau?= =?UTF-8?q?tofix=5Fcontext.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...pr_review_autofix_context_check_summary.py | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tests/test_pr_review_autofix_context_check_summary.py diff --git a/tests/test_pr_review_autofix_context_check_summary.py b/tests/test_pr_review_autofix_context_check_summary.py new file mode 100644 index 000000000..7e3a7759f --- /dev/null +++ b/tests/test_pr_review_autofix_context_check_summary.py @@ -0,0 +1,99 @@ +"""Tests for the check_summary function in pr_review_autofix_context.py.""" + +from typing import Any + +from scripts.ci.pr_review_autofix_context import check_summary + + +def test_check_summary_none_or_empty() -> None: + """Test check_summary with None or an empty list.""" + assert check_summary(None) == [] + assert check_summary([]) == [] + + +def test_check_summary_checkrun_full() -> None: + """Test check_summary with a complete CheckRun node.""" + data: list[dict[str, Any]] = [{ + "__typename": "CheckRun", + "name": "lint", + "workflowName": "CI", + "status": "COMPLETED", + "conclusion": "SUCCESS", + }] + assert check_summary(data) == ["- CI/lint: COMPLETED SUCCESS"] + + +def test_check_summary_checkrun_no_workflow() -> None: + """Test check_summary when a CheckRun node lacks a workflow name.""" + data: list[dict[str, Any]] = [{ + "__typename": "CheckRun", + "name": "lint", + "status": "COMPLETED", + "conclusion": "FAILURE", + }] + assert check_summary(data) == ["- lint: COMPLETED FAILURE"] + + +def test_check_summary_checkrun_no_name() -> None: + """Test check_summary when a CheckRun node lacks a name.""" + data: list[dict[str, Any]] = [{ + "__typename": "CheckRun", + "workflowName": "CI", + "status": "IN_PROGRESS", + }] + # if name is missing, it falls back to "check" + assert check_summary(data) == ["- CI/check: IN_PROGRESS"] + + +def test_check_summary_checkrun_no_name_no_workflow() -> None: + """Test check_summary when a CheckRun node lacks both name and workflow.""" + data: list[dict[str, Any]] = [{ + "__typename": "CheckRun", + }] + assert check_summary(data) == ["- check:"] + + +def test_check_summary_status_context() -> None: + """Test check_summary with a StatusContext node.""" + data: list[dict[str, Any]] = [{ + "__typename": "StatusContext", + "context": "security", + "state": "SUCCESS", + }] + assert check_summary(data) == ["- security: SUCCESS"] + + +def test_check_summary_unknown_typename() -> None: + """Test check_summary handles nodes with unknown or missing typenames gracefully.""" + data: list[dict[str, Any]] = [{ + "__typename": "Unknown", + "name": "lint", + }, { + "name": "missing_typename", + }] + assert check_summary(data) == [] + + +def test_check_summary_multiple() -> None: + """Test check_summary with multiple mixed nodes.""" + data: list[dict[str, Any]] = [ + { + "__typename": "CheckRun", + "name": "test", + "workflowName": "Tests", + "status": "COMPLETED", + "conclusion": "FAILURE", + }, + { + "__typename": "StatusContext", + "context": "code-quality", + "state": "PENDING", + }, + { + "__typename": "Unknown", + }, + ] + assert check_summary(data) == [ + "- Tests/test: COMPLETED FAILURE", + "- code-quality: PENDING", + ]