mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-09-16 14:57:15 +00:00
fix(bots): highlight unsupported processor events and show overlap
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { expect, test, type Page } from '@playwright/test';
|
||||
import { installLangBotApiMocks } from './fixtures/langbot-api';
|
||||
|
||||
const warning = /This bot cannot fully cover these subscribed events:/;
|
||||
const warning = /This bot only supports some of the subscribed events/;
|
||||
const definitions = [
|
||||
{ name: 'Messages only', patterns: ['message.received'] },
|
||||
{
|
||||
name: 'Community helper',
|
||||
patterns: [
|
||||
'message.received',
|
||||
'group.member_joined',
|
||||
'message.received',
|
||||
'friend.request_received',
|
||||
],
|
||||
},
|
||||
@@ -102,11 +102,28 @@ test('partial support warns in existing choices and saved bindings, and changes
|
||||
const community = dialog
|
||||
.locator('label')
|
||||
.filter({ hasText: 'Community helper' });
|
||||
await expect(community.getByRole('status')).toContainText('Member joined');
|
||||
await expect(community.getByRole('status')).toContainText('Friend request');
|
||||
await expect(community.getByRole('status')).not.toContainText(
|
||||
'Message received',
|
||||
await expect(community.getByRole('status')).toContainText(
|
||||
'(Message received)',
|
||||
);
|
||||
await expect(community.getByRole('status')).not.toContainText(
|
||||
'Member joined',
|
||||
);
|
||||
await expect(community.getByRole('listitem')).toHaveText([
|
||||
'Message received',
|
||||
'Member joined group',
|
||||
'Friend request received',
|
||||
]);
|
||||
for (const pattern of ['group.member_joined', 'friend.request_received']) {
|
||||
const event = community.getByTitle(pattern, { exact: true });
|
||||
await expect(event).toHaveClass(/text-amber-/);
|
||||
await expect(event.locator('svg')).toHaveCount(1);
|
||||
}
|
||||
await expect(
|
||||
community.getByTitle('message.received', { exact: true }),
|
||||
).not.toHaveClass(/text-amber-/);
|
||||
await expect(
|
||||
community.getByTitle('message.received', { exact: true }).locator('svg'),
|
||||
).toHaveCount(0);
|
||||
await expect(
|
||||
dialog
|
||||
.locator('label')
|
||||
@@ -122,6 +139,15 @@ test('partial support warns in existing choices and saved bindings, and changes
|
||||
).toHaveCount(1);
|
||||
await page.getByRole('button', { name: 'Save', exact: true }).click();
|
||||
await page.reload();
|
||||
await expect(
|
||||
page
|
||||
.getByRole('region', { name: 'Plugin processor', exact: true })
|
||||
.getByRole('listitem'),
|
||||
).toHaveText([
|
||||
'Message received',
|
||||
'Member joined group',
|
||||
'Friend request received',
|
||||
]);
|
||||
await expect(
|
||||
page.getByRole('status').filter({ hasText: warning }),
|
||||
).toHaveCount(1);
|
||||
@@ -159,6 +185,21 @@ test('new component choices warn for missing and wildcard events but allow creat
|
||||
.getByRole('status'),
|
||||
).toContainText(warning);
|
||||
}
|
||||
await expect(
|
||||
dialog.getByRole('button', { name: /Group observer/ }).getByRole('status'),
|
||||
).toContainText('(None)');
|
||||
await expect(
|
||||
dialog.getByRole('button', { name: /All observer/ }).getByRole('status'),
|
||||
).toContainText('(Message received)');
|
||||
const community = dialog.getByRole('button', { name: /Community helper/ });
|
||||
await expect(community.getByRole('listitem')).toHaveText([
|
||||
'Message received',
|
||||
'Member joined group',
|
||||
'Friend request received',
|
||||
]);
|
||||
await expect(
|
||||
community.getByTitle('group.member_joined', { exact: true }).locator('svg'),
|
||||
).toHaveCount(1);
|
||||
await expect(
|
||||
dialog.getByRole('button', { name: /Messages only/ }).getByRole('status'),
|
||||
).toHaveCount(0);
|
||||
|
||||
@@ -14,7 +14,10 @@ const exports = {};
|
||||
new Function(
|
||||
'exports',
|
||||
ts.transpileModule(source, {
|
||||
compilerOptions: { module: ts.ModuleKind.CommonJS },
|
||||
compilerOptions: {
|
||||
module: ts.ModuleKind.CommonJS,
|
||||
target: ts.ScriptTarget.ES2022,
|
||||
},
|
||||
}).outputText,
|
||||
)(exports);
|
||||
|
||||
@@ -34,3 +37,56 @@ for (const [supported, required, covered] of [
|
||||
assert.equal(exports.eventPatternCovers(supported, required), covered);
|
||||
});
|
||||
}
|
||||
|
||||
test('processor events put covered declarations first and report only the intersection', () => {
|
||||
const result = exports.processorEventCompatibility(
|
||||
[
|
||||
'group.member_joined',
|
||||
'message.received',
|
||||
'friend.request_received',
|
||||
'message.received',
|
||||
],
|
||||
['message.received', 'message.edited'],
|
||||
);
|
||||
assert.deepEqual(result.entries, [
|
||||
{ pattern: 'message.received', supported: true },
|
||||
{ pattern: 'group.member_joined', supported: false },
|
||||
{ pattern: 'friend.request_received', supported: false },
|
||||
]);
|
||||
assert.deepEqual(result.matchingEvents, ['message.received']);
|
||||
});
|
||||
|
||||
test('wildcard subscriptions show matching concrete adapter events without claiming full coverage', () => {
|
||||
const result = exports.processorEventCompatibility(
|
||||
['group.*'],
|
||||
['group.member_joined', 'message.received'],
|
||||
);
|
||||
assert.deepEqual(result.entries, [{ pattern: 'group.*', supported: false }]);
|
||||
assert.deepEqual(result.matchingEvents, ['group.member_joined']);
|
||||
assert.deepEqual(
|
||||
exports.processorEventCompatibility(['*'], ['message.received'])
|
||||
.matchingEvents,
|
||||
['message.received'],
|
||||
);
|
||||
});
|
||||
|
||||
test('adapter wildcards cover concrete subscriptions without expanding the intersection', () => {
|
||||
const result = exports.processorEventCompatibility(
|
||||
['group.member_joined'],
|
||||
['group.*'],
|
||||
);
|
||||
assert.equal(result.entries[0].supported, true);
|
||||
assert.deepEqual(result.matchingEvents, ['group.member_joined']);
|
||||
});
|
||||
|
||||
test('legacy adapters default to messages and unmatched subscriptions have an empty intersection', () => {
|
||||
assert.deepEqual(
|
||||
exports.processorEventCompatibility(['*'], []).matchingEvents,
|
||||
['message.received'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
exports.processorEventCompatibility(['group.*'], []).matchingEvents,
|
||||
[],
|
||||
);
|
||||
assert.deepEqual(exports.processorEventCompatibility([], []).entries, []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user