@myclaw163/clawclaw-cli 0.7.16 → 0.8.1
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/QUICKSTART_HERMES.md +1 -1
- package/QUICKSTART_OPENCLAW.md +3 -11
- package/QUICKSTART_OTHER.md +8 -8
- package/README.md +18 -9
- package/bin/clawclaw-channel.mjs +13 -0
- package/docs/configuration.md +86 -33
- package/docs/custom-modules/README.md +148 -0
- package/docs/custom-modules/api-reference.md +767 -0
- package/docs/custom-modules/behavior.md +318 -0
- package/docs/custom-modules/perception.md +305 -0
- package/docs/custom-modules/trigger.md +292 -0
- package/docs/desktop-event-push.md +6 -4
- package/docs/runtime/README.md +28 -10
- package/docs/runtime/agent-notifications.md +48 -29
- package/docs/runtime/behavior-runtime.md +139 -0
- package/docs/runtime/components-and-boundaries.md +89 -173
- package/docs/runtime/events-and-state.md +55 -66
- package/docs/runtime/official-perception-modules.md +17 -9
- package/docs/runtime/owner-lifecycle-and-observability.md +62 -39
- package/docs/runtime/perception-replay.md +6 -6
- package/docs/runtime/short-commands-and-capabilities.md +35 -37
- package/package.json +7 -4
- package/scripts/check-skill-command-surface.mjs +54 -10
- package/scripts/compare-perception-replays.test.ts +10 -10
- package/scripts/compare-perception-replays.ts +14 -10
- package/scripts/replay-perception.ts +3 -3
- package/scripts/watch-perception-events.test.ts +1 -1
- package/skills/clawclaw/SKILL.md +97 -59
- package/skills/clawclaw/references/BEHAVIORS.md +154 -0
- package/skills/clawclaw/references/CHANNELS.md +115 -0
- package/skills/clawclaw/references/CHATTERBOX.md +3 -2
- package/skills/clawclaw/references/COMMANDS.md +108 -58
- package/skills/clawclaw/references/GAME-MECHANICS.md +4 -3
- package/skills/clawclaw/references/HUB.md +27 -23
- package/skills/clawclaw/references/STREAM.md +18 -14
- package/skills/clawclaw/references/TACTICS.md +2 -2
- package/src/behaviors/official-finite/do-task.ts +141 -0
- package/src/behaviors/official-finite/evade.ts +78 -0
- package/src/behaviors/official-finite/find-player.ts +50 -0
- package/src/behaviors/official-finite/follow-player.ts +70 -0
- package/src/behaviors/official-finite/go-to.ts +69 -0
- package/src/behaviors/official-finite/hide-temporarily.ts +77 -0
- package/src/behaviors/official-finite/hold-position.ts +48 -0
- package/src/behaviors/official-finite/hunt-player.ts +47 -0
- package/src/behaviors/official-finite/index.test.ts +202 -0
- package/src/behaviors/official-finite/index.ts +47 -0
- package/src/behaviors/official-finite/inspect-corpse.ts +64 -0
- package/src/behaviors/official-finite/patrol-area.ts +80 -0
- package/src/behaviors/official-finite/report-corpse.ts +73 -0
- package/src/behaviors/official-finite/seek-kill-opportunity.ts +152 -0
- package/src/behaviors/official-finite/shared.ts +27 -0
- package/src/behaviors/official-finite/trigger-alarm.ts +53 -0
- package/src/channel/claude-channel-ipc-server.ts +295 -0
- package/src/channel/claude-channel-ipc.ts +152 -0
- package/src/channel/claude-channel-server.test.ts +202 -0
- package/src/channel/claude-channel-server.ts +221 -0
- package/src/cli.ts +4 -2
- package/src/commands/account.test.ts +17 -17
- package/src/commands/behavior.test.ts +158 -0
- package/src/commands/behavior.ts +443 -0
- package/src/commands/communication.test.ts +12 -0
- package/src/commands/communication.ts +6 -3
- package/src/commands/data.test.ts +1 -1
- package/src/commands/data.ts +1 -1
- package/src/commands/events-canonical-state.test.ts +221 -2
- package/src/commands/events.ts +205 -12
- package/src/commands/game/index.test.ts +172 -3
- package/src/commands/game/index.ts +69 -32
- package/src/commands/hub.test.ts +25 -14
- package/src/commands/hub.ts +15 -19
- package/src/commands/load.test.ts +228 -6
- package/src/commands/load.ts +102 -18
- package/src/commands/memory.ts +1 -1
- package/src/commands/peek.ts +1 -1
- package/src/commands/perception.test.ts +30 -1
- package/src/commands/perception.ts +15 -17
- package/src/commands/trigger.test.ts +140 -0
- package/src/commands/trigger.ts +314 -0
- package/src/lib/account-guidance.test.ts +4 -0
- package/src/lib/account-guidance.ts +1 -1
- package/src/lib/behavior-export.test.ts +282 -0
- package/src/lib/behavior-export.ts +514 -0
- package/src/lib/game-client.test.ts +4 -17
- package/src/lib/game-client.ts +1 -0
- package/src/lib/gameplay-config.test.ts +258 -37
- package/src/lib/gameplay-config.ts +175 -35
- package/src/lib/hub-install.test.ts +19 -41
- package/src/lib/hub-install.ts +10 -38
- package/src/lib/hub-reminder.ts +7 -9
- package/src/lib/init-command.ts +1 -1
- package/src/lib/official-resource-sync.test.ts +199 -0
- package/src/lib/official-resource-sync.ts +221 -0
- package/src/lib/perception-config.test.ts +9 -4
- package/src/lib/perception-config.ts +10 -13
- package/src/lib/perception-export.test.ts +145 -0
- package/src/lib/perception-export.ts +178 -0
- package/src/lib/trigger-config.test.ts +102 -0
- package/src/lib/trigger-config.ts +217 -0
- package/src/lib/user-data.test.ts +23 -6
- package/src/lib/user-data.ts +15 -123
- package/src/pipeline/canonical-event-presentation.test.ts +5 -5
- package/src/pipeline/canonical-event-presentation.ts +13 -5
- package/src/pipeline/event-format.test.ts +106 -3
- package/src/pipeline/event-format.ts +172 -4
- package/src/pipeline/event-hints.test.ts +57 -4
- package/src/pipeline/event-hints.ts +34 -8
- package/src/runtime/canonical-monitor.test.ts +2 -0
- package/src/runtime/canonical-monitor.ts +6 -2
- package/src/runtime/clawclaw/agent-event-policy.test.ts +23 -2
- package/src/runtime/clawclaw/agent-event-policy.ts +12 -5
- package/src/runtime/clawclaw/behavior-decision.test.ts +29 -0
- package/src/runtime/clawclaw/behavior-decision.ts +82 -0
- package/src/runtime/clawclaw/behavior-input-fields.test.ts +175 -0
- package/src/runtime/clawclaw/behavior-input-fields.ts +270 -0
- package/src/runtime/clawclaw/behavior-input.test.ts +151 -0
- package/src/runtime/clawclaw/behavior-input.ts +70 -0
- package/src/runtime/clawclaw/behavior-observation-memory.test.ts +59 -0
- package/src/runtime/clawclaw/behavior-observation-memory.ts +142 -0
- package/src/runtime/clawclaw/behavior-read-api.test.ts +123 -0
- package/src/runtime/clawclaw/behavior-read-api.ts +158 -0
- package/src/runtime/clawclaw/{plugins/perception/visual-state-projector.ts → observation-frame-projector.ts} +44 -25
- package/src/runtime/clawclaw/owner.test.ts +187 -0
- package/src/runtime/clawclaw/owner.ts +431 -69
- package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +304 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +285 -41
- package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +82 -0
- package/src/runtime/clawclaw/plugins/assembly.test.ts +135 -29
- package/src/runtime/clawclaw/plugins/assembly.ts +54 -28
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +180 -0
- package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +468 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +40 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-action.ts +30 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +152 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +156 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +104 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-manifest.ts +173 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +182 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.ts +223 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +157 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +848 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +1347 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +212 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +174 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +621 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +195 -0
- package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +180 -0
- package/src/runtime/clawclaw/plugins/behavior/index.ts +11 -0
- package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +766 -0
- package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +283 -0
- package/src/runtime/clawclaw/plugins/{strategy/thread-strategy-executor.ts → behavior/thread-behavior-executor.ts} +109 -121
- package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +80 -0
- package/src/runtime/clawclaw/plugins/behavior-input-source.ts +247 -0
- package/src/runtime/clawclaw/plugins/{strategy → game-query}/context-capabilities.ts +1 -1
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +13 -10
- package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +26 -14
- package/src/runtime/clawclaw/plugins/game-query/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/index.ts +3 -1
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +239 -0
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +100 -0
- package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +346 -0
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +230 -12
- package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +118 -90
- package/src/runtime/clawclaw/plugins/mailbox/consumer-ids.ts +5 -0
- package/src/runtime/clawclaw/plugins/mailbox/index.ts +3 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +1 -1
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +4 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +87 -0
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +70 -12
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +94 -11
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +1229 -345
- package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +479 -35
- package/src/runtime/clawclaw/plugins/perception/contracts.ts +4 -3
- package/src/runtime/clawclaw/plugins/perception/index.ts +1 -1
- package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +23 -13
- package/src/runtime/clawclaw/plugins/perception/module-runner.ts +11 -9
- package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +39 -38
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +92 -0
- package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +248 -0
- package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +39 -37
- package/src/runtime/clawclaw/plugins/perception/modules/index.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +22 -21
- package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +15 -9
- package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +3 -3
- package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +33 -18
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +6 -7
- package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +22 -16
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +6 -7
- package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +18 -12
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +14 -10
- package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +20 -14
- package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +5 -6
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +5 -6
- package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +49 -34
- package/src/runtime/clawclaw/plugins/perception/official-module-ids.ts +1 -0
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +126 -20
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +24 -3
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-worker.ts +59 -46
- package/src/runtime/clawclaw/plugins/perception/perception-module-loader.ts +27 -5
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +381 -49
- package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +267 -245
- package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +98 -0
- package/src/runtime/clawclaw/plugins/perception/perception-source.ts +89 -16
- package/src/runtime/clawclaw/plugins/perception/perception-test-fixtures.ts +34 -0
- package/src/runtime/clawclaw/plugins/perception/replay.test.ts +27 -15
- package/src/runtime/clawclaw/plugins/perception/replay.ts +10 -5
- package/src/runtime/clawclaw/plugins/perception/shared/math.ts +1 -107
- package/src/runtime/clawclaw/plugins/perception/spatial-facts.ts +7 -10
- package/src/runtime/clawclaw/plugins/plugin-api-version.ts +112 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +388 -559
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +56 -5
- package/src/runtime/clawclaw/plugins/source/player-change-tracker.ts +135 -26
- package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +249 -16
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +99 -2
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +212 -0
- package/src/runtime/clawclaw/plugins/source/task-change-tracker.ts +259 -0
- package/src/runtime/clawclaw/plugins/trigger/contracts.ts +97 -0
- package/src/runtime/clawclaw/plugins/trigger/index.ts +4 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +118 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +548 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +655 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +169 -0
- package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +457 -0
- package/src/runtime/clawclaw/runtime.ts +8 -0
- package/src/runtime/clawclaw/spatial-api.ts +76 -0
- package/src/runtime/clawclaw-event-catalog.test.ts +46 -1
- package/src/runtime/clawclaw-event-catalog.ts +40 -3
- package/src/runtime/framework/capability-registry.test.ts +196 -55
- package/src/runtime/framework/capability-registry.ts +99 -17
- package/src/runtime/framework/contracts.ts +30 -4
- package/src/runtime/framework/control/control-scheduler.ts +13 -5
- package/src/runtime/framework/control/types.ts +11 -4
- package/src/runtime/framework/control-coordinator.test.ts +95 -80
- package/src/runtime/framework/events/event-delivery-service.ts +4 -2
- package/src/runtime/framework/events/event-ingress.test.ts +25 -0
- package/src/runtime/framework/events/event-ingress.ts +2 -1
- package/src/runtime/framework/events/event-repository.ts +24 -2
- package/src/runtime/framework/events/mailbox-event-repositories.test.ts +124 -8
- package/src/runtime/framework/events/memory-event-repository.ts +92 -28
- package/src/runtime/framework/events/sqlite-event-repository.test.ts +604 -2
- package/src/runtime/framework/events/sqlite-event-repository.ts +531 -21
- package/src/runtime/framework/events/types.ts +24 -8
- package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +38 -1
- package/src/runtime/framework/modules/runtime-module-loader.test.ts +233 -7
- package/src/runtime/framework/modules/runtime-module-loader.ts +69 -4
- package/src/runtime/framework/plugins/contracts.ts +12 -18
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +81 -71
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +38 -20
- package/src/runtime/framework/runtime.ts +20 -23
- package/src/runtime/host-monitor-rate-gate.test.ts +73 -0
- package/src/runtime/host-monitor-rate-gate.ts +123 -0
- package/src/runtime/mailbox-host-relay.test.ts +45 -0
- package/src/runtime/mailbox-host-relay.ts +25 -0
- package/src/runtime/observability/factory.ts +4 -4
- package/src/runtime/observability/observability.test.ts +25 -3
- package/src/runtime/observability/reporter.ts +1 -1
- package/src/runtime/observability/types.ts +2 -2
- package/src/runtime/owner-control.ts +10 -2
- package/src/runtime/runtime-logger.test.ts +1 -1
- package/src/runtime/runtime-logger.ts +4 -6
- package/src/runtime/runtime.test.ts +88 -22
- package/src/sdk/action.ts +2 -2
- package/src/sdk/behavior-plugin/index.test.ts +74 -0
- package/src/sdk/behavior-plugin/index.ts +335 -0
- package/src/sdk/behavior-toolkit/corpse-search.ts +87 -0
- package/src/sdk/behavior-toolkit/escape.ts +40 -0
- package/src/sdk/behavior-toolkit/index.ts +7 -0
- package/src/sdk/behavior-toolkit/kill-flow.ts +299 -0
- package/src/sdk/behavior-toolkit/model.ts +263 -0
- package/src/sdk/behavior-toolkit/move-gate.ts +52 -0
- package/src/sdk/behavior-toolkit/patrol.ts +53 -0
- package/src/sdk/behavior-toolkit/search.ts +102 -0
- package/src/sdk/index.test.ts +45 -0
- package/src/sdk/index.ts +67 -73
- package/src/sdk/module-input/index.test.ts +49 -0
- package/src/sdk/module-input/index.ts +229 -0
- package/src/sdk/perception-plugin/index.test.ts +2 -2
- package/src/sdk/perception-plugin/index.ts +51 -142
- package/src/sdk/perception-plugin/math.ts +107 -0
- package/src/sdk/trigger-plugin/index.test.ts +41 -0
- package/src/sdk/trigger-plugin/index.ts +128 -0
- package/src/strategies/avoid-lone.ts +21 -10
- package/src/strategies/avoid-players.ts +26 -16
- package/src/strategies/corpse-patrol.ts +25 -14
- package/src/strategies/crab-sabotage.ts +20 -9
- package/src/strategies/find-player.ts +33 -21
- package/src/strategies/game-utils.ts +1 -1
- package/src/strategies/goals/crab-sabotage-top.test.ts +145 -0
- package/src/strategies/goals/crab-sabotage-top.ts +32 -69
- package/src/strategies/hide.ts +25 -15
- package/src/strategies/kill-frenzy.ts +21 -10
- package/src/strategies/kill-lone.ts +27 -17
- package/src/strategies/kill-target.ts +33 -22
- package/src/strategies/lone-kill-task.ts +20 -9
- package/src/strategies/move-room.ts +29 -18
- package/src/strategies/official-long-behavior.test.ts +89 -0
- package/src/strategies/paradise-fish.ts +29 -18
- package/src/strategies/pathfind/astar-path.test.ts +127 -2
- package/src/strategies/pathfind/astar-path.ts +136 -26
- package/src/strategies/patrol.ts +21 -10
- package/src/strategies/player-targets.test.ts +10 -0
- package/src/strategies/player-targets.ts +13 -0
- package/src/strategies/report-patrol.ts +21 -10
- package/src/strategies/shrimp-memory.ts +30 -19
- package/src/strategies/social-task.ts +34 -23
- package/src/strategies/task-kill-report.ts +33 -22
- package/src/strategies/task-only.test.ts +99 -85
- package/src/strategies/task-only.ts +23 -12
- package/src/strategies/task-report.ts +25 -14
- package/src/strategies/types.ts +8 -8
- package/src/strategies/warrior-memory.ts +29 -19
- package/docs/runtime/strategy-runtime.md +0 -111
- package/docs//350/207/252/345/256/232/344/271/211/346/204/237/347/237/245.md +0 -502
- package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +0 -395
- package/skills/clawclaw/references/STRATEGIES.md +0 -76
- package/src/commands/strategy.test.ts +0 -209
- package/src/commands/strategy.ts +0 -242
- package/src/lib/strategy-export.test.ts +0 -406
- package/src/lib/strategy-export.ts +0 -381
- package/src/runtime/clawclaw/plugins/perception/official-modules.ts +0 -31
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.test.ts +0 -177
- package/src/runtime/clawclaw/plugins/strategy/examples/task-only-strategy.ts +0 -191
- package/src/runtime/clawclaw/plugins/strategy/index.ts +0 -8
- package/src/runtime/clawclaw/plugins/strategy/local-strategy-executor.ts +0 -412
- package/src/runtime/clawclaw/plugins/strategy/strategy-action.ts +0 -80
- package/src/runtime/clawclaw/plugins/strategy/strategy-analysis-thread-host.ts +0 -183
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor-types.ts +0 -29
- package/src/runtime/clawclaw/plugins/strategy/strategy-executor.test.ts +0 -693
- package/src/runtime/clawclaw/plugins/strategy/strategy-game-api.ts +0 -57
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +0 -168
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +0 -2175
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +0 -1774
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.test.ts +0 -153
- package/src/runtime/clawclaw/plugins/strategy/strategy-source.ts +0 -443
- package/src/sdk/strategy-plugin/index.test.ts +0 -958
- package/src/sdk/strategy-plugin/index.ts +0 -1350
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
MemoryEventRepository,
|
|
6
6
|
type CanonicalEvent,
|
|
7
7
|
} from '../../../framework/events/index.js';
|
|
8
|
+
import type { RuntimeDiagnosticSeverity } from '../../../framework/plugins/contracts.js';
|
|
8
9
|
import type { RuntimeReadyView } from '../../../framework/runtime.js';
|
|
9
10
|
import { MailboxRelayBroker } from '../../../mailbox-host-relay.js';
|
|
10
11
|
import { ClawclawMailboxService } from './mailbox-service.js';
|
|
@@ -15,7 +16,20 @@ function expectCompactEventsOutput(output: Record<string, unknown>): void {
|
|
|
15
16
|
for (const field of INTERNAL_EVENTS_FIELDS) expect(output).not.toHaveProperty(field);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
function fixture(
|
|
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
|
+
} = {}) {
|
|
19
33
|
const repository = new MemoryEventRepository();
|
|
20
34
|
repository.saveSession({
|
|
21
35
|
sessionId: 'session-1',
|
|
@@ -41,6 +55,7 @@ function fixture() {
|
|
|
41
55
|
repository,
|
|
42
56
|
readyView: () => structuredClone(ready),
|
|
43
57
|
now: () => nowMs,
|
|
58
|
+
...options,
|
|
44
59
|
});
|
|
45
60
|
return {
|
|
46
61
|
repository,
|
|
@@ -178,15 +193,15 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
178
193
|
});
|
|
179
194
|
setReady(readyView('room-1', 1, ready.commitSeq, { phase: 'room_waiting' }));
|
|
180
195
|
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
|
|
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>;
|
|
184
199
|
|
|
185
200
|
expect(full).not.toHaveProperty('hint');
|
|
186
201
|
expect(derived?.hint).toContain('you are the owner');
|
|
187
202
|
});
|
|
188
203
|
|
|
189
|
-
it('
|
|
204
|
+
it('keeps Monitor-complete Events out of the detail batch across segments', async () => {
|
|
190
205
|
const { repository, ingress, service, setReady } = fixture();
|
|
191
206
|
const roomEvent = await publish(ingress, {
|
|
192
207
|
eventId: 'room-chat',
|
|
@@ -220,7 +235,7 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
220
235
|
const prepared = service.prepareEvents();
|
|
221
236
|
expect(prepared.deliveryToken).toBeTypeOf('string');
|
|
222
237
|
expect((prepared.output.events as Array<Record<string, unknown>>).map((event) => event.type))
|
|
223
|
-
.toEqual(['role_assigned'
|
|
238
|
+
.toEqual(['role_assigned']);
|
|
224
239
|
expect(prepared.output).toMatchObject({
|
|
225
240
|
state: { phase: 'wandering', tick: 7 },
|
|
226
241
|
});
|
|
@@ -229,7 +244,7 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
229
244
|
expect(repository.delivery(gameEvent.eventId, 'local-agent')?.detailState).toBe('pending');
|
|
230
245
|
|
|
231
246
|
expect(service.ackEvents(prepared.deliveryToken!)).toBe(true);
|
|
232
|
-
expect(repository.delivery(roomEvent.eventId, 'local-agent')?.detailState).toBe('
|
|
247
|
+
expect(repository.delivery(roomEvent.eventId, 'local-agent')?.detailState).toBe('deferred');
|
|
233
248
|
expect(repository.delivery(gameEvent.eventId, 'local-agent')?.detailState).toBe('delivered');
|
|
234
249
|
const empty = service.prepareEvents().output;
|
|
235
250
|
expect(empty).toMatchObject({ events: [] });
|
|
@@ -262,14 +277,14 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
262
277
|
const { repository, ingress, service, setReady } = fixture();
|
|
263
278
|
const first = await publish(ingress, {
|
|
264
279
|
eventId: 'speech-1',
|
|
265
|
-
type: '
|
|
280
|
+
type: 'meeting_briefing',
|
|
266
281
|
segmentId: 'room-1',
|
|
267
282
|
epochSeq: 1,
|
|
268
283
|
payload: { actor_name: '2号', text: '一' },
|
|
269
284
|
});
|
|
270
285
|
const second = await publish(ingress, {
|
|
271
286
|
eventId: 'speech-2',
|
|
272
|
-
type: '
|
|
287
|
+
type: 'meeting_briefing',
|
|
273
288
|
segmentId: 'room-1',
|
|
274
289
|
epochSeq: 2,
|
|
275
290
|
payload: { actor_name: '3号', text: '二' },
|
|
@@ -296,14 +311,14 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
296
311
|
// A faster upstream plugin may commit a newer epoch before the boundary finishes.
|
|
297
312
|
await publish(ingress, {
|
|
298
313
|
eventId: 'speech-later',
|
|
299
|
-
type: '
|
|
314
|
+
type: 'meeting_briefing',
|
|
300
315
|
segmentId: 'room-1',
|
|
301
316
|
epochSeq: 2,
|
|
302
317
|
payload: { actor_name: '3', text: 'after' },
|
|
303
318
|
});
|
|
304
319
|
const first = await publish(ingress, {
|
|
305
320
|
eventId: 'speech-boundary',
|
|
306
|
-
type: '
|
|
321
|
+
type: 'meeting_briefing',
|
|
307
322
|
segmentId: 'room-1',
|
|
308
323
|
epochSeq: 1,
|
|
309
324
|
payload: { actor_name: '2', text: 'before' },
|
|
@@ -322,7 +337,7 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
322
337
|
const { ingress, service, setReady } = fixture();
|
|
323
338
|
const event = await publish(ingress, {
|
|
324
339
|
eventId: 'speech-serial',
|
|
325
|
-
type: '
|
|
340
|
+
type: 'meeting_briefing',
|
|
326
341
|
segmentId: 'room-1',
|
|
327
342
|
epochSeq: 1,
|
|
328
343
|
payload: { actor_name: '2', text: 'serial' },
|
|
@@ -391,15 +406,12 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
391
406
|
});
|
|
392
407
|
setReady(readyView('room-1', 1, eventsOnly.commitSeq, { phase: 'wandering', tick: 3 }));
|
|
393
408
|
|
|
394
|
-
expect(service.prepareMonitor(true)).toBe(
|
|
409
|
+
expect(service.prepareMonitor(true)).toBe(1);
|
|
395
410
|
const prepared = service.prepareEvents();
|
|
396
|
-
expect(prepared.output.events).toEqual([
|
|
397
|
-
'visual.player_moved | 9:41,你从导航仓左上侧移动到2号走廊右下侧。',
|
|
398
|
-
]);
|
|
411
|
+
expect(prepared.output.events).toEqual([]);
|
|
399
412
|
expect(repository.delivery(internal.eventId, 'local-agent')?.detailState)
|
|
400
413
|
.toBe('not_applicable');
|
|
401
|
-
expect(repository.delivery(eventsOnly.eventId, 'local-agent')?.monitorState)
|
|
402
|
-
.toBe('not_applicable');
|
|
414
|
+
expect(repository.delivery(eventsOnly.eventId, 'local-agent')?.monitorState).toBe('pending');
|
|
403
415
|
});
|
|
404
416
|
|
|
405
417
|
it('hides task assignment and emits player changes as detailed Events instead of State', async () => {
|
|
@@ -511,6 +523,7 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
511
523
|
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
512
524
|
expect(service.composeMonitor(payloads)).toMatchObject({
|
|
513
525
|
events: ['task_completed'],
|
|
526
|
+
details_required: ['task_completed'],
|
|
514
527
|
messages: [expect.stringContaining('任务完成:擦拭酒瓶;新分配任务:消毒淋浴器(制氧舱)')],
|
|
515
528
|
});
|
|
516
529
|
|
|
@@ -526,7 +539,7 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
526
539
|
expect(repository.delivery(completed.eventId, 'local-agent')?.detailState).not.toBe('not_applicable');
|
|
527
540
|
});
|
|
528
541
|
|
|
529
|
-
it('presents player and system
|
|
542
|
+
it('presents complete player and system killer facts through Monitor without detail reads', async () => {
|
|
530
543
|
const { repository, ingress, service, setReady } = fixture();
|
|
531
544
|
const playerKilled = await publish(ingress, {
|
|
532
545
|
eventId: 'player-killed',
|
|
@@ -575,379 +588,1248 @@ describe('ClawClaw Mailbox Event query', () => {
|
|
|
575
588
|
]));
|
|
576
589
|
expect(JSON.stringify(monitor)).not.toContain('?号Shrimp God');
|
|
577
590
|
|
|
578
|
-
|
|
579
|
-
expect(events).toEqual(expect.arrayContaining([
|
|
580
|
-
expect.objectContaining({
|
|
581
|
-
type: 'killed',
|
|
582
|
-
tick: 41,
|
|
583
|
-
killer_kind: 'player',
|
|
584
|
-
killer_name: '某蟹',
|
|
585
|
-
killer_seat: 1,
|
|
586
|
-
hint: 'YOU ARE DEAD: seat 1 某蟹 removed you from play.',
|
|
587
|
-
}),
|
|
588
|
-
expect.objectContaining({
|
|
589
|
-
type: 'killed',
|
|
590
|
-
tick: 42,
|
|
591
|
-
killer_kind: 'system',
|
|
592
|
-
killer_name: 'Shrimp God',
|
|
593
|
-
hint: 'YOU ARE DEAD: Shrimp God removed you from play.',
|
|
594
|
-
}),
|
|
595
|
-
]));
|
|
591
|
+
expect(service.prepareEvents().output.events).toEqual([]);
|
|
596
592
|
expect(repository.delivery(playerKilled.eventId, 'local-agent')?.detailState)
|
|
597
593
|
.not.toBe('not_applicable');
|
|
598
594
|
});
|
|
599
595
|
|
|
600
|
-
|
|
601
|
-
|
|
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
602
|
const event = await publish(ingress, {
|
|
603
|
-
eventId: '
|
|
603
|
+
eventId: 'dedicated-monitor-consumer',
|
|
604
604
|
type: 'speech',
|
|
605
605
|
segmentId: 'room-1',
|
|
606
|
-
epochSeq:
|
|
607
|
-
payload: { actor_name: '2', text: '
|
|
606
|
+
epochSeq: 1,
|
|
607
|
+
payload: { actor_name: '2', text: 'hello' },
|
|
608
608
|
});
|
|
609
|
-
setReady(readyView('room-1',
|
|
610
|
-
phase: 'wandering',
|
|
611
|
-
tick: 105,
|
|
612
|
-
}, {
|
|
613
|
-
'strategy.status': {
|
|
614
|
-
pluginId: 'clawclaw.strategy',
|
|
615
|
-
topic: 'strategy.status',
|
|
616
|
-
value: {
|
|
617
|
-
strategy: 'runtime-task-demo',
|
|
618
|
-
activity: 'moving',
|
|
619
|
-
summary: 'Going to engine task.',
|
|
620
|
-
room: 'engine',
|
|
621
|
-
task: 'repair',
|
|
622
|
-
parameters: { greeting: 'hello' },
|
|
623
|
-
dataAvailability: { tasks: 'available' },
|
|
624
|
-
},
|
|
625
|
-
updatedEpochSeq: 1,
|
|
626
|
-
updatedDomainTick: 100,
|
|
627
|
-
},
|
|
628
|
-
}, {
|
|
629
|
-
'clawclaw.strategy': {
|
|
630
|
-
pluginId: 'clawclaw.strategy',
|
|
631
|
-
epochSeq: 2,
|
|
632
|
-
domainTick: 105,
|
|
633
|
-
outcome: 'noop',
|
|
634
|
-
reason: 'strategy_update_interval',
|
|
635
|
-
},
|
|
636
|
-
}));
|
|
609
|
+
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'wandering', tick: 1 }));
|
|
637
610
|
|
|
638
|
-
expect(service.
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
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',
|
|
648
634
|
});
|
|
649
635
|
});
|
|
650
636
|
|
|
651
|
-
it('
|
|
652
|
-
const
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
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 }));
|
|
662
651
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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
|
+
}],
|
|
676
683
|
},
|
|
677
|
-
}
|
|
684
|
+
});
|
|
685
|
+
setReady(readyView('room-1', 1, event.commitSeq, { phase: 'meeting', tick: 644 }));
|
|
678
686
|
|
|
679
|
-
expect(
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
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
|
+
],
|
|
683
701
|
});
|
|
702
|
+
});
|
|
684
703
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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 },
|
|
692
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);
|
|
693
750
|
});
|
|
694
751
|
|
|
695
|
-
it('
|
|
696
|
-
const {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
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
|
+
});
|
|
709
825
|
|
|
710
|
-
|
|
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, {
|
|
711
847
|
phase: 'meeting',
|
|
712
|
-
tick:
|
|
713
|
-
}, status, {
|
|
714
|
-
'clawclaw.strategy': {
|
|
715
|
-
pluginId: 'clawclaw.strategy',
|
|
716
|
-
epochSeq: 2,
|
|
717
|
-
domainTick: 105,
|
|
718
|
-
outcome: 'noop',
|
|
719
|
-
reason: 'strategy_waiting_for_current_state',
|
|
720
|
-
},
|
|
848
|
+
tick: 10,
|
|
721
849
|
}));
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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,
|
|
726
890
|
});
|
|
727
891
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
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',
|
|
734
991
|
epochSeq: 3,
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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',
|
|
738
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,
|
|
739
1087
|
}));
|
|
740
|
-
expect(
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
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',
|
|
744
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);
|
|
745
1135
|
});
|
|
746
1136
|
|
|
747
|
-
it('
|
|
748
|
-
const { service, setReady } = fixture(
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
},
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
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',
|
|
766
1162
|
epochSeq: 2,
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
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}` },
|
|
785
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);
|
|
786
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);
|
|
787
1264
|
});
|
|
788
1265
|
|
|
789
|
-
it('
|
|
790
|
-
const
|
|
791
|
-
const
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
summary: '正在前往引擎室执行任务“维修引擎”。',
|
|
799
|
-
parameters: { mode: 'fast' },
|
|
800
|
-
},
|
|
801
|
-
updatedEpochSeq: 1,
|
|
802
|
-
updatedDomainTick: 100,
|
|
803
|
-
},
|
|
804
|
-
};
|
|
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'> = [];
|
|
805
1275
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
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,
|
|
821
1335
|
}));
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
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',
|
|
826
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);
|
|
827
1356
|
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
domainTick: 102,
|
|
840
|
-
outcome: 'noop',
|
|
841
|
-
reason: 'strategy_not_selected',
|
|
842
|
-
},
|
|
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,
|
|
843
1368
|
}));
|
|
844
|
-
|
|
845
|
-
expect(
|
|
846
|
-
|
|
847
|
-
|
|
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号继续移动' },
|
|
848
1384
|
});
|
|
849
|
-
|
|
850
|
-
|
|
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();
|
|
851
1392
|
});
|
|
852
1393
|
|
|
853
|
-
it('
|
|
854
|
-
const { service, setReady } = fixture(
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
'
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
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,
|
|
872
1417
|
}));
|
|
873
1418
|
|
|
874
|
-
expect(service.
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
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,
|
|
880
1464
|
});
|
|
881
|
-
|
|
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);
|
|
882
1522
|
});
|
|
883
1523
|
|
|
884
|
-
it('
|
|
885
|
-
const { service, setReady } = fixture(
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
'
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
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,
|
|
897
1538
|
}));
|
|
898
1539
|
|
|
899
|
-
expect(service.
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
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' },
|
|
903
1569
|
});
|
|
1570
|
+
expect(service.ackEvents(details.deliveryToken!)).toBe(true);
|
|
904
1571
|
});
|
|
905
|
-
});
|
|
906
1572
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
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',
|
|
913
1638
|
producer: 'local_synth',
|
|
914
1639
|
segmentId: 'room-1',
|
|
915
1640
|
epochSeq: 1,
|
|
916
|
-
payload: {
|
|
917
|
-
tick: 644,
|
|
918
|
-
meeting: true,
|
|
919
|
-
meeting_count: 1,
|
|
920
|
-
changes: [{
|
|
921
|
-
change: 'died',
|
|
922
|
-
name: '陈皮一带四#c7',
|
|
923
|
-
seat: 9,
|
|
924
|
-
cause: 'killed',
|
|
925
|
-
killer: null,
|
|
926
|
-
}],
|
|
927
|
-
players: [{
|
|
928
|
-
name: '陈皮一带四#c7',
|
|
929
|
-
seat: 9,
|
|
930
|
-
status: 'dead',
|
|
931
|
-
death: { cause: 'killed', killer: null },
|
|
932
|
-
}],
|
|
933
|
-
},
|
|
1641
|
+
payload: { player_seat: 2, text: '2号移动了。' },
|
|
934
1642
|
});
|
|
935
|
-
setReady(readyView('room-1', 1,
|
|
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
|
+
}));
|
|
936
1659
|
|
|
937
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
|
+
});
|
|
938
1678
|
const broker = new MailboxRelayBroker(repository, 'short');
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
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号移动了' },
|
|
943
1686
|
});
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
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' },
|
|
950
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');
|
|
951
1833
|
});
|
|
952
1834
|
|
|
953
1835
|
it('keeps exact training mode while applying room-family terminal guidance', async () => {
|
|
@@ -990,7 +1872,7 @@ describe('ClawClaw Mailbox Monitor', () => {
|
|
|
990
1872
|
const { repository, ingress, service, setReady } = fixture();
|
|
991
1873
|
const event = await publish(ingress, {
|
|
992
1874
|
eventId: 'room-before-game',
|
|
993
|
-
type: '
|
|
1875
|
+
type: 'meeting_briefing',
|
|
994
1876
|
segmentId: 'room-1',
|
|
995
1877
|
epochSeq: 1,
|
|
996
1878
|
payload: { actor_name: '2', text: 'start' },
|
|
@@ -1035,7 +1917,7 @@ describe('ClawClaw Mailbox Monitor', () => {
|
|
|
1035
1917
|
.map((item) => item.text)).toEqual([event.payload.text]);
|
|
1036
1918
|
});
|
|
1037
1919
|
|
|
1038
|
-
it('
|
|
1920
|
+
it('emits decision Events immediately in one same-watermark batch', async () => {
|
|
1039
1921
|
const { repository, ingress, service, setReady, setNow } = fixture();
|
|
1040
1922
|
const start = Date.parse('2026-07-22T00:00:00.000Z');
|
|
1041
1923
|
const kill = await publish(ingress, {
|
|
@@ -1059,10 +1941,6 @@ describe('ClawClaw Mailbox Monitor', () => {
|
|
|
1059
1941
|
}));
|
|
1060
1942
|
|
|
1061
1943
|
setNow(start);
|
|
1062
|
-
expect(service.prepareMonitor()).toBe(0);
|
|
1063
|
-
setNow(start + 1_999);
|
|
1064
|
-
expect(service.prepareMonitor()).toBe(0);
|
|
1065
|
-
setNow(start + 2_000);
|
|
1066
1944
|
expect(service.prepareMonitor()).toBe(2);
|
|
1067
1945
|
|
|
1068
1946
|
const broker = new MailboxRelayBroker(repository, 'short');
|
|
@@ -1075,9 +1953,9 @@ describe('ClawClaw Mailbox Monitor', () => {
|
|
|
1075
1953
|
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
1076
1954
|
expect(service.composeMonitor(payloads)).toMatchObject({
|
|
1077
1955
|
events: ['kill', 'speech'],
|
|
1078
|
-
state: expect.stringContaining('wandering'),
|
|
1079
1956
|
messages: expect.arrayContaining([expect.stringContaining('4号')]),
|
|
1080
1957
|
});
|
|
1958
|
+
expect(service.composeMonitor(payloads)).not.toHaveProperty('state');
|
|
1081
1959
|
const ack = broker.handle({
|
|
1082
1960
|
type: 'mailbox_ack',
|
|
1083
1961
|
relay_id: 'relay-1',
|
|
@@ -1091,10 +1969,10 @@ describe('ClawClaw Mailbox Monitor', () => {
|
|
|
1091
1969
|
});
|
|
1092
1970
|
});
|
|
1093
1971
|
|
|
1094
|
-
it('does not expand
|
|
1972
|
+
it('does not expand Behavior status in the short Monitor notification', async () => {
|
|
1095
1973
|
const { repository, ingress, service, setReady } = fixture();
|
|
1096
1974
|
const event = await publish(ingress, {
|
|
1097
|
-
eventId: '
|
|
1975
|
+
eventId: 'behavior-monitor-hidden',
|
|
1098
1976
|
type: 'speech',
|
|
1099
1977
|
segmentId: 'room-1',
|
|
1100
1978
|
epochSeq: 1,
|
|
@@ -1104,10 +1982,16 @@ describe('ClawClaw Mailbox Monitor', () => {
|
|
|
1104
1982
|
phase: 'wandering',
|
|
1105
1983
|
tick: 10,
|
|
1106
1984
|
}, {
|
|
1107
|
-
'
|
|
1108
|
-
pluginId: 'clawclaw.
|
|
1109
|
-
topic: '
|
|
1110
|
-
value: {
|
|
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
|
+
},
|
|
1111
1995
|
updatedEpochSeq: 1,
|
|
1112
1996
|
updatedDomainTick: 10,
|
|
1113
1997
|
},
|
|
@@ -1117,12 +2001,12 @@ describe('ClawClaw Mailbox Monitor', () => {
|
|
|
1117
2001
|
const broker = new MailboxRelayBroker(repository, 'short');
|
|
1118
2002
|
const claim = broker.handle({
|
|
1119
2003
|
type: 'mailbox_claim',
|
|
1120
|
-
relay_id: 'relay-
|
|
2004
|
+
relay_id: 'relay-behavior-hidden',
|
|
1121
2005
|
mode: 'short',
|
|
1122
2006
|
});
|
|
1123
2007
|
const payloads = claim?.claim?.items.map((item: any) => item.payload) ?? [];
|
|
1124
2008
|
const output = service.composeMonitor(payloads);
|
|
1125
|
-
expect(JSON.stringify(output)).not.toContain('SECRET LONG
|
|
1126
|
-
expect(output).not.toHaveProperty('
|
|
2009
|
+
expect(JSON.stringify(output)).not.toContain('SECRET LONG BEHAVIOR STATUS');
|
|
2010
|
+
expect(output).not.toHaveProperty('behavior');
|
|
1127
2011
|
});
|
|
1128
2012
|
});
|