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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ validates inline candidates, and submits one grouped PR review when configured.
| `ledger-path` | empty | Optional read-only UB ledger path. |
| `ledger-max-bytes` | `65536` | Maximum ledger context bytes. |
| `fail-on-post-error` | `false` | Fail the action when PR review posting fails. |
| `fail-on-gate` | `auto` | Gate enforcement: `auto`, `true`, or `false`. The action's final `Enforce gate outcome` step fails the check when `review/gate_outcome.json` records a `fail` conclusion and enforcement resolves to `true`; artifacts, the job summary, and PR review posting always complete first. `auto` resolves to `true` for `mode=intelligent-ci` and `false` otherwise. |
| `github-summary` | `true` | Append running summary to job summary. |

## Repo Config Proof Policy
Expand Down Expand Up @@ -444,6 +445,7 @@ required = true
| `post-payload-path` | Exact grouped review payload submitted to GitHub. |
| `post-stdout-path` | GitHub post response body artifact. |
| `post-stderr-path` | GitHub post stderr artifact. |
| `gate-outcome-path` | Deterministic gate verdict `review/gate_outcome.json`. |

## Bootstrap note

Expand Down
67 changes: 67 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ inputs:
description: Fail the action when posting the grouped PR review fails.
default: 'false'
required: false
fail-on-gate:
description: 'Gate enforcement: auto, true, or false. The final Enforce gate outcome step exits non-zero when review/gate_outcome.json records a fail conclusion and this resolves to true; artifacts, the job summary, and PR review posting always complete first. auto resolves to true for mode=intelligent-ci and false otherwise.'
default: auto
required: false
github-summary:
description: Append running-summary.md to GITHUB_STEP_SUMMARY.
default: 'true'
Expand Down Expand Up @@ -232,6 +236,9 @@ outputs:
post-stderr-path:
description: Path to the GitHub review post stderr artifact.
value: ${{ steps.paths.outputs.post-stderr-path }}
gate-outcome-path:
description: Path to the deterministic gate verdict artifact.
value: ${{ steps.paths.outputs.gate-outcome-path }}

runs:
using: composite
Expand Down Expand Up @@ -483,6 +490,9 @@ runs:
esac
fi

# Gate enforcement is deferred to the final "Enforce gate outcome"
# step so a failing gate cannot skip PR review posting; the binary
# itself therefore always runs with --fail-on-gate false here.
"${{ steps.runner.outputs.bin }}" run \
--config "$config_path" \
--profile "${{ inputs.profile }}" \
Expand All @@ -494,6 +504,7 @@ runs:
--mode "${{ inputs.mode }}" \
--run-pass "${{ inputs['run-pass'] }}" \
--model-mode "${{ inputs['model-mode'] }}" \
--fail-on-gate false \
--depth "${{ inputs.depth }}" \
--lanes "${{ inputs.lanes }}" \
--except-lanes "${{ inputs['except-lanes'] }}" \
Expand Down Expand Up @@ -557,3 +568,59 @@ runs:
echo "post-payload-path=${{ inputs.out }}/review/github-review-post-payload.json" >> "$GITHUB_OUTPUT"
echo "post-stdout-path=${{ inputs.out }}/review/post-stdout.json" >> "$GITHUB_OUTPUT"
echo "post-stderr-path=${{ inputs.out }}/review/post-stderr.txt" >> "$GITHUB_OUTPUT"
echo "gate-outcome-path=${{ inputs.out }}/review/gate_outcome.json" >> "$GITHUB_OUTPUT"

- name: Enforce gate outcome
shell: bash
env:
UB_REVIEW_FAIL_ON_GATE: ${{ inputs['fail-on-gate'] }}
UB_REVIEW_MODE: ${{ inputs.mode }}
UB_REVIEW_GATE_OUTCOME_PATH: ${{ inputs.out }}/review/gate_outcome.json
run: |
set -euo pipefail

fail_on_gate="${UB_REVIEW_FAIL_ON_GATE:-auto}"
mode="${UB_REVIEW_MODE:-review-byok}"
gate_path="$UB_REVIEW_GATE_OUTCOME_PATH"

# Mirror the Rust FailOnGate::resolved semantics exactly:
# auto enforces the gate iff mode=intelligent-ci.
case "$fail_on_gate" in
true)
enforce=true
;;
false)
enforce=false
;;
auto)
if [[ "$mode" == "intelligent-ci" ]]; then
enforce=true
else
enforce=false
fi
;;
*)
echo "::error::unknown fail-on-gate '$fail_on_gate'; expected auto, true, or false"
exit 1
;;
esac

if [[ "$enforce" != "true" ]]; then
echo "gate enforcement is off (fail-on-gate=$fail_on_gate, mode=$mode); not enforcing $gate_path"
exit 0
fi

if [[ ! -f "$gate_path" ]]; then
echo "::error::gate enforcement is on but $gate_path is missing"
exit 1
fi

conclusion="$(jq -r '.conclusion // empty' "$gate_path")"
if [[ "$conclusion" != "fail" ]]; then
echo "gate conclusion is '${conclusion:-unknown}' in $gate_path; check stays green"
exit 0
fi

reasons="$(jq -r '[.reasons[]?.id] | join(", ")' "$gate_path")"
echo "::error::ub-review gate failed (blocking reasons: ${reasons:-none}); receipts are in $gate_path"
exit 1
4 changes: 2 additions & 2 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ artifact contracts: [CI_AUDIT_WIZARD.md](CI_AUDIT_WIZARD.md).

Write `review/gate_outcome.json` (`ub-review.gate_outcome.v1`) derived from the
terminal state, required-proof receipts, and tool gate outcomes. Add the
exit-code contract and the `fail-on-gate` action input with a `gate-outcome`
output.
exit-code contract and the `fail-on-gate` action input with a
`gate-outcome-path` output.

Acceptance:

Expand Down
5 changes: 3 additions & 2 deletions docs/adr/0002-single-gate-and-ci-audit-wizard.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ not fail the gate.

Exit-code contract: `ub-review run --mode intelligent-ci` exits non-zero when
the gate conclusion is `fail`. The action exposes `fail-on-gate` (default
`true` for `intelligent-ci`, `false` for `review-byok`) and a `gate-outcome`
output path. Posting failures keep the separate `fail-on-post-error` input;
`true` for `intelligent-ci`, `false` for `review-byok`) and a
`gate-outcome-path` output path. Posting failures keep the separate
`fail-on-post-error` input;
posting trouble is not gate trouble.

`gate_outcome.json` minimum fields:
Expand Down
2 changes: 1 addition & 1 deletion policy/allow.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema_version = 1
schema_version = "1"
tool = "cargo-allow"

# Default source-tree exception ledger. Keep this consolidated until real
Expand Down
46 changes: 46 additions & 0 deletions policy/cargo-allow.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# cargo-allow source-exception ledger (cargo-allow native dialect, schema 0.1).
#
# This file exists so the cargo-allow sensor reads a genuine cargo-allow
# policy instead of `policy/allow.toml`, which is the xtask-owned repo-policy
# ledger in a different dialect that happens to squat cargo-allow's default
# discovery path. See:
# https://github.com/EffortlessMetrics/cargo-allow/issues/1465
#
# The ledger is intentionally empty: workspace lints in Cargo.toml forbid the
# panic family (unwrap/expect/panic/todo/dbg) outright, so there are no
# sanctioned exceptions to record. The binding no-panic gate for this repo is
# the Cargo.toml lint wall plus `cargo xtask policy-check`.
#
# default_mode is `audit` (report-only) because cargo-allow's claim surface is
# wider than this repo's policy: it also counts indexing, string slicing,
# `unreachable!`, `#[expect(...)]` attributes, and every non-Rust file as
# findings that would need ledger entries. Those surfaces are governed by the
# repo-policy ledger (`policy/allow.toml`) and Cargo.toml lints instead, so
# cargo-allow runs as an audit-stage inventory sensor until this repo adopts
# its selector model with genuine entries.

schema_version = "0.1"
policy = "cargo-allow"
owner = "ub-review/core"
status = "advisory"

[workspace]
root = "."
inventory = "git-tracked"
default_mode = "audit"
ignored = [".git/**", "target/**"]
generated = ["target/**", "vendor/**"]

[requirements]
owner_required = true
reason_required = true
classification_required = true
evidence_required = false
expires_or_review_after_required = true
allow_bare_allow_attributes = false
lint_policy_id_required = false
stale_entries_fail = false

[requirements.unsafe]
evidence_required = true
safety_comment_required = false
36 changes: 36 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,31 @@ impl RunMode {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum)]
pub(crate) enum FailOnGate {
Auto,
True,
False,
}

impl FailOnGate {
pub(crate) fn key(self) -> &'static str {
match self {
Self::Auto => "auto",
Self::True => "true",
Self::False => "false",
}
}

pub(crate) fn resolved(self, mode: RunMode) -> bool {
match self {
Self::True => true,
Self::False => false,
Self::Auto => matches!(mode, RunMode::IntelligentCi),
}
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum RunPass {
Auto,
Expand Down Expand Up @@ -363,6 +388,17 @@ pub(crate) struct RunArgs {
/// Model execution mode.
#[arg(long, value_enum, default_value = "auto", env = "UB_REVIEW_MODEL_MODE")]
pub(crate) model_mode: ModelMode,
/// Gate enforcement. When this resolves to true and review/gate_outcome.json
/// records a `fail` conclusion, `run` exits non-zero (exit code 1) after all
/// artifacts are written. `auto` resolves to true for --mode intelligent-ci
/// and false otherwise.
#[arg(
long = "fail-on-gate",
value_enum,
default_value = "auto",
env = "UB_REVIEW_FAIL_ON_GATE"
)]
pub(crate) fail_on_gate: FailOnGate,
#[command(flatten)]
pub(crate) selectors: SelectorArgs,
/// Review depth selector. Nonstandard depths expand to lane/model budgets.
Expand Down
Loading
Loading