mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 17:43:20 +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
|
|
@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
|||
import { Readable } from 'node:stream';
|
||||
import { FeishuHarnessBridge } from '../../../src/channels/feishu/bridge.mjs';
|
||||
import { DEFAULT_IMAGE_PROMPT } from '../../../src/channels/shared/image-prompt.mjs';
|
||||
import { connectionTestTarget } from '../../../src/channels/shared/connection-test.mjs';
|
||||
|
||||
const PNG_1X1 = Buffer.from(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=',
|
||||
|
|
@ -86,6 +87,54 @@ function textClient(sendText) {
|
|||
};
|
||||
}
|
||||
|
||||
test('Feishu remembers any authorized private inbound message as a connection-test target', async () => {
|
||||
const groupFixture = stateFixture();
|
||||
const groupBridge = new FeishuHarnessBridge({
|
||||
client: textClient(async () => {}),
|
||||
channel: {},
|
||||
harness: { ensureRunning: async () => true },
|
||||
state: groupFixture.state,
|
||||
status: bridgeStatus(),
|
||||
allowedSenderOpenIds: new Set(['ou_user']),
|
||||
});
|
||||
await groupBridge.accept(event('target-group', '/help', {
|
||||
chat_type: 'group',
|
||||
chat_id: 'oc_group',
|
||||
}));
|
||||
await groupBridge.waitForIdle();
|
||||
assert.equal(connectionTestTarget(groupFixture.state), null);
|
||||
|
||||
const rejectedFixture = stateFixture();
|
||||
const rejectedBridge = new FeishuHarnessBridge({
|
||||
client: textClient(async () => {}),
|
||||
channel: {},
|
||||
harness: { ensureRunning: async () => true },
|
||||
state: rejectedFixture.state,
|
||||
status: bridgeStatus(),
|
||||
allowedSenderOpenIds: new Set(['ou_owner']),
|
||||
});
|
||||
await rejectedBridge.accept(event('target-rejected', '/help', {
|
||||
senderOpenId: 'ou_other',
|
||||
}));
|
||||
await rejectedBridge.waitForIdle();
|
||||
assert.equal(connectionTestTarget(rejectedFixture.state), null);
|
||||
|
||||
const privateFixture = stateFixture();
|
||||
const privateBridge = new FeishuHarnessBridge({
|
||||
client: textClient(async () => {}),
|
||||
channel: {},
|
||||
harness: { ensureRunning: async () => true },
|
||||
state: privateFixture.state,
|
||||
status: bridgeStatus(),
|
||||
allowedSenderOpenIds: new Set(['*']),
|
||||
});
|
||||
await privateBridge.accept(event('target-private', '/help', {
|
||||
chat_id: 'oc_private',
|
||||
}));
|
||||
await privateBridge.waitForIdle();
|
||||
assert.deepEqual(connectionTestTarget(privateFixture.state), { chatId: 'oc_private' });
|
||||
});
|
||||
|
||||
test('Feishu executes /compact for the bound Session without prompting the model', async () => {
|
||||
const fixture = stateFixture([['p2p:ou_user', 'session-compact']]);
|
||||
const sent = [];
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ test('Feishu connection check requests and displays test-message feedback', asyn
|
|||
import.meta.url,
|
||||
), 'utf8');
|
||||
assert.match(source, /FEISHU_ENDPOINTS\.reconnectBot, \{ botId, sendTest: true \}/);
|
||||
assert.match(source, /机器人尚未收到可用于测试的私聊消息/);
|
||||
assert.doesNotMatch(source, /请先私聊机器人发送 \/status/);
|
||||
|
||||
const markup = renderToStaticMarkup(React.createElement(BotCard, {
|
||||
connection: {
|
||||
|
|
|
|||
|
|
@ -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