Files
kebab/crates/kebab-app/tests/schema_report.rs
th-kim0823 3e33daaa9b 🧪 test(kebab-app): assert chunk_count + asset_count in schema_report (fb-27)
Plug coverage hole flagged in code review — test 1 was asserting only
doc_count + last_ingest_at, leaving count_summary's chunk_count and
asset_count queries un-pinned.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 12:06:04 +09:00

120 lines
4.1 KiB
Rust

//! Integration test: kebab_app::schema_with_config returns a SchemaV1
//! that is internally consistent with a freshly-ingested TempDir KB.
use std::fs;
use kebab_config::Config;
use kebab_core::SourceScope;
fn minimal_config(data_dir: &std::path::Path, workspace_root: &std::path::Path) -> Config {
let mut config = Config::defaults();
config.workspace.root = workspace_root.to_string_lossy().into_owned();
config.workspace.exclude.clear();
config.storage.data_dir = data_dir.to_string_lossy().into_owned();
config.storage.model_dir = data_dir.join("models").to_string_lossy().into_owned();
config.models.embedding.provider = "none".to_string();
config.models.embedding.dimensions = 0;
config.chunking.target_tokens = 80;
config.chunking.overlap_tokens = 20;
config
}
fn minimal_scope(workspace_root: &std::path::Path) -> SourceScope {
SourceScope {
root: workspace_root.to_path_buf(),
include: vec![],
exclude: vec![],
}
}
#[test]
fn schema_report_reflects_freshly_ingested_kb() {
let temp = tempfile::tempdir().expect("tempdir");
let workspace_root = temp.path().join("workspace");
let data_dir = temp.path().join("data");
fs::create_dir_all(&workspace_root).unwrap();
fs::create_dir_all(&data_dir).unwrap();
fs::write(workspace_root.join("a.md"), "# A\n\nbody A.").unwrap();
fs::write(workspace_root.join("b.md"), "# B\n\nbody B.").unwrap();
let config = minimal_config(&data_dir, &workspace_root);
let _report =
kebab_app::ingest_with_config(config.clone(), minimal_scope(&workspace_root), false)
.unwrap();
let schema = kebab_app::schema_with_config(&config).unwrap();
assert!(!schema.kebab_version.is_empty());
assert!(
schema.wire.schemas.contains(&"schema.v1".to_string()),
"schema.v1 missing from wire.schemas: {:?}",
schema.wire.schemas
);
assert!(
schema.wire.schemas.contains(&"error.v1".to_string()),
"error.v1 missing from wire.schemas: {:?}",
schema.wire.schemas
);
assert!(schema.capabilities.json_mode);
assert!(!schema.capabilities.streaming_ask);
assert_eq!(
schema.stats.doc_count, 2,
"expected 2 docs (a.md + b.md): {:?}",
schema.stats
);
assert!(
schema.stats.last_ingest_at.is_some(),
"last_ingest_at must be set after ingest: {:?}",
schema.stats
);
assert!(
schema.stats.chunk_count >= 2,
"expected ≥2 chunks (a.md + b.md): {:?}",
schema.stats
);
assert_eq!(
schema.stats.asset_count, 2,
"expected 2 assets (a.md + b.md): {:?}",
schema.stats
);
}
#[test]
fn schema_report_on_empty_kb_has_zero_counts() {
// An empty workspace dir with no .md files: ingest_with_config scans 0
// files but still creates + migrates kebab.sqlite. This seeds the DB so
// open_existing (used inside schema_with_config) succeeds and returns
// all-zero counts.
let temp = tempfile::tempdir().expect("tempdir");
let workspace_root = temp.path().join("workspace");
let data_dir = temp.path().join("data");
fs::create_dir_all(&workspace_root).unwrap();
fs::create_dir_all(&data_dir).unwrap();
let config = minimal_config(&data_dir, &workspace_root);
// Run ingest over the empty workspace — creates kebab.sqlite, runs
// migrations, records 0 docs. schema_with_config can then open_existing.
let report =
kebab_app::ingest_with_config(config.clone(), minimal_scope(&workspace_root), false)
.unwrap();
assert_eq!(report.new, 0, "empty workspace should yield 0 new docs");
let schema = kebab_app::schema_with_config(&config).unwrap();
assert_eq!(
schema.stats.doc_count, 0,
"empty KB doc_count: {:?}",
schema.stats
);
assert_eq!(
schema.stats.chunk_count, 0,
"empty KB chunk_count: {:?}",
schema.stats
);
assert!(
schema.stats.last_ingest_at.is_none(),
"last_ingest_at must be None when no docs ingested: {:?}",
schema.stats
);
}