cargo-allow 0.1.5

Source-tree exception ledger and policy scanner for Rust repositories.
use crate::{add, diff, doctor, explain, list, migrate, propose, prune, worklist};

pub(crate) struct ArtifactSample {
    pub(crate) name: &'static str,
    pub(crate) schema_name: &'static str,
    pub(crate) json: String,
    pub(crate) expected_command: &'static str,
    pub(crate) expected_top_level_keys: &'static [&'static str],
}

pub(crate) fn command_artifact_samples() -> Vec<ArtifactSample> {
    vec![
        ArtifactSample {
            name: "add",
            schema_name: "add",
            json: add::sample_add_json_for_contract_test(),
            expected_command: "add",
            expected_top_level_keys: &[
                "allow_entry",
                "claim_boundary",
                "command",
                "inventory",
                "options",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "selected_finding",
                "summary",
                "tool",
            ],
        },
        ArtifactSample {
            name: "doctor",
            schema_name: "doctor",
            json: doctor::sample_doctor_json_for_contract_test(),
            expected_command: "doctor",
            expected_top_level_keys: &[
                "claim_boundary",
                "command",
                "config",
                "inventory",
                "root",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "tool",
            ],
        },
        ArtifactSample {
            name: "explain",
            schema_name: "explain",
            json: explain::sample_explain_json_for_contract_test(),
            expected_command: "explain",
            expected_top_level_keys: &[
                "allow_entry",
                "claim_boundary",
                "command",
                "current_findings",
                "evidence_references",
                "inventory",
                "match_outcomes",
                "next",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "summary",
                "tool",
            ],
        },
        ArtifactSample {
            name: "list",
            schema_name: "list",
            json: list::sample_list_json_for_contract_test(),
            expected_command: "list",
            expected_top_level_keys: &[
                "allow_entries",
                "claim_boundary",
                "command",
                "filters",
                "inventory",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "summary",
                "tool",
            ],
        },
        ArtifactSample {
            name: "migrate",
            schema_name: "migrate",
            json: migrate::sample_migrate_json_for_contract_test(),
            expected_command: "migrate",
            expected_top_level_keys: &[
                "claim_boundary",
                "command",
                "evidence_repair_queues",
                "input",
                "inventory",
                "notes",
                "output",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "summary",
                "tool",
            ],
        },
        ArtifactSample {
            name: "propose",
            schema_name: "propose",
            json: propose::sample_propose_json_for_contract_test(),
            expected_command: "propose",
            expected_top_level_keys: &[
                "claim_boundary",
                "command",
                "follow_up_queues",
                "generated_entry_defaults",
                "inventory",
                "options",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "summary",
                "tool",
            ],
        },
        ArtifactSample {
            name: "prune",
            schema_name: "prune",
            json: prune::sample_prune_json_for_contract_test(),
            expected_command: "prune",
            expected_top_level_keys: &[
                "claim_boundary",
                "command",
                "inventory",
                "mode",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "stale_entries",
                "summary",
                "tool",
            ],
        },
        ArtifactSample {
            name: "worklist",
            schema_name: "worklist",
            json: worklist::sample_worklist_json_for_contract_test(),
            expected_command: "worklist",
            expected_top_level_keys: &[
                "claim_boundary",
                "command",
                "filters",
                "inventory",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "summary",
                "tool",
                "work_items",
            ],
        },
    ]
}

pub(crate) fn core_artifact_samples() -> Vec<ArtifactSample> {
    let audit_report_json = allow_report::render_json_with_context(
        "audit",
        &[],
        &[],
        false,
        allow_report::ReportContext::source_syntax(
            "filesystem_fallback",
            Some("fixtures/source-snapshot"),
            Some(7),
            None,
        ),
    );
    let check_report_json = allow_report::render_json_with_context(
        "check",
        &[],
        &[],
        false,
        allow_report::ReportContext::source_syntax(
            "git_tracked",
            Some("H:/Code/Rust/cargo-allow"),
            Some(42),
            None,
        ),
    );
    let receipt_json = allow_report::render_receipt_with_context(
        "check",
        &[],
        false,
        allow_report::ReportContext::source_syntax(
            "git_tracked",
            Some("H:/Code/Rust/cargo-allow"),
            Some(42),
            None,
        ),
    );
    let diff_base_json = allow_report::render_json_with_context(
        "diff",
        &[],
        &[],
        false,
        allow_report::ReportContext::source_syntax(
            "git_tracked",
            Some("H:/Code/Rust/cargo-allow"),
            Some(8),
            None,
        ),
    );
    let diff_json = diff::render_diff_json_with_posture(diff_base_json, 0, &[], &[], &[]);
    vec![
        ArtifactSample {
            name: "audit_report",
            schema_name: "report",
            json: audit_report_json,
            expected_command: "audit",
            expected_top_level_keys: &[
                "claim_boundary",
                "command",
                "failed",
                "findings",
                "inventory",
                "outcomes",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "status",
                "summary",
                "tool",
                "trend",
            ],
        },
        ArtifactSample {
            name: "check_report",
            schema_name: "report",
            json: check_report_json,
            expected_command: "check",
            expected_top_level_keys: &[
                "claim_boundary",
                "command",
                "failed",
                "findings",
                "inventory",
                "outcomes",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "status",
                "summary",
                "tool",
                "trend",
            ],
        },
        ArtifactSample {
            name: "receipt",
            schema_name: "receipt",
            json: receipt_json,
            expected_command: "check",
            expected_top_level_keys: &[
                "claim_boundary",
                "command",
                "counts",
                "failed",
                "inventory",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "status",
                "tool",
            ],
        },
        ArtifactSample {
            name: "diff",
            schema_name: "report",
            json: diff_json,
            expected_command: "diff",
            expected_top_level_keys: &[
                "claim_boundary",
                "command",
                "diff",
                "failed",
                "findings",
                "inventory",
                "outcomes",
                "scanner_limitations",
                "schema_id",
                "schema_version",
                "status",
                "summary",
                "tool",
                "trend",
            ],
        },
    ]
}