仅在有快照或检查点时允许重出一版。

避免无上下文可复用时误点重跑。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-14 01:14:33 +08:00
co-authored by Cursor
parent 16f66ffd5e
commit a6be5f7f62
2 changed files with 77 additions and 0 deletions
+60
View File
@@ -5,6 +5,8 @@ import {
ensureBranchForEdit,
recordPreMessageCheckpoint,
switchBranchVariant,
canAttemptRefresh,
isRefreshableMessage,
} from "../src/server/message-branch.js";
import { createSession } from "../src/runtime/phase-machine.js";
@@ -62,3 +64,61 @@ describe("message-branch", () => {
expect(branch.variants[0].messages[0].text).toBe("首句");
});
});
describe("canAttemptRefresh", () => {
const output = {
id: "w1",
role: "system" as const,
text: "场面",
createdAt: "1",
kind: "worker_output",
actor: "world-simulator",
};
it("rejects user bubbles", () => {
expect(
isRefreshableMessage({
id: "u1",
role: "user",
text: "行动",
createdAt: "1",
kind: "user_input",
}),
).toBe(false);
expect(
canAttemptRefresh(
{
id: "u1",
role: "user",
text: "行动",
createdAt: "1",
kind: "user_input",
},
{
lastWorkerId: "world-simulator",
hasLastWorkerSnapshot: true,
hasMessageCheckpoint: true,
},
),
).toBe(false);
});
it("allows worker output when a snapshot exists", () => {
expect(
canAttemptRefresh(output, {
lastWorkerId: "world-simulator",
hasLastWorkerSnapshot: true,
hasMessageCheckpoint: false,
}),
).toBe(true);
});
it("rejects worker output with no snapshot and no checkpoint", () => {
expect(
canAttemptRefresh(output, {
hasLastWorkerSnapshot: false,
hasMessageCheckpoint: false,
}),
).toBe(false);
});
});