@myclaw163/clawclaw-cli 0.8.3 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/README.md +4 -3
  2. package/docs/configuration.md +44 -26
  3. package/docs/custom-modules/README.md +7 -10
  4. package/docs/custom-modules/api-reference.md +3 -7
  5. package/docs/custom-modules/behavior.md +6 -4
  6. package/docs/custom-modules/perception.md +1 -1
  7. package/docs/custom-modules/trigger.md +1 -1
  8. package/docs/runtime/README.md +4 -4
  9. package/docs/runtime/official-perception-modules.md +2 -2
  10. package/docs/runtime/owner-lifecycle-and-observability.md +1 -1
  11. package/package.json +9 -2
  12. package/scripts/build-official-hub-behaviors.mjs +136 -0
  13. package/scripts/build-official-hub-behaviors.test.mjs +178 -0
  14. package/scripts/enable_ccl_permissions.cjs +4 -2
  15. package/scripts/enable_ccl_permissions.test.mjs +8 -4
  16. package/scripts/postinstall.mjs +1 -4
  17. package/scripts/sync-bundled-skill.mjs +12 -159
  18. package/scripts/sync-bundled-skill.test.mjs +9 -74
  19. package/skills/clawclaw/SKILL.md +18 -13
  20. package/skills/clawclaw/references/BEHAVIORS.md +4 -4
  21. package/skills/clawclaw/references/COMMANDS.md +33 -18
  22. package/skills/clawclaw/references/GAME-MECHANICS.md +16 -18
  23. package/skills/clawclaw/references/HUB.md +25 -38
  24. package/skills/clawclaw/references/STREAM.md +9 -11
  25. package/src/behaviors/official-finite/do-task.ts +70 -0
  26. package/src/behaviors/official-finite/index.ts +0 -3
  27. package/src/commands/account.ts +58 -14
  28. package/src/commands/behavior.ts +116 -38
  29. package/src/commands/hub.ts +110 -153
  30. package/src/commands/load.ts +138 -33
  31. package/src/commands/perception.ts +55 -24
  32. package/src/commands/persona.ts +66 -20
  33. package/src/commands/skill.ts +12 -48
  34. package/src/commands/trigger.ts +68 -40
  35. package/src/hub-official-behaviors/kill-lone.ts +138 -0
  36. package/src/hub-official-behaviors/patrol.ts +30 -0
  37. package/src/hub-official-behaviors/shared.ts +125 -0
  38. package/src/hub-official-behaviors/task-only.ts +158 -0
  39. package/src/lib/account-guidance.ts +54 -9
  40. package/src/lib/agent-workspace-client.ts +135 -0
  41. package/src/lib/agent-workspace-runtime.ts +154 -0
  42. package/src/lib/agent-workspace-skills.ts +177 -0
  43. package/src/lib/agent-workspace-sync.ts +852 -0
  44. package/src/lib/gameplay-config.ts +29 -15
  45. package/src/lib/hub-client.ts +252 -34
  46. package/src/lib/hub-reminder.ts +22 -7
  47. package/src/lib/init-command.ts +0 -6
  48. package/src/lib/load-context.ts +12 -6
  49. package/src/lib/persona.ts +141 -69
  50. package/src/lib/server-status.ts +78 -0
  51. package/src/lib/skill-host.ts +160 -0
  52. package/src/lib/user-data.ts +197 -4
  53. package/src/pipeline/event-format.ts +20 -4
  54. package/src/pipeline/event-hints.ts +20 -6
  55. package/src/pipeline/game-sync-event-normalization.ts +9 -0
  56. package/src/pipeline/role-display.ts +22 -0
  57. package/src/runtime/clawclaw/agent-ability-state.ts +1 -21
  58. package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
  59. package/src/runtime/clawclaw/owner.ts +63 -19
  60. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +8 -1
  61. package/src/runtime/clawclaw/plugins/action/automated-action-normalization.ts +0 -1
  62. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +8 -2
  63. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +2 -2
  64. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -9
  65. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +4 -1
  66. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +11 -5
  67. package/src/runtime/clawclaw/plugins/perception/replay.ts +0 -2
  68. package/src/runtime/clawclaw-event-catalog.ts +2 -0
  69. package/src/runtime/framework/action-diagnostics.ts +1 -0
  70. package/src/runtime/framework/modules/runtime-module-loader.ts +0 -1
  71. package/src/sdk/action.ts +8 -6
  72. package/src/sdk/behavior-plugin/index.ts +1 -2
  73. package/src/sdk/behavior-toolkit/model.ts +2 -0
  74. package/src/sdk/module-input/index.ts +0 -2
  75. package/src/strategies/goals/crab-sabotage-top.ts +5 -61
  76. package/src/strategies/types.ts +0 -6
  77. package/personas//345/217/243/346/230/257/345/277/203/351/235/236.md +0 -50
  78. package/personas//345/277/240/345/277/203/350/200/201/344/273/206.md +0 -51
  79. package/personas//346/227/240/344/272/272/350/256/276.md +0 -1
  80. package/personas//350/264/253/345/230/264/346/215/237/345/217/213.md +0 -48
  81. package/personas//350/275/257/350/220/214/350/205/271/351/273/221.md +0 -51
  82. package/src/behaviors/official-finite/index.test.ts +0 -202
  83. package/src/behaviors/official-finite/trigger-alarm.ts +0 -53
  84. package/src/channel/claude-channel-server.test.ts +0 -202
  85. package/src/commands/account.test.ts +0 -570
  86. package/src/commands/behavior.test.ts +0 -158
  87. package/src/commands/communication.test.ts +0 -282
  88. package/src/commands/competition.test.ts +0 -116
  89. package/src/commands/data.test.ts +0 -89
  90. package/src/commands/events-canonical-state.test.ts +0 -406
  91. package/src/commands/events.test.ts +0 -58
  92. package/src/commands/game/index.test.ts +0 -1251
  93. package/src/commands/game-map.test.ts +0 -69
  94. package/src/commands/hub.test.ts +0 -124
  95. package/src/commands/load.test.ts +0 -440
  96. package/src/commands/perception.test.ts +0 -75
  97. package/src/commands/setup/hermes.test.ts +0 -96
  98. package/src/commands/setup/openclaw.test.ts +0 -124
  99. package/src/commands/trigger.test.ts +0 -140
  100. package/src/commands/upgrade.test.ts +0 -82
  101. package/src/lib/account-guidance.test.ts +0 -36
  102. package/src/lib/auth.test.ts +0 -151
  103. package/src/lib/behavior-export.test.ts +0 -282
  104. package/src/lib/behavior-export.ts +0 -514
  105. package/src/lib/clawclaw-skill-spectate-guidance.test.ts +0 -21
  106. package/src/lib/custom-tts.test.ts +0 -387
  107. package/src/lib/diagnostics-config.test.ts +0 -59
  108. package/src/lib/game-client-tts.test.ts +0 -151
  109. package/src/lib/game-client.test.ts +0 -250
  110. package/src/lib/gameplay-config.test.ts +0 -301
  111. package/src/lib/host-config-patcher.test.ts +0 -130
  112. package/src/lib/http-transport.test.ts +0 -124
  113. package/src/lib/hub-client.test.ts +0 -57
  114. package/src/lib/hub-install.test.ts +0 -135
  115. package/src/lib/hub-install.ts +0 -185
  116. package/src/lib/hub-unzip.test.ts +0 -69
  117. package/src/lib/init-command.test.ts +0 -103
  118. package/src/lib/load-context.test.ts +0 -62
  119. package/src/lib/match-state.test.ts +0 -134
  120. package/src/lib/official-resource-sync.test.ts +0 -199
  121. package/src/lib/official-resource-sync.ts +0 -221
  122. package/src/lib/perception-config.test.ts +0 -143
  123. package/src/lib/perception-export.test.ts +0 -145
  124. package/src/lib/perception-export.ts +0 -178
  125. package/src/lib/persona.test.ts +0 -84
  126. package/src/lib/room.test.ts +0 -88
  127. package/src/lib/server-registry.test.ts +0 -64
  128. package/src/lib/service-status.test.ts +0 -81
  129. package/src/lib/skill-version.test.ts +0 -48
  130. package/src/lib/trigger-config.test.ts +0 -102
  131. package/src/lib/trigger-export.test.ts +0 -80
  132. package/src/lib/trigger-export.ts +0 -210
  133. package/src/lib/user-data.test.ts +0 -121
  134. package/src/lib/workspace-argv.test.ts +0 -49
  135. package/src/pipeline/canonical-event-presentation.test.ts +0 -255
  136. package/src/pipeline/event-format.test.ts +0 -828
  137. package/src/pipeline/event-hints.test.ts +0 -316
  138. package/src/pipeline/game-sync-event-normalization.test.ts +0 -371
  139. package/src/pipeline/player-projection.test.ts +0 -247
  140. package/src/runtime/auto-upgrade.test.ts +0 -66
  141. package/src/runtime/canonical-event-emitter.test.ts +0 -70
  142. package/src/runtime/canonical-monitor.test.ts +0 -577
  143. package/src/runtime/clawclaw/agent-event-policy.test.ts +0 -58
  144. package/src/runtime/clawclaw/behavior-decision.test.ts +0 -43
  145. package/src/runtime/clawclaw/behavior-input-fields.test.ts +0 -175
  146. package/src/runtime/clawclaw/behavior-input.test.ts +0 -173
  147. package/src/runtime/clawclaw/behavior-observation-memory.test.ts +0 -59
  148. package/src/runtime/clawclaw/behavior-read-api.test.ts +0 -123
  149. package/src/runtime/clawclaw/notifications.test.ts +0 -47
  150. package/src/runtime/clawclaw/owner-lock.test.ts +0 -221
  151. package/src/runtime/clawclaw/owner.test.ts +0 -203
  152. package/src/runtime/clawclaw/plugins/action/action-plugin.test.ts +0 -304
  153. package/src/runtime/clawclaw/plugins/assembly.test.ts +0 -200
  154. package/src/runtime/clawclaw/plugins/behavior/activation-manager.test.ts +0 -180
  155. package/src/runtime/clawclaw/plugins/behavior/behavior-action.test.ts +0 -40
  156. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.test.ts +0 -156
  157. package/src/runtime/clawclaw/plugins/behavior/behavior-module-loader.test.ts +0 -182
  158. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.test.ts +0 -1094
  159. package/src/runtime/clawclaw/plugins/behavior/behavior-source.test.ts +0 -174
  160. package/src/runtime/clawclaw/plugins/behavior/control-driver.test.ts +0 -195
  161. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.test.ts +0 -283
  162. package/src/runtime/clawclaw/plugins/behavior-input-source.test.ts +0 -80
  163. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.test.ts +0 -267
  164. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.test.ts +0 -226
  165. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.test.ts +0 -239
  166. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.test.ts +0 -407
  167. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-push.integration.test.ts +0 -397
  168. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.test.ts +0 -270
  169. package/src/runtime/clawclaw/plugins/mailbox/mailbox-agent-event-batch.test.ts +0 -166
  170. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.test.ts +0 -194
  171. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.test.ts +0 -87
  172. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.test.ts +0 -2012
  173. package/src/runtime/clawclaw/plugins/perception/module-runner.test.ts +0 -214
  174. package/src/runtime/clawclaw/plugins/perception/modules/co-movement-module.ts +0 -347
  175. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.test.ts +0 -92
  176. package/src/runtime/clawclaw/plugins/perception/modules/corpse-visibility-module.ts +0 -248
  177. package/src/runtime/clawclaw/plugins/perception/modules/follow-module.ts +0 -389
  178. package/src/runtime/clawclaw/plugins/perception/modules/index.ts +0 -8
  179. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.test.ts +0 -342
  180. package/src/runtime/clawclaw/plugins/perception/modules/motion-module.ts +0 -475
  181. package/src/runtime/clawclaw/plugins/perception/modules/parallel-module-test-helpers.ts +0 -30
  182. package/src/runtime/clawclaw/plugins/perception/modules/relation-stability.test.ts +0 -304
  183. package/src/runtime/clawclaw/plugins/perception/modules/route-module.test.ts +0 -179
  184. package/src/runtime/clawclaw/plugins/perception/modules/route-module.ts +0 -364
  185. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.test.ts +0 -81
  186. package/src/runtime/clawclaw/plugins/perception/modules/spatial-module.ts +0 -200
  187. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.test.ts +0 -216
  188. package/src/runtime/clawclaw/plugins/perception/modules/stop-module.ts +0 -284
  189. package/src/runtime/clawclaw/plugins/perception/modules/temporal-evidence.test.ts +0 -120
  190. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.test.ts +0 -105
  191. package/src/runtime/clawclaw/plugins/perception/modules/visibility-module.ts +0 -269
  192. package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.test.ts +0 -865
  193. package/src/runtime/clawclaw/plugins/perception/perception-plugin.test.ts +0 -1878
  194. package/src/runtime/clawclaw/plugins/perception/perception-source.test.ts +0 -278
  195. package/src/runtime/clawclaw/plugins/perception/replay.test.ts +0 -77
  196. package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +0 -854
  197. package/src/runtime/clawclaw/plugins/source/game-transport.test.ts +0 -287
  198. package/src/runtime/clawclaw/plugins/source/player-change-tracker.test.ts +0 -321
  199. package/src/runtime/clawclaw/plugins/source/room-transport.test.ts +0 -307
  200. package/src/runtime/clawclaw/plugins/source/source-plugin.test.ts +0 -2646
  201. package/src/runtime/clawclaw/plugins/source/task-change-tracker.test.ts +0 -212
  202. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.test.ts +0 -548
  203. package/src/runtime/clawclaw/plugins/trigger/trigger-source.test.ts +0 -169
  204. package/src/runtime/clawclaw/runtime-data-export.test.ts +0 -249
  205. package/src/runtime/clawclaw-event-catalog.test.ts +0 -126
  206. package/src/runtime/framework/action-diagnostics.test.ts +0 -81
  207. package/src/runtime/framework/capability-registry.test.ts +0 -423
  208. package/src/runtime/framework/control-coordinator.test.ts +0 -675
  209. package/src/runtime/framework/events/event-delivery-service.test.ts +0 -84
  210. package/src/runtime/framework/events/event-ingress.test.ts +0 -203
  211. package/src/runtime/framework/events/mailbox-event-repositories.test.ts +0 -710
  212. package/src/runtime/framework/events/sqlite-event-repository.test.ts +0 -802
  213. package/src/runtime/framework/mailbox/coalescer.test.ts +0 -55
  214. package/src/runtime/framework/mailbox/identity.test.ts +0 -38
  215. package/src/runtime/framework/mailbox/mailbox-dispatcher.test.ts +0 -513
  216. package/src/runtime/framework/mailbox/notification-projector.test.ts +0 -77
  217. package/src/runtime/framework/modules/runtime-module-loader.test.ts +0 -435
  218. package/src/runtime/framework/participation-manager.test.ts +0 -108
  219. package/src/runtime/framework/plugins/runtime-input-journal.test.ts +0 -179
  220. package/src/runtime/framework/plugins/runtime-plugin-scheduler.test.ts +0 -2040
  221. package/src/runtime/framework/state/durable-agent-state-snapshot.test.ts +0 -144
  222. package/src/runtime/framework/state/history/sqlite-state-history-repository.test.ts +0 -157
  223. package/src/runtime/framework/state/history/state-history.test.ts +0 -251
  224. package/src/runtime/framework/state/state-core.test.ts +0 -197
  225. package/src/runtime/game-sync-protocol.test.ts +0 -123
  226. package/src/runtime/host-monitor-rate-gate.test.ts +0 -73
  227. package/src/runtime/mailbox-host-relay.test.ts +0 -293
  228. package/src/runtime/observability/observability.test.ts +0 -583
  229. package/src/runtime/owner-control.test.ts +0 -153
  230. package/src/runtime/parent-process-watch.test.ts +0 -27
  231. package/src/runtime/pending-event-handoff.test.ts +0 -29
  232. package/src/runtime/raw-ws-log.test.ts +0 -102
  233. package/src/runtime/runtime-logger.test.ts +0 -58
  234. package/src/runtime/runtime-persistence.test.ts +0 -26
  235. package/src/runtime/runtime.test.ts +0 -1770
  236. package/src/runtime/ws-client.test.ts +0 -562
  237. package/src/sdk/behavior-plugin/index.test.ts +0 -74
  238. package/src/sdk/index.test.ts +0 -45
  239. package/src/sdk/module-input/index.test.ts +0 -49
  240. package/src/sdk/perception-plugin/index.test.ts +0 -22
  241. package/src/sdk/resource-metadata.test.ts +0 -40
  242. package/src/sdk/trigger-plugin/index.test.ts +0 -41
  243. package/src/short-command/classifier.test.ts +0 -107
  244. package/src/short-command/presenter.test.ts +0 -119
  245. package/src/short-command/runner.test.ts +0 -78
  246. package/src/short-command/sensitive-data-filter.test.ts +0 -56
  247. package/src/short-command/transport-response.test.ts +0 -39
  248. package/src/strategies/custom-module.test.ts +0 -268
  249. package/src/strategies/game-utils.test.ts +0 -306
  250. package/src/strategies/goals/avoid-players-top.test.ts +0 -96
  251. package/src/strategies/goals/crab-sabotage-top.test.ts +0 -145
  252. package/src/strategies/goals/kill-lone-top.test.ts +0 -97
  253. package/src/strategies/goals/kill-target-top.test.ts +0 -66
  254. package/src/strategies/goals/lone-kill-task-top.test.ts +0 -85
  255. package/src/strategies/goals/normal-shrimp-top.test.ts +0 -113
  256. package/src/strategies/goals/paradise-fish-top.test.ts +0 -204
  257. package/src/strategies/goals/task-only-top.test.ts +0 -89
  258. package/src/strategies/goals/warrior-shrimp-top.test.ts +0 -139
  259. package/src/strategies/meeting-gate.test.ts +0 -59
  260. package/src/strategies/official-long-behavior.test.ts +0 -89
  261. package/src/strategies/pathfind/astar-path.test.ts +0 -198
  262. package/src/strategies/pathfind/escape-planner.test.ts +0 -223
  263. package/src/strategies/player-targets.test.ts +0 -10
  264. package/src/strategies/task-only.test.ts +0 -138
@@ -1,1251 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import type { AuthProfile } from '../../lib/auth.js';
3
- import { ApiError } from '../../lib/game-client.js';
4
- import { getMeta } from '../../lib/command-meta.js';
5
- import { jsonTransportResponse } from '../../short-command/transport-response.js';
6
- import {
7
- CLAWCLAW_ENABLE_CLAUDE_CHANNELS,
8
- createGameCommand,
9
- createJoinCommand,
10
- createStartCommand,
11
- type GameCommandDependencies,
12
- } from './index.js';
13
-
14
- const profile: AuthProfile = {
15
- agentName: 'quit-test',
16
- apiKey: 'test-key',
17
- runtimeAccountId: 'acct_00000000000000000000000000000000',
18
- serverUrl: 'https://example.test/claw',
19
- };
20
-
21
- afterEach(() => vi.unstubAllEnvs());
22
-
23
- function fixture(
24
- queue: Record<string, any>,
25
- overrides: Partial<Record<'leaveGame' | 'leaveRoom' | 'leaveQueue', any>> = {},
26
- ) {
27
- const stdout: string[] = [];
28
- const exitCodes: number[] = [];
29
- const client = {
30
- getQueueStatus: vi.fn(async () => queue),
31
- getRoomStatus: vi.fn(async () => ({ success: true, data: {} })),
32
- leaveGame: vi.fn(async () => overrides.leaveGame ?? { success: true }),
33
- leaveRoom: vi.fn(async () => overrides.leaveRoom ?? { success: true }),
34
- leaveQueue: vi.fn(async () => overrides.leaveQueue ?? {
35
- success: true,
36
- data: { status: 'left_queue' },
37
- }),
38
- startRoom: vi.fn(async () => ({ success: true })),
39
- };
40
- const stopRuntime = vi.fn(async () => true);
41
- const dependencies: GameCommandDependencies = {
42
- activeProfile: () => profile,
43
- clientFactory: () => client,
44
- stopRuntime,
45
- io: {
46
- writeStdout: (text) => stdout.push(text),
47
- setExitCode: (code) => exitCodes.push(code),
48
- },
49
- };
50
- return { client, dependencies, exitCodes, stdout, stopRuntime };
51
- }
52
-
53
- function startRoomFixture(result: unknown | Error) {
54
- const stdout: string[] = [];
55
- const exitCodes: number[] = [];
56
- const client = {
57
- getQueueStatus: vi.fn(),
58
- getRoomStatus: vi.fn(),
59
- leaveGame: vi.fn(),
60
- leaveRoom: vi.fn(),
61
- leaveQueue: vi.fn(),
62
- startRoom: vi.fn(async () => {
63
- if (result instanceof Error) throw result;
64
- return result;
65
- }),
66
- };
67
- const dependencies: GameCommandDependencies = {
68
- activeProfile: () => profile,
69
- clientFactory: () => client,
70
- io: {
71
- writeStdout: (text) => stdout.push(text),
72
- setExitCode: (code) => exitCodes.push(code),
73
- },
74
- };
75
- return { client, dependencies, exitCodes, stdout };
76
- }
77
-
78
- function statusFixture(
79
- queue: Record<string, any>,
80
- room: Record<string, any> = { success: true, data: {} },
81
- ) {
82
- const stdout: string[] = [];
83
- const exitCodes: number[] = [];
84
- const client = {
85
- getQueueStatus: vi.fn(async () => queue),
86
- getRoomStatus: vi.fn(async () => room),
87
- leaveGame: vi.fn(),
88
- leaveRoom: vi.fn(),
89
- leaveQueue: vi.fn(),
90
- startRoom: vi.fn(),
91
- };
92
- const dependencies: GameCommandDependencies = {
93
- activeProfile: () => profile,
94
- clientFactory: () => client,
95
- io: {
96
- writeStdout: (text) => stdout.push(text),
97
- setExitCode: (code) => exitCodes.push(code),
98
- },
99
- };
100
- return { client, dependencies, exitCodes, stdout };
101
- }
102
-
103
- async function runStartRoom(value: ReturnType<typeof startRoomFixture>) {
104
- await createGameCommand(value.dependencies).parseAsync(
105
- ['node', 'game', 'start-room'],
106
- { from: 'node' },
107
- );
108
- expect(value.stdout).toHaveLength(1);
109
- return JSON.parse(value.stdout[0]);
110
- }
111
-
112
- async function runQuit(value: ReturnType<typeof fixture>) {
113
- await createGameCommand(value.dependencies).parseAsync(
114
- ['node', 'game', 'quit'],
115
- { from: 'node' },
116
- );
117
- expect(value.stdout).toHaveLength(1);
118
- return JSON.parse(value.stdout[0]);
119
- }
120
-
121
- async function runStatus(value: ReturnType<typeof statusFixture>) {
122
- await createGameCommand(value.dependencies).parseAsync(
123
- ['node', 'game', 'status'],
124
- { from: 'node' },
125
- );
126
- expect(value.stdout).toHaveLength(1);
127
- return JSON.parse(value.stdout[0]);
128
- }
129
-
130
- describe('game status', () => {
131
- it.each([
132
- {
133
- queue: { success: true, data: { status: 'not_in_queue' } },
134
- expected: { status: 'idle', queue_status: 'not_in_queue' },
135
- },
136
- {
137
- queue: { success: true, data: { status: 'queued', mode: 'match' } },
138
- expected: { status: 'matching', queue_status: 'queued', mode: 'match' },
139
- },
140
- {
141
- queue: {
142
- success: true,
143
- data: { status: 'allocated', mode: 'match', game_id: 'GAME1' },
144
- },
145
- expected: {
146
- status: 'in_game',
147
- queue_status: 'allocated',
148
- mode: 'match',
149
- game_id: 'GAME1',
150
- },
151
- },
152
- ])('projects backend queue state as $expected.status', async ({ queue, expected }) => {
153
- const value = statusFixture(queue);
154
-
155
- const output = await runStatus(value);
156
-
157
- expect(output).toMatchObject({ schema: 'ccl.game-status.v1', ...expected });
158
- expect(value.client.getQueueStatus).toHaveBeenCalledWith('clawclaw');
159
- expect(value.client.getRoomStatus).not.toHaveBeenCalled();
160
- expect(value.exitCodes).toEqual([0]);
161
- });
162
-
163
- it.each([
164
- { mode: 'room', roomType: 'casual' },
165
- { mode: 'training_simulation', roomType: 'training_simulation' },
166
- { mode: 'training_dummy', roomType: 'training_dummy' },
167
- ])('includes room context for an allocated $roomType game', async ({ mode, roomType }) => {
168
- const value = statusFixture(
169
- {
170
- success: true,
171
- data: { status: 'allocated', mode, game_id: 'GAME1' },
172
- },
173
- {
174
- success: true,
175
- data: {
176
- room_code: 'ROOM1',
177
- room_type: roomType,
178
- status: 'playing',
179
- },
180
- },
181
- );
182
-
183
- const output = await runStatus(value);
184
-
185
- expect(output).toMatchObject({
186
- schema: 'ccl.game-status.v1',
187
- status: 'in_game',
188
- queue_status: 'allocated',
189
- mode,
190
- game_id: 'GAME1',
191
- room_code: 'ROOM1',
192
- room_type: roomType,
193
- room_status: 'playing',
194
- });
195
- expect(value.client.getRoomStatus).toHaveBeenCalledOnce();
196
- expect(value.exitCodes).toEqual([0]);
197
- });
198
-
199
- it('falls back to allocated room queue state when room status is unavailable', async () => {
200
- const value = statusFixture({
201
- success: true,
202
- data: { status: 'allocated', mode: 'room', game_id: 'GAME1' },
203
- });
204
- value.client.getRoomStatus.mockRejectedValueOnce(new Error('room status unavailable'));
205
-
206
- const output = await runStatus(value);
207
-
208
- expect(output).toEqual({
209
- schema: 'ccl.game-status.v1',
210
- status: 'in_game',
211
- queue_status: 'allocated',
212
- mode: 'room',
213
- game_id: 'GAME1',
214
- });
215
- expect(value.exitCodes).toEqual([0]);
216
- });
217
-
218
- it.each([
219
- { roomType: 'casual', expectedStatus: 'friend_room' },
220
- { roomType: 'training_simulation', expectedStatus: 'training_room' },
221
- { roomType: 'training_dummy', expectedStatus: 'training_room' },
222
- ])('uses room status to classify $roomType', async ({ roomType, expectedStatus }) => {
223
- const value = statusFixture(
224
- { success: true, data: { status: 'in_room', mode: 'room', room_code: 'QUEUE1' } },
225
- {
226
- success: true,
227
- data: {
228
- room_code: 'ROOM1',
229
- room_type: roomType,
230
- status: 'waiting',
231
- },
232
- },
233
- );
234
-
235
- const output = await runStatus(value);
236
-
237
- expect(output).toMatchObject({
238
- schema: 'ccl.game-status.v1',
239
- status: expectedStatus,
240
- queue_status: 'in_room',
241
- room_code: 'ROOM1',
242
- room_type: roomType,
243
- room_status: 'waiting',
244
- });
245
- expect(value.client.getRoomStatus).toHaveBeenCalledOnce();
246
- expect(value.exitCodes).toEqual([0]);
247
- });
248
-
249
- it('keeps an unrecognized queue status visible and exits nonzero', async () => {
250
- const value = statusFixture({ success: true, data: { status: 'new_backend_state' } });
251
-
252
- const output = await runStatus(value);
253
-
254
- expect(output).toMatchObject({
255
- schema: 'ccl.game-status.v1',
256
- status: 'unknown',
257
- queue_status: 'new_backend_state',
258
- });
259
- expect(value.client.getRoomStatus).not.toHaveBeenCalled();
260
- expect(value.exitCodes).toEqual([1]);
261
- });
262
- });
263
-
264
- describe('top-level participation commands', () => {
265
- it('marks every simplified participation leaf as long-running', () => {
266
- const start = createStartCommand();
267
- expect(start.commands.map((command) => [command.name(), getMeta(command)]))
268
- .toEqual([
269
- ['match', { longRunning: true, timeoutMs: 1_800_000 }],
270
- ['room', { longRunning: true, timeoutMs: 1_800_000 }],
271
- ['training', { longRunning: true, timeoutMs: 1_800_000 }],
272
- ]);
273
- expect(getMeta(createJoinCommand()))
274
- .toEqual({ longRunning: true, timeoutMs: 1_800_000 });
275
- });
276
-
277
- const activeParticipationCases = [
278
- {
279
- active: 'ordinary match queue',
280
- kind: 'match',
281
- queue: { success: true, data: { status: 'queued', mode: 'match' } },
282
- room: undefined,
283
- },
284
- {
285
- active: 'ordinary match game',
286
- kind: 'match',
287
- queue: { success: true, data: { status: 'allocated', mode: 'match', game_id: 'MATCH1' } },
288
- room: undefined,
289
- },
290
- {
291
- active: 'friend room lobby',
292
- kind: 'room',
293
- queue: { success: true, data: { status: 'in_room', mode: 'room', room_code: 'ROOM1' } },
294
- room: {
295
- success: true,
296
- data: { room_code: 'ROOM1', room_type: 'casual', status: 'waiting' },
297
- },
298
- },
299
- {
300
- active: 'friend room game',
301
- kind: 'room',
302
- queue: { success: true, data: { status: 'allocated', mode: 'room', game_id: 'ROOMGAME1' } },
303
- room: undefined,
304
- },
305
- {
306
- active: 'simulation training lobby',
307
- kind: 'training_simulation',
308
- queue: {
309
- success: true,
310
- data: { status: 'in_room', mode: 'training_simulation', room_code: 'SIM1' },
311
- },
312
- room: {
313
- success: true,
314
- data: { room_code: 'SIM1', room_type: 'training_simulation', status: 'waiting' },
315
- },
316
- },
317
- {
318
- active: 'simulation training game',
319
- kind: 'training_simulation',
320
- queue: {
321
- success: true,
322
- data: { status: 'allocated', mode: 'training_simulation', game_id: 'SIMGAME1' },
323
- },
324
- room: undefined,
325
- },
326
- {
327
- active: 'dummy training lobby',
328
- kind: 'training_dummy',
329
- queue: {
330
- success: true,
331
- data: { status: 'in_room', mode: 'training_dummy', room_code: 'DUMMY1' },
332
- },
333
- room: {
334
- success: true,
335
- data: { room_code: 'DUMMY1', room_type: 'training_dummy', status: 'waiting' },
336
- },
337
- },
338
- {
339
- active: 'dummy training game',
340
- kind: 'training_dummy',
341
- queue: {
342
- success: true,
343
- data: { status: 'allocated', mode: 'training_dummy', game_id: 'DUMMYGAME1' },
344
- },
345
- room: undefined,
346
- },
347
- ] as const;
348
-
349
- const startTargetCases = [
350
- { target: 'match', argv: ['match'], kind: 'match' },
351
- { target: 'room', argv: ['room'], kind: 'room' },
352
- {
353
- target: 'training simulation',
354
- argv: ['training', 'simulation'],
355
- kind: 'training_simulation',
356
- },
357
- {
358
- target: 'training dummy',
359
- argv: ['training', 'dummy'],
360
- kind: 'training_dummy',
361
- },
362
- ] as const;
363
-
364
- it('starts a new ordinary match while idle and forwards force', async () => {
365
- const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
366
- const ownerRunner = vi.fn(async () => {});
367
-
368
- await createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
369
- 'node',
370
- 'start',
371
- 'match',
372
- '--agent-type',
373
- 'claude-code',
374
- '--llm-model',
375
- 'claude-opus-4-8',
376
- '--force',
377
- ], { from: 'node' });
378
-
379
- expect(ownerRunner).toHaveBeenCalledWith({
380
- kind: 'match',
381
- mode: 'match',
382
- agentType: 'claude-code',
383
- llmModel: 'claude-opus-4-8',
384
- }, {
385
- forceExistingRuntime: true,
386
- });
387
- });
388
-
389
- it('preserves Claude Channel delivery for the simplified start command', async () => {
390
- const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
391
- const ownerRunner = vi.fn(async () => {});
392
-
393
- await createStartCommand({
394
- ...value.dependencies,
395
- ownerRunner,
396
- env: { [CLAWCLAW_ENABLE_CLAUDE_CHANNELS]: '1' },
397
- }).parseAsync([
398
- 'node',
399
- 'start',
400
- 'match',
401
- '--agent-type',
402
- 'claude-code',
403
- ], { from: 'node' });
404
-
405
- expect(ownerRunner).toHaveBeenCalledWith(expect.objectContaining({
406
- kind: 'match',
407
- agentType: 'claude-code',
408
- }), {
409
- forceExistingRuntime: false,
410
- channelDelivery: true,
411
- });
412
- });
413
-
414
- it.each([
415
- { status: 'queued', mode: 'match' },
416
- { status: 'allocated', mode: 'match', game_id: 'GAME1' },
417
- ])('resumes an existing ordinary $status participation instead of creating a duplicate', async (queue) => {
418
- const value = statusFixture({
419
- success: true,
420
- data: queue,
421
- });
422
- const ownerRunner = vi.fn(async () => {});
423
-
424
- await createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
425
- 'node',
426
- 'start',
427
- 'match',
428
- '--agent-type',
429
- 'claude-code',
430
- ], { from: 'node' });
431
-
432
- expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
433
- forceExistingRuntime: false,
434
- });
435
- });
436
-
437
- it.each([
438
- { status: 'queued', mode: 'competition' },
439
- { status: 'queued' },
440
- { status: 'queued', mode: 'future_mode' },
441
- { status: 'allocated', mode: 'competition', game_id: 'COMP1' },
442
- { status: 'allocated', game_id: 'MISSING1' },
443
- { status: 'allocated', mode: 'future_mode', game_id: 'UNKNOWN1' },
444
- ])('does not reinterpret $status/$mode as an ordinary match', async (queue) => {
445
- const value = statusFixture({ success: true, data: queue });
446
- const ownerRunner = vi.fn(async () => {});
447
-
448
- await expect(createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
449
- 'node',
450
- 'start',
451
- 'match',
452
- '--agent-type',
453
- 'claude-code',
454
- ], { from: 'node' })).rejects.toThrow('another backend participation is active');
455
- expect(ownerRunner).not.toHaveBeenCalled();
456
- });
457
-
458
- it('rejects starting a match while a training room is active', async () => {
459
- const value = statusFixture(
460
- { success: true, data: { status: 'in_room', mode: 'training_dummy', room_code: 'ROOM1' } },
461
- {
462
- success: true,
463
- data: { room_code: 'ROOM1', room_type: 'training_dummy', status: 'waiting' },
464
- },
465
- );
466
- const ownerRunner = vi.fn(async () => {});
467
-
468
- await expect(createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
469
- 'node',
470
- 'start',
471
- 'match',
472
- '--agent-type',
473
- 'claude-code',
474
- ], { from: 'node' })).rejects.toThrow('another backend participation is active');
475
- expect(ownerRunner).not.toHaveBeenCalled();
476
- });
477
-
478
- it.each(activeParticipationCases.flatMap((active) => (
479
- startTargetCases.map((target) => ({ active, target }))
480
- )))('$active.active + start $target.target resumes only the same participation kind', async ({
481
- active,
482
- target,
483
- }) => {
484
- const value = statusFixture(active.queue, active.room);
485
- const ownerRunner = vi.fn(async () => {});
486
- const run = createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
487
- 'node',
488
- 'start',
489
- ...target.argv,
490
- '--agent-type',
491
- 'test-host',
492
- ], { from: 'node' });
493
-
494
- if (active.kind === target.kind) {
495
- await run;
496
- expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
497
- forceExistingRuntime: false,
498
- });
499
- return;
500
- }
501
-
502
- await expect(run).rejects.toThrow('another backend participation is active');
503
- expect(ownerRunner).not.toHaveBeenCalled();
504
- });
505
-
506
- it.each([
507
- { argv: [], roomType: 'training_simulation' },
508
- { argv: ['dummy'], roomType: 'training_dummy' },
509
- ])('creates training mode $roomType from the simplified command', async ({ argv, roomType }) => {
510
- const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
511
- const ownerRunner = vi.fn(async () => {});
512
-
513
- await createStartCommand({ ...value.dependencies, ownerRunner }).parseAsync([
514
- 'node',
515
- 'start',
516
- 'training',
517
- ...argv,
518
- '--agent-type',
519
- 'test-host',
520
- ], { from: 'node' });
521
-
522
- expect(ownerRunner).toHaveBeenCalledWith({
523
- kind: 'create_room',
524
- roomType,
525
- agentType: 'test-host',
526
- llmModel: undefined,
527
- }, {
528
- forceExistingRuntime: false,
529
- });
530
- });
531
-
532
- it('joins the current backend participation and replaces a stale runtime with force', async () => {
533
- const value = statusFixture({
534
- success: true,
535
- data: { status: 'allocated', mode: 'match', game_id: 'GAME1' },
536
- });
537
- const ownerRunner = vi.fn(async () => {});
538
-
539
- await createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
540
- 'node',
541
- 'join',
542
- '--force',
543
- ], { from: 'node' });
544
-
545
- expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
546
- forceExistingRuntime: true,
547
- });
548
- });
549
-
550
- it('preserves Claude Channel delivery when bare join resumes participation', async () => {
551
- const value = statusFixture({
552
- success: true,
553
- data: { status: 'allocated', mode: 'match', game_id: 'GAME1' },
554
- });
555
- const ownerRunner = vi.fn(async () => {});
556
-
557
- await createJoinCommand({
558
- ...value.dependencies,
559
- ownerRunner,
560
- env: { [CLAWCLAW_ENABLE_CLAUDE_CHANNELS]: '1' },
561
- }).parseAsync(['node', 'join'], { from: 'node' });
562
-
563
- expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
564
- forceExistingRuntime: false,
565
- channelDelivery: true,
566
- });
567
- });
568
-
569
- it.each(activeParticipationCases)('bare join resumes $active', async ({ queue, room }) => {
570
- const value = statusFixture(queue, room);
571
- const ownerRunner = vi.fn(async () => {});
572
-
573
- await createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
574
- 'node',
575
- 'join',
576
- ], { from: 'node' });
577
-
578
- expect(ownerRunner).toHaveBeenCalledWith({ kind: 'resume' }, {
579
- forceExistingRuntime: false,
580
- });
581
- });
582
-
583
- it('rejects bare join while the backend is idle', async () => {
584
- const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
585
- const ownerRunner = vi.fn(async () => {});
586
-
587
- await expect(createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
588
- 'node',
589
- 'join',
590
- ], { from: 'node' })).rejects.toThrow('No active backend participation to join.');
591
- expect(ownerRunner).not.toHaveBeenCalled();
592
- });
593
-
594
- it('joins a specified room while idle and passes Agent metadata', async () => {
595
- const value = statusFixture({ success: true, data: { status: 'not_in_queue' } });
596
- const ownerRunner = vi.fn(async () => {});
597
-
598
- await createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
599
- 'node',
600
- 'join',
601
- 'room',
602
- '123456',
603
- '--agent-type',
604
- 'openclaw',
605
- '--llm-model',
606
- 'deepseek-v4-pro',
607
- ], { from: 'node' });
608
-
609
- expect(ownerRunner).toHaveBeenCalledWith({
610
- kind: 'join_room',
611
- roomCode: '123456',
612
- agentType: 'openclaw',
613
- llmModel: 'deepseek-v4-pro',
614
- }, {
615
- forceExistingRuntime: false,
616
- });
617
- });
618
-
619
- it('resumes the same room but refuses to switch rooms implicitly', async () => {
620
- const currentRoom = {
621
- success: true,
622
- data: { room_code: '123456', room_type: 'casual', status: 'waiting' },
623
- };
624
- const same = statusFixture(
625
- { success: true, data: { status: 'in_room', mode: 'room', room_code: '123456' } },
626
- currentRoom,
627
- );
628
- const sameOwner = vi.fn(async () => {});
629
-
630
- await createJoinCommand({ ...same.dependencies, ownerRunner: sameOwner }).parseAsync([
631
- 'node',
632
- 'join',
633
- 'room',
634
- '123456',
635
- '--agent-type',
636
- 'claude-code',
637
- ], { from: 'node' });
638
-
639
- expect(sameOwner).toHaveBeenCalledWith({ kind: 'resume' }, {
640
- forceExistingRuntime: false,
641
- });
642
-
643
- const different = statusFixture(
644
- { success: true, data: { status: 'in_room', mode: 'room', room_code: '123456' } },
645
- currentRoom,
646
- );
647
- const differentOwner = vi.fn(async () => {});
648
-
649
- await expect(createJoinCommand({
650
- ...different.dependencies,
651
- ownerRunner: differentOwner,
652
- }).parseAsync([
653
- 'node',
654
- 'join',
655
- 'room',
656
- '654321',
657
- '--agent-type',
658
- 'claude-code',
659
- ], { from: 'node' })).rejects.toThrow('another backend participation is active');
660
- expect(differentOwner).not.toHaveBeenCalled();
661
- expect(different.client.leaveRoom).not.toHaveBeenCalled();
662
- });
663
-
664
- it.each([
665
- { roomType: 'training_simulation', mode: 'training_simulation' },
666
- { roomType: 'training_dummy', mode: 'training_dummy' },
667
- ])('refuses to join a friend room while $roomType is active', async ({ roomType, mode }) => {
668
- const value = statusFixture(
669
- { success: true, data: { status: 'in_room', mode, room_code: 'TRAIN1' } },
670
- {
671
- success: true,
672
- data: { room_code: 'TRAIN1', room_type: roomType, status: 'waiting' },
673
- },
674
- );
675
- const ownerRunner = vi.fn(async () => {});
676
-
677
- await expect(createJoinCommand({ ...value.dependencies, ownerRunner }).parseAsync([
678
- 'node',
679
- 'join',
680
- 'room',
681
- '654321',
682
- '--agent-type',
683
- 'claude-code',
684
- ], { from: 'node' })).rejects.toThrow('another backend participation is active');
685
- expect(ownerRunner).not.toHaveBeenCalled();
686
- expect(value.client.leaveRoom).not.toHaveBeenCalled();
687
- });
688
- });
689
-
690
- describe('game quit', () => {
691
- it('reports HTTP 200 STILL_ALIVE as a remote failure and stops only the local runtime', async () => {
692
- const value = fixture(
693
- {
694
- success: true,
695
- data: { status: 'allocated', mode: 'room', game_id: 'G1', room_code: 'ROOM1' },
696
- },
697
- {
698
- leaveGame: {
699
- success: false,
700
- error: { code: 'STILL_ALIVE', message: 'You can only leave when dead' },
701
- },
702
- },
703
- );
704
-
705
- const output = await runQuit(value);
706
-
707
- expect(value.client.leaveGame).toHaveBeenCalledOnce();
708
- expect(value.client.leaveRoom).not.toHaveBeenCalled();
709
- expect(value.client.leaveQueue).not.toHaveBeenCalled();
710
- expect(value.stopRuntime).toHaveBeenCalledWith(profile);
711
- expect(output).toMatchObject({
712
- ok: false,
713
- status: 'leave_game_failed',
714
- left: 'local_runtime',
715
- remote_left: false,
716
- partial: true,
717
- backend_participation: 'active_game',
718
- local_runtime: 'stopping',
719
- leave_error: {
720
- code: 'STILL_ALIVE',
721
- message: 'You can only leave when dead',
722
- still_alive: true,
723
- },
724
- runtime_stop_requested: true,
725
- });
726
- expect(output.message).toContain('local runtime accepted a stop request');
727
- expect(output.message).toContain('player still exists');
728
- expect(value.exitCodes).toEqual([1]);
729
- });
730
-
731
- it('does not report left_queue when the server says allocation is in progress', async () => {
732
- const value = fixture(
733
- { success: true, data: { status: 'queued', mode: 'match' } },
734
- { leaveQueue: { success: true, data: { status: 'allocating' } } },
735
- );
736
-
737
- const output = await runQuit(value);
738
-
739
- expect(value.client.leaveQueue).toHaveBeenCalledWith('clawclaw');
740
- expect(value.stopRuntime).not.toHaveBeenCalled();
741
- expect(output).toMatchObject({
742
- ok: false,
743
- status: 'leave_queue_allocating',
744
- left: 'none',
745
- remote_left: false,
746
- leave_error: {
747
- code: 'ALLOCATION_IN_PROGRESS',
748
- retryable: true,
749
- },
750
- runtime_stop_requested: false,
751
- });
752
- expect(value.exitCodes).toEqual([1]);
753
- });
754
-
755
- it('leaves only the current game when the allocation belongs to a room', async () => {
756
- const value = fixture({
757
- success: true,
758
- data: { status: 'allocated', mode: 'room', game_id: 'RG1', room_code: 'ROOM1' },
759
- });
760
-
761
- const output = await runQuit(value);
762
-
763
- expect(value.client.getQueueStatus).toHaveBeenCalledOnce();
764
- expect(value.client.leaveGame).toHaveBeenCalledOnce();
765
- expect(value.client.leaveRoom).not.toHaveBeenCalled();
766
- expect(value.stopRuntime).not.toHaveBeenCalled();
767
- expect(output).toMatchObject({
768
- ok: true,
769
- status: 'game_returned_room',
770
- left: 'game_returned_room',
771
- remote_left: true,
772
- runtime_stop_requested: false,
773
- });
774
- expect(value.exitCodes).toEqual([0]);
775
- });
776
-
777
- it.each(['training_simulation', 'training_dummy'])('abandons an alive %s round and keeps the runtime in its room', async (mode) => {
778
- const value = fixture({
779
- success: true,
780
- data: { status: 'allocated', mode, game_id: 'TG1', room_code: 'TRAIN1' },
781
- });
782
-
783
- const output = await runQuit(value);
784
-
785
- expect(value.client.leaveGame).toHaveBeenCalledOnce();
786
- expect(value.stopRuntime).not.toHaveBeenCalled();
787
- expect(output).toMatchObject({
788
- ok: true,
789
- status: 'game_returned_room',
790
- left: 'game_returned_room',
791
- runtime_stop_requested: false,
792
- });
793
- expect(value.exitCodes).toEqual([0]);
794
- });
795
-
796
- it('stops the local runtime after leaving a normal match', async () => {
797
- const value = fixture({
798
- success: true,
799
- data: { status: 'allocated', mode: 'match', game_id: 'G2' },
800
- });
801
-
802
- const output = await runQuit(value);
803
-
804
- expect(value.stopRuntime).toHaveBeenCalledWith(profile);
805
- expect(output).toMatchObject({
806
- ok: true,
807
- status: 'left_game',
808
- left: 'game',
809
- remote_left: true,
810
- runtime_stop_requested: true,
811
- });
812
- expect(value.exitCodes).toEqual([0]);
813
- });
814
-
815
- it('leaves the room and stops the local runtime when already back in the room lobby', async () => {
816
- const value = fixture({
817
- success: true,
818
- data: { status: 'in_room', mode: 'room', room_code: 'ROOM1' },
819
- });
820
-
821
- const output = await runQuit(value);
822
-
823
- expect(value.client.leaveGame).not.toHaveBeenCalled();
824
- expect(value.client.leaveRoom).toHaveBeenCalledOnce();
825
- expect(value.stopRuntime).toHaveBeenCalledWith(profile);
826
- expect(output).toMatchObject({
827
- ok: true,
828
- status: 'left_room',
829
- left: 'room',
830
- remote_left: true,
831
- runtime_stop_requested: true,
832
- });
833
- expect(value.exitCodes).toEqual([0]);
834
- });
835
-
836
- it('treats not_in_queue from leaveQueue as an idempotent success', async () => {
837
- const value = fixture(
838
- { success: true, data: { status: 'queued', mode: 'match' } },
839
- { leaveQueue: { success: true, data: { status: 'not_in_queue' } } },
840
- );
841
-
842
- const output = await runQuit(value);
843
-
844
- expect(value.stopRuntime).toHaveBeenCalledWith(profile);
845
- expect(output).toMatchObject({
846
- ok: true,
847
- status: 'not_in_queue',
848
- left: 'queue',
849
- remote_left: true,
850
- runtime_stop_requested: true,
851
- });
852
- expect(value.exitCodes).toEqual([0]);
853
- });
854
- });
855
-
856
- describe('game start runtime replacement', () => {
857
- it.each([
858
- { argv: [], expectedForce: false },
859
- { argv: ['--force'], expectedForce: true },
860
- ])('passes force=$expectedForce to the runtime lock layer', async ({ argv, expectedForce }) => {
861
- const ownerRunner = vi.fn(async () => {});
862
-
863
- await createGameCommand({ ownerRunner }).parseAsync([
864
- 'node',
865
- 'game',
866
- 'start',
867
- '--agent-type',
868
- 'test-host',
869
- ...argv,
870
- ], { from: 'node' });
871
-
872
- expect(ownerRunner).toHaveBeenCalledWith({
873
- kind: 'match',
874
- mode: 'match',
875
- agentType: 'test-host',
876
- llmModel: undefined,
877
- }, {
878
- forceExistingRuntime: expectedForce,
879
- });
880
- });
881
-
882
- it('passes the paired Desktop event IPC configuration outside the game intent', async () => {
883
- const ownerRunner = vi.fn(async () => {});
884
- const socket = process.platform === 'win32' ? 'desktop-wake-test' : '/tmp/desktop-wake-test.sock';
885
-
886
- await createGameCommand({ ownerRunner }).parseAsync([
887
- 'node',
888
- 'game',
889
- 'start',
890
- '--agent-type',
891
- 'codex-desktop',
892
- '--desktop-event-socket',
893
- socket,
894
- '--desktop-event-token',
895
- '0123456789abcdef0123456789abcdef',
896
- ], { from: 'node' });
897
-
898
- expect(ownerRunner).toHaveBeenCalledWith({
899
- kind: 'match',
900
- mode: 'match',
901
- agentType: 'codex-desktop',
902
- llmModel: undefined,
903
- }, {
904
- forceExistingRuntime: false,
905
- desktopEvents: {
906
- socketPath: process.platform === 'win32'
907
- ? '\\\\.\\pipe\\desktop-wake-test'
908
- : '/tmp/desktop-wake-test.sock',
909
- token: '0123456789abcdef0123456789abcdef',
910
- },
911
- });
912
- });
913
-
914
- it('keeps Claude Code on the default Monitor route when Channels are not enabled', async () => {
915
- const ownerRunner = vi.fn(async () => {});
916
-
917
- await createGameCommand({ ownerRunner, env: {} }).parseAsync([
918
- 'node',
919
- 'game',
920
- 'start',
921
- '--agent-type',
922
- 'claude-code',
923
- ], { from: 'node' });
924
-
925
- expect(ownerRunner).toHaveBeenCalledWith(expect.any(Object), {
926
- forceExistingRuntime: false,
927
- });
928
- });
929
-
930
- it('requires the exact opt-in value for Claude Channels', async () => {
931
- const ownerRunner = vi.fn(async () => {});
932
-
933
- await createGameCommand({
934
- ownerRunner,
935
- env: { [CLAWCLAW_ENABLE_CLAUDE_CHANNELS]: 'true' },
936
- }).parseAsync([
937
- 'node',
938
- 'game',
939
- 'start',
940
- '--agent-type',
941
- 'claude-code',
942
- ], { from: 'node' });
943
-
944
- expect(ownerRunner).toHaveBeenCalledWith(expect.any(Object), {
945
- forceExistingRuntime: false,
946
- });
947
- });
948
-
949
- it('adds the opt-in Channel adapter without removing another configured output', async () => {
950
- const ownerRunner = vi.fn(async () => {});
951
- const socket = process.platform === 'win32' ? 'desktop-wake-test' : '/tmp/desktop-wake-test.sock';
952
-
953
- await createGameCommand({
954
- ownerRunner,
955
- env: { [CLAWCLAW_ENABLE_CLAUDE_CHANNELS]: '1' },
956
- }).parseAsync([
957
- 'node',
958
- 'game',
959
- 'start',
960
- '--agent-type',
961
- 'claude-code',
962
- '--desktop-event-socket',
963
- socket,
964
- '--desktop-event-token',
965
- '0123456789abcdef0123456789abcdef',
966
- ], { from: 'node' });
967
-
968
- expect(ownerRunner).toHaveBeenCalledWith(expect.any(Object), {
969
- forceExistingRuntime: false,
970
- channelDelivery: true,
971
- desktopEvents: {
972
- socketPath: process.platform === 'win32'
973
- ? '\\\\.\\pipe\\desktop-wake-test'
974
- : '/tmp/desktop-wake-test.sock',
975
- token: '0123456789abcdef0123456789abcdef',
976
- },
977
- });
978
- });
979
-
980
- it('does not enable Channels for a non-Claude host', async () => {
981
- const ownerRunner = vi.fn(async () => {});
982
-
983
- await createGameCommand({
984
- ownerRunner,
985
- env: { [CLAWCLAW_ENABLE_CLAUDE_CHANNELS]: '1' },
986
- }).parseAsync([
987
- 'node',
988
- 'game',
989
- 'start',
990
- '--agent-type',
991
- 'openclaw',
992
- ], { from: 'node' });
993
-
994
- expect(ownerRunner).toHaveBeenCalledWith(expect.any(Object), {
995
- forceExistingRuntime: false,
996
- });
997
- });
998
-
999
- it('rejects an unpaired Desktop event IPC option before starting the Owner', async () => {
1000
- const ownerRunner = vi.fn(async () => {});
1001
- const socket = process.platform === 'win32' ? 'desktop-wake-test' : '/tmp/desktop-wake-test.sock';
1002
-
1003
- await expect(createGameCommand({ ownerRunner }).parseAsync([
1004
- 'node',
1005
- 'game',
1006
- 'start',
1007
- '--agent-type',
1008
- 'codex-desktop',
1009
- '--desktop-event-socket',
1010
- socket,
1011
- ], { from: 'node' })).rejects.toThrow(
1012
- '--desktop-event-socket and --desktop-event-token must be provided together.',
1013
- );
1014
- expect(ownerRunner).not.toHaveBeenCalled();
1015
- });
1016
- });
1017
-
1018
- describe('game room entry', () => {
1019
- it('exposes status, create-room, join-room, and start-room in game help', () => {
1020
- const help = createGameCommand().helpInformation();
1021
-
1022
- expect(help).toContain('status');
1023
- expect(help).toContain('create-room');
1024
- expect(help).toContain('join-room');
1025
- expect(help).toContain('start-room');
1026
- });
1027
-
1028
- it('passes create-room metadata and force to the Owner', async () => {
1029
- const ownerRunner = vi.fn(async () => {});
1030
-
1031
- await createGameCommand({ ownerRunner }).parseAsync([
1032
- 'node',
1033
- 'game',
1034
- 'create-room',
1035
- '--agent-type',
1036
- 'claude-code',
1037
- '--llm-model',
1038
- 'claude-opus-4-8',
1039
- '--force',
1040
- ], { from: 'node' });
1041
-
1042
- expect(ownerRunner).toHaveBeenCalledWith({
1043
- kind: 'create_room',
1044
- agentType: 'claude-code',
1045
- llmModel: 'claude-opus-4-8',
1046
- }, {
1047
- forceExistingRuntime: true,
1048
- });
1049
- });
1050
-
1051
- it('passes join-room metadata and force to the Owner', async () => {
1052
- const ownerRunner = vi.fn(async () => {});
1053
-
1054
- await createGameCommand({ ownerRunner }).parseAsync([
1055
- 'node',
1056
- 'game',
1057
- 'join-room',
1058
- '123456',
1059
- '--agent-type',
1060
- 'openclaw',
1061
- '--llm-model',
1062
- 'deepseek-v4-pro',
1063
- '--force',
1064
- ], { from: 'node' });
1065
-
1066
- expect(ownerRunner).toHaveBeenCalledWith({
1067
- kind: 'join_room',
1068
- roomCode: '123456',
1069
- agentType: 'openclaw',
1070
- llmModel: 'deepseek-v4-pro',
1071
- }, {
1072
- forceExistingRuntime: true,
1073
- });
1074
- });
1075
- });
1076
-
1077
- describe('game training', () => {
1078
- it.each([
1079
- { mode: 'simulation', roomType: 'training_simulation' },
1080
- { mode: 'dummy', roomType: 'training_dummy' },
1081
- ])('creates the $mode training lifecycle through the Owner', async ({ mode, roomType }) => {
1082
- const ownerRunner = vi.fn(async () => {});
1083
-
1084
- await createGameCommand({ ownerRunner }).parseAsync([
1085
- 'node',
1086
- 'game',
1087
- 'training',
1088
- 'create',
1089
- '--mode',
1090
- mode,
1091
- '--agent-type',
1092
- 'test-host',
1093
- '--llm-model',
1094
- 'test-model',
1095
- '--force',
1096
- ], { from: 'node' });
1097
-
1098
- expect(ownerRunner).toHaveBeenCalledWith({
1099
- kind: 'create_room',
1100
- roomType,
1101
- agentType: 'test-host',
1102
- llmModel: 'test-model',
1103
- }, {
1104
- forceExistingRuntime: true,
1105
- });
1106
- });
1107
-
1108
- it('routes mode and role configuration through the active Owner', async () => {
1109
- const stdout: string[] = [];
1110
- const exitCodes: number[] = [];
1111
- const ownerControl = vi.fn(async (
1112
- _profile: Pick<AuthProfile, 'apiKey' | 'runtimeAccountId'>,
1113
- type: string,
1114
- payload: Record<string, any> = {},
1115
- ) => ({ ok: true, type, result: { success: true, data: payload } }));
1116
- const dependencies: GameCommandDependencies = {
1117
- activeProfile: () => profile,
1118
- ownerControl,
1119
- io: {
1120
- writeStdout: (text) => stdout.push(text),
1121
- setExitCode: (code) => exitCodes.push(code),
1122
- },
1123
- };
1124
-
1125
- await createGameCommand(dependencies).parseAsync(
1126
- ['node', 'game', 'training', 'mode', 'dummy'],
1127
- { from: 'node' },
1128
- );
1129
- await createGameCommand(dependencies).parseAsync(
1130
- ['node', 'game', 'training', 'role-lock', '7'],
1131
- { from: 'node' },
1132
- );
1133
- await createGameCommand(dependencies).parseAsync(
1134
- ['node', 'game', 'training', 'role-unlock'],
1135
- { from: 'node' },
1136
- );
1137
-
1138
- expect(ownerControl.mock.calls.map(([, type, payload]) => ({ type, payload }))).toEqual([
1139
- { type: 'training_mode', payload: { room_type: 'training_dummy' } },
1140
- { type: 'training_role_lock', payload: { character_id: 7 } },
1141
- { type: 'training_role_clear', payload: {} },
1142
- ]);
1143
- expect(stdout.map((line) => JSON.parse(line).ok)).toEqual([true, true, true]);
1144
- expect(exitCodes).toEqual([0, 0, 0]);
1145
- });
1146
-
1147
- it('fails explicitly when configuration has no active training Owner', async () => {
1148
- const stdout: string[] = [];
1149
- const exitCodes: number[] = [];
1150
- const dependencies: GameCommandDependencies = {
1151
- activeProfile: () => profile,
1152
- ownerControl: vi.fn(async () => null),
1153
- io: {
1154
- writeStdout: (text) => stdout.push(text),
1155
- setExitCode: (code) => exitCodes.push(code),
1156
- },
1157
- };
1158
-
1159
- await createGameCommand(dependencies).parseAsync(
1160
- ['node', 'game', 'training', 'mode', 'simulation'],
1161
- { from: 'node' },
1162
- );
1163
-
1164
- expect(JSON.parse(stdout[0])).toMatchObject({
1165
- ok: false,
1166
- error: 'runtime_not_running',
1167
- });
1168
- expect(exitCodes).toEqual([1]);
1169
- });
1170
- });
1171
-
1172
- describe('game start-room', () => {
1173
- it('preserves a successful backend result and exits zero without a queue precheck', async () => {
1174
- const upstream = {
1175
- success: true,
1176
- data: { room_code: 'ROOM1', game_id: 'G1' },
1177
- };
1178
- const value = startRoomFixture(upstream);
1179
-
1180
- const output = await runStartRoom(value);
1181
-
1182
- expect(output).toEqual(upstream);
1183
- expect(value.client.getQueueStatus).not.toHaveBeenCalled();
1184
- expect(value.client.startRoom).toHaveBeenCalledOnce();
1185
- expect(value.exitCodes).toEqual([0]);
1186
- });
1187
-
1188
- it('preserves an HTTP 200 business failure and exits one', async () => {
1189
- const upstream = {
1190
- success: false,
1191
- error: {
1192
- code: 'NOT_ENOUGH_PLAYERS',
1193
- message: 'Need more players',
1194
- shortage: 2,
1195
- },
1196
- room_code: 'ROOM1',
1197
- };
1198
- const value = startRoomFixture(upstream);
1199
-
1200
- const output = await runStartRoom(value);
1201
- const { _ccl, ...root } = output;
1202
-
1203
- expect(root).toEqual(upstream);
1204
- expect(_ccl).toMatchObject({
1205
- schema: 'ccl.command-meta.v1',
1206
- command: 'ccl game start-room',
1207
- command_status: 'failure',
1208
- source: 'backend',
1209
- http_status: 200,
1210
- filtered_fields: [],
1211
- guidance: null,
1212
- });
1213
- expect(_ccl.command_id).toMatch(/^cmd_/);
1214
- expect(value.client.getQueueStatus).not.toHaveBeenCalled();
1215
- expect(value.exitCodes).toEqual([1]);
1216
- });
1217
-
1218
- it('preserves a structured non-2xx ApiError root and HTTP status', async () => {
1219
- const upstream = {
1220
- success: false,
1221
- error: { code: 'ROOM_COOLDOWN', message: 'Try again later' },
1222
- retry_after: 5,
1223
- };
1224
- const response = jsonTransportResponse(upstream, {
1225
- method: 'POST',
1226
- path: '/api/v1/room/start',
1227
- status: 409,
1228
- requestId: 'req-room-start',
1229
- });
1230
- const value = startRoomFixture(new ApiError(
1231
- 409,
1232
- JSON.stringify(upstream),
1233
- 'POST',
1234
- '/api/v1/room/start',
1235
- response,
1236
- ));
1237
-
1238
- const output = await runStartRoom(value);
1239
- const { _ccl, ...root } = output;
1240
-
1241
- expect(root).toEqual(upstream);
1242
- expect(_ccl).toMatchObject({
1243
- command_status: 'failure',
1244
- source: 'backend',
1245
- http_status: 409,
1246
- request_id: 'req-room-start',
1247
- });
1248
- expect(value.client.getQueueStatus).not.toHaveBeenCalled();
1249
- expect(value.exitCodes).toEqual([1]);
1250
- });
1251
- });