Add regression tests for code_interpreter middleware PTC allowlist

- Ensure 'task' is excluded from the default PTC allowlist to prevent ValueError in langchain-quickjs >=0.3.
- Verify that essential async dispatch tools remain in the allowlist.
- Confirm that the live quickjs filter accepts the default allowlist even with a 'task' tool present.
- Test the creation of the code_interpreter middleware to ensure it builds correctly.
This commit is contained in:
X-iZhang
2026-06-23 08:40:35 +01:00
parent 9460b9ecd6
commit c063a00c8f
8 changed files with 146 additions and 36 deletions
+47
View File
@@ -0,0 +1,47 @@
"""Regression tests for the code_interpreter PTC allowlist.
langchain-quickjs >=0.3 reserves the ``task`` sub-agent dispatch tool as the
top-level REPL global and raises ``ValueError`` if ``task`` appears in the
``ptc`` allowlist. EvoScientist must therefore keep ``task`` out of the
allowlist (``task()`` stays reachable as the REPL global, with responseSchema).
"""
from __future__ import annotations
import pytest
from EvoScientist.middleware.code_interpreter import (
_DEFAULT_PTC_ALLOWLIST,
create_code_interpreter_middleware,
)
def test_task_excluded_from_ptc_allowlist():
# Exposing `task` via ptc raises on quickjs >=0.3 — it is the REPL global.
assert "task" not in _DEFAULT_PTC_ALLOWLIST
def test_async_dispatch_tools_remain_in_allowlist():
# Guard against over-deletion: async fan-out is the killer PTC use case.
for name in ("start_async_task", "check_async_task", "list_async_tasks"):
assert name in _DEFAULT_PTC_ALLOWLIST
def test_filter_tools_for_ptc_accepts_default_allowlist():
# End-to-end guard: the live quickjs filter must accept our allowlist even
# when a `task` tool is present in the agent toolset.
_ptc = pytest.importorskip("langchain_quickjs._ptc")
from langchain_core.tools import tool
@tool
def task(description: str) -> str:
"""dummy sub-agent dispatch tool"""
return "ok"
_ptc.filter_tools_for_ptc(
[task], _DEFAULT_PTC_ALLOWLIST, self_tool_name="code_interpreter"
)
def test_create_code_interpreter_middleware_builds():
assert create_code_interpreter_middleware() is not None