()
| 97 | |
| 98 | #[test] |
| 99 | fn test_parse_agent() { |
| 100 | rootless_mutate(|mutation| { |
| 101 | let context = Context { |
| 102 | mutation, |
| 103 | strings: InternedStringSet::new(mutation), |
| 104 | }; |
| 105 | let source = r#" |
| 106 | agent Test { |
| 107 | instructions: "Test instruction.", |
| 108 | model: "gpt-4", |
| 109 | tools: [a, b], |
| 110 | tool_choice: "auto", |
| 111 | } |
| 112 | "#; |
| 113 | let mut parser = Parser::new(context, source); |
| 114 | let result = parser.parse().unwrap(); |
| 115 | let Stmt::Agent(AgentDecl { |
| 116 | name, fields, line, .. |
| 117 | }) = &result.statements[0] |
| 118 | else { |
| 119 | panic!("Expected agent statement"); |
| 120 | }; |
| 121 | assert_eq!(name.lexeme, "Test"); |
| 122 | assert_eq!(*line, 2); |
| 123 | assert_eq!(fields.len(), 4); |
| 124 | // let pairs = fields |
| 125 | // .iter() |
| 126 | // .map(|(key, value)| (key.to_string(), value)) |
| 127 | // .collect::<Vec<_>>(); |
| 128 | // assert_eq!(vec![("instructions", Expr::Literal(StringLiteral "Test instruction.")),], pairs); |
| 129 | |
| 130 | let source = r#" |
| 131 | agent Test { |
| 132 | model: "gpt-4", |
| 133 | tools: [a, b], |
| 134 | tool_choice: "auto", |
| 135 | } |
| 136 | "#; |
| 137 | let mut parser = Parser::new(context, source); |
| 138 | let result = parser.parse(); |
| 139 | assert!(result.is_err()); |
| 140 | let source = r#" |
| 141 | agent Test { |
| 142 | instructions: "Test instruction.", |
| 143 | } |
| 144 | "#; |
| 145 | let mut parser = Parser::new(context, source); |
| 146 | let result = parser.parse().unwrap(); |
| 147 | let Stmt::Agent(AgentDecl { name, fields, .. }) = &result.statements[0] else { |
| 148 | panic!("Expected agent statement"); |
| 149 | }; |
| 150 | assert_eq!(name.lexeme, "Test"); |
| 151 | assert_eq!(fields.len(), 1); |
| 152 | |
| 153 | let source = r#" |
| 154 | agent Test { |
| 155 | instructions: "Test instruction.", |
| 156 | tools: [a, b], |
nothing calls this directly
no test coverage detected