Files
kebab/crates/kebab-store-sqlite/tests/not_indexed.rs
th-kim0823 1c4d554bf4 🏗️ refactor(kebab-store-sqlite): harden open_existing against silent create (fb-27)
Replace `path.exists()` + `Connection::open` (which silently CREATEs on
race) with `Connection::open_with_flags` using READ_WRITE|URI but NOT
CREATE. SQLite surfaces `SQLITE_CANTOPEN` for missing files; we wrap as
NotIndexed { found: None } as before.

Adds open_existing_does_not_create_missing_db regression test pinning
the no-side-effect invariant.

Also documents read-only intent on open_existing, the format contract
on NotIndexed.found, and removes scaffolding comments from kebab-app
error_signal that are no longer load-bearing.

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

28 lines
1005 B
Rust

//! Signal test: `SqliteStore::open_existing` emits `NotIndexed` when the DB
//! file is absent.
use kebab_store_sqlite::{NotIndexed, SqliteStore};
#[test]
fn not_indexed_signal_emitted_when_db_missing() {
let dir = tempfile::tempdir().unwrap();
let nonexistent_db = dir.path().join("does-not-exist.sqlite");
let res = SqliteStore::open_existing(&nonexistent_db);
let err = match res {
Ok(_) => panic!("opening a missing DB should fail"),
Err(e) => e,
};
let signal = err
.downcast_ref::<NotIndexed>()
.expect("missing DB error should downcast to NotIndexed");
assert_eq!(signal.expected, nonexistent_db.to_string_lossy().as_ref());
}
#[test]
fn open_existing_does_not_create_missing_db() {
let dir = tempfile::tempdir().unwrap();
let nonexistent_db = dir.path().join("does-not-exist.sqlite");
let _ = SqliteStore::open_existing(&nonexistent_db);
assert!(!nonexistent_db.exists(), "open_existing must NOT create the file");
}