use assert_cmd::Command;
use predicates::prelude::*;
use tempfile::TempDir;
fn quorum() -> Command {
Command::cargo_bin("quorum").expect("quorum binary built")
}
fn init_repo() -> TempDir {
let td = TempDir::new().unwrap();
git2::Repository::init(td.path()).unwrap();
td
}
#[test]
fn unknown_hook_mode_exits_2_with_clear_error() {
let td = init_repo();
quorum()
.current_dir(td.path())
.args(["review", "--hook-mode=pre-rebase"])
.assert()
.failure()
.code(predicate::eq(2))
.stderr(predicate::str::contains("unknown --hook-mode"));
}
#[test]
fn pre_push_with_no_stdin_tuples_exits_0_with_note() {
let td = init_repo();
quorum()
.current_dir(td.path())
.args(["review", "--hook-mode=pre-push"])
.write_stdin("")
.assert()
.success()
.stderr(predicate::str::contains(
"pre-push received no ref tuples on stdin",
));
}
#[test]
fn pre_push_with_delete_tuple_only_exits_0_with_d4_skip_note() {
let td = init_repo();
let stdin = format!(
"(delete) {zeros} refs/heads/feature/x abc1234567890abcdef1234567890abcdef123456\n",
zeros = "0".repeat(40)
);
quorum()
.current_dir(td.path())
.args(["review", "--hook-mode=pre-push"])
.write_stdin(stdin)
.assert()
.success()
.stderr(predicate::str::contains("branch deletion detected"));
}
#[test]
fn pre_push_with_tag_tuple_only_exits_0_with_d5_skip_note() {
let td = init_repo();
let stdin = format!(
"refs/tags/v1.0 abc1234567890abcdef1234567890abcdef123456 refs/tags/v1.0 {zeros}\n",
zeros = "0".repeat(40)
);
quorum()
.current_dir(td.path())
.args(["review", "--hook-mode=pre-push"])
.write_stdin(stdin)
.assert()
.success()
.stderr(predicate::str::contains("tag push detected"))
.stderr(predicate::str::contains("refs/tags/*"));
}
#[test]
fn pre_push_mixed_tag_and_delete_tuples_both_skipped() {
let td = init_repo();
let stdin = format!(
"(delete) {zeros} refs/heads/old-feature abc1234567890abcdef1234567890abcdef123456\n\
refs/tags/v0.1 abc1234567890abcdef1234567890abcdef123456 refs/tags/v0.1 {zeros}\n",
zeros = "0".repeat(40)
);
quorum()
.current_dir(td.path())
.args(["review", "--hook-mode=pre-push"])
.write_stdin(stdin)
.assert()
.success()
.stderr(predicate::str::contains("branch deletion detected"))
.stderr(predicate::str::contains("tag push detected"));
}
#[test]
fn pre_commit_outside_a_git_repo_errors_cleanly() {
let td = TempDir::new().unwrap(); quorum()
.current_dir(td.path())
.args(["review", "--hook-mode=pre-commit"])
.assert()
.failure()
.code(predicate::eq(2));
}
fn linked_repo(bundle_section: &str) -> TempDir {
let td = init_repo();
let qd = td.path().join(".quorum");
std::fs::create_dir_all(&qd).unwrap();
std::fs::write(
qd.join("config.toml"),
format!("project_id = \"p_1\"\nbase_url = \"https://app.lippa.ai\"\n{bundle_section}"),
)
.unwrap();
td
}
#[test]
fn ac194a_oversized_total_budget_warns_about_credit_spend() {
let td = linked_repo("[bundle]\ntotal_budget_kb = 400\n");
quorum()
.current_dir(td.path())
.env("QUORUM_LIPPA_SESSION", "fake-cookie-for-warning-path")
.args(["review"])
.assert()
.stderr(
predicate::str::contains("total_budget_kb = 400")
.and(predicate::str::contains("credits"))
.and(predicate::str::contains("failed")),
);
}
#[test]
fn ac194a_default_total_budget_is_silent() {
for section in ["", "[bundle]\ntotal_budget_kb = 200\n"] {
let td = linked_repo(section);
quorum()
.current_dir(td.path())
.env("QUORUM_LIPPA_SESSION", "fake-cookie-for-warning-path")
.args(["review"])
.assert()
.stderr(predicate::str::contains("total_budget_kb").not());
}
}
#[test]
fn ac194a_warning_suppressed_under_hook_mode() {
let td = linked_repo("[bundle]\ntotal_budget_kb = 400\n");
quorum()
.current_dir(td.path())
.env("QUORUM_LIPPA_SESSION", "fake-cookie-for-warning-path")
.args(["review", "--hook-mode=pre-commit"])
.assert()
.stderr(predicate::str::contains("total_budget_kb").not());
}
#[test]
fn ac192_out_of_range_bundle_config_exits_2() {
let td = linked_repo("[bundle]\ntotal_budget_kb = 5000\n");
quorum()
.current_dir(td.path())
.env("QUORUM_LIPPA_SESSION", "fake-cookie-for-warning-path")
.args(["review"])
.assert()
.failure()
.code(predicate::eq(2))
.stderr(
predicate::str::contains("total_budget_kb").and(predicate::str::contains("100..=1024")),
);
}