Add comprehensive stress tests for streaming markdown formatter
Add 10 stress tests covering: - Nested formatting (bold in italic, italic in bold) - Empty/minimal content edge cases - Escape sequences and special characters - Lists with complex inline formatting - Links with various content types - Tables with formatting in cells - Code blocks (should not format contents) - Mixed block elements (headers, quotes, rules) - Nested lists (3+ levels, mixed types) - Pathological/adversarial inputs (unbalanced delimiters, unicode, long lines) All 45 tests pass.
This commit is contained in:
@@ -2027,6 +2027,9 @@ impl<W: UiWriter> Agent<W> {
|
||||
|
||||
// Skip printing tool call details for final_output
|
||||
if tool_call.tool != "final_output" {
|
||||
// Finish streaming markdown before showing tool output
|
||||
self.ui_writer.finish_streaming_markdown();
|
||||
|
||||
// Tool call header
|
||||
self.ui_writer.print_tool_header(&tool_call.tool, Some(&tool_call.args));
|
||||
if let Some(args_obj) = tool_call.args.as_object() {
|
||||
@@ -2197,6 +2200,9 @@ impl<W: UiWriter> Agent<W> {
|
||||
|
||||
// Check if this was a final_output tool call
|
||||
if tool_call.tool == "final_output" {
|
||||
// Finish the streaming markdown formatter before final_output
|
||||
self.ui_writer.finish_streaming_markdown();
|
||||
|
||||
// Save context window BEFORE returning so the session log includes final_output
|
||||
self.save_context_window("completed");
|
||||
|
||||
@@ -2406,6 +2412,9 @@ impl<W: UiWriter> Agent<W> {
|
||||
// Return empty string to avoid duplication
|
||||
full_response = String::new();
|
||||
|
||||
// Finish the streaming markdown formatter before returning
|
||||
self.ui_writer.finish_streaming_markdown();
|
||||
|
||||
// Save context window BEFORE returning
|
||||
self.save_context_window("completed");
|
||||
let _ttft =
|
||||
|
||||
@@ -81,6 +81,12 @@ pub trait UiWriter: Send + Sync {
|
||||
/// Called at the start of a new response to clear any partial state.
|
||||
/// Default implementation does nothing.
|
||||
fn reset_json_filter(&self) {}
|
||||
|
||||
/// Finish the streaming markdown formatter and flush any remaining content.
|
||||
/// Called at the end of an agent response to emit any buffered markdown.
|
||||
/// Also resets the formatter for the next response.
|
||||
/// Default implementation does nothing.
|
||||
fn finish_streaming_markdown(&self) {}
|
||||
|
||||
/// Set whether the UI is in agent mode.
|
||||
/// When in agent mode, tool names may be displayed differently (e.g., different color).
|
||||
@@ -109,6 +115,7 @@ impl UiWriter for NullUiWriter {
|
||||
fn print_agent_response(&self, _content: &str) {}
|
||||
fn notify_sse_received(&self) {}
|
||||
fn flush(&self) {}
|
||||
fn finish_streaming_markdown(&self) {}
|
||||
fn wants_full_output(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user