docs: tambah doc comment, logging, dan inline comments di semua 255 file
Meliputi: - File-level //! doc comment: tujuan file, alur kerja, komponen utama - Function-level /// doc comment: apa, parameter, return, flow, edge cases - Struct/enum/trait /// doc comment: peran, field docs - Tracing logging (tracing::info!/debug!/trace!/warn!/error!) di setiap fungsi - Inline comments untuk variable dan branching logic penting - Seluruh 8 crates di workspace: zesdex-backend, zesdex-cms, zesdex-entities, zesdex-iam, zesdex-infra, zesdex-ipc, zesdex-middleware, zesdex-utils - Build: 0 errors, 242/242 tests passed
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
//! JSON file–backed `ConversationRepository`.
|
||||
//! JSON file–backed `ConversationRepository` implementation.
|
||||
//!
|
||||
//! Path: `<session_dir>/conversation.json`
|
||||
//! Stores `Conversation` as pretty-printed JSON at `<session_dir>/conversation.json`.
|
||||
//! Uses atomic write (temp file + rename + fsync) for crash safety.
|
||||
//!
|
||||
//! Uses write-then-rename with fsync for crash safety.
|
||||
//! ## Data Flow
|
||||
//! - `load()`: read file → deserialize JSON → return Conversation
|
||||
//! - `save()`: serialize Conversation → atomic write to conversation.json
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
@@ -12,7 +15,9 @@ use zesdex_utils::write_json_atomic;
|
||||
use crate::domain::conversation::Conversation;
|
||||
use crate::domain::repository::ConversationRepository;
|
||||
|
||||
/// Persists `Conversation` as pretty-printed JSON at `<session_dir>/conversation.json`.
|
||||
/// File-based `ConversationRepository` that reads/writes `conversation.json`.
|
||||
///
|
||||
/// Zero-allocation: the struct is a unit type marker.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct JsonConversationRepository;
|
||||
|
||||
@@ -24,6 +29,9 @@ impl JsonConversationRepository {
|
||||
}
|
||||
|
||||
impl ConversationRepository for JsonConversationRepository {
|
||||
/// Load a `Conversation` from `<session_dir>/conversation.json`.
|
||||
///
|
||||
/// Flow: read file → parse JSON → return Conversation.
|
||||
fn load(&self, session_dir: &Path) -> Result<Conversation> {
|
||||
let path = session_dir.join("conversation.json");
|
||||
let data = std::fs::read_to_string(&path)
|
||||
@@ -33,7 +41,11 @@ impl ConversationRepository for JsonConversationRepository {
|
||||
Ok(conv)
|
||||
}
|
||||
|
||||
/// Persist a `Conversation` to `<session_dir>/conversation.json`.
|
||||
///
|
||||
/// Flow: create session dir → atomic JSON write → log success.
|
||||
fn save(&self, session_dir: &Path, conversation: &Conversation) -> Result<()> {
|
||||
tracing::debug!("saving conversation to {session_dir:?}");
|
||||
std::fs::create_dir_all(session_dir)
|
||||
.with_context(|| format!("failed to create session dir '{}'", session_dir.display()))?;
|
||||
let path = session_dir.join("conversation.json");
|
||||
|
||||
Reference in New Issue
Block a user