Run need_generate sampling via batch chance in auditor maintain path.

Auditor packets can request generation-rule pools without LLM randomness; results land in 运行.本轮.旁观.生成抽样 and clear each play turn.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-25 00:57:51 +08:00
co-authored by Cursor
parent ac474bcd1a
commit 6d4dfd0d89
3 changed files with 184 additions and 1 deletions
+43
View File
@@ -0,0 +1,43 @@
import { describe, expect, it } from "vitest";
import {
buildChanceBatchFromGenerationRule,
runMaintainNeedGenerateSampling,
} from "../src/skills/maintain-need-generate.js";
const SAMPLE_RULES = JSON.stringify({
schema: "context-fragment.v1",
正文: {
rules: [
{
rule_id: "npc-trait",
池: [
{
pool_id: "mood",
条目: [
{ id: "calm", 权重: 2 },
{ id: "angry", 权重: 1 },
],
},
],
},
],
},
});
describe("maintain need_generate sampling", () => {
it("builds pick requests from generation rule pools", () => {
const batch = buildChanceBatchFromGenerationRule(SAMPLE_RULES, "npc-trait");
expect(batch).toHaveLength(1);
expect(batch![0]!.id).toBe("pool:mood");
expect(batch![0]!.op).toBe("pick");
});
it("runs batch sampling for need_generate", () => {
const result = runMaintainNeedGenerateSampling({
need: { rule_id: "npc-trait", reason: "补一条" },
generationRulesRaw: SAMPLE_RULES,
});
expect(result?.schema).toBe("chance.batch.v1");
expect(result?.results[0]?.id).toBe("pool:mood");
});
});