refactor(rename): kb crates → kebab — Cargo packages, folders, Rust modules
프로젝트 이름 `kb` → `kebab` rename 의 첫 단계. - workspace `Cargo.toml`: members `crates/kb-*` → `crates/kebab-*`, repository URL `altair823/kb` → `altair823/kebab`. - 18 crate 폴더 rename via `git mv` (history 보존). - 각 crate `Cargo.toml`: `name = "kb-*"` → `"kebab-*"`, path deps `../kb-*` → `../kebab-*`. - 모든 `.rs`: `kb_<id>` snake-case 모듈 path 18 개 (`kb_core`, `kb_config`, `kb_app`, `kb_cli`, `kb_eval`, `kb_search`, `kb_chunk`, `kb_normalize`, `kb_source_fs`, `kb_parse_md`, `kb_parse_types`, `kb_store_sqlite`, `kb_store_vector`, `kb_embed`, `kb_embed_local`, `kb_llm`, `kb_llm_local`, `kb_rag`) → `kebab_<id>` 일괄 sed (단어 경계 \\b 사용해 영어 문장 안의 "kb" 약어 미오염). CLI binary 이름 (`[[bin]] name = "kb"`), 환경변수 `KB_*`, XDG paths, tracing target, 그리고 docs sweep 은 다음 commit 에서. ## 검증 - `cargo check --workspace` clean — 모든 crate 빌드 통과 후 commit. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
111
crates/kebab-parse-md/tests/frontmatter_snapshots.rs
Normal file
111
crates/kebab-parse-md/tests/frontmatter_snapshots.rs
Normal file
@@ -0,0 +1,111 @@
|
||||
//! 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_types::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,
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
Reference in New Issue
Block a user