diff --git a/horizon/dev/t1-1-debug/README.md b/horizon/dev/t1-1-debug/README.md new file mode 100644 index 00000000..1807a10c --- /dev/null +++ b/horizon/dev/t1-1-debug/README.md @@ -0,0 +1,44 @@ +# T1.1 local source fixture + +This isolated PostgreSQL-only stack uses Compose project `horizon-t1-1`, the loopback port +`127.0.0.1:55433`, and its own named volume. It does not use Authentik or People Portal and does +not connect to the shared Horizon/Auth stack. + +From the repository root, save a private one-off password locally (the ignored `.env.local` is +not part of the feature branch), then start only this project. Python 3.11 or newer must be first +on `PATH` because Nx creates the Horizon virtual environment using `python3`. On the verification +machine used for this handoff, the system `python3` is 3.9 and Homebrew Python 3.11 is at +`/opt/homebrew/bin/python3.11`; create a temporary `python3` shim and prepend it: + +```sh +mkdir -p /tmp/horizon-py311-bin +ln -sf /opt/homebrew/bin/python3.11 /tmp/horizon-py311-bin/python3 +export PATH="/tmp/horizon-py311-bin:$PATH" +umask 077 +if [ ! -f horizon/dev/t1-1-debug/.env.local ]; then + printf 'HORIZON_T1_1_DB_PASSWORD=%s\n' "$(/opt/homebrew/bin/python3.11 -c 'import secrets; print(secrets.token_urlsafe(32))')" > horizon/dev/t1-1-debug/.env.local +fi +docker compose --project-name horizon-t1-1 --env-file horizon/dev/t1-1-debug/.env.local -f horizon/dev/t1-1-debug/compose.yml up -d +set -a +source horizon/dev/t1-1-debug/.env.local +set +a +export HORIZON_TEST_DATABASE_URL="postgresql://horizon_t1_1:${HORIZON_T1_1_DB_PASSWORD}@127.0.0.1:55433/horizon_t1_1_test" +./nx run horizon-dag:fixture +HORIZON_TEST_DATABASE_URL="$HORIZON_TEST_DATABASE_URL" ./nx run horizon-dag:test +``` + +The fixture uses a synthetic FALL 2026 People Portal project and in-process Gitea responses. The +runner validates it is writing to loopback Postgres, performs the real Dagster +`ingest_project_sources` materialization, reports the Dagster run ID, verifies all six table row +counts, and checks the committed `project_source_runs` row and three asset checks. The database +test verifies unchanged reruns update retrieval timestamps only, changed project/PR rows update, +and counts match persisted rows. + +To stop the stack while preserving the isolated volume: + +```sh +docker compose --project-name horizon-t1-1 --env-file horizon/dev/t1-1-debug/.env.local -f horizon/dev/t1-1-debug/compose.yml down +``` + +Only delete this stack's volume if you intend to discard its local fixture rows. Do not use +`down -v` against any other compose project. diff --git a/horizon/dev/t1-1-debug/compose.yml b/horizon/dev/t1-1-debug/compose.yml new file mode 100644 index 00000000..9c63bac9 --- /dev/null +++ b/horizon/dev/t1-1-debug/compose.yml @@ -0,0 +1,19 @@ +services: + postgres: + image: postgres:16-alpine + environment: + POSTGRES_DB: horizon_t1_1_test + POSTGRES_USER: horizon_t1_1 + POSTGRES_PASSWORD: ${HORIZON_T1_1_DB_PASSWORD:?set a local-only password} + ports: + - "127.0.0.1:55433:5432" + volumes: + - horizon-t1-1-postgres:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 3s + timeout: 3s + retries: 30 + +volumes: + horizon-t1-1-postgres: diff --git a/horizon/project.json b/horizon/project.json index 578555bf..eaa1fc35 100644 --- a/horizon/project.json +++ b/horizon/project.json @@ -61,6 +61,16 @@ "command": "mkdir -p .dagster && DAGSTER_HOME=\"$PWD/.dagster\" .venv/bin/dagster dev -m pipeline.definitions", "cwd": "{projectRoot}" } + }, + "fixture": { + "executor": "nx:run-commands", + "dependsOn": [ + "install-deps" + ], + "options": { + "command": "mkdir -p .dagster && DAGSTER_HOME=\"$PWD/.dagster\" .venv/bin/python scripts/run_t1_1_fixture.py", + "cwd": "{projectRoot}" + } } } } diff --git a/horizon/scripts/run_t1_1_fixture.py b/horizon/scripts/run_t1_1_fixture.py new file mode 100644 index 00000000..59760588 --- /dev/null +++ b/horizon/scripts/run_t1_1_fixture.py @@ -0,0 +1,145 @@ +"""Materialize T1.1 against fake PP/Gitea data and a loopback-only Postgres.""" + +from __future__ import annotations + +import ipaddress +import os +from datetime import datetime, timezone +from urllib.parse import urlparse + +from dagster import DagsterInstance +from psycopg import connect + +from pipeline.definitions import defs +from pipeline.project_sources import ( + GiteaPRReviewRequestRow, + GiteaPRReviewRow, + GiteaPullRequestRow, + ProjectSources, + PullRequestSources, + parse_project_sources, +) +from pipeline.resources import PostgresResource + + +NOW = datetime.now(timezone.utc) +EVENT_AT = datetime(2026, 10, 15, 12, tzinfo=timezone.utc) + + +class FakePeoplePortal: + def get_projects(self, season_type: str, season_year: int) -> ProjectSources: + if (season_type, season_year) != ("FALL", 2026): + raise ValueError("Fixture only supports FALL 2026") + payload = { + "seasonType": "FALL", "seasonYear": 2026, + "generatedAt": NOW.isoformat(), "roleMappingVersion": "fixture-v1", + "projects": [{ + "projectPk": "fixture-atlas", "name": "fixture-atlas", + "friendlyName": "Atlas fixture", "teamStartDate": None, + "teamEndDate": None, "archived": False, + "members": [{ + "userPk": "user-1", "username": "alice", + "email": "alice@example.test", "name": "Fixture Alice", + "roles": ["engineer"], + "roleTitles": {"fixture-atlas": "Engineer"}, "tenureSemesters": 2, + }], + }], + } + return parse_project_sources(payload, "FALL", 2026, NOW) + + +class FakeGitea: + def list_org_repositories(self, org: str) -> list: + from pipeline.resources import OrgRepository + + return [OrgRepository(org, "demo", "main", False, False)] + + def get_repository_pull_requests(self, org: str, name: str): + from pipeline.resources import RepositoryPullRequests + + return RepositoryPullRequests( + [GiteaPullRequestRow(org, name, 1, "Fixture PR", "Synthetic source row", "alice", + None, "closed", True, EVENT_AT, EVENT_AT, EVENT_AT, "main", + "feature/demo", "https://example.test/fixture/pr/1")], + [GiteaPRReviewRow(org, name, 1, 10, "alice", None, "APPROVED", EVENT_AT)], + [GiteaPRReviewRequestRow(org, name, 1, 11, "alice", None, EVENT_AT)], + 1, + ) + + +def main() -> int: + database_url = os.environ.get("HORIZON_TEST_DATABASE_URL", "") + parsed = urlparse(database_url) + try: + loopback = ipaddress.ip_address(parsed.hostname or "").is_loopback + except ValueError: + loopback = parsed.hostname == "localhost" + if not database_url or not loopback: + raise SystemExit("Set HORIZON_TEST_DATABASE_URL to a local Postgres; remote writes are refused.") + + job = defs.resolve_job_def("ingest_project_sources") + result = job.execute_in_process( + run_config={ + "ops": { + "peopleportal_projects": { + "config": {"season_type": "FALL", "season_year": 2026} + } + } + }, + resources={ + "peopleportal": FakePeoplePortal(), + "gitea": FakeGitea(), + "postgres": PostgresResource(database_url=database_url), + }, + instance=DagsterInstance.get(), + raise_on_error=True, + ) + run_id = result.run_id + print(f"dagster_run_id={run_id}") + actual_counts = {} + with connect(database_url) as connection: + for table, where in ( + ("projects", "project_pk = 'fixture-atlas'"), + ("project_members", "project_pk = 'fixture-atlas'"), + ("project_repositories", "project_pk = 'fixture-atlas'"), + ("gitea_pull_requests", "organization = 'fixture-atlas'"), + ("gitea_pr_reviews", "organization = 'fixture-atlas'"), + ("gitea_pr_review_requests", "organization = 'fixture-atlas'"), + ): + count = connection.execute( + f"SELECT count(*) FROM horizon_gt_features.{table} WHERE {where}" + ).fetchone()[0] + actual_counts[table] = count + print(f"table={table} rows={count}") + row = connection.execute( + "SELECT status, persisted_counts FROM horizon_gt_features.project_source_runs " + "WHERE dagster_run_id = %s", (run_id,), + ).fetchone() + if row is None or row[0] != "complete": + raise SystemExit("T1.1 run manifest was not complete") + expected = { + "projects": 1, "project_members": 1, "project_repositories": 1, + "gitea_pull_requests": 1, "gitea_pr_reviews": 1, "gitea_pr_review_requests": 1, + } + if actual_counts != expected or row[1] != expected: + raise SystemExit(f"T1.1 rows disagree with the fixture: {actual_counts}; manifest={row[1]}") + checks = { + event.asset_check_evaluation_data.check_name: + event.asset_check_evaluation_data.passed + for event in result.all_events + if event.event_type_value == "ASSET_CHECK_EVALUATION" + } + expected_checks = { + "projects_are_non_empty", "project_orgs_have_repositories", + "pull_request_pages_are_complete", + } + if checks != {name: True for name in expected_checks}: + raise SystemExit(f"T1.1 asset checks did not all pass: {checks}") + print(f"run_status={row[0]}") + print(f"persisted_counts={row[1]}") + print(f"asset_checks={checks}") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())