@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,250 +0,0 @@
1
- // src/lib/game-client.test.ts
2
- import { describe, it, expect, vi, afterEach } from 'vitest';
3
- import { GameClient } from './game-client.js';
4
-
5
- afterEach(() => { vi.restoreAllMocks(); });
6
-
7
- function makeClient(): GameClient {
8
- return new GameClient({ lobbyUrl: 'https://lobby.example', apiKey: 'key' });
9
- }
10
-
11
- describe('GameClient.joinQueue X-Agent-Type', () => {
12
- it('sends X-Agent-Type header when agentType is provided', async () => {
13
- let captured: any;
14
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
15
- captured = { url, headers: init.headers, body: init.body };
16
- return new Response('{"status":"queued"}', { status: 200 });
17
- }));
18
- await makeClient().joinQueue({ gameType: 'clawclaw', mode: 'competition', agentType: 'claude-code' });
19
- expect(captured.url).toBe('https://lobby.example/api/v1/queue/join');
20
- expect(captured.headers['X-Agent-Type']).toBe('claude-code');
21
- // mode still travels in the request body, not the header
22
- expect(JSON.parse(captured.body)).toEqual({ game_type: 'clawclaw', mode: 'competition' });
23
- });
24
-
25
- it('omits X-Agent-Type header when agentType is absent', async () => {
26
- let captured: any;
27
- vi.stubGlobal('fetch', vi.fn(async (_url: string, init: any) => {
28
- captured = init.headers;
29
- return new Response('{"status":"queued"}', { status: 200 });
30
- }));
31
- await makeClient().joinQueue({ gameType: 'clawclaw', mode: 'match' });
32
- expect('X-Agent-Type' in captured).toBe(false);
33
- });
34
-
35
- it('omits X-Agent-Type for the legacy string form', async () => {
36
- let captured: any;
37
- vi.stubGlobal('fetch', vi.fn(async (_url: string, init: any) => {
38
- captured = init.headers;
39
- return new Response('{"status":"queued"}', { status: 200 });
40
- }));
41
- await makeClient().joinQueue('clawclaw');
42
- expect('X-Agent-Type' in captured).toBe(false);
43
- });
44
- });
45
-
46
- describe('GameClient.joinQueue X-LLM-Model', () => {
47
- it('sends X-LLM-Model when provided', async () => {
48
- let captured: any;
49
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
50
- captured = { url, headers: init.headers, body: init.body };
51
- return new Response('{"status":"queued"}', { status: 200 });
52
- }));
53
- await makeClient().joinQueue({ gameType: 'clawclaw', agentType: 'claude-code', llmModel: 'claude-opus-4-8' });
54
- expect(captured.headers['X-Agent-Type']).toBe('claude-code');
55
- expect(captured.headers['X-LLM-Model']).toBe('claude-opus-4-8');
56
- // still travels in the request body only, not the headers
57
- expect(JSON.parse(captured.body)).toEqual({ game_type: 'clawclaw', mode: 'match' });
58
- });
59
-
60
- it('omits the header when not provided', async () => {
61
- let captured: any;
62
- vi.stubGlobal('fetch', vi.fn(async (_url: string, init: any) => {
63
- captured = init.headers;
64
- return new Response('{"status":"queued"}', { status: 200 });
65
- }));
66
- await makeClient().joinQueue({ gameType: 'clawclaw', mode: 'match' });
67
- expect('X-LLM-Model' in captured).toBe(false);
68
- });
69
- });
70
-
71
- describe('GameClient room entry metadata', () => {
72
- it('gets the current room status from the lobby', async () => {
73
- let captured: any;
74
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
75
- captured = { url, method: init.method };
76
- return new Response('{"success":true,"data":{"room_type":"casual"}}', { status: 200 });
77
- }));
78
-
79
- await makeClient().getRoomStatus();
80
-
81
- expect(captured).toEqual({
82
- url: 'https://lobby.example/api/v1/room/status',
83
- method: 'GET',
84
- });
85
- });
86
-
87
- it('sends agent/model headers while preserving create-room request bodies', async () => {
88
- const calls: Array<{ url: string; headers: Record<string, string>; body?: string }> = [];
89
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
90
- calls.push({ url, headers: init.headers, body: init.body });
91
- return new Response('{"success":true}', { status: 200 });
92
- }));
93
- const client = makeClient();
94
-
95
- await client.createRoom({
96
- agentType: 'claude-code',
97
- llmModel: 'claude-opus-4-8',
98
- });
99
- await client.createRoom({
100
- roomType: 'training_simulation',
101
- agentType: 'openclaw',
102
- llmModel: 'deepseek-v4-pro',
103
- });
104
-
105
- expect(calls[0]).toMatchObject({
106
- url: 'https://lobby.example/api/v1/room/create',
107
- headers: {
108
- 'X-Agent-Type': 'claude-code',
109
- 'X-LLM-Model': 'claude-opus-4-8',
110
- },
111
- body: undefined,
112
- });
113
- expect(calls[1]).toMatchObject({
114
- url: 'https://lobby.example/api/v1/room/create',
115
- headers: {
116
- 'X-Agent-Type': 'openclaw',
117
- 'X-LLM-Model': 'deepseek-v4-pro',
118
- },
119
- body: JSON.stringify({ room_type: 'training_simulation' }),
120
- });
121
- });
122
-
123
- it('sends agent/model headers when joining a room', async () => {
124
- let captured: any;
125
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: any) => {
126
- captured = { url, headers: init.headers, body: init.body };
127
- return new Response('{"success":true}', { status: 200 });
128
- }));
129
-
130
- await makeClient().joinRoom('123456', {
131
- agentType: 'claude-code',
132
- llmModel: 'claude-opus-4-8',
133
- });
134
-
135
- expect(captured).toMatchObject({
136
- url: 'https://lobby.example/api/v1/room/join',
137
- headers: {
138
- 'X-Agent-Type': 'claude-code',
139
- 'X-LLM-Model': 'claude-opus-4-8',
140
- },
141
- body: JSON.stringify({ room_code: '123456' }),
142
- });
143
- });
144
- });
145
-
146
- describe('GameClient GameSync resume ownership', () => {
147
- const resumeState = {
148
- gameId: 'G1',
149
- seq: 12,
150
- tick: 120,
151
- locale: 'zh-CN' as const,
152
- state: { phase: 'wandering', you: { x: 10, y: 20 } },
153
- };
154
-
155
- it('keeps a same-game baseline across reconcile and drops it on a game-id change', () => {
156
- const client = makeClient() as any;
157
- client.gameSyncResumeState = structuredClone(resumeState);
158
-
159
- client.setExpectedGameSyncGameId('G1');
160
- client.disconnectWs({ preserveGameSyncResumeState: true });
161
- expect(client.gameSyncResumeState).toEqual(resumeState);
162
- expect(client.expectedGameSyncGameId).toBe('G1');
163
-
164
- client.setExpectedGameSyncGameId('G2');
165
- expect(client.gameSyncResumeState).toBeUndefined();
166
- expect(client.expectedGameSyncGameId).toBe('G2');
167
- });
168
-
169
- it('clears both baseline and identity on a terminal disconnect', () => {
170
- const client = makeClient() as any;
171
- client.gameSyncResumeState = structuredClone(resumeState);
172
- client.setExpectedGameSyncGameId('G1');
173
-
174
- client.disconnectWs();
175
-
176
- expect(client.gameSyncResumeState).toBeUndefined();
177
- expect(client.expectedGameSyncGameId).toBeUndefined();
178
- });
179
-
180
- it('proxies a Source commit to WsClient and retains only that committed baseline', () => {
181
- const client = makeClient() as any;
182
- const acknowledge = vi.fn();
183
- client.setExpectedGameSyncGameId('G1');
184
- client.ws = {
185
- acknowledge,
186
- resumeState,
187
- };
188
-
189
- client.acknowledgeGameSync('frame-token', true);
190
-
191
- expect(acknowledge).toHaveBeenCalledWith('frame-token', true);
192
- expect(client.gameSyncResumeState).toEqual(resumeState);
193
- });
194
- });
195
-
196
- describe('GameClient training room API', () => {
197
- it('sends the exact room type when creating training and keeps casual create bodyless', async () => {
198
- const calls: Array<{ url: string; method: string; body?: string }> = [];
199
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: RequestInit) => {
200
- calls.push({ url, method: String(init.method), body: init.body as string | undefined });
201
- return new Response('{"success":true}', { status: 200 });
202
- }));
203
- const client = makeClient();
204
-
205
- await client.createRoom('training_simulation');
206
- await client.createRoom();
207
-
208
- expect(calls[0]).toEqual({
209
- url: 'https://lobby.example/api/v1/room/create',
210
- method: 'POST',
211
- body: JSON.stringify({ room_type: 'training_simulation' }),
212
- });
213
- expect(calls[1]).toEqual({
214
- url: 'https://lobby.example/api/v1/room/create',
215
- method: 'POST',
216
- body: undefined,
217
- });
218
- });
219
-
220
- it('uses PUT/DELETE for training mode and role lock configuration', async () => {
221
- const calls: Array<{ url: string; method: string; body?: string }> = [];
222
- vi.stubGlobal('fetch', vi.fn(async (url: string, init: RequestInit) => {
223
- calls.push({ url, method: String(init.method), body: init.body as string | undefined });
224
- return new Response('{"success":true}', { status: 200 });
225
- }));
226
- const client = makeClient();
227
-
228
- await client.setTrainingRoomMode('training_dummy');
229
- await client.setTrainingRoleLock(7);
230
- await client.clearTrainingRoleLock();
231
-
232
- expect(calls).toEqual([
233
- {
234
- url: 'https://lobby.example/api/v1/room/training/mode',
235
- method: 'PUT',
236
- body: JSON.stringify({ room_type: 'training_dummy' }),
237
- },
238
- {
239
- url: 'https://lobby.example/api/v1/room/training/role-lock',
240
- method: 'PUT',
241
- body: JSON.stringify({ character_id: 7 }),
242
- },
243
- {
244
- url: 'https://lobby.example/api/v1/room/training/role-lock',
245
- method: 'DELETE',
246
- body: undefined,
247
- },
248
- ]);
249
- });
250
- });
@@ -1,301 +0,0 @@
1
- import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
- import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
4
- import { afterEach, describe, expect, it } from 'vitest';
5
- import {
6
- CLAWCLAW_ROLE_IDS,
7
- DEFAULT_BEHAVIOR_IDLE_MS,
8
- NPM_ROLE_FALLBACK_BEHAVIORS,
9
- defaultGameplayConfig,
10
- parseGameplayConfig,
11
- readGameplayConfig,
12
- updateGameplayConfig,
13
- } from './gameplay-config.js';
14
- import { getUserDataGameplayConfigFile } from './user-data.js';
15
-
16
- const dirs: string[] = [];
17
- const UNIFIED_FIELDS = [
18
- 'disabled_perception_modules',
19
- 'fallback_behaviors',
20
- 'disabled_behaviors',
21
- 'idle_ms',
22
- 'triggers',
23
- ];
24
-
25
- afterEach(() => {
26
- for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
27
- });
28
-
29
- function workspace(): string {
30
- const dir = mkdtempSync(join(tmpdir(), 'ccl-gameplay-config-'));
31
- dirs.push(dir);
32
- return dir;
33
- }
34
-
35
- function writeExistingConfig(dir: string, value: unknown): string {
36
- readGameplayConfig(dir);
37
- const path = getUserDataGameplayConfigFile(dir);
38
- writeFileSync(path, JSON.stringify(value, null, 2), 'utf8');
39
- return path;
40
- }
41
-
42
- function legacyDefaults(): Record<string, string | null> {
43
- return { ...NPM_ROLE_FALLBACK_BEHAVIORS };
44
- }
45
-
46
- function legacyConfig(fallbackIdleMs: unknown = 8_000): Record<string, unknown> {
47
- return {
48
- default_strategies: legacyDefaults(),
49
- disabled_strategies: ['runtime-task-demo'],
50
- disabled_perception_modules: [],
51
- disabled_intents: [],
52
- fallback_idle_ms: fallbackIdleMs,
53
- };
54
- }
55
-
56
- describe('gameplay config', () => {
57
- it('creates only the unified public fields with a 500ms default idle timeout', () => {
58
- const dir = workspace();
59
- const config = readGameplayConfig(dir);
60
-
61
- expect(Object.keys(config)).toEqual(UNIFIED_FIELDS);
62
- expect(config).toEqual({
63
- disabled_perception_modules: [],
64
- fallback_behaviors: NPM_ROLE_FALLBACK_BEHAVIORS,
65
- disabled_behaviors: [],
66
- idle_ms: DEFAULT_BEHAVIOR_IDLE_MS,
67
- triggers: {},
68
- });
69
- expect(Object.keys(config.fallback_behaviors)).toEqual(CLAWCLAW_ROLE_IDS);
70
- expect(existsSync(getUserDataGameplayConfigFile(dir))).toBe(true);
71
- expect(Object.keys(JSON.parse(
72
- readFileSync(getUserDataGameplayConfigFile(dir), 'utf8'),
73
- ))).toEqual(UNIFIED_FIELDS);
74
- });
75
-
76
- it('accepts only complete unified public config objects', () => {
77
- const base = defaultGameplayConfig();
78
- const missing = { ...base } as Record<string, unknown>;
79
- delete missing.triggers;
80
-
81
- expect(() => parseGameplayConfig({ ...base, default_strategies: legacyDefaults() }))
82
- .toThrow('contains unknown fields: default_strategies');
83
- expect(() => parseGameplayConfig({ ...base, surprise: true }))
84
- .toThrow('contains unknown fields: surprise');
85
- expect(() => parseGameplayConfig(missing))
86
- .toThrow('triggers must be an object');
87
- expect(() => parseGameplayConfig({ ...base, disabled_perception_modules: null }))
88
- .toThrow('disabled_perception_modules must be an array');
89
- expect(() => parseGameplayConfig({ ...base, fallback_behaviors: null }))
90
- .toThrow('fallback_behaviors must be an object');
91
- expect(() => parseGameplayConfig({ ...base, disabled_behaviors: null }))
92
- .toThrow('disabled_behaviors must be an array');
93
- expect(() => parseGameplayConfig({ ...base, idle_ms: null }))
94
- .toThrow('idle_ms must be an integer from 0 to 60000');
95
- expect(() => parseGameplayConfig({ ...base, triggers: null }))
96
- .toThrow('triggers must be an object');
97
- });
98
-
99
- it('requires exactly every role and a Behavior id or null for each fallback', () => {
100
- const base = defaultGameplayConfig();
101
- const missingRole = { ...base.fallback_behaviors } as Record<string, unknown>;
102
- delete missingRole.shrimp_generic;
103
- const inheritedRole = Object.assign(
104
- Object.create({ shrimp_generic: 'task-report' }) as Record<string, unknown>,
105
- missingRole,
106
- );
107
-
108
- expect(() => parseGameplayConfig({ ...base, fallback_behaviors: missingRole }))
109
- .toThrow('fallback_behaviors.shrimp_generic');
110
- expect(() => parseGameplayConfig({ ...base, fallback_behaviors: inheritedRole }))
111
- .toThrow('fallback_behaviors must be an object');
112
- expect(() => parseGameplayConfig({
113
- ...base,
114
- fallback_behaviors: { ...base.fallback_behaviors, extra_role: 'task-report' },
115
- })).toThrow('Unknown role in user-data/gameplay.json fallback_behaviors: extra_role');
116
- expect(() => parseGameplayConfig({
117
- ...base,
118
- fallback_behaviors: { ...base.fallback_behaviors, shrimp_generic: false },
119
- })).toThrow('fallback_behaviors.shrimp_generic');
120
- expect(parseGameplayConfig({
121
- ...base,
122
- fallback_behaviors: { ...base.fallback_behaviors, shrimp_generic: null },
123
- }).fallback_behaviors.shrimp_generic).toBeNull();
124
- });
125
-
126
- it.each([-1, 60_001, 500.5, '500'])('rejects invalid unified idle value %j', (value) => {
127
- const base = defaultGameplayConfig();
128
- expect(() => parseGameplayConfig({ ...base, idle_ms: value })).toThrow(
129
- 'idle_ms must be an integer from 0 to 60000',
130
- );
131
- });
132
-
133
- it('migrates a legacy file once and immediately removes all legacy fields', () => {
134
- const dir = workspace();
135
- const defaults = legacyDefaults();
136
- defaults.shrimp_generic = 'custom-shrimp';
137
- const path = writeExistingConfig(dir, {
138
- default_strategies: defaults,
139
- disabled_strategies: ['runtime-task-demo', 'custom.long', 'custom.long'],
140
- disabled_perception_modules: ['visual.removed'],
141
- disabled_intents: ['go_to', 'go_to'],
142
- fallback_idle_ms: 8_000,
143
- });
144
-
145
- const config = readGameplayConfig(dir);
146
- const persisted = JSON.parse(readFileSync(path, 'utf8'));
147
-
148
- expect(config.fallback_behaviors.shrimp_generic).toBe('custom-shrimp');
149
- expect(config.disabled_perception_modules).toEqual(['visual.removed']);
150
- expect(config.disabled_behaviors).toEqual(['custom.long', 'go_to']);
151
- expect(config.idle_ms).toBe(500);
152
- expect(config.triggers).toEqual({});
153
- expect(Object.keys(config)).toEqual(UNIFIED_FIELDS);
154
- expect(Object.keys(persisted)).toEqual(UNIFIED_FIELDS);
155
- expect(persisted).toEqual(config);
156
- });
157
-
158
- it('gives unified values precedence while merging legacy disabled ids', () => {
159
- const dir = workspace();
160
- const fallbackBehaviors = {
161
- ...NPM_ROLE_FALLBACK_BEHAVIORS,
162
- shrimp_generic: null,
163
- };
164
- const oldDefaults = legacyDefaults();
165
- oldDefaults.shrimp_generic = 'old-shrimp';
166
- writeExistingConfig(dir, {
167
- disabled_perception_modules: ['visual.current'],
168
- fallback_behaviors: fallbackBehaviors,
169
- disabled_behaviors: ['unified.behavior', 'shared.behavior'],
170
- idle_ms: 750,
171
- triggers: {
172
- 'danger.followed': {
173
- enabled: true,
174
- behavior: 'evade',
175
- reflex_priority: 20,
176
- },
177
- },
178
- default_strategies: oldDefaults,
179
- disabled_strategies: ['runtime-task-demo', 'legacy.strategy', 'shared.behavior'],
180
- disabled_intents: ['legacy.intent', 'shared.behavior'],
181
- fallback_idle_ms: 10_000,
182
- });
183
-
184
- const config = readGameplayConfig(dir);
185
-
186
- expect(config.fallback_behaviors.shrimp_generic).toBeNull();
187
- expect(config.disabled_behaviors).toEqual([
188
- 'unified.behavior',
189
- 'shared.behavior',
190
- 'legacy.strategy',
191
- 'legacy.intent',
192
- ]);
193
- expect(config.idle_ms).toBe(750);
194
- expect(config.triggers['danger.followed']).toEqual({
195
- enabled: true,
196
- behavior: 'evade',
197
- reflex_priority: 20,
198
- });
199
- });
200
-
201
- it('maps the legacy runtime fallback sentinel to official Behavior fallbacks', () => {
202
- const dir = workspace();
203
- writeExistingConfig(dir, {
204
- ...legacyConfig(),
205
- default_strategies: Object.fromEntries(
206
- CLAWCLAW_ROLE_IDS.map((role) => [role, 'runtime-task-demo']),
207
- ),
208
- });
209
-
210
- expect(readGameplayConfig(dir).fallback_behaviors)
211
- .toEqual(NPM_ROLE_FALLBACK_BEHAVIORS);
212
- });
213
-
214
- it.each([
215
- [0, 0],
216
- [750, 750],
217
- [8_000, 500],
218
- [10_000, 10_000],
219
- [60_000, 60_000],
220
- ])('migrates legacy fallback idle %i to unified idle %i', (legacyValue, expected) => {
221
- const dir = workspace();
222
- writeExistingConfig(dir, legacyConfig(legacyValue));
223
-
224
- expect(readGameplayConfig(dir).idle_ms).toBe(expected);
225
- });
226
-
227
- it('uses the unified 500ms default when a legacy file omitted its idle field', () => {
228
- const dir = workspace();
229
- const legacy = legacyConfig();
230
- delete legacy.fallback_idle_ms;
231
- writeExistingConfig(dir, legacy);
232
-
233
- expect(readGameplayConfig(dir).idle_ms).toBe(500);
234
- });
235
-
236
- it.each([-1, 60_001, 500.5, '8000', null])(
237
- 'rejects invalid legacy fallback idle value %j',
238
- (value) => {
239
- const dir = workspace();
240
- writeExistingConfig(dir, legacyConfig(value));
241
-
242
- expect(() => readGameplayConfig(dir)).toThrow(
243
- 'fallback_idle_ms must be an integer from 0 to 60000',
244
- );
245
- },
246
- );
247
-
248
- it('rejects unknown fields even while migrating a legacy file', () => {
249
- const dir = workspace();
250
- writeExistingConfig(dir, { ...legacyConfig(), surprise: true });
251
-
252
- expect(() => readGameplayConfig(dir)).toThrow('contains unknown fields: surprise');
253
- });
254
-
255
- it('updates and normalizes only unified fields', () => {
256
- const dir = workspace();
257
- const config = updateGameplayConfig((current) => {
258
- current.disabled_perception_modules = ['visual.removed', 'visual.removed'];
259
- current.fallback_behaviors.shrimp_generic = null;
260
- current.disabled_behaviors = ['custom.behavior', 'custom.behavior'];
261
- current.idle_ms = 1_000;
262
- current.triggers = {
263
- 'danger.followed': {
264
- enabled: true,
265
- behavior: 'evade',
266
- cooldown_ms: 250,
267
- },
268
- };
269
- }, dir);
270
-
271
- expect(Object.keys(config)).toEqual(UNIFIED_FIELDS);
272
- expect(config.disabled_perception_modules).toEqual(['visual.removed']);
273
- expect(config.fallback_behaviors.shrimp_generic).toBeNull();
274
- expect(config.disabled_behaviors).toEqual(['custom.behavior']);
275
- expect(config.idle_ms).toBe(1_000);
276
- expect(config.triggers['danger.followed']).toEqual({
277
- enabled: true,
278
- behavior: 'evade',
279
- cooldown_ms: 250,
280
- });
281
- });
282
-
283
- it('reads a complete unified file without rewriting it', () => {
284
- const dir = workspace();
285
- const path = writeExistingConfig(dir, defaultGameplayConfig());
286
- const original = `${JSON.stringify(defaultGameplayConfig(), null, 4)}\n`;
287
- writeFileSync(path, original, 'utf8');
288
-
289
- expect(readGameplayConfig(dir)).toEqual(defaultGameplayConfig());
290
- expect(readFileSync(path, 'utf8')).toBe(original);
291
- });
292
-
293
- it('reports malformed JSON without replacing the file', () => {
294
- const dir = workspace();
295
- const path = writeExistingConfig(dir, defaultGameplayConfig());
296
- writeFileSync(path, '{ bad json', 'utf8');
297
-
298
- expect(() => readGameplayConfig(dir)).toThrow(`Invalid JSON in ${path}`);
299
- expect(readFileSync(path, 'utf8')).toBe('{ bad json');
300
- });
301
- });
@@ -1,130 +0,0 @@
1
- import { mkdtempSync, readFileSync, writeFileSync, existsSync, readdirSync } from 'fs';
2
- import { tmpdir } from 'os';
3
- import { dirname, join } from 'path';
4
- import { describe, expect, it } from 'vitest';
5
- import { runHostConfigSetup, unionArrayField, type HostConfigPatcher } from './host-config-patcher.js';
6
-
7
- function tmpConfig(initial: unknown): string {
8
- const dir = mkdtempSync(join(tmpdir(), 'host-cfg-'));
9
- const p = join(dir, 'config.json');
10
- writeFileSync(p, JSON.stringify(initial, null, 2));
11
- return p;
12
- }
13
-
14
- const dummyHost: HostConfigPatcher<{ value: string }> = {
15
- hostName: 'dummy',
16
- resolveConfigPath: () => '/tmp/never-used',
17
- computePatch: (current, opts) => {
18
- const cur = (current as Record<string, unknown> | null) ?? {};
19
- const before = (cur.values as string[] | undefined) ?? [];
20
- if (before.includes(opts.value)) return { next: cur, changes: [], warnings: [] };
21
- return {
22
- next: { ...cur, values: [...before, opts.value] },
23
- changes: [`add ${opts.value} to values`],
24
- warnings: [],
25
- };
26
- },
27
- };
28
-
29
- describe('runHostConfigSetup', () => {
30
- it('prints recommended patch in --print mode without touching disk', () => {
31
- const r = runHostConfigSetup(dummyHost, { value: 'x' }, { print: true });
32
- expect(r.exitCode).toBe(0);
33
- expect(r.output.join('\n')).toContain('"values"');
34
- });
35
-
36
- it('reports missing config file gracefully', () => {
37
- const r = runHostConfigSetup(dummyHost, { value: 'x' }, { configPath: '/no/such/file.json' });
38
- expect(r.exitCode).toBe(0);
39
- expect(r.output.some((l) => l.includes('not found'))).toBe(true);
40
- });
41
-
42
- it('reports malformed JSON with exit 1', () => {
43
- const dir = mkdtempSync(join(tmpdir(), 'host-cfg-bad-'));
44
- const p = join(dir, 'config.json');
45
- writeFileSync(p, '{ not: valid json');
46
- const r = runHostConfigSetup(dummyHost, { value: 'x' }, { configPath: p });
47
- expect(r.exitCode).toBe(1);
48
- expect(r.output.join('\n')).toMatch(/Failed to parse/);
49
- });
50
-
51
- it('returns exit 2 with diff in dry-run when changes pending', () => {
52
- const p = tmpConfig({ values: ['a'] });
53
- const r = runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p });
54
- expect(r.exitCode).toBe(2);
55
- const txt = r.output.join('\n');
56
- expect(txt).toMatch(/Pending changes/);
57
- expect(txt).toMatch(/Re-run with -y to apply/);
58
- // file unchanged
59
- expect(JSON.parse(readFileSync(p, 'utf-8'))).toEqual({ values: ['a'] });
60
- });
61
-
62
- it('returns exit 0 no-op when already up to date', () => {
63
- const p = tmpConfig({ values: ['a'] });
64
- const r = runHostConfigSetup(dummyHost, { value: 'a' }, { configPath: p });
65
- expect(r.exitCode).toBe(0);
66
- expect(r.output.join('\n')).toMatch(/already up to date/);
67
- });
68
-
69
- it('applies changes atomically with backup when -y', () => {
70
- const p = tmpConfig({ values: ['a'] });
71
- const r = runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true });
72
- expect(r.exitCode).toBe(0);
73
- expect(JSON.parse(readFileSync(p, 'utf-8'))).toEqual({ values: ['a', 'b'] });
74
- const files = readdirSync(dirname(p));
75
- expect(files.some((f) => f.startsWith('config.json.bak.'))).toBe(true);
76
- });
77
-
78
- it('--no-backup skips backup file', () => {
79
- const p = tmpConfig({ values: ['a'] });
80
- const r = runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true, backup: false });
81
- expect(r.exitCode).toBe(0);
82
- const files = readdirSync(dirname(p));
83
- expect(files.some((f) => f.startsWith('config.json.bak.'))).toBe(false);
84
- });
85
-
86
- it('does not leave .tmp file behind on success', () => {
87
- const p = tmpConfig({ values: ['a'] });
88
- runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true, backup: false });
89
- const files = readdirSync(dirname(p));
90
- expect(files.some((f) => f.includes('.tmp.'))).toBe(false);
91
- });
92
-
93
- it('preserves CRLF line endings when original file uses CRLF', () => {
94
- const dir = mkdtempSync(join(tmpdir(), 'host-cfg-crlf-'));
95
- const p = join(dir, 'config.json');
96
- writeFileSync(p, '{\r\n "values": [\r\n "a"\r\n ]\r\n}\r\n');
97
- runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true, backup: false });
98
- const after = readFileSync(p, 'utf-8');
99
- expect(after.includes('\r\n')).toBe(true);
100
- expect(after.replace(/\r\n/g, '<EOL>').includes('\n')).toBe(false);
101
- });
102
-
103
- it('preserves LF line endings when original file uses LF', () => {
104
- const dir = mkdtempSync(join(tmpdir(), 'host-cfg-lf-'));
105
- const p = join(dir, 'config.json');
106
- writeFileSync(p, '{\n "values": [\n "a"\n ]\n}\n');
107
- runHostConfigSetup(dummyHost, { value: 'b' }, { configPath: p, yes: true, backup: false });
108
- const after = readFileSync(p, 'utf-8');
109
- expect(after.includes('\r\n')).toBe(false);
110
- });
111
- });
112
-
113
- describe('unionArrayField', () => {
114
- it('creates new array when field missing', () => {
115
- expect(unionArrayField(undefined, 'x')).toEqual({ next: ['x'], added: true });
116
- });
117
-
118
- it('returns warning when existing value is not an array', () => {
119
- const r = unionArrayField('not-an-array', 'x');
120
- expect(r).toEqual({ warning: 'existing value is not an array, refusing to overwrite' });
121
- });
122
-
123
- it('returns added=false when entry already present', () => {
124
- expect(unionArrayField(['a', 'b'], 'a')).toEqual({ next: ['a', 'b'], added: false });
125
- });
126
-
127
- it('appends entry when missing from array', () => {
128
- expect(unionArrayField(['a'], 'b')).toEqual({ next: ['a', 'b'], added: true });
129
- });
130
- });