Personal Telegram developer console for GitHub
test: define post-approval workspace recovery
davoodmehraban89 committed
Oct 4, 2026 at 07:37 UTC
b49d492861cf773a2635a6d02724be94726cc47e
1 file changed
+75
test/workspace-approved-recovery.test.js
new
+75
@@ -0,0 +1,75 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { NexaDevBot } from '../src/bot.js';
4
+import { buildApprovedActionFailedView } from '../src/core/callback-failure-view.js';
5
+
6
+const OWNER = 42;
7
+const WORKSPACE_ID = 'Ab12_cdEfG';
8
+const REPO_ID = 123;
9
+const INTENT_ID = 'Ab1_cdE2';
10
+
11
+const payload = {
12
+ pluginId: 'github',
13
+ actionId: 'github.workspace.commit_branch',
14
+ risk: 'WRITE',
15
+ input: { repoId: REPO_ID, intentId: INTENT_ID }
16
+};
17
+
18
+const callbacksOf = view => view.reply_markup.inline_keyboard.flat().map(button => button.callback_data);
19
+
20
+function workspaceStore() {
21
+ return {
22
+ async getIntent({ ownerId, intentId }) {
23
+ assert.equal(ownerId, String(OWNER));
24
+ assert.equal(intentId, INTENT_ID);
25
+ return { id: INTENT_ID, workspaceId: WORKSPACE_ID, repoId: REPO_ID };
26
+ }
27
+ };
28
+}
29
+
30
+test('approved workspace provider failure offers fresh Ready, Draft, Project and Main recovery', async () => {
31
+ const view = await buildApprovedActionFailedView({
32
+ payload,
33
+ error: new Error('GitHub create ref failed: 403 Resource not accessible by personal access token'),
34
+ ownerId: OWNER,
35
+ workspaces: workspaceStore()
36
+ });
37
+
38
+ const callbacks = callbacksOf(view);
39
+ assert.ok(callbacks.includes(`wready:${WORKSPACE_ID}`));
40
+ assert.ok(callbacks.includes(`ws:${WORKSPACE_ID}`));
41
+ assert.ok(callbacks.includes(`repo:${REPO_ID}`));
42
+ assert.ok(callbacks.includes('menu:main'));
43
+});
44
+
45
+test('bot uses durable intent context when approved workspace provider execution fails', async () => {
46
+ const bot = new NexaDevBot({ TELEGRAM_WEBHOOK_SECRET: 'approved-recovery-test' });
47
+ bot.approvals = { async consume() { return payload; } };
48
+ bot.workspaceStore = workspaceStore();
49
+ bot.router = { async dispatchCallback() { throw new Error('temporary GitHub provider failure'); } };
50
+
51
+ const edits = [];
52
+ bot.telegram = {
53
+ async answerCallbackQuery() { return { ok: true }; },
54
+ async editMessageText(chatId, messageId, text, replyMarkup) {
55
+ edits.push({ chatId, messageId, text, replyMarkup });
56
+ return { ok: true };
57
+ }
58
+ };
59
+
60
+ const result = await bot.handleCallbackQuery({
61
+ id: 'approve-recovery',
62
+ data: 'approve:synthetic',
63
+ from: { id: OWNER },
64
+ message: { chat: { id: 7 }, message_id: 9 }
65
+ });
66
+
67
+ assert.equal(result.ok, false);
68
+ assert.equal(result.approved, true);
69
+ assert.equal(edits.length, 1);
70
+ const callbacks = edits[0].replyMarkup.inline_keyboard.flat().map(button => button.callback_data);
71
+ assert.ok(callbacks.includes(`wready:${WORKSPACE_ID}`));
72
+ assert.ok(callbacks.includes(`ws:${WORKSPACE_ID}`));
73
+ assert.ok(callbacks.includes(`repo:${REPO_ID}`));
74
+ assert.ok(callbacks.includes('menu:main'));
75
+});