// EvidenceStore (the app/MCP read-only view) over the event store: it sees // the daemon's writes through Database::refresh(), reports "nothing changed" // when nothing did, and explains missing/legacy paths. #include "strawberry/evidence_store.hpp" #include #include #include #include #include namespace fs = std::filesystem; using namespace strawberry; int main() { const fs::path root = fs::temp_directory_path() / ("sb-evidence-store-" + std::to_string(::getpid())); fs::remove_all(root); fs::create_directories(root); const std::string path = (root / "evidence.db").string(); EvidenceStore view; view.set_path(path); assert(!view.reload_if_changed()); assert(!view.available() && view.error().find("no evidence stored yet") != std::string::npos); Database writer; assert(writer.open(path)); assert(view.reload_if_changed() && view.available()); assert(view.findings().empty()); assert(!view.reload_if_changed()); // nothing changed FindingRecord f; f.id = "finding-1"; f.title = "t"; f.severity = "high"; f.score = 80; assert(writer.store_finding(f)); assert(view.reload_if_changed()); assert(view.findings().size() == 1 && view.finding("finding-1")->score == 80); assert(!view.reload_if_changed()); // A transaction becomes visible on commit. assert(writer.begin_transaction()); f.score = 90; assert(writer.store_finding(f)); assert(writer.commit_transaction()); assert(view.reload_if_changed() && view.finding("finding-1")->score == 90); assert(view.size_bytes() > 0); writer.close(); assert(!view.reload_if_changed()); // close syncs; content unchanged // A legacy database file at the path is explained, not misread. const std::string legacy = (root / "legacy.db").string(); std::ofstream(legacy) << "not an event store"; EvidenceStore old; old.set_path(legacy); old.reload_if_changed(); assert(!old.available() && old.error().find("legacy") != std::string::npos); fs::remove_all(root); std::cout << "evidence store: PASSED" << std::endl; return 0; }