Files
kebab/crates/kebab-parse-md/tests/frontmatter_snapshots.rs
altair823 58ac62d53a feat(search): provenance 출처 필터 — [[workspace.sources]] 멀티소스 + --source/--source-type
혼합 출처 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
2026-06-21 08:35:19 +00:00

116 lines
3.9 KiB
Rust

//! Snapshot tests pinning the §0 Q9 derive output for two fixtures.
//!
//! The baseline JSON next to each fixture is hand-authored / regenerated
//! from a deterministic run. `BodyHints` timestamps are caller-provided
//! and therefore stable; lingua autodetect over our fixtures is also
//! stable for the language set we configured.
use kebab_parse_md::{BodyHints, parse_frontmatter};
use serde::Serialize;
use serde_json::Value;
use std::fs;
use std::path::PathBuf;
use time::macros::datetime;
/// Stable view of the parser output suitable for JSON snapshotting.
/// We deliberately exclude `FrontmatterSpan` byte offsets here too — they're
/// fully determined by the input file and are exercised by unit tests; the
/// snapshot focuses on the §0 Q9 derive contract.
#[derive(Serialize)]
struct Snapshot {
metadata: kebab_core::Metadata,
span_present: bool,
warnings: Vec<kebab_parse_md::Warning>,
}
fn fixtures_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("..")
.join("..")
.join("fixtures")
.join("markdown")
}
fn pinned_hints() -> BodyHints {
BodyHints {
first_h1: None,
fs_ctime: datetime!(2024-01-01 00:00:00 UTC),
fs_mtime: datetime!(2024-01-02 00:00:00 UTC),
fallback_lang: None,
source_id: None,
fallback_trust_level: None,
}
}
fn assert_snapshot(fixture: &str, baseline: &str) {
let dir = fixtures_dir();
let bytes = fs::read(dir.join(fixture)).expect("fixture readable");
let (meta, span, warns) = parse_frontmatter(&bytes, &pinned_hints()).unwrap();
let snap = Snapshot {
metadata: meta,
span_present: span.is_some(),
warnings: warns,
};
let actual: Value = serde_json::to_value(&snap).unwrap();
let expected_text = fs::read_to_string(dir.join(baseline)).expect("snapshot baseline readable");
let expected: Value = serde_json::from_str(&expected_text).expect("baseline parses as json");
if actual != expected {
let actual_pretty = serde_json::to_string_pretty(&actual).unwrap();
panic!(
"snapshot drift for {fixture}\n\
--- expected ({baseline}) ---\n{expected_text}\n\
--- actual ---\n{actual_pretty}\n\
If the change is intentional, update {baseline}."
);
}
}
#[test]
fn frontmatter_only_snapshot() {
assert_snapshot("frontmatter-only.md", "frontmatter-only.snapshot.json");
}
/// Run with `cargo test -p kb-parse-md --test frontmatter_snapshots emit_snapshots -- --ignored --nocapture`
/// to regenerate the baseline JSON files from the current parser output.
#[test]
#[ignore]
fn emit_snapshots() {
let dir = fixtures_dir();
for (fixture, baseline) in [
("frontmatter-only.md", "frontmatter-only.snapshot.json"),
("mixed-lang.md", "mixed-lang.snapshot.json"),
] {
let bytes = fs::read(dir.join(fixture)).unwrap();
let (meta, span, warns) = parse_frontmatter(&bytes, &pinned_hints()).unwrap();
let snap = Snapshot {
metadata: meta,
span_present: span.is_some(),
warnings: warns,
};
let json = serde_json::to_string_pretty(&snap).unwrap();
fs::write(dir.join(baseline), format!("{json}\n")).unwrap();
eprintln!("wrote {}", dir.join(baseline).display());
}
}
#[test]
fn mixed_lang_snapshot() {
assert_snapshot("mixed-lang.md", "mixed-lang.snapshot.json");
}
/// Determinism: parsing the same fixture twice in a row must give equal output.
#[test]
fn snapshot_is_deterministic_across_runs() {
let dir = fixtures_dir();
let bytes = fs::read(dir.join("frontmatter-only.md")).unwrap();
let (a, _, _) = parse_frontmatter(&bytes, &pinned_hints()).unwrap();
let (b, _, _) = parse_frontmatter(&bytes, &pinned_hints()).unwrap();
assert_eq!(
serde_json::to_value(&a).unwrap(),
serde_json::to_value(&b).unwrap()
);
}