From 2eeafa1f3743af1fa78d2f7d4d15a2ca1d4f25df Mon Sep 17 00:00:00 2001 From: Yash Ponnaganti Date: Wed, 25 Nov 2026 14:19:06 -0500 Subject: [PATCH] T1.1 (6/8): blocking source checks; a project with no repository only warns Three blocking checks on the source assets: - projects_are_non_empty: People Portal returned at least one project. - project_orgs_have_repositories: a project's Gitea organization has repositories. Three real Fall 2026 teams have no repository yet, so this one reports at WARN severity and does not stop the week for every other project. - pull_request_pages_are_complete: for every repository, the PRs fetched match the total Gitea reported. --- horizon/pipeline/checks.py | 85 +++++++++++++++++++++ horizon/pipeline/definitions.py | 6 ++ horizon/tests/test_pipeline_definitions.py | 14 ++++ horizon/tests/test_project_source_checks.py | 40 ++++++++++ 4 files changed, 145 insertions(+) create mode 100644 horizon/tests/test_project_source_checks.py diff --git a/horizon/pipeline/checks.py b/horizon/pipeline/checks.py index b602c5be..814cac41 100644 --- a/horizon/pipeline/checks.py +++ b/horizon/pipeline/checks.py @@ -14,6 +14,9 @@ from .assets import ( BlameCapture, + gitea_pull_requests, + peopleportal_projects, + project_repositories, authentik_users, blame_capture, blame_records, @@ -23,6 +26,7 @@ from .blame_parser import BlameRecord from .identity import IdentityCluster from .pull_requests import PullRequestReviewCounts +from .project_sources import ProjectRepositoryRow, ProjectSources, PullRequestSources from .resources import AuthentikRoster @@ -300,3 +304,84 @@ def records_parse_completely( "unexpected_paths": sorted(unexpected_paths)[:20], }, ) + + +@asset_check( + asset=peopleportal_projects, + blocking=True, + description="People Portal returned at least one project for the semester (T1.1).", +) +def projects_are_non_empty(peopleportal_projects: ProjectSources) -> AssetCheckResult: + count = len(peopleportal_projects.projects) + return AssetCheckResult( + passed=count > 0, + severity=AssetCheckSeverity.ERROR, + description=( + f"{count} project(s) for {peopleportal_projects.season_type} " + f"{peopleportal_projects.season_year}." + if count + else "People Portal returned zero projects; refusing to treat this as a real semester." + ), + metadata={"projects": count, "members": len(peopleportal_projects.members)}, + ) + + +@asset_check( + asset=project_repositories, + blocking=True, + additional_ins={"peopleportal_projects": AssetIn("peopleportal_projects")}, + description=( + "Every non-archived project organization has at least one usable repository (T1.1)." + ), +) +def project_orgs_have_repositories( + project_repositories: list[ProjectRepositoryRow], + peopleportal_projects: ProjectSources, +) -> AssetCheckResult: + with_repos = {row.project_pk for row in project_repositories} + missing = sorted( + project.gitea_org + for project in peopleportal_projects.projects + if not project.archived + and project.project_pk not in with_repos + ) + # A team that has not created a repository yet is real data, not a broken + # source: report it (WARN) but let the week run, so the other projects still + # publish. Such projects simply get no code metrics. + return AssetCheckResult( + passed=not missing, + severity=AssetCheckSeverity.WARN, + description=( + "Every non-archived project organization has repositories." + if not missing + else f"{len(missing)} non-archived project org(s) have no usable repository yet." + ), + metadata={"orgs_without_repositories": missing, "repositories": len(project_repositories)}, + ) + + +@asset_check( + asset=gitea_pull_requests, + blocking=True, + description=( + "For every repository, the PRs fetched match the total Gitea reported (T1.1)." + ), +) +def pull_request_pages_are_complete( + gitea_pull_requests: PullRequestSources, +) -> AssetCheckResult: + mismatched = { + slug: {"reported": reported, "fetched": fetched} + for slug, (reported, fetched) in gitea_pull_requests.pull_request_totals.items() + if reported != fetched + } + return AssetCheckResult( + passed=not mismatched, + severity=AssetCheckSeverity.ERROR, + description=( + "PR page counts match for every repository." + if not mismatched + else f"PR count mismatch in {len(mismatched)} repositories." + ), + metadata={"mismatched": mismatched, "repositories": len(gitea_pull_requests.pull_request_totals)}, + ) diff --git a/horizon/pipeline/definitions.py b/horizon/pipeline/definitions.py index 35fd28ab..8cd70bdb 100644 --- a/horizon/pipeline/definitions.py +++ b/horizon/pipeline/definitions.py @@ -55,6 +55,9 @@ records_carry_every_field, records_parse_completely, pr_reviewers_resolve_or_need_review, + project_orgs_have_repositories, + projects_are_non_empty, + pull_request_pages_are_complete, ) from .resources import build_resources @@ -136,6 +139,9 @@ pr_reviewers_resolve_or_need_review, member_scores_integrity, publish_ranking_integrity, + projects_are_non_empty, + project_orgs_have_repositories, + pull_request_pages_are_complete, ], resources=build_resources(), ) diff --git a/horizon/tests/test_pipeline_definitions.py b/horizon/tests/test_pipeline_definitions.py index d8d75d7b..4ff05392 100644 --- a/horizon/tests/test_pipeline_definitions.py +++ b/horizon/tests/test_pipeline_definitions.py @@ -159,7 +159,21 @@ def test_every_check_is_registered_against_its_asset(): (AssetKey("member_pr_review_counts"), "pr_reviewers_resolve_or_need_review"), (AssetKey("member_scores"), "member_scores_integrity"), (AssetKey("publish_ranking"), "publish_ranking_integrity"), + (AssetKey("peopleportal_projects"), "projects_are_non_empty"), + (AssetKey("project_repositories"), "project_orgs_have_repositories"), + (AssetKey("gitea_pull_requests"), "pull_request_pages_are_complete"), } + source_check_names = { + "projects_are_non_empty", + "project_orgs_have_repositories", + "pull_request_pages_are_complete", + } + assert all( + spec.blocking + for check in checks.values() + for spec in check.check_specs + if spec.name in source_check_names + ) def test_persistence_assets_depend_on_schema_setup_and_computed_rows(): diff --git a/horizon/tests/test_project_source_checks.py b/horizon/tests/test_project_source_checks.py new file mode 100644 index 00000000..c0f44737 --- /dev/null +++ b/horizon/tests/test_project_source_checks.py @@ -0,0 +1,40 @@ +"""T1.1: the source checks (zero projects, an org without repositories, PR page counts).""" + +from datetime import date + +from dagster import AssetCheckSeverity + +from pipeline.checks import ( + project_orgs_have_repositories, + projects_are_non_empty, + pull_request_pages_are_complete, +) +from pipeline.project_sources import ProjectRow, ProjectSources +from project_source_fixtures import NOW + + +def test_pr_count_check_detects_reported_vs_fetched_mismatch(): + from pipeline.project_sources import PullRequestSources + + result = PullRequestSources([], [], [], {"Atlas/app": (2, 1)}, NOW) + check = pull_request_pages_are_complete(result) + assert not check.passed + assert "Atlas/app" in str(check.metadata["mismatched"]) + + +def test_active_org_without_members_still_fails_when_it_has_no_repositories(): + project = ProjectRow( + "empty-roster", "FALL", 2026, "Empty", "EmptyOrg", "Empty Org", + date(2026, 8, 31), date(2026, 12, 11), False, + ) + sources = ProjectSources("FALL", 2026, "fixture-v1", [project], [], NOW) + check = project_orgs_have_repositories([], sources) + assert not check.passed + assert check.metadata["orgs_without_repositories"].value == ["EmptyOrg"] + # Reported, but it must not stop the week for every other project. + assert check.severity == AssetCheckSeverity.WARN + + +def test_zero_projects_fail_the_blocking_source_check(): + sources = ProjectSources("FALL", 2026, "fixture-v1", [], [], NOW) + assert not projects_are_non_empty(sources).passed