use crate::omf::import::ImportedChunk;
use crate::types::ChunkId;
#[derive(Debug, Clone)]
pub struct PostWriteEvent {
pub tenant_id: String,
pub chunk_id: ChunkId,
pub chunk_type: String,
pub project_id: Option<String>,
pub source_path: Option<String>,
pub text: String,
}
impl PostWriteEvent {
pub fn from_imported_chunk(ic: ImportedChunk, tenant_id: &str) -> Self {
Self {
tenant_id: tenant_id.to_string(),
chunk_id: ic.chunk_id,
chunk_type: ic.chunk_type.to_string(),
project_id: ic.project_id,
source_path: None,
text: ic.text,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::types::ChunkType;
#[test]
fn from_imported_chunk_preserves_fields_and_drops_source_path() {
let chunk_id = ChunkId::new();
let ic = ImportedChunk {
chunk_id: chunk_id.clone(),
chunk_type: ChunkType::Code,
project_id: Some("proj_a".to_string()),
text: "fn hello() {}".to_string(),
};
let event = PostWriteEvent::from_imported_chunk(ic, "tenant_x");
assert_eq!(event.tenant_id, "tenant_x");
assert_eq!(event.chunk_id, chunk_id);
assert_eq!(event.chunk_type, "code");
assert_eq!(event.project_id.as_deref(), Some("proj_a"));
assert_eq!(event.source_path, None);
assert_eq!(event.text, "fn hello() {}");
}
#[test]
fn from_imported_chunk_preserves_null_project_id() {
let chunk_id = ChunkId::new();
let ic = ImportedChunk {
chunk_id: chunk_id.clone(),
chunk_type: ChunkType::Doc,
project_id: None,
text: "anything".to_string(),
};
let event = PostWriteEvent::from_imported_chunk(ic, "tenant_y");
assert_eq!(event.tenant_id, "tenant_y");
assert_eq!(event.chunk_id, chunk_id);
assert_eq!(event.project_id, None);
assert_eq!(event.chunk_type, "doc");
assert_eq!(event.source_path, None);
assert_eq!(event.text, "anything");
}
#[allow(dead_code)]
fn _legacy_handlers_path_is_same_type(
e: crate::mcp::handlers::PostWriteEvent,
) -> crate::post_write_hooks::PostWriteEvent {
e
}
#[allow(dead_code)]
fn _flat_mcp_path_is_same_type(
e: crate::mcp::PostWriteEvent,
) -> crate::post_write_hooks::PostWriteEvent {
e
}
}