Skip to content
Merged
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
6 changes: 5 additions & 1 deletion .github/workflows/routed-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,14 @@ jobs:
DOCS_DETECT_RESULT: ${{ needs.detect-docs-only.result }}
DOCS_ONLY: ${{ needs.detect-docs-only.outputs.docs_only }}
DOCS_GATE_RESULT: ${{ needs.docs-gate.result }}
WORKFLOW_REF: ${{ github.ref }}
run: |
status=pass
message="selected implementation job succeeded"
if [ "$ADMISSION_RESULT" != "success" ]; then
if [ "$EVENT_NAME" = "workflow_dispatch" ] && [ "$WORKFLOW_REF" != "refs/heads/main" ] && [ "$WORKFLOW_REF" != "refs/heads/master" ]; then
status=fail
message="branch/tag dispatch is diagnostic-only; PR qualification requires the Draft to Ready handoff"
elif [ "$ADMISSION_RESULT" != "success" ]; then
status=fail
message="candidate admission result was $ADMISSION_RESULT"
elif [ "$ADMISSION_STATUS" != "admitted" ] && [ "$ADMISSION_STATUS" != "not_applicable" ]; then
Expand Down
3 changes: 3 additions & 0 deletions changelog.d/5394-diagnostic-dispatch-result.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- section: Internal / CI -->
- Branch and tag dispatches of Routed Rust remain diagnostic-only and fail the
required Result instead of supplying PR qualification without PR evidence (#5394).
18 changes: 12 additions & 6 deletions docs/CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,11 @@ labeled / unlabeled (any label):
no Routed Rust Small run; labels never create or refresh the required context
(only `labeled` of `merge-ready` admits the gated non-required lanes)

push to main / workflow_dispatch:
launch under their own authorities, unchanged
push to main / workflow_dispatch on main or master:
launch under their own authorities

workflow_dispatch on another branch or tag:
diagnostic jobs may run; the required Result explicitly fails
```

`windows-ci` continues to opt into `.github/workflows/windows-advisory.yml` only.
Expand All @@ -690,10 +693,13 @@ group is qualified by `github.event_name`, so a second Ready transition replaces
the prior admission attempt while independent main and manual work cannot replace
each other. No run posts a pseudo-result, so a Draft PR with no required check
blocks rather than inheriting stale proof. The result job keeps its static
`Ripr Rust Small Result` name on every run. One gap is not enforced: a
`workflow_dispatch` of `routed-rust.yml` on a PR branch also posts that context
on the branch head, without the `pull_request`-scoped PR-evidence steps.
Do not dispatch on PR branches; #5394 tracks enforcing this.
`Ripr Rust Small Result` name on every run. A manual dispatch on a branch or
tag other than `refs/heads/main` or `refs/heads/master` is diagnostic-only:
its implementation jobs may run, but Result fails explicitly even if they all
pass (#5394). The summary names the Draft to Ready handoff. This preserves
workflow-testing diagnostics without letting a run that skips PR-only evidence
qualify a PR. A skipped Result would report success, so the refusal runs inside
the Result shell; it is not a job-level skip or a renamed required check.

What this means for authors and agents:

Expand Down
2 changes: 2 additions & 0 deletions policy/process_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,5 @@ xtask/examples/contabo_product_proof.rs|Command::new|2|contabo-consumer-qualific
xtask/tests/contabo_result_policy.rs|Command::new|1|contabo-result-policy-tests|#4988 real Bash/jq consumer policy with isolated synthetic imported-context fixtures and discriminating stale-attempt/incomplete-product controls; no network or runner dispatch.
xtask/tests/hard_cut_admission_selftest.rs|Command::new|3|hard-cut-admission-selftest|#5391: the integration test runs the checked-in Python self-test scripts and the real action shell with a stubbed read-only gh in a temp dir (python3, bash, chmod); no production subprocess is introduced.
xtask/tests/hard_cut_admission_selftest.rs|use std::process::Command|1|hard-cut-admission-selftest|#5391: imports Command only for the bounded self-test invocation described above.
xtask/tests/routed_dispatch_result.rs|Command::new|2|routed-dispatch-result|#5394: executes the checked-in Result and admission shells locally with fixture environments; no GitHub dispatch, credential or network operation.
xtask/tests/routed_dispatch_result.rs|use std::process::Command|1|routed-dispatch-result|#5394: imports Command only for the bounded workflow shell controls described above.
2 changes: 1 addition & 1 deletion policy/workflow_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
.github/workflows/publish-extension.yml|20|Release workflow includes marketplace packaging and publishing orchestration.
.github/workflows/python-wheel-qualification.yml|194|Read-only #4490 package rehearsal retains exact native and PEP 440 identities, wheel metadata/RECORD and two executable-integrity negative controls, plus isolated pip/uv Python preview journeys; static adapter and workflow-shape policy remains in Rust xtask and the workflow has no publication authority.
.github/workflows/release-server-binaries.yml|1|Release workflow delegates server archive packaging, manifest generation, and release upload branching to Rust xtask commands.
.github/workflows/routed-rust.yml|63|Routed Rust selects one trusted self-hosted runner or the hosted fallback, preserves normalized result semantics, and delegates implementation proof to the reusable Rust gate workflow.
.github/workflows/routed-rust.yml|66|Routed Rust selects one trusted self-hosted runner or the hosted fallback, preserves normalized result semantics, and delegates implementation proof to the reusable Rust gate workflow; branch/tag dispatch remains diagnostic-only and cannot pass the required Result (#5394).
.github/workflows/rust-corpus.yml|4|Shared Rust corpus lane: one-command build, fetch and smoke steps, then one folded cargo xtask dx-scoreboard gate command.
.github/workflows/rust-gates.yml|31|Reusable Rust gate implementation preserves scratch tempfail fallback, required proof, bounded PR evidence, and failure-only ordinary artifacts.
.github/workflows/scratch-gc.yml|3|Scheduled scratch-GC lane reclaims terminal scratch through the shared ci-scratch-lease action (#3841), then trims sccache, reports disk, and keeps the hard-fail guard on a timer so disk recovery does not depend on PR traffic (#1028).
Expand Down
10 changes: 10 additions & 0 deletions tools/repo-policy/tests/docs_only_routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@ fn routed_result_admitted(
assert!(env.len() >= 20, "actual result env is initialized");
env.extend([
("EVENT_NAME", event),
// Manual/push positives represent the independent main authority;
// diagnostic branch/tag refusal is exercised by routed_dispatch_result.
(
"WORKFLOW_REF",
if event == "pull_request" {
"refs/pull/10/merge"
} else {
"refs/heads/main"
},
),
("DOCS_DETECT_RESULT", detector),
("DOCS_ONLY", docs),
("DOCS_GATE_RESULT", docs_gate),
Expand Down
278 changes: 278 additions & 0 deletions xtask/tests/routed_dispatch_result.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
//! #5394: execute the checked-in Result shell, including a real manual
//! admission producer, without dispatching a workflow or creating a check.

use std::collections::BTreeMap;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use std::sync::atomic::{AtomicUsize, Ordering};

static NEXT: AtomicUsize = AtomicUsize::new(0);

fn root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..")
}

struct Scratch(PathBuf);

impl Scratch {
fn new() -> Result<Self, String> {
let parent = std::env::temp_dir();
fs::create_dir_all(&parent).map_err(|e| e.to_string())?;
let path = parent.join(format!(
"ripr-dispatch-result-{}-{}",
std::process::id(),
NEXT.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir(&path).map_err(|e| e.to_string())?;
Ok(Self(path))
}
}

impl Drop for Scratch {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}

fn workflow() -> Result<String, String> {
fs::read_to_string(root().join(".github/workflows/routed-rust.yml")).map_err(|e| e.to_string())
}

fn result_step(source: &str) -> Result<&str, String> {
let (_, job) = source
.split_once("\n result:\n")
.ok_or("missing actual result job")?;
let (_, step) = job
.split_once(" - name: Summarize routed result\n")
.ok_or("missing actual Result step")?;
Ok(step)
}

fn result_shell(step: &str) -> Result<String, String> {
let (_, body) = step
.split_once(" run: |\n")
.ok_or("missing Result shell")?;
body.lines()
.map(|line| {
if line.is_empty() {
Ok("")
} else {
line.strip_prefix(" ")
.ok_or("unexpected Result shell nesting")
}
})
.collect::<Result<Vec<_>, _>>()
.map(|lines| lines.join("\n"))
.map_err(str::to_string)
}

fn run_result(
source: &str,
event: &str,
reference: &str,
admission: &str,
status: &str,
overrides: &[(&str, &str)],
) -> Result<(bool, String), String> {
let scratch = Scratch::new()?;
let step = result_step(source)?;
let mut env = BTreeMap::new();
// Derive the consumed inputs from the actual step, then give its child
// outcomes a successful fixture. Tests vary authoritative inputs below.
for line in step
.split(" run: |\n")
.next()
.ok_or("missing env")?
.lines()
{
if let Some((name, _)) = line
.strip_prefix(" ")
.and_then(|l| l.split_once(':'))
{
env.insert(name.to_string(), "success".to_string());
}
}
for (name, value) in [
("EVENT_NAME", event),
("WORKFLOW_REF", reference),
("ADMISSION_RESULT", admission),
("ADMISSION_STATUS", status),
("ADMISSION_REASON", "fixture"),
("TARGET", "github"),
("DOCS_ONLY", "false"),
]
.into_iter()
.chain(overrides.iter().copied())
{
env.insert(name.to_string(), value.to_string());
}
let summary = scratch.0.join("summary");
let output = Command::new("bash")
.args(["-e", "-c", &result_shell(step)?])
.env_clear()
.envs(env)
.env("PATH", std::env::var_os("PATH").ok_or("PATH unavailable")?)
.env("GITHUB_STEP_SUMMARY", &summary)
.output()
.map_err(|e| e.to_string())?;
let report =
fs::read_to_string(summary).map_err(|e| format!("missing summary: {e}; {output:?}"))?;
assert!(report.contains("### Ripr Rust Small Result"));
Ok((output.status.success(), report))
}

#[test]
fn branch_dispatch_cannot_qualify_even_when_every_child_succeeds() -> Result<(), String> {
for reference in ["refs/heads/fix/5394", "refs/tags/v0.11.0", "", "main"] {
let (success, report) = run_result(
&workflow()?,
"workflow_dispatch",
reference,
"success",
"not_applicable",
&[],
)?;
assert!(
!success,
"diagnostic dispatch must not qualify: {reference}: {report}"
);
assert!(
report.contains("diagnostic-only"),
"must explain the event refusal: {report}"
);
}
Ok(())
}

#[test]
fn ready_and_main_authorities_keep_real_child_result_checks() -> Result<(), String> {
for (event, reference, status) in [
("pull_request", "refs/pull/10/merge", "admitted"),
("workflow_dispatch", "refs/heads/main", "not_applicable"),
("workflow_dispatch", "refs/heads/master", "not_applicable"),
("push", "refs/heads/main", "not_applicable"),
] {
assert!(run_result(&workflow()?, event, reference, "success", status, &[])?.0);
assert!(
!run_result(
&workflow()?,
event,
reference,
"success",
status,
&[("GITHUB_RESULT", "failure")]
)?
.0
);
}
for (admission, status) in [
("failure", "admitted"),
("success", "refused"),
("success", ""),
] {
assert!(
!run_result(
&workflow()?,
"pull_request",
"refs/pull/10/merge",
admission,
status,
&[]
)?
.0
);
}
assert!(
run_result(
&workflow()?,
"pull_request",
"refs/pull/10/merge",
"success",
"admitted",
&[("DOCS_ONLY", "true")]
)?
.0
);
assert!(
!run_result(
&workflow()?,
"pull_request",
"refs/pull/10/merge",
"success",
"admitted",
&[("DOCS_ONLY", "true"), ("DOCS_GATE_RESULT", "skipped")]
)?
.0
);
Ok(())
}

#[test]
fn manual_admission_producer_does_not_supply_pr_qualification() -> Result<(), String> {
let scratch = Scratch::new()?;
let action = root().join(".github/actions/pr-candidate-admission");
let source = fs::read_to_string(action.join("action.yml")).map_err(|e| e.to_string())?;
let (_, body) = source
.split_once(" run: |\n")
.ok_or("missing action shell")?;
let shell = body
.lines()
.map(|line| line.strip_prefix(" ").unwrap_or(line))
.collect::<Vec<_>>()
.join("\n");
let outputs = scratch.0.join("outputs");
let output = Command::new("bash")
.args(["-e", "-c", &shell])
.env_clear()
.env("PATH", std::env::var_os("PATH").ok_or("PATH unavailable")?)
.env("GITHUB_ACTION_PATH", action)
.env("GITHUB_WORKSPACE", root())
.env("GITHUB_OUTPUT", &outputs)
.env("GITHUB_STEP_SUMMARY", scratch.0.join("summary"))
.env("ADMISSION_MODE", "admit")
.env("ADMISSION_PR_NUMBER", "")
.output()
.map_err(|e| e.to_string())?;
assert!(output.status.success(), "{output:?}");
let outputs = fs::read_to_string(outputs).map_err(|e| e.to_string())?;
let status = outputs
.lines()
.find_map(|line| line.strip_prefix("status="))
.ok_or("no producer status")?;
assert_eq!(status, "not_applicable");
assert!(outputs.contains("cut_reason=cut_non_pull_request_invocation"));
assert!(
!run_result(
&workflow()?,
"workflow_dispatch",
"refs/heads/fix/5394",
"success",
status,
&[]
)?
.0
);
assert!(
run_result(
&workflow()?,
"workflow_dispatch",
"refs/heads/main",
"success",
status,
&[]
)?
.0
);
Ok(())
}

#[test]
fn event_identity_is_wired_from_github_not_candidate_inputs() -> Result<(), String> {
let source = workflow()?;
let step = result_step(&source)?;
assert!(step.contains(" EVENT_NAME: ${{ github.event_name }}\n"));
assert!(step.contains(" WORKFLOW_REF: ${{ github.ref }}\n"));
assert!(!source.contains(" continue-on-error: true"));
Ok(())
}
Loading