Files
InfoRSI/tests/ledger-pending.test.ts
iomgaa 0ac1e01613 feat: 任务书 08,jev 模块与账本记 Jev 判断
src/jev 3 个文件 515 行:判重、查冻结条款、查代码改动三个函数,九问问法和阈值照参考项目,只改说法和字段名,阈值注明未在新项目材料上校准,等真实数据。
新增 npm run test:jev(真实 Jev 三处各问一次)。vocab 加 JevJudgment。
ledger 表结构版本 3:callEnded 四种结局对上 agents,墙钟时间用 Measured(恢复时补写出错、原因"进程中断"、测不到);退回、提交记录都带 jev。
config 加必填的 models.jev。

用户原话:"这次就给提交记录加一个和退回记录同样的 Jev 判断字段";"墙钟时间改用 Measured,恢复时写出错加测不到(原因'进程中断')"。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 02:11:20 -04:00

82 lines
3.8 KiB
TypeScript

import assert from "node:assert/strict";
import { join } from "node:path";
import { test } from "node:test";
import { Ledger } from "../src/ledger/index.ts";
import { callStart, exited, freshLedger, notStarted, planRun, tempDir, usage } from "./ledger-helpers.ts";
// 未完成的动作(方法.md 第九部分"中断与恢复时的记账含义":先登记、再执行、再登记结果):
// 登记了但没有结果的运行、开始了但没有结束的模型调用能被找出来;写了结果之后就不再出现。
test("运行:登记了没结果的被找出来,带着有没有确认启动;写了结果就不再出现", (t) => {
const { ledger } = freshLedger(t);
planRun(ledger, "base", "baseline", 0);
planRun(ledger, "run1", "forward", 1);
planRun(ledger, "run2", "forward", 1);
ledger.append("runStarted", { run: "base" });
ledger.append("runStarted", { run: "run1" });
ledger.append("runResult", { run: "base", process: exited, judged: null });
assert.deepEqual(
ledger.pending().runs.map((r) => [r.plan.content.run, r.started]),
[
["run1", true],
["run2", false],
],
);
ledger.append("runResult", { run: "run2", process: notStarted, judged: null });
assert.deepEqual(ledger.pending().runs.map((r) => r.plan.content.run), ["run1"]);
ledger.append("runResult", { run: "run1", process: exited, judged: null });
assert.deepEqual(ledger.pending().runs, []);
});
test("模型调用:开始了没结束的被找出来,带着这次任务的全部材料;有用量也还算没结束;结束后不再出现", (t) => {
const { ledger } = freshLedger(t);
ledger.append("callStarted", callStart("k1", "r1", "s1"));
ledger.append("callStarted", callStart("k2", "e1"));
ledger.append("callUsage", { call: "k1", reply: 1, usage });
ledger.append("callEnded", { call: "k2", wallSeconds: { status: "measured", value: 30 }, status: "failed", reason: "接口超时" });
const calls = ledger.pending().calls;
assert.deepEqual(calls.map((c) => c.content.call), ["k1"]);
assert.deepEqual(calls[0]!.content.materials, callStart("k1").materials);
ledger.append("callEnded", { call: "k1", wallSeconds: { status: "measured", value: 600 }, status: "notSubmitted", reason: "模型自己停下了" });
assert.deepEqual(ledger.pending(), { runs: [], calls: [] });
});
test("中断后恢复:给没结束的旧调用补写出错加测不到(进程中断),补写后不再算未完成", (t) => {
const path = join(tempDir(t), "ledger.db");
const ledger = Ledger.open(path);
ledger.append("callStarted", callStart("k1", "r1", "s1"));
ledger.append("callUsage", { call: "k1", reply: 1, usage });
ledger.close(); // 控制进程被系统杀掉
const reopened = Ledger.open(path);
t.after(() => reopened.close());
assert.deepEqual(reopened.pending().calls.map((c) => c.content.call), ["k1"]);
reopened.append("callEnded", {
call: "k1",
wallSeconds: { status: "unmeasured", reason: "进程中断" },
status: "failed",
reason: "进程中断",
});
assert.deepEqual(reopened.pending(), { runs: [], calls: [] });
assert.deepEqual(reopened.records().at(-1)!.content, {
call: "k1",
wallSeconds: { status: "unmeasured", reason: "进程中断" },
status: "failed",
reason: "进程中断",
});
});
test("关掉再打开:未完成的动作照样找得出来", (t) => {
const path = join(tempDir(t), "ledger.db");
const ledger = Ledger.open(path);
planRun(ledger, "run1", "forward", 1);
ledger.append("runStarted", { run: "run1" });
ledger.append("callStarted", callStart("k1"));
const before = ledger.pending();
ledger.close();
const reopened = Ledger.open(path);
t.after(() => reopened.close());
assert.deepEqual(reopened.pending(), before);
assert.equal(before.runs.length, 1);
assert.equal(before.calls.length, 1);
});