1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use serde::Deserialize;
use tryparse::parse;
#[derive(Deserialize, Debug, PartialEq)]
struct User {
name: String,
age: u32,
}
#[test]
fn test_architectural_flaw_is_now_fixed() {
// This WAS the KILLER scenario that demonstrated the architectural flaw:
// - JSON is buried in prose (needs heuristic extraction)
// - AND has syntax errors (needs fixing)
//
// OLD architecture COULDN'T handle this because:
// 1. HeuristicStrategy extracted but didn't fix
// 2. JsonFixerStrategy fixed but didn't extract
// 3. RESULT: Both strategies failed
//
// NEW architecture (multi-stage) CAN handle this:
// 1. Extract candidates (heuristic finds {name: 'Alice', age: 30})
// 2. Try parsing each candidate
// 3. If parsing fails, apply fixes
// 4. SUCCESS!
let response = r#"
Sure! Here's the user data: {name: 'Alice', age: 30}
Hope that helps!
"#;
let result: Result<User, _> = parse(response);
match &result {
Ok(user) => {
println!("SUCCESS: {:?}", user);
assert_eq!(user.name, "Alice");
assert_eq!(user.age, 30);
}
Err(e) => {
println!("FAILED: {:?}", e);
panic!("Architectural flaw still exists!");
}
}
// This should NOW work with the multi-stage architecture
assert!(
result.is_ok(),
"Multi-stage architecture should handle extraction + fixing"
);
}