Skip to main content
NiceEval 的评估单位是 Assertion。作者调用 t.check(value, match)turn.succeeded()calledTool(...), 或显式 check(JudgeMaterial, pure ScoreMatch) 时,NiceEval 立即登记一条 Assertion。 不存在先创建中间对象、再由另一条 API 消费它的流程;返回的 handle 只配置这一条 entry。
每条 Assertion 的 keylabel 最多各配置一次。重复配置即使写入同一个值也是作者错误。

Match 只比较值

niceeval/expect 导出纯 Match factory。Match 是可复用、不可变、确定性且无副作用的比较规则;它没有身份、调用位置、阈值、分值或控制流。t.check(value, match) 严格接收两个参数,在调用时读取 value 并登记 Assertion。
matchedmismatched 只说明候选值是否满足当前 Match。它们不能单独证明这条规则刚好覆盖任务允许的全部正确结果。 equals(expected) 比较值的深相等;候选值是字符串时,它要求完全相同的字符串。如果任务接受多种等价表示,先把产物解析或归一化为任务关心的值,再选择能覆盖这些结果的 Match。只有字面表示本身属于任务要求时,才用精确字符串比较。

作用域 Assertion

作用域方法在调用时直接登记 Boolean Assertion。接收者决定证据范围:turn.* 只看该不可变 Turn,session.* 看该 Session 调用点之前的前缀,根 t.* 看调用点时所有已启动 Session 的 vector cut。
calledTool 不接计数 options。toolMatch 自带 occurrence quantifier,例如 .exactly(2)inputoutputstatus 条件也写进 toolMatch;JSON 结构交给 jsonMatch,命令 token 交给 commandMatchnotCalledTool 接收未量化的同类 matcher。

两种评估用例

defineEval 创建通过制评估。Boolean matched 进入 Attempt Verdict;mismatched 使最终 Verdict 为 failed,但不会阻止后续检查继续登记。连续 evaluator 与 Judge factory 给出 [0,1] measurement;先在 ScoreMatch.atLeast(n) 形成 threshold,再对登记后的 handle 调用无参 .gate(),才把它纳入 failed。
defineScoreEval 创建计分制评估。它只有累计 score,没有 Attempt Verdict、总分、百分比或另一种数值单位。Assertion 默认只保存 evaluation,不计分;用 .score(n) 才让已有 Assertion 贡献 score。Boolean matched 贡献 n,mismatched 贡献 0;measurement m 贡献 m * nt.score(n) 直接登记 contribution,返回的 handle 只能配置 keylabel
计分制评估的 measurement 不必 threshold 就能封口。需要 threshold 时,在登记前对 Match 调用 .atLeast(n);它不改变 contribution。没有 .score() 的 Assertion 不显示 +0;正常没有计分项的计分制评估得到正式且可排名的 score: 0

控制流

.orStop() 是同一 Assertion handle 的 async barrier,必须 await。Boolean mismatch,或 thresholded measurement below 时,它设置 authoring stop latch 并拒绝私有控制信号。它只停止当前被 await 的 continuation,不撤销普通 JavaScript 副作用,也不取消此前启动的并发任务;尚未执行的源码不生成结果。
正常 stop 后,通过制评估仍按触发 Assertion 得到 failed Verdict;计分制评估仍是 scored,保留正式 score 和 stop cause,因此可以排名。

Judge

Judge factory 只构造 measurement Match。check({ input, output }, match) 登记 Assertion;通过制评估对已 threshold 的 handle 用无参 .gate(),计分制评估用 .score(n)。两种配置都只运行一次 Judge evaluator。材料、配置和失败语义见 Judge

不可用与读取

缺少 evidence 不能伪装成普通 mismatch。unavailableerrored 保留原因与脱敏 evidence。 AssertionResult 也不是只保存成功或失败。所有入口都遵循同一个 check(a, b) 模型:每条结果保存 subject a 的安全结构化内容或稳定引用、evaluator / Match b 的 identity 与完整安全 config,以及 evaluation、policy 和显示所需的结构化结果。显式 t.check(a, b) 与 Judge 的 check(JudgeMaterial, ScoreMatch) 都由作者提供两者;calledToolsucceeded 等领域包装才是替作者取得 a 并构造 b 的语法糖,保存规则不变。 例如 t.check(await t.sandbox.runCommand(...), commandSucceeded()) 会保留已求值 CommandResult 的命令、参数、退出状态、运行时间以及脱敏 stdout / stderr 内容或引用。calledTool(...) 会保留其 scope 中归一化的 tool occurrence context。context 包括 operation / event identity、脱敏 input、status、output / error refs、coverage 与匹配 event refs。没有命中时也保留观察范围与候选 occurrence refs,而不是只存 false 固定 query operation、view 与 source result 因此可以从同一份结构化 AssertionResult 组织文案和界面,不必重新运行 Match 或调用 Judge。expected / received 是读取面根据 ab 与 evaluation 生成的文案,不是仅存的两个字符串。Assertion 只规定必须保留什么;Record 决定怎样落盘。无法安全保留 evaluator 判定所需的 subject 数据时,结果必须是 unavailable,不能只留下 matchedmismatched

相关阅读