🧪 test(kebab-app): schema_with_config integration coverage (fb-27)
Two scenarios: freshly-ingested 2-doc KB (stats reflect counts + last_ingest_at populated) and empty-but-initialized KB (counts zero, last_ingest_at None). The empty case runs ingest_with_config over an empty workspace dir to seed kebab.sqlite before calling schema_with_config, since open_existing (used internally) returns NotIndexed if the DB is absent. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
109
crates/kebab-app/tests/schema_report.rs
Normal file
109
crates/kebab-app/tests/schema_report.rs
Normal file
@@ -0,0 +1,109 @@
|
||||
//! 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
|
||||
);
|
||||
}
|
||||
|
||||
#[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
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user