跳转到主要内容
Fixture 是评估 coding agent 的推荐方式。它把”给 agent 的任务”和”验证结果的测试”放在同一个目录里,但 agent 无法看到验证文件。

目录结构

evals/fixtures/button/
├─ PROMPT.md
├─ EVAL.ts
├─ package.json
├─ tsconfig.json
└─ src/
文件作用
PROMPT.md发给 agent 的任务
EVAL.ts验证测试,agent 完成后才出现
package.jsonfixture 的依赖和脚本
src/初始 workspace

PROMPT.md

Create `src/components/Button.tsx`.

The component must accept:
- `label: string`
- `onClick: () => void`
Prompt 应描述目标行为,不要把测试答案写进去。

EVAL.ts

import { test, expect } from "vitest";
import { existsSync, readFileSync } from "node:fs";

test("Button component exists", () => {
  expect(existsSync("src/components/Button.tsx")).toBe(true);
});

test("accepts label and onClick", () => {
  const src = readFileSync("src/components/Button.tsx", "utf-8");
  expect(src).toContain("label");
  expect(src).toContain("onClick");
});

运行 fixture

npx niceeval exp local fixtures/button --sandbox docker
实验名之后的位置参数是 eval ID 前缀,不是 agent 名。

验证 agent 行为

niceeval 会把 o11y 摘要注入 __niceeval__/results.jsonEVAL.ts 可以检查 agent 是否调用了预期命令:
import { test, expect } from "vitest";
import { readFileSync } from "node:fs";

test("used project test script", () => {
  const result = JSON.parse(readFileSync("__niceeval__/results.json", "utf-8"));
  const commands = result.o11y.shellCommands.map((c: { command: string }) => c.command);
  expect(commands.some((cmd) => cmd.includes("npm test"))).toBe(true);
});

何时用 fixture

  • 需要 agent 修改真实文件。
  • 需要运行项目测试、构建或 lint。
  • 需要比较生成 diff。
  • 任务适合批量收集 pass rate。
如果只是调用 HTTP 或进程内函数,用普通 defineEval 更轻。