Test command hierarchy resolution.
()
| 567 | |
| 568 | |
| 569 | def test_hierarchy_resolution(): |
| 570 | """Test command hierarchy resolution.""" |
| 571 | print("\nTesting hierarchy resolution:\n") |
| 572 | passed = 0 |
| 573 | failed = 0 |
| 574 | |
| 575 | with tempfile.TemporaryDirectory() as tmphome: |
| 576 | with tempfile.TemporaryDirectory() as tmpproject: |
| 577 | # Use temporary_home for cross-platform compatibility |
| 578 | with temporary_home(tmphome): |
| 579 | org_dir = Path(tmphome) / ".autoforge" |
| 580 | org_dir.mkdir() |
| 581 | org_config_path = org_dir / "config.yaml" |
| 582 | |
| 583 | # Create org config with allowed and blocked commands |
| 584 | org_config_path.write_text("""version: 1 |
| 585 | allowed_commands: |
| 586 | - name: jq |
| 587 | description: JSON processor |
| 588 | - name: python3 |
| 589 | description: Python interpreter |
| 590 | blocked_commands: |
| 591 | - terraform |
| 592 | - kubectl |
| 593 | """) |
| 594 | |
| 595 | project_dir = Path(tmpproject) |
| 596 | project_autoforge = project_dir / ".autoforge" |
| 597 | project_autoforge.mkdir() |
| 598 | project_config = project_autoforge / "allowed_commands.yaml" |
| 599 | |
| 600 | # Create project config |
| 601 | project_config.write_text("""version: 1 |
| 602 | commands: |
| 603 | - name: swift |
| 604 | description: Swift compiler |
| 605 | """) |
| 606 | |
| 607 | # Test 1: Org allowed commands are included |
| 608 | allowed, blocked = get_effective_commands(project_dir) |
| 609 | if "jq" in allowed and "python3" in allowed: |
| 610 | print(" PASS: Org allowed commands included") |
| 611 | passed += 1 |
| 612 | else: |
| 613 | print(" FAIL: Org allowed commands included") |
| 614 | print(f" jq in allowed: {'jq' in allowed}") |
| 615 | print(f" python3 in allowed: {'python3' in allowed}") |
| 616 | failed += 1 |
| 617 | |
| 618 | # Test 2: Org blocked commands are in blocklist |
| 619 | if "terraform" in blocked and "kubectl" in blocked: |
| 620 | print(" PASS: Org blocked commands in blocklist") |
| 621 | passed += 1 |
| 622 | else: |
| 623 | print(" FAIL: Org blocked commands in blocklist") |
| 624 | failed += 1 |
| 625 | |
| 626 | # Test 3: Project commands are included |
no test coverage detected