引入游玩回合与开场收口,抽出可替换 agent 司机并支持运行中止;完善预设洞位、世界书拼装与试跑,并打磨会话运行时与 Web 交互。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import {
|
||||
MockLlmProvider,
|
||||
} from "../src/llm/client.js";
|
||||
import { PhaseRuntime, createDecision } from "../src/runtime/phase-runtime.js";
|
||||
import { createSession } from "../src/runtime/phase-machine.js";
|
||||
import { Blackboard } from "../src/blackboard/blackboard.js";
|
||||
|
||||
describe("phase runtime", () => {
|
||||
it("auto-loads default orchestrator and awaits first user input", async () => {
|
||||
@@ -47,4 +49,82 @@ describe("phase runtime", () => {
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("play turn runs declared pipeline without review and waits for input", async () => {
|
||||
const session = createSession("default");
|
||||
session.phase = "waiting_user";
|
||||
session.waitingReason = { kind: "input" };
|
||||
session.slots = {
|
||||
designInstanceReady: true,
|
||||
uiLifecycleStage: "play",
|
||||
playLayerActive: true,
|
||||
startupCompleted: true,
|
||||
};
|
||||
const blackboard = new Blackboard();
|
||||
blackboard.write({
|
||||
tag: "设计.worker集",
|
||||
content: JSON.stringify({
|
||||
version: 1,
|
||||
play_slots: {
|
||||
auditor: false,
|
||||
gm: true,
|
||||
narrator: true,
|
||||
perspective: false,
|
||||
},
|
||||
workers: [
|
||||
{ ref: "world-simulator", acceptance: "continue" },
|
||||
{ ref: "narrator", acceptance: "review" },
|
||||
],
|
||||
}),
|
||||
source: "test",
|
||||
});
|
||||
const runtime = new PhaseRuntime({
|
||||
autoStubWorker: true,
|
||||
initialSession: session,
|
||||
initialBlackboardItems: blackboard.exportItems(),
|
||||
});
|
||||
await runtime.submitInput("我网购一个金首饰试试");
|
||||
expect(runtime.getSession().waitingReason?.kind).toBe("input");
|
||||
expect(runtime.getSession().artifacts.map((a) => a.workerId)).toEqual([
|
||||
"world-simulator",
|
||||
"narrator",
|
||||
]);
|
||||
expect(runtime.getSession().artifacts.every((a) => a.status === "accepted")).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("retryStuckRun restores the in-flight worker snapshot and reruns", async () => {
|
||||
const runtime = new PhaseRuntime({ autoStubWorker: true });
|
||||
await runtime.start();
|
||||
await runtime.submitInput("网恋对象对话");
|
||||
await runtime.submitDecision(
|
||||
createDecision({
|
||||
action: "run_worker",
|
||||
reason: "编排创作流程",
|
||||
workerId: "design-flow",
|
||||
requiresApproval: false,
|
||||
}),
|
||||
);
|
||||
const snap = runtime.getLastWorkerRunSnapshot();
|
||||
expect(snap?.workerId).toBe("design-flow");
|
||||
const artifactsBefore = runtime.getSession().artifacts.length;
|
||||
|
||||
const session = runtime.getSession();
|
||||
session.phase = "running";
|
||||
session.waitingReason = undefined;
|
||||
session.currentWorkerId = "design-flow";
|
||||
|
||||
await runtime.retryStuckRun();
|
||||
expect(runtime.getSession().artifacts.length).toBeGreaterThan(artifactsBefore);
|
||||
expect(
|
||||
runtime.getSession().artifacts.filter((a) => a.workerId === "design-flow").length,
|
||||
).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
it("retryStuckRun throws when nothing is running", async () => {
|
||||
const runtime = new PhaseRuntime({ autoStubWorker: true });
|
||||
await runtime.start();
|
||||
await expect(runtime.retryStuckRun()).rejects.toThrow("当前没有可重试的执行");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user