python-yama 0.10.8__tar.gz → 0.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_yama-0.10.8 → python_yama-0.11.0}/PKG-INFO +1 -1
- {python_yama-0.10.8 → python_yama-0.11.0}/docs/agent-skill-test-framework-design.md +23 -49
- {python_yama-0.10.8 → python_yama-0.11.0}/skills/eval-plugin-with-yama/SKILL.md +1 -1
- {python_yama-0.10.8 → python_yama-0.11.0}/skills/eval-plugin-with-yama/references/case-schema.md +15 -5
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_framework.py +130 -10
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_tool_loader.py +6 -3
- python_yama-0.11.0/yama/_matching.py +64 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/loaders/tool_loader.py +18 -16
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/mocks.py +19 -59
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/runner.py +18 -2
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/tools/bash/_cli_shim.py +5 -11
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/tools/bash/bash.py +6 -2
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/tools/bash/fs.py +233 -74
- {python_yama-0.10.8 → python_yama-0.11.0}/.github/workflows/publish.yml +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/.gitignore +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/CLAUDE.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/LICENSE +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/README.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/README.zh-CN.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/docs/case-schema-reference.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/docs/superpowers/plans/2026-08-17-concurrency-defaults.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/docs/superpowers/plans/2026-08-17-step-timeout-failure.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/docs/superpowers/specs/2026-08-17-concurrency-defaults-design.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/docs/superpowers/specs/2026-08-17-step-timeout-failure-design.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/docs/yama-intro.html +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/pyproject.toml +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/skills/eval-plugin-with-yama/references/debugging.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/skills/eval-plugin-with-yama/references/install-upgrade.md +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_assertions.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_cli.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_cli_shim.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_dashboard.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_judge_llm.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_llm.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_main_entrypoint.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_mocks.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_openai_llm.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_pr.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_preview.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_public_api.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_report.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_report_bundle.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_report_upload.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_run_plan.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_runner.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_skill_loader.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_skill_tool.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_thread_case.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_usage.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/tests/test_workspace.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/uv.lock +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/__init__.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/__main__.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/assertions.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/cli.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/dashboard.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/judge_llm.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/judge_routing.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/llm.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/loaders/__init__.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/loaders/case.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/loaders/common.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/loaders/skill_loader.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/models.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/openai_llm.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/pr.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/preview.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/report.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/report_bundle.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/report_upload.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/thread_case.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/tools/__init__.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/tools/base.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/tools/bash/__init__.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/tools/skill/__init__.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/tools/skill/skill.py +0 -0
- {python_yama-0.10.8 → python_yama-0.11.0}/yama/workspace.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: python-yama
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: A reproducible evaluation runner for tool-using Agent skills
|
|
5
5
|
Project-URL: Repository, https://github.com/world-sim-dev/yama
|
|
6
6
|
Project-URL: Issues, https://github.com/world-sim-dev/yama/issues
|
|
@@ -835,7 +835,7 @@ context:
|
|
|
835
835
|
当前内置 Tool 有两个:
|
|
836
836
|
|
|
837
837
|
- `skill`:暴露静态的 Skill 读取 Schema(`name`/`file?`/`call_reason?`,取自生产 skill 工具定义,见 6.4 节),并在未配置 `mocks.tools.skill` 时使用框架内置 Handler;启用集合的约束由默认 Mock 的 `match` 与 Handler 的 `enabled` 检查实现,不在 Schema 里。
|
|
838
|
-
- `bash`:暴露一个命令执行 Tool。默认按 `mocks.cli` 声明的命令返回确定性的 stdout / stderr / exit code,未声明的命令一律 `command not found`(exit code 127),详见 8.4.1;需要模型执行任意命令(包括任意 Python 脚本)时改用 `mocks.fs`,在一个真实、隔离的工作目录里执行真实 shell,详见 8.4.3
|
|
838
|
+
- `bash`:暴露一个命令执行 Tool。默认按 `mocks.cli` 声明的命令返回确定性的 stdout / stderr / exit code,未声明的命令一律 `command not found`(exit code 127),详见 8.4.1;需要模型执行任意命令(包括任意 Python 脚本)时改用 `mocks.fs`,在一个真实、隔离的工作目录里执行真实 shell,详见 8.4.3。可以同时用 `mocks.fs` 配置隔离与文件,并用 `mocks.cli` 声明模拟命令。
|
|
839
839
|
|
|
840
840
|
内置 bash 的 Schema(`loaders/tool_loader.py:_bash_tool_schema`)参考生产 Agent Runner 的 Bash 工具编写:描述是一段完整的使用指引(用途、When to use、Arguments、Execution behavior、Safety constraints),参数为:
|
|
841
841
|
|
|
@@ -1491,7 +1491,7 @@ Runner 收到 bash Tool Call 后,把整条 `command` 字符串原样交给持
|
|
|
1491
1491
|
- 命令未在 `mocks.cli` 中声明、不是 bash 内建命令、且未开启透传(见下)时,得到真实 bash 自己的 `command not found`(`bash: line 2: <name>: command not found\n`,exit code 127;见前述"行号固定为 2"的说明)。
|
|
1492
1492
|
- Handler 返回值统一为 `{stdout, stderr, exit_code}`,由 8.4.3 节的 marker 协议从持久 shell 的真实 stdout/stderr 中截取;这份完整信封保留在 Mock Event 与 `tool_calls[].result` 中供断言使用。但 Runner 发给模型的 Tool Result Message 只取其中的 `stdout + stderr`(`runner.py:_tool_result_content`,不加分隔符地原样拼接,不再是三个字段的 JSON),贴近真实终端工具"给什么就是什么"的观感;`exit_code` 不出现在模型看到的内容里,模型只能通过输出文本本身判断命令是否成功。这个"bash 形状结果特判"逻辑位于 `runner.py`,而非 `mocks.py`。
|
|
1493
1493
|
|
|
1494
|
-
`mocks.cli` 只服务于内置 bash 执行实现:Case 里没有任何 `handler: {builtin: bash}` Mock(既没声明 `{builtin: bash}`,也没有自定义 Tool 指向 builtin handler)时出现 `mocks.cli` 在 collection 阶段失败(`"mocks.cli requires a builtin bash handler: ..."`);声明了 `{builtin: bash}` 却用自定义 `mocks.tools.bash` Handler 覆盖其 Mock 时同样失败(`"mocks.cli cannot be combined with a custom mocks.tools.bash handler"
|
|
1494
|
+
`mocks.cli` 只服务于内置 bash 执行实现:Case 里没有任何 `handler: {builtin: bash}` Mock(既没声明 `{builtin: bash}`,也没有自定义 Tool 指向 builtin handler)时出现 `mocks.cli` 在 collection 阶段失败(`"mocks.cli requires a builtin bash handler: ..."`);声明了 `{builtin: bash}` 却用自定义 `mocks.tools.bash` Handler 覆盖其 Mock 时同样失败(`"mocks.cli cannot be combined with a custom mocks.tools.bash handler"`);可以与 `mocks.fs` 共用一个会话(8.4.3 节)。多个 Tool 的 Mock 都指向 `handler: {builtin: bash}` 时共享同一份 `mocks.cli`/`mocks.fs` 执行配置与同一个沙箱会话。
|
|
1495
1495
|
|
|
1496
1496
|
#### 8.4.2 透传:找不到 Mock 时执行真实命令
|
|
1497
1497
|
|
|
@@ -1520,7 +1520,7 @@ mocks:
|
|
|
1520
1520
|
节点/规则级 `passthrough: true`(与 `stdout`/`stderr`/`exit_code` 互斥,同时出现在 collection 阶段失败;`cat: { passthrough: true }` 这种命令级简写其实是一条"无 `match` 的透传规则",并非独立字段——是统一规则/节点语法的自然产物)编译进该命令的规则树后,由 `yama.tools.bash._cli_shim` 在匹配到这条规则时执行 `os.execvpe`,把自己替换成真实二进制——`exec` 时使用的 `PATH` 来自会话环境变量 `YAMA_REAL_PATH`(真实系统 PATH,与 `.mockbin/` 无关),避免二次调用又绕回自己的 shadow 脚本。
|
|
1521
1521
|
|
|
1522
1522
|
- `mocks.cli.passthrough_timeout_seconds`(正数,默认 30):单条命令的超时时间;超时会杀掉整个进程组、重启一个新的沙箱会话(cwd 重置为初始值),以统一的 `BASH_TIMEOUT` 错误返回给模型——不再区分"mock 超时"和"透传超时",因为二者现在共用同一个执行引擎和同一个超时机制。仍受 `execution.timeout_seconds_per_step` 总预算约束。
|
|
1523
|
-
- 会话的工作目录是 8.4.3 节描述的隔离沙箱工作目录(`.yama/fs-runs/<case-key>/run-{run_index:03d}/`),不再是 Plugin 根目录;普通 `yama` 运行下 `mocks.cli` 默认使用 `backend: none`(不做 OS 级隔离,`fs.py:compile_cli_config` 硬编码),因此像 `../escape.txt` 这样的写入不会被这一层拦截——它会落在沙箱工作目录的上一级(仍在框架自己的 `.yama/fs-runs/` 树内,不会碰到 Plugin 的真实源码目录),需要 OS 级写入边界时改用 `mocks.fs`,让 `backend: auto` 在 macOS/Linux 上选择对应 backend,或显式选择 `macos-sandbox-exec` / `linux-bubblewrap`。`yama pr-run` 是例外:它会把内置 bash 的执行 backend 统一覆盖为 `linux-bubblewrap`,包括由 `mocks.cli` 编译出来的执行配置。
|
|
1523
|
+
- 会话的工作目录是 8.4.3 节描述的隔离沙箱工作目录(`.yama/fs-runs/<case-key>/run-{run_index:03d}/`),不再是 Plugin 根目录;普通 `yama` 运行下 `mocks.cli` 默认使用 `backend: none`(不做 OS 级隔离,`fs.py:compile_cli_config` 硬编码),因此像 `../escape.txt` 这样的写入不会被这一层拦截——它会落在沙箱工作目录的上一级(仍在框架自己的 `.yama/fs-runs/` 树内,不会碰到 Plugin 的真实源码目录),需要 OS 级写入边界时改用 `mocks.fs`,让 `backend: auto` 在 macOS/Linux 上选择对应 backend,或显式选择 `macos-sandbox-exec` / `linux-bubblewrap`。`yama pr-run` 是例外:它会把内置 bash 的执行 backend 统一覆盖为 `linux-bubblewrap`,并启用 `read_scope: workspace`,包括由 `mocks.cli` 编译出来的执行配置。
|
|
1524
1524
|
- 透传是显式的安全逃生舱:开启后,模型产生的 Tool Call 会执行真实子进程,不再是纯确定性回放。建议只在本地联调、且信任模型不会拿到危险命令时启用;CI 或需要严格可重复结果的场景应保持默认关闭,逐个命令补齐 Mock。
|
|
1525
1525
|
|
|
1526
1526
|
#### 8.4.3 `mocks.fs`:真实沙箱工作区
|
|
@@ -1529,7 +1529,9 @@ mocks:
|
|
|
1529
1529
|
|
|
1530
1530
|
`mocks.cli` 与 `mocks.fs` 底层是**同一套执行引擎**(`yama/tools/bash/fs.py` 的持久 shell 会话):区别只在于沙箱工作目录里预先放了什么——`mocks.fs.files`/`mocks.fs.bin` 是 Case 作者直接声明的内容,`mocks.cli` 是框架把声明式规则树编译成的 `.mockbin/` 脚本(8.4.1 节)。两者因此共享本节描述的生命周期、marker 协议、PATH shadow 机制、rlimit/环境变量护栏;普通 `yama` 运行下差别仅是 `mocks.cli` 固定用 `backend: none`(不叠加 OS 级 backend),而 `mocks.fs` 默认 `backend: auto`;`yama pr-run` 会把二者统一覆盖为 `linux-bubblewrap`。会话环境变量里始终有 `YAMA_WORKSPACE`(沙箱工作目录绝对路径)、`YAMA_PYTHON`(运行 yama 的解释器路径)、`YAMA_REAL_PATH`(未叠加 `.mockbin/` 的真实系统 PATH,供节点/规则级 `passthrough: true` 或用户自己的 `mocks.fs.bin` 脚本按需 `exec` 真实二进制)。
|
|
1531
1531
|
|
|
1532
|
-
`mocks.fs` 与 `mocks.cli`
|
|
1532
|
+
`mocks.fs` 与 `mocks.cli` 可以同时使用。会话按 `mocks.fs` 读取文件和执行命令,
|
|
1533
|
+
同时从 `.mockbin/` 查找声明式 CLI mock。重复定义同名命令会在 collection 阶段报错。
|
|
1534
|
+
两个配置都要求 Case 使用 `{builtin: bash}` 或 `handler: {builtin: bash}`。
|
|
1533
1535
|
|
|
1534
1536
|
**配置 Schema:**
|
|
1535
1537
|
|
|
@@ -1544,6 +1546,8 @@ mocks:
|
|
|
1544
1546
|
network: false # 可选,默认 false,是否放行沙箱内的网络访问
|
|
1545
1547
|
backend: auto # 可选:auto(默认)| macos-sandbox-exec | linux-bubblewrap | none
|
|
1546
1548
|
|
|
1549
|
+
read_scope: workspace # workspace | host;有 OS 沙箱时默认 workspace
|
|
1550
|
+
|
|
1547
1551
|
files: # 相对路径 -> 初始内容
|
|
1548
1552
|
project/README.md: |
|
|
1549
1553
|
# Demo
|
|
@@ -1570,17 +1574,15 @@ mocks:
|
|
|
1570
1574
|
|
|
1571
1575
|
**生命周期:** 每次 run(含 `execution.repeat` 的每一轮)的沙箱工作目录是
|
|
1572
1576
|
`<plugin_root>/.yama/fs-runs/<sanitized-case-key>/run-{run_index:03d}/`(三位数字
|
|
1573
|
-
零填充,如 `run-001
|
|
1574
|
-
持久
|
|
1577
|
+
零填充,如 `run-001`)。声明 `mocks.fs` 时,文件在首轮模型请求前物化。
|
|
1578
|
+
持久 Bash 子进程在第一次调用时启动。这个路径是 `plugin_root/case_key/run_index` 的纯函数,Python
|
|
1575
1579
|
Handler 可以在物化发生之前就用包根导出的 `workspace_dir(context)`(定义在
|
|
1576
1580
|
`tools/bash/fs.py`)预先计算它;首次物化时同一路径也会写入共享 state 的
|
|
1577
1581
|
`__fs__.workspace_dir`,供没有 `ToolMockContext` 的 Python Checker 读取。
|
|
1578
1582
|
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
`.mockbin/` 假命令和编译后的 `mocks.cli` 规则文件全部写到最新状态;run 中途因超时/
|
|
1583
|
-
会话死亡而重建 shell 会话时则不再重复物化,模型已写入的文件得以保留。此外
|
|
1583
|
+
每个 run 会展开初始消息、步骤、状态、mock 配置及自定义 Python mock 返回值中的
|
|
1584
|
+
`{{workspace}}`。例如 `{{workspace}}/work/input.json` 对应 `mocks.fs.files` 的相对路径
|
|
1585
|
+
`work/input.json`。`__fs__` 标记保证超时或会话死亡后的 shell 重启保留当前 run 的文件。此外
|
|
1584
1586
|
`YamaRunner.run_case` 在一个 Case 的第一轮 run 开始前会整体删除
|
|
1585
1587
|
`.yama/fs-runs/<sanitized-case-key>/`(`runner.py:_clean_case_dirs`)——run 编号每次
|
|
1586
1588
|
执行都从 1 重新计数,不先清掉上一次执行遗留的同名工作目录,本次执行就会复用过期的
|
|
@@ -1622,44 +1624,16 @@ printf '%s %d\n' '<marker>' "$__yama_ec__" 1>&2
|
|
|
1622
1624
|
|
|
1623
1625
|
**命令级拦截:PATH shadow 而不是 argv 匹配。** 真实执行下没法安全地在管道中间插入一段模拟结果(`real | mocked | real` 要求真的把标准流接起来喂给模拟阶段)。`mocks.fs.bin` 声明的脚本会被写到工作目录下 `.mockbin/` 并加执行权限,这个目录被 prepend 进沙箱的 `PATH`;任何位置——包括管道、`&&`、子 shell 内部——只要调用到这个命令名,系统真实的 PATH 解析就会找到这个"假二进制",不需要框架自己再解析一次命令行。
|
|
1624
1626
|
|
|
1625
|
-
**macOS
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
(version 1)
|
|
1629
|
-
(deny default)
|
|
1630
|
-
|
|
1631
|
-
(allow process-fork)
|
|
1632
|
-
(allow process-exec)
|
|
1633
|
-
(allow signal (target self))
|
|
1634
|
-
(allow sysctl-read)
|
|
1635
|
-
(allow mach-lookup)
|
|
1636
|
-
(allow iokit-open)
|
|
1637
|
-
|
|
1638
|
-
(allow file-read*)
|
|
1639
|
-
(allow file-write* (subpath "<workspace>"))
|
|
1640
|
-
(allow file-write-data (literal "/dev/null") (literal "/dev/tty") (literal "/dev/dtracehelper"))
|
|
1641
|
-
|
|
1642
|
-
(deny file-read* (subpath "<home>/.ssh"))
|
|
1643
|
-
(deny file-read* (subpath "<home>/.aws"))
|
|
1644
|
-
(deny file-read* (subpath "<home>/.config/gcloud"))
|
|
1645
|
-
(deny file-read* (subpath "<home>/.gnupg"))
|
|
1646
|
-
(deny file-read* (subpath "<home>/Library/Keychains"))
|
|
1647
|
-
|
|
1648
|
-
(deny network*) ; network: true 时省略这条
|
|
1649
|
-
```
|
|
1627
|
+
**macOS 后端 `sandbox-exec`。** 每个 run 的 profile 位于工作目录旁边,例如 `run-001.sb`。
|
|
1628
|
+
`workspace` 允许读取当前 run、系统依赖和解释器运行时,并限制写入当前 run 和必要的设备文件。
|
|
1629
|
+
`host` 保留原来的读取规则及敏感目录屏蔽。macOS 的绝对 `/tmp` 仍受写入限制。
|
|
1650
1630
|
|
|
1651
|
-
|
|
1631
|
+
**Linux 后端 `bubblewrap`。** `workspace` 从空挂载空间开始,只读挂载系统和 Python
|
|
1632
|
+
运行时,可写挂载当前 run,并提供独立 `/tmp`。`host` 保留宿主根目录的只读挂载,并遮住
|
|
1633
|
+
原始 HOME 与 `/tmp`。两个模式默认使用独立的网络命名空间。
|
|
1652
1634
|
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
false` 时加 `--unshare-net`,把宿主根目录只读挂载,把 yama 工作目录可写 bind 到同一路径,
|
|
1656
|
-
把 `/tmp` 和当前用户 `HOME` 覆盖成 tmpfs,并 `--chdir` 到 `mocks.fs.cwd` 指定的初始目录。
|
|
1657
|
-
这给 eval 提供写入边界和默认网络边界,同时保留足够的只读系统路径让 bash、Python 解释器
|
|
1658
|
-
和 `.mockbin` shim 正常运行。它不是面向任意不可信代码的强保密沙箱:宿主根目录大部分仍
|
|
1659
|
-
可只读访问,只是当前用户 HOME 被 tmpfs 遮住以避免常见凭据目录被读到。Linux runner 缺少
|
|
1660
|
-
`bwrap`/`bubblewrap` 二进制时会报
|
|
1661
|
-
`"mocks.fs.backend: linux-bubblewrap requires bubblewrap; install the bwrap package"`;
|
|
1662
|
-
Ubuntu 系 CI 里通常需要先安装 `bubblewrap` 包。
|
|
1635
|
+
`workspace` 模式为每个 run 设置独立的 `HOME`、`TMPDIR` 和 Python 缓存目录。PR 评测
|
|
1636
|
+
强制使用 `linux-bubblewrap` 和 `workspace`,需要提前安装 `bubblewrap`。
|
|
1663
1637
|
|
|
1664
1638
|
其他平台的 `backend: auto` 在 collection 阶段直接报错(`"mocks.fs has no sandboxing
|
|
1665
1639
|
backend on this platform; set mocks.fs.backend: none to run without OS-level isolation"`),
|
|
@@ -1678,7 +1652,7 @@ backend on this platform; set mocks.fs.backend: none to run without OS-level iso
|
|
|
1678
1652
|
context.tools: [{builtin: bash}] # 或自定义 Tool + handler: {builtin: bash}
|
|
1679
1653
|
│
|
|
1680
1654
|
▼
|
|
1681
|
-
loaders.tool_loader.resolve_builtin_handlers #
|
|
1655
|
+
loaders.tool_loader.resolve_builtin_handlers # 校验并归一化 mocks.cli 和 mocks.fs
|
|
1682
1656
|
│ 把每条 handler: {builtin: bash} 展开为
|
|
1683
1657
|
│ handler.python = "yama.tools.bash.bash:run_bash"
|
|
1684
1658
|
▼
|
|
@@ -2639,7 +2613,7 @@ def check(
|
|
|
2639
2613
|
- `step_result` 是当前 Step 的 `StepResult`,其 `tool_calls` 是 `ToolCallRecord` 列表(`request_index`/`call_index`/`call: ToolCall`/`result`/`is_error`)。
|
|
2640
2614
|
- `transcript` 是截至当前 Step 结束的完整消息序列的深拷贝元组(包含本 Step 的 user/assistant/tool 消息),只读。
|
|
2641
2615
|
- `state` 与 Python Handler 共享同一个 run 级 Mock state dict(不是拷贝);`config` 是该断言 `with:` 的深拷贝,未写时为 `{}`。
|
|
2642
|
-
- Checker 没有 `ToolMockContext`,需要 bash 沙箱工作目录时读 `state["__fs__"]["workspace_dir"]
|
|
2616
|
+
- Checker 没有 `ToolMockContext`,需要 bash 沙箱工作目录时读 `state["__fs__"]["workspace_dir"]`(由 8.4.3 的工作区物化逻辑写入)。
|
|
2643
2617
|
|
|
2644
2618
|
所有 Hard Assert 按声明顺序执行并分别保存结果,**不会短路**:任一失败都会令当前 Step 的 `hard_pass=false`;后续 Hard Assert 仍继续执行,以便一次报告全部确定性问题。
|
|
2645
2619
|
|
|
@@ -134,7 +134,7 @@ outcome:
|
|
|
134
134
|
Skill 名或 Tool 名。
|
|
135
135
|
4. 每个 Tool 条目在 `builtin` / `file` / `inline` 中三选一;`mocks.tools.<name>` 的
|
|
136
136
|
`respond` 与 `handler` 二选一。
|
|
137
|
-
5. `mocks.cli`
|
|
137
|
+
5. `mocks.cli` 和 `mocks.fs` 可共用一个沙箱会话,且都要求 Case 里存在内置 bash 执行——声明
|
|
138
138
|
`{builtin: bash}`,或某个 Tool 的 Mock 使用 `handler: {builtin: bash}`;
|
|
139
139
|
也不能与自定义 `mocks.tools.bash` Handler 并存。
|
|
140
140
|
6. `steps` 至少一个,每个 Step 必须有 Case 内唯一的 `id` 和 `user`。
|
{python_yama-0.10.8 → python_yama-0.11.0}/skills/eval-plugin-with-yama/references/case-schema.md
RENAMED
|
@@ -281,7 +281,9 @@ mocks:
|
|
|
281
281
|
|
|
282
282
|
### `{builtin: bash}` + mocks.fs:真实沙箱工作区
|
|
283
283
|
|
|
284
|
-
|
|
284
|
+
用 `mocks.fs` 配置 Bash 的运行目录和读取权限,也可同时用 `mocks.cli` 声明模拟命令。
|
|
285
|
+
组合使用时,未被模拟的命令仍可从系统 `PATH` 查找。同一个命令名只能在
|
|
286
|
+
`mocks.fs.bin` 和 `mocks.cli` 中声明一次。
|
|
285
287
|
|
|
286
288
|
```yaml
|
|
287
289
|
mocks:
|
|
@@ -289,6 +291,7 @@ mocks:
|
|
|
289
291
|
cwd: project # 初始 cwd,相对工作目录
|
|
290
292
|
network: false # 默认拒绝网络
|
|
291
293
|
backend: auto # macOS=sandbox-exec;Linux=bubblewrap;其它平台显式 none
|
|
294
|
+
read_scope: workspace # workspace | host
|
|
292
295
|
files:
|
|
293
296
|
project/README.md: "# Demo\n"
|
|
294
297
|
project/src/main.py: { file: fixtures/main.py, mode: "0755" }
|
|
@@ -303,14 +306,21 @@ mocks:
|
|
|
303
306
|
- 工作目录:`<plugin_root>/.yama/fs-runs/<case-key>/run-00N/`,run 结束**不清理**,
|
|
304
307
|
供排查;下一次执行同一 Case 时才整体清掉重建(改 mock 配置后重跑不会复用旧
|
|
305
308
|
`.mockbin` 脚本)。持久 bash 会话贯穿整个 run,`cd`/`export`/写文件状态自然延续。
|
|
309
|
+
- 有 OS 沙箱时,`read_scope` 默认 `workspace`,可读取当前 run、系统工具及 Python 运行时。
|
|
310
|
+
`HOME`、`TMPDIR` 和 Python 字节码缓存使用 run 内的目录。`host` 使用该后端原有的读取策略。
|
|
311
|
+
`backend: none` 仅支持 `host`。
|
|
312
|
+
- 字符串值可使用 `{{workspace}}`,例如 `{{workspace}}/work/input.json`。每个 run 会展开
|
|
313
|
+
初始消息、步骤、`mocks.state` 和 mock 配置(包括声明式返回值和 `mocks.cli` 输出),
|
|
314
|
+
也会展开自定义 Python mock 返回的字符串值。
|
|
315
|
+
在 `mocks.fs.files` 中以相对路径 `work/input.json` 声明文件。
|
|
306
316
|
- Python Handler 可用 `from yama import workspace_dir` 提前算出该路径
|
|
307
|
-
(`workspace_dir(context)
|
|
308
|
-
|
|
317
|
+
(`workspace_dir(context)`,物化前即可调用)。显式配置 `mocks.fs` 时,yama 在模型首轮
|
|
318
|
+
请求前物化文件并写入共享 state 的 `__fs__.workspace_dir`,供 Python Checker 读取。
|
|
309
319
|
- 单条命令超时(默认 30s;模型通过 bash Tool 的 `timeout_seconds` 参数请求更短
|
|
310
320
|
超时会生效,超过配置上限被钳到上限)→ `BASH_TIMEOUT` 错误返回给模型并重启会话。
|
|
311
321
|
- 会话内可用环境变量:`YAMA_WORKSPACE`、`YAMA_PYTHON`、`YAMA_REAL_PATH`。
|
|
312
|
-
- `yama pr-run` 面向 Linux CI runner
|
|
313
|
-
|
|
322
|
+
- `yama pr-run` 面向 Linux CI runner:它会统一强制内置 bash 使用
|
|
323
|
+
`linux-bubblewrap` 和 `read_scope: workspace`。因此 PR CI 环境必须安装 `bwrap`/`bubblewrap`;普通
|
|
314
324
|
`yama` 运行仍按这里声明的 `backend` / `auto` 规则执行。
|
|
315
325
|
- 远端 Plugin latest 报告里的 Case 身份就是 `case_key`(相对 Plugin Root 的 Case 路径)。
|
|
316
326
|
`yama pr-run --report --upload-report --commit-id <sha>` 合并远端报告时,会用相同
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
+
import shlex
|
|
4
5
|
import shutil
|
|
5
6
|
import sys
|
|
6
7
|
import tempfile
|
|
@@ -15,7 +16,7 @@ import yaml
|
|
|
15
16
|
from yama.assertions import run_hard_assertions
|
|
16
17
|
from yama.cli import format_text_results
|
|
17
18
|
from yama.workspace import DEFAULT_CASE_PATTERNS, WorkspaceConfig, load_workspace_config
|
|
18
|
-
from yama.tools.bash.fs import _SESSIONS, cleanup_session
|
|
19
|
+
from yama.tools.bash.fs import _SESSIONS, cleanup_session, run_workspace
|
|
19
20
|
from yama.llm import LLMClient, LiteLLMClient, LLMError, ScriptedLLMClient
|
|
20
21
|
from yama.loaders import CollectionError, resolve_case
|
|
21
22
|
from yama.mocks import MockConfigurationError, MockToolRegistry, ToolMockContext
|
|
@@ -2743,7 +2744,7 @@ class BashFsBackendSelectionTests(unittest.TestCase):
|
|
|
2743
2744
|
self.assertEqual(executable, "/usr/bin/bwrap")
|
|
2744
2745
|
self.assertIn("--unshare-net", argv)
|
|
2745
2746
|
self.assertIn("--bind", argv)
|
|
2746
|
-
self.assertIn("/tmp/yama-workspace", argv)
|
|
2747
|
+
self.assertIn(str(Path("/tmp/yama-workspace").resolve()), argv)
|
|
2747
2748
|
self.assertIn("--tmpfs", argv)
|
|
2748
2749
|
self.assertIn(str(Path.home()), argv)
|
|
2749
2750
|
|
|
@@ -2792,7 +2793,24 @@ class BashFsBackendSelectionTests(unittest.TestCase):
|
|
|
2792
2793
|
argv, _ = session._command_argv()
|
|
2793
2794
|
|
|
2794
2795
|
chdir_index = argv.index("--chdir")
|
|
2795
|
-
self.assertEqual(argv[chdir_index + 1], "/tmp/yama-workspace/project")
|
|
2796
|
+
self.assertEqual(argv[chdir_index + 1], str(Path("/tmp/yama-workspace/project").resolve()))
|
|
2797
|
+
|
|
2798
|
+
def test_bubblewrap_workspace_scope_mounts_only_runtime_and_run(self) -> None:
|
|
2799
|
+
from yama.tools.bash.fs import _bubblewrap_argv
|
|
2800
|
+
|
|
2801
|
+
workspace = Path("/tmp/yama-workspace")
|
|
2802
|
+
with patch("yama.tools.bash.fs.shutil.which", return_value="/usr/bin/bwrap"):
|
|
2803
|
+
argv, _ = _bubblewrap_argv(
|
|
2804
|
+
workspace, cwd=workspace, network=False,
|
|
2805
|
+
bash_path="/bin/bash", read_scope="workspace",
|
|
2806
|
+
)
|
|
2807
|
+
|
|
2808
|
+
read_binds = [(argv[index + 1], argv[index + 2]) for index, flag in enumerate(argv) if flag == "--ro-bind"]
|
|
2809
|
+
self.assertIn(("/usr", "/usr"), read_binds)
|
|
2810
|
+
self.assertNotIn(("/", "/"), read_binds)
|
|
2811
|
+
self.assertNotIn(("/etc", "/etc"), read_binds)
|
|
2812
|
+
self.assertNotIn(str(Path.home()), argv)
|
|
2813
|
+
self.assertLess(argv.index("--tmpfs"), argv.index("--bind"))
|
|
2796
2814
|
|
|
2797
2815
|
|
|
2798
2816
|
class BashFsMockTests(unittest.IsolatedAsyncioTestCase):
|
|
@@ -2858,17 +2876,22 @@ class BashFsMockTests(unittest.IsolatedAsyncioTestCase):
|
|
|
2858
2876
|
):
|
|
2859
2877
|
self.resolve(plugin_root, case_path)
|
|
2860
2878
|
|
|
2861
|
-
def
|
|
2879
|
+
async def test_fs_and_cli_mocks_share_the_workspace(self) -> None:
|
|
2862
2880
|
with tempfile.TemporaryDirectory() as temporary:
|
|
2863
2881
|
plugin_root = Path(temporary)
|
|
2864
|
-
case_path = self.write_case(plugin_root, {
|
|
2882
|
+
case_path = self.write_case(plugin_root, {
|
|
2883
|
+
"backend": "none", "files": {"fixture.txt": "inside\n"},
|
|
2884
|
+
})
|
|
2865
2885
|
raw = yaml.safe_load(case_path.read_text(encoding="utf-8"))
|
|
2866
|
-
raw["mocks"]["cli"] = {"
|
|
2886
|
+
raw["mocks"]["cli"] = {"vidmuse": "mocked\n"}
|
|
2867
2887
|
case_path.write_text(yaml.safe_dump(raw, allow_unicode=True), encoding="utf-8")
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2888
|
+
case = self.resolve(plugin_root, case_path)
|
|
2889
|
+
registry, call = self.open_session(case)
|
|
2890
|
+
try:
|
|
2891
|
+
result = await call("cat fixture.txt && vidmuse")
|
|
2892
|
+
self.assertEqual(result, {"stdout": "inside\nmocked\n", "stderr": "", "exit_code": 0})
|
|
2893
|
+
finally:
|
|
2894
|
+
await cleanup_session(registry.state)
|
|
2872
2895
|
|
|
2873
2896
|
def test_fs_mock_conflicts_with_custom_bash_handler(self) -> None:
|
|
2874
2897
|
with tempfile.TemporaryDirectory() as temporary:
|
|
@@ -2885,6 +2908,8 @@ class BashFsMockTests(unittest.IsolatedAsyncioTestCase):
|
|
|
2885
2908
|
def test_invalid_fs_mock_configs_fail_collection(self) -> None:
|
|
2886
2909
|
for fs, message in [
|
|
2887
2910
|
({"backend": "docker"}, "backend must be one of"),
|
|
2911
|
+
({"read_scope": "unknown"}, "read_scope must be workspace or host"),
|
|
2912
|
+
({"backend": "none", "read_scope": "workspace"}, "workspace requires a sandbox backend"),
|
|
2888
2913
|
({"cwd": "../escape"}, "cannot contain '..'"),
|
|
2889
2914
|
({"files": {"a.txt": {}}}, "must set exactly one of content or file"),
|
|
2890
2915
|
(
|
|
@@ -2904,6 +2929,101 @@ class BashFsMockTests(unittest.IsolatedAsyncioTestCase):
|
|
|
2904
2929
|
with self.assertRaisesRegex(CollectionError, message):
|
|
2905
2930
|
self.resolve(plugin_root, case_path)
|
|
2906
2931
|
|
|
2932
|
+
async def test_workspace_placeholder_is_resolved_per_run(self) -> None:
|
|
2933
|
+
with tempfile.TemporaryDirectory(prefix="yama workspace ") as temporary:
|
|
2934
|
+
plugin_root = Path(temporary)
|
|
2935
|
+
case_path = self.write_case(plugin_root, {
|
|
2936
|
+
"backend": "none", "files": {"work/fixture.txt": "content\n"},
|
|
2937
|
+
})
|
|
2938
|
+
raw = yaml.safe_load(case_path.read_text(encoding="utf-8"))
|
|
2939
|
+
template = "{{workspace}}/work/fixture.txt"
|
|
2940
|
+
raw["execution"] = {"repeat": 2}
|
|
2941
|
+
raw["context"]["messages"] = [{"role": "user", "content": f"Earlier: {template}"}]
|
|
2942
|
+
raw["context"]["tools"].append({"inline": {
|
|
2943
|
+
"name": "lookup", "description": "Look up the fixture",
|
|
2944
|
+
"parameters": {"type": "object", "properties": {}},
|
|
2945
|
+
}})
|
|
2946
|
+
raw["context"]["tools"].append({"inline": {
|
|
2947
|
+
"name": "python_lookup", "description": "Check the fixture from a Python mock",
|
|
2948
|
+
"parameters": {"type": "object", "properties": {}},
|
|
2949
|
+
}})
|
|
2950
|
+
(case_path.parent.parent / "fixture_mock.py").write_text(
|
|
2951
|
+
"from pathlib import Path\n"
|
|
2952
|
+
"def lookup(*, arguments, context, config):\n"
|
|
2953
|
+
" return {'path': '{{workspace}}/work/fixture.txt',\n"
|
|
2954
|
+
" 'content': Path(context.state['path']).read_text()}\n",
|
|
2955
|
+
encoding="utf-8",
|
|
2956
|
+
)
|
|
2957
|
+
raw["mocks"]["state"] = {"path": template}
|
|
2958
|
+
raw["mocks"]["tools"] = {
|
|
2959
|
+
"lookup": {"respond": {"result": {"path": template}}},
|
|
2960
|
+
"python_lookup": {"handler": {"python": "fixture_mock.py:lookup"}},
|
|
2961
|
+
}
|
|
2962
|
+
raw["mocks"]["cli"] = {"list-fixture": {"stdout": template}}
|
|
2963
|
+
raw["steps"][0]["user"] = f"Read: {template}"
|
|
2964
|
+
raw["steps"][0]["message_inject"] = [{
|
|
2965
|
+
"position": "before_user_message",
|
|
2966
|
+
"message": {"role": "user", "content": f"Injected: {template}"},
|
|
2967
|
+
}]
|
|
2968
|
+
case_path.write_text(yaml.safe_dump(raw), encoding="utf-8")
|
|
2969
|
+
case = self.resolve(plugin_root, case_path)
|
|
2970
|
+
paths = [str(run_workspace(case.plugin_root, case.case_key, number) / "work/fixture.txt") for number in (1, 2)]
|
|
2971
|
+
responses = []
|
|
2972
|
+
for path in paths:
|
|
2973
|
+
responses.extend([
|
|
2974
|
+
{"tool_calls": [
|
|
2975
|
+
{"name": "lookup", "arguments": {}},
|
|
2976
|
+
{"name": "python_lookup", "arguments": {}},
|
|
2977
|
+
{"name": "bash", "arguments": {"command": f"cat {shlex.quote(path)} && list-fixture"}},
|
|
2978
|
+
{"name": "bash", "arguments": {"command": "printf '%s' '{{workspace}}'"}},
|
|
2979
|
+
]},
|
|
2980
|
+
{"content": "done"},
|
|
2981
|
+
])
|
|
2982
|
+
llm = ScriptedLLMClient(responses)
|
|
2983
|
+
result = await YamaRunner(llm, write_artifacts=False).run_case(case)
|
|
2984
|
+
|
|
2985
|
+
self.assertTrue(result.passed, result.to_dict())
|
|
2986
|
+
for index, (run, path) in enumerate(zip(result.runs, paths)):
|
|
2987
|
+
self.assertEqual(run.mock_state["path"], path)
|
|
2988
|
+
self.assertEqual(run.mock_events[0]["result"], {"path": path})
|
|
2989
|
+
self.assertEqual(run.mock_events[1]["result"], {"path": path, "content": "content\n"})
|
|
2990
|
+
self.assertEqual(run.mock_events[2]["result"]["stdout"], f"content\n{path}")
|
|
2991
|
+
self.assertEqual(run.mock_events[3]["result"]["stdout"], "{{workspace}}")
|
|
2992
|
+
contents = [message["content"] for message in llm.requests[index * 2]["messages"]]
|
|
2993
|
+
self.assertIn(f"Earlier: {path}", contents)
|
|
2994
|
+
self.assertIn(f"Injected: {path}", contents)
|
|
2995
|
+
self.assertIn(f"Read: {path}", contents)
|
|
2996
|
+
self.assertEqual(case.mocks["state"]["path"], template)
|
|
2997
|
+
|
|
2998
|
+
@unittest.skipUnless(
|
|
2999
|
+
sys.platform == "darwin" or (sys.platform.startswith("linux") and shutil.which("bwrap")),
|
|
3000
|
+
"requires a native Bash sandbox backend",
|
|
3001
|
+
)
|
|
3002
|
+
async def test_workspace_scope_hides_cases_and_other_runs_with_cli_mock_enabled(self) -> None:
|
|
3003
|
+
with tempfile.TemporaryDirectory() as temporary:
|
|
3004
|
+
plugin_root = Path(temporary)
|
|
3005
|
+
case_path = self.write_case(plugin_root, {
|
|
3006
|
+
"files": {"work/fixture.txt": "fixture\n"},
|
|
3007
|
+
})
|
|
3008
|
+
raw = yaml.safe_load(case_path.read_text(encoding="utf-8"))
|
|
3009
|
+
raw["mocks"]["cli"] = {"vidmuse": "mock available\n"}
|
|
3010
|
+
case_path.write_text(yaml.safe_dump(raw), encoding="utf-8")
|
|
3011
|
+
case = self.resolve(plugin_root, case_path)
|
|
3012
|
+
second_run = run_workspace(case.plugin_root, case.case_key, 2)
|
|
3013
|
+
second_run.mkdir(parents=True)
|
|
3014
|
+
outside_file = second_run / "sentinel.txt"
|
|
3015
|
+
outside_file.write_text("another run\n", encoding="utf-8")
|
|
3016
|
+
registry, call = self.open_session(case)
|
|
3017
|
+
try:
|
|
3018
|
+
inside = await call('cat work/fixture.txt && vidmuse && printf ok > "$TMPDIR/probe"')
|
|
3019
|
+
self.assertEqual(inside, {"stdout": "fixture\nmock available\n", "stderr": "", "exit_code": 0})
|
|
3020
|
+
for outside in (case_path, outside_file):
|
|
3021
|
+
result = await call(f"cat {shlex.quote(str(outside))}")
|
|
3022
|
+
self.assertNotEqual(result["exit_code"], 0, result)
|
|
3023
|
+
self.assertEqual(result["stdout"], "")
|
|
3024
|
+
finally:
|
|
3025
|
+
await cleanup_session(registry.state)
|
|
3026
|
+
|
|
2907
3027
|
async def test_fs_mock_materializes_files_and_persists_state_across_calls(
|
|
2908
3028
|
self,
|
|
2909
3029
|
) -> None:
|
|
@@ -285,9 +285,12 @@ class CliFsLeftoverTests(unittest.TestCase):
|
|
|
285
285
|
):
|
|
286
286
|
resolve([{"builtin": "bash"}], mocks, [])
|
|
287
287
|
|
|
288
|
-
def
|
|
289
|
-
mocks: dict = {
|
|
290
|
-
|
|
288
|
+
def test_cli_and_fs_reject_duplicate_command_names(self) -> None:
|
|
289
|
+
mocks: dict = {
|
|
290
|
+
"cli": {"vidmuse": "ok"},
|
|
291
|
+
"fs": {"backend": "none", "bin": {"vidmuse": "exit 1"}},
|
|
292
|
+
}
|
|
293
|
+
with self.assertRaisesRegex(CollectionError, "command names in both mocks.cli and mocks.fs.bin"):
|
|
291
294
|
resolve([{"builtin": "bash"}], mocks, [])
|
|
292
295
|
|
|
293
296
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MockConfigurationError(ValueError):
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _matches(actual: Any, expected: Any) -> bool:
|
|
11
|
+
if isinstance(expected, dict):
|
|
12
|
+
matcher_keys = {
|
|
13
|
+
"equals",
|
|
14
|
+
"contains",
|
|
15
|
+
"matches",
|
|
16
|
+
"is_instance",
|
|
17
|
+
"exists",
|
|
18
|
+
"one_of",
|
|
19
|
+
}
|
|
20
|
+
selected = matcher_keys.intersection(expected)
|
|
21
|
+
if selected:
|
|
22
|
+
if len(selected) != 1:
|
|
23
|
+
raise MockConfigurationError("a matcher must use exactly one operation")
|
|
24
|
+
operation = next(iter(selected))
|
|
25
|
+
wanted = expected[operation]
|
|
26
|
+
if operation == "equals":
|
|
27
|
+
return actual == wanted
|
|
28
|
+
if operation == "contains":
|
|
29
|
+
return (
|
|
30
|
+
wanted in actual if isinstance(actual, (str, list, dict)) else False
|
|
31
|
+
)
|
|
32
|
+
if operation == "one_of":
|
|
33
|
+
return isinstance(wanted, list) and actual in wanted
|
|
34
|
+
if operation == "matches":
|
|
35
|
+
import re
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
isinstance(actual, str)
|
|
39
|
+
and re.search(str(wanted), actual) is not None
|
|
40
|
+
)
|
|
41
|
+
if operation == "exists":
|
|
42
|
+
return (actual is not _MISSING) is bool(wanted)
|
|
43
|
+
types = {
|
|
44
|
+
"array": list,
|
|
45
|
+
"object": dict,
|
|
46
|
+
"string": str,
|
|
47
|
+
"number": (int, float),
|
|
48
|
+
"integer": int,
|
|
49
|
+
"boolean": bool,
|
|
50
|
+
"null": type(None),
|
|
51
|
+
}
|
|
52
|
+
return wanted in types and isinstance(actual, types[wanted])
|
|
53
|
+
if not isinstance(actual, dict):
|
|
54
|
+
return False
|
|
55
|
+
return all(
|
|
56
|
+
_matches(actual.get(key, _MISSING), value)
|
|
57
|
+
for key, value in expected.items()
|
|
58
|
+
)
|
|
59
|
+
if isinstance(expected, list):
|
|
60
|
+
return actual == expected
|
|
61
|
+
return actual == expected
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
_MISSING = object()
|
|
@@ -7,7 +7,7 @@ from typing import Any
|
|
|
7
7
|
from ..mocks import MockConfigurationError
|
|
8
8
|
from ..models import LoadedSkill, ToolSchema
|
|
9
9
|
from ..tools.bash.bash import normalize_cli_config
|
|
10
|
-
from ..tools.bash.fs import normalize_fs_config
|
|
10
|
+
from ..tools.bash.fs import BASH_HANDLER, normalize_fs_config
|
|
11
11
|
from .common import CollectionError, load_yaml
|
|
12
12
|
|
|
13
13
|
# Argument each builtin handler reads from the tool call; a custom schema wired
|
|
@@ -137,31 +137,33 @@ def resolve_builtin_handlers(
|
|
|
137
137
|
if bash_entries:
|
|
138
138
|
cli_raw = mocks.pop("cli", {})
|
|
139
139
|
fs_raw = mocks.pop("fs", None)
|
|
140
|
-
if cli_raw and fs_raw is not None:
|
|
141
|
-
raise CollectionError("mocks.cli cannot be combined with mocks.fs")
|
|
142
140
|
try:
|
|
141
|
+
handler_with: dict[str, Any] = {}
|
|
143
142
|
if fs_raw is not None:
|
|
144
143
|
if force_bash_backend is not None and isinstance(fs_raw, dict):
|
|
145
144
|
fs_raw = dict(fs_raw)
|
|
146
145
|
fs_raw["backend"] = force_bash_backend
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
handler_with =
|
|
154
|
-
|
|
155
|
-
cli_raw, base_dir=evals_root, root=evals_root.parent
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
if force_bash_backend is not None:
|
|
146
|
+
fs_raw["read_scope"] = "workspace"
|
|
147
|
+
handler_with["fs"] = normalize_fs_config(
|
|
148
|
+
fs_raw, base_dir=evals_root, root=evals_root.parent
|
|
149
|
+
)
|
|
150
|
+
if fs_raw is None or cli_raw != {}:
|
|
151
|
+
cli = normalize_cli_config(cli_raw, base_dir=evals_root, root=evals_root.parent)
|
|
152
|
+
handler_with["cli"] = cli
|
|
153
|
+
if fs_raw is None and force_bash_backend is not None:
|
|
159
154
|
handler_with["fs_backend"] = force_bash_backend
|
|
155
|
+
if "fs" in handler_with:
|
|
156
|
+
cli_commands = cli.keys() - {"passthrough", "passthrough_timeout_seconds"}
|
|
157
|
+
conflicts = cli_commands & handler_with["fs"]["bin"].keys()
|
|
158
|
+
if conflicts:
|
|
159
|
+
raise MockConfigurationError(
|
|
160
|
+
f"command names in both mocks.cli and mocks.fs.bin: {sorted(conflicts)}"
|
|
161
|
+
)
|
|
160
162
|
except MockConfigurationError as exc:
|
|
161
163
|
raise CollectionError(str(exc)) from exc
|
|
162
164
|
for entry in bash_entries:
|
|
163
165
|
entry["handler"] = {
|
|
164
|
-
"python":
|
|
166
|
+
"python": BASH_HANDLER,
|
|
165
167
|
"with": deepcopy(handler_with),
|
|
166
168
|
}
|
|
167
169
|
|