instinct-cli 0.3.6

Local memory for AI coding agents: an MCP server and CLI that gives Claude Code, Codex, Cursor and any MCP client the one lesson that fits. Lessons that keep failing go quiet.
//! `hit --check` is user-bank only: a team lesson is refused with a clear message and nothing is recorded.
use std::path::{Path, PathBuf};
use std::process::{Command, Output};

fn run(dir: &Path, home: &Path, args: &[&str]) -> Output {
    Command::new(env!("CARGO_BIN_EXE_instinct"))
        .current_dir(dir)
        .args(args)
        .env("HOME", home)
        .env("INSTINCT_STORE", home.join("bank"))
        .env("INSTINCT_STARTER", "0")
        .env_remove("INSTINCT_TEAM")
        .output()
        .unwrap()
}

fn text(o: &Output) -> String {
    format!("{}{}", String::from_utf8_lossy(&o.stdout), String::from_utf8_lossy(&o.stderr))
}

#[test]
fn a_checked_hit_on_a_team_lesson_is_refused_and_records_nothing() {
    let base: PathBuf = Path::new(env!("CARGO_TARGET_TMPDIR")).join(format!("check-team-{}", std::process::id()));
    let _ = std::fs::remove_dir_all(&base);
    let repo = base.join("repo");
    let home = base.join("home");
    let root = base.join("root");
    for d in [&repo, &home, &root] {
        std::fs::create_dir_all(d).unwrap();
    }
    std::fs::write(root.join("release.bin"), b"x").unwrap();

    let g = Command::new("git").current_dir(&repo).args(["init", "-q"]).output().unwrap();
    assert!(g.status.success());
    let o = run(&repo, &home, &["team", "init"]);
    assert!(o.status.success(), "{}", text(&o));
    let o = run(
        &repo,
        &home,
        &[
            "bank", "--team", "--title", "Ship only release", "--when", "Packaging the release",
            "--found", "Stray files get shipped", "--how", "Check the inventory", "--evidence", "seen twice",
        ],
    );
    assert!(o.status.success(), "{}", text(&o));
    let t = text(&o);
    let id = t.split_whitespace().nth(1).unwrap().to_string();
    let team_file = repo.join(".instinct").join("lessons.jsonl");
    let before = std::fs::read(&team_file).unwrap();

    let o = run(
        &repo,
        &home,
        &["hit", &id, "--check", "--root", root.to_str().unwrap(), "--trusted-staging", "--outcome-id", "k1", "--note", "it worked"],
    );
    assert_eq!(o.status.code(), Some(2), "{}", text(&o));
    assert!(text(&o).contains("does not support team lessons"), "{}", text(&o));
    assert!(text(&o).contains("nothing recorded"), "{}", text(&o));
    assert_eq!(std::fs::read(&team_file).unwrap(), before, "the project bank must be unchanged");
    assert!(!home.join("bank").exists() || !std::fs::read_to_string(home.join("bank")).unwrap_or_default().contains("\"hit\""));

    // the plain hit on the same team lesson still works and lands in the project bank
    let o = run(&repo, &home, &["hit", &id, "--note", "ok"]);
    assert!(o.status.success(), "{}", text(&o));
    assert_ne!(std::fs::read(&team_file).unwrap(), before);
    let _ = std::fs::remove_dir_all(&base);
}