mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-11 04:03:16 +08:00
fix: remember direct recipients for connection tests
This commit is contained in:
parent
fb61c4235f
commit
3ac70a7c65
34 changed files with 397 additions and 178 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { FeishuRuntime } from '../../../src/channels/feishu/feishu-runtime.mjs';
|
||||
import { rememberConnectionTestTarget } from '../../../src/channels/shared/connection-test.mjs';
|
||||
|
||||
class FakeClient {
|
||||
static instances = [];
|
||||
|
|
@ -86,7 +87,7 @@ test('FeishuRuntime becomes chat-ready only after Harness and Feishu are connect
|
|||
lark: fakeLark(),
|
||||
appId: 'cli_test',
|
||||
appSecret: 'secret',
|
||||
ownerOpenId: 'ou_owner',
|
||||
ownerOpenIds: ['*', 'ou_owner'],
|
||||
harness: {
|
||||
async ensureRunning(options) {
|
||||
harnessChecks += 1;
|
||||
|
|
@ -133,6 +134,40 @@ test('FeishuRuntime becomes chat-ready only after Harness and Feishu are connect
|
|||
assert.equal(harnessSignal.aborted, true);
|
||||
});
|
||||
|
||||
test('FeishuRuntime uses a remembered private target for wildcard-only manual bots', async () => {
|
||||
const state = { hasSeen: () => false };
|
||||
const runtime = new FeishuRuntime({
|
||||
lark: fakeLark(),
|
||||
appId: 'cli_manual',
|
||||
appSecret: 'secret',
|
||||
ownerOpenIds: ['*'],
|
||||
harness: { async ensureRunning() {} },
|
||||
state,
|
||||
});
|
||||
|
||||
const starting = runtime.start();
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
FakeWSClient.instances[0].becomeReady();
|
||||
await starting;
|
||||
|
||||
await assert.rejects(
|
||||
runtime.sendConnectionTest('连接测试'),
|
||||
(error) => error?.code === 'test-target-unavailable',
|
||||
);
|
||||
rememberConnectionTestTarget(state, { chatId: 'oc_manual_private' });
|
||||
assert.deepEqual(await runtime.sendConnectionTest('连接测试'), { sent: true });
|
||||
assert.deepEqual(FakeClient.sent, [{
|
||||
params: { receive_id_type: 'chat_id' },
|
||||
data: {
|
||||
receive_id: 'oc_manual_private',
|
||||
msg_type: 'text',
|
||||
content: JSON.stringify({ text: '连接测试' }),
|
||||
},
|
||||
}]);
|
||||
|
||||
await runtime.stop();
|
||||
});
|
||||
|
||||
test('FeishuRuntime fails closed when the initial WebSocket handshake times out', async () => {
|
||||
const runtime = new FeishuRuntime({
|
||||
lark: fakeLark(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue