测试替身对齐宿主的按身份判定:alreadyDispatched 只认正在跑那一条

- hostQueue 记录被放行的 clientTurnId,cancel 只在身份一致时回 alreadyDispatched,其余回 notFound
- 与宿主 remove_pending_turn(按 active_turn.turn_id 比对)保持一致,避免复用该替身时掩盖 notFound 分支
This commit is contained in:
2026-09-30 11:33:42 +08:00
parent 354acfd70b
commit 3e8954548a
@@ -244,11 +244,14 @@ function hostQueue(
) {
const queued: Array<{ clientTurnId: string; userItem: unknown }> = [];
let running = alreadyRunning;
/** 正在跑那一轮的回合身份:与宿主一致,`alreadyDispatched` 只认它(不是"随便哪一轮在跑")。 */
let dispatchedClientTurnId: string | null = null;
const dispatchHeadIfIdle = () => {
if (running) return;
const head = queued.shift();
if (!head) return;
running = true;
dispatchedClientTurnId = head.clientTurnId;
harness.emitDirectThreadEvents(
{
type: 'queue.removed',
@@ -283,7 +286,11 @@ function hostQueue(
const index = queued.findIndex(
(item) => item.clientTurnId === clientTurnId,
);
if (index < 0) return running ? 'alreadyDispatched' : 'notFound';
if (index < 0) {
return dispatchedClientTurnId === clientTurnId
? 'alreadyDispatched'
: 'notFound';
}
queued.splice(index, 1);
harness.emitDirectThreadEvents({
type: 'queue.removed',
@@ -296,6 +303,7 @@ function hostQueue(
/** 回合收尾:宿主在占用释放那一刻踢一脚,队首接上。 */
complete(status = 'completed') {
running = false;
dispatchedClientTurnId = null;
harness.emitDirectThreadEvents({ type: 'turn.completed', status, at: 4 });
dispatchHeadIfIdle();
},