8cb0531959
* fix(lint): organize imports in queen_orchestrator.create_queen Ruff I001 blocks CI on every PR against main. The deferred imports inside create_queen were not in alphabetical order between the queen package and the framework package; ruff auto-fix moves framework.config below the framework.agents.queen.nodes block. No behavior change. * fix(ci): install Playwright Chromium before Test Tools job The new chart_tools smoke tests added infeabf327require a Chromium build for ECharts/Mermaid rendering, but the test-tools workflow only ran `uv sync` and went straight to pytest. Three tests (test_render_echarts_bar_chart, test_render_echarts_accepts_string_spec, test_render_mermaid_flowchart) crash on every PR with: BrowserType.launch: Executable doesn't exist at /home/runner/.cache/ms-playwright/chromium_headless_shell-1208/... Split the install/run into separate steps and add `playwright install chromium` before pytest. Use `--with-deps` on Linux to pull system libraries; Windows runners only need the browser binary. * fix(tests): adapt test_file_state_cache to new file_ops API The file_ops rewrite infeabf327dropped the standalone hashline_edit tool (the file_system_toolkits/hashline_edit/ directory was removed) and switched edit_file to a mode-first signature (mode, path, old_string, new_string, ...). The test fixture still tried to look up "hashline_edit" via the MCP tool manager and crashed with KeyError before any test could run, and the edit_file calls were positional in the old order so they hit "unknown mode 'e.py'" once the fixture was fixed. Drop the stale hashline_edit lookup and pass mode="replace" explicitly to every edit_file call. All 11 tests pass locally. * fix(tests): skip terminal_tools tests on Windows (POSIX-only) The new terminal_tools package added infeabf327imports the Unix-only `resource` module in tools/src/terminal_tools/common/limits.py to set RLIMIT_CPU / RLIMIT_AS / RLIMIT_FSIZE on subprocesses. Five of the six terminal_tools test files therefore crash on windows-latest with `ModuleNotFoundError: No module named 'resource'` once their fixtures trigger the import chain. test_terminal_tools_pty.py already has the right module-level skip (PTY is POSIX-only). Apply the same `pytestmark = skipif(win32)` to the other five so the whole suite skips cleanly on Windows. The terminal-tools package is bash-only by design (zsh refused at the shell-resolver level), so a Windows port is out of scope.
99 lines
3.1 KiB
Python
99 lines
3.1 KiB
Python
"""Job lifecycle: ring buffer offsets, signals, stdin."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import pytest
|
|
|
|
pytestmark = pytest.mark.skipif(sys.platform == "win32", reason="terminal_tools is POSIX-only (uses resource module)")
|
|
|
|
|
|
@pytest.fixture
|
|
def job_tools(mcp):
|
|
from terminal_tools.jobs.tools import register_job_tools
|
|
|
|
register_job_tools(mcp)
|
|
return {
|
|
"start": mcp._tool_manager._tools["terminal_job_start"].fn,
|
|
"logs": mcp._tool_manager._tools["terminal_job_logs"].fn,
|
|
"manage": mcp._tool_manager._tools["terminal_job_manage"].fn,
|
|
}
|
|
|
|
|
|
def test_start_logs_wait_basic(job_tools):
|
|
started = job_tools["start"](command="echo first; echo second; echo third", shell=True)
|
|
assert "job_id" in started
|
|
job_id = started["job_id"]
|
|
|
|
# Wait for completion via logs
|
|
result = job_tools["logs"](job_id=job_id, wait_until_exit=True, wait_timeout_sec=5)
|
|
assert result["status"] == "exited"
|
|
assert result["exit_code"] == 0
|
|
assert "first" in result["data"] and "third" in result["data"]
|
|
|
|
|
|
def test_offset_bookkeeping(job_tools):
|
|
started = job_tools["start"](
|
|
command="for i in 1 2 3 4 5; do echo line$i; sleep 0.1; done",
|
|
shell=True,
|
|
)
|
|
job_id = started["job_id"]
|
|
|
|
# Read a couple times with offset bookkeeping
|
|
seen = ""
|
|
offset = 0
|
|
for _ in range(20):
|
|
result = job_tools["logs"](job_id=job_id, since_offset=offset, max_bytes=4096)
|
|
seen += result["data"]
|
|
offset = result["next_offset"]
|
|
if result["status"] == "exited":
|
|
# Drain anything left
|
|
tail = job_tools["logs"](job_id=job_id, since_offset=offset, max_bytes=4096)
|
|
seen += tail["data"]
|
|
break
|
|
time.sleep(0.1)
|
|
|
|
for n in range(1, 6):
|
|
assert f"line{n}" in seen, f"missing line{n} from {seen!r}"
|
|
|
|
|
|
def test_merge_stderr(job_tools):
|
|
started = job_tools["start"](
|
|
command="echo stdout1; echo stderr1 1>&2; echo stdout2",
|
|
shell=True,
|
|
merge_stderr=True,
|
|
)
|
|
job_id = started["job_id"]
|
|
result = job_tools["logs"](job_id=job_id, stream="merged", wait_until_exit=True, wait_timeout_sec=5)
|
|
assert "stdout1" in result["data"]
|
|
assert "stderr1" in result["data"]
|
|
|
|
|
|
def test_signal_term(job_tools):
|
|
started = job_tools["start"](command="sleep 30")
|
|
job_id = started["job_id"]
|
|
|
|
# Give it a moment to actually start
|
|
time.sleep(0.2)
|
|
|
|
result = job_tools["manage"](action="signal_term", job_id=job_id)
|
|
assert result["ok"] is True
|
|
|
|
final = job_tools["logs"](job_id=job_id, wait_until_exit=True, wait_timeout_sec=3)
|
|
assert final["status"] == "exited"
|
|
# On SIGTERM, exit_code is -15 (subprocess convention)
|
|
assert final["exit_code"] == -15
|
|
|
|
|
|
def test_list_action(job_tools):
|
|
started = job_tools["start"](command="sleep 1")
|
|
listing = job_tools["manage"](action="list")
|
|
assert any(j["job_id"] == started["job_id"] for j in listing["jobs"])
|
|
|
|
|
|
def test_unknown_job_id(job_tools):
|
|
result = job_tools["logs"](job_id="job_doesnotexist", wait_until_exit=False)
|
|
assert "error" in result
|