feat: update README and documentation for new tools and features
- Updated README.md to reflect the addition of 3 new built-in tools, bringing the total to 37. - Revised architecture documentation to indicate the increase in tool count. - Enhanced backend documentation with updated line counts for various modules. - Modified data documentation to change edit log format from JSON to JSONL. - Updated dependencies documentation to reflect version upgrades for several crates. - Improved prompts for auto-reviewer, division implementer, planner, tester, and quality reviewer to enforce stricter coding standards regarding linter bypasses. - Refactored code in various modules to improve clarity and performance, including updates to error handling and tool execution logic. - Added comprehensive tests for IPC frame serialization and deserialization.
This commit is contained in:
@@ -73,3 +73,123 @@ pub fn serialize_frame<T: serde::Serialize>(value: &T) -> Result<Vec<u8>> {
|
||||
pub fn deserialize_frame<'a, T: serde::Deserialize<'a>>(data: &'a [u8]) -> Result<T> {
|
||||
Ok(serde_json::from_slice(data)?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Write a value, read it back, and verify exact equality.
|
||||
fn roundtrip_bytes(data: &[u8]) {
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
write_frame(&mut buf, data).unwrap();
|
||||
let read_back = read_frame(&mut buf.as_slice())
|
||||
.unwrap()
|
||||
.expect("expected Some(frame)");
|
||||
assert_eq!(read_back, data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_read_roundtrip_empty() {
|
||||
roundtrip_bytes(b"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_read_roundtrip_small_text() {
|
||||
roundtrip_bytes(b"hello world");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_read_roundtrip_binary() {
|
||||
roundtrip_bytes(&[0x00, 0xFF, 0xAB, 0xCD, 0x01, 0x02, 0x03]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_read_roundtrip_large() {
|
||||
let data = vec![0x42u8; 100_000];
|
||||
roundtrip_bytes(&data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_rejects_too_large_frame() {
|
||||
let oversized = vec![0u8; MAX_FRAME_SIZE + 1];
|
||||
let mut buf = Vec::new();
|
||||
let result = write_frame(&mut buf, &oversized);
|
||||
assert!(result.is_err());
|
||||
let err = result.unwrap_err().to_string();
|
||||
assert!(err.contains("too large") || err.contains("64 MiB"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_rejects_too_large_header() {
|
||||
// Manually craft a 4-byte length header that exceeds MAX_FRAME_SIZE
|
||||
let len = (MAX_FRAME_SIZE as u32).wrapping_add(1);
|
||||
let header = len.to_be_bytes();
|
||||
let mut buf = Vec::from(&header[..]);
|
||||
buf.extend_from_slice(b"dummy");
|
||||
let result = read_frame(&mut buf.as_slice());
|
||||
assert!(result.is_err());
|
||||
let err = result.unwrap_err().to_string();
|
||||
assert!(err.contains("too large"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_empty_buf_returns_none() {
|
||||
let empty: &[u8] = &[];
|
||||
let result = read_frame(&mut &empty[..]).unwrap();
|
||||
assert!(result.is_none(), "expected None for empty reader");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_partial_header_returns_none() {
|
||||
// Only 2 bytes of the 4-byte header → EOF
|
||||
let partial: &[u8] = &[0x00, 0x01];
|
||||
let result = read_frame(&mut &partial[..]).unwrap();
|
||||
assert!(result.is_none(), "expected None for partial header");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_truncated_payload_returns_err() {
|
||||
let mut buf = Vec::new();
|
||||
let header = (10u32).to_be_bytes();
|
||||
buf.extend_from_slice(&header);
|
||||
buf.extend_from_slice(b"abc"); // only 3 of 10 bytes
|
||||
let result = read_frame(&mut buf.as_slice());
|
||||
assert!(result.is_err(), "truncated payload should error");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_deserialize_roundtrip() {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
struct Msg {
|
||||
id: u32,
|
||||
content: String,
|
||||
tags: Vec<String>,
|
||||
}
|
||||
|
||||
let original = Msg {
|
||||
id: 42,
|
||||
content: "hello world".into(),
|
||||
tags: vec!["foo".into(), "bar".into()],
|
||||
};
|
||||
|
||||
let bytes = serialize_frame(&original).unwrap();
|
||||
let deserialized: Msg = deserialize_frame(&bytes).unwrap();
|
||||
assert_eq!(original, deserialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_rejects_oversized_value() {
|
||||
let huge = vec![0u8; MAX_FRAME_SIZE + 1];
|
||||
let result = serialize_frame(&huge);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deserialize_malformed_json_errors() {
|
||||
let bad_json = b"this is not json";
|
||||
let result: Result<String> = deserialize_frame(bad_json);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user