Skip to content
Draft
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
5 changes: 5 additions & 0 deletions scripts/pr-risk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ A map must MAP every provenance class (`runbook`, `agent-supervised`, `human`,
tier nobody chose — that is how a map that forgot `external` used to grade a fork
the same as a teammate.

Live schema 5 records include `observed_base_sha` from the PR read and `head_sha` from its
latest commit. The base is an observation, not proof that the override files or
changed-file list were read at that revision: those reads are separate and can race
with a base update. Do not use this record alone as current-snapshot readiness evidence.

Every graded record carries `map_version` + `registry_version`, so grades made
under different maps stay comparable and a map revision can be replayed against
accumulated records.
Expand Down
7 changes: 4 additions & 3 deletions scripts/pr-risk/grade-pr-risk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ fetch_pr_record() { # <repo> <num> -> record JSON on stdout, rc 1 on an unreadab
q='query($owner:String!,$name:String!,$num:Int!){
repository(owner:$owner,name:$name){ pullRequest(number:$num){
number title state isDraft createdAt updatedAt closedAt mergedAt
author{ login __typename } authorAssociation baseRefName headRefName isCrossRepository
author{ login __typename } authorAssociation baseRefName baseRefOid headRefName isCrossRepository
additions deletions changedFiles
labels(first:100){ pageInfo{ hasNextPage } nodes{ name } }
commits(last:1){ nodes{ commit{ oid statusCheckRollup{ state
Expand Down Expand Up @@ -786,7 +786,7 @@ fetch_pr_record() { # <repo> <num> -> record JSON on stdout, rc 1 on an unreadab
then {list: null, status: "unknown",
reason: "changed-file list is short (\($files | length) of \(.changedFiles)) — GitHub caps the files API at 3000 files"}
else {list: $files, status: "ok", reason: null} end) as $fread
| {schema_version:4, repo:$repo, pr:.number, title:.title, author:(.author.login // null),
| {schema_version:5, repo:$repo, pr:.number, title:.title, author:(.author.login // null),
# The actor type GitHub itself assigns the author, recorded because the LOGIN cannot answer
# it here: GraphQL reports a Bot login UNSUFFIXED, so `cloud-code-bot[bot]` arrives as
# `cloud-code-bot` and the `[bot]` test in the shared resolver never fires on this path.
Expand All @@ -798,7 +798,8 @@ fetch_pr_record() { # <repo> <num> -> record JSON on stdout, rc 1 on an unreadab
labels:$labels, agent_coded:($labels | index("agent-coded") != null),
labels_status:(if $labels_trunc then "unknown" else "ok" end),
created_at:.createdAt, updated_at:.updatedAt, closed_at:.closedAt, merged_at:.mergedAt,
base_ref:.baseRefName, head_ref:.headRefName, is_draft:.isDraft,
base_ref:.baseRefName, observed_base_sha:(.baseRefOid // null),
head_ref:.headRefName, is_draft:.isDraft,
# THE COMMIT THIS GRADE IS ABOUT. Recorded so a publish surface attaches the grade to the
# commit whose rollup and file list produced it, rather than re-reading "head" one job
# later: grading waits out the rollup settle, so a push inside that window would otherwise
Expand Down
10 changes: 9 additions & 1 deletion scripts/pr-risk/tests/test_grade_pr_risk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ cat > "$SANDBOX/fixture.json" <<'FIX'
{"data":{"repository":{"pullRequest":{
"number":42,"title":"docs: tweak readme","state":"OPEN","isDraft":false,
"createdAt":"2026-08-01T00:00:00Z","updatedAt":"2026-08-01T00:10:00Z","closedAt":null,"mergedAt":null,
"author":{"login":"dev"},"authorAssociation":"MEMBER","baseRefName":"main","headRefName":"docs-tweak",
"author":{"login":"dev"},"authorAssociation":"MEMBER","baseRefName":"main","baseRefOid":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","headRefName":"docs-tweak",
"isCrossRepository":false,"additions":3,"deletions":1,"changedFiles":1,
"labels":{"pageInfo":{"hasNextPage":false},"nodes":[]},
"commits":{"nodes":[{"commit":{"oid":"c0ffee1234567890abcdef1234567890abcdef12","statusCheckRollup":{"state":"PENDING","contexts":{
Expand Down Expand Up @@ -170,6 +170,14 @@ eq "self-excluded rollup reads SUCCESS (by name)" SUCCESS "$(jq -r '.checks_stat
# this commit's tier to a different commit as an immutable Check Run.
eq "the record carries the graded head sha" \
"c0ffee1234567890abcdef1234567890abcdef12" "$(jq -r '.head_sha' <<<"$out")"
eq "the live record has the additive base-observation schema" 5 "$(jq -r '.schema_version' <<<"$out")"
eq "the record carries the observed PR base sha" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "$(jq -r '.observed_base_sha' <<<"$out")"
# Missing base evidence stays null; it must not be inferred from the branch name.
cp "$SANDBOX/fixture.json" "$SANDBOX/fixture-base.json"
jq 'del(.data.repository.pullRequest.baseRefOid)' "$SANDBOX/fixture-base.json" > "$SANDBOX/fixture.json"
missing_base="$(graded_pr --self-context 'CI - PR Risk Grade')"
eq "a missing observed base stays null" null "$(jq -r '.observed_base_sha' <<<"$missing_base")"
cp "$SANDBOX/fixture-base.json" "$SANDBOX/fixture.json"
eq "nothing else pending" false "$(jq -r '.checks_pending_excl_self' <<<"$out")"
eq "live docs PR grades R1" R1 "$(jq -r '.risk.tier' <<<"$out")"
# --self-run-id is the EXACT selector: same result, but keyed on github.run_id, so a
Expand Down
Loading