|
| 1 | +import subprocess |
| 2 | +import time |
| 3 | +import sys |
| 4 | +import os |
| 5 | + |
| 6 | + |
| 7 | +def run_integration_test(): |
| 8 | + print("🚀 Starting Integration Test for 'exec' tool...") |
| 9 | + |
| 10 | + # Ensure current directory is in PYTHONPATH for the subprocess |
| 11 | + env = os.environ.copy() |
| 12 | + env["PYTHONPATH"] = os.getcwd() + ":" + env.get("PYTHONPATH", "") |
| 13 | + |
| 14 | + # Start the mini-copilot process |
| 15 | + process = subprocess.Popen( |
| 16 | + [sys.executable, "-m", "mini_copilot.main"], |
| 17 | + stdin=subprocess.PIPE, |
| 18 | + stdout=subprocess.PIPE, |
| 19 | + stderr=subprocess.STDOUT, # Combine stdout and stderr |
| 20 | + text=True, |
| 21 | + bufsize=1, |
| 22 | + cwd=os.getcwd(), |
| 23 | + env=env, |
| 24 | + ) |
| 25 | + |
| 26 | + try: |
| 27 | + # 1. Wait for prompt |
| 28 | + print("Waiting for prompt...") |
| 29 | + output = "" |
| 30 | + start_time = time.time() |
| 31 | + while time.time() - start_time < 30: |
| 32 | + char = process.stdout.read(1) |
| 33 | + if not char: |
| 34 | + break |
| 35 | + output += char |
| 36 | + if "> " in output: |
| 37 | + print("✅ Prompt detected.") |
| 38 | + break |
| 39 | + |
| 40 | + if "> " not in output: |
| 41 | + print(f"❌ Timed out waiting for prompt. Last output: {output}") |
| 42 | + return False |
| 43 | + |
| 44 | + # 2. Trigger tool |
| 45 | + print("Sending message to trigger 'exec' tool...") |
| 46 | + process.stdin.write("run command: echo integration_test_success\n") |
| 47 | + process.stdin.flush() |
| 48 | + |
| 49 | + # 3. Look for tool execution |
| 50 | + print("Monitoring for tool invocation and response...") |
| 51 | + found_tool = False |
| 52 | + found_output = False |
| 53 | + start_time = time.time() |
| 54 | + output = "" |
| 55 | + while time.time() - start_time < 60: |
| 56 | + char = process.stdout.read(1) |
| 57 | + if not char: |
| 58 | + break |
| 59 | + output += char |
| 60 | + sys.stdout.write(char) # Echo for observability |
| 61 | + sys.stdout.flush() |
| 62 | + |
| 63 | + if "[exec] Running command: echo integration_test_success" in output: |
| 64 | + found_tool = True |
| 65 | + |
| 66 | + if "integration_test_success" in output and found_tool: |
| 67 | + found_output = True |
| 68 | + print("\n✅ Found expected output in responses!") |
| 69 | + break |
| 70 | + |
| 71 | + if found_output: |
| 72 | + print("\n🎉 Integration Test PASSED!") |
| 73 | + return True |
| 74 | + else: |
| 75 | + print("\n❌ Integration Test FAILED.") |
| 76 | + return False |
| 77 | + |
| 78 | + finally: |
| 79 | + process.terminate() |
| 80 | + |
| 81 | + |
| 82 | +if __name__ == "__main__": |
| 83 | + if run_integration_test(): |
| 84 | + sys.exit(0) |
| 85 | + else: |
| 86 | + sys.exit(1) |
0 commit comments