Test YAML config loading and validation.
()
| 266 | |
| 267 | |
| 268 | def test_yaml_loading(): |
| 269 | """Test YAML config loading and validation.""" |
| 270 | print("\nTesting YAML loading:\n") |
| 271 | passed = 0 |
| 272 | failed = 0 |
| 273 | |
| 274 | with tempfile.TemporaryDirectory() as tmpdir: |
| 275 | project_dir = Path(tmpdir) |
| 276 | autoforge_dir = project_dir / ".autoforge" |
| 277 | autoforge_dir.mkdir() |
| 278 | |
| 279 | # Test 1: Valid YAML |
| 280 | config_path = autoforge_dir / "allowed_commands.yaml" |
| 281 | config_path.write_text("""version: 1 |
| 282 | commands: |
| 283 | - name: swift |
| 284 | description: Swift compiler |
| 285 | - name: xcodebuild |
| 286 | description: Xcode build |
| 287 | - name: swift* |
| 288 | description: All Swift tools |
| 289 | """) |
| 290 | config = load_project_commands(project_dir) |
| 291 | if config and config["version"] == 1 and len(config["commands"]) == 3: |
| 292 | print(" PASS: Load valid YAML") |
| 293 | passed += 1 |
| 294 | else: |
| 295 | print(" FAIL: Load valid YAML") |
| 296 | print(f" Got: {config}") |
| 297 | failed += 1 |
| 298 | |
| 299 | # Test 2: Missing file returns None |
| 300 | (project_dir / ".autoforge" / "allowed_commands.yaml").unlink() |
| 301 | config = load_project_commands(project_dir) |
| 302 | if config is None: |
| 303 | print(" PASS: Missing file returns None") |
| 304 | passed += 1 |
| 305 | else: |
| 306 | print(" FAIL: Missing file returns None") |
| 307 | print(f" Got: {config}") |
| 308 | failed += 1 |
| 309 | |
| 310 | # Test 3: Invalid YAML returns None |
| 311 | config_path.write_text("invalid: yaml: content:") |
| 312 | config = load_project_commands(project_dir) |
| 313 | if config is None: |
| 314 | print(" PASS: Invalid YAML returns None") |
| 315 | passed += 1 |
| 316 | else: |
| 317 | print(" FAIL: Invalid YAML returns None") |
| 318 | print(f" Got: {config}") |
| 319 | failed += 1 |
| 320 | |
| 321 | # Test 4: Over limit (100 commands) |
| 322 | commands = [f" - name: cmd{i}\n description: Command {i}" for i in range(101)] |
| 323 | config_path.write_text("version: 1\ncommands:\n" + "\n".join(commands)) |
| 324 | config = load_project_commands(project_dir) |
| 325 | if config is None: |
no test coverage detected