Personal Telegram developer console for GitHub

test: reproduce unsafe workspace provider error feedback

davoodmehraban89 committed Oct 3, 2026 at 13:45 UTC 0eb3806a506880e604b996836d0675bdb1d46456
1 file changed +46
test/github-workspace-provider-error-ui.test.js new
+46
@@ -0,0 +1,46 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { NexaDevBot } from '../src/bot.js';
4 +import { ApprovalService } from '../src/core/approval.js';
5 +
6 +function replayStore() {
7 + return { async consume() { return true; } };
8 +}
9 +
10 +test('workspace approved provider errors are HTML-escaped before Telegram rendering', async () => {
11 + const bot = new NexaDevBot({ TELEGRAM_WEBHOOK_SECRET: 'test-secret' });
12 + bot.approvals = new ApprovalService({ secret: 'test-secret', replayStore: replayStore() });
13 + bot.router = {
14 + async dispatchCallback(data, context) {
15 + if (context?.approved === true) throw new Error('GitHub provider <bad>& response');
16 + return null;
17 + }
18 + };
19 + const edits = [];
20 + bot.telegram = {
21 + async answerCallbackQuery() { return { ok: true }; },
22 + async editMessageText(chatId, messageId, text, replyMarkup) {
23 + edits.push({ chatId, messageId, text, replyMarkup });
24 + return { ok: true };
25 + }
26 + };
27 +
28 + const token = await bot.approvals.issue({
29 + pluginId: 'github',
30 + actionId: 'github.workspace.commit_branch',
31 + risk: 'WRITE',
32 + ownerId: '42',
33 + input: { repoId: 123, intentId: 'Ab12_cdE' }
34 + });
35 + const result = await bot.handleCallbackQuery({
36 + id: 'cb',
37 + from: { id: 42 },
38 + data: `approve:${token}`,
39 + message: { chat: { id: 7 }, message_id: 9 }
40 + });
41 +
42 + assert.equal(result.providerError, true);
43 + assert.equal(edits.length, 1);
44 + assert.match(edits[0].text, /GitHub provider &lt;bad&gt;&amp; response/);
45 + assert.doesNotMatch(edits[0].text, /<bad>/);
46 +});