From 1a4360b071d63e45cf1520fd72bbe6518caa6b2f Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:00:28 +0100 Subject: [PATCH 1/4] Verify test report archives for rejected merge groups --- oxa/docs/work.md | 16 ++ oxa/oxa-cli/src/work_board.rs | 40 +-- oxa/oxa-cli/src/work_board/landing.rs | 2 + oxa/oxa-cli/src/work_board/landing/report.rs | 207 +++++++++++++++ oxa/oxa-cli/tests/work_shadow.rs | 132 +++++++++- oxa/oxa-work/src/board/queue.rs | 5 + oxa/oxa-work/src/board/queue/report.rs | 251 +++++++++++++++++++ oxa/oxa-work/src/shadow.rs | 13 + 8 files changed, 643 insertions(+), 23 deletions(-) create mode 100644 oxa/oxa-cli/src/work_board/landing/report.rs create mode 100644 oxa/oxa-work/src/board/queue/report.rs diff --git a/oxa/docs/work.md b/oxa/docs/work.md index 623307e67..810394d2b 100644 --- a/oxa/docs/work.md +++ b/oxa/docs/work.md @@ -18,6 +18,22 @@ and verified merge-group rejection evidence in `queue_rejections`, including the removal event time. Use `--queue-evidence` to record only the rejection evidence alongside the board. +To verify the provenance of test-report archives, pass `--queue-report-policy FILE` with an owner-only +JSON file in a private directory. Set the trusted workflow path, the exact names +of required checks that consume those reports, and every JUnit producer and artifact. + +```json +{ + "workflow_path": ".github/workflows/checks.yml", + "required_check_names": ["workspace test gate"], + "reports": [{"producer_name": "Workspace shard 1", "artifact_name": "test-report-1"}] +} +``` + +That option also enables queue evidence. The shadow journal records the checked +run, attempt, required check IDs, and SHA-256 digests after verifying every +configured archive for that attempt. + Limit: 100 PRs/items per connection. Reported checks are matched against the base's classic protection and active repository/organization rulesets; missing required contexts and unknown/no required checks stay pending. Review diff --git a/oxa/oxa-cli/src/work_board.rs b/oxa/oxa-cli/src/work_board.rs index 98d1e1fdd..9e22d5c35 100644 --- a/oxa/oxa-cli/src/work_board.rs +++ b/oxa/oxa-cli/src/work_board.rs @@ -157,20 +157,8 @@ impl<'a> Reader<'a> { let invalid = QueryError::Other; let (owner, name) = self.repo.split_once('/').ok_or(invalid("expected OWNER/REPO"))?; let query = format!("query{{repository(owner:{owner:?},name:{name:?}){{{fields}}}}}"); - let mut command = Command::new(self.gh); - command - .env("PATH", self.path) - .env("GH_TOKEN", self.token) - .env_remove("GH_DEBUG") - .args([ - "api", - "--include", - "--hostname", - "github.com", - "graphql", - "-f", - &format!("query={query}"), - ]); + let mut command = self.api_command(); + command.args(["--include", "graphql", "-f", &format!("query={query}")]); let (code, text) = oxa_work::command_runner(command, Some(MAX_RESPONSE), oxa_work::COMMAND_DEADLINE) .ok_or(invalid( "GitHub read failed, exceeded its byte limit or timed out", @@ -209,6 +197,16 @@ impl<'a> Reader<'a> { .ok_or(invalid("missing GitHub repository"))?; Ok((repository, text.len())) } + + fn api_command(&self) -> Command { + let mut command = Command::new(self.gh); + command + .env("PATH", self.path) + .env("GH_TOKEN", self.token) + .env_remove("GH_DEBUG") + .args(["api", "--hostname", "github.com"]); + command + } } fn nodes(value: &Value) -> Result<&Vec, String> { @@ -428,10 +426,11 @@ pub(crate) fn run( // Existing parser declaration; migrate command/flag metadata together in #1062. let (repo, options) = match args { [shadow, flag, repo, options @ ..] if shadow == "--shadow" && flag == "--repo" => (repo, options), - _ => return Err("usage: oxa work board --shadow --repo OWNER/REPO [--once] [--token-stdin] [--review-policy FILE] [--queue-evidence] [--landing-shadow]".into()), + _ => return Err("usage: oxa work board --shadow --repo OWNER/REPO [--once] [--token-stdin] [--review-policy FILE] [--queue-evidence] [--landing-shadow] [--queue-report-policy FILE]".into()), }; let (mut once, mut streamed, mut review_file) = (false, false, None); let (mut queue_evidence, mut landing_shadow) = (false, false); + let mut report_file = None; let mut options = options.iter(); while let Some(option) = options.next() { match option.as_str() { @@ -439,6 +438,9 @@ pub(crate) fn run( "--token-stdin" => streamed = true, "--queue-evidence" => queue_evidence = true, "--landing-shadow" => landing_shadow = true, + "--queue-report-policy" if report_file.is_none() => { + report_file = Some(options.next().ok_or("missing queue report policy file")?); + } "--review-policy" if review_file.is_none() => { review_file = Some(options.next().ok_or("missing board review policy file")?); } @@ -468,6 +470,9 @@ pub(crate) fn run( let review_settings = review_file .map(|path| review::Settings::read(Path::new(path))) .transpose()?; + let mut report_settings = report_file + .map(|path| landing::report::Settings::read(Path::new(path))) + .transpose()?; let inherited = env.get("GH_TOKEN").filter(|s| !s.is_empty()); if !streamed && inherited.is_none() { return Err("shadow board requires an explicit GitHub App token".into()); @@ -514,11 +519,14 @@ pub(crate) fn run( Board::read(&mut reader, &board_policy, &BTreeMap::new(), now) .map(|board| (board, BTreeMap::new())) }?; - let queue_rejections = if queue_evidence || landing_shadow { + let mut queue_rejections = if queue_evidence || landing_shadow || report_settings.is_some() { oxa_work::board::queue::read(&board, |fields| reader.repository_read(fields))? } else { Vec::new() }; + if let Some(settings) = &mut report_settings { + reader.sample_test_reports(&mut queue_rejections, settings)?; + } let (landing, landing_main) = if landing_shadow { landing::review_decisions(&reader, &board)? } else { diff --git a/oxa/oxa-cli/src/work_board/landing.rs b/oxa/oxa-cli/src/work_board/landing.rs index 3a141440e..76fd0381b 100644 --- a/oxa/oxa-cli/src/work_board/landing.rs +++ b/oxa/oxa-cli/src/work_board/landing.rs @@ -10,6 +10,8 @@ use oxa_work::shadow::{LandingDecision, QueueObservation}; use serde_json::Value; use std::{collections::BTreeMap, fmt::Write}; +pub(super) mod report; + const BATCH: usize = 8; pub(super) fn review_decisions( diff --git a/oxa/oxa-cli/src/work_board/landing/report.rs b/oxa/oxa-cli/src/work_board/landing/report.rs new file mode 100644 index 000000000..42ea3476b --- /dev/null +++ b/oxa/oxa-cli/src/work_board/landing/report.rs @@ -0,0 +1,207 @@ +//! Download an exact Actions report through the existing Board Reader. +use super::Reader; +use oxa_work::board::queue::{ + report::{ + attempt_for, select, ActionMetadata, ReportArchive, ReportSource, VerifiedArchive, VerifiedReports, + }, + RejectionEvidence, +}; +use serde_json::Value; +use sha2::{Digest, Sha256}; +use std::{ + collections::{BTreeMap, BTreeSet}, + path::Path, + process::Command, +}; + +pub(in crate::work_board) struct Settings { + workflow_path: String, + required_check_names: BTreeSet, + reports: Vec<(String, String)>, + verified: BTreeMap<(String, u64, u64), VerifiedReports>, +} + +impl Settings { + pub(in crate::work_board) fn read(path: &Path) -> Result { + let input = oxa_work::shadow::read_queue_report_policy(path)?; + let invalid = "invalid queue report policy"; + let policy: Value = serde_json::from_slice(&input).map_err(|_| invalid)?; + if policy.as_object().is_none_or(|map| map.len() != 3) { + return Err(invalid.into()); + } + let workflow_path = policy["workflow_path"] + .as_str() + .filter(|path| path.starts_with(".github/workflows/") && !path.chars().any(char::is_control)) + .ok_or(invalid)? + .to_owned(); + let reports = policy["reports"] + .as_array() + .filter(|rows| !rows.is_empty()) + .ok_or(invalid)?; + let label = |value: &Value| { + value + .as_str() + .filter(|name| !name.trim().is_empty() && !name.chars().any(char::is_control)) + .map(str::to_owned) + .ok_or(invalid) + }; + let checks = policy["required_check_names"] + .as_array() + .filter(|rows| !rows.is_empty()) + .ok_or(invalid)?; + let required_check_names = checks.iter().map(label).collect::, _>>()?; + if required_check_names.len() != checks.len() { + return Err(invalid.into()); + } + let mut names = BTreeSet::new(); + let mut sources = Vec::new(); + for row in reports { + if row.as_object().is_none_or(|map| map.len() != 2) { + return Err(invalid.into()); + } + let producer = label(&row["producer_name"])?; + let artifact = label(&row["artifact_name"])?; + if !names.insert(artifact.clone()) { + return Err(invalid.into()); + } + sources.push((producer, artifact)); + } + Ok(Self { + workflow_path, + required_check_names, + reports: sources, + verified: BTreeMap::new(), + }) + } +} + +impl Reader<'_> { + fn actions_get(&self, path: &str) -> Command { + let mut command = self.api_command(); + command.args(["--method", "GET", &format!("repos/{}/actions/{path}", self.repo)]); + command + } + + fn actions_json(&self, path: &str, observed_bytes: &mut usize) -> Result { + let (code, text) = oxa_work::command_runner( + self.actions_get(path), + Some(crate::work_board::MAX_RESPONSE), + oxa_work::COMMAND_DEADLINE, + ) + .ok_or("GitHub Actions response exceeds its limit or timed out")?; + if code != 0 { + return Err("GitHub Actions metadata unavailable".into()); + } + crate::work_board::charge(observed_bytes, text.len())?; + serde_json::from_str(&text).map_err(|_| "invalid GitHub Actions metadata".into()) + } + + pub(in crate::work_board) fn sample_test_reports( + &self, + rejections: &mut [RejectionEvidence], + settings: &mut Settings, + ) -> Result<(), String> { + let mut previous = std::mem::take(&mut settings.verified); + let mut observed_bytes = 0; + for rejection in rejections { + let mut attempts = BTreeMap::<_, Vec<_>>::new(); + for id in rejection.workflow_checks() { + if let Some(attempt) = attempt_for(rejection, id) { + attempts.entry(attempt).or_default().push(id); + } + } + for ((run, attempt), checks) in attempts { + let key = (rejection.removal_event().to_owned(), run, attempt); + let proof = match previous.remove(&key) { + Some(saved) if saved.failed_check_runs == checks => Some(saved), + _ => self.verify_attempt_reports( + rejection, + checks, + (run, attempt), + settings, + &mut observed_bytes, + )?, + }; + if let Some(proof) = proof { + rejection.record_verified_reports(proof.clone()); + settings.verified.insert(key, proof); + } + } + } + Ok(()) + } + + fn verify_attempt_reports( + &self, + rejection: &RejectionEvidence, + checks: Vec, + (run, attempt): (u64, u64), + settings: &Settings, + observed_bytes: &mut usize, + ) -> Result, String> { + let workflow = self.actions_json(&format!("runs/{run}/attempts/{attempt}"), observed_bytes)?; + if workflow["path"].as_str() != Some(settings.workflow_path.as_str()) { + return Ok(None); + } + let producer_jobs = self.actions_json( + &format!("runs/{run}/attempts/{attempt}/jobs?per_page=100"), + observed_bytes, + )?; + let artifacts = self.actions_json(&format!("runs/{run}/artifacts?per_page=100"), observed_bytes)?; + let metadata = ActionMetadata { + attempt: &workflow, + jobs: &producer_jobs, + artifact_listing: &artifacts, + }; + let mut archives = Vec::new(); + for (producer_name, artifact_name) in &settings.reports { + let source = ReportSource { + workflow_path: &settings.workflow_path, + required_check_names: &settings.required_check_names, + producer_name, + artifact_name, + max_archive_bytes: crate::work_board::MAX_RESPONSE as u64, + }; + let mut selected = checks.iter().map(|id| select(rejection, *id, &source, metadata)); + let Some(Some(first)) = selected.next() else { + return Ok(None); + }; + if selected.any(|archive| archive.as_ref() != Some(&first)) { + return Ok(None); + } + archives.push(first); + } + let mut verified = Vec::new(); + for report in archives { + self.verify_archive(&report, observed_bytes)?; + verified.push(VerifiedArchive { + id: report.artifact_id, + sha256: report.sha256.to_owned(), + }); + } + Ok(Some(VerifiedReports { + failed_check_runs: checks, + workflow_run: run, + run_attempt: attempt, + archives: verified, + })) + } + + fn verify_archive(&self, selected: &ReportArchive<'_>, observed_bytes: &mut usize) -> Result<(), String> { + let size = usize::try_from(selected.size_bytes).map_err(|_| "invalid GitHub archive size")?; + crate::work_board::charge(observed_bytes, size)?; + let (code, bytes) = oxa_work::command_output_bytes( + self.actions_get(&format!("artifacts/{}/zip", selected.artifact_id)), + Some(size), + oxa_work::COMMAND_DEADLINE, + ) + .ok_or("GitHub test archive exceeds its limit or timed out")?; + if code != 0 || bytes.len() != size { + return Err("GitHub test archive unavailable or incomplete".into()); + } + if format!("{:x}", Sha256::digest(&bytes)) != selected.sha256 { + return Err("GitHub test archive digest mismatch".into()); + } + Ok(()) + } +} diff --git a/oxa/oxa-cli/tests/work_shadow.rs b/oxa/oxa-cli/tests/work_shadow.rs index 5ca0d3029..27ced19d6 100644 --- a/oxa/oxa-cli/tests/work_shadow.rs +++ b/oxa/oxa-cli/tests/work_shadow.rs @@ -52,6 +52,10 @@ if [ -e oversized ]; then exit 0 fi case "$*" in + *'actions/runs/61/attempts/1/jobs?per_page=100'*) cat report-jobs.json ;; + *'actions/runs/61/attempts/1'*) cat report-attempt.json ;; + *'actions/runs/61/artifacts?per_page=100'*) cat report-artifacts.json ;; + *'actions/artifacts/71/zip'*) printf 'read\n' >> report-reads; cat report.zip ;; *'enqueuedAt headCommit'*) cat queue-state.json ;; *'comments(last:100)'*) cat review.json ;; *'REMOVED_FROM_MERGE_QUEUE_EVENT'*) printf 'read\n' >> queue-calls; cat queue.json ;; @@ -736,12 +740,8 @@ fn opt_in_review_policy_observes_pinned_diff_and_authenticated_reviews() { } } -#[test] -fn real_shadow_cli_records_exact_queue_evidence_only_when_opted_in() { - use serde_json::{json, Value}; - let (env, _) = fixture(); - let group = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; - let queue = json!({"data":{"repository":{ +fn queue_rejection(group: &str) -> serde_json::Value { + serde_json::json!({"data":{"repository":{ "mergeQueue":{"id":"queue-1"}, "p42":{ "number":42,"headRefOid":"synthetic-head","state":"OPEN","baseRefName":"main", @@ -756,7 +756,15 @@ fn real_shadow_cli_records_exact_queue_evidence_only_when_opted_in() { }} }]} } - }}}); + }}}) +} + +#[test] +fn real_shadow_cli_records_exact_queue_evidence_only_when_opted_in() { + use serde_json::{json, Value}; + let (env, _) = fixture(); + let group = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; + let queue = queue_rejection(group); fs::write(env.work().join("queue.json"), queue.to_string()).unwrap(); let args = "work board --shadow --repo example/repo --once"; @@ -796,6 +804,116 @@ fn real_shadow_cli_records_exact_queue_evidence_only_when_opted_in() { ); } +#[test] +fn report_policy_records_only_archives_verified_for_all_required_failed_checks() { + use serde_json::{json, Value}; + use sha2::{Digest, Sha256}; + let (env, _) = fixture(); + let group = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; + let workflow_path = ".github/workflows/checks.yml"; + let mut queue = queue_rejection(group); + let contexts = queue + .pointer_mut("/data/repository/p42/timelineItems/nodes/0/beforeCommit/statusCheckRollup/contexts") + .unwrap(); + contexts["nodes"][0]["checkSuite"] = json!({ + "databaseId":51,"commit":{"oid":group}, + "workflowRun":{"databaseId":61,"event":"merge_group","runAttempt":1} + }); + let mut second = contexts["nodes"][0].clone(); + second["databaseId"] = 12.into(); + contexts["nodes"].as_array_mut().unwrap().push(second); + contexts["totalCount"] = 2.into(); + let write = |file: &str, value: Value| { + fs::write(env.work().join(file), value.to_string()).unwrap(); + }; + write("queue.json", queue); + write( + "report-attempt.json", + json!({"id":61,"run_attempt":1,"check_suite_id":51,"head_sha":group, + "event":"merge_group","status":"completed","path":workflow_path,"run_started_at":"2025-12-31T23:59:40Z"}), + ); + write( + "report-jobs.json", + json!({"total_count":3,"jobs":[ + {"id":11,"name":"Test aggregate","run_id":61,"run_attempt":1,"head_sha":group, + "status":"completed","conclusion":"failure","completed_at":"2026-01-01T00:00:00Z"}, + {"id":12,"name":"Gate","run_id":61,"run_attempt":1,"head_sha":group, + "status":"completed","conclusion":"failure","completed_at":"2026-01-01T00:00:00Z"}, + {"id":21,"name":"Test shard","run_id":61,"run_attempt":1,"head_sha":group, + "status":"completed","started_at":"2025-12-31T23:59:50Z", + "completed_at":"2025-12-31T23:59:58Z"} + ]}), + ); + let policy = env.write( + "tmp/report-policy.json", + &json!({ + "workflow_path":workflow_path, + "required_check_names":["Test aggregate","Gate"], + "reports":[{"producer_name":"Test shard","artifact_name":"report-1"}] + }) + .to_string(), + ); + fs::set_permissions(&policy, fs::Permissions::from_mode(0o600)).unwrap(); + + let bytes = b"synthetic opaque report bytes"; + fs::write(env.work().join("report.zip"), bytes).unwrap(); + let digest = format!("{:x}", Sha256::digest(bytes)); + let listing = |sha256: &str| { + json!({"total_count":1,"artifacts":[{"id":71,"name":"report-1", + "size_in_bytes":bytes.len(),"digest":format!("sha256:{sha256}"),"expired":false, + "created_at":"2025-12-31T23:59:57Z","updated_at":"2025-12-31T23:59:57Z", + "workflow_run":{"id":61,"head_sha":group}}]}) + }; + write("report-artifacts.json", listing(&digest)); + let args = format!( + "work board --shadow --repo example/repo --once --queue-report-policy {}", + policy.display() + ); + let result = invoke(&env, &args); + assert!( + result.status.success(), + "{}", + String::from_utf8_lossy(&result.stderr) + ); + let log = log_for(&env, "example/repo"); + let saved = fs::read_to_string(&log).unwrap(); + let sample: Value = serde_json::from_str(saved.trim()).unwrap(); + assert_eq!( + sample["queue_rejections"][0]["verified_test_reports"], + json!([{ + "failed_check_runs":[11,12],"workflow_run":61,"run_attempt":1, + "archives":[{"id":71,"sha256":digest}] + }]) + ); + assert_eq!( + fs::read_to_string(env.work().join("report-reads")).unwrap(), + "read\n" + ); + + write("report-artifacts.json", listing(&"0".repeat(64))); + let result = invoke(&env, &args); + assert_eq!(result.status.code(), Some(2)); + assert!(String::from_utf8_lossy(&result.stderr).contains("GitHub test archive digest mismatch")); + assert_eq!(fs::read_to_string(&log).unwrap(), saved); + + let job_path = env.work().join("report-jobs.json"); + let mut jobs: Value = serde_json::from_str(&fs::read_to_string(job_path).unwrap()).unwrap(); + jobs["jobs"][1]["name"] = "Unrelated check".into(); + write("report-jobs.json", jobs); + let result = invoke(&env, &args); + assert!(result.status.success()); + let updated = fs::read_to_string(log).unwrap(); + assert!(updated.starts_with(&saved)); + let sample: Value = serde_json::from_str(updated.lines().last().unwrap()).unwrap(); + assert!(sample["queue_rejections"][0] + .get("verified_test_reports") + .is_none()); + assert_eq!( + fs::read_to_string(env.work().join("report-reads")).unwrap(), + "read\nread\n" + ); +} + #[test] fn landing_shadow_holds_an_approved_head_on_unresolved_older_review() { use serde_json::{json, Value}; diff --git a/oxa/oxa-work/src/board/queue.rs b/oxa/oxa-work/src/board/queue.rs index 4119ce66b..6257f06bc 100644 --- a/oxa/oxa-work/src/board/queue.rs +++ b/oxa/oxa-work/src/board/queue.rs @@ -4,6 +4,8 @@ use serde::Serialize; use serde_json::Value; use std::collections::{BTreeMap, BTreeSet}; +pub mod report; + const BATCH: usize = 8; const MAX_PRS: usize = 1000; const MAX_BYTES: usize = 4 * 1024 * 1024; @@ -18,6 +20,8 @@ pub struct RejectionEvidence { failed_required_check_runs: Vec, #[serde(skip_serializing_if = "BTreeMap::is_empty")] failed_required_workflows: BTreeMap, + #[serde(skip_serializing_if = "Vec::is_empty")] + verified_test_reports: Vec, } #[derive(Clone, Copy, Debug, Serialize, PartialEq, Eq)] @@ -212,6 +216,7 @@ fn rejection(row: &Value, entry: &Entry, queue_id: &str) -> Result { + pub workflow_path: &'a str, + pub required_check_names: &'a BTreeSet, + pub producer_name: &'a str, + pub artifact_name: &'a str, + pub max_archive_bytes: u64, +} + +/// Authenticated JSON from the existing GitHub Reader's Actions endpoints. +#[derive(Clone, Copy)] +pub struct ActionMetadata<'a> { + pub attempt: &'a Value, + pub jobs: &'a Value, + pub artifact_listing: &'a Value, +} + +#[derive(Debug, PartialEq, Eq)] +pub struct ReportArchive<'a> { + pub artifact_id: u64, + pub size_bytes: u64, + pub sha256: &'a str, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize)] +pub struct VerifiedArchive { + pub id: u64, + pub sha256: String, +} + +#[derive(Clone, Debug, PartialEq, Eq, Serialize)] +pub struct VerifiedReports { + pub failed_check_runs: Vec, + pub workflow_run: u64, + pub run_attempt: u64, + pub archives: Vec, +} + +impl RejectionEvidence { + pub fn removal_event(&self) -> &str { + &self.removal_event + } + + pub fn workflow_checks(&self) -> impl Iterator + '_ { + self.failed_required_workflows.keys().copied() + } + + pub fn record_verified_reports(&mut self, report: VerifiedReports) { + if !report.failed_check_runs.is_empty() + && report.failed_check_runs.windows(2).all(|ids| ids[0] < ids[1]) + && report + .failed_check_runs + .iter() + .all(|id| attempt_for(self, *id) == Some((report.workflow_run, report.run_attempt))) + { + self.verified_test_reports.push(report); + } + } +} + +/// Read addresses derived from the rejected group's verified check suite. +pub fn attempt_for(rejection: &RejectionEvidence, failed_check_id: u64) -> Option<(u64, u64)> { + let expected = rejection.failed_required_workflows.get(&failed_check_id)?; + Some((expected.workflow_run_id, expected.observed_run_attempt)) +} + +fn unique_row<'a>(listing: &'a Value, key: &str, matches: impl Fn(&Value) -> bool) -> Option<&'a Value> { + let rows = listing[key].as_array()?; + if rows.len() > 100 || listing["total_count"].as_u64() != Some(rows.len() as u64) { + return None; + } + let mut matching = rows.iter().filter(|row| matches(row)); + let first = matching.next()?; + matching.next().is_none().then_some(first) +} + +/// Verify the exact failed job and the report producer before selecting bytes. +/// The caller must still verify the downloaded archive against this digest. +pub fn select<'a>( + rejection: &RejectionEvidence, + failed_check_id: u64, + source: &ReportSource<'_>, + metadata: ActionMetadata<'a>, +) -> Option> { + let expected = rejection.failed_required_workflows.get(&failed_check_id)?; + let head = rejection.merge_group_head.as_str(); + let run_id = expected.workflow_run_id; + let attempt_number = expected.observed_run_attempt; + let job_matches = |job: &Value| { + job["run_id"].as_u64() == Some(run_id) + && job["run_attempt"].as_u64() == Some(attempt_number) + && job["head_sha"].as_str() == Some(head) + && job["status"] == "completed" + }; + let failed = unique_row(metadata.jobs, "jobs", |job| { + job["id"].as_u64() == Some(failed_check_id) + })?; + let failed_at = github_utc(&failed["completed_at"])?; + if !source.required_check_names.contains(failed["name"].as_str()?) + || !job_matches(failed) + || failed["conclusion"] != "failure" + || failed_at > rejection.removed_at.as_str() + { + return None; + } + let attempt = metadata.attempt; + if attempt["id"].as_u64() != Some(run_id) + || attempt["run_attempt"].as_u64() != Some(attempt_number) + || attempt["check_suite_id"].as_u64() != Some(expected.check_suite_id) + || attempt["head_sha"].as_str() != Some(head) + || attempt["event"] != "merge_group" + || attempt["status"] != "completed" + || attempt["path"].as_str() != Some(source.workflow_path) + { + return None; + } + let producer = unique_row(metadata.jobs, "jobs", |job| { + job["name"].as_str() == Some(source.producer_name) + })?; + if !job_matches(producer) || positive_id(&producer["id"]).is_none() { + return None; + } + let start = github_utc(&producer["started_at"])?; + let finish = github_utc(&producer["completed_at"])?; + if start < github_utc(&attempt["run_started_at"])? || finish > failed_at { + return None; + } + + let artifact = unique_row(metadata.artifact_listing, "artifacts", |artifact| { + artifact["name"].as_str() == Some(source.artifact_name) + })?; + let created = github_utc(&artifact["created_at"])?; + let updated = github_utc(&artifact["updated_at"])?; + if artifact["expired"] != false + || artifact["workflow_run"]["id"].as_u64() != Some(run_id) + || artifact["workflow_run"]["head_sha"].as_str() != Some(head) + || !(start <= created && created <= updated && updated <= finish) + { + return None; + } + let sha256 = artifact["digest"].as_str()?.strip_prefix("sha256:")?; + if sha256.len() != 64 || !super::is_object_id(sha256) { + return None; + } + Some(ReportArchive { + artifact_id: positive_id(&artifact["id"])?, + size_bytes: positive_id(&artifact["size_in_bytes"]) + .filter(|size| *size <= source.max_archive_bytes)?, + sha256, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::board::queue::WorkflowIdentity; + use serde_json::json; + + const HEAD: &str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + const DIGEST: &str = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; + + #[test] + fn selects_only_the_exact_attempt_and_producer_archive() { + let evidence = RejectionEvidence { + number: 17, + removal_event: "removal".into(), + removed_at: "2026-01-01T00:09:00Z".into(), + merge_group_head: HEAD.into(), + failed_required_check_runs: vec![42], + failed_required_workflows: [( + 42, + WorkflowIdentity { + check_suite_id: 51, + workflow_run_id: 61, + observed_run_attempt: 2, + }, + )] + .into(), + verified_test_reports: Vec::new(), + }; + let source = ReportSource { + workflow_path: ".github/workflows/checks.yml", + required_check_names: &BTreeSet::from(["required aggregate".into()]), + producer_name: "mandatory shard 2", + artifact_name: "test-report-2", + max_archive_bytes: 1024, + }; + let failed = json!({"id":42,"run_id":61,"run_attempt":2,"head_sha":HEAD, + "status":"completed","name":"required aggregate", + "conclusion":"failure","completed_at":"2026-01-01T00:08:59Z"}); + let attempt = json!({"id":61,"run_attempt":2,"head_sha":HEAD,"check_suite_id":51, + "event":"merge_group","status":"completed","path":source.workflow_path,"run_started_at":"2026-01-01T00:04:00Z"}); + let producer = json!({"id":44,"run_id":61,"run_attempt":2,"head_sha":HEAD, + "status":"completed","name":source.producer_name, + "started_at":"2026-01-01T00:06:00Z","completed_at":"2026-01-01T00:08:00Z"}); + let artifact = json!({"id":71,"name":source.artifact_name,"size_in_bytes":128, + "digest":format!("sha256:{DIGEST}"),"expired":false, + "created_at":"2026-01-01T00:07:59Z","updated_at":"2026-01-01T00:07:59Z", + "workflow_run":{"id":61,"head_sha":HEAD}}); + let verify = |failed: &Value, attempt: &Value, producer: &Value, listing: &Value| { + let mut jobs = producer.clone(); + jobs["jobs"].as_array_mut().unwrap().push(failed.clone()); + jobs["total_count"] = (producer["total_count"].as_u64().unwrap() + 1).into(); + select( + &evidence, + 42, + &source, + ActionMetadata { + attempt, + jobs: &jobs, + artifact_listing: listing, + }, + ) + .map(|archive| (archive.artifact_id, archive.size_bytes, archive.sha256.to_owned())) + }; + let producers = json!({"total_count":1,"jobs":[producer]}); + let listing = json!({"total_count":1,"artifacts":[artifact]}); + assert_eq!( + verify(&failed, &attempt, &producers, &listing), + Some((71, 128, DIGEST.into())) + ); + let mut replaced_job = failed.clone(); + replaced_job["run_attempt"] = 3.into(); + assert!(verify(&replaced_job, &attempt, &producers, &listing).is_none()); + replaced_job = failed.clone(); + replaced_job["completed_at"] = "2026-01-01T00:07:30Z".into(); + assert!(verify(&replaced_job, &attempt, &producers, &listing).is_none()); + let mut unrelated = failed.clone(); + unrelated["name"] = "unrelated required check".into(); + assert!(verify(&unrelated, &attempt, &producers, &listing).is_none()); + let mut replaced_producer = producers.clone(); + replaced_producer["jobs"][0]["run_attempt"] = 1.into(); + assert!(verify(&failed, &attempt, &replaced_producer, &listing).is_none()); + let mut earlier = listing.clone(); + earlier["artifacts"][0]["created_at"] = "2026-01-01T00:05:59Z".into(); + assert!(verify(&failed, &attempt, &producers, &earlier).is_none()); + let mut partial = listing.clone(); + partial["total_count"] = 2.into(); + assert!(verify(&failed, &attempt, &producers, &partial).is_none()); + let duplicate = json!({"total_count":2,"artifacts":[artifact,artifact]}); + assert!(verify(&failed, &attempt, &producers, &duplicate).is_none()); + let duplicate_producer = json!({"total_count":2,"jobs":[producer,producer]}); + assert!(verify(&failed, &attempt, &duplicate_producer, &listing).is_none()); + } +} diff --git a/oxa/oxa-work/src/shadow.rs b/oxa/oxa-work/src/shadow.rs index e0f84c0c5..96bde0715 100644 --- a/oxa/oxa-work/src/shadow.rs +++ b/oxa/oxa-work/src/shadow.rs @@ -12,6 +12,19 @@ use std::time::{Duration, Instant}; pub const INTERVAL: Duration = Duration::from_secs(300); pub const MAX_LOG_BYTES: u64 = 64 * 1024 * 1024; +/// Read the owner's explicit report policy through the private facts storage checks. +pub fn read_queue_report_policy(path: &Path) -> Result> { + let path = std::path::absolute(path).map_err(|_| "invalid queue report policy path")?; + let name = path + .file_name() + .and_then(|file| file.to_str()) + .ok_or("invalid queue report policy file")?; + let parent = path + .parent() + .ok_or("queue report policy needs a private directory")?; + crate::facts_io::Root::open(parent, false)?.read(name, 16_384) +} + #[derive(Serialize)] struct Sample<'a> { schema_version: u32, From 8067c2bfc6d882f5ec93fc86d5ca0f89261483f9 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:44:24 +0100 Subject: [PATCH 2/4] Reproduce repeated archive reads for two PRs in one merge group --- oxa/oxa-cli/tests/work_shadow.rs | 48 +++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/oxa/oxa-cli/tests/work_shadow.rs b/oxa/oxa-cli/tests/work_shadow.rs index ecf3882ba..2546bd600 100644 --- a/oxa/oxa-cli/tests/work_shadow.rs +++ b/oxa/oxa-cli/tests/work_shadow.rs @@ -53,7 +53,7 @@ if [ -e oversized ]; then fi case "$*" in *'actions/runs/61/attempts/1/jobs?per_page=100'*) cat report-jobs.json ;; - *'actions/runs/61/attempts/1'*) cat report-attempt.json ;; + *'actions/runs/61/attempts/1'*) printf 'read\n' >> report-attempt-reads; cat report-attempt.json ;; *'actions/runs/61/artifacts?per_page=100'*) cat report-artifacts.json ;; *'actions/artifacts/71/zip'*) printf 'read\n' >> report-reads; cat report.zip ;; *'enqueuedAt headCommit'*) cat queue-state.json ;; @@ -987,7 +987,8 @@ fn real_shadow_cli_records_exact_queue_evidence_only_when_opted_in() { fn report_policy_records_only_archives_verified_for_all_required_failed_checks() { use serde_json::{json, Value}; use sha2::{Digest, Sha256}; - let (env, _) = fixture(); + let (env, mut detail) = fixture(); + let second_head = "second-synthetic-head"; let group = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; let workflow_path = ".github/workflows/checks.yml"; let mut queue = queue_rejection(group); @@ -1005,6 +1006,23 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() let write = |file: &str, value: Value| { fs::write(env.work().join(file), value.to_string()).unwrap(); }; + let repo = &mut detail["data"]["repository"]; + let mut second = repo["p42"].clone(); + second["number"] = 43.into(); + second["headRefOid"] = second_head.into(); + repo["p43"] = second; + repo["pullRequests"]["totalCount"] = 2.into(); + repo["pullRequests"]["nodes"].as_array_mut().unwrap().push(json!({ + "number":43,"headRefOid":second_head + })); + write("first.json", detail.clone()); + write("detail.json", detail); + let rows = &mut queue["data"]["repository"]; + let mut second = rows["p42"].clone(); + second["number"] = 43.into(); + second["headRefOid"] = second_head.into(); + second["timelineItems"]["nodes"][0]["id"] = "removal-2".into(); + rows["p43"] = second; write("queue.json", queue); write( "report-attempt.json", @@ -1057,17 +1075,21 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() let log = log_for(&env, "example/repo"); let saved = fs::read_to_string(&log).unwrap(); let sample: Value = serde_json::from_str(saved.trim()).unwrap(); - assert_eq!( - sample["queue_rejections"][0]["verified_test_reports"], - json!([{ - "failed_check_runs":[11,12],"workflow_run":61,"run_attempt":1, - "archives":[{"id":71,"sha256":digest}] - }]) - ); - assert_eq!( - fs::read_to_string(env.work().join("report-reads")).unwrap(), - "read\n" - ); + for (index, number, event) in [(0, 42, "removal-1"), (1, 43, "removal-2")] { + let row = &sample["queue_rejections"][index]; + assert_eq!(row["number"], number); + assert_eq!(row["removal_event"], event); + assert_eq!( + row["verified_test_reports"], + json!([{ + "failed_check_runs":[11,12],"workflow_run":61,"run_attempt":1, + "archives":[{"id":71,"sha256":digest}] + }]) + ); + } + for log in ["report-reads", "report-attempt-reads"] { + assert_eq!(fs::read_to_string(env.work().join(log)).unwrap(), "read\n"); + } write("report-artifacts.json", listing(&"0".repeat(64))); let result = invoke(&env, &args); From 117b10bb0b3da93ab42c633822583932718af657 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:52:49 +0100 Subject: [PATCH 3/4] Share verified report downloads within a merge-group attempt --- oxa/oxa-cli/src/work_board/landing/report.rs | 58 ++++++++++++++++---- oxa/oxa-cli/tests/work_shadow.rs | 40 +++++++++++++- 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/oxa/oxa-cli/src/work_board/landing/report.rs b/oxa/oxa-cli/src/work_board/landing/report.rs index 55f2cdec6..d5b4e591e 100644 --- a/oxa/oxa-cli/src/work_board/landing/report.rs +++ b/oxa/oxa-cli/src/work_board/landing/report.rs @@ -9,11 +9,18 @@ use oxa_work::board::queue::{ use serde_json::Value; use sha2::{Digest, Sha256}; use std::{ - collections::{BTreeMap, BTreeSet}, + collections::{btree_map::Entry, BTreeMap, BTreeSet}, path::Path, process::Command, }; +struct AttemptRead { + workflow: Value, + jobs: Value, + artifacts: Value, + verified_archives: BTreeSet<(u64, u64, String)>, +} + pub(in crate::work_board) struct Settings { workflow_path: String, required_check_names: BTreeSet, @@ -99,6 +106,7 @@ impl Reader<'_> { settings: &mut Settings, ) -> Result<(), String> { let mut previous = std::mem::take(&mut settings.verified); + let mut attempts_read = BTreeMap::new(); for rejection in rejections { let mut attempts = BTreeMap::<_, Vec<_>>::new(); for id in rejection.workflow_checks() { @@ -110,7 +118,16 @@ impl Reader<'_> { let key = (rejection.removal_event().to_owned(), run, attempt); let proof = match previous.remove(&key) { Some(saved) if saved.failed_check_runs == checks => Some(saved), - _ => self.verify_attempt_reports(rejection, checks, (run, attempt), settings)?, + _ => { + let sources = match attempts_read.entry((run, attempt)) { + Entry::Occupied(entry) => entry.into_mut(), + Entry::Vacant(entry) => { + entry.insert(self.read_attempt(run, attempt, &settings.workflow_path)?) + } + }; + let Some(sources) = sources else { continue }; + self.verify_attempt_reports(rejection, checks, (run, attempt), settings, sources)? + } }; if let Some(proof) = proof { rejection.record_verified_reports(proof.clone()); @@ -121,23 +138,36 @@ impl Reader<'_> { Ok(()) } + fn read_attempt( + &self, + run: u64, + attempt: u64, + workflow_path: &str, + ) -> Result, String> { + let workflow = self.actions_json(&format!("runs/{run}/attempts/{attempt}"))?; + if workflow["path"].as_str() != Some(workflow_path) { + return Ok(None); + } + Ok(Some(AttemptRead { + workflow, + jobs: self.actions_json(&format!("runs/{run}/attempts/{attempt}/jobs?per_page=100"))?, + artifacts: self.actions_json(&format!("runs/{run}/artifacts?per_page=100"))?, + verified_archives: BTreeSet::new(), + })) + } + fn verify_attempt_reports( &self, rejection: &RejectionEvidence, checks: Vec, (run, attempt): (u64, u64), settings: &Settings, + sources: &mut AttemptRead, ) -> Result, String> { - let workflow = self.actions_json(&format!("runs/{run}/attempts/{attempt}"))?; - if workflow["path"].as_str() != Some(settings.workflow_path.as_str()) { - return Ok(None); - } - let producer_jobs = self.actions_json(&format!("runs/{run}/attempts/{attempt}/jobs?per_page=100"))?; - let artifacts = self.actions_json(&format!("runs/{run}/artifacts?per_page=100"))?; let metadata = ActionMetadata { - attempt: &workflow, - jobs: &producer_jobs, - artifact_listing: &artifacts, + attempt: &sources.workflow, + jobs: &sources.jobs, + artifact_listing: &sources.artifacts, }; let mut archives = Vec::new(); for (producer_name, artifact_name) in &settings.reports { @@ -159,7 +189,11 @@ impl Reader<'_> { } let mut verified = Vec::new(); for report in archives { - self.verify_archive(&report)?; + let key = (report.artifact_id, report.size_bytes, report.sha256.to_owned()); + if !sources.verified_archives.contains(&key) { + self.verify_archive(&report)?; + sources.verified_archives.insert(key); + } verified.push(VerifiedArchive { id: report.artifact_id, sha256: report.sha256.to_owned(), diff --git a/oxa/oxa-cli/tests/work_shadow.rs b/oxa/oxa-cli/tests/work_shadow.rs index 2546bd600..ce24e4c82 100644 --- a/oxa/oxa-cli/tests/work_shadow.rs +++ b/oxa/oxa-cli/tests/work_shadow.rs @@ -1023,7 +1023,7 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() second["headRefOid"] = second_head.into(); second["timelineItems"]["nodes"][0]["id"] = "removal-2".into(); rows["p43"] = second; - write("queue.json", queue); + write("queue.json", queue.clone()); write( "report-attempt.json", json!({"id":61,"run_attempt":1,"check_suite_id":51,"head_sha":group, @@ -1099,6 +1099,7 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() let job_path = env.work().join("report-jobs.json"); let mut jobs: Value = serde_json::from_str(&fs::read_to_string(job_path).unwrap()).unwrap(); + let valid_jobs = jobs.clone(); jobs["jobs"][1]["name"] = "Unrelated check".into(); write("report-jobs.json", jobs); let result = invoke(&env, &args); @@ -1117,6 +1118,7 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() // This REST reply fits in isolation, but the board has already used part of the budget. let attempt_path = env.work().join("report-attempt.json"); let mut attempt: Value = serde_json::from_str(&fs::read_to_string(&attempt_path).unwrap()).unwrap(); + let valid_attempt = attempt.clone(); let cap = 4 * 1024 * 1024; attempt["padding"] = "a".repeat(cap - 512).into(); assert!(attempt.to_string().len() < cap); @@ -1124,7 +1126,41 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() let result = invoke(&env, &args); assert_eq!(result.status.code(), Some(2)); assert!(String::from_utf8_lossy(&result.stderr).contains("GitHub Actions response exceeds its limit")); - assert_eq!(fs::read_to_string(log).unwrap(), updated); + assert_eq!(fs::read_to_string(&log).unwrap(), updated); + + write("report-jobs.json", valid_jobs); + write("report-attempt.json", valid_attempt); + write("report-artifacts.json", listing(&digest)); + let early = &mut queue["data"]["repository"]["p43"]["timelineItems"]["nodes"][0]; + let before_completion = json!("2025-12-31T23:59:59Z"); + early["createdAt"] = before_completion.clone(); + for check in early["beforeCommit"]["statusCheckRollup"]["contexts"]["nodes"] + .as_array_mut() + .unwrap() + { + check["completedAt"] = before_completion.clone(); + } + write("queue.json", queue); + let result = invoke(&env, &args); + assert!( + result.status.success(), + "{}", + String::from_utf8_lossy(&result.stderr) + ); + let text = fs::read_to_string(log).unwrap(); + let sample: Value = serde_json::from_str(text.lines().last().unwrap()).unwrap(); + assert_eq!( + sample["queue_rejections"][0]["verified_test_reports"][0]["failed_check_runs"], + json!([11, 12]) + ); + assert_eq!(sample["queue_rejections"][1]["removal_event"], "removal-2"); + assert!(sample["queue_rejections"][1] + .get("verified_test_reports") + .is_none()); + assert_eq!( + fs::read_to_string(env.work().join("report-reads")).unwrap(), + "read\nread\nread\n" + ); } #[test] From 29333db9f85f55a4db58000c8adc57202e60b3e5 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Wed, 18 Nov 2026 02:50:25 +0100 Subject: [PATCH 4/4] Qualify merge-group evidence with a synthetic JUnit archive --- oxa/Cargo.lock | 67 ++++++++++++++++++++++++++++-- oxa/oxa-cli/Cargo.toml | 1 + oxa/oxa-cli/tests/work_shadow.rs | 70 ++++++++++++++++++++++++++++++-- 3 files changed, 132 insertions(+), 6 deletions(-) diff --git a/oxa/Cargo.lock b/oxa/Cargo.lock index 353a5c1fc..794a50c44 100644 --- a/oxa/Cargo.lock +++ b/oxa/Cargo.lock @@ -327,6 +327,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "constant_time_eq" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eb6feb175df65d0a3ccd3e73484e940d0ac664e8034f0519fd49a93db3071d9" +dependencies = [ + "rustversion", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -1097,6 +1106,18 @@ dependencies = [ "libc", ] +[[package]] +name = "nix" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77730ed34f01f4990cb2ea67fec715ecebc6fab9a6396cf83c5529b13f581bdc" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "num-bigint" version = "0.4.8" @@ -1183,6 +1204,7 @@ dependencies = [ "serde_json", "sha2", "signal-hook", + "zip", ] [[package]] @@ -1355,7 +1377,7 @@ dependencies = [ name = "oxa-proto" version = "0.2.0" dependencies = [ - "nix", + "nix 0.30.1", "serde_json", ] @@ -1481,7 +1503,7 @@ dependencies = [ "futures-util", "getrandom 0.3.4", "hmac", - "nix", + "nix 0.30.1", "num-traits", "oxa-engine", "oxa-proto", @@ -1498,7 +1520,7 @@ version = "0.2.0" dependencies = [ "async-io", "futures-lite", - "nix", + "nix 0.30.1", "oxa-engine", "oxa-fake", "oxa-proto", @@ -2379,6 +2401,12 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "typed-path" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e" + [[package]] name = "typenum" version = "1.20.1" @@ -2972,6 +3000,20 @@ name = "zeroize" version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] [[package]] name = "zerotrie" @@ -3006,6 +3048,25 @@ dependencies = [ "syn 3.0.10", ] +[[package]] +name = "zip" +version = "9.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953a376f4930ed5af88e1e65948385f76866b45e7f75b21ac275327d0eeb9b46" +dependencies = [ + "constant_time_eq", + "crc32fast", + "flate2", + "getrandom 0.4.3", + "indexmap", + "libc", + "memchr", + "nix 0.32.0", + "typed-path", + "windows-sys 0.61.2", + "zeroize", +] + [[package]] name = "zlib-rs" version = "0.6.8" diff --git a/oxa/oxa-cli/Cargo.toml b/oxa/oxa-cli/Cargo.toml index 822043843..1ae35c97f 100644 --- a/oxa/oxa-cli/Cargo.toml +++ b/oxa/oxa-cli/Cargo.toml @@ -51,6 +51,7 @@ pulldown-cmark = { version = "0.13.6", default-features = false } [dev-dependencies] oxa-fake.workspace = true +zip = { version = "9.6.1", default-features = false, features = ["deflate-flate2-zlib-rs"] } [target.'cfg(target_os = "linux")'.dev-dependencies] oxa-orchestrator = { path = "../oxa-orchestrator", features = ["a2a"] } diff --git a/oxa/oxa-cli/tests/work_shadow.rs b/oxa/oxa-cli/tests/work_shadow.rs index ce24e4c82..adb4b1688 100644 --- a/oxa/oxa-cli/tests/work_shadow.rs +++ b/oxa/oxa-cli/tests/work_shadow.rs @@ -987,7 +987,24 @@ fn real_shadow_cli_records_exact_queue_evidence_only_when_opted_in() { fn report_policy_records_only_archives_verified_for_all_required_failed_checks() { use serde_json::{json, Value}; use sha2::{Digest, Sha256}; + use std::io::{Cursor, Write}; + use zip::{write::SimpleFileOptions, CompressionMethod, ZipWriter}; let (env, mut detail) = fixture(); + fs::rename(env.tmp().join("gh"), env.tmp().join("gh-fixture")).unwrap(); + let gh = env.write( + "tmp/gh", + r#"#!/bin/sh +if [ "$1 $2 $3" = 'api --hostname github.com' ]; then + case "$#:$4:$5:$6:$7" in + '7:--include:graphql:-f:query=query{'*|'6:--method:GET:repos/example/repo/actions/'*':') + exec "$0-fixture" "$@" ;; + esac +fi +printf 'unexpected command\n' >> unexpected-github-command +exit 94 +"#, + ); + fs::set_permissions(gh, fs::Permissions::from_mode(0o700)).unwrap(); let second_head = "second-synthetic-head"; let group = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; let workflow_path = ".github/workflows/checks.yml"; @@ -1023,6 +1040,7 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() second["headRefOid"] = second_head.into(); second["timelineItems"]["nodes"][0]["id"] = "removal-2".into(); rows["p43"] = second; + let valid_queue = queue.clone(); write("queue.json", queue.clone()); write( "report-attempt.json", @@ -1052,9 +1070,24 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() ); fs::set_permissions(&policy, fs::Permissions::from_mode(0o600)).unwrap(); - let bytes = b"synthetic opaque report bytes"; - fs::write(env.work().join("report.zip"), bytes).unwrap(); - let digest = format!("{:x}", Sha256::digest(bytes)); + let mut archive = ZipWriter::new(Cursor::new(Vec::new())); + archive + .start_file( + "junit.xml", + SimpleFileOptions::default().compression_method(CompressionMethod::Deflated), + ) + .unwrap(); + archive + .write_all( + br#" + + synthetic output +"#, + ) + .unwrap(); + let bytes = archive.finish().unwrap().into_inner(); + fs::write(env.work().join("report.zip"), &bytes).unwrap(); + let digest = format!("{:x}", Sha256::digest(&bytes)); let listing = |sha256: &str| { json!({"total_count":1,"artifacts":[{"id":71,"name":"report-1", "size_in_bytes":bytes.len(),"digest":format!("sha256:{sha256}"),"expired":false, @@ -1079,6 +1112,7 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() let row = &sample["queue_rejections"][index]; assert_eq!(row["number"], number); assert_eq!(row["removal_event"], event); + assert_eq!(row["merge_group_head"], group); assert_eq!( row["verified_test_reports"], json!([{ @@ -1161,6 +1195,36 @@ fn report_policy_records_only_archives_verified_for_all_required_failed_checks() fs::read_to_string(env.work().join("report-reads")).unwrap(), "read\nread\nread\n" ); + + let mut wrong_suite = valid_queue; + let checks = &mut wrong_suite["data"]["repository"]["p43"]["timelineItems"]["nodes"][0]["beforeCommit"] + ["statusCheckRollup"]["contexts"]["nodes"]; + for check in checks.as_array_mut().unwrap() { + check["checkSuite"]["databaseId"] = 52.into(); + } + write("queue.json", wrong_suite); + let result = invoke(&env, &args); + assert!( + result.status.success(), + "{}", + String::from_utf8_lossy(&result.stderr) + ); + let text = fs::read_to_string(log_for(&env, "example/repo")).unwrap(); + let sample: Value = serde_json::from_str(text.lines().last().unwrap()).unwrap(); + assert_eq!( + sample["queue_rejections"][0]["verified_test_reports"][0]["archives"], + json!([{"id":71,"sha256":digest}]) + ); + let other = &sample["queue_rejections"][1]; + assert_eq!(other["merge_group_head"], group); + assert_eq!(other["removal_event"], "removal-2"); + assert_eq!(other["failed_required_check_runs"], json!([11, 12])); + assert!(other.get("verified_test_reports").is_none()); + assert_eq!( + fs::read_to_string(env.work().join("report-reads")).unwrap(), + "read\nread\nread\nread\n" + ); + assert!(!env.work().join("unexpected-github-command").exists()); } #[test]