From b9b1817b557c413128a69420b5f0c6c5b9904810 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:02:26 +0000 Subject: [PATCH 01/10] feat(review): read-only pre-commit.ci check-run collector with strict app and head identity --- lib/hypatia/review_check_run_collector.ex | 259 ++++++++++++++++++++++ 1 file changed, 259 insertions(+) create mode 100644 lib/hypatia/review_check_run_collector.ex diff --git a/lib/hypatia/review_check_run_collector.ex b/lib/hypatia/review_check_run_collector.ex new file mode 100644 index 00000000..d328bb76 --- /dev/null +++ b/lib/hypatia/review_check_run_collector.ex @@ -0,0 +1,259 @@ +# SPDX-License-Identifier: MPL-2.0 +# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) + +defmodule Hypatia.ReviewCheckRunCollector do + @moduledoc """ + Read-only GitHub Checks API adapter for positively identified pre-commit.ci + PR runs. This is S-04, separate from GitHub bot review comments. + + A successful check is an external service assertion, not an independently + verified clean repository or an authorisation to merge or learn. No observed + check is UNKNOWN, never PASS. Other CI products cannot impersonate this + provider by naming their check "pre-commit.ci - pr". + + GitHub's REST check runs may be paginated and are not an atomic database + snapshot. The collector reads the full bounded inventory twice and refuses + inconsistent lists or a moving PR head. Only GET requests are issued. + """ + + alias Hypatia.ReviewGithubCollector + alias Hypatia.ReviewObservation + + @page_size 100 + @max_budget 10 + @default_budget 5 + @app_id 68672 + @app_slug "pre-commit-ci" + @check_name "pre-commit.ci - pr" + @sha ~r/\A[0-9a-f]{40}\z/i + @repo ~r/\A[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\z/ + @outcomes ~w(success failure neutral skipped cancelled timed_out action_required startup_failure stale) + + @doc """ + Read the subject PR and all paginated check runs at its exact head. + + The optional :api one-argument callback is solely an injectable GET API + client, returning {:ok, decoded_json} or {:error, reason}. Production + delegates to the GitHub collector's bounded gh CLI GET transport. + """ + @spec collect(String.t(), pos_integer(), keyword()) :: {:ok, map()} | {:error, term()} + def collect(repo, number, opts \\ []) do + api = Keyword.get(opts, :api, &ReviewGithubCollector.gh_get/1) + budget = Keyword.get(opts, :page_budget, @default_budget) + + cond do + not valid_repo?(repo) -> + {:error, :invalid_repository} + + not (is_integer(number) and number > 0) -> + {:error, :invalid_pull_request} + + not is_function(api, 1) -> + {:error, :invalid_api_client} + + not (is_integer(budget) and budget >= 1 and budget <= @max_budget) -> + {:error, :invalid_page_budget} + + true -> + collect_snapshot(repo, number, api, budget) + end + end + + defp collect_snapshot(repo, number, api, budget) do + subject_path = "repos/#{repo}/pulls/#{number}" + + with {:ok, start_pr} <- get_object(api, subject_path), + {:ok, head} <- subject_head(start_pr, repo, number), + path = "repos/#{repo}/commits/#{head}/check-runs", + {:ok, first} <- fetch_check_runs(api, path, budget), + {:ok, second} <- fetch_check_runs(api, path, budget), + :ok <- same_inventory(first, second), + {:ok, end_pr} <- get_object(api, subject_path), + {:ok, ^head} <- subject_head(end_pr, repo, number), + {:ok, observations} <- classify(first, repo, number, head) do + {:ok, + %{ + "repository" => repo, + "pull_request" => number, + "head_sha" => head, + "source" => "github_checks_api_via_gh", + "collection" => "repeated_stable_observation", + "coverage" => "pre_commit_ci_pr_check_runs_only", + "transport_provenance" => "github_api_observed", + "provider" => "pre-commit.ci", + "matching_checks" => length(observations), + "provider_observed" => observations != [], + "coverage_verdict" => "not_established", + "observations" => Enum.sort_by(observations, &get_in(&1, ["source", "event_id"])) + }} + else + {:ok, _other_head} -> {:error, :head_changed_during_collection} + {:error, _reason} = error -> error + end + end + + defp valid_repo?(repo) when is_binary(repo) do + Regex.match?(@repo, repo) and + Enum.all?(String.split(repo, "/"), &(&1 not in [".", ".."])) + end + + defp valid_repo?(_), do: false + + defp subject_head( + %{ + "number" => actual_number, + "head" => %{"sha" => sha}, + "base" => %{"repo" => %{"full_name" => actual_repo}} + }, + repo, + number + ) do + cond do + actual_number != number -> {:error, :subject_number_mismatch} + not (is_binary(actual_repo) and String.downcase(actual_repo) == String.downcase(repo)) -> + {:error, :subject_repository_mismatch} + not (is_binary(sha) and Regex.match?(@sha, sha)) -> {:error, :invalid_head_sha} + true -> {:ok, String.downcase(sha)} + end + end + + defp subject_head(_other, _repo, _number), do: {:error, :invalid_subject_shape} + + defp get_object(api, path) do + case api.(path) do + {:ok, %{} = object} -> {:ok, object} + {:ok, _} -> {:error, {:invalid_api_object, path}} + {:error, _} = error -> error + _ -> {:error, {:invalid_api_result, path}} + end + end + + defp fetch_check_runs(api, path, budget), do: fetch_page(api, path, 1, budget, []) + + defp fetch_page(api, path, page, budget, acc) do + endpoint = "#{path}?per_page=#{@page_size}&page=#{page}&filter=all" + + case api.(endpoint) do + {:ok, %{"total_count" => total, "check_runs" => batch}} + when is_integer(total) and total >= 0 and is_list(batch) and + length(batch) <= @page_size -> + accumulated = [batch | acc] + received = Enum.reduce(accumulated, 0, fn x, count -> count + length(x) end) + + cond do + received > total -> + {:error, {:inconsistent_total_count, path}} + + length(batch) == @page_size and page >= budget -> + {:error, {:page_budget_exhausted, path}} + + length(batch) == @page_size -> + fetch_page(api, path, page + 1, budget, accumulated) + + received != total -> + {:error, {:incomplete_check_inventory, path}} + + true -> + records = accumulated |> Enum.reverse() |> List.flatten() + + ids = Enum.map(records, fn + %{"id" => id} when is_integer(id) and id > 0 -> id + _ -> nil + end) + + if Enum.all?(ids, &is_integer/1) and length(ids) == length(Enum.uniq(ids)) do + {:ok, records} + else + {:error, {:invalid_or_duplicate_check_ids, path}} + end + end + + {:ok, _other} -> + {:error, {:invalid_check_runs_shape, endpoint}} + + {:error, _} = error -> + error + + _ -> + {:error, {:invalid_check_runs_result, endpoint}} + end + end + + defp same_inventory(left, right) when left == right, do: :ok + defp same_inventory(_left, _right), do: {:error, :check_inventory_changed} + + defp classify(runs, repo, number, head) do + Enum.reduce_while(runs, {:ok, []}, fn run, {:ok, accepted} -> + case from_run(run, repo, number, head) do + {:ok, record} -> {:cont, {:ok, [record | accepted]}} + :ignore -> {:cont, {:ok, accepted}} + {:error, reason} -> {:halt, {:error, {:invalid_provider_check, reason}}} + end + end) + |> case do + {:ok, items} -> {:ok, Enum.reverse(items)} + error -> error + end + end + + defp from_run(%{"name" => @check_name, "app" => %{"id" => @app_id, "slug" => @app_slug}} = run, + repo, number, head) do + with {:ok, id} <- positive_id(run["id"]), + :ok <- matching_sha(run["head_sha"], head), + {:ok, status, conclusion} <- check_state(run["status"], run["conclusion"]), + {:ok, observation} <- + ReviewObservation.admit( + %{ + "provider" => "pre-commit.ci", + "scope" => "hooks", + "repo" => repo, + "pr_number" => number, + "reviewed_sha" => head, + "source_event_id" => "github:check_run:#{id}", + "source_url" => "https://github.com/#{repo}/pull/#{number}", + "status" => status, + # Native conclusion is a provider claim, not a count of + # independently reproduced hook findings. + "has_findings" => nil + }, + head + ) do + {:ok, + Map.merge(observation, %{ + "check_conclusion" => conclusion, + "check_status" => run["status"], + "provider_run_status" => "github_check_observed", + "provider_app_id" => Integer.to_string(@app_id) + })} + else + {:error, reason} -> {:error, reason} + end + end + + # The app identity and exact PR check name must BOTH match. A renamed check + # or unrecognised app is unknown, not evidence of success. + defp from_run(_other, _repo, _number, _head), do: :ignore + + defp positive_id(id) when is_integer(id) and id > 0, do: {:ok, id} + defp positive_id(_), do: {:error, :invalid_check_id} + + defp matching_sha(value, head) when is_binary(value) do + if Regex.match?(@sha, value) and String.downcase(value) == head, + do: :ok, + else: {:error, :check_head_mismatch} + end + + defp matching_sha(_value, _head), do: {:error, :missing_check_head} + + defp check_state(state, conclusion) when state in ~w(queued in_progress pending) do + if is_nil(conclusion), + do: {:ok, "running", "unknown"}, + else: {:error, :running_with_conclusion} + end + + defp check_state("completed", conclusion) when conclusion in @outcomes do + {:ok, "completed", conclusion} + end + + defp check_state(_state, _conclusion), do: {:error, :unsupported_check_state} +end From 7940526515c3e8362eee38d2718a350f53d049f8 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:03:07 +0000 Subject: [PATCH 02/10] test(review): pre-commit check-run identity, completion and pagination negative controls --- test/review_check_run_collector_test.exs | 237 +++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 test/review_check_run_collector_test.exs diff --git a/test/review_check_run_collector_test.exs b/test/review_check_run_collector_test.exs new file mode 100644 index 00000000..f24d3bd0 --- /dev/null +++ b/test/review_check_run_collector_test.exs @@ -0,0 +1,237 @@ +# SPDX-License-Identifier: MPL-2.0 + +defmodule Hypatia.ReviewCheckRunCollectorTest do + use ExUnit.Case, async: true + + alias Hypatia.ReviewCheckRunCollector, as: Collector + + @repo "stuff-of-awe/awesome-zig" + @number 20 + @sha String.duplicate("a", 40) + @other String.duplicate("b", 40) + @path "repos/stuff-of-awe/awesome-zig/pulls/20" + @checks "repos/stuff-of-awe/awesome-zig/commits/#{@sha}/check-runs" + @first_page @checks <> "?per_page=100&page=1&filter=all" + @second_page @checks <> "?per_page=100&page=2&filter=all" + + defp pr do + %{ + "number" => @number, + "head" => %{"sha" => @sha}, + "base" => %{"repo" => %{"full_name" => @repo}} + } + end + + defp check(overrides \\ %{}) do + Map.merge( + %{ + "id" => 101, + "name" => "pre-commit.ci - pr", + "app" => %{"id" => 68672, "slug" => "pre-commit-ci"}, + "head_sha" => @sha, + "status" => "completed", + "conclusion" => "success", + "html_url" => "https://results.pre-commit.ci/run/github/irrelevant" + }, + overrides + ) + end + + defp response(runs \\ []) do + %{ + @path => {:ok, pr()}, + @first_page => {:ok, %{"total_count" => length(runs), "check_runs" => runs}} + } + end + + defp api(responses) do + fn endpoint -> Map.get(responses, endpoint, {:error, :unexpected_endpoint}) end + end + + test "missing pre-commit.ci is not a pass even when all other checks succeeded" do + generic = check(%{"app" => %{"id" => 99, "slug" => "github-actions"}}) + + assert {:ok, snapshot} = + Collector.collect(@repo, @number, api: api(response([generic]))) + + assert snapshot["provider_observed"] == false + assert snapshot["matching_checks"] == 0 + assert snapshot["observations"] == [] + assert snapshot["coverage_verdict"] == "not_established" + end + + test "a native successful pre-commit.ci check remains an unverified assertion" do + assert {:ok, snapshot} = + Collector.collect(@repo, @number, api: api(response([check()]))) + + assert snapshot["provider_observed"] + assert snapshot["matching_checks"] == 1 + assert [observation] = snapshot["observations"] + assert observation["source"]["provider"] == "pre-commit.ci" + assert observation["source"]["scope"] == "hooks" + assert observation["source"]["event_id"] == "github:check_run:101" + assert observation["source"]["url"] == "https://github.com/#{@repo}/pull/#{@number}" + assert observation["review_status"] == "completed" + assert observation["check_conclusion"] == "success" + assert observation["finding_signal"] == "unknown" + assert observation["assessment"] == "finding_summary_missing" + assert observation["qualification"] == "unqualified" + assert observation["learning_eligible"] == false + assert observation["merge_approval"] == false + assert snapshot["coverage_verdict"] == "not_established" + end + + test "failed and skipped checks do not turn into independent findings" do + runs = [ + check(%{"id" => 102, "conclusion" => "failure"}), + check(%{"id" => 103, "conclusion" => "skipped"}) + ] + + assert {:ok, snapshot} = Collector.collect(@repo, @number, api: api(response(runs))) + assert length(snapshot["observations"]) == 2 + + assert Enum.map(snapshot["observations"], & &1["check_conclusion"]) == [ + "failure", + "skipped" + ] + + assert Enum.all?(snapshot["observations"], fn item -> + item["finding_signal"] == "unknown" and + item["learning_eligible"] == false and item["merge_approval"] == false + end) + end + + test "pending check has unknown conclusion and cannot declare clean" do + waiting = check(%{"status" => "in_progress", "conclusion" => nil}) + + assert {:ok, snapshot} = + Collector.collect(@repo, @number, api: api(response([waiting]))) + + assert [item] = snapshot["observations"] + assert item["review_status"] == "running" + assert item["check_conclusion"] == "unknown" + assert item["assessment"] == "review_pending" + end + + test "forged check name, slug or numeric app identifier never authenticates" do + spoofed = [ + check(%{"app" => %{"id" => 42, "slug" => "pre-commit-ci"}}), + check(%{"app" => %{"id" => 68672, "slug" => "other-ci"}}), + check(%{"name" => "pre-commit.ci - push"}), + check(%{"name" => "pre-commit.ci - pr ", "id" => 103}) + ] + + spoofed = + spoofed + |> Enum.with_index(201) + |> Enum.map(fn {run, id} -> Map.put(run, "id", id) end) + + assert {:ok, snapshot} = Collector.collect(@repo, @number, api: api(response(spoofed))) + assert snapshot["observations"] == [] + refute snapshot["provider_observed"] + end + + test "positively identified check with invalid state or SHA fails the inventory" do + for invalid <- [ + check(%{"head_sha" => @other}), + check(%{"status" => "completed", "conclusion" => nil}), + check(%{"status" => "in_progress", "conclusion" => "success"}), + check(%{"status" => "completed", "conclusion" => "some_future_state"}), + check(%{"id" => nil}) + ] do + assert {:error, {:invalid_provider_check, _}} = + Collector.collect(@repo, @number, api: api(response([invalid]))) + end + end + + test "empty or incomplete pagination never yields clean coverage" do + assert {:ok, empty} = Collector.collect(@repo, @number, api: api(response())) + refute empty["provider_observed"] + + incomplete = Map.put(response(), @first_page, {:ok, %{"total_count" => 2, "check_runs" => []}}) + + assert {:error, {:incomplete_check_inventory, _}} = + Collector.collect(@repo, @number, api: api(incomplete)) + end + + test "duplicate or malformed source ids fail closed" do + for malformed <- [ + [check(%{"id" => 101}), check(%{"id" => 101})], + [check(%{"id" => nil})], + [%{"name" => "Unrelated check"}] + ] do + assert {:error, {:invalid_or_duplicate_check_ids, _}} = + Collector.collect(@repo, @number, api: api(response(malformed))) + end + end + + test "page budget exhaustion fails, even if the last page was full" do + full = Enum.map(1..100, fn id -> check(%{"id" => id}) end) + responses = Map.put(response(), @first_page, {:ok, %{"total_count" => 100, "check_runs" => full}}) + + assert {:error, {:page_budget_exhausted, _}} = + Collector.collect(@repo, @number, api: api(responses), page_budget: 1) + + responses = + responses + |> Map.put(@second_page, {:ok, %{"total_count" => 100, "check_runs" => []}}) + + assert {:ok, snapshot} = Collector.collect(@repo, @number, api: api(responses), page_budget: 2) + assert length(snapshot["observations"]) == 100 + end + + test "changed inventory between reads is rejected despite constant PR head" do + {:ok, counter} = Agent.start_link(fn -> 0 end) + + varying = fn endpoint -> + if endpoint == @path do + {:ok, pr()} + else + count = Agent.get_and_update(counter, fn index -> {index, index + 1} end) + {:ok, %{"total_count" => 1, "check_runs" => [check(%{"id" => 101 + count})]}} + end + end + + assert {:error, :check_inventory_changed} = + Collector.collect(@repo, @number, api: varying) + end + + test "moved PR head, bad PR shape, API error or malformed checks refuse collection" do + {:ok, counter} = Agent.start_link(fn -> 0 end) + + moved = fn endpoint -> + if endpoint == @path do + count = Agent.get_and_update(counter, fn index -> {index, index + 1} end) + if count == 0, do: {:ok, pr()}, else: {:ok, put_in(pr(), ["head", "sha"], @other)} + else + {:ok, %{"total_count" => 0, "check_runs" => []}} + end + end + + assert {:error, :head_changed_during_collection} = + Collector.collect(@repo, @number, api: moved) + + assert {:error, :invalid_subject_shape} = + Collector.collect(@repo, @number, api: api(Map.put(response(), @path, {:ok, %{"head" => []}}))) + + assert {:error, :network_failure} = + Collector.collect(@repo, @number, api: api(Map.put(response(), @path, {:error, :network_failure}))) + + assert {:error, {:invalid_check_runs_shape, _}} = + Collector.collect( + @repo, + @number, + api: api(Map.put(response(), @first_page, {:ok, %{"check_runs" => []}})) + ) + end + + test "subject validation rejects path tricks and invalid limits" do + for invalid <- ["../repo", "owner/..", "owner//repo"] do + assert {:error, :invalid_repository} = Collector.collect(invalid, @number, api: api(response())) + end + + assert {:error, :invalid_pull_request} = Collector.collect(@repo, -1, api: api(response())) + assert {:error, :invalid_page_budget} = + Collector.collect(@repo, @number, api: api(response()), page_budget: 0) + end +end From 9769d05a7b43b1f89ca96e35c21feb3e01049f6c Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:03:21 +0000 Subject: [PATCH 03/10] docs(readme): count pre-commit check-run collector --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 29caa97e..1ce24e93 100644 --- a/README.adoc +++ b/README.adoc @@ -76,7 +76,7 @@ PatternRegistry ──> TriangleRouter ──> FleetDispatcher ──> DispatchM [cols="1,3"] |=== -| `lib/` | 177 Elixir source files — pipeline, rules, VCL, neural, safety, web, merge orchestration +| `lib/` | 178 Elixir source files — pipeline, rules, VCL, neural, safety, web, merge orchestration | `lib/rules/` | 44 source files: rule modules and their helpers; see link:docs/rules/catalogue.adoc[the catalogue] | `lib/neural/` | 8 networks + blackboard, coordinator, persistence, rebalancer | `lib/vcl/` | VCL query layer over verisim-data: parser, file executor, cache, federation From 70447ea6d0f70203fb3aa1ee39a88301f7e6e30c Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:03:26 +0000 Subject: [PATCH 04/10] test(ci): include pre-commit source-intake negative controls --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b655d96..bce9750c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -362,6 +362,7 @@ jobs: test/review_observation_test.exs \ test/review_github_collector_test.exs \ test/review_evidence_test.exs \ + test/review_check_run_collector_test.exs \ test/egress_decision_mirror_test.exs \ test/deed_test.exs \ test/kyaml_test.exs \ From aae1a7aabf29a121c304d43baaf87dbbbbb9e52c Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:03:52 +0000 Subject: [PATCH 05/10] docs(review): define S-04 pre-commit checks source and trust boundary --- .../2026-11-23-review-check-run-intake.adoc | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 docs/design/2026-11-23-review-check-run-intake.adoc diff --git a/docs/design/2026-11-23-review-check-run-intake.adoc b/docs/design/2026-11-23-review-check-run-intake.adoc new file mode 100644 index 00000000..7d48f7b5 --- /dev/null +++ b/docs/design/2026-11-23-review-check-run-intake.adoc @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 += S-04: GitHub Checks API intake for pre-commit.ci +:date: 2026-11-23 +:toc: + +== Purpose + +This implements a *read-only, external-check assertion* boundary for +pre-commit.ci and deliberately remains separate from review comments. +The parent is https://github.com/hyperpolymath/hypatia/pull/1220[#1220]. +This adapter **does not** trigger pre-commit.ci, rerun jobs, autofix, +post a comment, approve a merge, or authorise Bayesian learning. + +The upstream ReviewObservation.admit/2 already permits provider +pre-commit.ci with scope hooks. The new collector emits those observations +through a distinct GitHub native Check Runs API intake. + +== Verified provider identity + +The authenticated GitHub Get App endpoint +(https://docs.github.com/en/rest/apps/apps[GitHub Apps REST]) returned +numeric app ID 68672 for slug pre-commit-ci on 2026-11-23. + +Matching is conjunctive: + +* native check.app.id exactly 68672; +* native check.app.slug exactly pre-commit-ci; +* native check.name exactly pre-commit.ci - pr; +* native check.head_sha equals the current PR head after full validation. + +An arbitrary repository workflow merely named pre-commit.ci - pr +is **not** the provider. An unknown app, renamed run, absent check, +or checks not executed on that commit is unknown, never an inferred pass. + +Only the strict native state and conclusion vocabulary is preserved. +The API-reported source event ID has prefix github:check_run: and the +positive native check-run ID. The source locator is the validated GitHub +PR permalink: the external details_url is untrusted and intentionally +not forwarded as evidence. + +== Retrieval and consistency + +The adapter reads the PR via GitHub REST, checks its number, base repo +and 40-hex head, then retrieves every check-run page using +per_page=100 and filter=all, re-reads the inventory, and validates +the head again. + +The API total_count is reconciled with retrieved count; incomplete +pagination, duplicate IDs, invalid record shapes, API failures, +full final pages at budget, shifted inventories and moved PR heads +all fail closed. + +No GitHub API can supply an atomic cross-endpoint PR/check-run +snapshot. Repeated agreement is observation, not a transaction. + +The default is five 100-item pages and an absolute budget of ten; +no cursor is silently ignored. Even a zero-item response has +coverage_verdict=not_established and provider_observed=false. +This describes *observed* check runs, not installation state. + +== Admitted verdicts + +A completed pre-commit.ci check with conclusion success is a +**provider-reported success**, not independent evidence that every +hook ran or that the repository is defect-free. The native conclusion +is carried separately as check_conclusion. + +The review-observation representation uses has_findings=nil for +all check conclusions because GitHub's Checks API status alone +contains no structured hook finding count. The provider's +completed status does not become a clean review; finding_signal +remains unknown and qualification unqualified. + +Failure/neutral/skipped/cancelled/timed_out/action_required and +startup_failure outcomes are likewise preserved as bounded +external assertions without inventing underlying defects. +All admitted records have learning_eligible=false and +merge_approval=false. + +This adapter is not yet merged into the S-03 JSON evidence envelope. +A future versioned envelope union will need its own strict +check-run schema and pinned JCS differential fixtures. It must +not replace the existing permitted S-03 fields or broaden +the E0 learning receipt as a shortcut. + +== Live availability and tests + +A GET-only reconnaissance of five pilot PR heads across four estate +organisations plus Hypatia #1220 found **no matching pre-commit.ci +check run** as of this check. That is evidence of absence of matching +check-run events *on those heads*, not proof that the provider is +uninstalled or that checks passed. + +test/review_check_run_collector_test.exs contains injected API +fixtures for native app-name spoofing, successful/failed/running +and skipped conclusions, incomplete and shifting pagination, +duplicate or invalid check-run IDs, malformed subjects, +stale/moved heads and absent providers. + +A real positive end-to-end provider check will be required before +classifying this adapter as operationally verified beyond +negative-source cases. Do not generate paid reviews or cause +autofix commits merely to populate a test. From 769e96edbed72a0cc2e7e90928823af1d0e7debd Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:05:31 +0000 Subject: [PATCH 06/10] fix(review): align S-04 with Elixir formatter and correct malformed-ID test classification --- lib/hypatia/review_check_run_collector.ex | 29 ++++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/hypatia/review_check_run_collector.ex b/lib/hypatia/review_check_run_collector.ex index d328bb76..e559f7ed 100644 --- a/lib/hypatia/review_check_run_collector.ex +++ b/lib/hypatia/review_check_run_collector.ex @@ -109,11 +109,17 @@ defmodule Hypatia.ReviewCheckRunCollector do number ) do cond do - actual_number != number -> {:error, :subject_number_mismatch} + actual_number != number -> + {:error, :subject_number_mismatch} + not (is_binary(actual_repo) and String.downcase(actual_repo) == String.downcase(repo)) -> {:error, :subject_repository_mismatch} - not (is_binary(sha) and Regex.match?(@sha, sha)) -> {:error, :invalid_head_sha} - true -> {:ok, String.downcase(sha)} + + not (is_binary(sha) and Regex.match?(@sha, sha)) -> + {:error, :invalid_head_sha} + + true -> + {:ok, String.downcase(sha)} end end @@ -156,10 +162,11 @@ defmodule Hypatia.ReviewCheckRunCollector do true -> records = accumulated |> Enum.reverse() |> List.flatten() - ids = Enum.map(records, fn - %{"id" => id} when is_integer(id) and id > 0 -> id - _ -> nil - end) + ids = + Enum.map(records, fn + %{"id" => id} when is_integer(id) and id > 0 -> id + _ -> nil + end) if Enum.all?(ids, &is_integer/1) and length(ids) == length(Enum.uniq(ids)) do {:ok, records} @@ -196,8 +203,12 @@ defmodule Hypatia.ReviewCheckRunCollector do end end - defp from_run(%{"name" => @check_name, "app" => %{"id" => @app_id, "slug" => @app_slug}} = run, - repo, number, head) do + defp from_run( + %{"name" => @check_name, "app" => %{"id" => @app_id, "slug" => @app_slug}} = run, + repo, + number, + head + ) do with {:ok, id} <- positive_id(run["id"]), :ok <- matching_sha(run["head_sha"], head), {:ok, status, conclusion} <- check_state(run["status"], run["conclusion"]), From 05562709bf6d64c31dc522087f9ed614335ef059 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:05:35 +0000 Subject: [PATCH 07/10] fix(review): align S-04 with Elixir formatter and correct malformed-ID test classification --- test/review_check_run_collector_test.exs | 26 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/test/review_check_run_collector_test.exs b/test/review_check_run_collector_test.exs index f24d3bd0..7da2f3c0 100644 --- a/test/review_check_run_collector_test.exs +++ b/test/review_check_run_collector_test.exs @@ -136,8 +136,7 @@ defmodule Hypatia.ReviewCheckRunCollectorTest do check(%{"head_sha" => @other}), check(%{"status" => "completed", "conclusion" => nil}), check(%{"status" => "in_progress", "conclusion" => "success"}), - check(%{"status" => "completed", "conclusion" => "some_future_state"}), - check(%{"id" => nil}) + check(%{"status" => "completed", "conclusion" => "some_future_state"}) ] do assert {:error, {:invalid_provider_check, _}} = Collector.collect(@repo, @number, api: api(response([invalid]))) @@ -148,7 +147,8 @@ defmodule Hypatia.ReviewCheckRunCollectorTest do assert {:ok, empty} = Collector.collect(@repo, @number, api: api(response())) refute empty["provider_observed"] - incomplete = Map.put(response(), @first_page, {:ok, %{"total_count" => 2, "check_runs" => []}}) + incomplete = + Map.put(response(), @first_page, {:ok, %{"total_count" => 2, "check_runs" => []}}) assert {:error, {:incomplete_check_inventory, _}} = Collector.collect(@repo, @number, api: api(incomplete)) @@ -167,7 +167,9 @@ defmodule Hypatia.ReviewCheckRunCollectorTest do test "page budget exhaustion fails, even if the last page was full" do full = Enum.map(1..100, fn id -> check(%{"id" => id}) end) - responses = Map.put(response(), @first_page, {:ok, %{"total_count" => 100, "check_runs" => full}}) + + responses = + Map.put(response(), @first_page, {:ok, %{"total_count" => 100, "check_runs" => full}}) assert {:error, {:page_budget_exhausted, _}} = Collector.collect(@repo, @number, api: api(responses), page_budget: 1) @@ -176,7 +178,9 @@ defmodule Hypatia.ReviewCheckRunCollectorTest do responses |> Map.put(@second_page, {:ok, %{"total_count" => 100, "check_runs" => []}}) - assert {:ok, snapshot} = Collector.collect(@repo, @number, api: api(responses), page_budget: 2) + assert {:ok, snapshot} = + Collector.collect(@repo, @number, api: api(responses), page_budget: 2) + assert length(snapshot["observations"]) == 100 end @@ -212,10 +216,14 @@ defmodule Hypatia.ReviewCheckRunCollectorTest do Collector.collect(@repo, @number, api: moved) assert {:error, :invalid_subject_shape} = - Collector.collect(@repo, @number, api: api(Map.put(response(), @path, {:ok, %{"head" => []}}))) + Collector.collect(@repo, @number, + api: api(Map.put(response(), @path, {:ok, %{"head" => []}})) + ) assert {:error, :network_failure} = - Collector.collect(@repo, @number, api: api(Map.put(response(), @path, {:error, :network_failure}))) + Collector.collect(@repo, @number, + api: api(Map.put(response(), @path, {:error, :network_failure})) + ) assert {:error, {:invalid_check_runs_shape, _}} = Collector.collect( @@ -227,10 +235,12 @@ defmodule Hypatia.ReviewCheckRunCollectorTest do test "subject validation rejects path tricks and invalid limits" do for invalid <- ["../repo", "owner/..", "owner//repo"] do - assert {:error, :invalid_repository} = Collector.collect(invalid, @number, api: api(response())) + assert {:error, :invalid_repository} = + Collector.collect(invalid, @number, api: api(response())) end assert {:error, :invalid_pull_request} = Collector.collect(@repo, -1, api: api(response())) + assert {:error, :invalid_page_budget} = Collector.collect(@repo, @number, api: api(response()), page_budget: 0) end From f07dbf2a2649e272d6c5b1098e4a952f3239ad8b Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:06:44 +0000 Subject: [PATCH 08/10] feat(review): operator read-only pre-commit.ci check-run inspection task --- lib/mix/tasks/hypatia.review_check_collect.ex | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 lib/mix/tasks/hypatia.review_check_collect.ex diff --git a/lib/mix/tasks/hypatia.review_check_collect.ex b/lib/mix/tasks/hypatia.review_check_collect.ex new file mode 100644 index 00000000..38784956 --- /dev/null +++ b/lib/mix/tasks/hypatia.review_check_collect.ex @@ -0,0 +1,58 @@ +# SPDX-License-Identifier: MPL-2.0 +# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) + +defmodule Mix.Tasks.Hypatia.ReviewCheckCollect do + @moduledoc """ + Read-only summary of GitHub Check Runs emitted by pre-commit.ci. + + mix hypatia.review_check_collect --repo OWNER/REPO --pr NUMBER + + Requires authenticated read access to GitHub through gh CLI. There is no + check-run re-request, auto-fix, bot dispatch, issue comment, learning + event, merge approval, or receipt write. Missing provider events are + UNKNOWN, never a clean review. + """ + + use Mix.Task + + alias Hypatia.ReviewCheckRunCollector + + @shortdoc "Read one PR's pre-commit.ci check-run assertions (not merge approval)" + @switches [repo: :string, pr: :integer, page_budget: :integer] + + @impl Mix.Task + def run(argv) do + {opts, rest, invalid} = OptionParser.parse(argv, strict: @switches) + + if rest != [] or invalid != [] or is_nil(opts[:repo]) or is_nil(opts[:pr]) do + Mix.raise("Usage: mix hypatia.review_check_collect --repo OWNER/REPO --pr NUMBER") + end + + budget = if is_nil(opts[:page_budget]), do: [], else: [page_budget: opts[:page_budget]] + + case ReviewCheckRunCollector.collect(opts[:repo], opts[:pr], budget) do + {:ok, report} -> + IO.puts("External Check Run intake: #{report["repository"]}##{report["pull_request"]}") + IO.puts("Head: #{report["head_sha"]}") + IO.puts("Provider: pre-commit.ci") + IO.puts("Matching current-head PR checks: #{report["matching_checks"]}") + IO.puts("Coverage verdict: #{report["coverage_verdict"]} (not a clean certificate)") + + if not report["provider_observed"] do + IO.puts("State: NOT OBSERVED; not proof of pass, absence, or installation") + end + + Enum.each(report["observations"], fn item -> + IO.puts( + " #{item["source"]["event_id"]}: " <> + "status=#{item["check_status"]} conclusion=#{item["check_conclusion"]} " <> + "[external assertion, unqualified, no merge authority]" + ) + end) + + {:error, reason} -> + Mix.shell().error("Check Run intake unavailable; not a clean result: #{inspect(reason)}") + exit({:shutdown, 2}) + end + end +end From be46cf06edca6f282fc6cd4b7299ab39fd38ee15 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:06:54 +0000 Subject: [PATCH 09/10] docs(readme): count S-04 collector and inspection Mix task --- README.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 1ce24e93..a05ed0cf 100644 --- a/README.adoc +++ b/README.adoc @@ -76,7 +76,7 @@ PatternRegistry ──> TriangleRouter ──> FleetDispatcher ──> DispatchM [cols="1,3"] |=== -| `lib/` | 178 Elixir source files — pipeline, rules, VCL, neural, safety, web, merge orchestration +| `lib/` | 179 Elixir source files — pipeline, rules, VCL, neural, safety, web, merge orchestration | `lib/rules/` | 44 source files: rule modules and their helpers; see link:docs/rules/catalogue.adoc[the catalogue] | `lib/neural/` | 8 networks + blackboard, coordinator, persistence, rebalancer | `lib/vcl/` | VCL query layer over verisim-data: parser, file executor, cache, federation @@ -153,7 +153,7 @@ hypatia help ---- Mix tasks cover the operational surface — `mix hypatia.rsr_score`, `mix hypatia.recipe_health`, -`mix hypatia.watch`, `mix hypatia.triage_issues` and sixteen more. See the +`mix hypatia.watch`, `mix hypatia.triage_issues` and seventeen more. See the https://github.com/hyperpolymath/hypatia/wiki/Operations[Operations wiki page]. Running the supervision tree also serves an HTML dashboard, an SSE event stream, a Prometheus From a4f3e5ffe5ce5553bb3d7723f868add85a3bccb0 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:07:07 +0000 Subject: [PATCH 10/10] docs(review): document GET-only pre-commit check inspection command --- docs/design/2026-11-23-review-check-run-intake.adoc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/design/2026-11-23-review-check-run-intake.adoc b/docs/design/2026-11-23-review-check-run-intake.adoc index 7d48f7b5..33f8f50c 100644 --- a/docs/design/2026-11-23-review-check-run-intake.adoc +++ b/docs/design/2026-11-23-review-check-run-intake.adoc @@ -11,6 +11,16 @@ The parent is https://github.com/hyperpolymath/hypatia/pull/1220[#1220]. This adapter **does not** trigger pre-commit.ci, rerun jobs, autofix, post a comment, approve a merge, or authorise Bayesian learning. +For an operational, read-only inspection of one PR, run: + +---- +mix hypatia.review_check_collect --repo stuff-of-awe/awesome-zig --pr 20 +---- + +The command reports exact source IDs and native statuses only. It neither +writes receipts nor runs the hooks. A missing check is explicitly +"NOT OBSERVED", not success, compliance or a checked installation. + The upstream ReviewObservation.admit/2 already permits provider pre-commit.ci with scope hooks. The new collector emits those observations through a distinct GitHub native Check Runs API intake.