Files
kebab/crates/kebab-cli/tests/cli_schema.rs
altair823 7c85de065a chore: workspace-wide cleanup — clippy::pedantic baseline + auto-fix
cut PR v0.18.0 전 마지막 정리. 사용자 요청: "전체 코드베이스를 깔끔하고 알아보기 쉽게".

## Workspace lints

- `Cargo.toml` 의 `[workspace.lints.clippy]` 에 `pedantic = "warn"` (priority -1) + 의도적 allow-list 추가:
  - cast_possible_truncation / cast_possible_wrap / cast_sign_loss / cast_precision_loss — ONNX i64 / hash modular reduction 등 의도적 truncation.
  - doc_markdown / missing_errors_doc / missing_panics_doc — cosmetic doc style.
  - too_many_lines / module_name_repetitions / must_use_candidate / needless_pass_by_value / manual_let_else / items_after_statements / similar_names — informational only.
  - format_collect / match_wildcard_for_single_variants / trivially_copy_pass_by_ref / unnecessary_wraps — intentional patterns (exhaustive match, future Result variants 등).
  - default_trait_access — `Foo::default()` 가 idiomatic.
  - float_cmp — NLI / RRF score 의 explicit threshold 비교 의도.
  - struct_excessive_bools / case_sensitive_file_extension_comparisons / naive_bytecount / ignore_without_reason — domain-specific 의도.
  - format_push_string / return_self_not_must_use / match_same_arms — builder / wire-label / hot-path 패턴 보존.
  - needless_continue / used_underscore_binding / nonminimal_bool / unreadable_literal / many_single_char_names / doc_link_with_quotes / assigning_clones / collapsible_str_replace / trivial_regex / elidable_lifetime_names / range_plus_one / explicit_iter_loop / implicit_hasher / ref_option — remaining low-value style.
- 각 24 crate `Cargo.toml` 에 `[lints] workspace = true` 추가.

## Auto-fix

`cargo clippy --workspace --all-targets --fix` 적용 — 128 files changed, 552 insertions / 472 deletions. 주로:
- uninlined_format_args (~18): `format!("{}", x)` → `format!("{x}")`.
- redundant_closure_for_method_calls (~33): `.map(|x| x.foo())` → `.map(T::foo)`.
- 그 외 mechanical refactor.

## 검증

- `cargo clippy --workspace --all-targets -j 1 -- -D warnings` clean (pedantic + 모든 lint group).
- `cargo test --workspace --no-fail-fast -j 1` — **1293 tests pass + 1 pre-existing flaky fail** (`kebab-mcp::tools_call_ask_multi_hop::ask_tool_routes_multi_hop_true_to_decompose_first`, HOTFIX candidate, cleanup 무관). 회귀 0.

Wire 영향: 없음.
Behavior 영향: 없음 (mechanical refactor only).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 03:01:58 +00:00

134 lines
4.0 KiB
Rust

//! Integration: spawn the kebab binary and parse `kebab schema [--json]`.
//!
//! Each test builds an isolated TempDir-rooted XDG layout, runs
//! `kebab ingest` over an empty workspace (which creates and migrates
//! kebab.sqlite), then exercises `kebab schema` in JSON and text modes.
//! Using an empty workspace avoids the embedding model dependency while
//! still seeding the DB so `open_existing` inside schema_with_config
//! succeeds (a NotIndexed error fires when the DB file is absent).
use std::process::Command;
fn kebab_bin() -> std::path::PathBuf {
let manifest = env!("CARGO_MANIFEST_DIR");
std::path::PathBuf::from(manifest)
.parent()
.unwrap()
.parent()
.unwrap()
.join("target/debug/kebab")
}
fn xdg_envs(tmp: &std::path::Path) -> [(&'static str, std::path::PathBuf); 4] {
[
("XDG_CONFIG_HOME", tmp.join("cfg")),
("XDG_DATA_HOME", tmp.join("data")),
("XDG_CACHE_HOME", tmp.join("cache")),
("XDG_STATE_HOME", tmp.join("state")),
]
}
/// Seed kebab.sqlite by running `kebab ingest` over an empty workspace dir.
/// This is the minimum required for `kebab schema` to succeed: the store
/// uses `open_existing`, which errors when the DB file is absent.
fn seed_db(tmp: &tempfile::TempDir) {
let ws = tmp.path().join("ws");
std::fs::create_dir_all(&ws).unwrap();
let mut cmd = Command::new(kebab_bin());
cmd.args(["ingest", "--root", ws.to_str().unwrap(), "--summary-only"]);
for (k, v) in xdg_envs(tmp.path()) {
cmd.env(k, v);
}
let out = cmd.output().unwrap();
assert!(
out.status.success(),
"seed ingest failed: {}",
String::from_utf8_lossy(&out.stderr)
);
}
#[test]
fn cli_schema_json_emits_schema_v1() {
let tmp = tempfile::tempdir().unwrap();
seed_db(&tmp);
let mut cmd = Command::new(kebab_bin());
cmd.args(["--json", "schema"]);
for (k, v) in xdg_envs(tmp.path()) {
cmd.env(k, v);
}
let out = cmd.output().unwrap();
assert!(
out.status.success(),
"kebab --json schema failed: {}",
String::from_utf8_lossy(&out.stderr)
);
let stdout = String::from_utf8(out.stdout).unwrap();
let v: serde_json::Value = serde_json::from_str(&stdout).expect("stdout must be valid JSON");
assert_eq!(
v.get("schema_version").and_then(|s| s.as_str()),
Some("schema.v1"),
"schema_version must be schema.v1"
);
assert!(
v.get("kebab_version")
.and_then(|s| s.as_str())
.is_some_and(|s| !s.is_empty()),
"kebab_version must be a non-empty string"
);
let caps = v
.get("capabilities")
.and_then(|c| c.as_object())
.expect("capabilities must be a JSON object");
assert_eq!(
caps.get("json_mode").and_then(serde_json::Value::as_bool),
Some(true),
"capabilities.json_mode must be true"
);
assert_eq!(
caps.get("mcp_server").and_then(serde_json::Value::as_bool),
Some(true),
"capabilities.mcp_server must be true (fb-30)"
);
}
#[test]
fn cli_schema_text_mode_runs() {
let tmp = tempfile::tempdir().unwrap();
seed_db(&tmp);
let mut cmd = Command::new(kebab_bin());
cmd.args(["schema"]);
for (k, v) in xdg_envs(tmp.path()) {
cmd.env(k, v);
}
let out = cmd.output().unwrap();
assert!(
out.status.success(),
"kebab schema (text) failed: {}",
String::from_utf8_lossy(&out.stderr)
);
let stdout = String::from_utf8(out.stdout).unwrap();
assert!(
stdout.contains("kebab v"),
"text output must contain 'kebab v', got: {stdout}"
);
assert!(
stdout.contains("capabilities"),
"text output must contain 'capabilities', got: {stdout}"
);
assert!(
stdout.contains("models"),
"text output must contain 'models', got: {stdout}"
);
assert!(
stdout.contains("stats"),
"text output must contain 'stats', got: {stdout}"
);
}