完整的 Bash 执行流程
()
| 727 | # ============================================================ |
| 728 | |
| 729 | def demo_full_workflow(): |
| 730 | """完整的 Bash 执行流程""" |
| 731 | print("\n" + "=" * 60) |
| 732 | print("完整 Bash 执行流程演示") |
| 733 | print("=" * 60) |
| 734 | |
| 735 | # 模拟模型发送的命令 |
| 736 | test_cases = [ |
| 737 | # 场景 1: 普通命令 |
| 738 | BashCommandInput( |
| 739 | command="echo 'hello world'", |
| 740 | timeout=5000, |
| 741 | description="Print hello", |
| 742 | ), |
| 743 | # 场景 2: 超时命令 |
| 744 | BashCommandInput( |
| 745 | command="sleep 10", |
| 746 | timeout=500, # 500ms 超时 |
| 747 | description="This will timeout", |
| 748 | ), |
| 749 | # 场景 3: 失败命令 |
| 750 | BashCommandInput( |
| 751 | command="exit 1", |
| 752 | timeout=5000, |
| 753 | description="Expected failure", |
| 754 | ), |
| 755 | ] |
| 756 | |
| 757 | for i, inp in enumerate(test_cases, 1): |
| 758 | print(f"\n--- 场景 {i}: {inp.description} ---") |
| 759 | print(f"命令: {inp.command}") |
| 760 | |
| 761 | output = execute_bash(inp) |
| 762 | |
| 763 | print(f"stdout: {output.stdout.strip() or '(empty)'}") |
| 764 | if output.stderr: |
| 765 | print(f"stderr: {output.stderr.strip()}") |
| 766 | print(f"interrupted: {output.interrupted}") |
| 767 | if output.return_code_interpretation: |
| 768 | print(f"返回码: {output.return_code_interpretation}") |
| 769 | if output.sandbox_status: |
| 770 | print(f"沙箱启用: {output.sandbox_status.enabled}") |
| 771 | print(f"沙箱生效: {output.sandbox_status.active}") |
| 772 | if output.sandbox_status.fallback_reason: |
| 773 | print(f"降级原因: {output.sandbox_status.fallback_reason}") |
| 774 | |
| 775 | |
| 776 | def demo_sandbox_decision_tree(): |
no test coverage detected