Test organization-level config loading.
()
| 474 | |
| 475 | |
| 476 | def test_org_config_loading(): |
| 477 | """Test organization-level config loading.""" |
| 478 | print("\nTesting org config loading:\n") |
| 479 | passed = 0 |
| 480 | failed = 0 |
| 481 | |
| 482 | with tempfile.TemporaryDirectory() as tmpdir: |
| 483 | # Use temporary_home for cross-platform compatibility |
| 484 | with temporary_home(tmpdir): |
| 485 | org_dir = Path(tmpdir) / ".autoforge" |
| 486 | org_dir.mkdir() |
| 487 | org_config_path = org_dir / "config.yaml" |
| 488 | |
| 489 | # Test 1: Valid org config |
| 490 | org_config_path.write_text("""version: 1 |
| 491 | allowed_commands: |
| 492 | - name: jq |
| 493 | description: JSON processor |
| 494 | blocked_commands: |
| 495 | - aws |
| 496 | - kubectl |
| 497 | """) |
| 498 | config = load_org_config() |
| 499 | if config and config["version"] == 1: |
| 500 | if len(config["allowed_commands"]) == 1 and len(config["blocked_commands"]) == 2: |
| 501 | print(" PASS: Load valid org config") |
| 502 | passed += 1 |
| 503 | else: |
| 504 | print(" FAIL: Load valid org config (wrong counts)") |
| 505 | failed += 1 |
| 506 | else: |
| 507 | print(" FAIL: Load valid org config") |
| 508 | print(f" Got: {config}") |
| 509 | failed += 1 |
| 510 | |
| 511 | # Test 2: Missing file returns None |
| 512 | org_config_path.unlink() |
| 513 | config = load_org_config() |
| 514 | if config is None: |
| 515 | print(" PASS: Missing org config returns None") |
| 516 | passed += 1 |
| 517 | else: |
| 518 | print(" FAIL: Missing org config returns None") |
| 519 | failed += 1 |
| 520 | |
| 521 | # Test 3: Non-string command name is rejected |
| 522 | org_config_path.write_text("""version: 1 |
| 523 | allowed_commands: |
| 524 | - name: 123 |
| 525 | description: Invalid numeric name |
| 526 | """) |
| 527 | config = load_org_config() |
| 528 | if config is None: |
| 529 | print(" PASS: Non-string command name rejected") |
| 530 | passed += 1 |
| 531 | else: |
| 532 | print(" FAIL: Non-string command name rejected") |
| 533 | print(f" Got: {config}") |
no test coverage detected