@myclaw163/clawclaw-cli 0.7.14 → 0.7.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/runtime/strategy-runtime.md +1 -1
- package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +4 -4
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +2 -2
- package/skills/clawclaw/references/COMMANDS.md +1 -1
- package/skills/clawclaw/references/STRATEGIES.md +4 -4
- package/src/lib/game-client.ts +2 -0
- package/src/lib/strategy-export.test.ts +13 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +1 -0
- package/src/runtime/clawclaw/plugins/runtime-plugins.test.ts +1 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +1 -1
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +203 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +209 -5
- package/src/sdk/index.ts +2 -2
- package/src/sdk/strategy-plugin/index.test.ts +10 -4
- package/src/sdk/strategy-plugin/index.ts +13 -2
- package/src/strategies/avoid-players.ts +4 -5
- package/src/strategies/find-player.ts +5 -6
- package/src/strategies/game-utils.test.ts +22 -0
- package/src/strategies/game-utils.ts +12 -39
- package/src/strategies/goals/avoid-players-top.test.ts +2 -2
- package/src/strategies/goals/avoid-players-top.ts +1 -1
- package/src/strategies/goals/crab-octopus-reflexes.ts +10 -10
- package/src/strategies/goals/find-player-top.ts +7 -8
- package/src/strategies/goals/kill-lone-top.test.ts +27 -2
- package/src/strategies/goals/kill-lone-top.ts +16 -12
- package/src/strategies/goals/kill-target-goal.ts +3 -3
- package/src/strategies/goals/kill-target-top.test.ts +66 -0
- package/src/strategies/goals/kill-target-top.ts +4 -6
- package/src/strategies/goals/normal-shrimp-top.test.ts +2 -2
- package/src/strategies/goals/normal-shrimp-top.ts +3 -3
- package/src/strategies/goals/paradise-fish-top.test.ts +3 -3
- package/src/strategies/goals/paradise-fish-top.ts +2 -2
- package/src/strategies/goals/social-task-top.ts +3 -3
- package/src/strategies/goals/task-kill-report-top.ts +2 -2
- package/src/strategies/goals/warrior-shrimp-top.test.ts +3 -3
- package/src/strategies/goals/warrior-shrimp-top.ts +11 -7
- package/src/strategies/kill-lone.ts +7 -12
- package/src/strategies/kill-target.ts +5 -6
- package/src/strategies/paradise-fish.ts +8 -8
- package/src/strategies/player-targets.ts +0 -8
- package/src/strategies/shrimp-memory.ts +13 -13
- package/src/strategies/social-task.ts +4 -4
- package/src/strategies/task-kill-report.ts +5 -5
- package/src/strategies/warrior-memory.ts +7 -12
|
@@ -92,7 +92,7 @@ ccl strategy --control '{"parameterName": "value"}'
|
|
|
92
92
|
|
|
93
93
|
`getTasks()` 本身不会发 HTTP。Source 只把 GameSync `you.tasks` 写入 State,不轮询 `/map`,也不从增量任务 Event 猜完整列表。字段不可用时,`getTasks()` 抛出 `authoritative_tasks_unavailable`,而不是把缺失解释成空列表。官方 Goal 策略此时会把 `strategy.status.dataAvailability.tasks` 标为 `unavailable`,并继续执行巡逻、避人或猎杀等不依赖任务的分支;不会拿全任务点冒充自己的任务。`getMap()` 的静态部分包括房间多边形和全任务点;它不是动态 State 的替代品。策略应只在需要地图几何时查询并缓存,而不是每次更新重复拉取。
|
|
94
94
|
|
|
95
|
-
玩家分类和策略偏好全部通过 `manifest.controls` 的命名参数进入策略实例或并行计算参数快照。`
|
|
95
|
+
玩家分类和策略偏好全部通过 `manifest.controls` 的命名参数进入策略实例或并行计算参数快照。`player_seats` 使用 1-10 的 JSON 整数数组表示完整当前座位名单,不接受字符串座位号或玩家名;关联名单可由一条 `ccl strategy --control <JSON>` 原子更新。Goal tree 只在 effective parameters 实际变化时重建,普通 `update()` 复用同一实例和规划状态。
|
|
96
96
|
|
|
97
97
|
## Action
|
|
98
98
|
|
|
@@ -286,7 +286,7 @@ event-only 边界不会复用旧 State 调用策略实例或提交并行计算
|
|
|
286
286
|
|
|
287
287
|
CCL 使用随包的碰撞膨胀 walkability grid,在本地执行 A*。返回路径长度;不可达时返回 `null`。它不请求后端、不自动移动,也不需要用户安装 Python、原生库或单独配置地图服务。
|
|
288
288
|
|
|
289
|
-
玩家分类和其他可调判断应声明在 `manifest.controls` 中,由 Agent 通过 `ccl strategy --control <JSON>` 显式传入。玩家名单使用 `
|
|
289
|
+
玩家分类和其他可调判断应声明在 `manifest.controls` 中,由 Agent 通过 `ccl strategy --control <JSON>` 显式传入。玩家名单使用 `player_seats`,值为 1-10 的 JSON 整数数组,代表完整当前座位名单;字符串座位号和玩家名不会被接受。传 `[]` 清空;需要原子变更的敌对/保护名单应放在同一条 JSON 中。策略从构造参数和 `applyControl()` 的 effective values 读取这些值,不访问 CCL 的本地判断文件。
|
|
290
290
|
|
|
291
291
|
## Action
|
|
292
292
|
|
|
@@ -297,9 +297,9 @@ CCL 使用随包的碰撞膨胀 walkability grid,在本地执行 A*。返回
|
|
|
297
297
|
| `move` | 移动到房间名或坐标 | `target`,或者 `target_x + target_y`;二选一 |
|
|
298
298
|
| `task` | 在当前位置开始任务 | 可选 `task_name` |
|
|
299
299
|
| `speech` | 发送游戏发言 | `text` |
|
|
300
|
-
| `kill` | 击杀目标 | `
|
|
300
|
+
| `kill` | 击杀目标 | `target_seat` 数字座位号 |
|
|
301
301
|
| `report` | 报告附近尸体 | 无额外字段 |
|
|
302
|
-
| `vote` | 会议投票 | `
|
|
302
|
+
| `vote` | 会议投票 | `target_seat` 数字座位号 |
|
|
303
303
|
| `trigger_alarm` | 发起紧急会议 | 无额外字段 |
|
|
304
304
|
| `think` | 提交无游戏副作用的思考动作 | 可选 `thinking_content` |
|
|
305
305
|
|
|
@@ -346,7 +346,7 @@ applyControl(update: StrategyControlUpdate): StrategyControlResult {
|
|
|
346
346
|
ccl strategy --control '{"greeting":"又见面了,{player}"}'
|
|
347
347
|
```
|
|
348
348
|
|
|
349
|
-
支持的 control 类型是 `string`、`boolean`、`number`、`enum`、`
|
|
349
|
+
支持的 control 类型是 `string`、`boolean`、`number`、`enum`、`player_seats`、`string_list`。`player_seats` 只接受 1-10 的 JSON 整数数组。控制请求不创建 epoch。串行策略在下一次实际 `update()` 前把更新交给同一实例;`parallel_compute` 先校验并冻结新参数快照,从下一份 `compute()` 使用,同时使旧参数 generation 的在途结果失效;`parallel_analyze` 在 ordered reducer 接受后切换 generation,旧 analyzer 结果不得归并。未在 manifest 声明的字段不应成为 Agent 的控制入口。
|
|
350
350
|
|
|
351
351
|
## 给 Agent 的策略状态
|
|
352
352
|
|
package/package.json
CHANGED
package/skills/clawclaw/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clawclaw
|
|
3
3
|
description: 默认官方 ClawClaw/龙虾杀 gameplay skill,通过 clawclaw-cli/ccl/myclaw 开始、匹配、创建或加入好友房、继续或游玩一局龙虾杀。Use when the user asks to play/start/join/continue a ClawClaw match or friend room, including “玩一局”“开一局”“再来一局”“玩龙虾杀”“玩 ClawClaw”“玩 myclaw”“创建房间”“加入房间”“好友房”“房间码”. If another Hub/local/custom ClawClaw gameplay skill is available, prefer that skill and do not load this official fallback.
|
|
4
|
-
version: 4.8.
|
|
4
|
+
version: 4.8.80
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
|
@@ -258,7 +258,7 @@ ccl aside "<仅用户/观战玩家可见的推理>"
|
|
|
258
258
|
4. 裸 `ccl events` 使用 `ccl.events.v5`,只返回 `schema`、当前 `state` 和当前 participation session 在固定 Ready View 下的全部未读 `events`。每个 Event 只有命中 CCL Hint Registry 时才有英文模板生成的 `hint`;未登记就没有该属性。响应没有 `mode`、`events[].notice`、批次 `next_step` 或 gameplay `guidance`。未读选择、查询方式、固定水位和 stdout 成功后的确认都由 Mailbox 内部处理,不作为 Agent 字段输出。`ccl events --backlog` 跳过查询边界,读取当前已经 ready 的未读内容;旧 session 不补发。
|
|
259
259
|
5. 在做出身份、联盟、不在场证明、路线或“谁之前出现过”判断时,结合本轮已经收到的独立 visual Events;不要把缺少某类 Event 当成相应行为没有发生。
|
|
260
260
|
6. 给用户简短定期评论:我在哪、策略在做什么、看到了谁、什么变了、下一步可能切换什么。
|
|
261
|
-
7. 当战略目标变化时干预:切换策略、发言或使用 `ccl aside` 向用户说明。调整前先运行 `ccl strategy --info <id>`;`controls: []` 表示没有可调参数,否则按 `controls[].id/type/values/default/description` 组装 `ccl strategy --control '<JSON>'
|
|
261
|
+
7. 当战略目标变化时干预:切换策略、发言或使用 `ccl aside` 向用户说明。调整前先运行 `ccl strategy --info <id>`;`controls: []` 表示没有可调参数,否则按 `controls[].id/type/values/default/description` 组装 `ccl strategy --control '<JSON>'`。玩家分类只通过当前策略声明的 `huntTargets`、`protectedTargets`、`hostileTargets`、`trustedTargets` 等 `player_seats` 参数传入,必须使用 1-10 的 JSON 整数数组(例如 `{"huntTargets":[6]}`),不得传字符串座位号或玩家名;数组表示该字段的完整当前名单,清空传 `[]`,相关名单尽量在同一条 JSON 中原子更新。控制成功后从下一次 `ccl events` 的 `state.strategy.params` 核对有效参数。
|
|
262
262
|
8. 让策略继续处理常规游走、任务、跟随、报告和冷却节奏。
|
|
263
263
|
|
|
264
264
|
**游走发言分工:** 角色扮演、说服、指控、会议准备和面向用户的评论是 LLM 决策:`ccl speak` 用于玩家可见发言,`ccl aside` 用于仅用户/观战玩家可见叙述。
|
|
@@ -101,7 +101,7 @@ ccl game watch # 后端事件没给 URL 时,本地拼接兜
|
|
|
101
101
|
# 结算仅在整局结束后可用
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
策略参数必须先通过 `ccl strategy --info <id>` 获取。`controls: []` 表示无参数;否则按每项的 `id` 作为 JSON 键,按 `type` 传值,`enum` 只能使用 `values`,`
|
|
104
|
+
策略参数必须先通过 `ccl strategy --info <id>` 获取。`controls: []` 表示无参数;否则按每项的 `id` 作为 JSON 键,按 `type` 传值,`enum` 只能使用 `values`,`player_seats` 使用 1-10 的 JSON 整数数组(如 `[6]`),`string_list` 使用字符串数组。`player_seats` 不接受字符串座位号或玩家名。`default` 仅在返回时存在才可依赖。玩家座位数组表示完整当前名单,清空传 `[]`;有关联的名单放在同一条 `--control` JSON 中更新。`--control` 只更新当前活动策略;成功后从下一次 `ccl events` 的 `state.strategy.params` 核对有效参数。
|
|
105
105
|
|
|
106
106
|
## 匹配模式
|
|
107
107
|
|
|
@@ -29,12 +29,12 @@ ccl strategy --info <id>
|
|
|
29
29
|
`--info` 返回 `id`、`name`、`description`、`disabled`、`default_for_roles` 和 `controls`。每个 control 使用:
|
|
30
30
|
|
|
31
31
|
- `id`:传给 `--control` 的 JSON 键。
|
|
32
|
-
- `type`:`string`、`boolean`、`number`、`enum`、`
|
|
32
|
+
- `type`:`string`、`boolean`、`number`、`enum`、`player_seats` 或 `string_list`。
|
|
33
33
|
- `description`:是否必填、数量限制、玩家引用/房间格式等约束。
|
|
34
34
|
- `values`:`enum` 允许值;只在 enum 上存在。
|
|
35
35
|
- `default`:未设置时的默认值;没有该字段就不要自行假设。
|
|
36
36
|
|
|
37
|
-
`
|
|
37
|
+
`player_seats` 传 JSON 整数数组,座位号范围为 1-10;例如 `[6]`。不要传字符串座位号(如 `["6"]`)或玩家名。`string_list` 才传 JSON 字符串数组。`controls: []` 表示该策略没有可调参数,不要调用 `--control`。
|
|
38
38
|
|
|
39
39
|
6. 启动策略(`<id>` 处也可填 `name`),命令不接位置参数:
|
|
40
40
|
|
|
@@ -45,12 +45,12 @@ ccl strategy <id>
|
|
|
45
45
|
7. 需要配置时,按刚读取的 control ID 和类型更新当前策略:
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
|
-
ccl strategy --control '{"targets":[
|
|
48
|
+
ccl strategy --control '{"targets":[3,6]}'
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
`--control` 只作用于当前正在运行的策略,并在下一份可执行游走 State 前应用;成功返回会给出 effective values。随后可在 `ccl events` 的 `state.strategy.params` 核对当前有效参数。缺少必填参数的策略会处于等待状态,此时按 `--info` 补齐,不要换用位置参数。
|
|
52
52
|
|
|
53
|
-
玩家分类统一使用策略声明的 `
|
|
53
|
+
玩家分类统一使用策略声明的 `player_seats` 参数,例如 `huntTargets`、`protectedTargets`、`hostileTargets`、`trustedTargets`。每个数组是该字段的完整当前座位号名单,清空必须显式传 `[]`;同一次判断变化涉及多个名单时,用一条 `--control` JSON 原子更新。若同一座位同时出现在敌对和保护名单,官方策略以 `protectedTargets` / `trustedTargets` 为先。参数只属于当前活动策略,切换策略或重启 runtime 后按新实例参数重新配置。Goal tree 只在参数实际变化且控制被接受时重建,不会每次游戏 `update()` 都重算一棵新树。
|
|
54
54
|
|
|
55
55
|
## 当前策略
|
|
56
56
|
|
package/src/lib/game-client.ts
CHANGED
|
@@ -263,6 +263,14 @@ export default class StaticValidationStrategy extends ClawclawGoalStrategy {
|
|
|
263
263
|
'task-report': ['greetings'],
|
|
264
264
|
'warrior-memory': ['huntTargets', 'trustedTargets'],
|
|
265
265
|
};
|
|
266
|
+
const playerSeatControlIds = new Set([
|
|
267
|
+
'targets',
|
|
268
|
+
'protectedTargets',
|
|
269
|
+
'huntTargets',
|
|
270
|
+
'hostileTargets',
|
|
271
|
+
'trustedTargets',
|
|
272
|
+
'paradiseFishTargets',
|
|
273
|
+
]);
|
|
266
274
|
|
|
267
275
|
const officialIds = Object.keys(readManifest());
|
|
268
276
|
expect(officialIds).toHaveLength(20);
|
|
@@ -281,6 +289,11 @@ export default class StaticValidationStrategy extends ClawclawGoalStrategy {
|
|
|
281
289
|
for (const control of expectedControls[id] ?? []) {
|
|
282
290
|
expect(source).toContain(`id: '${control}'`);
|
|
283
291
|
}
|
|
292
|
+
for (const control of discoveredById.get(id)?.controls ?? []) {
|
|
293
|
+
if (playerSeatControlIds.has(control.id)) {
|
|
294
|
+
expect(control.type).toBe('player_seats');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
284
297
|
}
|
|
285
298
|
});
|
|
286
299
|
|
|
@@ -93,6 +93,7 @@ describe('ClawClaw runtime capabilities', () => {
|
|
|
93
93
|
['speech', ['communication']],
|
|
94
94
|
['vote', ['meeting_vote']],
|
|
95
95
|
['think', []],
|
|
96
|
+
['strategy', []],
|
|
96
97
|
['future_action', ['*']],
|
|
97
98
|
])('maps %s onto generic control domains', (action, domains) => {
|
|
98
99
|
expect(describeClawclawActionControl({ action: { action } })).toEqual({
|
|
@@ -54,7 +54,7 @@ function validateControlSpecs(controls: readonly StrategyControlSpec[] | undefin
|
|
|
54
54
|
if (controls === undefined) return;
|
|
55
55
|
if (!Array.isArray(controls)) throw new Error('strategy_controls_invalid');
|
|
56
56
|
const ids = new Set<string>();
|
|
57
|
-
const types = new Set(['string', 'boolean', 'number', 'enum', '
|
|
57
|
+
const types = new Set(['string', 'boolean', 'number', 'enum', 'player_seats', 'string_list']);
|
|
58
58
|
for (const control of controls) {
|
|
59
59
|
if (!control || typeof control !== 'object') throw new Error('strategy_control_invalid');
|
|
60
60
|
if (!/^[A-Za-z][A-Za-z0-9_.-]{0,79}$/.test(control.id) || ids.has(control.id)) {
|
|
@@ -167,6 +167,30 @@ function actionContext(actions: Array<{ epoch: number; action: Record<string, un
|
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
function successfulStrategyReportResult() {
|
|
171
|
+
return {
|
|
172
|
+
scope,
|
|
173
|
+
actionId: 'strategy-report-action',
|
|
174
|
+
status: 'success' as const,
|
|
175
|
+
source: 'backend' as const,
|
|
176
|
+
actionOutcome: 'confirmed' as const,
|
|
177
|
+
value: { success: true, data: { ok: true } },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function reportingPlugin(): ClawclawStrategyPlugin {
|
|
182
|
+
return new ClawclawStrategyPlugin({
|
|
183
|
+
executorFactory: () => ({
|
|
184
|
+
runtimeInstanceId: 'strategy-reporting-test',
|
|
185
|
+
isAlive: true,
|
|
186
|
+
async start() {},
|
|
187
|
+
async reset() {},
|
|
188
|
+
async update() { return {}; },
|
|
189
|
+
async stop() {},
|
|
190
|
+
}),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
170
194
|
async function run(
|
|
171
195
|
plugin: ClawclawStrategyPlugin,
|
|
172
196
|
pluginInput: RuntimeEpochPluginInput<Record<string, any>>,
|
|
@@ -177,6 +201,28 @@ async function run(
|
|
|
177
201
|
}
|
|
178
202
|
|
|
179
203
|
describe('ClawClaw Strategy plugin scheduling', () => {
|
|
204
|
+
it('accepts numeric player_seats controls and rejects string seats or names', () => {
|
|
205
|
+
const plugin = new ClawclawStrategyPlugin();
|
|
206
|
+
plugin.select({
|
|
207
|
+
id: 'seat-controls',
|
|
208
|
+
execution: 'parallel_analyze',
|
|
209
|
+
sourcePath: 'unused',
|
|
210
|
+
sourceRoot: 'unused',
|
|
211
|
+
controls: [{
|
|
212
|
+
id: 'targets',
|
|
213
|
+
type: 'player_seats',
|
|
214
|
+
description: 'Target seats.',
|
|
215
|
+
}],
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
expect(() => plugin.control({ targets: ['6'] })).toThrow('invalid_strategy_control:targets');
|
|
219
|
+
expect(() => plugin.control({ targets: ['木桩机器虾'] })).toThrow('invalid_strategy_control:targets');
|
|
220
|
+
expect(() => plugin.control({ targets: [0, 11] })).toThrow('invalid_strategy_control:targets');
|
|
221
|
+
|
|
222
|
+
const accepted = plugin.control({ targets: [6] });
|
|
223
|
+
void accepted.catch(() => {});
|
|
224
|
+
});
|
|
225
|
+
|
|
180
226
|
it('exposes localized metadata only after a strategy becomes active', async () => {
|
|
181
227
|
const plugin = new ClawclawStrategyPlugin({
|
|
182
228
|
executorFactory: () => ({
|
|
@@ -213,6 +259,163 @@ describe('ClawClaw Strategy plugin scheduling', () => {
|
|
|
213
259
|
await plugin.stop('shutdown');
|
|
214
260
|
});
|
|
215
261
|
|
|
262
|
+
it('reports the effective strategy asynchronously and suppresses repeats after the exact ack', async () => {
|
|
263
|
+
vi.useFakeTimers();
|
|
264
|
+
try {
|
|
265
|
+
let resolveReport!: (value: ReturnType<typeof successfulStrategyReportResult>) => void;
|
|
266
|
+
const pendingReport = new Promise<ReturnType<typeof successfulStrategyReportResult>>((resolve) => {
|
|
267
|
+
resolveReport = resolve;
|
|
268
|
+
});
|
|
269
|
+
const performAction = vi.fn(() => pendingReport);
|
|
270
|
+
const baseContext = context(() => {});
|
|
271
|
+
const pluginContext: RuntimeEpochPluginContext<Record<string, any>> = {
|
|
272
|
+
...baseContext,
|
|
273
|
+
capabilities: {
|
|
274
|
+
...baseContext.capabilities,
|
|
275
|
+
performAction: performAction as RuntimeEpochPluginContext<Record<string, any>>[
|
|
276
|
+
'capabilities'
|
|
277
|
+
]['performAction'],
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
const plugin = reportingPlugin();
|
|
281
|
+
plugin.select({
|
|
282
|
+
id: 'task-only',
|
|
283
|
+
name: 'Task only',
|
|
284
|
+
description: 'Complete assigned tasks.',
|
|
285
|
+
localizations: {
|
|
286
|
+
'zh-CN': { name: '纯任务', description: '专心完成分配的任务。' },
|
|
287
|
+
},
|
|
288
|
+
sourcePath: 'unused',
|
|
289
|
+
sourceRoot: 'unused',
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
await expect(run(plugin, input(1), pluginContext)).resolves.toMatchObject({
|
|
293
|
+
outcome: 'processed',
|
|
294
|
+
});
|
|
295
|
+
expect(performAction).not.toHaveBeenCalled();
|
|
296
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
297
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
298
|
+
expect(performAction).toHaveBeenCalledWith('clawclaw.action', {
|
|
299
|
+
route: 'game',
|
|
300
|
+
action: {
|
|
301
|
+
action: 'strategy',
|
|
302
|
+
name: '纯任务',
|
|
303
|
+
description: '专心完成分配的任务。',
|
|
304
|
+
},
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
resolveReport(successfulStrategyReportResult());
|
|
308
|
+
await Promise.resolve();
|
|
309
|
+
await Promise.resolve();
|
|
310
|
+
await run(plugin, input(2), pluginContext);
|
|
311
|
+
await vi.advanceTimersByTimeAsync(5_000);
|
|
312
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
313
|
+
await plugin.stop('shutdown');
|
|
314
|
+
} finally {
|
|
315
|
+
vi.useRealTimers();
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('retries an incorrect strategy report response once per second until acknowledged', async () => {
|
|
320
|
+
vi.useFakeTimers();
|
|
321
|
+
try {
|
|
322
|
+
const performAction = vi.fn()
|
|
323
|
+
.mockResolvedValueOnce({
|
|
324
|
+
...successfulStrategyReportResult(),
|
|
325
|
+
value: { success: true, data: { ok: false } },
|
|
326
|
+
})
|
|
327
|
+
.mockResolvedValue(successfulStrategyReportResult());
|
|
328
|
+
const baseContext = context(() => {});
|
|
329
|
+
const pluginContext: RuntimeEpochPluginContext<Record<string, any>> = {
|
|
330
|
+
...baseContext,
|
|
331
|
+
capabilities: {
|
|
332
|
+
...baseContext.capabilities,
|
|
333
|
+
performAction: performAction as RuntimeEpochPluginContext<Record<string, any>>[
|
|
334
|
+
'capabilities'
|
|
335
|
+
]['performAction'],
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
const plugin = reportingPlugin();
|
|
339
|
+
plugin.select({
|
|
340
|
+
id: 'patrol',
|
|
341
|
+
name: '巡逻',
|
|
342
|
+
description: '按房间顺序巡逻。',
|
|
343
|
+
sourcePath: 'unused',
|
|
344
|
+
sourceRoot: 'unused',
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
await run(plugin, input(1), pluginContext);
|
|
348
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
349
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
350
|
+
await vi.advanceTimersByTimeAsync(999);
|
|
351
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
352
|
+
await vi.advanceTimersByTimeAsync(1);
|
|
353
|
+
expect(performAction).toHaveBeenCalledTimes(2);
|
|
354
|
+
await vi.advanceTimersByTimeAsync(5_000);
|
|
355
|
+
expect(performAction).toHaveBeenCalledTimes(2);
|
|
356
|
+
await plugin.stop('shutdown');
|
|
357
|
+
} finally {
|
|
358
|
+
vi.useRealTimers();
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('does not let an old in-flight acknowledgement confirm a newly selected strategy', async () => {
|
|
363
|
+
vi.useFakeTimers();
|
|
364
|
+
try {
|
|
365
|
+
let resolveFirst!: (value: ReturnType<typeof successfulStrategyReportResult>) => void;
|
|
366
|
+
const first = new Promise<ReturnType<typeof successfulStrategyReportResult>>((resolve) => {
|
|
367
|
+
resolveFirst = resolve;
|
|
368
|
+
});
|
|
369
|
+
const performAction = vi.fn()
|
|
370
|
+
.mockImplementationOnce(() => first)
|
|
371
|
+
.mockResolvedValue(successfulStrategyReportResult());
|
|
372
|
+
const baseContext = context(() => {});
|
|
373
|
+
const pluginContext: RuntimeEpochPluginContext<Record<string, any>> = {
|
|
374
|
+
...baseContext,
|
|
375
|
+
capabilities: {
|
|
376
|
+
...baseContext.capabilities,
|
|
377
|
+
performAction: performAction as RuntimeEpochPluginContext<Record<string, any>>[
|
|
378
|
+
'capabilities'
|
|
379
|
+
]['performAction'],
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
const plugin = reportingPlugin();
|
|
383
|
+
plugin.select({
|
|
384
|
+
id: 'first',
|
|
385
|
+
name: '策略甲',
|
|
386
|
+
description: '策略甲描述。',
|
|
387
|
+
sourcePath: 'unused',
|
|
388
|
+
sourceRoot: 'unused',
|
|
389
|
+
});
|
|
390
|
+
await run(plugin, input(1), pluginContext);
|
|
391
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
392
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
393
|
+
|
|
394
|
+
plugin.select({
|
|
395
|
+
id: 'second',
|
|
396
|
+
name: '策略乙',
|
|
397
|
+
description: '策略乙描述。',
|
|
398
|
+
sourcePath: 'unused',
|
|
399
|
+
sourceRoot: 'unused',
|
|
400
|
+
});
|
|
401
|
+
await run(plugin, input(2), pluginContext);
|
|
402
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
403
|
+
expect(performAction).toHaveBeenCalledTimes(1);
|
|
404
|
+
|
|
405
|
+
resolveFirst(successfulStrategyReportResult());
|
|
406
|
+
await Promise.resolve();
|
|
407
|
+
await Promise.resolve();
|
|
408
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
409
|
+
expect(performAction).toHaveBeenCalledTimes(2);
|
|
410
|
+
expect(performAction.mock.calls[1]?.[1]).toMatchObject({
|
|
411
|
+
action: { action: 'strategy', name: '策略乙', description: '策略乙描述。' },
|
|
412
|
+
});
|
|
413
|
+
await plugin.stop('shutdown');
|
|
414
|
+
} finally {
|
|
415
|
+
vi.useRealTimers();
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
|
|
216
419
|
it('releases each Strategy activation, including a same-id parameter generation', async () => {
|
|
217
420
|
const releases: Array<{ capability: string; id: string; reason?: string }> = [];
|
|
218
421
|
const baseContext = context(() => {});
|