혼합 출처 KB(위키+jira 등)에서 색인은 전부 하되 질의 시 출처로 좁히는 provenance 레버. 전역 trust 곱셈가중(weighted-RRF)은 A/B 에서 반증(θ=0.85 만으로 incident MRR 0.918→0.340 절벽, 점수 압축) — 필터가 see-saw 없는 올바른 레버. - config [[workspace.sources]] (각 id/root/exclude/trust_level/source_type); 단일 root 는 implicit `default` source 로 정규화. validate: id 유일·비어있지 않음. - config schema v3→v4 (step_3_to_4, root→[[workspace.sources]] id=default 미러, 멱등) - V014 documents.source_id 컬럼+인덱스 (additive, DEFAULT 'default', 재색인 0) - Metadata.source_id + BodyHints trust precedence(frontmatter > source 기본값 > Primary) - ingest: --root 미지정 시 resolved_sources() 순회 + doc 마다 source_id/trust stamp - 검색 SearchFilters.source_type/source_id → lexical + vector 두 site (IN, OR) - CLI kebab search --source <id> / --source-type <type> (repeatable/comma-sep) 도그푸딩(620 doc, jira400+wiki220): --source wiki 로 개념 질의 MRR 0.780→0.810, --source jira 로 incident 0.918→0.975. trust precedence 실측(jira=secondary 기본값). version bump 0.28.0 → 0.29.0 (신규 CLI flag + config 키 + V014 migration → minor). follow-up: MCP search 필터 미노출 · kebab list source_id 미표시 · RAG provenance 라벨. 자세한 내용: tasks/HOTFIXES.md (2026-06-21), docs/release-notes/v0.29.0-draft.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Mc6W1fgsrbFKTsqA6P8La
172 lines
6.2 KiB
Rust
172 lines
6.2 KiB
Rust
//! Snapshot test pinning the `Vec<Chunk>` JSON for the
|
|
//! `fixtures/markdown/long-section.md` fixture.
|
|
//!
|
|
//! This is an integration test. `kb-parse-md` and `kb-normalize` are
|
|
//! dev-dep only — `cargo tree -p kb-chunk --depth 1` (default scope,
|
|
//! excludes dev-deps) confirms they are not regular deps. The §8
|
|
//! module-boundary rule is preserved.
|
|
//!
|
|
//! The chunker output is fully deterministic given fixed inputs, so we
|
|
//! pin the entire `Vec<Chunk>` JSON.
|
|
//!
|
|
//! Set `UPDATE_SNAPSHOTS=1` to re-bake the baseline.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use kebab_chunk::MdHeadingV1Chunker;
|
|
use kebab_core::{
|
|
AssetId, AssetStorage, Checksum, ChunkPolicy, Chunker, ChunkerVersion, MediaType,
|
|
ParserVersion, RawAsset, SourceUri, WorkspacePath,
|
|
};
|
|
use kebab_parse_md::{BodyHints, build_canonical_document, parse_blocks, parse_frontmatter};
|
|
use serde_json::Value;
|
|
use time::OffsetDateTime;
|
|
|
|
fn fixtures_dir() -> PathBuf {
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
.join("..")
|
|
.join("..")
|
|
.join("fixtures")
|
|
.join("markdown")
|
|
}
|
|
|
|
fn fixed_asset(workspace_path: &str) -> RawAsset {
|
|
let wp = WorkspacePath::new(workspace_path.into()).unwrap();
|
|
RawAsset {
|
|
asset_id: AssetId("a".repeat(32)),
|
|
source_uri: SourceUri::File(PathBuf::from("/tmp/long-section.md")),
|
|
workspace_path: wp,
|
|
media_type: MediaType::Markdown,
|
|
byte_len: 0,
|
|
checksum: Checksum("0".repeat(64)),
|
|
discovered_at: OffsetDateTime::from_unix_timestamp(1_700_000_000).unwrap(),
|
|
stored: AssetStorage::Reference {
|
|
path: PathBuf::from("/tmp/long-section.md"),
|
|
sha: Checksum("0".repeat(64)),
|
|
},
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn long_section_chunks_snapshot() {
|
|
let dir = fixtures_dir();
|
|
let bytes = std::fs::read(dir.join("long-section.md")).expect("fixture readable");
|
|
|
|
let asset = fixed_asset("notes/long-section.md");
|
|
let hints = BodyHints {
|
|
first_h1: Some("Alpha".into()),
|
|
fs_ctime: asset.discovered_at,
|
|
fs_mtime: asset.discovered_at,
|
|
fallback_lang: Some("en".into()),
|
|
source_id: None,
|
|
fallback_trust_level: None,
|
|
};
|
|
let (metadata, fm_span, _fm_warns) =
|
|
parse_frontmatter(&bytes, &hints).expect("frontmatter parses");
|
|
let body_offset_lines: u32 = match fm_span {
|
|
Some(span) => bytes[..span.end].iter().filter(|b| **b == b'\n').count() as u32 + 1,
|
|
None => 1,
|
|
};
|
|
let (blocks, parse_warns) = parse_blocks(&bytes, body_offset_lines).expect("blocks parse");
|
|
|
|
// Pin parser_version so doc_id / block_ids are reproducible.
|
|
let parser_version = ParserVersion("kb-chunk-snapshot-test-0".into());
|
|
let mut metadata = metadata;
|
|
metadata.aliases.sort();
|
|
metadata.tags.sort();
|
|
|
|
let doc = build_canonical_document(&asset, metadata, blocks, &parser_version, parse_warns)
|
|
.expect("build_canonical_document");
|
|
|
|
// Pin policy so policy_hash and chunk_ids are reproducible.
|
|
let policy = ChunkPolicy {
|
|
target_tokens: 200,
|
|
overlap_tokens: 40,
|
|
respect_markdown_headings: true,
|
|
chunker_version: ChunkerVersion("md-heading-v1".into()),
|
|
};
|
|
|
|
let chunks = MdHeadingV1Chunker.chunk(&doc, &policy).expect("chunk");
|
|
let actual = serde_json::to_value(&chunks).unwrap();
|
|
|
|
let baseline_path = dir.join("long-section.chunks.snapshot.json");
|
|
let baseline_text = match std::fs::read_to_string(&baseline_path) {
|
|
Ok(s) => s,
|
|
Err(_) if std::env::var("UPDATE_SNAPSHOTS").is_ok() => {
|
|
let pretty = serde_json::to_string_pretty(&actual).unwrap();
|
|
std::fs::write(&baseline_path, format!("{pretty}\n")).unwrap();
|
|
return;
|
|
}
|
|
Err(e) => panic!(
|
|
"missing baseline {}; run with UPDATE_SNAPSHOTS=1 to create: {e}",
|
|
baseline_path.display()
|
|
),
|
|
};
|
|
let expected: Value = serde_json::from_str(&baseline_text).expect("baseline parses as json");
|
|
|
|
if actual != expected {
|
|
if std::env::var("UPDATE_SNAPSHOTS").is_ok() {
|
|
let pretty = serde_json::to_string_pretty(&actual).unwrap();
|
|
std::fs::write(&baseline_path, format!("{pretty}\n")).unwrap();
|
|
eprintln!("updated baseline {}", baseline_path.display());
|
|
return;
|
|
}
|
|
let pretty = serde_json::to_string_pretty(&actual).unwrap();
|
|
panic!(
|
|
"long-section chunks snapshot drift\n\
|
|
--- expected ({}) ---\n{baseline_text}\n\
|
|
--- actual ---\n{pretty}\n\
|
|
If intentional, re-run with UPDATE_SNAPSHOTS=1.",
|
|
baseline_path.display()
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Determinism cross-check: re-running the same pipeline yields the same
|
|
/// chunk_ids byte-for-byte.
|
|
#[test]
|
|
fn long_section_chunks_are_deterministic() {
|
|
let dir = fixtures_dir();
|
|
let bytes = std::fs::read(dir.join("long-section.md")).expect("fixture readable");
|
|
|
|
let asset = fixed_asset("notes/long-section.md");
|
|
let hints = BodyHints {
|
|
first_h1: Some("Alpha".into()),
|
|
fs_ctime: asset.discovered_at,
|
|
fs_mtime: asset.discovered_at,
|
|
fallback_lang: Some("en".into()),
|
|
source_id: None,
|
|
fallback_trust_level: None,
|
|
};
|
|
|
|
let policy = ChunkPolicy {
|
|
target_tokens: 200,
|
|
overlap_tokens: 40,
|
|
respect_markdown_headings: true,
|
|
chunker_version: ChunkerVersion("md-heading-v1".into()),
|
|
};
|
|
let parser_version = ParserVersion("kb-chunk-snapshot-test-0".into());
|
|
|
|
let mut baseline: Option<Vec<String>> = None;
|
|
for _ in 0..5 {
|
|
let (metadata, _fm_span, _fm_warns) =
|
|
parse_frontmatter(&bytes, &hints).expect("frontmatter parses");
|
|
let (blocks, parse_warns) = parse_blocks(&bytes, 1).expect("blocks parse");
|
|
let mut metadata = metadata;
|
|
metadata.aliases.sort();
|
|
metadata.tags.sort();
|
|
let doc = build_canonical_document(&asset, metadata, blocks, &parser_version, parse_warns)
|
|
.expect("build_canonical_document");
|
|
let ids: Vec<String> = MdHeadingV1Chunker
|
|
.chunk(&doc, &policy)
|
|
.unwrap()
|
|
.into_iter()
|
|
.map(|c| c.chunk_id.0)
|
|
.collect();
|
|
match &baseline {
|
|
None => baseline = Some(ids),
|
|
Some(prev) => assert_eq!(prev, &ids),
|
|
}
|
|
}
|
|
}
|