Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions horizon/pipeline/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

from .assets import (
BlameCapture,
gitea_pull_requests,
peopleportal_projects,
project_repositories,
authentik_users,
blame_capture,
blame_records,
Expand All @@ -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


Expand Down Expand Up @@ -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)},
)
6 changes: 6 additions & 0 deletions horizon/pipeline/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(),
)
14 changes: 14 additions & 0 deletions horizon/tests/test_pipeline_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
40 changes: 40 additions & 0 deletions horizon/tests/test_project_source_checks.py
Original file line number Diff line number Diff line change
@@ -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
Loading