python-yama 0.10.4__tar.gz → 0.10.5__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 (72) hide show
  1. {python_yama-0.10.4 → python_yama-0.10.5}/PKG-INFO +3 -2
  2. {python_yama-0.10.4 → python_yama-0.10.5}/README.md +2 -1
  3. {python_yama-0.10.4 → python_yama-0.10.5}/README.zh-CN.md +2 -1
  4. {python_yama-0.10.4 → python_yama-0.10.5}/docs/agent-skill-test-framework-design.md +19 -3
  5. {python_yama-0.10.4 → python_yama-0.10.5}/skills/eval-plugin-with-yama/SKILL.md +4 -1
  6. {python_yama-0.10.4 → python_yama-0.10.5}/skills/eval-plugin-with-yama/references/debugging.md +4 -0
  7. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_cli.py +211 -0
  8. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_runner.py +48 -1
  9. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_workspace.py +30 -0
  10. {python_yama-0.10.4 → python_yama-0.10.5}/yama/cli.py +58 -11
  11. {python_yama-0.10.4 → python_yama-0.10.5}/yama/runner.py +16 -6
  12. {python_yama-0.10.4 → python_yama-0.10.5}/yama/workspace.py +1 -0
  13. {python_yama-0.10.4 → python_yama-0.10.5}/.github/workflows/publish.yml +0 -0
  14. {python_yama-0.10.4 → python_yama-0.10.5}/.gitignore +0 -0
  15. {python_yama-0.10.4 → python_yama-0.10.5}/CLAUDE.md +0 -0
  16. {python_yama-0.10.4 → python_yama-0.10.5}/LICENSE +0 -0
  17. {python_yama-0.10.4 → python_yama-0.10.5}/docs/case-schema-reference.md +0 -0
  18. {python_yama-0.10.4 → python_yama-0.10.5}/docs/yama-intro.html +0 -0
  19. {python_yama-0.10.4 → python_yama-0.10.5}/pyproject.toml +0 -0
  20. {python_yama-0.10.4 → python_yama-0.10.5}/skills/eval-plugin-with-yama/references/case-schema.md +0 -0
  21. {python_yama-0.10.4 → python_yama-0.10.5}/skills/eval-plugin-with-yama/references/install-upgrade.md +0 -0
  22. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_assertions.py +0 -0
  23. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_cli_shim.py +0 -0
  24. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_dashboard.py +0 -0
  25. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_framework.py +0 -0
  26. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_judge_llm.py +0 -0
  27. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_llm.py +0 -0
  28. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_main_entrypoint.py +0 -0
  29. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_mocks.py +0 -0
  30. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_openai_llm.py +0 -0
  31. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_pr.py +0 -0
  32. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_preview.py +0 -0
  33. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_public_api.py +0 -0
  34. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_report.py +0 -0
  35. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_report_bundle.py +0 -0
  36. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_report_upload.py +0 -0
  37. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_run_plan.py +0 -0
  38. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_skill_loader.py +0 -0
  39. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_skill_tool.py +0 -0
  40. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_thread_case.py +0 -0
  41. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_tool_loader.py +0 -0
  42. {python_yama-0.10.4 → python_yama-0.10.5}/tests/test_usage.py +0 -0
  43. {python_yama-0.10.4 → python_yama-0.10.5}/uv.lock +0 -0
  44. {python_yama-0.10.4 → python_yama-0.10.5}/yama/__init__.py +0 -0
  45. {python_yama-0.10.4 → python_yama-0.10.5}/yama/__main__.py +0 -0
  46. {python_yama-0.10.4 → python_yama-0.10.5}/yama/assertions.py +0 -0
  47. {python_yama-0.10.4 → python_yama-0.10.5}/yama/dashboard.py +0 -0
  48. {python_yama-0.10.4 → python_yama-0.10.5}/yama/judge_llm.py +0 -0
  49. {python_yama-0.10.4 → python_yama-0.10.5}/yama/judge_routing.py +0 -0
  50. {python_yama-0.10.4 → python_yama-0.10.5}/yama/llm.py +0 -0
  51. {python_yama-0.10.4 → python_yama-0.10.5}/yama/loaders/__init__.py +0 -0
  52. {python_yama-0.10.4 → python_yama-0.10.5}/yama/loaders/case.py +0 -0
  53. {python_yama-0.10.4 → python_yama-0.10.5}/yama/loaders/common.py +0 -0
  54. {python_yama-0.10.4 → python_yama-0.10.5}/yama/loaders/skill_loader.py +0 -0
  55. {python_yama-0.10.4 → python_yama-0.10.5}/yama/loaders/tool_loader.py +0 -0
  56. {python_yama-0.10.4 → python_yama-0.10.5}/yama/mocks.py +0 -0
  57. {python_yama-0.10.4 → python_yama-0.10.5}/yama/models.py +0 -0
  58. {python_yama-0.10.4 → python_yama-0.10.5}/yama/openai_llm.py +0 -0
  59. {python_yama-0.10.4 → python_yama-0.10.5}/yama/pr.py +0 -0
  60. {python_yama-0.10.4 → python_yama-0.10.5}/yama/preview.py +0 -0
  61. {python_yama-0.10.4 → python_yama-0.10.5}/yama/report.py +0 -0
  62. {python_yama-0.10.4 → python_yama-0.10.5}/yama/report_bundle.py +0 -0
  63. {python_yama-0.10.4 → python_yama-0.10.5}/yama/report_upload.py +0 -0
  64. {python_yama-0.10.4 → python_yama-0.10.5}/yama/thread_case.py +0 -0
  65. {python_yama-0.10.4 → python_yama-0.10.5}/yama/tools/__init__.py +0 -0
  66. {python_yama-0.10.4 → python_yama-0.10.5}/yama/tools/base.py +0 -0
  67. {python_yama-0.10.4 → python_yama-0.10.5}/yama/tools/bash/__init__.py +0 -0
  68. {python_yama-0.10.4 → python_yama-0.10.5}/yama/tools/bash/_cli_shim.py +0 -0
  69. {python_yama-0.10.4 → python_yama-0.10.5}/yama/tools/bash/bash.py +0 -0
  70. {python_yama-0.10.4 → python_yama-0.10.5}/yama/tools/bash/fs.py +0 -0
  71. {python_yama-0.10.4 → python_yama-0.10.5}/yama/tools/skill/__init__.py +0 -0
  72. {python_yama-0.10.4 → python_yama-0.10.5}/yama/tools/skill/skill.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: python-yama
3
- Version: 0.10.4
3
+ Version: 0.10.5
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
@@ -34,7 +34,8 @@ English | [简体中文](https://github.com/world-sim-dev/yama/blob/main/README.
34
34
  ## Quick start
35
35
 
36
36
  ```bash
37
- # Run from a plugin root; collects __evals__/cases/**/*.yaml by default
37
+ # Run from a plugin root; collects __evals__/cases/**/*.yaml by default,
38
+ # excluding macOS AppleDouble ._* sidecars
38
39
  cd dingding-simple
39
40
  YAMA_LLM_API_KEY=... uv run --project yama yama
40
41
 
@@ -7,7 +7,8 @@ English | [简体中文](https://github.com/world-sim-dev/yama/blob/main/README.
7
7
  ## Quick start
8
8
 
9
9
  ```bash
10
- # Run from a plugin root; collects __evals__/cases/**/*.yaml by default
10
+ # Run from a plugin root; collects __evals__/cases/**/*.yaml by default,
11
+ # excluding macOS AppleDouble ._* sidecars
11
12
  cd dingding-simple
12
13
  YAMA_LLM_API_KEY=... uv run --project yama yama
13
14
 
@@ -7,7 +7,8 @@
7
7
  ## 快速开始
8
8
 
9
9
  ```bash
10
- # 在 Plugin 根目录下直接运行,默认收集 __evals__/cases/**/*.yaml
10
+ # 在 Plugin 根目录下直接运行,默认收集 __evals__/cases/**/*.yaml,
11
+ # 并忽略 macOS AppleDouble 的 ._* 边车文件
11
12
  cd dingding-simple
12
13
  YAMA_LLM_API_KEY=... uv run --project yama yama
13
14
 
@@ -304,6 +304,9 @@ PATTERN 含 `*`/`?`/`[` 任一字符时按 `fnmatch` 通配符(大小写敏感
304
304
  所以被筛掉的 Case 即使 YAML 损坏也不会阻塞本次运行;`--list` 同样受筛选影响。
305
305
  筛选后一个 Case 都不剩时报 `No eval cases matched the case filter.` 并以退出码 2
306
306
  结束(与"根本没收集到 Case"同级别,但错误信息区分两种情况)。
307
+ glob 或显式路径展开后,basename 以 `._` 开头的 macOS AppleDouble 边车文件会在
308
+ `is_file()` 校验和上述筛选之前直接丢弃;它们是 exFAT 等文件系统上的二进制元数据,
309
+ 不是 Case YAML。这里只保留 `._*` 前缀,不会泛化为忽略所有点文件。
307
310
 
308
311
  **Case/run 两级并发调度(`--concurrency` / `--run-concurrency`,`cli.py:_run`)。**
309
312
  收集到的多个 Case 先用 `asyncio.Semaphore(concurrency)` + `asyncio.gather` 在同一事件
@@ -322,9 +325,15 @@ PATTERN 含 `*`/`?`/`[` 任一字符时按 `fnmatch` 通配符(大小写敏感
322
325
  - 结果数组保持**收集顺序**(`gather` 保序),与完成先后无关;汇总表格、`--json`
323
326
  输出、HTML 报告的 Case 顺序因此稳定;Case 内第二层 `gather` 同样让 `runs` 始终按
324
327
  `run_index` 排列。
325
- - 某个 Case 抛出异常(罕见:run 内的错误都会被 `_run_once` 捕获进
326
- `RunResult.error`)时,其余 Case 仍会跑完并写完产物(`gather`
327
- `return_exceptions=True`),随后第一个异常按原有 `main()` 错误出口重新抛出。
328
+ - 某个 Case 逸出普通、非 `LLMError` 的 `Exception`(罕见:run 内的错误通常都会被
329
+ `_run_once` 捕获进 `RunResult.error`)时,其余 Case 仍会跑完并写完产物(`gather`
330
+ `return_exceptions=True`);CLI 随后为该 Case 合成一个 `run_index=1`、
331
+ `status=error`、`error_kind=framework` 的 RunResult,使终端、JSON、HTML 和 PR
332
+ summary/report 都保留正确的 Case 顺序、错误计数或错误详情,HTML 另保留 traceback。
333
+ suite 完成报告后返回退出码 2;
334
+ 普通 CLI 的顶层 `LLMError` 继续走现有 LLM error 出口;`pr-run` 则把它附着为
335
+ 对应 Case 的 `error_kind=llm` 结果,以便继续写完整 summary/report。
336
+ `KeyboardInterrupt`、`SystemExit`、`asyncio.CancelledError` 等非普通异常仍向上传播。
328
337
  - run 间的 Mock state、bash 沙箱工作目录、持久 shell 会话和产物目录都已按
329
338
  `run_index` 隔离;Case 级旧目录清理只在并发任务启动前执行一次。
330
339
  - 进度输出按实际并发模式切换(见第 13 节):多个 Case 可重叠或任一 Case 的有效 run
@@ -1581,6 +1590,11 @@ mock 脚本与旧文件,结果不可复现。run 结束(成功、断言失
1581
1590
  进程贯穿整个 run,`cd`、`export`、写文件等状态天然延续到下一次 Tool Call,不需要
1582
1591
  额外的状态字典维护 cwd/环境。
1583
1592
 
1593
+ 启动前删除通过 `shutil.rmtree(onexc=...)` 逐项处理:某个目录项已经消失产生的
1594
+ `FileNotFoundError`/`ENOENT` 视为删除目标已达成并继续遍历,权限、I/O、非空目录等
1595
+ 其他异常不被静默吞掉。这个精确容错同时用于下述旧产物目录清理,专门覆盖 macOS +
1596
+ exFAT 上 AppleDouble `._*` 文件在扫描与 `unlink` 之间消失的竞态。
1597
+
1584
1598
  **命令执行:持久 shell + marker 协议。** 每次 Tool Call 把命令包装成如下 payload
1585
1599
  写入这个 shell 的 stdin:
1586
1600
 
@@ -2509,6 +2523,8 @@ class ToolCallRecord:
2509
2523
  `execution.repeat` 比上次小,不清理就会留下过期的 `run-002` 等目录,人工或脚本
2510
2524
  扫描 `.yama/runs` 时会把旧执行误当成本次结果。`--no-artifacts` 时不写也不删任何
2511
2525
  产物目录(用户显式选择不落盘,不应顺带删掉历史产物),但 fs-runs 工作目录照常清理。
2526
+ 每个 run 重写自身产物目录前也使用同一条“只忽略 ENOENT”的删除规则;创建目录、复制
2527
+ fixture 或写入新产物失败仍产生 framework error,不会被清理容错隐藏。
2512
2528
 
2513
2529
  `--report` 触发的单文件 HTML 报告(`report.py:write_html_report` /
2514
2530
  `write_timestamped_report`)是 CLI 层面单独生成的汇总产物,**不属于**上面这份逐
@@ -49,7 +49,7 @@ yama eval。接到自然语言请求时,先把意图归到下面一类,再
49
49
  ├── config.json # 可用 skill_refs 显式引用版本化公共 Skill
50
50
  ├── skills/<skill-name>/SKILL.md # 可被模型按需查阅的 Skill
51
51
  └── __evals__/
52
- ├── cases/ # Case 收集目录(默认 glob __evals__/cases/**/*.yaml)
52
+ ├── cases/ # 默认 glob __evals__/cases/**/*.yaml;忽略 macOS ._* 边车
53
53
  ├── tools/ # Tool Schema YAML(推荐)
54
54
  ├── mocks/ # Python Handler(推荐)
55
55
  ├── fixtures/ # 图片 / 音频等多模态附件
@@ -284,6 +284,9 @@ Judge 默认超时均为 120 秒,整 Step 默认超时仍为 300 秒。
284
284
  设 `repeat_concurrency: 1` 可让指定 Case 串行。只要 Case 或 run 存在并发,终端底部就
285
285
  显示逐 Case 状态面板,并在 Case 完成后把 Run/Step 明细整块打印到面板上方;需要逐 Step
286
286
  流式输出时,同时使用 `--concurrency 1 --run-concurrency 1`,或让目标 Case 显式串行。
287
+ macOS 在 exFAT 等卷上生成的 AppleDouble `._*.yaml` 会在解析前被忽略;启动前清理旧
288
+ `fs-runs`/产物时,目录项已经消失产生的 ENOENT 视为清理成功,权限和其他 I/O 错误仍作为
289
+ 对应 Case 的 Framework ERROR 进入报告,其他 Case 继续运行。
287
290
 
288
291
  退出码:`0` 全部通过;`1` 有 Case 失败;`2` Collection error、顶层 LLM error、
289
292
  没有收集到任何 Case,或运行后只有/存在 ERROR(LLM 调用异常、Step 超时)且没有
@@ -89,6 +89,7 @@ CI 若开启 `yama pr-run --report --upload-report --commit-id <sha>`,上传
89
89
  | Python handler/checker 相关 | 引用缺 `:callable`、目标不存在/不可调用/签名不兼容、路径逃出 Plugin Root |
90
90
  | `No eval cases collected.` | glob 没命中任何文件;用 `--list` 验证收集范围,确认文件在 `__evals__/cases/**/*.yaml` 下 |
91
91
  | `No eval cases matched the case filter.` | 收集到了 Case 但全部被 `-k/--filter` 筛掉;PATTERN 匹配的是相对 Plugin Root 的 case key(如 `__evals__/cases/foo.yaml`),子串匹配大小写敏感,含 `*`/`?`/`[` 时整个 key 要能被通配符匹配上;用 `--list`(不带 `-k`)核对完整 key |
92
+ | `UnicodeDecodeError` / YAML 错误指向 `._*.yaml` | 这是 macOS 在 exFAT 等卷上生成的 AppleDouble 二进制边车文件,不是真正 Case;当前 Yama 会在解析前忽略 `._*`。若仍出现,先确认实际运行的是包含该兼容修复的 Yama 版本 |
92
93
 
93
94
  注意两个**不会**在 collection 阶段报错的陷阱:
94
95
  `context.builders` 的 `position` 拼错会静默失效(不报错不生效);
@@ -257,6 +258,9 @@ Judge:被 tag 容忍的 hard check 失败依然会让该 Step 的 `hard_pass`
257
258
  不清理——直接进去看模型写了什么文件、`.mockbin/` 里编译出了哪些假命令。
258
259
  该目录在**下一次执行同一 Case 时**才被整体清掉重建,因此排查时看到的内容
259
260
  总是最近一次执行的;改了 `mocks.cli`/`mocks.fs` 配置后重跑不会复用旧脚本。
261
+ macOS + exFAT 上 `._*` 在删除中途消失产生的 ENOENT 会被视为已删除并继续清理;
262
+ 权限和其他 I/O 错误不会静默忽略,而会作为当前 Case 的 Framework ERROR 进入报告,
263
+ 其余 Case 继续运行,suite 最终返回退出码 2。
260
264
  - `command not found`(exit 127)三种可能:命令没在 `mocks.cli` 声明;模型用了
261
265
  绝对路径/带 `/` 的调用(绕过 PATH shadow,Mock 不生效,要求模型用裸命令名);
262
266
  命令名拼错。
@@ -18,6 +18,7 @@ from yama.cli import (
18
18
  DEFAULT_REPORT,
19
19
  ParallelProgressPrinter,
20
20
  ProgressPrinter,
21
+ _case_results_from_outcomes,
21
22
  _create_runner,
22
23
  _dashboard_parser,
23
24
  _parser,
@@ -33,6 +34,37 @@ from yama.runner import CaseResult, RunResult
33
34
  from yama.thread_case import ThreadCaseError
34
35
 
35
36
 
37
+ class CaseOutcomeNormalizationTests(unittest.TestCase):
38
+ def test_exception_becomes_case_framework_error(self) -> None:
39
+ case = SimpleNamespace(case_key="cases/a.yaml", description="a")
40
+ error = PermissionError("denied")
41
+
42
+ [result] = _case_results_from_outcomes([case], [error])
43
+
44
+ self.assertEqual(result.status, "error")
45
+ self.assertEqual(result.description, "a")
46
+ self.assertEqual(len(result.runs), 1)
47
+ self.assertEqual(result.runs[0].run_index, 1)
48
+ self.assertEqual(result.runs[0].error_kind, "framework")
49
+ self.assertEqual(result.runs[0].error, "PermissionError: denied")
50
+ self.assertIn("PermissionError: denied", result.runs[0].traceback)
51
+
52
+ def test_cancelled_error_is_reraised(self) -> None:
53
+ case = SimpleNamespace(case_key="cases/a.yaml", description="a")
54
+
55
+ with self.assertRaises(asyncio.CancelledError):
56
+ _case_results_from_outcomes([case], [asyncio.CancelledError()])
57
+
58
+ def test_llm_error_keeps_the_top_level_llm_error_path(self) -> None:
59
+ case = SimpleNamespace(case_key="cases/a.yaml", description="a")
60
+
61
+ with self.assertRaisesRegex(LLMError, "provider unavailable"):
62
+ _case_results_from_outcomes(
63
+ [case],
64
+ [LLMError("provider unavailable")],
65
+ )
66
+
67
+
36
68
  def write_plugin(
37
69
  root: Path,
38
70
  *,
@@ -696,6 +728,60 @@ class RunnerFactoryTests(unittest.TestCase):
696
728
 
697
729
 
698
730
  class MainEndToEndTests(unittest.TestCase):
731
+ def test_case_framework_error_does_not_abort_remaining_cases(self) -> None:
732
+ with tempfile.TemporaryDirectory() as tmp:
733
+ plugin_root = write_plugin(
734
+ Path(tmp) / "plugin",
735
+ case_names=["a", "b"],
736
+ )
737
+ report_path = Path(tmp) / "report.html"
738
+
739
+ class StubRunner:
740
+ def __init__(self, *args, **kwargs):
741
+ pass
742
+
743
+ async def run_case(self, case):
744
+ if case.case_key.endswith("a.yaml"):
745
+ raise PermissionError("denied")
746
+ return CaseResult(
747
+ case_key=case.case_key,
748
+ description=case.description,
749
+ passed=True,
750
+ status="pass",
751
+ runs=[RunResult(run_index=1, passed=True, status="pass")],
752
+ pass_rate=1.0,
753
+ )
754
+
755
+ stdout = io.StringIO()
756
+ stderr = io.StringIO()
757
+ with patch("yama.cli.YamaRunner", StubRunner), \
758
+ contextlib.redirect_stdout(stdout), \
759
+ contextlib.redirect_stderr(stderr):
760
+ code = main(
761
+ [
762
+ "--plugin-root",
763
+ str(plugin_root),
764
+ "--no-artifacts",
765
+ "--json",
766
+ "--concurrency",
767
+ "1",
768
+ "--report",
769
+ str(report_path),
770
+ ]
771
+ )
772
+
773
+ payload = json.loads(stdout.getvalue())
774
+ self.assertEqual(code, 2)
775
+ self.assertEqual(len(payload), 2)
776
+ self.assertEqual(payload[0]["status"], "error")
777
+ self.assertEqual(payload[0]["runs"][0]["error_kind"], "framework")
778
+ self.assertEqual(payload[1]["status"], "pass")
779
+ self.assertTrue(report_path.is_file())
780
+ self.assertIn(
781
+ "PermissionError: denied",
782
+ report_path.read_text(encoding="utf-8"),
783
+ )
784
+
699
785
  def test_list_flag_prints_case_keys_without_running(self) -> None:
700
786
  with tempfile.TemporaryDirectory() as tmp:
701
787
  plugin_root = write_plugin(Path(tmp) / "plugin")
@@ -1799,6 +1885,131 @@ class PrRunCliTests(unittest.TestCase):
1799
1885
  (plugin_root / ".yama" / "reports" / "latest.html").exists()
1800
1886
  )
1801
1887
 
1888
+ def test_pr_run_case_framework_error_stays_attached_to_case(self) -> None:
1889
+ with tempfile.TemporaryDirectory() as tmp:
1890
+ root = Path(tmp)
1891
+ plugin_root = write_plugin(
1892
+ root / "plugin-a",
1893
+ case_names=["a", "b"],
1894
+ )
1895
+ (root / "yama.toml").write_text(
1896
+ '[plugins.plugin-a]\npath = "plugin-a"\n',
1897
+ encoding="utf-8",
1898
+ )
1899
+ changed = root / "changed.txt"
1900
+ changed.write_text(
1901
+ "plugin-a/__evals__/cases/a.yaml\n"
1902
+ "plugin-a/__evals__/cases/b.yaml\n",
1903
+ encoding="utf-8",
1904
+ )
1905
+ summary = root / "summary.json"
1906
+
1907
+ class StubRunner:
1908
+ def __init__(self, *args, **kwargs):
1909
+ pass
1910
+
1911
+ async def run_case(self, case):
1912
+ if case.case_key.endswith("a.yaml"):
1913
+ raise PermissionError("denied")
1914
+ return CaseResult(
1915
+ case_key=case.case_key,
1916
+ description=case.description,
1917
+ passed=True,
1918
+ status="pass",
1919
+ runs=[RunResult(run_index=1, passed=True, status="pass")],
1920
+ pass_rate=1.0,
1921
+ )
1922
+
1923
+ with chdir(root), patch("yama.cli.YamaRunner", StubRunner):
1924
+ code = main(
1925
+ [
1926
+ "pr-run",
1927
+ "--changed-files",
1928
+ str(changed),
1929
+ "--report",
1930
+ "--json-summary",
1931
+ str(summary),
1932
+ "--concurrency",
1933
+ "1",
1934
+ ]
1935
+ )
1936
+
1937
+ payload = json.loads(summary.read_text(encoding="utf-8"))
1938
+ plugin = payload["plugins"][0]
1939
+ report_path = plugin_root / ".yama" / "reports" / "latest.html"
1940
+ self.assertEqual(code, 2)
1941
+ self.assertEqual(plugin["status"], "error")
1942
+ self.assertEqual(plugin["counts"]["pass"], 1)
1943
+ self.assertEqual(plugin["counts"]["error"], 1)
1944
+ self.assertEqual(plugin["errors"], [])
1945
+ self.assertTrue(report_path.is_file())
1946
+ self.assertIn(
1947
+ "PermissionError: denied",
1948
+ report_path.read_text(encoding="utf-8"),
1949
+ )
1950
+
1951
+ def test_pr_run_case_llm_error_stays_attached_to_case(self) -> None:
1952
+ with tempfile.TemporaryDirectory() as tmp:
1953
+ root = Path(tmp)
1954
+ plugin_root = write_plugin(
1955
+ root / "plugin-a",
1956
+ case_names=["a", "b"],
1957
+ )
1958
+ (root / "yama.toml").write_text(
1959
+ '[plugins.plugin-a]\npath = "plugin-a"\n',
1960
+ encoding="utf-8",
1961
+ )
1962
+ changed = root / "changed.txt"
1963
+ changed.write_text(
1964
+ "plugin-a/__evals__/cases/a.yaml\n"
1965
+ "plugin-a/__evals__/cases/b.yaml\n",
1966
+ encoding="utf-8",
1967
+ )
1968
+ summary = root / "summary.json"
1969
+
1970
+ class StubRunner:
1971
+ def __init__(self, *args, **kwargs):
1972
+ pass
1973
+
1974
+ async def run_case(self, case):
1975
+ if case.case_key.endswith("a.yaml"):
1976
+ raise LLMError("provider unavailable")
1977
+ return CaseResult(
1978
+ case_key=case.case_key,
1979
+ description=case.description,
1980
+ passed=True,
1981
+ status="pass",
1982
+ runs=[RunResult(run_index=1, passed=True, status="pass")],
1983
+ pass_rate=1.0,
1984
+ )
1985
+
1986
+ with chdir(root), patch("yama.cli.YamaRunner", StubRunner):
1987
+ code = main(
1988
+ [
1989
+ "pr-run",
1990
+ "--changed-files",
1991
+ str(changed),
1992
+ "--report",
1993
+ "--json-summary",
1994
+ str(summary),
1995
+ "--concurrency",
1996
+ "1",
1997
+ ]
1998
+ )
1999
+
2000
+ payload = json.loads(summary.read_text(encoding="utf-8"))
2001
+ plugin = payload["plugins"][0]
2002
+ report_path = plugin_root / ".yama" / "reports" / "latest.html"
2003
+ self.assertEqual(code, 2)
2004
+ self.assertEqual(plugin["status"], "error")
2005
+ self.assertEqual(plugin["counts"]["pass"], 1)
2006
+ self.assertEqual(plugin["counts"]["error"], 1)
2007
+ self.assertEqual(plugin["errors"], [])
2008
+ self.assertTrue(report_path.is_file())
2009
+ report = report_path.read_text(encoding="utf-8")
2010
+ self.assertIn("LLM error", report)
2011
+ self.assertIn("LLMError: provider unavailable", report)
2012
+
1802
2013
  def test_pr_run_upload_requires_report(self) -> None:
1803
2014
  with tempfile.TemporaryDirectory() as tmp:
1804
2015
  root = Path(tmp)
@@ -1,7 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import asyncio
4
+ import errno
4
5
  import json
6
+ import os
5
7
  import tempfile
6
8
  import unittest
7
9
  from pathlib import Path
@@ -9,7 +11,52 @@ from unittest.mock import patch
9
11
 
10
12
  from yama.assertions import AssertionConfigurationError
11
13
  from yama.models import StepResult, ToolSchema
12
- from yama.runner import CaseResult, RunResult, case_tag_summary, tag_pass_summary
14
+ from yama.runner import (
15
+ CaseResult,
16
+ RunResult,
17
+ _rmtree_missing_ok,
18
+ case_tag_summary,
19
+ tag_pass_summary,
20
+ )
21
+
22
+
23
+ class RmtreeMissingOkTests(unittest.TestCase):
24
+ def test_continues_when_unlink_target_disappears(self) -> None:
25
+ with tempfile.TemporaryDirectory() as tmp:
26
+ root = Path(tmp) / "stale"
27
+ root.mkdir()
28
+ (root / "._case.yaml").write_bytes(b"appledouble")
29
+ (root / "remaining.txt").write_text("old", encoding="utf-8")
30
+ original_unlink = os.unlink
31
+ disappeared = False
32
+
33
+ def unlink_then_disappear(path, *args, **kwargs):
34
+ nonlocal disappeared
35
+ if Path(path).name == "._case.yaml" and not disappeared:
36
+ disappeared = True
37
+ original_unlink(path, *args, **kwargs)
38
+ raise FileNotFoundError(
39
+ errno.ENOENT,
40
+ "already gone",
41
+ str(path),
42
+ )
43
+ return original_unlink(path, *args, **kwargs)
44
+
45
+ with patch("os.unlink", side_effect=unlink_then_disappear):
46
+ _rmtree_missing_ok(root)
47
+
48
+ self.assertTrue(disappeared)
49
+ self.assertFalse(root.exists())
50
+
51
+ def test_reraises_non_missing_errors(self) -> None:
52
+ with tempfile.TemporaryDirectory() as tmp:
53
+ root = Path(tmp) / "stale"
54
+ root.mkdir()
55
+ (root / "locked.txt").write_text("old", encoding="utf-8")
56
+
57
+ with patch("os.unlink", side_effect=PermissionError("denied")):
58
+ with self.assertRaises(PermissionError):
59
+ _rmtree_missing_ok(root)
13
60
 
14
61
 
15
62
  def make_step(hard_checks: list[dict]) -> StepResult:
@@ -367,6 +367,36 @@ class CollectCasePathsTests(unittest.TestCase):
367
367
  paths = collect_case_paths(root, config, {})
368
368
  self.assertEqual(paths, sorted([first.resolve(), second.resolve()]))
369
369
 
370
+ def test_glob_skips_appledouble_yaml_sidecars(self) -> None:
371
+ with tempfile.TemporaryDirectory() as tmp:
372
+ root = Path(tmp)
373
+ cases_dir = root / "__evals__" / "cases"
374
+ cases_dir.mkdir(parents=True)
375
+ case_file = cases_dir / "valid.yaml"
376
+ case_file.write_text("", encoding="utf-8")
377
+ (cases_dir / "._valid.yaml").write_bytes(b"\x00\x05AppleDouble")
378
+
379
+ paths = collect_case_paths(root, WorkspaceConfig(root=root), {})
380
+
381
+ self.assertEqual(paths, [case_file.resolve()])
382
+
383
+ def test_explicit_appledouble_path_is_skipped(self) -> None:
384
+ with tempfile.TemporaryDirectory() as tmp:
385
+ root = Path(tmp)
386
+ cases_dir = root / "__evals__" / "cases"
387
+ cases_dir.mkdir(parents=True)
388
+ sidecar = cases_dir / "._case.yaml"
389
+ sidecar.write_bytes(b"\x00\x05AppleDouble")
390
+
391
+ paths = collect_case_paths(
392
+ root,
393
+ WorkspaceConfig(root=root),
394
+ {},
395
+ explicit_paths=[sidecar],
396
+ )
397
+
398
+ self.assertEqual(paths, [])
399
+
370
400
  def test_plugin_specific_case_patterns_override_workspace(self) -> None:
371
401
  with tempfile.TemporaryDirectory() as tmp:
372
402
  root = Path(tmp)
@@ -5,6 +5,7 @@ import asyncio
5
5
  import json
6
6
  import os
7
7
  import sys
8
+ import traceback
8
9
  from io import StringIO
9
10
  from pathlib import Path
10
11
  from typing import Any
@@ -46,7 +47,10 @@ from .report import write_html_report, write_timestamped_report
46
47
  from .report_bundle import validate_commit_id
47
48
  from .report_upload import upload_pr_reports
48
49
  from .runner import (
50
+ CaseResult,
51
+ ResultErrorKind,
49
52
  RunConcurrencyLimiter,
53
+ RunResult,
50
54
  YamaRunner,
51
55
  combine_usage,
52
56
  resolve_repeat_concurrency,
@@ -68,6 +72,52 @@ from .thread_case import (
68
72
  DEFAULT_REPORT = Path("__yama_default_report__")
69
73
 
70
74
 
75
+ def _case_error_result(
76
+ case: Any,
77
+ exc: Exception,
78
+ *,
79
+ error_kind: ResultErrorKind,
80
+ ) -> CaseResult:
81
+ run = RunResult(
82
+ run_index=1,
83
+ passed=False,
84
+ status="error",
85
+ error_kind=error_kind,
86
+ error=f"{type(exc).__name__}: {exc}",
87
+ traceback="".join(traceback.format_exception(exc)),
88
+ )
89
+ return CaseResult(
90
+ case_key=case.case_key,
91
+ description=case.description,
92
+ passed=False,
93
+ status="error",
94
+ runs=[run],
95
+ pass_rate=0.0,
96
+ )
97
+
98
+
99
+ def _case_results_from_outcomes(
100
+ cases: list[Any],
101
+ outcomes: list[Any],
102
+ *,
103
+ llm_errors_as_results: bool = False,
104
+ ) -> list[CaseResult]:
105
+ results = []
106
+ for case, outcome in zip(cases, outcomes, strict=True):
107
+ if isinstance(outcome, LLMError):
108
+ if not llm_errors_as_results:
109
+ raise outcome
110
+ results.append(_case_error_result(case, outcome, error_kind="llm"))
111
+ continue
112
+ if isinstance(outcome, Exception):
113
+ results.append(_case_error_result(case, outcome, error_kind="framework"))
114
+ elif isinstance(outcome, BaseException):
115
+ raise outcome
116
+ else:
117
+ results.append(outcome)
118
+ return results
119
+
120
+
71
121
  def _result_status(value: Any) -> str:
72
122
  if isinstance(value, bool):
73
123
  return "pass" if value else "fail"
@@ -860,7 +910,8 @@ async def _run(args: argparse.Namespace) -> int:
860
910
 
861
911
  try:
862
912
  # return_exceptions lets every case finish (and write its artifacts)
863
- # before the first failure is re-raised for main()'s error handling.
913
+ # before framework exceptions are attached to their cases. Top-level
914
+ # LLM/process-control errors keep their existing error paths.
864
915
  outcomes = await asyncio.gather(
865
916
  *(
866
917
  run_one(case, result_root)
@@ -870,10 +921,7 @@ async def _run(args: argparse.Namespace) -> int:
870
921
  )
871
922
  finally:
872
923
  progress.close()
873
- for outcome in outcomes:
874
- if isinstance(outcome, BaseException):
875
- raise outcome
876
- all_results = list(outcomes)
924
+ all_results = _case_results_from_outcomes(collected, outcomes)
877
925
  report_target = args.report
878
926
  if report_target == DEFAULT_REPORT:
879
927
  # Default reports accumulate as history: a timestamped file per
@@ -1095,13 +1143,12 @@ async def _run_pr_run(args: argparse.Namespace) -> int:
1095
1143
  )
1096
1144
  finally:
1097
1145
  progress.close()
1146
+ results = _case_results_from_outcomes(
1147
+ cases,
1148
+ outcomes,
1149
+ llm_errors_as_results=True,
1150
+ )
1098
1151
  plugin_errors = []
1099
- for outcome in outcomes:
1100
- if isinstance(outcome, BaseException):
1101
- plugin_errors.append({"phase": "execution", "message": str(outcome)})
1102
- results = [
1103
- outcome for outcome in outcomes if not isinstance(outcome, BaseException)
1104
- ]
1105
1152
  report_path = None
1106
1153
  if args.report:
1107
1154
  report_path = write_timestamped_report(
@@ -79,6 +79,19 @@ def _case_status_from_runs(runs: Iterable["RunResult"]) -> ResultStatus:
79
79
  return "pass"
80
80
 
81
81
 
82
+ def _rmtree_missing_ok(path: Path) -> None:
83
+ def onexc(
84
+ function: Callable[..., Any],
85
+ target: str,
86
+ exc: BaseException,
87
+ ) -> None:
88
+ if isinstance(exc, FileNotFoundError):
89
+ return
90
+ raise exc
91
+
92
+ shutil.rmtree(path, onexc=onexc)
93
+
94
+
82
95
  def _tool_result_content(result: Any) -> str:
83
96
  """Render a mock tool result as the `content` of a `role: tool` message.
84
97
 
@@ -1104,12 +1117,10 @@ class YamaRunner:
1104
1117
  execution.repeat shrinks.
1105
1118
  """
1106
1119
  fs_root = case_workspace_root(case.plugin_root, case.case_key)
1107
- if fs_root.exists():
1108
- shutil.rmtree(fs_root)
1120
+ _rmtree_missing_ok(fs_root)
1109
1121
  if self.write_artifacts:
1110
1122
  case_dir = self._case_artifact_root(case)
1111
- if case_dir.exists():
1112
- shutil.rmtree(case_dir)
1123
+ _rmtree_missing_ok(case_dir)
1113
1124
 
1114
1125
  def _case_artifact_root(self, case: ResolvedCase) -> Path:
1115
1126
  root = self.result_root or case.plugin_root / ".yama" / "runs"
@@ -1123,8 +1134,7 @@ class YamaRunner:
1123
1134
  def _write_artifacts(self, case: ResolvedCase, run: RunResult) -> None:
1124
1135
  assert run.artifact_dir is not None
1125
1136
  directory = run.artifact_dir
1126
- if directory.exists():
1127
- shutil.rmtree(directory)
1137
+ _rmtree_missing_ok(directory)
1128
1138
  directory.mkdir(parents=True, exist_ok=True)
1129
1139
  fixture_entries = deepcopy(case.fixture_manifest)
1130
1140
  fixture_dir = directory / "fixtures"
@@ -183,6 +183,7 @@ def collect_case_paths(
183
183
  for pattern in patterns:
184
184
  paths.extend(plugin_root.glob(pattern))
185
185
  paths = sorted(set(path.resolve() for path in paths))
186
+ paths = [path for path in paths if not path.name.startswith("._")]
186
187
  missing = [path for path in paths if not path.is_file()]
187
188
  if missing:
188
189
  raise ConfigurationError(f"case file does not exist: {missing[0]}")
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes