DrSmoothl b32a8110af refactor(core): make ApiActionContext required, drop 80 dead defensive guards
ApiActionContext had 81 optional method fields (\`name?: ...\`) plus 4
required ones — but every single optional field was wired in
buildApiContext (verified by diffing the two lists). The optionality
was dead: nothing else implemented this interface, no test ever
swapped fields out, and the action handlers all paid for the
fiction with defensive guards like:

    if (!ctx.sendGroupMessage) {
      return failedResponse(RETCODE.ACTION_FAILED, 'send_group_msg is not implemented');
    }

— 80 such guards total across the action files (78 in the 3-line
form, 1 single-line, 1 \`if (!(ctx.a && ctx.b))\` compound). None of
them could ever fire.

This commit deletes the dead optionality. Two mechanical changes:

1. api-handler.ts: 81 \`name?: ...\` -> \`name: ...\` in ApiActionContext.
   The MessageSendResult optionals (meta?, echoEvent?) are unrelated
   and stay as-is. After: 85 required fields, 0 optionals.

2. actions/*.ts: drop the 80 guard blocks. Net -129 lines across
   extended, group-admin, group-file, group-info, friend, message,
   request. info.ts had none to begin with.

What this buys:

- The type system now enforces the wiring contract. If
  buildApiContext forgets to wire a field, tsc fails at the call
  site — the bug we were ostensibly catching at runtime in 80 places
  is now caught at compile time in 0 places, for free.
- Action handler bodies shrink visibly (avg ~3 lines per handler).
  extended.ts goes 1021 -> 935.
- AI / human readers no longer skim past dead code.

Caught one TS2774 ("This condition will always return true since
this function is always defined") on a compound guard in
extended.ts:186 that the regex missed; removed it manually. That
diagnostic is the type system actually doing its job — exactly the
point of the change.

244 tests pass (was 244). Same pre-existing macOS-arm64 websocket
addon failure, unrelated.
2026-05-12 17:09:56 +08:00
2026-05-02 19:06:29 +08:00
2026-05-03 14:02:29 +08:00
2026-05-10 01:26:35 +08:00
2026-05-09 14:58:37 +08:00

❄️ SnowLuma

Next Remote Protocol Framework.

关于项目

项目处于开发初期,仅支持部分功能,高速迭代中,随时可能出现破坏性更新。

鸣谢

LagrangeV2 - Proto

NapCatQQ - Scaner/Packet

辅助编程

推荐 Opus4.6 + Gemini3.1pro 对本项目辅助开发

本项目大量使用Ai技术。

加入我们

SnowLuma-QQ

SnowLuma-TG

S
Description
[BACKUP] Next Remote Protocol Framework.
Readme
64 MiB
0 Stars 1 Watchers 0 Forks
Languages
TypeScript 98.9%
CSS 0.5%
JavaScript 0.5%