From 3433be9997a2431564eeb080f29109e1c90f4b55 Mon Sep 17 00:00:00 2001 From: huang47 <157390+huang47@users.noreply.github.com> Date: Wed, 28 Oct 2026 16:52:01 +0800 Subject: [PATCH] feat(pr-risk): record observed base revision --- scripts/pr-risk/README.md | 5 +++++ scripts/pr-risk/grade-pr-risk.sh | 7 ++++--- scripts/pr-risk/tests/test_grade_pr_risk.sh | 10 +++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/pr-risk/README.md b/scripts/pr-risk/README.md index ddbd17fd..c9dd9838 100644 --- a/scripts/pr-risk/README.md +++ b/scripts/pr-risk/README.md @@ -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. diff --git a/scripts/pr-risk/grade-pr-risk.sh b/scripts/pr-risk/grade-pr-risk.sh index fe2d0a0c..fc113386 100755 --- a/scripts/pr-risk/grade-pr-risk.sh +++ b/scripts/pr-risk/grade-pr-risk.sh @@ -640,7 +640,7 @@ fetch_pr_record() { # -> 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 @@ -786,7 +786,7 @@ fetch_pr_record() { # -> 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. @@ -798,7 +798,8 @@ fetch_pr_record() { # -> 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 diff --git a/scripts/pr-risk/tests/test_grade_pr_risk.sh b/scripts/pr-risk/tests/test_grade_pr_risk.sh index 086d2699..3b1abc23 100755 --- a/scripts/pr-risk/tests/test_grade_pr_risk.sh +++ b/scripts/pr-risk/tests/test_grade_pr_risk.sh @@ -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":{ @@ -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