LazyBoy2/tests/live_cli.py

28 lines
1.7 KiB
Python
Raw Normal View History

2026-09-13 16:38:32 +00:00
"""Small opt-in test using the existing model config and a disposable workspace."""
import json
import os
from pathlib import Path
import subprocess
import tempfile
BINARY=Path(__file__).resolve().parents[1]/'target/debug/grokboy'
def main():
with tempfile.TemporaryDirectory(prefix='grokboy-live-') as root:
Path(root,'items.txt').write_text('banana\napple\nbanana\npear\n')
env={**os.environ,'GROKBOY_MAX_ROUNDS_TOTAL':'12','GROKBOY_MAX_ROUNDS':'4',
'GROKBOY_SESSIONS_DIR':str(Path(root,'sessions')),'GROKBOY_PROGRESS':'1'}
prompt='幫我整理目前目錄的 items.txt去除重複、依字母排序另存 clean.txt每行一筆再產生 report.txt用數字記錄原本幾筆、整理後幾筆。請實際讀回兩個產物確認內容最後告訴我結果。只需要操作目前目錄不需要上網。'
result=subprocess.run([str(BINARY),'run',prompt],cwd=root,env=env,stdin=subprocess.DEVNULL,
capture_output=True,text=True,timeout=240)
print(result.stderr[-5000:])
print(result.stdout)
assert result.returncode==0, result.returncode
assert Path(root,'clean.txt').read_text().splitlines()==['apple','banana','pear']
report=Path(root,'report.txt').read_text()
assert '4' in report and '3' in report,report
assert '〔進度〕' in result.stderr or '〔計畫〕' in result.stderr
session=json.loads(next(Path(root,'sessions').glob('*.json')).read_text())
assert session['last_verdict'] in ('done','answer')
print('PASS live model: opening/progress, tools, two verified artifacts and final answer')
if __name__=='__main__':main()