python-yama 0.10.1__tar.gz → 0.10.2__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.
Files changed (79) hide show
  1. {python_yama-0.10.1 → python_yama-0.10.2}/PKG-INFO +4 -3
  2. {python_yama-0.10.1 → python_yama-0.10.2}/README.md +2 -1
  3. {python_yama-0.10.1 → python_yama-0.10.2}/README.zh-CN.md +2 -1
  4. {python_yama-0.10.1 → python_yama-0.10.2}/docs/agent-skill-test-framework-design.md +69 -34
  5. {python_yama-0.10.1 → python_yama-0.10.2}/docs/case-schema-reference.md +6 -0
  6. {python_yama-0.10.1 → python_yama-0.10.2}/skills/eval-plugin-with-yama/SKILL.md +6 -4
  7. {python_yama-0.10.1 → python_yama-0.10.2}/skills/eval-plugin-with-yama/references/case-schema.md +5 -0
  8. {python_yama-0.10.1 → python_yama-0.10.2}/skills/eval-plugin-with-yama/references/debugging.md +2 -1
  9. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_cli.py +104 -2
  10. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_judge_llm.py +12 -0
  11. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_llm.py +45 -1
  12. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_openai_llm.py +44 -0
  13. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_preview.py +7 -0
  14. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_run_plan.py +41 -1
  15. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_runner.py +393 -2
  16. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_thread_case.py +273 -7
  17. {python_yama-0.10.1 → python_yama-0.10.2}/yama/cli.py +52 -11
  18. {python_yama-0.10.1 → python_yama-0.10.2}/yama/judge_llm.py +10 -1
  19. {python_yama-0.10.1 → python_yama-0.10.2}/yama/llm.py +31 -2
  20. {python_yama-0.10.1 → python_yama-0.10.2}/yama/openai_llm.py +11 -4
  21. {python_yama-0.10.1 → python_yama-0.10.2}/yama/preview.py +8 -5
  22. {python_yama-0.10.1 → python_yama-0.10.2}/yama/runner.py +200 -23
  23. {python_yama-0.10.1 → python_yama-0.10.2}/yama/thread_case.py +116 -1
  24. {python_yama-0.10.1 → python_yama-0.10.2}/.github/workflows/publish.yml +0 -0
  25. {python_yama-0.10.1 → python_yama-0.10.2}/.gitignore +0 -0
  26. {python_yama-0.10.1 → python_yama-0.10.2}/CLAUDE.md +0 -0
  27. {python_yama-0.10.1 → python_yama-0.10.2}/LICENSE +0 -0
  28. {python_yama-0.10.1 → python_yama-0.10.2}/docs/superpowers/plans/2026-08-07-judge-model-resolution.md +0 -0
  29. {python_yama-0.10.1 → python_yama-0.10.2}/docs/superpowers/plans/2026-08-07-local-judge-default-model-retry.md +0 -0
  30. {python_yama-0.10.1 → python_yama-0.10.2}/docs/superpowers/plans/2026-08-07-openai-timeout-retry-reporting.md +0 -0
  31. {python_yama-0.10.1 → python_yama-0.10.2}/docs/superpowers/specs/2026-08-04-judge-model-object-design.md +0 -0
  32. {python_yama-0.10.1 → python_yama-0.10.2}/docs/superpowers/specs/2026-08-04-openai-adapter-safety-design.md +0 -0
  33. {python_yama-0.10.1 → python_yama-0.10.2}/docs/superpowers/specs/2026-08-07-judge-model-resolution-design.md +0 -0
  34. {python_yama-0.10.1 → python_yama-0.10.2}/docs/superpowers/specs/2026-08-07-local-judge-default-model-retry-design.md +0 -0
  35. {python_yama-0.10.1 → python_yama-0.10.2}/docs/superpowers/specs/2026-08-07-openai-timeout-retry-reporting-design.md +0 -0
  36. {python_yama-0.10.1 → python_yama-0.10.2}/docs/yama-intro.html +0 -0
  37. {python_yama-0.10.1 → python_yama-0.10.2}/pyproject.toml +0 -0
  38. {python_yama-0.10.1 → python_yama-0.10.2}/skills/eval-plugin-with-yama/references/install-upgrade.md +0 -0
  39. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_assertions.py +0 -0
  40. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_cli_shim.py +0 -0
  41. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_dashboard.py +0 -0
  42. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_framework.py +0 -0
  43. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_main_entrypoint.py +0 -0
  44. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_mocks.py +0 -0
  45. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_pr.py +0 -0
  46. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_public_api.py +0 -0
  47. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_report.py +0 -0
  48. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_report_bundle.py +0 -0
  49. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_report_upload.py +0 -0
  50. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_skill_loader.py +0 -0
  51. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_skill_tool.py +0 -0
  52. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_tool_loader.py +0 -0
  53. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_usage.py +0 -0
  54. {python_yama-0.10.1 → python_yama-0.10.2}/tests/test_workspace.py +0 -0
  55. {python_yama-0.10.1 → python_yama-0.10.2}/uv.lock +0 -0
  56. {python_yama-0.10.1 → python_yama-0.10.2}/yama/__init__.py +0 -0
  57. {python_yama-0.10.1 → python_yama-0.10.2}/yama/__main__.py +0 -0
  58. {python_yama-0.10.1 → python_yama-0.10.2}/yama/assertions.py +0 -0
  59. {python_yama-0.10.1 → python_yama-0.10.2}/yama/dashboard.py +0 -0
  60. {python_yama-0.10.1 → python_yama-0.10.2}/yama/loaders/__init__.py +0 -0
  61. {python_yama-0.10.1 → python_yama-0.10.2}/yama/loaders/case.py +0 -0
  62. {python_yama-0.10.1 → python_yama-0.10.2}/yama/loaders/common.py +0 -0
  63. {python_yama-0.10.1 → python_yama-0.10.2}/yama/loaders/skill_loader.py +0 -0
  64. {python_yama-0.10.1 → python_yama-0.10.2}/yama/loaders/tool_loader.py +0 -0
  65. {python_yama-0.10.1 → python_yama-0.10.2}/yama/mocks.py +0 -0
  66. {python_yama-0.10.1 → python_yama-0.10.2}/yama/models.py +0 -0
  67. {python_yama-0.10.1 → python_yama-0.10.2}/yama/pr.py +0 -0
  68. {python_yama-0.10.1 → python_yama-0.10.2}/yama/report.py +0 -0
  69. {python_yama-0.10.1 → python_yama-0.10.2}/yama/report_bundle.py +0 -0
  70. {python_yama-0.10.1 → python_yama-0.10.2}/yama/report_upload.py +0 -0
  71. {python_yama-0.10.1 → python_yama-0.10.2}/yama/tools/__init__.py +0 -0
  72. {python_yama-0.10.1 → python_yama-0.10.2}/yama/tools/base.py +0 -0
  73. {python_yama-0.10.1 → python_yama-0.10.2}/yama/tools/bash/__init__.py +0 -0
  74. {python_yama-0.10.1 → python_yama-0.10.2}/yama/tools/bash/_cli_shim.py +0 -0
  75. {python_yama-0.10.1 → python_yama-0.10.2}/yama/tools/bash/bash.py +0 -0
  76. {python_yama-0.10.1 → python_yama-0.10.2}/yama/tools/bash/fs.py +0 -0
  77. {python_yama-0.10.1 → python_yama-0.10.2}/yama/tools/skill/__init__.py +0 -0
  78. {python_yama-0.10.1 → python_yama-0.10.2}/yama/tools/skill/skill.py +0 -0
  79. {python_yama-0.10.1 → python_yama-0.10.2}/yama/workspace.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: python-yama
3
- Version: 0.10.1
3
+ Version: 0.10.2
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
@@ -104,6 +104,7 @@ uv run --project yama yama --plugin dingding-simple --report
104
104
  | `-k, --filter PATTERN` (repeatable) | Only run cases whose case key (path relative to the plugin root) matches — a substring, or an fnmatch glob when the pattern contains `*` `?` `[`; with several patterns a case runs if any matches |
105
105
  | `--result-dir PATH` | Override the artifact root (default `<plugin_root>/.yama/runs`) |
106
106
  | `--concurrency N` | Maximum number of cases running in parallel (default 10; `1` runs cases one at a time) |
107
+ | `--run-concurrency N` | Maximum number of runs active across all cases (default 32) |
107
108
  | `--report [PATH]` | Also generate a single-file HTML report. Without PATH it writes a timestamped `.yama/reports/report-<ts>.html` (history accumulates) and keeps `.yama/reports/latest.html` as a symlink to the newest one; an explicit PATH writes exactly that file |
108
109
  | `--preview` | Don't run anything (no LLM calls): resolve the collected Cases and write an HTML case preview (default `.yama/reports/preview.html`; `--report PATH` overrides), or print a JSON preview to stdout when combined with `--json` |
109
110
  | `--list` | Only print the collected Cases, without running them |
@@ -138,4 +139,4 @@ the just-run cases into the previous remote Plugin report.
138
139
 
139
140
  ### Output
140
141
 
141
- Cases run in parallel, up to 10 at a time by default (`--concurrency` changes the cap); runs within one case stay sequential, and results keep collection order regardless of completion order. While several cases run concurrently, a transient dashboard at the bottom of the terminal shows one row per case, updated in place — waiting, then a spinner with the run/step currently executing, then its ✓/✗ verdict — and each case's full run/step detail is printed above the dashboard as one block the moment it finishes, so blocks of different cases never interleave. With `--concurrency 1` (or a single collected case) it streams instead — a spinner marks the step currently executing (on a terminal), and each case, run, and assertion result is printed the moment it completes. Either way a per-case summary table closes the output, and with `--json` the progress stream goes to stderr so stdout stays valid JSON.
142
+ Cases run in parallel, up to 10 at a time by default (`--concurrency` changes the cap). Runs produced by one Case's `execution.repeat` also run in parallel: omitted `execution.repeat_concurrency` means all expanded runs, subject to the command-wide `--run-concurrency` cap (default 32); set it to `1` to restore serial runs for that Case. Case results keep collection order and run results keep `run_index` order regardless of completion order. Whenever Cases or runs overlap, a transient dashboard at the bottom of the terminal shows one row per Case and each completed Case's full run/step detail is printed above it as one block, so concurrent output never interleaves. Fully serial execution streams each Case, run, and assertion as it completes. Either way a per-Case summary table closes the output, and with `--json` the progress stream goes to stderr so stdout stays valid JSON.
@@ -77,6 +77,7 @@ uv run --project yama yama --plugin dingding-simple --report
77
77
  | `-k, --filter PATTERN` (repeatable) | Only run cases whose case key (path relative to the plugin root) matches — a substring, or an fnmatch glob when the pattern contains `*` `?` `[`; with several patterns a case runs if any matches |
78
78
  | `--result-dir PATH` | Override the artifact root (default `<plugin_root>/.yama/runs`) |
79
79
  | `--concurrency N` | Maximum number of cases running in parallel (default 10; `1` runs cases one at a time) |
80
+ | `--run-concurrency N` | Maximum number of runs active across all cases (default 32) |
80
81
  | `--report [PATH]` | Also generate a single-file HTML report. Without PATH it writes a timestamped `.yama/reports/report-<ts>.html` (history accumulates) and keeps `.yama/reports/latest.html` as a symlink to the newest one; an explicit PATH writes exactly that file |
81
82
  | `--preview` | Don't run anything (no LLM calls): resolve the collected Cases and write an HTML case preview (default `.yama/reports/preview.html`; `--report PATH` overrides), or print a JSON preview to stdout when combined with `--json` |
82
83
  | `--list` | Only print the collected Cases, without running them |
@@ -111,4 +112,4 @@ the just-run cases into the previous remote Plugin report.
111
112
 
112
113
  ### Output
113
114
 
114
- Cases run in parallel, up to 10 at a time by default (`--concurrency` changes the cap); runs within one case stay sequential, and results keep collection order regardless of completion order. While several cases run concurrently, a transient dashboard at the bottom of the terminal shows one row per case, updated in place — waiting, then a spinner with the run/step currently executing, then its ✓/✗ verdict — and each case's full run/step detail is printed above the dashboard as one block the moment it finishes, so blocks of different cases never interleave. With `--concurrency 1` (or a single collected case) it streams instead — a spinner marks the step currently executing (on a terminal), and each case, run, and assertion result is printed the moment it completes. Either way a per-case summary table closes the output, and with `--json` the progress stream goes to stderr so stdout stays valid JSON.
115
+ Cases run in parallel, up to 10 at a time by default (`--concurrency` changes the cap). Runs produced by one Case's `execution.repeat` also run in parallel: omitted `execution.repeat_concurrency` means all expanded runs, subject to the command-wide `--run-concurrency` cap (default 32); set it to `1` to restore serial runs for that Case. Case results keep collection order and run results keep `run_index` order regardless of completion order. Whenever Cases or runs overlap, a transient dashboard at the bottom of the terminal shows one row per Case and each completed Case's full run/step detail is printed above it as one block, so concurrent output never interleaves. Fully serial execution streams each Case, run, and assertion as it completes. Either way a per-Case summary table closes the output, and with `--json` the progress stream goes to stderr so stdout stays valid JSON.
@@ -77,6 +77,7 @@ uv run --project yama yama --plugin dingding-simple --report
77
77
  | `-k, --filter PATTERN`(可重复) | 只运行 case key(相对 Plugin Root 的路径)匹配 PATTERN 的 Case——默认子串匹配,PATTERN 含 `*` `?` `[` 时按 fnmatch 通配符匹配;传多个时命中任意一个即运行 |
78
78
  | `--result-dir PATH` | 覆盖产物根目录(默认 `<plugin_root>/.yama/runs`) |
79
79
  | `--concurrency N` | 同时运行的 Case 数上限(默认 10;`1` 表示逐个顺序执行) |
80
+ | `--run-concurrency N` | 所有 Case 的活跃 run 总上限(默认 32) |
80
81
  | `--report [PATH]` | 额外生成单文件 HTML 报告。省略 PATH 时写带时间戳的 `.yama/reports/report-<ts>.html`(历史累积),并把 `.yama/reports/latest.html` 维护成指向最新报告的软链;显式给 PATH 时精确写到该文件 |
81
82
  | `--preview` | 不运行、不发起任何 LLM 调用:解析收集到的 Case 后生成用例预览 HTML(默认 `.yama/reports/preview.html`,`--report PATH` 可覆盖);与 `--json` 组合时改为向 stdout 打印 JSON 预览 |
82
83
  | `--list` | 只打印匹配到的 Case,不运行 |
@@ -110,4 +111,4 @@ CI 需要把报告发布到 Yama Eval Report 服务时,在 `--report` 之外
110
111
 
111
112
  ### 输出
112
113
 
113
- Case 之间并行执行,默认最多同时 10 个(用 `--concurrency` 调整上限);同一 Case 内的多个 run 仍顺序执行,结果始终保持收集顺序,与完成先后无关。多个 Case 并发运行时,终端底部会有一张原地刷新的状态面板,每个 Case 固定占一行——排队等待、转圈显示当前执行到的 Run/Step、完成后原地翻成 ✓/✗——任何一个 Case 一完成,它的完整 Run/Step 明细就作为一个整块打印到面板上方,不同 Case 的块不会交错。使用 `--concurrency 1`(或只收集到一个 Case)时则实时流式输出——正在执行的 Step 会显示转圈的 loading 状态(终端下),每个 Case、Run、断言一完成就立即打印结果。两种模式最后都以逐 Case 的汇总表格收尾;使用 `--json` 时进度流打印到 stderr,stdout 保持为纯 JSON。
114
+ Case 之间并行执行,默认最多同时 10 个(用 `--concurrency` 调整上限)。同一 Case 的 `execution.repeat` 展开的 run 也会并行:未设置 `execution.repeat_concurrency` 时自动使用展开后的总 run 数,但受命令级 `--run-concurrency`(默认 32)限制;设为 `1` 可恢复该 Case 的串行 run。Case 结果保持收集顺序,run 结果保持 `run_index` 顺序,与完成先后无关。只要 Case 或 run 存在重叠执行,终端底部就会显示逐 Case 状态面板,每个 Case 完成后把完整 Run/Step 明细作为一个整块打印到面板上方,避免并发输出交错;完全串行时则逐 Case、Run、断言实时流式打印。两种模式最后都以逐 Case 的汇总表格收尾;使用 `--json` 时进度流打印到 stderr,stdout 保持为纯 JSON。
@@ -81,12 +81,12 @@ SYSTEM.md Skill Catalog Extra Messages
81
81
  | `tools/bash/fs.py` | `bash` 工具真正的沙箱执行引擎:校验 `mocks.fs`、物化沙箱工作目录、生成 macOS sandbox-exec profile、管理贯穿一次 run 的持久 shell 会话;同时把 `mocks.cli` 编译成同一套引擎能吃的合成 fs 配置 | `normalize_fs_config`、`materialize_workspace`、`workspace_dir`、`ShellSession`、`compile_cli_config`、`cleanup_session` |
82
82
  | `tools/bash/_cli_shim.py` | 独立子进程入口,被编译出的 `.mockbin/<cmd>` 脚本调用,复用 `mocks.py` 的 `_matches` 语义在规则树里做匹配 | `main`、`_resolve` |
83
83
  | `tools/skill/skill.py` | `{builtin: skill}` 默认 Handler:按 Skill 目录 + 文件名读取 Skill 正文/子文件 | `SkillTool`、`read_skill`(`= SkillTool().run`) |
84
- | `llm.py` | LLM 抽象、消息/附件转换 helper、usage 规范化 helper;保留 LiteLLM legacy adapter 与可脚本化的确定性 Client 供测试/回放用 | `LLMClient`(抽象)、`LiteLLMClient`、`ScriptedLLMClient`、`delivered_content` |
84
+ | `llm.py` | LLM 抽象、并发 run 的 Client wrapper fork、消息/附件转换 helper、usage 规范化 helper;保留 LiteLLM legacy adapter 与可脚本化的确定性 Client 供测试/回放用 | `LLMClient`(抽象)、`LiteLLMClient`、`ScriptedLLMClient`、`delivered_content` |
85
85
  | `openai_llm.py` | 默认真实 LLM adapter,通过 OpenAI SDK 调 OpenAI-compatible chat completions endpoint | `OpenAICompatibleLLMClient` |
86
- | `runner.py` | 核心编排:按 run/step/request 三层驱动一次 Case 执行,并通过 `on_event` 回调对外发布进度事件(见第 13 节) | `YamaRunner`、`RunResult`、`CaseResult`、`RunnerEventCallback`、`MaxToolRoundsExceeded` |
86
+ | `runner.py` | 核心编排:展开并并行调度 run,按 step/request 驱动每条 run,并通过 `on_event` 回调对外发布进度事件(见第 13 节) | `YamaRunner`、`RunConcurrencyLimiter`、`RunResult`、`CaseResult`、`RunnerEventCallback`、`MaxToolRoundsExceeded` |
87
87
  | `assertions.py` | 硬断言(tool_called / assistant_matches / jsonpath 等)与 LLM-as-Judge 的实现 | `run_hard_assertions`、`run_judge` |
88
88
  | `report.py` | 把执行结果渲染成单个自包含 HTML 报告 | `write_html_report` |
89
- | `cli.py` | 命令行入口:串联 config → loaders → runner → report;按 `--concurrency` 并行调度多个 Case(asyncio),执行中流式打印进度,收尾打印汇总表格 | `main`、`ProgressPrinter`、`ParallelProgressPrinter`、`build_case_tree`、`build_summary_table`、`build_results_renderable` |
89
+ | `cli.py` | 命令行入口:串联 config → loaders → runner → report;用 `--concurrency` 限制 Case、用 `--run-concurrency` 限制全局活跃 run,执行中打印进度,收尾打印汇总表格 | `main`、`ProgressPrinter`、`ParallelProgressPrinter`、`build_case_tree`、`build_summary_table`、`build_results_renderable` |
90
90
 
91
91
  ### 3.2 一次 Case 执行的数据流
92
92
 
@@ -104,7 +104,7 @@ cli.main
104
104
  │ 接到 tools/skill/skill.py:read_skill(派生 enabled/skills_dir)
105
105
  └─ 解析 context.messages / steps[].user 里的 fixture 引用
106
106
  └─ YamaRunner.run_case(case)
107
- └─ 按 execution.repeat 跑 N 次 _run_once
107
+ └─ 展开 execution.repeat,按 repeat_concurrency 并行跑 N 次 _run_once
108
108
  ├─ 建 MockToolRegistry(校验 mocks.tools 与 exposed_tools 完全相等)
109
109
  ├─ 按 step 顺序:
110
110
  │ before_user_message message_inject → 发一条 user 消息
@@ -227,6 +227,7 @@ yama --plugin-root ./dingding-simple
227
227
  | `-k, --filter PATTERN`(可重复) | Case 筛选:只保留 case key 匹配 PATTERN 的 Case(见下) |
228
228
  | `--result-dir PATH` | 覆盖产物根目录(默认每个 Case 写到其所属 `plugin_root/.yama/runs`) |
229
229
  | `--concurrency N` | 同时运行的 Case 数上限(必须 ≥ 1,默认 10);`1` 表示按收集顺序逐个执行 |
230
+ | `--run-concurrency N` | 所有 Case 的活跃 run 总上限(必须 ≥ 1,默认 32) |
230
231
  | `--report [PATH]` | 额外写一份单文件 HTML 报告;省略路径时写到 `<第一个 result_root 的上级>/reports/report-<时间戳>.html`(历史累积),并把同目录的 `latest.html` 维护成指向最新报告的软链;显式给 PATH 时精确写到该文件、不建软链 |
231
232
  | `--preview` | 不运行任何 Case、不发起任何 LLM 调用:解析收集到的 Case 后输出**用例预览**。默认写一张与报告同风格的 HTML(`<第一个 result_root 的上级>/reports/preview.html`,`--report PATH` 可覆盖目标路径);与 `--json` 组合时改为向 stdout 打印逐 Case 的 JSON 预览数组(见第 13 节) |
232
233
  | `--list` | 只收集并打印 `case_key` 列表,不运行 |
@@ -304,26 +305,31 @@ PATTERN 含 `*`/`?`/`[` 任一字符时按 `fnmatch` 通配符(大小写敏感
304
305
  筛选后一个 Case 都不剩时报 `No eval cases matched the case filter.` 并以退出码 2
305
306
  结束(与"根本没收集到 Case"同级别,但错误信息区分两种情况)。
306
307
 
307
- **Case 级并发调度(`--concurrency`,`cli.py:_run`)。** 收集到的多个 Case 用
308
- `asyncio.Semaphore(concurrency)` + `asyncio.gather` 在同一事件循环里并发执行
309
- (执行链路本就是全异步:`AsyncOpenAI` 请求被直接 await,bash 沙箱使用 asyncio
310
- 子进程,工作负载是 I/O 密集的 LLM 请求)。
308
+ **Case/run 两级并发调度(`--concurrency` / `--run-concurrency`,`cli.py:_run`)。**
309
+ 收集到的多个 Case 先用 `asyncio.Semaphore(concurrency)` + `asyncio.gather` 在同一事件
310
+ 循环里并发执行;所有 Runner 再共享一个 `RunConcurrencyLimiter(run_concurrency)`。
311
+ 每个 Case 内部把 `execution.repeat` 展开的 `RunSpec` 建成异步任务,用自己的
312
+ `repeat_concurrency` semaphore 和共享 limiter 双重限流。
311
313
  语义边界:
312
314
 
313
- - 并发单位是 **Case**;同一 Case 内 `execution.repeat` 的多个 run 仍严格顺序执行。
314
- - 每个 Case 用独立的 `YamaRunner` + 独立的 `OpenAICompatibleLLMClient`——runner 在每次
315
- `complete()` 后回读 client 的 `last_request`/`last_provider` 写入请求记录,
316
- 共享 client 会被并发 Case 互相覆盖。
315
+ - `--concurrency` 只限制活跃 **Case**,默认 10;`--run-concurrency` 限制本次命令的
316
+ 活跃 **run 总数**,默认 32。二者都必须是正整数。
317
+ - Case 未声明 `execution.repeat_concurrency` 时按展开后的总 run 数自动并行;显式值必须
318
+ 是正整数,`1` 恢复串行。实际 Case 上限会先被总 run 数和全局 run 上限钳制。
319
+ - 每个并行 run 使用 `LLMClient.fork()` 得到独立 adapter wrapper;Agent/Judge 本来是同一
320
+ Client 时只 fork 一次并在该 run 内共享。这样 `last_request`/`last_provider`/
321
+ `last_retry_count` 不会跨 run 串扰;自定义有状态 Client 可覆盖默认浅拷贝 `fork()`。
317
322
  - 结果数组保持**收集顺序**(`gather` 保序),与完成先后无关;汇总表格、`--json`
318
- 输出、HTML 报告的 Case 顺序因此在任何并发度下都稳定。
323
+ 输出、HTML 报告的 Case 顺序因此稳定;Case 内第二层 `gather` 同样让 `runs` 始终按
324
+ `run_index` 排列。
319
325
  - 某个 Case 抛出异常(罕见:run 内的错误都会被 `_run_once` 捕获进
320
326
  `RunResult.error`)时,其余 Case 仍会跑完并写完产物(`gather`
321
327
  `return_exceptions=True`),随后第一个异常按原有 `main()` 错误出口重新抛出。
322
- - Case 间的隔离不依赖新机制:bash 沙箱工作目录/产物目录本就按 `case_key` 分目录,
323
- 持久 shell 会话按每 run 的 `state` 身份键控(见 8.4.3 与第 12 节)。
324
- - 进度输出按并发模式切换(见第 13 节):并发 >1 且收集到多个 Case 时使用
325
- `ParallelProgressPrinter`(终端底部一张原地刷新的逐 Case 状态面板 + 完成时
326
- 整 Case 成块打印),否则保持逐 Step 流式的 `ProgressPrinter`。
328
+ - run 间的 Mock state、bash 沙箱工作目录、持久 shell 会话和产物目录都已按
329
+ `run_index` 隔离;Case 级旧目录清理只在并发任务启动前执行一次。
330
+ - 进度输出按实际并发模式切换(见第 13 节):多个 Case 可重叠或任一 Case 的有效 run
331
+ 并发大于 1 时使用 `ParallelProgressPrinter`,完全串行时才使用逐 Step 流式的
332
+ `ProgressPrinter`。
327
333
 
328
334
  ## 5. 全局配置
329
335
 
@@ -395,8 +401,9 @@ timeout_seconds_per_step = 60
395
401
  ```
396
402
 
397
403
  **不存在** CLI 对 `model`/`execution`/超时参数的覆盖层——CLI 能覆盖的运行期配置只有
398
- `--result-dir`(产物根目录)和 `--concurrency`(Case 级并发上限,纯调度参数,
399
- 不影响任何 Case 语义)。也**不存在** `[conventions]`、`[templates]` 两个配置表,
404
+ `--result-dir`(产物根目录)、`--concurrency`(Case 级并发上限)和
405
+ `--run-concurrency`(命令级 run 总上限);后两者都是纯调度参数,不改变 Case 文件。
406
+ 也**不存在** `[conventions]`、`[templates]` 两个配置表,
400
407
  也没有 `baseline_dir` 字段:
401
408
 
402
409
  - `[conventions]`:System Prompt/Skill 目录/入口文件名等约定只能在 **Plugin 级别**
@@ -1668,6 +1675,7 @@ execution:
1668
1675
  timeout_seconds_per_step: 300
1669
1676
  max_tool_rounds_per_step: 10
1670
1677
  repeat: 3
1678
+ repeat_concurrency: 2
1671
1679
  ```
1672
1680
 
1673
1681
  `repeat` 也可以写成**运行矩阵**,用不同模型配置执行同一 Case 并在报告中对比:
@@ -1721,6 +1729,9 @@ execution:
1721
1729
  评分口径一致、可对比。
1722
1730
  - `repeat` 在 defaults / plugin / Case 三层间按整值替换(`dict.update`),
1723
1731
  不做逐条目合并:Case 写 `repeat: 3` 会整体覆盖全局矩阵,反之亦然。
1732
+ - `repeat_concurrency`:同一 Case 的活跃 run 上限。显式值必须是正整数;`1` 表示串行。
1733
+ 省略时为 **auto**,即展开后的总 run 数;CLI 再用 `--run-concurrency`(默认 32)限制
1734
+ 所有 Case 的总活跃 run。显式值超过总 run 数或全局上限时按较小值分批执行,不报错。
1724
1735
 
1725
1736
  ### 8.6 `steps[]`:确定性推进的用户回合
1726
1737
 
@@ -2958,7 +2969,8 @@ Step 内的 Resolved transcript 和 run 底部的 `LLM requests (N)` / `Mock eve
2958
2969
 
2959
2970
  `--preview --json` 打印的预览 payload(`preview.py:preview_payload`)是逐 Case 的
2960
2971
  JSON 对象数组:`case_key`/`description`/`path`/`plugin_root`/`evals_root`/
2961
- `model`/`execution`/`run_plan`(展开后的计划 run 列表,非法 repeat 时为
2972
+ `model`/`execution`/`run_plan`(展开后的计划 run 列表,非法 repeat 或
2973
+ `repeat_concurrency` 时为
2962
2974
  `{"error": ...}`)/`context`/`mocks`/`steps`(解析后的 Step,含 fixture 展开)/
2963
2975
  `outcome`/`system_prompt`(渲染后的最终文本)/`skills`/`tools`(provider 形态
2964
2976
  schema)/`initial_messages`/`fixtures`。
@@ -2970,10 +2982,10 @@ schema)/`initial_messages`/`fixtures`。
2970
2982
  `/preview` 页的页眉标注 "refresh to re-resolve"(区别于 `--preview` 写盘的
2971
2983
  static snapshot 措辞)。
2972
2984
 
2973
- 终端输出(不用 `--json` 时)在执行过程中**实时流式打印进度**,形态取决于并发模式
2974
- (见 4.3 节的 `--concurrency`);两种模式最后都以逐 Case 的汇总表格收尾。
2985
+ 终端输出(不用 `--json` 时)在执行过程中打印进度,形态取决于 Case/run 是否会重叠
2986
+ (见 4.3 节的两个并发上限);两种模式最后都以逐 Case 的汇总表格收尾。
2975
2987
 
2976
- **顺序模式**(`--concurrency 1`,或只收集到一个 Case):每个 Case、Run、Step
2988
+ **顺序模式**(Case 逐个执行,且每个 Case 的有效 run 并发均为 1):每个 Case、Run、Step
2977
2989
  一完成就立即打印结果(含每条 hard check 的通过情况与失败详情、Judge 结论):
2978
2990
 
2979
2991
  ```text
@@ -3001,8 +3013,8 @@ Yama Eval Results
3001
3013
  表格单元格显示 `–`,caption 也不带 tokens 段。`✓`/`✗`/`!` 分别对应
3002
3014
  `status=pass`/`fail`/`error`;ERROR 行不会计入 cases/runs passed 的分母。
3003
3015
 
3004
- **并发模式**(并发 >1 且收集到多个 Case,默认即是):不同 Case 的 Step 结果会
3005
- 乱序到达,逐 Step 流式打印会把不相关 Case 的行交错在错误的 Case 标题下,因此改为
3016
+ **并发模式**(多个 Case 或同一 Case 的多个 run 会重叠):Step 结果会乱序到达,
3017
+ 逐 Step 流式打印会把不相关运行的行交错在错误的标题下,因此改为
3006
3018
  在终端底部维护一张**原地刷新的逐 Case 状态面板**(transient `rich Live`):每个
3007
3019
  收集到的 Case 固定占一行、按收集顺序排列,状态原地更新——`waiting`(排队等并发
3008
3020
  槽位)→ spinner + 当前 `Run k/n · <step_id>` → `✓/✗` 加简要结果。任何一个 Case
@@ -3025,9 +3037,9 @@ Yama Eval Results
3025
3037
  ```
3026
3038
 
3027
3039
  流式进度由 `YamaRunner` 的进度回调驱动(`runner.py:RunnerEventCallback`,
3028
- 构造参数 `on_event`)。每个 Case 的事件顺序固定为:`case_start`
3040
+ 构造参数 `on_event`)。每个 Case 先发 `case_start`
3029
3041
  `{case_key, description, repeat}`(`repeat` 是展开后的**总 run 数**,运行矩阵下
3030
- = Σ times)→ 每个 run:`run_start` `{case_key, run_index, repeat, label}`
3042
+ = Σ times);随后每个并行 run 独立发送 `run_start` `{case_key, run_index, repeat, label}`
3031
3043
  (`label` 是该 run 的变体标签,整数 `repeat` 时为 None;CLI 的顺序模式
3032
3044
  `Run i/N` 行、并发面板行与 `build_case_tree` 的 Run 节点都会把非空 label 显示为
3033
3045
  `Run i/N · <label>`)→ 每个 Step:`step_start` `{case_key, run_index, step_id}`、`step_end`
@@ -3035,9 +3047,10 @@ Yama Eval Results
3035
3047
  RunResult}` → `case_end` `{result: CaseResult}`。`step_end` 在该 Step 的 hard
3036
3048
  check 与 Judge 都结算完之后才触发(含 max-tool-rounds 失败的 Step),payload
3037
3049
  携带的是最终判定;run 在 Step 中途死掉(超时、Handler 异常)时该 Step 没有
3038
- `step_end`,但 `run_end` 仍会触发(在产物写盘之后)。并发执行时多个 Case 的事件
3039
- 流会在时间上交错,但单个 Case 内部的事件顺序不变(每个事件 payload 都带
3040
- `case_key` 可供归属)。
3050
+ `step_end`,但 `run_end` 仍会触发(在产物写盘之后)。并发执行时不同 Case 或 run 的
3051
+ 事件会在时间上交错;只有**单条 run 内部**保持 step/request 顺序。每个事件 payload
3052
+ 都带 `case_key`,run/step 事件还带 `run_index`,可准确归属。`case_end` 一定在全部
3053
+ `run_end` 之后发出。
3041
3054
 
3042
3055
  CLI 侧按并发模式挑选回调实现,两者的**已完成结果**都只做顺序追加打印(不回改
3043
3056
  已输出内容),管道/CI 日志中同样可读;动态元素(spinner/面板)都是 transient
@@ -3075,6 +3088,28 @@ record 的 request 生成 `context.skills`/`context.tools`/`context.messages`;
3075
3088
  `mocks.state.dsl`。当 DSL workflow 和 request history 足够完整时,还会自动生成一条
3076
3089
  `steps[]`:
3077
3090
 
3091
+ 模型记录的 HTTP transport 由 `YAMA_THREAD_HTTP_TRANSPORT` 控制,值会去除首尾空白并
3092
+ 按大小写不敏感方式解析:
3093
+
3094
+ | 配置值 | prod | dev/staging |
3095
+ | --- | --- | --- |
3096
+ | 未设置或 `auto` | curl | urllib |
3097
+ | `curl` | curl | curl |
3098
+ | `urllib` | urllib | urllib |
3099
+
3100
+ 其他值在发出网络请求前报 `ThreadCaseError`。`auto` 每次只选一个 transport,不会在
3101
+ 失败后 fallback:prod 直接用 curl,避免先等待已知会触发 CAPTCHA 的 urllib 请求;
3102
+ dev/staging 保持原 urllib 行为。curl 调用首先用 `--disable` 忽略用户 `.curlrc`,只跟随
3103
+ 最多 5 次 HTTPS 跳转,并同时设置 30 秒传输超时和 35 秒子进程超时。Bearer token 与
3104
+ `Accept: application/json` 通过 `--header @-` 从 stdin 传入,不进入 curl 子进程 argv;
3105
+ `--write-out` 在正文后追加最终 HTTP 状态和 content type,由 Python 统一解释,因此不
3106
+ 依赖 `--fail-with-body`。
3107
+
3108
+ prod curl 遇到 `text/html`,或遇到包含 `captcha` 且不是正常 `records` 载荷的响应时,
3109
+ 直接报 `prod edge returned CAPTCHA`;正常 model-records JSON 内的历史消息即使提到
3110
+ CAPTCHA 也不会误报。其他非 2xx、curl 非零退出、curl 不存在、超时、响应元数据缺失和
3111
+ 非 JSON 响应都包装为 `ThreadCaseError`,错误正文有长度上限且会去除 bearer token。
3112
+
3078
3113
  - 当前 step id 来自 `dsl.workflow.steps`,优先第一条 `status == "in_progress"`,否则取
3079
3114
  第一条非 `completed`/`skipped`;若全部完成/跳过、没有 DSL、或步骤缺少 id,则不填充
3080
3115
  step。
@@ -3186,8 +3221,8 @@ stdout 仍只输出 YAML,stderr 只输出 record/response/DSL 抓取诊断信
3186
3221
  `model`,没有对 Step 输入、Mock 配置等任意参数做笛卡尔展开的通用参数矩阵。
3187
3222
  - **HTML Transcript Viewer 的进一步能力**、**人工评分与 Judge 校准**、**远程
3188
3223
  执行**:`report.py` 目前只产出一个静态汇总 HTML,没有专门的单 Case 交互式
3189
- Transcript Viewer;Case 级的本地并发调度已实现(CLI `--concurrency`,默认 10,
3190
- 见 4.3 节),但仍没有把执行分发到远程机器的能力。
3224
+ Transcript Viewer;Case/run 两级的本地并发调度已实现(CLI `--concurrency` 默认 10、
3225
+ `--run-concurrency` 默认 32,见 4.3 节),但仍没有把执行分发到远程机器的能力。
3191
3226
 
3192
3227
  已经完成、且与原设计基本对齐或已按上文修正描述的能力(供快速核对现状):
3193
3228
 
@@ -3205,7 +3240,7 @@ stdout 仍只输出 YAML,stderr 只输出 record/response/DSL 抓取诊断信
3205
3240
  严格校验,见 7.6 节)。
3206
3241
  - 纯文本与多模态 Message Part、fixture manifest。
3207
3242
  - 9 种硬检查、多维 LLM Judge、`execution.repeat` 稳定通过率统计(含多模型
3208
- 运行矩阵与报告中的分组对比)。
3243
+ 运行矩阵、Case 内并行 run 与报告中的分组对比)。
3209
3244
  - JSON 产物(逐 Case/逐 run)与单文件 HTML 汇总报告。
3210
3245
  - LLM token 用量统计:逐请求采集、run/Case 级聚合、CLI 与 HTML 报告展示
3211
3246
  (见第 11 节与第 13 节)。
@@ -726,17 +726,23 @@ mocks:
726
726
  刻意不同:轮数超限更像是"这一步的任务对模型来说太难/陷入了局部循环",而不是整条
727
727
  会话不可恢复,所以允许后续 Step 有机会独立通过。 |
728
728
  | `repeat` | 正整数,或运行矩阵列表 | `1` | 见下文 [repeat](#executionrepeat)。 |
729
+ | `repeat_concurrency` | 正整数 | `auto` | 同一 Case 同时执行的 run 上限;省略时使用
730
+ 展开后的总 run 数,再由命令级 `--run-concurrency` 统一限制。设为 `1` 可串行执行。 |
729
731
 
730
732
  ```yaml
731
733
  execution:
732
734
  timeout_seconds_per_step: 300
733
735
  max_tool_rounds_per_step: 10
734
736
  repeat: 3
737
+ repeat_concurrency: 2
735
738
  ```
736
739
 
737
740
  ### execution.repeat
738
741
 
739
742
  最简单的形式是一个正整数 `N`:用 Case 的 `model` 原样重复跑 `N` 次,统计通过率。
743
+ 这些 run 默认并行执行;省略 `repeat_concurrency` 时并发值取展开后的总 run 数,CLI
744
+ 再用 `--run-concurrency`(默认 32)限制所有 Case 的活跃 run 总数。显式值必须是正整数;
745
+ 它大于总 run 数或全局上限时会被自然钳制,而不会报错。
740
746
 
741
747
  更复杂的场景——比较同一个 Case 在不同模型/不同参数下的表现——可以写成运行矩阵:
742
748
 
@@ -264,10 +264,12 @@ yama --preview --json # 向 stdout 打印逐 Case 的 JSON 预览
264
264
  yama dashboard # 默认 http://127.0.0.1:8765/
265
265
  ```
266
266
 
267
- 多个 Case 默认并行执行(最多同时 10 个,`--concurrency N` 调整;Case 内的多个
268
- run 仍顺序执行)。并行时终端底部有一张原地刷新的逐 Case 状态面板(等待/执行中的
269
- Run·Step/✓✗),每个 Case 的 Run/Step 明细在该 Case 完成后整块打印到面板上方;
270
- 需要逐 Step 实时流式输出来盯一个用例时,用 `--concurrency 1` 或只跑那一个 Case。
267
+ 多个 Case 默认并行执行(最多同时 10 个,`--concurrency N` 调整)。Case 内由
268
+ `execution.repeat` 展开的 run 也默认并行:省略 `execution.repeat_concurrency` 时使用
269
+ 展开后的总 run 数,所有 Case 再共享 `--run-concurrency N`(默认 32)的全局上限;
270
+ 设 `repeat_concurrency: 1` 可让指定 Case 串行。只要 Case 或 run 存在并发,终端底部就
271
+ 显示逐 Case 状态面板,并在 Case 完成后把 Run/Step 明细整块打印到面板上方;需要逐 Step
272
+ 流式输出时,同时使用 `--concurrency 1 --run-concurrency 1`,或让目标 Case 显式串行。
271
273
 
272
274
  退出码:`0` 全部通过;`1` 有 Case 失败;`2` Collection error、顶层 LLM error、
273
275
  没有收集到任何 Case,或运行后只有/存在 ERROR(LLM 调用异常、Step 超时)且没有
@@ -324,8 +324,13 @@ execution:
324
324
  timeout_seconds_per_step: 120 # 超时 = 整条 run 标 ERROR 并终止(不只当前 Step)
325
325
  max_tool_rounds_per_step: 10 # 超限 = 仅当前 Step 记 max_tool_rounds_exceeded 失败,run 继续
326
326
  repeat: 3 # 重复运行统计通过率;每次 repeat 重建 Mock state
327
+ repeat_concurrency: 2 # 可省略;省略时按总 run 数自动并行
327
328
  ```
328
329
 
330
+ `repeat_concurrency` 显式配置时必须是正整数;`1` 表示串行。省略时取展开后的总 run 数,
331
+ CLI 再用 `--run-concurrency`(默认 32)限制所有 Case 的活跃 run 总数。设置值超过总 run
332
+ 数或全局上限不会报错,实际执行按较小值分批推进。
333
+
329
334
  `repeat` 也可以写成运行矩阵列表,用不同模型配置各跑若干次并在报告中分组对比
330
335
  (可写在 Case 里,也可写在 `yama.toml` 的 `[[defaults.execution.repeat]]` /
331
336
  Plugin 级同名字段;三层之间整值替换、不逐条目合并):
@@ -250,7 +250,8 @@ Judge:被 tag 容忍的 hard check 失败依然会让该 Step 的 `hard_pass`
250
250
 
251
251
  - 只跑出问题的 Case:`yama __evals__/cases/foo.yaml`。
252
252
  - 结果不稳定:`execution.repeat` 调大看 `pass_rate`,每次 run 的产物目录独立
253
- (`run-001`、`run-002`…),可横向对比 transcript 找分叉点。
253
+ (`run-001`、`run-002`…),可横向对比 transcript 找分叉点。repeat 默认并行;
254
+ 排查时需要逐 run 观察可临时设 `execution.repeat_concurrency: 1`。
254
255
  - 怀疑是模型差异:`execution.repeat` 写成运行矩阵(多份 `model` 配置各跑
255
256
  `times` 次,见 case-schema.md 的 execution 一节),HTML 报告的 Run
256
257
  comparison 会按变体给出结果/Judge/token 对比,并给唯一最优的 run 标 🏆;
@@ -27,8 +27,8 @@ from yama.cli import (
27
27
  main,
28
28
  )
29
29
  from yama.judge_llm import CI_ENV_MARKERS
30
- from yama.llm import LLMError, ScriptedLLMClient
31
- from yama.models import StepResult
30
+ from yama.llm import LLMClient, LLMError, ScriptedLLMClient
31
+ from yama.models import LLMResponse, StepResult
32
32
  from yama.runner import CaseResult, RunResult
33
33
  from yama.thread_case import ThreadCaseError
34
34
 
@@ -59,6 +59,15 @@ steps:
59
59
  return root
60
60
 
61
61
 
62
+ def set_case_execution(plugin_root: Path, execution: dict) -> None:
63
+ for case_path in (plugin_root / "__evals__" / "cases").glob("*.yaml"):
64
+ case = yaml.safe_load(case_path.read_text(encoding="utf-8"))
65
+ case["execution"] = execution
66
+ case_path.write_text(
67
+ yaml.safe_dump(case, allow_unicode=True), encoding="utf-8"
68
+ )
69
+
70
+
62
71
  @contextlib.contextmanager
63
72
  def scripted_llm(*, count: int = 1):
64
73
  """Patch the CLI's LLM client with deterministic scripted responses."""
@@ -106,6 +115,7 @@ class ParserTests(unittest.TestCase):
106
115
  self.assertFalse(args.no_artifacts)
107
116
  self.assertFalse(args.json)
108
117
  self.assertEqual(args.concurrency, 10)
118
+ self.assertEqual(args.run_concurrency, 32)
109
119
  self.assertIsNone(args.filters)
110
120
 
111
121
  def test_dashboard_parser_defaults(self) -> None:
@@ -184,6 +194,18 @@ class ParserTests(unittest.TestCase):
184
194
  _parser().parse_args(["--concurrency", value])
185
195
  self.assertEqual(caught.exception.code, 2)
186
196
 
197
+ def test_run_concurrency_accepts_a_positive_integer(self) -> None:
198
+ args = _parser().parse_args(["--run-concurrency", "64"])
199
+ self.assertEqual(args.run_concurrency, 64)
200
+
201
+ def test_run_concurrency_rejects_zero_negative_and_garbage(self) -> None:
202
+ for value in ["0", "-2", "many"]:
203
+ with self.subTest(value=value), contextlib.redirect_stderr(
204
+ io.StringIO()
205
+ ), self.assertRaises(SystemExit) as caught:
206
+ _parser().parse_args(["--run-concurrency", value])
207
+ self.assertEqual(caught.exception.code, 2)
208
+
187
209
  def test_report_flag_uses_default_sentinel_without_value(self) -> None:
188
210
  args = _parser().parse_args(["--report"])
189
211
  self.assertEqual(args.report, DEFAULT_REPORT)
@@ -204,6 +226,13 @@ class ParserTests(unittest.TestCase):
204
226
 
205
227
  self.assertTrue(args.upload_report)
206
228
  self.assertEqual(args.commit_id, "146bdae")
229
+ self.assertEqual(args.run_concurrency, 32)
230
+
231
+ def test_pr_run_parser_accepts_run_concurrency(self) -> None:
232
+ args = _pr_run_parser().parse_args(
233
+ ["--json-summary", "summary.json", "--run-concurrency", "48"]
234
+ )
235
+ self.assertEqual(args.run_concurrency, 48)
207
236
 
208
237
  def test_report_flag_accepts_explicit_path(self) -> None:
209
238
  args = _parser().parse_args(["--report", "out/custom.html"])
@@ -855,6 +884,79 @@ class MainEndToEndTests(unittest.TestCase):
855
884
  self.assertEqual(counters["peak"], expected_peak)
856
885
  self.assertEqual(len(json.loads(stdout.getvalue())), 5)
857
886
 
887
+ def test_run_concurrency_caps_total_runs_across_cases(self) -> None:
888
+ with tempfile.TemporaryDirectory() as tmp:
889
+ plugin_root = write_plugin(
890
+ Path(tmp) / "plugin", case_names=["a", "b"]
891
+ )
892
+ set_case_execution(plugin_root, {"repeat": 4})
893
+ counters = {"active": 0, "peak": 0}
894
+
895
+ class TimedClient(LLMClient):
896
+ async def complete(self, *, messages, tools, model):
897
+ counters["active"] += 1
898
+ counters["peak"] = max(counters["peak"], counters["active"])
899
+ try:
900
+ await asyncio.sleep(0.01)
901
+ finally:
902
+ counters["active"] -= 1
903
+ return LLMResponse(content="hi there")
904
+
905
+ stdout = io.StringIO()
906
+ with patch(
907
+ "yama.cli.OpenAICompatibleLLMClient", side_effect=TimedClient
908
+ ), patch(
909
+ "yama.cli.LocalFirstJudgeLLMClient",
910
+ side_effect=lambda api_client: api_client,
911
+ ), contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(
912
+ io.StringIO()
913
+ ):
914
+ code = main(
915
+ [
916
+ "--plugin-root",
917
+ str(plugin_root),
918
+ "--no-artifacts",
919
+ "--concurrency",
920
+ "2",
921
+ "--run-concurrency",
922
+ "3",
923
+ "--json",
924
+ ]
925
+ )
926
+
927
+ self.assertEqual(code, 0)
928
+ self.assertEqual(counters["peak"], 3)
929
+ self.assertEqual(
930
+ [len(case["runs"]) for case in json.loads(stdout.getvalue())],
931
+ [4, 4],
932
+ )
933
+
934
+ def test_single_case_with_parallel_repeats_uses_buffered_progress(self) -> None:
935
+ with tempfile.TemporaryDirectory() as tmp:
936
+ plugin_root = write_plugin(Path(tmp) / "plugin")
937
+ set_case_execution(plugin_root, {"repeat": 2})
938
+ stdout = io.StringIO()
939
+
940
+ with scripted_llm(count=2), contextlib.redirect_stdout(stdout):
941
+ code = main(["--plugin-root", str(plugin_root), "--no-artifacts"])
942
+
943
+ self.assertEqual(code, 0)
944
+ self.assertNotIn("Run 1/2", stdout.getvalue())
945
+
946
+ def test_explicit_serial_repeats_keep_streamed_progress(self) -> None:
947
+ with tempfile.TemporaryDirectory() as tmp:
948
+ plugin_root = write_plugin(Path(tmp) / "plugin")
949
+ set_case_execution(
950
+ plugin_root, {"repeat": 2, "repeat_concurrency": 1}
951
+ )
952
+ stdout = io.StringIO()
953
+
954
+ with scripted_llm(count=2), contextlib.redirect_stdout(stdout):
955
+ code = main(["--plugin-root", str(plugin_root), "--no-artifacts"])
956
+
957
+ self.assertEqual(code, 0)
958
+ self.assertIn("Run 1/2", stdout.getvalue())
959
+
858
960
  def test_only_error_results_return_two_not_failure_code(self) -> None:
859
961
  with tempfile.TemporaryDirectory() as tmp:
860
962
  plugin_root = write_plugin(Path(tmp) / "plugin")
@@ -62,6 +62,18 @@ class RecordingClient(LLMClient):
62
62
  return LLMResponse(content=self.content)
63
63
 
64
64
 
65
+ class LocalFirstJudgeForkTests(unittest.TestCase):
66
+ def test_fork_uses_an_independent_api_wrapper(self) -> None:
67
+ api_client = RecordingClient("ok")
68
+ client = LocalFirstJudgeLLMClient(api_client)
69
+
70
+ forked = client.fork()
71
+
72
+ self.assertIsNot(forked, client)
73
+ self.assertIsNot(forked.api_client, api_client)
74
+ self.assertIs(forked.api_client.calls, api_client.calls)
75
+
76
+
65
77
  class FakeProcess:
66
78
  def __init__(self, *, returncode, stdout=b"", stderr=b"") -> None:
67
79
  self.returncode = returncode
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import asyncio
3
4
  import base64
4
5
  import sys
5
6
  import tempfile
@@ -8,7 +9,13 @@ from pathlib import Path
8
9
  from types import ModuleType, SimpleNamespace
9
10
  from unittest.mock import patch
10
11
 
11
- from yama.llm import LLMClient, LiteLLMClient, _litellm_content, delivered_content
12
+ from yama.llm import (
13
+ LLMClient,
14
+ LiteLLMClient,
15
+ ScriptedLLMClient,
16
+ _litellm_content,
17
+ delivered_content,
18
+ )
12
19
  from yama.models import LLMResponse
13
20
 
14
21
 
@@ -202,5 +209,42 @@ class StructuredCompletionTests(unittest.IsolatedAsyncioTestCase):
202
209
  self.assertEqual(len(client.calls), 1)
203
210
 
204
211
 
212
+ class ClientForkTests(unittest.TestCase):
213
+ def test_default_fork_returns_a_distinct_wrapper_with_shared_dependencies(
214
+ self,
215
+ ) -> None:
216
+ client = CapturingStructuredClient()
217
+
218
+ forked = client.fork()
219
+
220
+ self.assertIsNot(forked, client)
221
+ self.assertIs(forked.calls, client.calls)
222
+
223
+
224
+ class ScriptedClientForkTests(unittest.IsolatedAsyncioTestCase):
225
+ async def test_parallel_forks_share_one_script_cursor(self) -> None:
226
+ client = ScriptedLLMClient(
227
+ [{"content": "one"}, {"content": "two"}]
228
+ )
229
+ forks = [client.fork(), client.fork()]
230
+
231
+ responses = await asyncio.gather(
232
+ *(
233
+ fork.complete(
234
+ messages=[{"role": "user", "content": "hello"}],
235
+ tools=[],
236
+ model={"name": "test-model"},
237
+ )
238
+ for fork in forks
239
+ )
240
+ )
241
+
242
+ self.assertEqual(
243
+ [response.content for response in responses], ["one", "two"]
244
+ )
245
+ self.assertEqual(client.index, 2)
246
+ client.assert_consumed()
247
+
248
+
205
249
  if __name__ == "__main__":
206
250
  unittest.main()
@@ -230,6 +230,50 @@ class OpenAICompatibleLLMClientTests(unittest.IsolatedAsyncioTestCase):
230
230
  self.assertNotIn("api_key", call)
231
231
  self.assertNotIn("base_url", call)
232
232
 
233
+ async def test_parallel_forks_share_the_lazy_transport_for_one_endpoint(
234
+ self,
235
+ ) -> None:
236
+ constructed: list[dict] = []
237
+ stub = ModuleType("openai")
238
+
239
+ class AsyncOpenAI:
240
+ def __init__(self, *, api_key=None, base_url=None, max_retries=None):
241
+ constructed.append(
242
+ {
243
+ "api_key": api_key,
244
+ "base_url": base_url,
245
+ "max_retries": max_retries,
246
+ }
247
+ )
248
+ self.chat = SimpleNamespace(completions=_FakeCompletions())
249
+
250
+ stub.AsyncOpenAI = AsyncOpenAI
251
+
252
+ with patch.dict(sys.modules, {"openai": stub}):
253
+ adapter = OpenAICompatibleLLMClient(
254
+ environment={
255
+ "YAMA_LLM_API_KEY": "shared-key",
256
+ "YAMA_LLM_BASE_URL": "https://shared.example/v1",
257
+ }
258
+ )
259
+ responses = await asyncio.gather(
260
+ *(self._complete(adapter.fork()) for _ in range(2))
261
+ )
262
+
263
+ self.assertEqual(
264
+ [response.content for response in responses], ["done", "done"]
265
+ )
266
+ self.assertEqual(
267
+ constructed,
268
+ [
269
+ {
270
+ "api_key": "shared-key",
271
+ "base_url": "https://shared.example/v1",
272
+ "max_retries": 0,
273
+ }
274
+ ],
275
+ )
276
+
233
277
  async def test_normalizes_unexpected_client_construction_error(self) -> None:
234
278
  fake = _FakeClient()
235
279
  adapter = OpenAICompatibleLLMClient(client=fake)