| 164 | # ── Test 4: Array output ───────────────────────────────────────────────── |
| 165 | |
| 166 | def test_array(): |
| 167 | result = session.tool("generate_object", { |
| 168 | "schema": { |
| 169 | "type": "object", |
| 170 | "required": ["colors"], |
| 171 | "properties": { |
| 172 | "colors": { |
| 173 | "type": "array", |
| 174 | "minItems": 3, |
| 175 | "maxItems": 3, |
| 176 | "items": { |
| 177 | "type": "object", |
| 178 | "required": ["name", "hex"], |
| 179 | "properties": { |
| 180 | "name": {"type": "string"}, |
| 181 | "hex": {"type": "string", "pattern": "^#[0-9a-fA-F]{6}$"}, |
| 182 | }, |
| 183 | }, |
| 184 | } |
| 185 | }, |
| 186 | }, |
| 187 | "prompt": "List exactly 3 colors with their hex codes: red, green, blue.", |
| 188 | "schema_name": "colors", |
| 189 | }) |
| 190 | assert result.exit_code == 0, f"Tool failed: {result.output}" |
| 191 | parsed = json.loads(result.output) |
| 192 | colors = parsed["object"]["colors"] |
| 193 | assert len(colors) == 3, f"Expected 3 colors, got {len(colors)}" |
| 194 | for c in colors: |
| 195 | assert c["hex"].startswith("#"), f"Invalid hex: {c['hex']}" |
| 196 | assert len(c["hex"]) == 7, f"Hex wrong length: {c['hex']}" |
| 197 | print(f" Result: {', '.join(c['name'] + '=' + c['hex'] for c in colors)}") |
| 198 | |
| 199 | run_test("generate_object: array with pattern validation", test_array) |
| 200 | |