//! `koala-core workflow size` table-rendering contract.

use koala_workflow::{classify, render_size_report, DiffSummary, Size, Thresholds};

fn small_summary() -> DiffSummary {
    DiffSummary {
        files_changed: 1,
        loc_changed: 5,
        crates_touched: vec!["koala-cli".into()],
        touches_architecture: false,
        touches_public_api: false,
        all_tests: false,
    }
}

fn architectural_summary() -> DiffSummary {
    DiffSummary {
        files_changed: 1,
        loc_changed: 3,
        crates_touched: vec![],
        touches_architecture: true,
        touches_public_api: false,
        all_tests: false,
    }
}

#[test]
fn cli_emits_size_and_gate_table() {
    let s = small_summary();
    let size = classify(&s, &Thresholds::default());
    let out = render_size_report(&s, size);
    assert!(out.starts_with("PR size: small"), "got:\n{out}");
    assert!(out.contains("files changed:      1"), "got:\n{out}");
    assert!(out.contains("LOC changed:        5"), "got:\n{out}");
    assert!(out.contains("crates touched:     koala-cli"), "got:\n{out}");
    assert!(out.contains("Required gates (small):"), "got:\n{out}");
}

#[test]
fn architectural_lists_adr_gate() {
    let s = architectural_summary();
    let out = render_size_report(&s, Size::Architectural);
    assert!(out.contains("PR size: architectural"));
    assert!(
        out.contains("koala.adr"),
        "expected ADR gate in architectural table:\n{out}"
    );
    assert!(
        out.contains("koala.feature-sync"),
        "expected feature-sync gate in architectural table:\n{out}"
    );
}

#[test]
fn small_omits_artifact_gate() {
    let s = small_summary();
    let out = render_size_report(&s, Size::Small);
    assert!(
        !out.contains("artifact"),
        "small size should not require reviewer artifact:\n{out}"
    );
}
