Skip to content
Closed
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
145 changes: 145 additions & 0 deletions .github/workflows/diagnose-2384-required-gates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Diagnose #2384 required gates

on:
pull_request:
branches:
- main

permissions:
contents: read

jobs:
diagnose:
if: github.event.pull_request.head.ref == 'debug/2384-required-gates'
runs-on: ubuntu-24.04
timeout-minutes: 90
env:
CARGO_TERM_COLOR: always
steps:
- name: Check out the exact merge tree plus diagnostic workflow
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803
with:
fetch-depth: 0
persist-credentials: false
- name: Install Rust 1.95.0
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
with:
toolchain: 1.95.0
- name: Reuse Rust build cache
uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32
with:
shared-key: diagnose-2384-required-gates
- name: cargo fmt --check
id: fmt
continue-on-error: true
shell: bash
run: set -o pipefail; cargo fmt --check 2>&1 | tee 01-fmt.log
- name: cargo check --workspace --all-targets
id: check
continue-on-error: true
shell: bash
run: set -o pipefail; cargo check --workspace --all-targets 2>&1 | tee 02-check.log
- name: cargo clippy --workspace --all-targets -- -D warnings
id: clippy
continue-on-error: true
shell: bash
run: set -o pipefail; cargo clippy --workspace --all-targets -- -D warnings 2>&1 | tee 03-clippy.log
- name: cargo test --workspace
id: test
continue-on-error: true
shell: bash
run: set -o pipefail; cargo test --workspace 2>&1 | tee 04-test.log
- name: cargo xtask precommit
id: precommit
continue-on-error: true
shell: bash
run: set -o pipefail; cargo xtask precommit 2>&1 | tee 05-precommit.log
- name: cargo xtask check-evidence-promotion-honesty
id: evidence
continue-on-error: true
shell: bash
run: set -o pipefail; cargo xtask check-evidence-promotion-honesty 2>&1 | tee 06-evidence.log
- name: cargo xtask check-dependencies
id: dependencies
continue-on-error: true
shell: bash
run: set -o pipefail; cargo xtask check-dependencies 2>&1 | tee 07-dependencies.log
- name: cargo xtask check-process-policy
id: process
continue-on-error: true
shell: bash
run: set -o pipefail; cargo xtask check-process-policy 2>&1 | tee 08-process.log
- name: cargo xtask check-network-policy
id: network
continue-on-error: true
shell: bash
run: set -o pipefail; cargo xtask check-network-policy 2>&1 | tee 09-network.log
- name: cargo xtask goldens check
id: goldens
continue-on-error: true
shell: bash
run: set -o pipefail; cargo xtask goldens check 2>&1 | tee 10-goldens.log
- name: cargo xtask fixtures
id: fixtures
continue-on-error: true
shell: bash
run: set -o pipefail; cargo xtask fixtures 2>&1 | tee 11-fixtures.log
- name: Write outcome matrix
if: always()
shell: bash
env:
FMT: ${{ steps.fmt.outcome }}
CHECK: ${{ steps.check.outcome }}
CLIPPY: ${{ steps.clippy.outcome }}
TEST: ${{ steps.test.outcome }}
PRECOMMIT: ${{ steps.precommit.outcome }}
EVIDENCE: ${{ steps.evidence.outcome }}
DEPENDENCIES: ${{ steps.dependencies.outcome }}
PROCESS: ${{ steps.process.outcome }}
NETWORK: ${{ steps.network.outcome }}
GOLDENS: ${{ steps.goldens.outcome }}
FIXTURES: ${{ steps.fixtures.outcome }}
run: |
{
printf 'fmt=%s\n' "$FMT"
printf 'check=%s\n' "$CHECK"
printf 'clippy=%s\n' "$CLIPPY"
printf 'test=%s\n' "$TEST"
printf 'precommit=%s\n' "$PRECOMMIT"
printf 'evidence=%s\n' "$EVIDENCE"
printf 'dependencies=%s\n' "$DEPENDENCIES"
printf 'process=%s\n' "$PROCESS"
printf 'network=%s\n' "$NETWORK"
printf 'goldens=%s\n' "$GOLDENS"
printf 'fixtures=%s\n' "$FIXTURES"
} | tee outcome-matrix.txt
- name: Upload diagnostic matrix
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: diagnose-2384-required-gates-${{ github.run_id }}
path: |
*.log
outcome-matrix.txt
if-no-files-found: error
retention-days: 1
- name: Fail when any required command failed
if: always()
shell: bash
env:
FMT: ${{ steps.fmt.outcome }}
CHECK: ${{ steps.check.outcome }}
CLIPPY: ${{ steps.clippy.outcome }}
TEST: ${{ steps.test.outcome }}
PRECOMMIT: ${{ steps.precommit.outcome }}
EVIDENCE: ${{ steps.evidence.outcome }}
DEPENDENCIES: ${{ steps.dependencies.outcome }}
PROCESS: ${{ steps.process.outcome }}
NETWORK: ${{ steps.network.outcome }}
GOLDENS: ${{ steps.goldens.outcome }}
FIXTURES: ${{ steps.fixtures.outcome }}
run: |
for outcome in "$FMT" "$CHECK" "$CLIPPY" "$TEST" "$PRECOMMIT" "$EVIDENCE" "$DEPENDENCIES" "$PROCESS" "$NETWORK" "$GOLDENS" "$FIXTURES"
do
test "$outcome" = success || exit 1
done
146 changes: 142 additions & 4 deletions crates/ripr/tests/cli_smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,69 @@ fn run_git(root: &Path, args: &[&str]) -> Result<(), String> {
))
}

fn is_concrete_commit_id(value: &str) -> bool {
value.len() == 40 && value.bytes().all(|byte| byte.is_ascii_hexdigit())
}

fn bounded_command_text(bytes: &[u8]) -> String {
String::from_utf8_lossy(bytes).chars().take(512).collect()
}

fn select_fixture_repository_head(
git_succeeded: bool,
stdout: &[u8],
stderr: &[u8],
actions_fallback: Option<&str>,
) -> Result<String, String> {
let candidate = String::from_utf8_lossy(stdout).trim().to_string();
if git_succeeded {
if is_concrete_commit_id(&candidate) {
return Ok(candidate.to_ascii_lowercase());
}
return Err(format!(
"git rev-parse --verify HEAD^{{commit}} returned non-concrete repository HEAD `{candidate}`"
));
}

if let Some(fallback) = actions_fallback {
if is_concrete_commit_id(fallback) {
return Ok(fallback.to_ascii_lowercase());
}
}

Err(format!(
"git rev-parse --verify HEAD^{{commit}} failed; stdout: {}; stderr: {}",
bounded_command_text(stdout),
bounded_command_text(stderr)
))
}

fn concrete_fixture_repository_head(root: &Path) -> Result<String, Box<dyn std::error::Error>> {
let output = run_command(
"git",
Some(root),
&["rev-parse", "--verify", "HEAD^{commit}"],
)?;
let root_is_workspace = root
.canonicalize()
.ok()
.zip(workspace_root().canonicalize().ok())
.is_some_and(|(root, workspace)| root == workspace);
let actions_fallback =
if root_is_workspace && std::env::var("GITHUB_ACTIONS").ok().as_deref() == Some("true") {
std::env::var("GITHUB_SHA").ok()
} else {
None
};
select_fixture_repository_head(
output.status.success(),
&output.stdout,
&output.stderr,
actions_fallback.as_deref(),
)
.map_err(Into::into)
}

fn workspace_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
Expand Down Expand Up @@ -110,8 +173,7 @@ fn write_bound_repo_exposure_fixture(
path: &Path,
seam_json: &str,
) -> Result<(), Box<dyn std::error::Error>> {
let head = run_command("git", Some(root), &["rev-parse", "HEAD"])?;
let head = String::from_utf8(head.stdout)?.trim().to_string();
let head = concrete_fixture_repository_head(root)?;
let root_identity = root.canonicalize()?.to_string_lossy().replace('\\', "/");
let placeholder = "sha256:0000000000000000000000000000000000000000000000000000000000000000";
let raw = format!(
Expand Down Expand Up @@ -227,8 +289,7 @@ fn bind_repo_exposure_fixture_with_worktree(
let mut value: serde_json::Value = serde_json::from_str(&std::fs::read_to_string(source)?)?;
value["schema_version"] = serde_json::Value::String("0.3".to_string());
value["run_status"] = serde_json::Value::String("complete".to_string());
let head = run_command("git", Some(root), &["rev-parse", "HEAD"])?;
let head = String::from_utf8(head.stdout)?.trim().to_string();
let head = concrete_fixture_repository_head(root)?;
let root_identity = root.canonicalize()?.to_string_lossy().replace('\\', "/");
let placeholder = serde_json::Value::String(
"sha256:0000000000000000000000000000000000000000000000000000000000000000".to_string(),
Expand Down Expand Up @@ -341,6 +402,83 @@ fn agent_brief_sample_workspace(
Ok((root, diff))
}

#[test]
fn concrete_fixture_repository_head_matches_a_committed_fixture()
-> Result<(), Box<dyn std::error::Error>> {
let root = unique_temp_workspace("concrete-head");
std::fs::create_dir_all(&root)?;
init_git_fixture_repo(&root)?;
let actual = concrete_fixture_repository_head(&root)?;
let expected = run_command(
"git",
Some(&root),
&["rev-parse", "--verify", "HEAD^{commit}"],
)?;
if !expected.status.success() {
return Err(format!(
"fixture rev-parse failed: {}",
bounded_command_text(&expected.stderr)
)
.into());
}
let expected = String::from_utf8(expected.stdout)?.trim().to_string();
std::fs::remove_dir_all(&root)?;
if actual != expected {
return Err(format!("fixture HEAD mismatch: actual={actual} expected={expected}").into());
}
Ok(())
}

#[test]
fn fixture_repository_head_rejects_unresolved_head_and_malformed_actions_fallback()
-> Result<(), String> {
let result = select_fixture_repository_head(
false,
b"HEAD\n",
b"fatal: ambiguous argument 'HEAD'",
Some("not-a-commit"),
);
let Err(error) = result else {
return Err("unresolved HEAD unexpectedly became fixture authority".to_string());
};
if !error.contains("stdout: HEAD") || !error.contains("fatal: ambiguous argument") {
return Err(format!("fixture HEAD error lost command context: {error}"));
}
Ok(())
}

#[test]
fn fixture_repository_head_accepts_valid_actions_checkout_fallback_after_git_failure()
-> Result<(), String> {
let fallback = "0123456789abcdef0123456789abcdef01234567";
let actual = select_fixture_repository_head(
false,
b"HEAD\n",
b"fatal: ambiguous argument 'HEAD'",
Some(fallback),
)?;
if actual != fallback {
return Err(format!(
"valid Actions checkout fallback changed: actual={actual} expected={fallback}"
));
}
Ok(())
}

#[test]
fn fixture_repository_head_does_not_replace_malformed_success_output_with_fallback()
-> Result<(), String> {
let fallback = "0123456789abcdef0123456789abcdef01234567";
let result = select_fixture_repository_head(true, b"HEAD\n", b"", Some(fallback));
let Err(error) = result else {
return Err("successful but symbolic git output used the Actions fallback".to_string());
};
if !error.contains("non-concrete repository HEAD `HEAD`") {
return Err(format!("unexpected non-concrete HEAD error: {error}"));
}
Ok(())
}

#[test]
fn version_runs() {
let output = run_ripr(&["--version"]);
Expand Down
Loading