Initial commit
This commit is contained in:
151
tests/agent-view.test.ts
Normal file
151
tests/agent-view.test.ts
Normal file
@@ -0,0 +1,151 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
|
||||
classifyAgentMessage,
|
||||
|
||||
buildFocus,
|
||||
|
||||
buildSkillCatalog,
|
||||
|
||||
buildToolTrace,
|
||||
|
||||
inferLifecycleStage,
|
||||
|
||||
canEnterPlay,
|
||||
|
||||
} from "../src/server/agent-view.js";
|
||||
|
||||
import { createSession } from "../src/runtime/phase-machine.js";
|
||||
|
||||
|
||||
|
||||
describe("classifyAgentMessage", () => {
|
||||
|
||||
it("parses orchestrator decisions", () => {
|
||||
|
||||
const m = classifyAgentMessage("[总管] run_worker: 生成规则");
|
||||
|
||||
expect(m.kind).toBe("orchestrator_decision");
|
||||
|
||||
expect(m.body).toBe("生成规则");
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("parses agent tool calls", () => {
|
||||
|
||||
const m = classifyAgentMessage("[总管 tool] invoke_worker: write-rules");
|
||||
|
||||
expect(m.kind).toBe("agent_tool");
|
||||
|
||||
expect(m.title).toContain("invoke_worker");
|
||||
|
||||
expect(m.body).toBe("write-rules");
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("parses worker output", () => {
|
||||
|
||||
const m = classifyAgentMessage("[Worker] write-rules 已完成\n\n### rules\n\n1. foo");
|
||||
|
||||
expect(m.kind).toBe("worker_output");
|
||||
|
||||
expect(m.actor).toBe("write-rules");
|
||||
|
||||
expect(m.body).toContain("1. foo");
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("parses worker questions", () => {
|
||||
|
||||
const m = classifyAgentMessage(
|
||||
|
||||
"[Worker] setup-scenario 提问:\n- 请提供玩家人数",
|
||||
|
||||
);
|
||||
|
||||
expect(m.kind).toBe("worker_questions");
|
||||
|
||||
expect(m.actor).toBe("setup-scenario");
|
||||
|
||||
expect(m.body).toContain("请提供玩家人数");
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("falls back when worker question body is empty", () => {
|
||||
|
||||
const m = classifyAgentMessage("Worker 提问:\n");
|
||||
|
||||
expect(m.kind).toBe("worker_questions");
|
||||
|
||||
expect(m.body).toContain("请补充当前步骤");
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe("lifecycle", () => {
|
||||
|
||||
it("infers design before startup completed", () => {
|
||||
|
||||
const session = createSession();
|
||||
|
||||
expect(inferLifecycleStage(session)).toBe("design");
|
||||
|
||||
expect(canEnterPlay(session)).toBe(false);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("infers play after startup completed", () => {
|
||||
|
||||
const session = {
|
||||
|
||||
...createSession(),
|
||||
|
||||
slots: { ...createSession().slots, startupCompleted: true },
|
||||
|
||||
};
|
||||
|
||||
expect(inferLifecycleStage(session)).toBe("play");
|
||||
|
||||
expect(canEnterPlay(session)).toBe(true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
it("respects uiLifecycleStage override", () => {
|
||||
|
||||
const session = {
|
||||
|
||||
...createSession(),
|
||||
|
||||
slots: { ...createSession().slots, uiLifecycleStage: "play" },
|
||||
|
||||
};
|
||||
|
||||
expect(inferLifecycleStage(session)).toBe("play");
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe("buildSkillCatalog", () => {
|
||||
|
||||
it("lists design skills for world-simulator", () => {
|
||||
|
||||
const session = createSession();
|
||||
Reference in New Issue
Block a user