From a9f84a2aa0e2ff066926a46223d0c1c8c2d16a70 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Thu, 18 Jun 2026 16:49:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(onebot):=20TierB=20P1=20=E2=80=94=20honest?= =?UTF-8?q?=20compat-divergence=20comments=20+=20pin=20defaults?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adversarial review: code/test comments claimed napcat-surface parity while get_online_clients ({clients:[]}) and _get_model_show (echoes model vs NapCat's hardcoded 'napcat') deliberately diverge. Correct the comments to state these are intentional OneBot-v11/spec choices, and strengthen the default-model test to pin 'snowluma' literally + cover explicit empty string. No behavior change. --- packages/onebot/src/actions/extended.ts | 14 +++++++++----- .../onebot/tests/extended-actions.test.ts | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/packages/onebot/src/actions/extended.ts b/packages/onebot/src/actions/extended.ts index fa2eea3d..4b97648f 100644 --- a/packages/onebot/src/actions/extended.ts +++ b/packages/onebot/src/actions/extended.ts @@ -860,10 +860,13 @@ export const actions = [ }, }), - // NapCat 似乎也用不了,暂时不处理。 + // get_online_clients — 在线设备列表。NapCat 也拿不到(注册监听后 sleep 500ms + // 直接返回空),且其返回是裸数组 [],偏离 OneBot v11 / go-cqhttp 规范。 + // SnowLuma 暂无对应单包 SSO cmd,返回 OneBot v11 标准空壳 { clients: [] } + // ——刻意采用规范形状而非 NapCat 的裸 [],故对照 NapCat 客户端此处不严格 parity。 defineAction({ name: 'get_online_clients', - summary: '获取在线客户端(占位)', + summary: '获取在线客户端(占位,OneBot v11 形状)', readOnly: true, params: {}, run: async () => { @@ -872,9 +875,10 @@ export const actions = [ }), // _get_model_show — NapCat 纯内核无 packet wire,其实现是硬编码 mock - // (返回单条 variants,model_show 固定 'napcat')。SnowLuma 同样无对应单包 - // SSO cmd,故给出 NapCat 同形状的兼容返回:data 为数组 [{ variants: {...} }], - // model_show 回显请求的 model(缺省 'snowluma'),need_pay 恒 false。 + // (无视入参,model_show 恒返回字面量 'napcat')。SnowLuma 同样无对应单包 + // SSO cmd,故只复用 NapCat 的*外层形状*:data 为数组 [{ variants: {...} }]、 + // need_pay 恒 false;但刻意不照搬其固定字面量——回显请求的 model(缺省 + // 'snowluma'),对调用方更有信息量。属有意的行为分歧,仅形状对齐。 defineAction({ name: '_get_model_show', summary: '获取机型展示(兼容 mock)', diff --git a/packages/onebot/tests/extended-actions.test.ts b/packages/onebot/tests/extended-actions.test.ts index d4ea4620..b56a248f 100644 --- a/packages/onebot/tests/extended-actions.test.ts +++ b/packages/onebot/tests/extended-actions.test.ts @@ -800,7 +800,12 @@ describe('extended-actions / ocr_image', () => { // ─── TierB Phase 1: compat stubs (model_show / online_clients / mark_all_as_read) ─── // These are kernel-only in NapCat (mock/no-op), so SnowLuma ships honest // compat shapes rather than RE-ing a wire that doesn't exist. We pin the -// response *shape* so clients written against the napcat surface keep working. +// response *shape* of each. NOTE two deliberate divergences from NapCat: +// • _get_model_show reuses NapCat's array/variants shape but ECHOES the +// requested model instead of NapCat's hardcoded 'napcat'. +// • get_online_clients returns the OneBot-v11/go-cqhttp { clients: [] } +// envelope, NOT NapCat's (non-standard) bare []. A strict-NapCat client +// would expect an array here; we intentionally follow the spec instead. describe('extended-actions / TierB compat stubs', () => { it('_get_model_show returns the napcat-shaped variants array, echoing the model', async () => { @@ -812,11 +817,13 @@ describe('extended-actions / TierB compat stubs', () => { expect((res.data as any)[0].variants).toMatchObject({ model_show: 'MyPhone', need_pay: false }); }); - it('_get_model_show defaults model_show when no model is given', async () => { - const res = await makeHandler(fakeCtx(fakeBridge())).handle('_get_model_show', {}); - expect(res.status).toBe('ok'); - expect((res.data as any)[0].variants.model_show).toBeTruthy(); - expect((res.data as any)[0].variants.need_pay).toBe(false); + it('_get_model_show defaults model_show to snowluma when model is absent or empty', async () => { + for (const params of [{}, { model: '' }]) { + const res = await makeHandler(fakeCtx(fakeBridge())).handle('_get_model_show', params); + expect(res.status).toBe('ok'); + expect((res.data as any)[0].variants.model_show).toBe('snowluma'); + expect((res.data as any)[0].variants.need_pay).toBe(false); + } }); it('_set_model_show is an accepted no-op', async () => {