@myclaw163/clawclaw-cli 0.8.3 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/docs/configuration.md +44 -26
- package/docs/custom-modules/README.md +7 -10
- package/docs/custom-modules/api-reference.md +3 -7
- package/docs/custom-modules/behavior.md +6 -4
- package/docs/custom-modules/perception.md +1 -1
- package/docs/custom-modules/trigger.md +1 -1
- package/docs/runtime/README.md +4 -4
- package/docs/runtime/official-perception-modules.md +2 -2
- package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
- package/package.json +9 -2
- package/scripts/build-official-hub-behaviors.mjs +136 -0
- package/scripts/build-official-hub-behaviors.test.mjs +178 -0
- package/scripts/enable_ccl_permissions.cjs +4 -2
- package/scripts/enable_ccl_permissions.test.mjs +8 -4
- package/scripts/postinstall.mjs +1 -4
- package/scripts/sync-bundled-skill.mjs +12 -159
- package/scripts/sync-bundled-skill.test.mjs +9 -74
- package/skills/clawclaw/SKILL.md +18 -13
- package/skills/clawclaw/references/BEHAVIORS.md +4 -4
- package/skills/clawclaw/references/COMMANDS.md +33 -18
- package/skills/clawclaw/references/GAME-MECHANICS.md +16 -18
- package/skills/clawclaw/references/HUB.md +25 -38
- package/skills/clawclaw/references/STREAM.md +9 -11
- package/src/behaviors/official-finite/do-task.ts +70 -0
- package/src/behaviors/official-finite/index.ts +0 -3
- package/src/commands/account.ts +58 -14
- package/src/commands/behavior.ts +116 -38
- package/src/commands/hub.ts +110 -153
- package/src/commands/load.ts +138 -33
- package/src/commands/perception.ts +55 -24
- package/src/commands/persona.ts +66 -20
- package/src/commands/skill.ts +12 -48
- package/src/commands/trigger.ts +68 -40
- package/src/hub-official-behaviors/kill-lone.ts +138 -0
- package/src/hub-official-behaviors/patrol.ts +30 -0
- package/src/hub-official-behaviors/shared.ts +125 -0
- package/src/hub-official-behaviors/task-only.ts +158 -0
- package/src/lib/account-guidance.ts +54 -9
- package/src/lib/agent-workspace-client.ts +135 -0
- package/src/lib/agent-workspace-runtime.ts +154 -0
- package/src/lib/agent-workspace-skills.ts +177 -0
- package/src/lib/agent-workspace-sync.ts +852 -0
- package/src/lib/gameplay-config.ts +29 -15
- package/src/lib/hub-client.ts +252 -34
- package/src/lib/hub-reminder.ts +22 -7
- package/src/lib/init-command.ts +0 -6
- package/src/lib/load-context.ts +12 -6
- package/src/lib/persona.ts +141 -69
- package/src/lib/server-status.ts +78 -0
- package/src/lib/skill-host.ts +160 -0
- package/src/lib/user-data.ts +197 -4
- package/src/pipeline/event-format.ts +20 -4
- package/src/pipeline/event-hints.ts +20 -6
- package/src/pipeline/game-sync-event-normalization.ts +9 -0
- package/src/pipeline/role-display.ts +22 -0
- package/src/runtime/clawclaw/agent-ability-state.ts +1 -21
- package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
- package/src/runtime/clawclaw/owner.ts +63 -19
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +8 -1
- package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +0 -1
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +8 -2
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +2 -2
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -9
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +4 -1
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -5
- package/src/runtime/clawclaw/plugins/perception/replay.ts +0 -2
- package/src/runtime/clawclaw-event-catalog.ts +2 -0
- package/src/runtime/framework/action-diagnostics.ts +1 -0
- package/src/runtime/framework/modules/runtime-module-loader.ts +0 -1
- package/src/sdk/action.ts +8 -6
- package/src/sdk/behavior-plugin/index.ts +1 -2
- package/src/sdk/behavior-toolkit/model.ts +2 -0
- package/src/sdk/module-input/index.ts +0 -2
- package/src/strategies/goals/crab-sabotage-top.ts +5 -61
- package/src/strategies/types.ts +0 -6
- package/personas//345/217/243/346/230/257/345/277/203/351/235/236.md +0 -50
- package/personas//345/277/240/345/277/203/350/200/201/344/273/206.md +0 -51
- package/personas//346/227/240/344/272/272/350/256/276.md +0 -1
- package/personas//350/264/253/345/230/264/346/215/237/345/217/213.md +0 -48
- package/personas//350/275/257/350/220/214/350/205/271/351/273/221.md +0 -51
- package/src/behaviors/official-finite/index.test.ts +0 -202
- package/src/behaviors/official-finite/trigger-alarm.ts +0 -53
- package/src/channel/claude-channel-server.test.ts +0 -202
- package/src/commands/account.test.ts +0 -570
- package/src/commands/behavior.test.ts +0 -158
- package/src/commands/communication.test.ts +0 -282
- package/src/commands/competition.test.ts +0 -116
- package/src/commands/data.test.ts +0 -89
- package/src/commands/events-canonical-state.test.ts +0 -406
- package/src/commands/events.test.ts +0 -58
- package/src/commands/game/index.test.ts +0 -1251
- package/src/commands/game-map.test.ts +0 -69
- package/src/commands/hub.test.ts +0 -124
- package/src/commands/load.test.ts +0 -440
- package/src/commands/perception.test.ts +0 -75
- package/src/commands/setup/hermes.test.ts +0 -96
- package/src/commands/setup/openclaw.test.ts +0 -124
- package/src/commands/trigger.test.ts +0 -140
- package/src/commands/upgrade.test.ts +0 -82
- package/src/lib/account-guidance.test.ts +0 -36
- package/src/lib/auth.test.ts +0 -151
- package/src/lib/behavior-export.test.ts +0 -282
- package/src/lib/behavior-export.ts +0 -514
- package/src/lib/clawclaw-skill-spectate-guidance.test.ts +0 -21
- package/src/lib/custom-tts.test.ts +0 -387
- package/src/lib/diagnostics-config.test.ts +0 -59
- package/src/lib/game-client-tts.test.ts +0 -151
- package/src/lib/game-client.test.ts +0 -250
- package/src/lib/gameplay-config.test.ts +0 -301
- package/src/lib/host-config-patcher.test.ts +0 -130
- package/src/lib/http-transport.test.ts +0 -124
- package/src/lib/hub-client.test.ts +0 -57
- package/src/lib/hub-install.test.ts +0 -135
- package/src/lib/hub-install.ts +0 -185
- package/src/lib/hub-unzip.test.ts +0 -69
- package/src/lib/init-command.test.ts +0 -103
- package/src/lib/load-context.test.ts +0 -62
- package/src/lib/match-state.test.ts +0 -134
- package/src/lib/official-resource-sync.test.ts +0 -199
- package/src/lib/official-resource-sync.ts +0 -221
- package/src/lib/perception-config.test.ts +0 -143
- package/src/lib/perception-export.test.ts +0 -145
- package/src/lib/perception-export.ts +0 -178
- package/src/lib/persona.test.ts +0 -84
- package/src/lib/room.test.ts +0 -88
- package/src/lib/server-registry.test.ts +0 -64
- package/src/lib/service-status.test.ts +0 -81
- package/src/lib/skill-version.test.ts +0 -48
- package/src/lib/trigger-config.test.ts +0 -102
- package/src/lib/trigger-export.test.ts +0 -80
- package/src/lib/trigger-export.ts +0 -210
- package/src/lib/user-data.test.ts +0 -121
- package/src/lib/workspace-argv.test.ts +0 -49
- package/src/pipeline/canonical-event-presentation.test.ts +0 -255
- package/src/pipeline/event-format.test.ts +0 -828
- package/src/pipeline/event-hints.test.ts +0 -316
- package/src/pipeline/game-sync-event-normalization.test.ts +0 -371
- package/src/pipeline/player-projection.test.ts +0 -247
- package/src/runtime/auto-upgrade.test.ts +0 -66
- package/src/runtime/canonical-event-emitter.test.ts +0 -70
- package/src/runtime/canonical-monitor.test.ts +0 -577
- package/src/runtime/clawclaw/agent-event-policy.test.ts +0 -58
- package/src/runtime/clawclaw/behavior-decision.test.ts +0 -43
- package/src/runtime/clawclaw/behavior-input-fields.test.ts +0 -175
- package/src/runtime/clawclaw/behavior-input.test.ts +0 -173
- package/src/runtime/clawclaw/behavior-observation-memory.test.ts +0 -59
- package/src/runtime/clawclaw/behavior-read-api.test.ts +0 -123
- package/src/runtime/clawclaw/notifications.test.ts +0 -47
- package/src/runtime/clawclaw/owner-lock.test.ts +0 -221
- package/src/runtime/clawclaw/owner.test.ts +0 -203
- package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +0 -304
- package/src/runtime/clawclaw/plugins/assembly.test.ts +0 -200
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +0 -180
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +0 -40
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +0 -156
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +0 -182
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +0 -1094
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +0 -174
- package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +0 -195
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +0 -283
- package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +0 -80
- package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +0 -267
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +0 -226
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +0 -239
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +0 -407
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +0 -397
- package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +0 -270
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +0 -166
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +0 -194
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +0 -87
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +0 -2012
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +0 -214
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +0 -347
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +0 -92
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +0 -248
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +0 -389
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +0 -8
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +0 -342
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +0 -475
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +0 -30
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +0 -304
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +0 -179
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +0 -364
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +0 -81
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +0 -200
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +0 -216
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +0 -284
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +0 -120
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +0 -105
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +0 -269
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +0 -865
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +0 -1878
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +0 -278
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +0 -77
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -854
- package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +0 -287
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +0 -321
- package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +0 -307
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +0 -2646
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +0 -212
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +0 -548
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +0 -169
- package/src/runtime/clawclaw/runtime-data-export.test.ts +0 -249
- package/src/runtime/clawclaw-event-catalog.test.ts +0 -126
- package/src/runtime/framework/action-diagnostics.test.ts +0 -81
- package/src/runtime/framework/capability-registry.test.ts +0 -423
- package/src/runtime/framework/control-coordinator.test.ts +0 -675
- package/src/runtime/framework/events/event-delivery-service.test.ts +0 -84
- package/src/runtime/framework/events/event-ingress.test.ts +0 -203
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +0 -710
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +0 -802
- package/src/runtime/framework/mailbox/coalescer.test.ts +0 -55
- package/src/runtime/framework/mailbox/identity.test.ts +0 -38
- package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +0 -513
- package/src/runtime/framework/mailbox/notification-projector.test.ts +0 -77
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +0 -435
- package/src/runtime/framework/participation-manager.test.ts +0 -108
- package/src/runtime/framework/plugins/runtime-input-journal.test.ts +0 -179
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +0 -2040
- package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +0 -144
- package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +0 -157
- package/src/runtime/framework/state/history/state-history.test.ts +0 -251
- package/src/runtime/framework/state/state-core.test.ts +0 -197
- package/src/runtime/game-sync-protocol.test.ts +0 -123
- package/src/runtime/host-monitor-rate-gate.test.ts +0 -73
- package/src/runtime/mailbox-host-relay.test.ts +0 -293
- package/src/runtime/observability/observability.test.ts +0 -583
- package/src/runtime/owner-control.test.ts +0 -153
- package/src/runtime/parent-process-watch.test.ts +0 -27
- package/src/runtime/pending-event-handoff.test.ts +0 -29
- package/src/runtime/raw-ws-log.test.ts +0 -102
- package/src/runtime/runtime-logger.test.ts +0 -58
- package/src/runtime/runtime-persistence.test.ts +0 -26
- package/src/runtime/runtime.test.ts +0 -1770
- package/src/runtime/ws-client.test.ts +0 -562
- package/src/sdk/behavior-plugin/index.test.ts +0 -74
- package/src/sdk/index.test.ts +0 -45
- package/src/sdk/module-input/index.test.ts +0 -49
- package/src/sdk/perception-plugin/index.test.ts +0 -22
- package/src/sdk/resource-metadata.test.ts +0 -40
- package/src/sdk/trigger-plugin/index.test.ts +0 -41
- package/src/short-command/classifier.test.ts +0 -107
- package/src/short-command/presenter.test.ts +0 -119
- package/src/short-command/runner.test.ts +0 -78
- package/src/short-command/sensitive-data-filter.test.ts +0 -56
- package/src/short-command/transport-response.test.ts +0 -39
- package/src/strategies/custom-module.test.ts +0 -268
- package/src/strategies/game-utils.test.ts +0 -306
- package/src/strategies/goals/avoid-players-top.test.ts +0 -96
- package/src/strategies/goals/crab-sabotage-top.test.ts +0 -145
- package/src/strategies/goals/kill-lone-top.test.ts +0 -97
- package/src/strategies/goals/kill-target-top.test.ts +0 -66
- package/src/strategies/goals/lone-kill-task-top.test.ts +0 -85
- package/src/strategies/goals/normal-shrimp-top.test.ts +0 -113
- package/src/strategies/goals/paradise-fish-top.test.ts +0 -204
- package/src/strategies/goals/task-only-top.test.ts +0 -89
- package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -139
- package/src/strategies/meeting-gate.test.ts +0 -59
- package/src/strategies/official-long-behavior.test.ts +0 -89
- package/src/strategies/pathfind/astar-path.test.ts +0 -198
- package/src/strategies/pathfind/escape-planner.test.ts +0 -223
- package/src/strategies/player-targets.test.ts +0 -10
- package/src/strategies/task-only.test.ts +0 -138
|
@@ -1,2012 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { createClawclawEventCatalog } from '../../../clawclaw-event-catalog.js';
|
|
3
|
-
import {
|
|
4
|
-
EventIngress,
|
|
5
|
-
MemoryEventRepository,
|
|
6
|
-
type CanonicalEvent,
|
|
7
|
-
} from '../../../framework/events/index.js';
|
|
8
|
-
import type { RuntimeDiagnosticSeverity } from '../../../framework/plugins/contracts.js';
|
|
9
|
-
import type { RuntimeReadyView } from '../../../framework/runtime.js';
|
|
10
|
-
import { MailboxRelayBroker } from '../../../mailbox-host-relay.js';
|
|
11
|
-
import { ClawclawMailboxService } from './mailbox-service.js';
|
|
12
|
-
|
|
13
|
-
const INTERNAL_EVENTS_FIELDS = ['mode', 'scope', 'state_status', 'backlog', 'delivery', 'counts'] as const;
|
|
14
|
-
|
|
15
|
-
function expectCompactEventsOutput(output: Record<string, unknown>): void {
|
|
16
|
-
for (const field of INTERNAL_EVENTS_FIELDS) expect(output).not.toHaveProperty(field);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function fixture(options: {
|
|
20
|
-
consumerId?: string;
|
|
21
|
-
monitorEnabled?: boolean;
|
|
22
|
-
monitorPendingItemLimit?: number;
|
|
23
|
-
monitorOrdinaryWindowItemBudget?: number;
|
|
24
|
-
monitorBacklogHintWindowItemBudget?: number;
|
|
25
|
-
monitorAdmissionWindowMs?: number;
|
|
26
|
-
monitorVisualMinIntervalMs?: number;
|
|
27
|
-
diagnostic?: (
|
|
28
|
-
name: string,
|
|
29
|
-
attributes?: Record<string, unknown>,
|
|
30
|
-
severity?: RuntimeDiagnosticSeverity,
|
|
31
|
-
) => void;
|
|
32
|
-
} = {}) {
|
|
33
|
-
const repository = new MemoryEventRepository();
|
|
34
|
-
repository.saveSession({
|
|
35
|
-
sessionId: 'session-1',
|
|
36
|
-
adapterId: 'clawclaw',
|
|
37
|
-
accountId: 'account-1',
|
|
38
|
-
status: 'open',
|
|
39
|
-
isCurrent: true,
|
|
40
|
-
openedAt: '2026-07-22T00:00:00.000Z',
|
|
41
|
-
});
|
|
42
|
-
repository.saveSegment({
|
|
43
|
-
segmentId: 'room-1',
|
|
44
|
-
sessionId: 'session-1',
|
|
45
|
-
sequence: 1,
|
|
46
|
-
kind: 'room',
|
|
47
|
-
status: 'open',
|
|
48
|
-
isCurrent: true,
|
|
49
|
-
openedAt: '2026-07-22T00:00:00.000Z',
|
|
50
|
-
});
|
|
51
|
-
const ingress = new EventIngress(repository, createClawclawEventCatalog());
|
|
52
|
-
let nowMs = Date.parse('2026-07-22T00:00:00.000Z');
|
|
53
|
-
let ready = readyView('room-1', 1, 0, { phase: 'room_waiting' });
|
|
54
|
-
const service = new ClawclawMailboxService({
|
|
55
|
-
repository,
|
|
56
|
-
readyView: () => structuredClone(ready),
|
|
57
|
-
now: () => nowMs,
|
|
58
|
-
...options,
|
|
59
|
-
});
|
|
60
|
-
return {
|
|
61
|
-
repository,
|
|
62
|
-
ingress,
|
|
63
|
-
service,
|
|
64
|
-
setReady: (next: RuntimeReadyView) => { ready = next; },
|
|
65
|
-
setNow: (next: number) => { nowMs = next; },
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function readyView(
|
|
70
|
-
segmentId: string,
|
|
71
|
-
epochSeq: number,
|
|
72
|
-
eventWatermark: number,
|
|
73
|
-
state: Record<string, any>,
|
|
74
|
-
pluginStates: RuntimeReadyView['pluginStates'] = {},
|
|
75
|
-
pluginOutcomes: RuntimeReadyView['pluginOutcomes'] = {},
|
|
76
|
-
): RuntimeReadyView {
|
|
77
|
-
const runtimeScope = {
|
|
78
|
-
adapterId: 'clawclaw',
|
|
79
|
-
accountId: 'account-1',
|
|
80
|
-
sessionId: 'session-1',
|
|
81
|
-
segmentId,
|
|
82
|
-
segmentSeq: segmentId === 'room-1' ? 1 : 2,
|
|
83
|
-
};
|
|
84
|
-
return {
|
|
85
|
-
scope: {
|
|
86
|
-
adapterId: runtimeScope.adapterId,
|
|
87
|
-
sessionId: runtimeScope.sessionId,
|
|
88
|
-
segmentId: runtimeScope.segmentId,
|
|
89
|
-
segmentSeq: runtimeScope.segmentSeq,
|
|
90
|
-
},
|
|
91
|
-
state: {
|
|
92
|
-
state,
|
|
93
|
-
stateStatus: {
|
|
94
|
-
status: 'fresh',
|
|
95
|
-
semantics: 'latest_received',
|
|
96
|
-
source: 'owner_memory',
|
|
97
|
-
scope: runtimeScope,
|
|
98
|
-
connectionId: 'connection-1',
|
|
99
|
-
connectionState: 'connected',
|
|
100
|
-
receivedAtMs: Date.parse('2026-07-22T00:00:00.000Z'),
|
|
101
|
-
ageMs: 0,
|
|
102
|
-
backendTick: Number(state.tick ?? 0),
|
|
103
|
-
reason: null,
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
pluginStates,
|
|
107
|
-
pluginOutcomes,
|
|
108
|
-
events: [],
|
|
109
|
-
throughCommitSeq: eventWatermark,
|
|
110
|
-
frameSeq: epochSeq,
|
|
111
|
-
eventWatermark,
|
|
112
|
-
epochSeq,
|
|
113
|
-
hasMore: false,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async function publish(
|
|
118
|
-
ingress: EventIngress,
|
|
119
|
-
input: {
|
|
120
|
-
eventId: string;
|
|
121
|
-
type: string;
|
|
122
|
-
segmentId: string;
|
|
123
|
-
epochSeq: number;
|
|
124
|
-
payload?: Record<string, unknown>;
|
|
125
|
-
producer?: 'backend_push' | 'local_synth';
|
|
126
|
-
producerPluginId?: string;
|
|
127
|
-
},
|
|
128
|
-
): Promise<CanonicalEvent> {
|
|
129
|
-
return (await ingress.publish({
|
|
130
|
-
epochSeq: input.epochSeq,
|
|
131
|
-
eventId: input.eventId,
|
|
132
|
-
type: input.type,
|
|
133
|
-
producer: input.producer ?? 'backend_push',
|
|
134
|
-
producerPluginId: input.producerPluginId,
|
|
135
|
-
sessionId: 'session-1',
|
|
136
|
-
segmentId: input.segmentId,
|
|
137
|
-
payload: input.payload,
|
|
138
|
-
source: { sourceId: 'game-ws', eventId: `remote:${input.eventId}` },
|
|
139
|
-
})).event;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
describe('ClawClaw Mailbox Event query', () => {
|
|
143
|
-
it('returns only the CCL-owned optional Event hint while delivery stays internal', async () => {
|
|
144
|
-
const { ingress, service, setReady } = fixture();
|
|
145
|
-
const event = await publish(ingress, {
|
|
146
|
-
eventId: 'role-hint',
|
|
147
|
-
type: 'role_assigned',
|
|
148
|
-
segmentId: 'room-1',
|
|
149
|
-
epochSeq: 1,
|
|
150
|
-
payload: {
|
|
151
|
-
role: 'shrimp_generic',
|
|
152
|
-
faction: 'lobster',
|
|
153
|
-
hint: 'backend hint',
|
|
154
|
-
next_step: 'backend next step',
|
|
155
|
-
notice: 'backend notice',
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'loading', tick: 0 }));
|
|
159
|
-
|
|
160
|
-
const result = service.prepareEvents({ eventType: 'role_assigned' }).output;
|
|
161
|
-
const presented = result.event as Record<string, unknown>;
|
|
162
|
-
|
|
163
|
-
expect(result).toMatchObject({
|
|
164
|
-
schema: 'ccl.events.v5',
|
|
165
|
-
found: true,
|
|
166
|
-
});
|
|
167
|
-
expectCompactEventsOutput(result);
|
|
168
|
-
expect(presented.hint).toContain('You are shrimp_generic');
|
|
169
|
-
expect(JSON.stringify(result)).not.toContain('backend hint');
|
|
170
|
-
expect(result).not.toHaveProperty('guidance');
|
|
171
|
-
expect(result).not.toHaveProperty('next_step');
|
|
172
|
-
expect(presented).not.toHaveProperty('notice');
|
|
173
|
-
expect(presented).not.toHaveProperty('next_step');
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('omits hint for room.full and adds it only to the authorized Derived readiness Event', async () => {
|
|
177
|
-
const { ingress, service, setReady } = fixture();
|
|
178
|
-
await publish(ingress, {
|
|
179
|
-
eventId: 'room-full',
|
|
180
|
-
type: 'room.full',
|
|
181
|
-
segmentId: 'room-1',
|
|
182
|
-
epochSeq: 1,
|
|
183
|
-
payload: { room_code: '123456', member_count: 10 },
|
|
184
|
-
});
|
|
185
|
-
const ready = await publish(ingress, {
|
|
186
|
-
eventId: 'room-ready',
|
|
187
|
-
type: 'room_ready_to_start',
|
|
188
|
-
producer: 'local_synth',
|
|
189
|
-
producerPluginId: 'clawclaw.derived-event',
|
|
190
|
-
segmentId: 'room-1',
|
|
191
|
-
epochSeq: 1,
|
|
192
|
-
payload: { room_code: '123456', ready_to_start: true },
|
|
193
|
-
});
|
|
194
|
-
setReady(readyView('room-1', 1, ready.commitSeq, { phase: 'room_waiting' }));
|
|
195
|
-
|
|
196
|
-
const full = service.prepareEvents({ eventType: 'room.full' }).output.event as Record<string, unknown>;
|
|
197
|
-
const derived = service.prepareEvents({ eventType: 'room_ready_to_start' })
|
|
198
|
-
.output.event as Record<string, unknown>;
|
|
199
|
-
|
|
200
|
-
expect(full).not.toHaveProperty('hint');
|
|
201
|
-
expect(derived?.hint).toContain('you are the owner');
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('keeps Monitor-complete Events out of the detail batch across segments', async () => {
|
|
205
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
206
|
-
const roomEvent = await publish(ingress, {
|
|
207
|
-
eventId: 'room-chat',
|
|
208
|
-
type: 'room.chat',
|
|
209
|
-
segmentId: 'room-1',
|
|
210
|
-
epochSeq: 1,
|
|
211
|
-
payload: { name: '2号', content: '开局吗' },
|
|
212
|
-
});
|
|
213
|
-
repository.saveSegment({
|
|
214
|
-
segmentId: 'game-1',
|
|
215
|
-
sessionId: 'session-1',
|
|
216
|
-
sequence: 2,
|
|
217
|
-
kind: 'game',
|
|
218
|
-
status: 'open',
|
|
219
|
-
isCurrent: true,
|
|
220
|
-
openedAt: '2026-07-22T00:00:01.000Z',
|
|
221
|
-
});
|
|
222
|
-
const gameEvent = await publish(ingress, {
|
|
223
|
-
eventId: 'role',
|
|
224
|
-
type: 'role_assigned',
|
|
225
|
-
segmentId: 'game-1',
|
|
226
|
-
epochSeq: 2,
|
|
227
|
-
payload: { role: 'shrimp_generic', faction: 'lobster' },
|
|
228
|
-
});
|
|
229
|
-
setReady(readyView('game-1', 2, gameEvent.commitSeq, {
|
|
230
|
-
phase: 'wandering',
|
|
231
|
-
tick: 7,
|
|
232
|
-
you: { name: 'self', seat: 1, alive: true },
|
|
233
|
-
}));
|
|
234
|
-
|
|
235
|
-
const prepared = service.prepareEvents();
|
|
236
|
-
expect(prepared.deliveryToken).toBeTypeOf('string');
|
|
237
|
-
expect((prepared.output.events as Array<Record<string, unknown>>).map((event) => event.type))
|
|
238
|
-
.toEqual(['role_assigned']);
|
|
239
|
-
expect(prepared.output).toMatchObject({
|
|
240
|
-
state: { phase: 'wandering', tick: 7 },
|
|
241
|
-
});
|
|
242
|
-
expectCompactEventsOutput(prepared.output);
|
|
243
|
-
expect(repository.delivery(roomEvent.eventId, 'local-agent')?.detailState).toBe('deferred');
|
|
244
|
-
expect(repository.delivery(gameEvent.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
245
|
-
|
|
246
|
-
expect(service.ackEvents(prepared.deliveryToken!)).toBe(true);
|
|
247
|
-
expect(repository.delivery(roomEvent.eventId, 'local-agent')?.detailState).toBe('deferred');
|
|
248
|
-
expect(repository.delivery(gameEvent.eventId, 'local-agent')?.detailState).toBe('delivered');
|
|
249
|
-
const empty = service.prepareEvents().output;
|
|
250
|
-
expect(empty).toMatchObject({ events: [] });
|
|
251
|
-
expectCompactEventsOutput(empty);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('returns every unread Event in one response without paging', async () => {
|
|
255
|
-
const { ingress, service, setReady } = fixture();
|
|
256
|
-
let watermark = 0;
|
|
257
|
-
for (let index = 0; index < 20; index += 1) {
|
|
258
|
-
const event = await publish(ingress, {
|
|
259
|
-
eventId: `bulk-${index}`,
|
|
260
|
-
type: 'speech',
|
|
261
|
-
segmentId: 'room-1',
|
|
262
|
-
epochSeq: 1,
|
|
263
|
-
payload: { actor_name: `player-${index}`, text: 'x'.repeat(2_000) },
|
|
264
|
-
});
|
|
265
|
-
watermark = event.commitSeq;
|
|
266
|
-
}
|
|
267
|
-
setReady(readyView('room-1', 1, watermark, { phase: 'meeting', tick: 1 }));
|
|
268
|
-
|
|
269
|
-
const prepared = service.prepareEvents();
|
|
270
|
-
|
|
271
|
-
expectCompactEventsOutput(prepared.output);
|
|
272
|
-
expect((prepared.output.events as unknown[])).toHaveLength(20);
|
|
273
|
-
expect(Buffer.byteLength(JSON.stringify(prepared.output), 'utf8')).toBeGreaterThan(24 * 1024);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it('never exposes or consumes Events beyond the captured Ready View', async () => {
|
|
277
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
278
|
-
const first = await publish(ingress, {
|
|
279
|
-
eventId: 'speech-1',
|
|
280
|
-
type: 'meeting_briefing',
|
|
281
|
-
segmentId: 'room-1',
|
|
282
|
-
epochSeq: 1,
|
|
283
|
-
payload: { actor_name: '2号', text: '一' },
|
|
284
|
-
});
|
|
285
|
-
const second = await publish(ingress, {
|
|
286
|
-
eventId: 'speech-2',
|
|
287
|
-
type: 'meeting_briefing',
|
|
288
|
-
segmentId: 'room-1',
|
|
289
|
-
epochSeq: 2,
|
|
290
|
-
payload: { actor_name: '3号', text: '二' },
|
|
291
|
-
});
|
|
292
|
-
setReady(readyView('room-1', 1, first.commitSeq, { phase: 'meeting', tick: 1 }));
|
|
293
|
-
|
|
294
|
-
const prepared = service.prepareEvents();
|
|
295
|
-
const firstEvents = prepared.output.events as Array<Record<string, unknown>>;
|
|
296
|
-
expect(firstEvents.map((event) => event.text)).toEqual([first.payload.text]);
|
|
297
|
-
expect(firstEvents[0]).not.toHaveProperty('event_id');
|
|
298
|
-
expect(firstEvents[0]).not.toHaveProperty('occurred_at');
|
|
299
|
-
expect(firstEvents[0]).not.toHaveProperty('received_at');
|
|
300
|
-
expect(service.releaseEvents(prepared.deliveryToken!)).toBe(true);
|
|
301
|
-
expect(repository.delivery(first.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
302
|
-
expect(repository.delivery(second.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
303
|
-
|
|
304
|
-
setReady(readyView('room-1', 2, second.commitSeq, { phase: 'meeting', tick: 2 }));
|
|
305
|
-
expect((service.prepareEvents().output.events as Array<Record<string, unknown>>)
|
|
306
|
-
.map((event) => event.text)).toEqual([second.payload.text, first.payload.text]);
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it('uses an explicitly captured boundary after the live view advances', async () => {
|
|
310
|
-
const { ingress, service, setReady } = fixture();
|
|
311
|
-
// A faster upstream plugin may commit a newer epoch before the boundary finishes.
|
|
312
|
-
await publish(ingress, {
|
|
313
|
-
eventId: 'speech-later',
|
|
314
|
-
type: 'meeting_briefing',
|
|
315
|
-
segmentId: 'room-1',
|
|
316
|
-
epochSeq: 2,
|
|
317
|
-
payload: { actor_name: '3', text: 'after' },
|
|
318
|
-
});
|
|
319
|
-
const first = await publish(ingress, {
|
|
320
|
-
eventId: 'speech-boundary',
|
|
321
|
-
type: 'meeting_briefing',
|
|
322
|
-
segmentId: 'room-1',
|
|
323
|
-
epochSeq: 1,
|
|
324
|
-
payload: { actor_name: '2', text: 'before' },
|
|
325
|
-
});
|
|
326
|
-
const boundary = readyView('room-1', 1, first.commitSeq, { phase: 'meeting', tick: 1 });
|
|
327
|
-
setReady(readyView('room-1', 2, first.commitSeq, { phase: 'meeting', tick: 2 }));
|
|
328
|
-
|
|
329
|
-
const prepared = service.prepareEvents({}, boundary);
|
|
330
|
-
expect(prepared.output).toMatchObject({ state: { tick: 1 } });
|
|
331
|
-
expect((prepared.output.events as Array<Record<string, unknown>>).map((event) => event.text))
|
|
332
|
-
.toEqual([first.payload.text]);
|
|
333
|
-
expect(service.releaseEvents(prepared.deliveryToken!)).toBe(true);
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
it('waits for the previous prepared delivery before preparing another response', async () => {
|
|
337
|
-
const { ingress, service, setReady } = fixture();
|
|
338
|
-
const event = await publish(ingress, {
|
|
339
|
-
eventId: 'speech-serial',
|
|
340
|
-
type: 'meeting_briefing',
|
|
341
|
-
segmentId: 'room-1',
|
|
342
|
-
epochSeq: 1,
|
|
343
|
-
payload: { actor_name: '2', text: 'serial' },
|
|
344
|
-
});
|
|
345
|
-
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'meeting', tick: 1 }));
|
|
346
|
-
|
|
347
|
-
const first = service.prepareEvents();
|
|
348
|
-
let secondSettled = false;
|
|
349
|
-
const secondPromise = service.prepareEventsWhenAvailable().finally(() => {
|
|
350
|
-
secondSettled = true;
|
|
351
|
-
});
|
|
352
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
353
|
-
expect(secondSettled).toBe(false);
|
|
354
|
-
expect(service.releaseEvents(first.deliveryToken!)).toBe(true);
|
|
355
|
-
|
|
356
|
-
const second = await secondPromise;
|
|
357
|
-
expect((second.output.events as Array<Record<string, unknown>>).map((item) => item.text))
|
|
358
|
-
.toEqual([event.payload.text]);
|
|
359
|
-
expect(service.releaseEvents(second.deliveryToken!)).toBe(true);
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
it('queries the latest type without changing unread state', async () => {
|
|
363
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
364
|
-
const event = await publish(ingress, {
|
|
365
|
-
eventId: 'role',
|
|
366
|
-
type: 'role_assigned',
|
|
367
|
-
segmentId: 'room-1',
|
|
368
|
-
epochSeq: 1,
|
|
369
|
-
payload: { role: 'shrimp_generic' },
|
|
370
|
-
});
|
|
371
|
-
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'loading', tick: 0 }));
|
|
372
|
-
|
|
373
|
-
const result = service.prepareEvents({ eventType: 'role_assigned' });
|
|
374
|
-
expect(result.deliveryToken).toBeUndefined();
|
|
375
|
-
expect(result.output).toMatchObject({
|
|
376
|
-
found: true,
|
|
377
|
-
event: { type: 'role_assigned', role: 'shrimp_generic' },
|
|
378
|
-
});
|
|
379
|
-
expect(result.output.event).not.toHaveProperty('event_id');
|
|
380
|
-
expect(result.output.event).not.toHaveProperty('occurred_at');
|
|
381
|
-
expect(result.output.event).not.toHaveProperty('received_at');
|
|
382
|
-
expectCompactEventsOutput(result.output);
|
|
383
|
-
expect(repository.delivery(event.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
it('uses delivery class configuration for Monitor and ccl events independently', async () => {
|
|
387
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
388
|
-
const internal = await publish(ingress, {
|
|
389
|
-
eventId: 'move-1',
|
|
390
|
-
type: 'move',
|
|
391
|
-
segmentId: 'room-1',
|
|
392
|
-
epochSeq: 1,
|
|
393
|
-
payload: { x: 1, y: 2 },
|
|
394
|
-
});
|
|
395
|
-
const eventsOnly = await publish(ingress, {
|
|
396
|
-
eventId: 'visual-1',
|
|
397
|
-
type: 'visual.player_moved',
|
|
398
|
-
producer: 'local_synth',
|
|
399
|
-
segmentId: 'room-1',
|
|
400
|
-
epochSeq: 1,
|
|
401
|
-
payload: {
|
|
402
|
-
player_seat: 2,
|
|
403
|
-
direction: 'right',
|
|
404
|
-
text: '9:41,你从导航仓左上侧移动到2号走廊右下侧。',
|
|
405
|
-
},
|
|
406
|
-
});
|
|
407
|
-
setReady(readyView('room-1', 1, eventsOnly.commitSeq, { phase: 'wandering', tick: 3 }));
|
|
408
|
-
|
|
409
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
410
|
-
const prepared = service.prepareEvents();
|
|
411
|
-
expect(prepared.output.events).toEqual([]);
|
|
412
|
-
expect(repository.delivery(internal.eventId, 'local-agent')?.detailState)
|
|
413
|
-
.toBe('not_applicable');
|
|
414
|
-
expect(repository.delivery(eventsOnly.eventId, 'local-agent')?.monitorState).toBe('pending');
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
it('hides task assignment and emits player changes as detailed Events instead of State', async () => {
|
|
418
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
419
|
-
const task = await publish(ingress, {
|
|
420
|
-
eventId: 'task-assigned-1',
|
|
421
|
-
type: 'task_assigned',
|
|
422
|
-
segmentId: 'room-1',
|
|
423
|
-
epochSeq: 1,
|
|
424
|
-
payload: { task_name: '丢垃圾', room: '自助餐厅', x: 321, y: 654 },
|
|
425
|
-
});
|
|
426
|
-
const changed = await publish(ingress, {
|
|
427
|
-
eventId: 'players-changed-1',
|
|
428
|
-
type: 'players_changed',
|
|
429
|
-
producer: 'local_synth',
|
|
430
|
-
segmentId: 'room-1',
|
|
431
|
-
epochSeq: 1,
|
|
432
|
-
payload: {
|
|
433
|
-
tick: 644,
|
|
434
|
-
meeting: true,
|
|
435
|
-
meeting_count: 1,
|
|
436
|
-
changes: [{
|
|
437
|
-
change: 'died',
|
|
438
|
-
name: '陈皮一带四#c7',
|
|
439
|
-
seat: 9,
|
|
440
|
-
cause: 'killed',
|
|
441
|
-
killer: null,
|
|
442
|
-
}],
|
|
443
|
-
players: [{
|
|
444
|
-
name: 'Alpha',
|
|
445
|
-
seat: 2,
|
|
446
|
-
status: 'alive',
|
|
447
|
-
death: null,
|
|
448
|
-
}, {
|
|
449
|
-
name: '陈皮一带四#c7',
|
|
450
|
-
seat: 9,
|
|
451
|
-
status: 'dead',
|
|
452
|
-
death: { cause: 'killed', killer: null },
|
|
453
|
-
}],
|
|
454
|
-
},
|
|
455
|
-
});
|
|
456
|
-
setReady(readyView('room-1', 1, changed.commitSeq, {
|
|
457
|
-
phase: 'meeting',
|
|
458
|
-
tick: 644,
|
|
459
|
-
players: [{ name: '陈皮一带四#c7', seat: 9, status: 'dead' }],
|
|
460
|
-
meeting: { meeting_count: 1 },
|
|
461
|
-
}));
|
|
462
|
-
|
|
463
|
-
const output = service.prepareEvents().output;
|
|
464
|
-
expect(output.state).not.toHaveProperty('players');
|
|
465
|
-
expect(output.events).toEqual([{
|
|
466
|
-
type: 'players_changed',
|
|
467
|
-
tick: 644,
|
|
468
|
-
meeting: true,
|
|
469
|
-
meeting_count: 1,
|
|
470
|
-
changes: [{
|
|
471
|
-
change: 'died',
|
|
472
|
-
name: '陈皮一带四#c7',
|
|
473
|
-
seat: 9,
|
|
474
|
-
cause: 'killed',
|
|
475
|
-
killer: null,
|
|
476
|
-
}],
|
|
477
|
-
players: [{
|
|
478
|
-
name: 'Alpha',
|
|
479
|
-
seat: 2,
|
|
480
|
-
status: 'alive',
|
|
481
|
-
death: null,
|
|
482
|
-
}, {
|
|
483
|
-
name: '陈皮一带四#c7',
|
|
484
|
-
seat: 9,
|
|
485
|
-
status: 'dead',
|
|
486
|
-
death: { cause: 'killed', killer: null },
|
|
487
|
-
}],
|
|
488
|
-
}]);
|
|
489
|
-
expect(repository.delivery(task.eventId, 'local-agent')?.detailState).toBe('not_applicable');
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
it('uses one enriched task_completed for Monitor and ccl events while task_assigned stays internal', async () => {
|
|
493
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
494
|
-
const completed = await publish(ingress, {
|
|
495
|
-
eventId: 'task-completed-1',
|
|
496
|
-
type: 'task_completed',
|
|
497
|
-
segmentId: 'room-1',
|
|
498
|
-
epochSeq: 1,
|
|
499
|
-
payload: {
|
|
500
|
-
tick: 42,
|
|
501
|
-
task_name: '擦拭酒瓶',
|
|
502
|
-
newly_assigned_task: {
|
|
503
|
-
name: '消毒淋浴器', room: '制氧舱', x: 123, y: 456, is_fake_shrimp: false,
|
|
504
|
-
},
|
|
505
|
-
},
|
|
506
|
-
});
|
|
507
|
-
const assigned = await publish(ingress, {
|
|
508
|
-
eventId: 'task-assigned-1',
|
|
509
|
-
type: 'task_assigned',
|
|
510
|
-
segmentId: 'room-1',
|
|
511
|
-
epochSeq: 1,
|
|
512
|
-
payload: { tick: 42, task_name: '消毒淋浴器', room: '制氧舱', x: 123, y: 456 },
|
|
513
|
-
});
|
|
514
|
-
setReady(readyView('room-1', 1, assigned.commitSeq, { phase: 'wandering', tick: 42 }));
|
|
515
|
-
|
|
516
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
517
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
518
|
-
const claim = broker.handle({
|
|
519
|
-
type: 'mailbox_claim',
|
|
520
|
-
relay_id: 'relay-task-completed',
|
|
521
|
-
mode: 'short',
|
|
522
|
-
});
|
|
523
|
-
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
524
|
-
expect(service.composeMonitor(payloads)).toMatchObject({
|
|
525
|
-
events: ['task_completed'],
|
|
526
|
-
details_required: ['task_completed'],
|
|
527
|
-
messages: [expect.stringContaining('任务完成:擦拭酒瓶;新分配任务:消毒淋浴器(制氧舱)')],
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
expect(service.prepareEvents().output.events).toEqual([{
|
|
531
|
-
type: 'task_completed',
|
|
532
|
-
tick: 42,
|
|
533
|
-
task_name: '擦拭酒瓶',
|
|
534
|
-
newly_assigned_task: {
|
|
535
|
-
name: '消毒淋浴器', room: '制氧舱', x: 123, y: 456, is_fake_shrimp: false,
|
|
536
|
-
},
|
|
537
|
-
}]);
|
|
538
|
-
expect(repository.delivery(assigned.eventId, 'local-agent')?.detailState).toBe('not_applicable');
|
|
539
|
-
expect(repository.delivery(completed.eventId, 'local-agent')?.detailState).not.toBe('not_applicable');
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
it('presents complete player and system killer facts through Monitor without detail reads', async () => {
|
|
543
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
544
|
-
const playerKilled = await publish(ingress, {
|
|
545
|
-
eventId: 'player-killed',
|
|
546
|
-
type: 'killed',
|
|
547
|
-
segmentId: 'room-1',
|
|
548
|
-
epochSeq: 1,
|
|
549
|
-
payload: {
|
|
550
|
-
tick: 41,
|
|
551
|
-
room: '制氧舱',
|
|
552
|
-
actor_name: 'victim',
|
|
553
|
-
actor_seat: 4,
|
|
554
|
-
killer_kind: 'player',
|
|
555
|
-
killer_name: '某蟹',
|
|
556
|
-
killer_seat: 1,
|
|
557
|
-
},
|
|
558
|
-
});
|
|
559
|
-
const systemKilled = await publish(ingress, {
|
|
560
|
-
eventId: 'system-killed',
|
|
561
|
-
type: 'killed',
|
|
562
|
-
segmentId: 'room-1',
|
|
563
|
-
epochSeq: 2,
|
|
564
|
-
payload: {
|
|
565
|
-
tick: 42,
|
|
566
|
-
room: '制氧舱',
|
|
567
|
-
actor_name: 'victim',
|
|
568
|
-
actor_seat: 4,
|
|
569
|
-
killer_kind: 'system',
|
|
570
|
-
killer_name: 'Shrimp God',
|
|
571
|
-
},
|
|
572
|
-
});
|
|
573
|
-
setReady(readyView('room-1', 2, systemKilled.commitSeq, { phase: 'wandering', tick: 42 }));
|
|
574
|
-
|
|
575
|
-
expect(service.prepareMonitor(true)).toBe(2);
|
|
576
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
577
|
-
const claim = broker.handle({
|
|
578
|
-
type: 'mailbox_claim',
|
|
579
|
-
relay_id: 'relay-structured-killers',
|
|
580
|
-
mode: 'short',
|
|
581
|
-
});
|
|
582
|
-
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
583
|
-
const monitor = service.composeMonitor(payloads);
|
|
584
|
-
expect(monitor).toMatchObject({ events: ['killed', 'killed'] });
|
|
585
|
-
expect(monitor.messages).toEqual(expect.arrayContaining([
|
|
586
|
-
expect.stringContaining('被1号某蟹击杀'),
|
|
587
|
-
expect.stringContaining('被Shrimp God击杀'),
|
|
588
|
-
]));
|
|
589
|
-
expect(JSON.stringify(monitor)).not.toContain('?号Shrimp God');
|
|
590
|
-
|
|
591
|
-
expect(service.prepareEvents().output.events).toEqual([]);
|
|
592
|
-
expect(repository.delivery(playerKilled.eventId, 'local-agent')?.detailState)
|
|
593
|
-
.not.toBe('not_applicable');
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
describe('ClawClaw Mailbox Monitor', () => {
|
|
599
|
-
it('claims and ACKs the same dedicated consumer used for Monitor projection', async () => {
|
|
600
|
-
const consumerId = 'local-agent:monitor';
|
|
601
|
-
const { repository, ingress, service, setReady } = fixture({ consumerId });
|
|
602
|
-
const event = await publish(ingress, {
|
|
603
|
-
eventId: 'dedicated-monitor-consumer',
|
|
604
|
-
type: 'speech',
|
|
605
|
-
segmentId: 'room-1',
|
|
606
|
-
epochSeq: 1,
|
|
607
|
-
payload: { actor_name: '2', text: 'hello' },
|
|
608
|
-
});
|
|
609
|
-
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'wandering', tick: 1 }));
|
|
610
|
-
|
|
611
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
612
|
-
expect(new MailboxRelayBroker(repository, 'short').handle({
|
|
613
|
-
type: 'mailbox_claim',
|
|
614
|
-
relay_id: 'wrong-consumer',
|
|
615
|
-
mode: 'short',
|
|
616
|
-
})?.claim).toBeNull();
|
|
617
|
-
|
|
618
|
-
const broker = new MailboxRelayBroker(repository, 'short', consumerId);
|
|
619
|
-
const claim = broker.handle({
|
|
620
|
-
type: 'mailbox_claim',
|
|
621
|
-
relay_id: 'monitor-consumer',
|
|
622
|
-
mode: 'short',
|
|
623
|
-
});
|
|
624
|
-
expect(claim?.claim?.items).toMatchObject([{ event_id: event.eventId }]);
|
|
625
|
-
expect(broker.handle({
|
|
626
|
-
type: 'mailbox_ack',
|
|
627
|
-
relay_id: 'monitor-consumer',
|
|
628
|
-
mode: 'short',
|
|
629
|
-
claim_token: claim?.claim?.claim_token,
|
|
630
|
-
})).toMatchObject({ ok: true, result: { status: 'accepted' } });
|
|
631
|
-
expect(repository.delivery(event.eventId, consumerId)).toMatchObject({
|
|
632
|
-
monitorState: 'notified',
|
|
633
|
-
detailState: 'not_applicable',
|
|
634
|
-
});
|
|
635
|
-
});
|
|
636
|
-
|
|
637
|
-
it('does not accumulate Monitor items when that output adapter is disabled', async () => {
|
|
638
|
-
const consumerId = 'local-agent:monitor';
|
|
639
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
640
|
-
consumerId,
|
|
641
|
-
monitorEnabled: false,
|
|
642
|
-
});
|
|
643
|
-
const event = await publish(ingress, {
|
|
644
|
-
eventId: 'disabled-monitor-consumer',
|
|
645
|
-
type: 'speech',
|
|
646
|
-
segmentId: 'room-1',
|
|
647
|
-
epochSeq: 1,
|
|
648
|
-
payload: { actor_name: '2', text: 'hello' },
|
|
649
|
-
});
|
|
650
|
-
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'wandering', tick: 1 }));
|
|
651
|
-
|
|
652
|
-
await service.flush();
|
|
653
|
-
expect(service.adapter).toBeUndefined();
|
|
654
|
-
expect(new MailboxRelayBroker(repository, 'short', consumerId).hasPendingCurrent()).toBe(false);
|
|
655
|
-
expect(repository.delivery(event.eventId, consumerId)).toBeNull();
|
|
656
|
-
});
|
|
657
|
-
|
|
658
|
-
it('uses the registered short player-change message', async () => {
|
|
659
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
660
|
-
const event = await publish(ingress, {
|
|
661
|
-
eventId: 'players-changed-monitor',
|
|
662
|
-
type: 'players_changed',
|
|
663
|
-
producer: 'local_synth',
|
|
664
|
-
segmentId: 'room-1',
|
|
665
|
-
epochSeq: 1,
|
|
666
|
-
payload: {
|
|
667
|
-
tick: 644,
|
|
668
|
-
meeting: true,
|
|
669
|
-
meeting_count: 1,
|
|
670
|
-
changes: [{
|
|
671
|
-
change: 'died',
|
|
672
|
-
name: '陈皮一带四#c7',
|
|
673
|
-
seat: 9,
|
|
674
|
-
cause: 'killed',
|
|
675
|
-
killer: null,
|
|
676
|
-
}],
|
|
677
|
-
players: [{
|
|
678
|
-
name: '陈皮一带四#c7',
|
|
679
|
-
seat: 9,
|
|
680
|
-
status: 'dead',
|
|
681
|
-
death: { cause: 'killed', killer: null },
|
|
682
|
-
}],
|
|
683
|
-
},
|
|
684
|
-
});
|
|
685
|
-
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'meeting', tick: 644 }));
|
|
686
|
-
|
|
687
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
688
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
689
|
-
const claim = broker.handle({
|
|
690
|
-
type: 'mailbox_claim',
|
|
691
|
-
relay_id: 'relay-players-changed',
|
|
692
|
-
mode: 'short',
|
|
693
|
-
});
|
|
694
|
-
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
695
|
-
expect(service.composeMonitor(payloads)).toMatchObject({
|
|
696
|
-
events: ['players_changed'],
|
|
697
|
-
details_required: ['players_changed'],
|
|
698
|
-
messages: [
|
|
699
|
-
't644 players_changed 第1次会议中发现9号陈皮一带四#c7已被击杀,凶手未知。',
|
|
700
|
-
],
|
|
701
|
-
});
|
|
702
|
-
});
|
|
703
|
-
|
|
704
|
-
it('pulls only an oversized speech while keeping the short speech in Monitor', async () => {
|
|
705
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
706
|
-
const short = await publish(ingress, {
|
|
707
|
-
eventId: 'speech-short-monitor',
|
|
708
|
-
type: 'speech',
|
|
709
|
-
segmentId: 'room-1',
|
|
710
|
-
epochSeq: 1,
|
|
711
|
-
payload: { actor_name: '2号', text: '我在厨房看到3号。' },
|
|
712
|
-
});
|
|
713
|
-
const longText = `开场判断:${'很长的会议证词'.repeat(50)}`;
|
|
714
|
-
const long = await publish(ingress, {
|
|
715
|
-
eventId: 'speech-long-detail',
|
|
716
|
-
type: 'speech',
|
|
717
|
-
segmentId: 'room-1',
|
|
718
|
-
epochSeq: 1,
|
|
719
|
-
payload: { actor_name: '3号', text: longText },
|
|
720
|
-
});
|
|
721
|
-
setReady(readyView('room-1', 1, long.commitSeq, { phase: 'meeting', tick: 10 }));
|
|
722
|
-
|
|
723
|
-
expect(service.prepareMonitor(true)).toBe(2);
|
|
724
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
725
|
-
const monitorOutputs: Record<string, unknown>[] = [];
|
|
726
|
-
while (true) {
|
|
727
|
-
const claim = broker.handle({
|
|
728
|
-
type: 'mailbox_claim', relay_id: 'relay-speech-detail', mode: 'short',
|
|
729
|
-
});
|
|
730
|
-
if (!claim?.claim) break;
|
|
731
|
-
monitorOutputs.push(service.composeMonitor(
|
|
732
|
-
claim.claim.items.map((item: any) => item.payload),
|
|
733
|
-
));
|
|
734
|
-
broker.handle({
|
|
735
|
-
type: 'mailbox_ack', relay_id: 'relay-speech-detail', mode: 'short',
|
|
736
|
-
claim_token: claim.claim.claim_token,
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
expect(monitorOutputs.some((output) => (
|
|
740
|
-
Array.isArray(output.details_required) && output.details_required.includes('speech')
|
|
741
|
-
))).toBe(true);
|
|
742
|
-
expect(monitorOutputs.every((output) => !Object.hasOwn(output, 'state'))).toBe(true);
|
|
743
|
-
|
|
744
|
-
const details = service.prepareEvents();
|
|
745
|
-
expect((details.output.events as Array<Record<string, unknown>>).map((event) => event.text))
|
|
746
|
-
.toEqual([longText]);
|
|
747
|
-
expect((details.output.events as Array<Record<string, unknown>>).map((event) => event.type))
|
|
748
|
-
.toEqual(['speech']);
|
|
749
|
-
expect(short.commitSeq).toBeLessThan(long.commitSeq);
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
it('splits many short facts into complete Monitor notifications instead of truncating them', async () => {
|
|
753
|
-
const diagnostics: Array<{
|
|
754
|
-
name: string;
|
|
755
|
-
attributes?: Record<string, unknown>;
|
|
756
|
-
severity?: RuntimeDiagnosticSeverity;
|
|
757
|
-
}> = [];
|
|
758
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
759
|
-
diagnostic: (name, attributes, severity) => diagnostics.push({ name, attributes, severity }),
|
|
760
|
-
});
|
|
761
|
-
let watermark = 0;
|
|
762
|
-
for (let index = 0; index < 8; index += 1) {
|
|
763
|
-
const event = await publish(ingress, {
|
|
764
|
-
eventId: `monitor-pack-${index}`,
|
|
765
|
-
type: 'speech',
|
|
766
|
-
segmentId: 'room-1',
|
|
767
|
-
epochSeq: 1,
|
|
768
|
-
payload: { actor_name: `${index + 1}号`, text: `证词${index}-${'x'.repeat(70)}` },
|
|
769
|
-
});
|
|
770
|
-
watermark = event.commitSeq;
|
|
771
|
-
}
|
|
772
|
-
setReady(readyView('room-1', 1, watermark, { phase: 'meeting', tick: 10 }));
|
|
773
|
-
expect(service.prepareMonitor(true)).toBe(8);
|
|
774
|
-
|
|
775
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
776
|
-
let deliveredEvents = 0;
|
|
777
|
-
let notificationCount = 0;
|
|
778
|
-
while (true) {
|
|
779
|
-
const claim = broker.handle({
|
|
780
|
-
type: 'mailbox_claim', relay_id: 'relay-monitor-pack', mode: 'short',
|
|
781
|
-
});
|
|
782
|
-
if (!claim?.claim) break;
|
|
783
|
-
const payloads = claim.claim.items.map((item: any) => item.payload);
|
|
784
|
-
const output = service.composeMonitor(payloads);
|
|
785
|
-
expect(output.truncated).not.toBe(true);
|
|
786
|
-
expect(JSON.stringify(output).length).toBeLessThanOrEqual(500);
|
|
787
|
-
deliveredEvents += (output.events as string[]).length;
|
|
788
|
-
notificationCount += 1;
|
|
789
|
-
broker.handle({
|
|
790
|
-
type: 'mailbox_ack',
|
|
791
|
-
relay_id: 'relay-monitor-pack',
|
|
792
|
-
mode: 'short',
|
|
793
|
-
claim_token: claim.claim.claim_token,
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
expect(deliveredEvents).toBe(8);
|
|
797
|
-
expect(notificationCount).toBeGreaterThan(1);
|
|
798
|
-
const splitDiagnostics = diagnostics.filter((entry) => (
|
|
799
|
-
entry.name === 'runtime.mailbox.monitor_batch_split'
|
|
800
|
-
));
|
|
801
|
-
expect(splitDiagnostics).toHaveLength(1);
|
|
802
|
-
expect(splitDiagnostics[0]?.severity).toBe('info');
|
|
803
|
-
expect(splitDiagnostics[0]?.attributes).toMatchObject({
|
|
804
|
-
consumer_id: 'local-agent',
|
|
805
|
-
session_id: 'session-1',
|
|
806
|
-
segment_id: 'room-1',
|
|
807
|
-
ready_epoch_seq: 1,
|
|
808
|
-
event_watermark: watermark,
|
|
809
|
-
event_count: 8,
|
|
810
|
-
inserted_event_count: 8,
|
|
811
|
-
notification_count: notificationCount,
|
|
812
|
-
event_type_counts: { speech: 8 },
|
|
813
|
-
});
|
|
814
|
-
expect((splitDiagnostics[0]?.attributes?.events_per_notification as number[])
|
|
815
|
-
.reduce((sum, count) => sum + count, 0)).toBe(8);
|
|
816
|
-
expect(splitDiagnostics[0]?.attributes?.notification_char_counts as number[])
|
|
817
|
-
.toHaveLength(notificationCount);
|
|
818
|
-
expect(splitDiagnostics[0]?.attributes?.notification_char_counts as number[])
|
|
819
|
-
.toSatisfy((counts: number[]) => counts.every((count) => count <= 500));
|
|
820
|
-
|
|
821
|
-
expect(service.prepareMonitor(true)).toBe(0);
|
|
822
|
-
expect(diagnostics.filter((entry) => entry.name === 'runtime.mailbox.monitor_batch_split'))
|
|
823
|
-
.toHaveLength(1);
|
|
824
|
-
});
|
|
825
|
-
|
|
826
|
-
it('bounds the short queue and delegates one coalesced overflow hint to ccl events', async () => {
|
|
827
|
-
const diagnostics: Array<{
|
|
828
|
-
name: string;
|
|
829
|
-
attributes?: Record<string, unknown>;
|
|
830
|
-
severity?: RuntimeDiagnosticSeverity;
|
|
831
|
-
}> = [];
|
|
832
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
833
|
-
monitorPendingItemLimit: 2,
|
|
834
|
-
diagnostic: (name, attributes, severity) => diagnostics.push({ name, attributes, severity }),
|
|
835
|
-
});
|
|
836
|
-
const events: CanonicalEvent[] = [];
|
|
837
|
-
for (let index = 0; index < 5; index += 1) {
|
|
838
|
-
events.push(await publish(ingress, {
|
|
839
|
-
eventId: `monitor-overflow-${index}`,
|
|
840
|
-
type: 'speech',
|
|
841
|
-
segmentId: 'room-1',
|
|
842
|
-
epochSeq: 1,
|
|
843
|
-
payload: { actor_name: `${index + 1}号`, text: `short-${index}` },
|
|
844
|
-
}));
|
|
845
|
-
}
|
|
846
|
-
setReady(readyView('room-1', 1, events.at(-1)!.commitSeq, {
|
|
847
|
-
phase: 'meeting',
|
|
848
|
-
tick: 10,
|
|
849
|
-
}));
|
|
850
|
-
|
|
851
|
-
expect(service.prepareMonitor(true)).toBe(2);
|
|
852
|
-
expect(repository.peekMailbox({
|
|
853
|
-
consumerId: 'local-agent',
|
|
854
|
-
sessionId: 'session-1',
|
|
855
|
-
modes: ['short'],
|
|
856
|
-
states: ['pending', 'claimed'],
|
|
857
|
-
order: 'asc',
|
|
858
|
-
})).toHaveLength(2);
|
|
859
|
-
expect(events.slice(0, 2).map((event) => (
|
|
860
|
-
repository.delivery(event.eventId, 'local-agent')?.monitorState
|
|
861
|
-
))).toEqual(['pending', 'pending']);
|
|
862
|
-
expect(events.slice(2).map((event) => (
|
|
863
|
-
repository.delivery(event.eventId, 'local-agent')?.monitorState
|
|
864
|
-
))).toEqual(['suppressed', 'suppressed', 'suppressed']);
|
|
865
|
-
expect(service.prepareMonitor(true)).toBe(0);
|
|
866
|
-
|
|
867
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
868
|
-
const firstClaim = broker.handle({
|
|
869
|
-
type: 'mailbox_claim', relay_id: 'relay-monitor-overflow', mode: 'short',
|
|
870
|
-
});
|
|
871
|
-
const firstOutput = service.composeMonitor(
|
|
872
|
-
firstClaim?.claim?.items.map((item: any) => item.payload) ?? [],
|
|
873
|
-
);
|
|
874
|
-
expect(firstOutput).toMatchObject({
|
|
875
|
-
events: ['speech'],
|
|
876
|
-
backlog: {
|
|
877
|
-
remaining_events: 3,
|
|
878
|
-
through_event_commit_seq: events.at(-1)!.commitSeq,
|
|
879
|
-
command: 'ccl events',
|
|
880
|
-
},
|
|
881
|
-
guidance: expect.stringContaining('run ccl events now'),
|
|
882
|
-
truncated: true,
|
|
883
|
-
});
|
|
884
|
-
expect(JSON.stringify(firstOutput).length).toBeLessThanOrEqual(500);
|
|
885
|
-
broker.handle({
|
|
886
|
-
type: 'mailbox_ack',
|
|
887
|
-
relay_id: 'relay-monitor-overflow',
|
|
888
|
-
mode: 'short',
|
|
889
|
-
claim_token: firstClaim?.claim?.claim_token,
|
|
890
|
-
});
|
|
891
|
-
|
|
892
|
-
const secondClaim = broker.handle({
|
|
893
|
-
type: 'mailbox_claim', relay_id: 'relay-monitor-overflow', mode: 'short',
|
|
894
|
-
});
|
|
895
|
-
const secondOutput = service.composeMonitor(
|
|
896
|
-
secondClaim?.claim?.items.map((item: any) => item.payload) ?? [],
|
|
897
|
-
);
|
|
898
|
-
expect(secondOutput).not.toHaveProperty('backlog');
|
|
899
|
-
expect(secondOutput).not.toHaveProperty('guidance');
|
|
900
|
-
broker.handle({
|
|
901
|
-
type: 'mailbox_ack',
|
|
902
|
-
relay_id: 'relay-monitor-overflow',
|
|
903
|
-
mode: 'short',
|
|
904
|
-
claim_token: secondClaim?.claim?.claim_token,
|
|
905
|
-
});
|
|
906
|
-
|
|
907
|
-
const details = service.prepareEvents();
|
|
908
|
-
expect(details.output.events).toMatchObject([
|
|
909
|
-
{ type: 'speech', text: 'short-4' },
|
|
910
|
-
{ type: 'speech', text: 'short-3' },
|
|
911
|
-
{ type: 'speech', text: 'short-2' },
|
|
912
|
-
]);
|
|
913
|
-
expect(details.deliveryToken).toBeTypeOf('string');
|
|
914
|
-
expect(service.ackEvents(details.deliveryToken!)).toBe(true);
|
|
915
|
-
expect(diagnostics.filter((entry) => (
|
|
916
|
-
entry.name === 'runtime.mailbox.monitor_backlog_delegated'
|
|
917
|
-
))).toMatchObject([{
|
|
918
|
-
severity: 'info',
|
|
919
|
-
attributes: {
|
|
920
|
-
pending_item_limit: 2,
|
|
921
|
-
queued_item_count: 0,
|
|
922
|
-
direct_event_count: 2,
|
|
923
|
-
delegated_event_count: 3,
|
|
924
|
-
},
|
|
925
|
-
}]);
|
|
926
|
-
});
|
|
927
|
-
|
|
928
|
-
it('uses one extra coalesced hint slot when the ordinary short queue is already full', async () => {
|
|
929
|
-
const diagnostics: Array<{
|
|
930
|
-
name: string;
|
|
931
|
-
attributes?: Record<string, unknown>;
|
|
932
|
-
severity?: RuntimeDiagnosticSeverity;
|
|
933
|
-
}> = [];
|
|
934
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
935
|
-
monitorPendingItemLimit: 2,
|
|
936
|
-
diagnostic: (name, attributes, severity) => diagnostics.push({ name, attributes, severity }),
|
|
937
|
-
});
|
|
938
|
-
const baseline: CanonicalEvent[] = [];
|
|
939
|
-
for (let index = 0; index < 2; index += 1) {
|
|
940
|
-
baseline.push(await publish(ingress, {
|
|
941
|
-
eventId: `monitor-full-baseline-${index}`,
|
|
942
|
-
type: 'speech',
|
|
943
|
-
segmentId: 'room-1',
|
|
944
|
-
epochSeq: 1,
|
|
945
|
-
payload: { actor_name: `${index + 1}号`, text: `baseline-${index}` },
|
|
946
|
-
}));
|
|
947
|
-
}
|
|
948
|
-
setReady(readyView('room-1', 1, baseline.at(-1)!.commitSeq, {
|
|
949
|
-
phase: 'meeting', tick: 1,
|
|
950
|
-
}));
|
|
951
|
-
expect(service.prepareMonitor(true)).toBe(2);
|
|
952
|
-
|
|
953
|
-
const firstOverflow: CanonicalEvent[] = [];
|
|
954
|
-
for (let index = 0; index < 4; index += 1) {
|
|
955
|
-
firstOverflow.push(await publish(ingress, {
|
|
956
|
-
eventId: `monitor-full-overflow-${index}`,
|
|
957
|
-
type: 'speech',
|
|
958
|
-
segmentId: 'room-1',
|
|
959
|
-
epochSeq: 2,
|
|
960
|
-
payload: { actor_name: `${index + 3}号`, text: `overflow-${index}` },
|
|
961
|
-
}));
|
|
962
|
-
}
|
|
963
|
-
setReady(readyView('room-1', 2, firstOverflow.at(-1)!.commitSeq, {
|
|
964
|
-
phase: 'meeting', tick: 2,
|
|
965
|
-
}));
|
|
966
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
967
|
-
|
|
968
|
-
let queued = repository.peekMailbox<Record<string, unknown>>({
|
|
969
|
-
consumerId: 'local-agent',
|
|
970
|
-
sessionId: 'session-1',
|
|
971
|
-
modes: ['short'],
|
|
972
|
-
states: ['pending', 'claimed'],
|
|
973
|
-
order: 'asc',
|
|
974
|
-
});
|
|
975
|
-
expect(queued).toHaveLength(3);
|
|
976
|
-
expect(queued.filter((item) => (
|
|
977
|
-
!!item.payload.backlog && typeof item.payload.backlog === 'object'
|
|
978
|
-
))).toHaveLength(1);
|
|
979
|
-
expect(repository.delivery(firstOverflow[0]!.eventId, 'local-agent')?.monitorState)
|
|
980
|
-
.toBe('pending');
|
|
981
|
-
expect(firstOverflow.slice(1).map((event) => (
|
|
982
|
-
repository.delivery(event.eventId, 'local-agent')?.monitorState
|
|
983
|
-
))).toEqual(['suppressed', 'suppressed', 'suppressed']);
|
|
984
|
-
|
|
985
|
-
const laterOverflow: CanonicalEvent[] = [];
|
|
986
|
-
for (let index = 0; index < 2; index += 1) {
|
|
987
|
-
laterOverflow.push(await publish(ingress, {
|
|
988
|
-
eventId: `monitor-full-later-${index}`,
|
|
989
|
-
type: 'speech',
|
|
990
|
-
segmentId: 'room-1',
|
|
991
|
-
epochSeq: 3,
|
|
992
|
-
payload: { actor_name: `${index + 7}号`, text: `later-${index}` },
|
|
993
|
-
}));
|
|
994
|
-
}
|
|
995
|
-
setReady(readyView('room-1', 3, laterOverflow.at(-1)!.commitSeq, {
|
|
996
|
-
phase: 'meeting', tick: 3,
|
|
997
|
-
}));
|
|
998
|
-
expect(service.prepareMonitor(true)).toBe(0);
|
|
999
|
-
queued = repository.peekMailbox<Record<string, unknown>>({
|
|
1000
|
-
consumerId: 'local-agent',
|
|
1001
|
-
sessionId: 'session-1',
|
|
1002
|
-
modes: ['short'],
|
|
1003
|
-
states: ['pending', 'claimed'],
|
|
1004
|
-
order: 'asc',
|
|
1005
|
-
});
|
|
1006
|
-
expect(queued).toHaveLength(3);
|
|
1007
|
-
expect(queued.filter((item) => (
|
|
1008
|
-
!!item.payload.backlog && typeof item.payload.backlog === 'object'
|
|
1009
|
-
))).toHaveLength(1);
|
|
1010
|
-
expect(laterOverflow.map((event) => (
|
|
1011
|
-
repository.delivery(event.eventId, 'local-agent')?.monitorState
|
|
1012
|
-
))).toEqual(['suppressed', 'suppressed']);
|
|
1013
|
-
|
|
1014
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1015
|
-
const baselineClaim = broker.handle({
|
|
1016
|
-
type: 'mailbox_claim', relay_id: 'relay-monitor-full', mode: 'short',
|
|
1017
|
-
});
|
|
1018
|
-
expect(service.composeMonitor(
|
|
1019
|
-
baselineClaim?.claim?.items.map((item: any) => item.payload) ?? [],
|
|
1020
|
-
)).not.toHaveProperty('backlog');
|
|
1021
|
-
broker.handle({
|
|
1022
|
-
type: 'mailbox_ack', relay_id: 'relay-monitor-full', mode: 'short',
|
|
1023
|
-
claim_token: baselineClaim?.claim?.claim_token,
|
|
1024
|
-
});
|
|
1025
|
-
|
|
1026
|
-
const hintClaim = broker.handle({
|
|
1027
|
-
type: 'mailbox_claim', relay_id: 'relay-monitor-full', mode: 'short',
|
|
1028
|
-
});
|
|
1029
|
-
const hintPayloads = hintClaim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
1030
|
-
expect(service.composeMonitor(hintPayloads)).toMatchObject({
|
|
1031
|
-
backlog: {
|
|
1032
|
-
remaining_events: 5,
|
|
1033
|
-
through_event_commit_seq: laterOverflow.at(-1)!.commitSeq,
|
|
1034
|
-
command: 'ccl events',
|
|
1035
|
-
},
|
|
1036
|
-
guidance: expect.stringContaining('run ccl events now'),
|
|
1037
|
-
truncated: true,
|
|
1038
|
-
});
|
|
1039
|
-
|
|
1040
|
-
const details = service.prepareEvents();
|
|
1041
|
-
expect(details.output.events).toMatchObject([
|
|
1042
|
-
{ type: 'speech', text: 'later-1' },
|
|
1043
|
-
{ type: 'speech', text: 'later-0' },
|
|
1044
|
-
{ type: 'speech', text: 'overflow-3' },
|
|
1045
|
-
{ type: 'speech', text: 'overflow-2' },
|
|
1046
|
-
{ type: 'speech', text: 'overflow-1' },
|
|
1047
|
-
]);
|
|
1048
|
-
expect(service.ackEvents(details.deliveryToken!)).toBe(true);
|
|
1049
|
-
expect(service.composeMonitor(hintPayloads)).not.toHaveProperty('backlog');
|
|
1050
|
-
broker.handle({
|
|
1051
|
-
type: 'mailbox_ack', relay_id: 'relay-monitor-full', mode: 'short',
|
|
1052
|
-
claim_token: hintClaim?.claim?.claim_token,
|
|
1053
|
-
});
|
|
1054
|
-
expect(diagnostics.filter((entry) => (
|
|
1055
|
-
entry.name === 'runtime.mailbox.monitor_backlog_delegated'
|
|
1056
|
-
))).toHaveLength(1);
|
|
1057
|
-
});
|
|
1058
|
-
|
|
1059
|
-
it('keeps one blocked Event pending until a second Event forms a full-queue backlog', async () => {
|
|
1060
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1061
|
-
monitorPendingItemLimit: 2,
|
|
1062
|
-
});
|
|
1063
|
-
const baseline: CanonicalEvent[] = [];
|
|
1064
|
-
for (let index = 0; index < 2; index += 1) {
|
|
1065
|
-
baseline.push(await publish(ingress, {
|
|
1066
|
-
eventId: `monitor-single-baseline-${index}`,
|
|
1067
|
-
type: 'speech',
|
|
1068
|
-
segmentId: 'room-1',
|
|
1069
|
-
epochSeq: 1,
|
|
1070
|
-
payload: { actor_name: `${index + 1}号`, text: `baseline-${index}` },
|
|
1071
|
-
}));
|
|
1072
|
-
}
|
|
1073
|
-
setReady(readyView('room-1', 1, baseline.at(-1)!.commitSeq, {
|
|
1074
|
-
phase: 'meeting', tick: 1,
|
|
1075
|
-
}));
|
|
1076
|
-
expect(service.prepareMonitor(true)).toBe(2);
|
|
1077
|
-
|
|
1078
|
-
const firstBlocked = await publish(ingress, {
|
|
1079
|
-
eventId: 'monitor-single-blocked-first',
|
|
1080
|
-
type: 'speech',
|
|
1081
|
-
segmentId: 'room-1',
|
|
1082
|
-
epochSeq: 2,
|
|
1083
|
-
payload: { actor_name: '3号', text: 'blocked-first' },
|
|
1084
|
-
});
|
|
1085
|
-
setReady(readyView('room-1', 2, firstBlocked.commitSeq, {
|
|
1086
|
-
phase: 'meeting', tick: 2,
|
|
1087
|
-
}));
|
|
1088
|
-
expect(service.prepareMonitor(true)).toBe(0);
|
|
1089
|
-
expect(repository.peekMailbox({
|
|
1090
|
-
consumerId: 'local-agent',
|
|
1091
|
-
sessionId: 'session-1',
|
|
1092
|
-
modes: ['short'],
|
|
1093
|
-
states: ['pending', 'claimed'],
|
|
1094
|
-
order: 'asc',
|
|
1095
|
-
})).toHaveLength(2);
|
|
1096
|
-
expect(repository.delivery(firstBlocked.eventId, 'local-agent')?.monitorState)
|
|
1097
|
-
.toBe('pending');
|
|
1098
|
-
expect(repository.mailboxItemForEvent('local-agent', firstBlocked.eventId, 'short'))
|
|
1099
|
-
.toBeNull();
|
|
1100
|
-
|
|
1101
|
-
const secondBlocked = await publish(ingress, {
|
|
1102
|
-
eventId: 'monitor-single-blocked-second',
|
|
1103
|
-
type: 'speech',
|
|
1104
|
-
segmentId: 'room-1',
|
|
1105
|
-
epochSeq: 3,
|
|
1106
|
-
payload: { actor_name: '4号', text: 'blocked-second' },
|
|
1107
|
-
});
|
|
1108
|
-
setReady(readyView('room-1', 3, secondBlocked.commitSeq, {
|
|
1109
|
-
phase: 'meeting', tick: 3,
|
|
1110
|
-
}));
|
|
1111
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1112
|
-
const queued = repository.peekMailbox<Record<string, unknown>>({
|
|
1113
|
-
consumerId: 'local-agent',
|
|
1114
|
-
sessionId: 'session-1',
|
|
1115
|
-
modes: ['short'],
|
|
1116
|
-
states: ['pending', 'claimed'],
|
|
1117
|
-
order: 'asc',
|
|
1118
|
-
});
|
|
1119
|
-
expect(queued).toHaveLength(3);
|
|
1120
|
-
expect(queued.filter((item) => (
|
|
1121
|
-
!!item.payload.backlog && typeof item.payload.backlog === 'object'
|
|
1122
|
-
))).toHaveLength(1);
|
|
1123
|
-
expect(repository.delivery(firstBlocked.eventId, 'local-agent')?.monitorState)
|
|
1124
|
-
.toBe('pending');
|
|
1125
|
-
expect(repository.mailboxItemForEvent('local-agent', firstBlocked.eventId, 'short'))
|
|
1126
|
-
.not.toBeNull();
|
|
1127
|
-
expect(repository.delivery(secondBlocked.eventId, 'local-agent')?.monitorState)
|
|
1128
|
-
.toBe('suppressed');
|
|
1129
|
-
|
|
1130
|
-
const details = service.prepareEvents();
|
|
1131
|
-
expect(details.output.events).toMatchObject([{
|
|
1132
|
-
type: 'speech', text: 'blocked-second',
|
|
1133
|
-
}]);
|
|
1134
|
-
expect(service.ackEvents(details.deliveryToken!)).toBe(true);
|
|
1135
|
-
});
|
|
1136
|
-
|
|
1137
|
-
it('does not suppress overflow when persisting the unique hint anchor throws', async () => {
|
|
1138
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1139
|
-
monitorPendingItemLimit: 2,
|
|
1140
|
-
});
|
|
1141
|
-
const baseline: CanonicalEvent[] = [];
|
|
1142
|
-
for (let index = 0; index < 2; index += 1) {
|
|
1143
|
-
baseline.push(await publish(ingress, {
|
|
1144
|
-
eventId: `monitor-hint-failure-baseline-${index}`,
|
|
1145
|
-
type: 'speech',
|
|
1146
|
-
segmentId: 'room-1',
|
|
1147
|
-
epochSeq: 1,
|
|
1148
|
-
payload: { actor_name: `${index + 1}号`, text: `baseline-${index}` },
|
|
1149
|
-
}));
|
|
1150
|
-
}
|
|
1151
|
-
setReady(readyView('room-1', 1, baseline.at(-1)!.commitSeq, {
|
|
1152
|
-
phase: 'meeting', tick: 1,
|
|
1153
|
-
}));
|
|
1154
|
-
expect(service.prepareMonitor(true)).toBe(2);
|
|
1155
|
-
|
|
1156
|
-
const overflow: CanonicalEvent[] = [];
|
|
1157
|
-
for (let index = 0; index < 2; index += 1) {
|
|
1158
|
-
overflow.push(await publish(ingress, {
|
|
1159
|
-
eventId: `monitor-hint-failure-overflow-${index}`,
|
|
1160
|
-
type: 'speech',
|
|
1161
|
-
segmentId: 'room-1',
|
|
1162
|
-
epochSeq: 2,
|
|
1163
|
-
payload: { actor_name: `${index + 3}号`, text: `overflow-${index}` },
|
|
1164
|
-
}));
|
|
1165
|
-
}
|
|
1166
|
-
setReady(readyView('room-1', 2, overflow.at(-1)!.commitSeq, {
|
|
1167
|
-
phase: 'meeting', tick: 2,
|
|
1168
|
-
}));
|
|
1169
|
-
|
|
1170
|
-
const enqueue = repository.enqueueMailboxItem.bind(repository) as typeof repository.enqueueMailboxItem;
|
|
1171
|
-
repository.enqueueMailboxItem = ((request: any) => {
|
|
1172
|
-
const payload = request.payload as Record<string, unknown>;
|
|
1173
|
-
if (payload.backlog && typeof payload.backlog === 'object') {
|
|
1174
|
-
throw new Error('injected_hint_enqueue_failure');
|
|
1175
|
-
}
|
|
1176
|
-
return enqueue(request);
|
|
1177
|
-
}) as typeof repository.enqueueMailboxItem;
|
|
1178
|
-
expect(() => service.prepareMonitor(true)).toThrow('injected_hint_enqueue_failure');
|
|
1179
|
-
repository.enqueueMailboxItem = enqueue;
|
|
1180
|
-
|
|
1181
|
-
expect(overflow.map((event) => (
|
|
1182
|
-
repository.delivery(event.eventId, 'local-agent')?.monitorState
|
|
1183
|
-
))).toEqual(['pending', 'pending']);
|
|
1184
|
-
expect(overflow.map((event) => (
|
|
1185
|
-
repository.mailboxItemForEvent('local-agent', event.eventId, 'short')
|
|
1186
|
-
))).toEqual([null, null]);
|
|
1187
|
-
|
|
1188
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1189
|
-
expect(repository.delivery(overflow[0]!.eventId, 'local-agent')?.monitorState)
|
|
1190
|
-
.toBe('pending');
|
|
1191
|
-
expect(repository.mailboxItemForEvent('local-agent', overflow[0]!.eventId, 'short'))
|
|
1192
|
-
.not.toBeNull();
|
|
1193
|
-
expect(repository.delivery(overflow[1]!.eventId, 'local-agent')?.monitorState)
|
|
1194
|
-
.toBe('suppressed');
|
|
1195
|
-
});
|
|
1196
|
-
|
|
1197
|
-
it('bounds a fast-ACK ordinary stream within one rolling admission window', async () => {
|
|
1198
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1199
|
-
monitorPendingItemLimit: 10,
|
|
1200
|
-
monitorOrdinaryWindowItemBudget: 2,
|
|
1201
|
-
monitorBacklogHintWindowItemBudget: 2,
|
|
1202
|
-
monitorVisualMinIntervalMs: 0,
|
|
1203
|
-
});
|
|
1204
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1205
|
-
const events: CanonicalEvent[] = [];
|
|
1206
|
-
let notificationCount = 0;
|
|
1207
|
-
|
|
1208
|
-
for (let index = 0; index < 20; index += 1) {
|
|
1209
|
-
const event = await publish(ingress, {
|
|
1210
|
-
eventId: `monitor-window-budget-${index}`,
|
|
1211
|
-
type: 'visual.player_moved',
|
|
1212
|
-
producer: 'local_synth',
|
|
1213
|
-
segmentId: 'room-1',
|
|
1214
|
-
epochSeq: index + 1,
|
|
1215
|
-
payload: { player_seat: 2, text: `2号移动了-${index}` },
|
|
1216
|
-
});
|
|
1217
|
-
events.push(event);
|
|
1218
|
-
setReady(readyView('room-1', index + 1, event.commitSeq, {
|
|
1219
|
-
phase: 'wandering', tick: index + 1,
|
|
1220
|
-
}));
|
|
1221
|
-
service.prepareMonitor(true);
|
|
1222
|
-
|
|
1223
|
-
while (true) {
|
|
1224
|
-
const claim = broker.handle({
|
|
1225
|
-
type: 'mailbox_claim',
|
|
1226
|
-
relay_id: 'relay-window-budget',
|
|
1227
|
-
mode: 'short',
|
|
1228
|
-
});
|
|
1229
|
-
if (!claim?.claim) break;
|
|
1230
|
-
const output = service.composeMonitor(
|
|
1231
|
-
claim.claim.items.map((item: any) => item.payload),
|
|
1232
|
-
);
|
|
1233
|
-
expect(JSON.stringify(output).length).toBeLessThanOrEqual(500);
|
|
1234
|
-
notificationCount += 1;
|
|
1235
|
-
broker.handle({
|
|
1236
|
-
type: 'mailbox_ack',
|
|
1237
|
-
relay_id: 'relay-window-budget',
|
|
1238
|
-
mode: 'short',
|
|
1239
|
-
claim_token: claim.claim.claim_token,
|
|
1240
|
-
});
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
// Drain whenever a bounded hint delegated ordinary details. This is the
|
|
1244
|
-
// adversarial case for a pending-capacity-only design: both queues become
|
|
1245
|
-
// empty as quickly as possible, but the active rolling window must stay bounded.
|
|
1246
|
-
const details = service.prepareEvents();
|
|
1247
|
-
if (details.deliveryToken) expect(service.ackEvents(details.deliveryToken)).toBe(true);
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
expect(notificationCount).toBe(2);
|
|
1251
|
-
expect(events.filter((event) => (
|
|
1252
|
-
repository.delivery(event.eventId, 'local-agent')?.monitorState === 'notified'
|
|
1253
|
-
))).toHaveLength(2);
|
|
1254
|
-
expect(events.filter((event) => (
|
|
1255
|
-
repository.delivery(event.eventId, 'local-agent')?.monitorState === 'suppressed'
|
|
1256
|
-
))).toHaveLength(18);
|
|
1257
|
-
expect(repository.peekMailbox({
|
|
1258
|
-
consumerId: 'local-agent',
|
|
1259
|
-
sessionId: 'session-1',
|
|
1260
|
-
modes: ['short'],
|
|
1261
|
-
states: ['pending', 'claimed'],
|
|
1262
|
-
order: 'asc',
|
|
1263
|
-
})).toHaveLength(0);
|
|
1264
|
-
});
|
|
1265
|
-
|
|
1266
|
-
it('recovers ordinary admission across successive rolling windows', async () => {
|
|
1267
|
-
const baseMs = Date.parse('2026-07-22T00:00:00.000Z');
|
|
1268
|
-
const { repository, ingress, service, setReady, setNow } = fixture({
|
|
1269
|
-
monitorOrdinaryWindowItemBudget: 1,
|
|
1270
|
-
monitorBacklogHintWindowItemBudget: 0,
|
|
1271
|
-
monitorAdmissionWindowMs: 1_000,
|
|
1272
|
-
});
|
|
1273
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1274
|
-
const outcomes: Array<'notified' | 'suppressed'> = [];
|
|
1275
|
-
|
|
1276
|
-
for (const [index, offsetMs] of [0, 100, 1_000, 1_100, 2_000].entries()) {
|
|
1277
|
-
setNow(baseMs + offsetMs);
|
|
1278
|
-
const event = await publish(ingress, {
|
|
1279
|
-
eventId: `monitor-window-recovery-${index}`,
|
|
1280
|
-
type: 'speech',
|
|
1281
|
-
segmentId: 'room-1',
|
|
1282
|
-
epochSeq: index + 1,
|
|
1283
|
-
payload: { actor_name: '2号', text: `window-${index}` },
|
|
1284
|
-
});
|
|
1285
|
-
setReady(readyView('room-1', index + 1, event.commitSeq, {
|
|
1286
|
-
phase: 'meeting', tick: index + 1,
|
|
1287
|
-
}));
|
|
1288
|
-
service.prepareMonitor(true);
|
|
1289
|
-
|
|
1290
|
-
const claim = broker.handle({
|
|
1291
|
-
type: 'mailbox_claim', relay_id: 'relay-window-recovery', mode: 'short',
|
|
1292
|
-
});
|
|
1293
|
-
if (claim?.claim) {
|
|
1294
|
-
broker.handle({
|
|
1295
|
-
type: 'mailbox_ack',
|
|
1296
|
-
relay_id: 'relay-window-recovery',
|
|
1297
|
-
mode: 'short',
|
|
1298
|
-
claim_token: claim.claim.claim_token,
|
|
1299
|
-
});
|
|
1300
|
-
}
|
|
1301
|
-
outcomes.push(repository.delivery(event.eventId, 'local-agent')?.monitorState as (
|
|
1302
|
-
'notified' | 'suppressed'
|
|
1303
|
-
));
|
|
1304
|
-
|
|
1305
|
-
const details = service.prepareEvents();
|
|
1306
|
-
if (details.deliveryToken) expect(service.ackEvents(details.deliveryToken)).toBe(true);
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
expect(outcomes).toEqual([
|
|
1310
|
-
'notified', 'suppressed', 'notified', 'suppressed', 'notified',
|
|
1311
|
-
]);
|
|
1312
|
-
});
|
|
1313
|
-
|
|
1314
|
-
it('coalesces noisy motion bursts to the latest direct fact and rate-limits later motion', async () => {
|
|
1315
|
-
const baseMs = Date.parse('2026-07-22T00:00:00.000Z');
|
|
1316
|
-
const { repository, ingress, service, setReady, setNow } = fixture({
|
|
1317
|
-
monitorOrdinaryWindowItemBudget: 10,
|
|
1318
|
-
monitorBacklogHintWindowItemBudget: 0,
|
|
1319
|
-
monitorVisualMinIntervalMs: 5_000,
|
|
1320
|
-
});
|
|
1321
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1322
|
-
const burst: CanonicalEvent[] = [];
|
|
1323
|
-
for (let index = 0; index < 3; index += 1) {
|
|
1324
|
-
burst.push(await publish(ingress, {
|
|
1325
|
-
eventId: `monitor-visual-burst-${index}`,
|
|
1326
|
-
type: 'visual.player_moved',
|
|
1327
|
-
producer: 'local_synth',
|
|
1328
|
-
segmentId: 'room-1',
|
|
1329
|
-
epochSeq: 1,
|
|
1330
|
-
payload: { player_seat: 2, text: `2号移动了-${index}` },
|
|
1331
|
-
}));
|
|
1332
|
-
}
|
|
1333
|
-
setReady(readyView('room-1', 1, burst.at(-1)!.commitSeq, {
|
|
1334
|
-
phase: 'wandering', tick: 1,
|
|
1335
|
-
}));
|
|
1336
|
-
|
|
1337
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1338
|
-
expect(repository.mailboxItemForEvent(
|
|
1339
|
-
'local-agent', burst.at(-1)!.eventId, 'short',
|
|
1340
|
-
)).not.toBeNull();
|
|
1341
|
-
expect(burst.slice(0, -1).map((event) => (
|
|
1342
|
-
repository.delivery(event.eventId, 'local-agent')?.monitorState
|
|
1343
|
-
))).toEqual(['suppressed', 'suppressed']);
|
|
1344
|
-
const burstClaim = broker.handle({
|
|
1345
|
-
type: 'mailbox_claim', relay_id: 'relay-visual-burst', mode: 'short',
|
|
1346
|
-
});
|
|
1347
|
-
broker.handle({
|
|
1348
|
-
type: 'mailbox_ack',
|
|
1349
|
-
relay_id: 'relay-visual-burst',
|
|
1350
|
-
mode: 'short',
|
|
1351
|
-
claim_token: burstClaim?.claim?.claim_token,
|
|
1352
|
-
});
|
|
1353
|
-
const burstDetails = service.prepareEvents();
|
|
1354
|
-
expect(burstDetails.output.events).toHaveLength(2);
|
|
1355
|
-
expect(service.ackEvents(burstDetails.deliveryToken!)).toBe(true);
|
|
1356
|
-
|
|
1357
|
-
setNow(baseMs + 1_000);
|
|
1358
|
-
const rateLimited = await publish(ingress, {
|
|
1359
|
-
eventId: 'monitor-visual-rate-limited',
|
|
1360
|
-
type: 'visual.player_moved',
|
|
1361
|
-
producer: 'local_synth',
|
|
1362
|
-
segmentId: 'room-1',
|
|
1363
|
-
epochSeq: 2,
|
|
1364
|
-
payload: { player_seat: 2, text: '2号又移动了' },
|
|
1365
|
-
});
|
|
1366
|
-
setReady(readyView('room-1', 2, rateLimited.commitSeq, {
|
|
1367
|
-
phase: 'wandering', tick: 2,
|
|
1368
|
-
}));
|
|
1369
|
-
expect(service.prepareMonitor(true)).toBe(0);
|
|
1370
|
-
expect(repository.delivery(rateLimited.eventId, 'local-agent')?.monitorState)
|
|
1371
|
-
.toBe('suppressed');
|
|
1372
|
-
const rateLimitedDetails = service.prepareEvents();
|
|
1373
|
-
expect(rateLimitedDetails.output.events).toHaveLength(1);
|
|
1374
|
-
expect(service.ackEvents(rateLimitedDetails.deliveryToken!)).toBe(true);
|
|
1375
|
-
|
|
1376
|
-
setNow(baseMs + 5_000);
|
|
1377
|
-
const recovered = await publish(ingress, {
|
|
1378
|
-
eventId: 'monitor-visual-recovered',
|
|
1379
|
-
type: 'visual.player_moved',
|
|
1380
|
-
producer: 'local_synth',
|
|
1381
|
-
segmentId: 'room-1',
|
|
1382
|
-
epochSeq: 3,
|
|
1383
|
-
payload: { player_seat: 2, text: '2号继续移动' },
|
|
1384
|
-
});
|
|
1385
|
-
setReady(readyView('room-1', 3, recovered.commitSeq, {
|
|
1386
|
-
phase: 'wandering', tick: 3,
|
|
1387
|
-
}));
|
|
1388
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1389
|
-
expect(repository.mailboxItemForEvent(
|
|
1390
|
-
'local-agent', recovered.eventId, 'short',
|
|
1391
|
-
)).not.toBeNull();
|
|
1392
|
-
});
|
|
1393
|
-
|
|
1394
|
-
it('retains a visual transition ahead of later noisy motion', async () => {
|
|
1395
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1396
|
-
monitorOrdinaryWindowItemBudget: 1,
|
|
1397
|
-
monitorBacklogHintWindowItemBudget: 0,
|
|
1398
|
-
});
|
|
1399
|
-
const entered = await publish(ingress, {
|
|
1400
|
-
eventId: 'monitor-visual-transition-entered',
|
|
1401
|
-
type: 'visual.player_entered',
|
|
1402
|
-
producer: 'local_synth',
|
|
1403
|
-
segmentId: 'room-1',
|
|
1404
|
-
epochSeq: 1,
|
|
1405
|
-
payload: { player_seat: 2, text: '2号进入视野' },
|
|
1406
|
-
});
|
|
1407
|
-
const moved = await publish(ingress, {
|
|
1408
|
-
eventId: 'monitor-visual-transition-later-moved',
|
|
1409
|
-
type: 'visual.player_moved',
|
|
1410
|
-
producer: 'local_synth',
|
|
1411
|
-
segmentId: 'room-1',
|
|
1412
|
-
epochSeq: 1,
|
|
1413
|
-
payload: { player_seat: 2, text: '2号随后移动' },
|
|
1414
|
-
});
|
|
1415
|
-
setReady(readyView('room-1', 1, moved.commitSeq, {
|
|
1416
|
-
phase: 'wandering', tick: 1,
|
|
1417
|
-
}));
|
|
1418
|
-
|
|
1419
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1420
|
-
expect(repository.mailboxItemForEvent(
|
|
1421
|
-
'local-agent', entered.eventId, 'short',
|
|
1422
|
-
)).not.toBeNull();
|
|
1423
|
-
expect(repository.mailboxItemForEvent(
|
|
1424
|
-
'local-agent', moved.eventId, 'short',
|
|
1425
|
-
)).toBeNull();
|
|
1426
|
-
expect(repository.delivery(moved.eventId, 'local-agent')?.monitorState).toBe('suppressed');
|
|
1427
|
-
|
|
1428
|
-
const details = service.prepareEvents();
|
|
1429
|
-
expect(details.output.events).toEqual(['visual.player_moved | 2号随后移动']);
|
|
1430
|
-
expect(service.ackEvents(details.deliveryToken!)).toBe(true);
|
|
1431
|
-
});
|
|
1432
|
-
|
|
1433
|
-
it('consumes an ordinary output token only after its durable enqueue succeeds', async () => {
|
|
1434
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1435
|
-
monitorOrdinaryWindowItemBudget: 1,
|
|
1436
|
-
monitorBacklogHintWindowItemBudget: 0,
|
|
1437
|
-
});
|
|
1438
|
-
const event = await publish(ingress, {
|
|
1439
|
-
eventId: 'monitor-budget-enqueue-retry',
|
|
1440
|
-
type: 'speech',
|
|
1441
|
-
segmentId: 'room-1',
|
|
1442
|
-
epochSeq: 1,
|
|
1443
|
-
payload: { actor_name: '2号', text: 'retry me' },
|
|
1444
|
-
});
|
|
1445
|
-
setReady(readyView('room-1', 1, event.commitSeq, {
|
|
1446
|
-
phase: 'meeting', tick: 1,
|
|
1447
|
-
}));
|
|
1448
|
-
|
|
1449
|
-
const enqueue = repository.enqueueMailboxItem.bind(repository) as typeof repository.enqueueMailboxItem;
|
|
1450
|
-
repository.enqueueMailboxItem = (() => {
|
|
1451
|
-
throw new Error('injected_ordinary_enqueue_failure');
|
|
1452
|
-
}) as typeof repository.enqueueMailboxItem;
|
|
1453
|
-
expect(() => service.prepareMonitor(true)).toThrow('injected_ordinary_enqueue_failure');
|
|
1454
|
-
repository.enqueueMailboxItem = enqueue;
|
|
1455
|
-
|
|
1456
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1457
|
-
expect(repository.mailboxItemForEvent('local-agent', event.eventId, 'short')).not.toBeNull();
|
|
1458
|
-
});
|
|
1459
|
-
|
|
1460
|
-
it('uses the remaining hint budget within one rolling window after ccl events drains backlog', async () => {
|
|
1461
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1462
|
-
monitorOrdinaryWindowItemBudget: 0,
|
|
1463
|
-
monitorBacklogHintWindowItemBudget: 2,
|
|
1464
|
-
});
|
|
1465
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1466
|
-
|
|
1467
|
-
const publishBacklogPair = async (prefix: string, epochSeq: number): Promise<void> => {
|
|
1468
|
-
let watermark = 0;
|
|
1469
|
-
for (let index = 0; index < 2; index += 1) {
|
|
1470
|
-
watermark = (await publish(ingress, {
|
|
1471
|
-
eventId: `${prefix}-${index}`,
|
|
1472
|
-
type: 'speech',
|
|
1473
|
-
segmentId: 'room-1',
|
|
1474
|
-
epochSeq,
|
|
1475
|
-
payload: { actor_name: '2号', text: `${prefix}-${index}` },
|
|
1476
|
-
})).commitSeq;
|
|
1477
|
-
}
|
|
1478
|
-
setReady(readyView('room-1', epochSeq, watermark, {
|
|
1479
|
-
phase: 'meeting', tick: epochSeq,
|
|
1480
|
-
}));
|
|
1481
|
-
};
|
|
1482
|
-
const claimHint = (relayId: string): Record<string, unknown> => {
|
|
1483
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1484
|
-
const claim = broker.handle({
|
|
1485
|
-
type: 'mailbox_claim', relay_id: relayId, mode: 'short',
|
|
1486
|
-
});
|
|
1487
|
-
const output = service.composeMonitor(
|
|
1488
|
-
claim?.claim?.items.map((item: any) => item.payload) ?? [],
|
|
1489
|
-
);
|
|
1490
|
-
expect(output).toMatchObject({
|
|
1491
|
-
backlog: { remaining_events: 1, command: 'ccl events' },
|
|
1492
|
-
});
|
|
1493
|
-
broker.handle({
|
|
1494
|
-
type: 'mailbox_ack',
|
|
1495
|
-
relay_id: relayId,
|
|
1496
|
-
mode: 'short',
|
|
1497
|
-
claim_token: claim?.claim?.claim_token,
|
|
1498
|
-
});
|
|
1499
|
-
return output;
|
|
1500
|
-
};
|
|
1501
|
-
|
|
1502
|
-
await publishBacklogPair('monitor-hint-cycle-one', 1);
|
|
1503
|
-
claimHint('relay-hint-cycle-one');
|
|
1504
|
-
const firstDetails = service.prepareEvents();
|
|
1505
|
-
expect(firstDetails.output.events).toHaveLength(1);
|
|
1506
|
-
expect(service.ackEvents(firstDetails.deliveryToken!)).toBe(true);
|
|
1507
|
-
|
|
1508
|
-
await publishBacklogPair('monitor-hint-cycle-two', 2);
|
|
1509
|
-
claimHint('relay-hint-cycle-two');
|
|
1510
|
-
const secondDetails = service.prepareEvents();
|
|
1511
|
-
expect(secondDetails.output.events).toHaveLength(1);
|
|
1512
|
-
expect(service.ackEvents(secondDetails.deliveryToken!)).toBe(true);
|
|
1513
|
-
|
|
1514
|
-
await publishBacklogPair('monitor-hint-cycle-exhausted', 3);
|
|
1515
|
-
expect(service.prepareMonitor(true)).toBe(0);
|
|
1516
|
-
expect(broker.handle({
|
|
1517
|
-
type: 'mailbox_claim', relay_id: 'relay-hint-cycle-exhausted', mode: 'short',
|
|
1518
|
-
})?.claim).toBeNull();
|
|
1519
|
-
const exhaustedDetails = service.prepareEvents();
|
|
1520
|
-
expect(exhaustedDetails.output.events).toHaveLength(2);
|
|
1521
|
-
expect(service.ackEvents(exhaustedDetails.deliveryToken!)).toBe(true);
|
|
1522
|
-
});
|
|
1523
|
-
|
|
1524
|
-
it('delegates one quiet-tail ordinary Event after the direct budget is exhausted and uses a later Event as the hint anchor', async () => {
|
|
1525
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1526
|
-
monitorOrdinaryWindowItemBudget: 0,
|
|
1527
|
-
monitorBacklogHintWindowItemBudget: 1,
|
|
1528
|
-
});
|
|
1529
|
-
const quietTail = await publish(ingress, {
|
|
1530
|
-
eventId: 'monitor-budget-quiet-tail',
|
|
1531
|
-
type: 'speech',
|
|
1532
|
-
segmentId: 'room-1',
|
|
1533
|
-
epochSeq: 1,
|
|
1534
|
-
payload: { actor_name: '2号', text: 'quiet tail' },
|
|
1535
|
-
});
|
|
1536
|
-
setReady(readyView('room-1', 1, quietTail.commitSeq, {
|
|
1537
|
-
phase: 'meeting', tick: 1,
|
|
1538
|
-
}));
|
|
1539
|
-
|
|
1540
|
-
expect(service.prepareMonitor(true)).toBe(0);
|
|
1541
|
-
expect(repository.delivery(quietTail.eventId, 'local-agent')?.monitorState)
|
|
1542
|
-
.toBe('suppressed');
|
|
1543
|
-
expect(repository.mailboxItemForEvent('local-agent', quietTail.eventId, 'short'))
|
|
1544
|
-
.toBeNull();
|
|
1545
|
-
const details = service.prepareEvents();
|
|
1546
|
-
expect(details.output.events).toMatchObject([{
|
|
1547
|
-
type: 'speech', text: 'quiet tail',
|
|
1548
|
-
}]);
|
|
1549
|
-
|
|
1550
|
-
const hintAnchor = await publish(ingress, {
|
|
1551
|
-
eventId: 'monitor-budget-quiet-tail-hint-anchor',
|
|
1552
|
-
type: 'speech',
|
|
1553
|
-
segmentId: 'room-1',
|
|
1554
|
-
epochSeq: 2,
|
|
1555
|
-
payload: { actor_name: '3号', text: 'hint anchor' },
|
|
1556
|
-
});
|
|
1557
|
-
setReady(readyView('room-1', 2, hintAnchor.commitSeq, {
|
|
1558
|
-
phase: 'meeting', tick: 2,
|
|
1559
|
-
}));
|
|
1560
|
-
|
|
1561
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1562
|
-
expect(repository.mailboxItemForEvent<Record<string, unknown>>(
|
|
1563
|
-
'local-agent',
|
|
1564
|
-
hintAnchor.eventId,
|
|
1565
|
-
'short',
|
|
1566
|
-
)?.payload).toMatchObject({
|
|
1567
|
-
event: { type: 'speech' },
|
|
1568
|
-
backlog: { remaining_events: 1, command: 'ccl events' },
|
|
1569
|
-
});
|
|
1570
|
-
expect(service.ackEvents(details.deliveryToken!)).toBe(true);
|
|
1571
|
-
});
|
|
1572
|
-
|
|
1573
|
-
it('resets the admission budget for a restarted service without re-enqueueing inherited durable items', async () => {
|
|
1574
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1575
|
-
monitorOrdinaryWindowItemBudget: 1,
|
|
1576
|
-
monitorBacklogHintWindowItemBudget: 0,
|
|
1577
|
-
});
|
|
1578
|
-
const inherited = await publish(ingress, {
|
|
1579
|
-
eventId: 'monitor-budget-restart-inherited',
|
|
1580
|
-
type: 'speech',
|
|
1581
|
-
segmentId: 'room-1',
|
|
1582
|
-
epochSeq: 1,
|
|
1583
|
-
payload: { actor_name: '2号', text: 'inherited durable item' },
|
|
1584
|
-
});
|
|
1585
|
-
setReady(readyView('room-1', 1, inherited.commitSeq, {
|
|
1586
|
-
phase: 'meeting', tick: 1,
|
|
1587
|
-
}));
|
|
1588
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1589
|
-
await service.stop();
|
|
1590
|
-
|
|
1591
|
-
let restartedReady = readyView('room-1', 1, inherited.commitSeq, {
|
|
1592
|
-
phase: 'meeting', tick: 1,
|
|
1593
|
-
});
|
|
1594
|
-
const restarted = new ClawclawMailboxService({
|
|
1595
|
-
repository,
|
|
1596
|
-
readyView: () => structuredClone(restartedReady),
|
|
1597
|
-
monitorOrdinaryWindowItemBudget: 1,
|
|
1598
|
-
monitorBacklogHintWindowItemBudget: 0,
|
|
1599
|
-
});
|
|
1600
|
-
expect(restarted.prepareMonitor(true)).toBe(0);
|
|
1601
|
-
expect(repository.peekMailbox({
|
|
1602
|
-
consumerId: 'local-agent',
|
|
1603
|
-
sessionId: 'session-1',
|
|
1604
|
-
modes: ['short'],
|
|
1605
|
-
states: ['pending', 'claimed'],
|
|
1606
|
-
order: 'asc',
|
|
1607
|
-
})).toHaveLength(1);
|
|
1608
|
-
|
|
1609
|
-
const fresh = await publish(ingress, {
|
|
1610
|
-
eventId: 'monitor-budget-restart-fresh',
|
|
1611
|
-
type: 'speech',
|
|
1612
|
-
segmentId: 'room-1',
|
|
1613
|
-
epochSeq: 2,
|
|
1614
|
-
payload: { actor_name: '3号', text: 'fresh admission' },
|
|
1615
|
-
});
|
|
1616
|
-
restartedReady = readyView('room-1', 2, fresh.commitSeq, {
|
|
1617
|
-
phase: 'meeting', tick: 2,
|
|
1618
|
-
});
|
|
1619
|
-
expect(restarted.prepareMonitor(true)).toBe(1);
|
|
1620
|
-
expect(repository.peekMailbox({
|
|
1621
|
-
consumerId: 'local-agent',
|
|
1622
|
-
sessionId: 'session-1',
|
|
1623
|
-
modes: ['short'],
|
|
1624
|
-
states: ['pending', 'claimed'],
|
|
1625
|
-
order: 'asc',
|
|
1626
|
-
})).toHaveLength(2);
|
|
1627
|
-
await restarted.stop();
|
|
1628
|
-
});
|
|
1629
|
-
|
|
1630
|
-
it('keeps speech_your_turn direct and piggybacks backlog after both ordinary budgets are exhausted', async () => {
|
|
1631
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1632
|
-
monitorOrdinaryWindowItemBudget: 0,
|
|
1633
|
-
monitorBacklogHintWindowItemBudget: 0,
|
|
1634
|
-
});
|
|
1635
|
-
const visual = await publish(ingress, {
|
|
1636
|
-
eventId: 'monitor-exhausted-visual',
|
|
1637
|
-
type: 'visual.player_moved',
|
|
1638
|
-
producer: 'local_synth',
|
|
1639
|
-
segmentId: 'room-1',
|
|
1640
|
-
epochSeq: 1,
|
|
1641
|
-
payload: { player_seat: 2, text: '2号移动了。' },
|
|
1642
|
-
});
|
|
1643
|
-
setReady(readyView('room-1', 1, visual.commitSeq, {
|
|
1644
|
-
phase: 'meeting', tick: 1,
|
|
1645
|
-
}));
|
|
1646
|
-
expect(service.prepareMonitor(true)).toBe(0);
|
|
1647
|
-
expect(repository.delivery(visual.eventId, 'local-agent')?.monitorState).toBe('suppressed');
|
|
1648
|
-
|
|
1649
|
-
const yourTurn = await publish(ingress, {
|
|
1650
|
-
eventId: 'monitor-exhausted-your-turn',
|
|
1651
|
-
type: 'speech_your_turn',
|
|
1652
|
-
segmentId: 'room-1',
|
|
1653
|
-
epochSeq: 2,
|
|
1654
|
-
payload: { actor_name: 'self', remaining_secs: 45 },
|
|
1655
|
-
});
|
|
1656
|
-
setReady(readyView('room-1', 2, yourTurn.commitSeq, {
|
|
1657
|
-
phase: 'meeting', tick: 2,
|
|
1658
|
-
}));
|
|
1659
|
-
|
|
1660
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1661
|
-
const item = repository.mailboxItemForEvent<Record<string, unknown>>(
|
|
1662
|
-
'local-agent',
|
|
1663
|
-
yourTurn.eventId,
|
|
1664
|
-
'short',
|
|
1665
|
-
);
|
|
1666
|
-
expect(item?.payload).toMatchObject({
|
|
1667
|
-
event: { type: 'speech_your_turn' },
|
|
1668
|
-
backlog: { remaining_events: 1, command: 'ccl events' },
|
|
1669
|
-
});
|
|
1670
|
-
});
|
|
1671
|
-
|
|
1672
|
-
it('keeps kill, Behavior lifecycle, and decision-critical meeting Events direct after early noise', async () => {
|
|
1673
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1674
|
-
monitorOrdinaryWindowItemBudget: 0,
|
|
1675
|
-
monitorBacklogHintWindowItemBudget: 0,
|
|
1676
|
-
monitorPendingItemLimit: 1,
|
|
1677
|
-
});
|
|
1678
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1679
|
-
const noise = await publish(ingress, {
|
|
1680
|
-
eventId: 'monitor-protected-early-noise',
|
|
1681
|
-
type: 'visual.player_moved',
|
|
1682
|
-
producer: 'local_synth',
|
|
1683
|
-
segmentId: 'room-1',
|
|
1684
|
-
epochSeq: 1,
|
|
1685
|
-
payload: { player_seat: 2, text: '2号移动了' },
|
|
1686
|
-
});
|
|
1687
|
-
setReady(readyView('room-1', 1, noise.commitSeq, {
|
|
1688
|
-
phase: 'wandering', tick: 1,
|
|
1689
|
-
}));
|
|
1690
|
-
expect(service.prepareMonitor(true)).toBe(0);
|
|
1691
|
-
expect(repository.delivery(noise.eventId, 'local-agent')?.monitorState).toBe('suppressed');
|
|
1692
|
-
|
|
1693
|
-
const protectedTypes = [
|
|
1694
|
-
'kill',
|
|
1695
|
-
'killed',
|
|
1696
|
-
'murder_witnessed',
|
|
1697
|
-
'behavior.completed',
|
|
1698
|
-
'behavior.failed',
|
|
1699
|
-
'meeting_briefing',
|
|
1700
|
-
'speech_your_turn',
|
|
1701
|
-
'vote_phase_start',
|
|
1702
|
-
'vote_speech_phase_ended',
|
|
1703
|
-
'exile',
|
|
1704
|
-
'no_exile',
|
|
1705
|
-
];
|
|
1706
|
-
for (const [index, type] of protectedTypes.entries()) {
|
|
1707
|
-
const event = await publish(ingress, {
|
|
1708
|
-
eventId: `monitor-protected-${type}`,
|
|
1709
|
-
type,
|
|
1710
|
-
producer: type.startsWith('behavior.') ? 'local_synth' : 'backend_push',
|
|
1711
|
-
segmentId: 'room-1',
|
|
1712
|
-
epochSeq: index + 2,
|
|
1713
|
-
payload: type === 'meeting_briefing'
|
|
1714
|
-
? { meeting_caller_name: '2号', reported_corpses: [] }
|
|
1715
|
-
: {},
|
|
1716
|
-
});
|
|
1717
|
-
setReady(readyView('room-1', index + 2, event.commitSeq, {
|
|
1718
|
-
phase: 'meeting', tick: index + 2,
|
|
1719
|
-
}));
|
|
1720
|
-
expect(service.prepareMonitor(true), type).toBe(1);
|
|
1721
|
-
expect(repository.mailboxItemForEvent(
|
|
1722
|
-
'local-agent', event.eventId, 'short',
|
|
1723
|
-
), type).not.toBeNull();
|
|
1724
|
-
const claim = broker.handle({
|
|
1725
|
-
type: 'mailbox_claim', relay_id: 'relay-protected-events', mode: 'short',
|
|
1726
|
-
});
|
|
1727
|
-
expect(claim?.claim?.items, type).toHaveLength(1);
|
|
1728
|
-
broker.handle({
|
|
1729
|
-
type: 'mailbox_ack',
|
|
1730
|
-
relay_id: 'relay-protected-events',
|
|
1731
|
-
mode: 'short',
|
|
1732
|
-
claim_token: claim?.claim?.claim_token,
|
|
1733
|
-
});
|
|
1734
|
-
expect(repository.delivery(event.eventId, 'local-agent')?.monitorState, type)
|
|
1735
|
-
.toBe('notified');
|
|
1736
|
-
}
|
|
1737
|
-
});
|
|
1738
|
-
|
|
1739
|
-
it('keeps speech_your_turn direct when the ordinary queue is full', async () => {
|
|
1740
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1741
|
-
monitorPendingItemLimit: 2,
|
|
1742
|
-
});
|
|
1743
|
-
const baseline: CanonicalEvent[] = [];
|
|
1744
|
-
for (let index = 0; index < 2; index += 1) {
|
|
1745
|
-
baseline.push(await publish(ingress, {
|
|
1746
|
-
eventId: `monitor-priority-baseline-${index}`,
|
|
1747
|
-
type: 'speech',
|
|
1748
|
-
segmentId: 'room-1',
|
|
1749
|
-
epochSeq: 1,
|
|
1750
|
-
payload: { actor_name: `${index + 1}号`, text: `baseline-${index}` },
|
|
1751
|
-
}));
|
|
1752
|
-
}
|
|
1753
|
-
setReady(readyView('room-1', 1, baseline.at(-1)!.commitSeq, {
|
|
1754
|
-
phase: 'meeting', tick: 1,
|
|
1755
|
-
}));
|
|
1756
|
-
expect(service.prepareMonitor(true)).toBe(2);
|
|
1757
|
-
|
|
1758
|
-
const visual = await publish(ingress, {
|
|
1759
|
-
eventId: 'monitor-priority-visual',
|
|
1760
|
-
type: 'visual.player_moved',
|
|
1761
|
-
producer: 'local_synth',
|
|
1762
|
-
segmentId: 'room-1',
|
|
1763
|
-
epochSeq: 2,
|
|
1764
|
-
payload: { player_seat: 2, text: '2号移动了。' },
|
|
1765
|
-
});
|
|
1766
|
-
const yourTurn = await publish(ingress, {
|
|
1767
|
-
eventId: 'monitor-priority-your-turn',
|
|
1768
|
-
type: 'speech_your_turn',
|
|
1769
|
-
segmentId: 'room-1',
|
|
1770
|
-
epochSeq: 2,
|
|
1771
|
-
payload: { actor_name: 'self', remaining_secs: 45 },
|
|
1772
|
-
});
|
|
1773
|
-
setReady(readyView('room-1', 2, yourTurn.commitSeq, {
|
|
1774
|
-
phase: 'meeting', tick: 2,
|
|
1775
|
-
}));
|
|
1776
|
-
|
|
1777
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1778
|
-
expect(repository.delivery(yourTurn.eventId, 'local-agent')?.monitorState)
|
|
1779
|
-
.toBe('pending');
|
|
1780
|
-
const yourTurnItem = repository.mailboxItemForEvent<Record<string, unknown>>(
|
|
1781
|
-
'local-agent',
|
|
1782
|
-
yourTurn.eventId,
|
|
1783
|
-
'short',
|
|
1784
|
-
);
|
|
1785
|
-
expect(yourTurnItem).not.toBeNull();
|
|
1786
|
-
expect(yourTurnItem?.payload).toMatchObject({
|
|
1787
|
-
event: { type: 'speech_your_turn' },
|
|
1788
|
-
backlog: { remaining_events: 1, command: 'ccl events' },
|
|
1789
|
-
});
|
|
1790
|
-
expect(repository.delivery(visual.eventId, 'local-agent')?.monitorState)
|
|
1791
|
-
.toBe('suppressed');
|
|
1792
|
-
expect(repository.peekMailbox({
|
|
1793
|
-
consumerId: 'local-agent',
|
|
1794
|
-
sessionId: 'session-1',
|
|
1795
|
-
modes: ['short'],
|
|
1796
|
-
states: ['pending', 'claimed'],
|
|
1797
|
-
order: 'asc',
|
|
1798
|
-
})).toHaveLength(3);
|
|
1799
|
-
|
|
1800
|
-
const details = service.prepareEvents();
|
|
1801
|
-
expect(details.output.events).toEqual(['visual.player_moved | 2号移动了。']);
|
|
1802
|
-
expect(service.ackEvents(details.deliveryToken!)).toBe(true);
|
|
1803
|
-
});
|
|
1804
|
-
|
|
1805
|
-
it('delegates an ordinary visual Event before a nonvisual short fact', async () => {
|
|
1806
|
-
const { repository, ingress, service, setReady } = fixture({
|
|
1807
|
-
monitorPendingItemLimit: 1,
|
|
1808
|
-
});
|
|
1809
|
-
const speech = await publish(ingress, {
|
|
1810
|
-
eventId: 'monitor-retention-speech',
|
|
1811
|
-
type: 'speech',
|
|
1812
|
-
segmentId: 'room-1',
|
|
1813
|
-
epochSeq: 1,
|
|
1814
|
-
payload: { actor_name: '2号', text: '保留这条短事实。' },
|
|
1815
|
-
});
|
|
1816
|
-
const visual = await publish(ingress, {
|
|
1817
|
-
eventId: 'monitor-retention-visual',
|
|
1818
|
-
type: 'visual.player_moved',
|
|
1819
|
-
producer: 'local_synth',
|
|
1820
|
-
segmentId: 'room-1',
|
|
1821
|
-
epochSeq: 1,
|
|
1822
|
-
payload: { player_seat: 3, text: '3号移动了。' },
|
|
1823
|
-
});
|
|
1824
|
-
setReady(readyView('room-1', 1, visual.commitSeq, {
|
|
1825
|
-
phase: 'meeting', tick: 1,
|
|
1826
|
-
}));
|
|
1827
|
-
|
|
1828
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1829
|
-
expect(repository.delivery(speech.eventId, 'local-agent')?.monitorState)
|
|
1830
|
-
.toBe('pending');
|
|
1831
|
-
expect(repository.delivery(visual.eventId, 'local-agent')?.monitorState)
|
|
1832
|
-
.toBe('suppressed');
|
|
1833
|
-
});
|
|
1834
|
-
|
|
1835
|
-
it('keeps exact training mode while applying room-family terminal guidance', async () => {
|
|
1836
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
1837
|
-
const event = await publish(ingress, {
|
|
1838
|
-
eventId: 'room-game-over',
|
|
1839
|
-
type: 'game_over',
|
|
1840
|
-
segmentId: 'room-1',
|
|
1841
|
-
epochSeq: 1,
|
|
1842
|
-
payload: { game_mode: 'training_dummy', winner: 'lobster', reason: 'tasks' },
|
|
1843
|
-
});
|
|
1844
|
-
setReady(readyView('room-1', 1, event.commitSeq, {
|
|
1845
|
-
phase: 'game_over',
|
|
1846
|
-
game_mode: 'training_dummy',
|
|
1847
|
-
}));
|
|
1848
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1849
|
-
|
|
1850
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1851
|
-
const claim = broker.handle({
|
|
1852
|
-
type: 'mailbox_claim',
|
|
1853
|
-
relay_id: 'relay-room-game-over',
|
|
1854
|
-
mode: 'short',
|
|
1855
|
-
});
|
|
1856
|
-
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
1857
|
-
const output = service.composeMonitor(payloads);
|
|
1858
|
-
|
|
1859
|
-
expect(output).toMatchObject({
|
|
1860
|
-
events: ['game_over'],
|
|
1861
|
-
game_mode: 'training_dummy',
|
|
1862
|
-
messages: [expect.stringContaining('Review the result with the user')],
|
|
1863
|
-
});
|
|
1864
|
-
expect((output.messages as string[])[0]).toContain('wait for the room lifecycle to resume');
|
|
1865
|
-
expect((output.messages as string[])[0]).toContain('do not start normal matchmaking');
|
|
1866
|
-
expect(output).not.toHaveProperty('next_step');
|
|
1867
|
-
expect(output).not.toHaveProperty('guidance');
|
|
1868
|
-
expect(output).not.toHaveProperty('notice');
|
|
1869
|
-
});
|
|
1870
|
-
|
|
1871
|
-
it('projects an unsent old-segment Event after switching within one session', async () => {
|
|
1872
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
1873
|
-
const event = await publish(ingress, {
|
|
1874
|
-
eventId: 'room-before-game',
|
|
1875
|
-
type: 'meeting_briefing',
|
|
1876
|
-
segmentId: 'room-1',
|
|
1877
|
-
epochSeq: 1,
|
|
1878
|
-
payload: { actor_name: '2', text: 'start' },
|
|
1879
|
-
});
|
|
1880
|
-
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'room_waiting' }));
|
|
1881
|
-
|
|
1882
|
-
repository.saveSegment({
|
|
1883
|
-
segmentId: 'game-1',
|
|
1884
|
-
sessionId: 'session-1',
|
|
1885
|
-
sequence: 2,
|
|
1886
|
-
kind: 'game',
|
|
1887
|
-
status: 'open',
|
|
1888
|
-
isCurrent: true,
|
|
1889
|
-
openedAt: '2026-07-22T00:00:01.000Z',
|
|
1890
|
-
});
|
|
1891
|
-
setReady(readyView('game-1', 2, event.commitSeq, { phase: 'loading', tick: 0 }));
|
|
1892
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
1893
|
-
|
|
1894
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1895
|
-
const claim = broker.handle({
|
|
1896
|
-
type: 'mailbox_claim',
|
|
1897
|
-
relay_id: 'relay-after-switch',
|
|
1898
|
-
mode: 'short',
|
|
1899
|
-
});
|
|
1900
|
-
expect(claim).toMatchObject({
|
|
1901
|
-
scope: { session_id: 'session-1', segment_id: 'room-1' },
|
|
1902
|
-
claim: { items: [{ event_id: event.eventId }] },
|
|
1903
|
-
});
|
|
1904
|
-
broker.handle({
|
|
1905
|
-
type: 'mailbox_ack',
|
|
1906
|
-
relay_id: 'relay-after-switch',
|
|
1907
|
-
mode: 'short',
|
|
1908
|
-
claim_token: claim?.claim?.claim_token,
|
|
1909
|
-
});
|
|
1910
|
-
expect(repository.delivery(event.eventId, 'local-agent')).toMatchObject({
|
|
1911
|
-
monitorState: 'notified',
|
|
1912
|
-
detailState: 'deferred',
|
|
1913
|
-
});
|
|
1914
|
-
|
|
1915
|
-
const prepared = service.prepareEvents();
|
|
1916
|
-
expect((prepared.output.events as Array<Record<string, unknown>>)
|
|
1917
|
-
.map((item) => item.text)).toEqual([event.payload.text]);
|
|
1918
|
-
});
|
|
1919
|
-
|
|
1920
|
-
it('emits decision Events immediately in one same-watermark batch', async () => {
|
|
1921
|
-
const { repository, ingress, service, setReady, setNow } = fixture();
|
|
1922
|
-
const start = Date.parse('2026-07-22T00:00:00.000Z');
|
|
1923
|
-
const kill = await publish(ingress, {
|
|
1924
|
-
eventId: 'kill-1',
|
|
1925
|
-
type: 'kill',
|
|
1926
|
-
segmentId: 'room-1',
|
|
1927
|
-
epochSeq: 1,
|
|
1928
|
-
payload: { killer_name: '2号', target_name: '3号' },
|
|
1929
|
-
});
|
|
1930
|
-
const speech = await publish(ingress, {
|
|
1931
|
-
eventId: 'speech-1',
|
|
1932
|
-
type: 'speech',
|
|
1933
|
-
segmentId: 'room-1',
|
|
1934
|
-
epochSeq: 1,
|
|
1935
|
-
payload: { actor_name: '4号', text: '看到了' },
|
|
1936
|
-
});
|
|
1937
|
-
setReady(readyView('room-1', 1, speech.commitSeq, {
|
|
1938
|
-
phase: 'wandering',
|
|
1939
|
-
tick: 10,
|
|
1940
|
-
you: { name: 'self', alive: true },
|
|
1941
|
-
}));
|
|
1942
|
-
|
|
1943
|
-
setNow(start);
|
|
1944
|
-
expect(service.prepareMonitor()).toBe(2);
|
|
1945
|
-
|
|
1946
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1947
|
-
const claim = broker.handle({
|
|
1948
|
-
type: 'mailbox_claim',
|
|
1949
|
-
relay_id: 'relay-1',
|
|
1950
|
-
mode: 'short',
|
|
1951
|
-
lease_ttl_ms: 10_000,
|
|
1952
|
-
});
|
|
1953
|
-
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
1954
|
-
expect(service.composeMonitor(payloads)).toMatchObject({
|
|
1955
|
-
events: ['kill', 'speech'],
|
|
1956
|
-
messages: expect.arrayContaining([expect.stringContaining('4号')]),
|
|
1957
|
-
});
|
|
1958
|
-
expect(service.composeMonitor(payloads)).not.toHaveProperty('state');
|
|
1959
|
-
const ack = broker.handle({
|
|
1960
|
-
type: 'mailbox_ack',
|
|
1961
|
-
relay_id: 'relay-1',
|
|
1962
|
-
mode: 'short',
|
|
1963
|
-
claim_token: claim?.claim?.claim_token,
|
|
1964
|
-
});
|
|
1965
|
-
expect(ack).toMatchObject({ ok: true, result: { status: 'accepted' } });
|
|
1966
|
-
expect(repository.delivery(kill.eventId, 'local-agent')).toMatchObject({
|
|
1967
|
-
monitorState: 'notified',
|
|
1968
|
-
detailState: 'pending',
|
|
1969
|
-
});
|
|
1970
|
-
});
|
|
1971
|
-
|
|
1972
|
-
it('does not expand Behavior status in the short Monitor notification', async () => {
|
|
1973
|
-
const { repository, ingress, service, setReady } = fixture();
|
|
1974
|
-
const event = await publish(ingress, {
|
|
1975
|
-
eventId: 'behavior-monitor-hidden',
|
|
1976
|
-
type: 'speech',
|
|
1977
|
-
segmentId: 'room-1',
|
|
1978
|
-
epochSeq: 1,
|
|
1979
|
-
payload: { actor_name: '2', text: 'hello' },
|
|
1980
|
-
});
|
|
1981
|
-
setReady(readyView('room-1', 1, event.commitSeq, {
|
|
1982
|
-
phase: 'wandering',
|
|
1983
|
-
tick: 10,
|
|
1984
|
-
}, {
|
|
1985
|
-
'behavior.status': {
|
|
1986
|
-
pluginId: 'clawclaw.behavior',
|
|
1987
|
-
topic: 'behavior.status',
|
|
1988
|
-
value: {
|
|
1989
|
-
running: true,
|
|
1990
|
-
activation_id: 'long-1',
|
|
1991
|
-
behavior: 'task-only',
|
|
1992
|
-
layer: 'long',
|
|
1993
|
-
status: { summary: 'SECRET LONG BEHAVIOR STATUS' },
|
|
1994
|
-
},
|
|
1995
|
-
updatedEpochSeq: 1,
|
|
1996
|
-
updatedDomainTick: 10,
|
|
1997
|
-
},
|
|
1998
|
-
}));
|
|
1999
|
-
|
|
2000
|
-
expect(service.prepareMonitor(true)).toBe(1);
|
|
2001
|
-
const broker = new MailboxRelayBroker(repository, 'short');
|
|
2002
|
-
const claim = broker.handle({
|
|
2003
|
-
type: 'mailbox_claim',
|
|
2004
|
-
relay_id: 'relay-behavior-hidden',
|
|
2005
|
-
mode: 'short',
|
|
2006
|
-
});
|
|
2007
|
-
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
2008
|
-
const output = service.composeMonitor(payloads);
|
|
2009
|
-
expect(JSON.stringify(output)).not.toContain('SECRET LONG BEHAVIOR STATUS');
|
|
2010
|
-
expect(output).not.toHaveProperty('behavior');
|
|
2011
|
-
});
|
|
2012
|
-
});
|