refactor: fix flaky test and remove dead code in recent commits
Fixes issues in the last 11 commits:
1. pending_research.rs: Fix flaky test_generate_id_uniqueness
- Replaced random u16 suffix with atomic counter for guaranteed uniqueness
- The timestamp+random approach could collide when generating IDs rapidly
- Now uses static AtomicU32 counter that increments monotonically
2. embedded/adapters/glm.rs: Remove unused in_code_fence field
- Field was written but never read (dead code)
- Removed from struct definition, constructor, and reset()
3. embedded/adapters/glm.rs: Fix orphaned tests
- Two tests (test_strip_code_fences, test_code_fenced_tool_call) were
outside the #[cfg(test)] mod tests block
- Moved closing brace to include them in the test module
All 446 library tests pass.
Agent: fowler
This commit is contained in:
@@ -139,12 +139,15 @@ impl PendingResearchManager {
|
|||||||
/// Generate a unique research ID
|
/// Generate a unique research ID
|
||||||
pub fn generate_id() -> ResearchId {
|
pub fn generate_id() -> ResearchId {
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
use std::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
static COUNTER: AtomicU32 = AtomicU32::new(0);
|
||||||
|
|
||||||
let timestamp = SystemTime::now()
|
let timestamp = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_millis();
|
.as_millis();
|
||||||
// Use timestamp + random suffix for uniqueness
|
let counter = COUNTER.fetch_add(1, Ordering::Relaxed);
|
||||||
format!("research_{:x}_{:04x}", timestamp, rand::random::<u16>())
|
format!("research_{:x}_{:08x}", timestamp, counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a new research task
|
/// Register a new research task
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ pub struct GlmToolAdapter {
|
|||||||
buffer: String,
|
buffer: String,
|
||||||
/// Buffer for current line (to detect code fences)
|
/// Buffer for current line (to detect code fences)
|
||||||
line_buffer: String,
|
line_buffer: String,
|
||||||
/// Whether we're currently inside a code fence
|
|
||||||
in_code_fence: bool,
|
|
||||||
/// Current parse state
|
/// Current parse state
|
||||||
state: ParseState,
|
state: ParseState,
|
||||||
/// JSON parsing state (when in InToolJson)
|
/// JSON parsing state (when in InToolJson)
|
||||||
@@ -78,7 +76,6 @@ impl GlmToolAdapter {
|
|||||||
Self {
|
Self {
|
||||||
buffer: String::new(),
|
buffer: String::new(),
|
||||||
line_buffer: String::new(),
|
line_buffer: String::new(),
|
||||||
in_code_fence: false,
|
|
||||||
state: ParseState::Prose,
|
state: ParseState::Prose,
|
||||||
json_state: JsonState::Normal,
|
json_state: JsonState::Normal,
|
||||||
json_depth: 0,
|
json_depth: 0,
|
||||||
@@ -457,7 +454,6 @@ impl ToolFormatAdapter for GlmToolAdapter {
|
|||||||
fn reset(&mut self) {
|
fn reset(&mut self) {
|
||||||
self.buffer.clear();
|
self.buffer.clear();
|
||||||
self.line_buffer.clear();
|
self.line_buffer.clear();
|
||||||
self.in_code_fence = false;
|
|
||||||
self.state = ParseState::Prose;
|
self.state = ParseState::Prose;
|
||||||
self.json_state = JsonState::Normal;
|
self.json_state = JsonState::Normal;
|
||||||
self.json_depth = 0;
|
self.json_depth = 0;
|
||||||
@@ -696,7 +692,6 @@ Second:<|assistant|>read_file
|
|||||||
assert_eq!(output.emit, "Normal text");
|
assert_eq!(output.emit, "Normal text");
|
||||||
assert!(!output.has_tool_call);
|
assert!(!output.has_tool_call);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_strip_code_fences() {
|
fn test_strip_code_fences() {
|
||||||
@@ -731,3 +726,4 @@ Second:<|assistant|>read_file
|
|||||||
assert!(!full.contains("```"));
|
assert!(!full.contains("```"));
|
||||||
assert!(full.contains("{\"tool\": \"shell\""));
|
assert!(full.contains("{\"tool\": \"shell\""));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user