kiromi-ai-cli 0.2.1

Operator and developer CLI for the kiromi-ai-memory store: append, search, snapshot, regenerate, migrate-scheme, gc, audit-tail.
// SPDX-License-Identifier: Apache-2.0 OR MIT
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic, missing_docs)]

mod common;

use assert_cmd::Command;
use common::CliWorkspace;

#[test]
fn init_writes_schema_meta() {
    let ws = CliWorkspace::new();
    let out = ws.init();
    assert!(out.status.success(), "init failed: {out:?}");
    assert!(ws.path().join("metadata.db").exists());
}

#[test]
fn init_is_idempotent() {
    let ws = CliWorkspace::new();
    assert!(ws.init().status.success());
    assert!(ws.init().status.success());
}

/// Pin the post-Plan-8 semantics: with no embedder configured, `init`
/// succeeds and writes the caller-provided sentinel into `schema_meta`.
/// Mirrors the `cargo install kiromi-ai-cli` (no `--features embed-onnx`)
/// onboarding path.
#[test]
fn init_with_no_embedder_succeeds_and_uses_caller_provided_sentinel() {
    let ws = CliWorkspace::new();
    let mut c = Command::cargo_bin("kiromi-ai").expect("bin");
    c.env("KIROMI_AI_STORAGE", ws.store_uri())
        .env("KIROMI_AI_METADATA", ws.meta_uri())
        .env("KIROMI_AI_TENANT", "test")
        .env(
            "KIROMI_AI_SCHEME",
            "user={user}/year={year}/month={month}/topic={topic}",
        )
        // Note: do NOT set KIROMI_AI_EMBEDDER_FAMILY. Caller-provided mode.
        .arg("--no-embedder")
        .arg("init");
    let out = c.output().expect("init");
    assert!(
        out.status.success(),
        "init without embedder should succeed: {out:?}"
    );
    assert!(ws.path().join("metadata.db").exists());
}

/// Pin the new error path: when the binary was built without
/// `--features embed-onnx`, asking for `--embedder-family onnx` should
/// fail with a helpful hint pointing at the feature flag — never the
/// generic "family not registered" message.
#[cfg(not(feature = "embed-onnx"))]
#[test]
fn init_with_onnx_family_errors_when_feature_missing() {
    let ws = CliWorkspace::new();
    let mut c = Command::cargo_bin("kiromi-ai").expect("bin");
    c.env("KIROMI_AI_STORAGE", ws.store_uri())
        .env("KIROMI_AI_METADATA", ws.meta_uri())
        .env("KIROMI_AI_TENANT", "test")
        .env(
            "KIROMI_AI_SCHEME",
            "user={user}/year={year}/month={month}/topic={topic}",
        )
        .env("KIROMI_AI_EMBEDDER_FAMILY", "onnx")
        .env("KIROMI_AI_EMBEDDER_CONFIG", "null")
        .arg("init");
    let out = c.output().expect("init");
    assert!(!out.status.success(), "expected failure: {out:?}");
    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(
        stderr.contains("embed-onnx"),
        "expected hint about embed-onnx feature in stderr, got: {stderr}"
    );
}