assay-cli 6.1.2

Policy-as-code gate for MCP agent tool calls, with verifiable evidence and Linux kernel enforcement.
use assert_cmd::Command;
use std::fs;
use tempfile::tempdir;

#[test]
#[allow(deprecated)]
fn contract_import_rejects_boolean_jsonrpc_id() {
    let dir = tempdir().expect("tempdir");
    let input = dir.path().join("bool-id.jsonl");
    fs::write(
        &input,
        r#"
{"timestamp_ms":1000,"jsonrpc":"2.0","id":true,"method":"tools/call","params":{"name":"BoolId","arguments":{"x":1}}}
"#,
    )
    .expect("write input");

    let assert = Command::cargo_bin("assay")
        .expect("assay binary")
        .arg("import")
        .arg(&input)
        .arg("--format")
        .arg("jsonrpc")
        .assert()
        .failure();

    let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
    assert!(
        stderr.contains("failed to parse MCP transcript"),
        "missing parse context: {stderr}"
    );
    assert!(
        stderr.contains("must not be a boolean"),
        "missing boolean-id diagnostic: {stderr}"
    );
}

#[test]
#[allow(deprecated)]
fn contract_import_rejects_duplicate_tool_call_request_ids() {
    let dir = tempdir().expect("tempdir");
    let input = dir.path().join("duplicate-id.jsonl");
    fs::write(
        &input,
        r#"
{"timestamp_ms":1000,"jsonrpc":"2.0","id":"dup-1","method":"tools/call","params":{"name":"First","arguments":{"x":1}}}
{"timestamp_ms":1001,"jsonrpc":"2.0","id":"dup-1","method":"tools/call","params":{"name":"Second","arguments":{"x":2}}}
"#,
    )
    .expect("write input");

    let assert = Command::cargo_bin("assay")
        .expect("assay binary")
        .arg("import")
        .arg(&input)
        .arg("--format")
        .arg("jsonrpc")
        .assert()
        .failure();

    let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
    // The semantic phrase only. The old message named the offending id, which is input-chosen data
    // the parser no longer echoes, and the full diagnostic also carries a source line that moves
    // whenever a fixture gains a line. Pinning either would make this test fail on changes that are
    // not about the refusal.
    assert!(
        stderr.contains("two outstanding JSON-RPC requests share an id"),
        "missing outstanding-id diagnostic: {stderr}"
    );
    assert!(
        !stderr.contains("dup-1"),
        "the refusal must not echo the id: {stderr}"
    );
}