mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-22 16:35:20 +08:00
fix(tools): require python3 for Box native file scripts (#2658)
* fix(tools): require python3 for Box native file scripts Unversioned `python` is still Python 2 on some host-rootfs nsjail mounts. Falling back to it made read/write/edit scripts fail with SyntaxError on f-strings (#2603). Resolve only `python3`, and return a clear JSON error when it is missing instead of invoking Python 2. Fixes #2603 * style(tools): format Box interpreter error command Co-authored-by: multica-agent <[email protected]> --------- Co-authored-by: Li-john1021 <[email protected]> Co-authored-by: Chin Rock <[email protected]> Co-authored-by: multica-agent <[email protected]>
This commit is contained in:
co-authored by
multica-agent
Li-john1021
Chin Rock
parent
5c3675f4cc
commit
bce94bd0d9
@@ -747,10 +747,18 @@ class NativeToolLoader(loader.ToolLoader):
|
||||
return f'{str(base).rstrip("/")}/{relative}'
|
||||
|
||||
async def _run_workspace_file_script(self, script: str, query: pipeline_query.Query) -> dict:
|
||||
# Sandbox images built from a host rootfs may only ship `python3`, and a
|
||||
# read-only /usr prevents creating a `python` shim inside the jail, so
|
||||
# resolve the interpreter instead of assuming its name.
|
||||
command = f'PYTHON_BIN=$(command -v python3 || command -v python); "$PYTHON_BIN" - <<\'PY\'\n{script}\nPY'
|
||||
# Box file tools need Python 3 (f-strings, etc.). Prefer `python3` and
|
||||
# never fall back to unversioned `python`, which may still be Python 2
|
||||
# on host-rootfs nsjail mounts (LangBot #2603). Missing python3 yields a
|
||||
# clear JSON error instead of a SyntaxError tool result.
|
||||
command = (
|
||||
'PYTHON_BIN=$(command -v python3 || true); '
|
||||
'if [ -z "$PYTHON_BIN" ]; then '
|
||||
'printf \'%s\\n\' \'{"ok": false, "error": "Python 3 interpreter not found in Box (python3 required for native file tools)"}\'; '
|
||||
'exit 0; '
|
||||
'fi; '
|
||||
f'"$PYTHON_BIN" - <<\'PY\'\n{script}\nPY'
|
||||
)
|
||||
result = await self.ap.box_service.execute_tool(
|
||||
{
|
||||
'command': command,
|
||||
|
||||
@@ -866,7 +866,7 @@ async def test_box_grep_script_serializes_optional_include_as_python(monkeypatch
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_workspace_file_script_resolves_the_sandbox_interpreter():
|
||||
"""Sandboxes built from a host rootfs may only ship `python3`."""
|
||||
"""Native file tools must use python3 and never fall back to python2."""
|
||||
|
||||
captured: dict = {}
|
||||
|
||||
@@ -892,5 +892,7 @@ async def test_workspace_file_script_resolves_the_sandbox_interpreter():
|
||||
|
||||
assert result == {'ok': True}
|
||||
command = captured['command']
|
||||
assert command.startswith('PYTHON_BIN=$(command -v python3 || command -v python)')
|
||||
assert 'command -v python3 || true' in command
|
||||
assert 'python3 required for native file tools' in command
|
||||
assert command.endswith(' - <<\'PY\'\nprint("x")\nPY')
|
||||
assert '|| command -v python)' not in command
|
||||
|
||||
Reference in New Issue
Block a user