Skip to content

Commit 8d37d25

Browse files
committed
test: add integration test for @ mention file support
1 parent bf0b5c8 commit 8d37d25

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import subprocess
2+
import time
3+
import sys
4+
import os
5+
import tempfile
6+
7+
8+
def run_integration_test():
9+
print("Starting Integration Test for '@' file mention...")
10+
11+
env = os.environ.copy()
12+
env["PYTHONPATH"] = os.getcwd() + ":" + env.get("PYTHONPATH", "")
13+
14+
# Create a temp file with distinctive content
15+
tmpdir = tempfile.mkdtemp()
16+
test_filename = os.path.join(tmpdir, "secret_phrase.txt")
17+
secret_content = "XYZZY_UNIQUE_SECRET_42"
18+
with open(test_filename, "w") as f:
19+
f.write(f"The magic word is: {secret_content}\n")
20+
21+
process = subprocess.Popen(
22+
[sys.executable, "-m", "iclaw.main"],
23+
stdin=subprocess.PIPE,
24+
stdout=subprocess.PIPE,
25+
stderr=subprocess.STDOUT,
26+
text=True,
27+
bufsize=1,
28+
cwd=os.getcwd(),
29+
env=env,
30+
)
31+
32+
try:
33+
# 1. Wait for prompt
34+
print("Waiting for prompt...")
35+
output = ""
36+
start_time = time.time()
37+
while time.time() - start_time < 30:
38+
char = process.stdout.read(1)
39+
if not char:
40+
break
41+
output += char
42+
if "> " in output:
43+
print("Prompt detected.")
44+
break
45+
46+
if "> " not in output:
47+
print(f"Timed out waiting for prompt. Last output: {output}")
48+
return False
49+
50+
# 2. Send message with @ mention of the test file
51+
print(f"Sending message with @{test_filename}...")
52+
request = (
53+
f"What is written in @{test_filename} ? Just repeat the exact content.\n"
54+
)
55+
process.stdin.write(request)
56+
process.stdin.flush()
57+
58+
# 3. Wait for the LLM response containing the secret phrase
59+
print("Monitoring for response containing file content...")
60+
found_content = False
61+
start_time = time.time()
62+
output = ""
63+
while time.time() - start_time < 60:
64+
char = process.stdout.read(1)
65+
if not char:
66+
break
67+
output += char
68+
sys.stdout.write(char)
69+
sys.stdout.flush()
70+
71+
if secret_content in output:
72+
found_content = True
73+
74+
# Wait for next prompt to confirm response is complete
75+
if found_content and output.endswith("> "):
76+
break
77+
78+
if found_content:
79+
print(f"\nLLM response contained file content ({secret_content}).")
80+
print("\nIntegration Test PASSED!")
81+
return True
82+
else:
83+
print("\nIntegration Test FAILED (file content not found in response).")
84+
print(f"Output was:\n{output}")
85+
return False
86+
87+
finally:
88+
process.terminate()
89+
if os.path.exists(test_filename):
90+
os.remove(test_filename)
91+
if os.path.exists(tmpdir):
92+
os.rmdir(tmpdir)
93+
94+
95+
if __name__ == "__main__":
96+
if run_integration_test():
97+
sys.exit(0)
98+
else:
99+
sys.exit(1)

0 commit comments

Comments
 (0)