Personal Telegram developer console for GitHub

phase2-20261005-m
audit/commit-drilldown audit/finalize-workspace-menu-security audit/ops-actionability audit/pr-menu-consolidation audit/status-menu-consolidation audit/telegram-menu-e2e audit/telegram-menu-e2e-wave2 chore/actions-node24-runtime cleanup/remove-diag design/cloudflare-ops-read docs/control-plane-2-7-design docs/guide-v2-1-sync docs/menu-audit-final-sync docs/phase2-acceptance-closeout docs/phase2-multifile-design feat/bootstrap-worker feat/cloudflare-ops-read feat/cp2-multifile-final feat/cp2-multifile-workspace feat/cp3-github-write-final feat/cp4-cloudflare-ops-final feat/cp5-cicd-control-plane feat/cp6-incident-manager feat/cp7-automation-engine feat/deep-file-browser feat/final-delivery-16-20 feat/github-advanced-read feat/in-app-guide-v2 feat/navigation-recovery-ux-v2 feat/ops-console-v2-1 feat/persistent-menu-code-input feat/phase2-multifile-workspace feat/phase2-multifile-workspace-v2 feat/plugin-foundation-v1 feat/safe-github-ops feat/self-register-webhook feat/studio-g0-foundation feat/telegram-main-inline-menu feat/telegram-pr-merge feat/ux-platform-8-12 feat/v3a-readonly-copilot feat/workspace-file-upload feature/mobile-repo-browser feature/multi-file-change-set fix/approval-expiry-feedback fix/callback-resilience-and-docs fix/ci-actions-pagination fix/cloudflare-fetch-binding fix/editor-request-body-cap fix/editor-safe-file-options fix/issues-permission-release-empty-ux fix/main-menu-callback-fallback fix/phase2-file-editor-selection fix/phase2-final-ux fix/phase2-workspace-ref-persistence fix/production-auto-deploy fix/provider-write-error-feedback fix/repository-id-navigation-fallback fix/repository-pr-navigation fix/telegram-callback-updates fix/telegram-runtime-diagnostics fix/workspace-editor-flow-v2 fix/workspace-recovery-validation hardening/ci-zero-test-telegram-token hardening/pr1-destructive-totp hardening/pr2-kill-switch main multifile-workspace nexa/edit-BwJEIIY3PW nexa/edit-IPHT8irO7b nexa/edit-b4Od3BIMYd p2-multifile phase2-20261005 phase2-20261005-a phase2-20261005-b phase2-20261005-c phase2-20261005-d phase2-20261005-e phase2-20261005-f phase2-20261005-g phase2-20261005-h phase2-20261005-i phase2-20261005-j phase2-20261005-k phase2-20261005-l phase2-20261005-m phase2-20261005-n phase2-20261005-o phase2-20261005-p phase2-20261005-q phase2-20261005-r phase2-20261005-s phase2-20261005-t phase2-20261005-u phase2-20261005-v phase2-20261005-w phase2-20261005-x phase2-20261005-y phase2-20261005-z phase2-acceptance-closeout phase2-add-file-hotfix phase2-change-set phase2-design-20261005 phase2-design-final phase2-implementation phase2-multifile-implementation phase2-multifile-spec phase2-spec-final phase2-workspace phase2/multifile-workspace plan/nexa-studio-v2-reviewed security/remove-telegram-setup spec/repository-workspace-editor v3a/multifile work/multifile
js 132 lines 6.28 KB
Raw
1 import { describe, it } from 'node:test';
2 import assert from 'node:assert/strict';
3 import { readFileSync } from 'node:fs';
4 import { GuideMenuManager } from '../src/guide-menu.js';
5 import { GuidedNexaDevBot } from '../src/guide-bot.js';
6
7 const github = {
8 owner: 'davoodmehraban89',
9 async listRepositories() { return []; },
10 async getRepository(repo) {
11 return { id: repo, name: String(repo), fullName: `davoodmehraban89/${repo}`, private: true, defaultBranch: 'main', archived: false };
12 }
13 };
14
15 function callbacks(view) {
16 return (view.reply_markup?.inline_keyboard || []).flat().map(button => button.callback_data).filter(Boolean);
17 }
18
19 describe('Nexa Dev Bot - in-app V2.1 guide', () => {
20 const menu = new GuideMenuManager(github);
21
22 it('exposes Guide from the main inline menu', () => {
23 const view = menu.getMainMenuView();
24 assert.ok(callbacks(view).includes('menu:help'));
25 assert.ok(view.reply_markup.inline_keyboard.flat().some(button => button.text.includes('راهنما')));
26 });
27
28 it('guide index and pages identify V2.1 and expose all seven navigable chapters', async () => {
29 const index = await menu.renderByCallback('menu:help');
30 assert.match(index.text, /راهنمای Nexa Dev.*V2\.1/);
31 const indexCallbacks = callbacks(index);
32 for (const callback of ['help:1', 'help:2', 'help:3', 'help:4', 'help:5', 'help:6', 'help:7']) {
33 assert.ok(indexCallbacks.includes(callback), `missing ${callback}`);
34 }
35
36 const menuHelp = await menu.renderByCallback('help:1');
37 for (const label of ['منوی اصلی', 'پروژه‌ها', 'وضعیت', 'ابزارها', 'پیکربندی', 'امنیت', 'راهنما']) {
38 assert.ok(menuHelp.text.includes(label), `menu guide missing ${label}`);
39 }
40
41 const repoHelp = await menu.renderByCallback('help:2');
42 for (const label of ['فایل‌ها', 'Pull Request', 'Commit', 'جزئیات Commit', 'CI / Actions', 'Branches', 'Issues', 'Releases', 'جزئیات Issue', 'Release notes']) {
43 assert.ok(repoHelp.text.includes(label), `repo guide missing ${label}`);
44 }
45
46 const workspaceHelp = await menu.renderByCallback('help:3');
47 for (const label of ['Edit', 'Editor', 'Mini App', 'WORKSPACE_STORE', 'بارگذاری فایل', 'Paste متن', 'پیام Commit', 'Diff', 'آماده Commit', 'لغو Draft']) {
48 assert.ok(workspaceHelp.text.includes(label), `workspace guide missing ${label}`);
49 }
50
51 const ciHelp = await menu.renderByCallback('help:5');
52 for (const label of ['Job', 'Artifacts', 'log', 'اجرای مجدد', 'لغو Workflow', 'بروزرسانی', 'جدیدتر', 'قدیمی‌تر']) {
53 assert.ok(ciHelp.text.includes(label), `CI guide missing ${label}`);
54 }
55 });
56
57 it('documents operational diagnostics, read-only configuration and Security Center controls', async () => {
58 const menuHelp = await menu.renderByCallback('help:1');
59 for (const label of ['خودآزمایی', 'تست اتصال GitHub', 'Runtime', 'Plugin Registry', 'پیکربندی', 'فقط‌خواندنی']) {
60 assert.ok(menuHelp.text.includes(label), `operational guide missing ${label}`);
61 }
62
63 const securityHelp = await menu.renderByCallback('help:6');
64 for (const label of ['مرکز امنیت', 'سیاست عملیات', 'Safe Approval', 'Replay', 'Owner-only']) {
65 assert.ok(securityHelp.text.includes(label), `security guide missing ${label}`);
66 }
67 });
68
69 it('documents the complete file-edit flow from project selection through branch-only Safe Approval commit', async () => {
70 const view = await menu.renderByCallback('help:4');
71 const expected = [
72 'پروژه‌ها',
73 'فایل‌ها',
74 'Edit',
75 'Editor',
76 'ذخیره Draft',
77 'Diff',
78 'پیام Commit',
79 'آماده Commit',
80 'Safe Approval',
81 'تأیید و اجرا',
82 'nexa/edit-',
83 'main'
84 ];
85 for (const item of expected) assert.ok(view.text.includes(item), `file-edit guide missing ${item}`);
86 assert.match(view.text, /main.*مستقیم.*تغییر|شاخه.*پیش.?فرض.*تغییر.*نمی/);
87 });
88
89 it('documents production, Cloudflare deployment, preview isolation and the public status boundary', async () => {
90 const view = await menu.renderByCallback('help:7');
91 for (const label of ['Production', 'Cloudflare', 'Deploy', 'Preview', 'Durable Object', '/status', 'حداقلی', 'Observability']) {
92 assert.ok(view.text.includes(label), `production guide missing ${label}`);
93 }
94 assert.match(view.text, /داخل Telegram.*جزئیات|جزئیات.*داخل Telegram/);
95 });
96
97 it('keeps every guide page and callback within Telegram limits', async () => {
98 const encoder = new TextEncoder();
99 for (const callback of ['menu:help', 'help:1', 'help:2', 'help:3', 'help:4', 'help:5', 'help:6', 'help:7']) {
100 const view = await menu.renderByCallback(callback);
101 assert.ok(view.text.length <= 4096, `${callback} exceeds Telegram message limit`);
102 for (const value of callbacks(view)) {
103 assert.ok(encoder.encode(value).length <= 64, `${value} exceeds Telegram callback limit`);
104 }
105 }
106 });
107
108 it('keeps Guide in the persistent bottom keyboard and routes its text without consuming workspace input', async () => {
109 const bot = new GuidedNexaDevBot({});
110 const sent = [];
111 bot.telegram.sendMessage = async (chatId, text, replyMarkup) => {
112 sent.push({ chatId, text, replyMarkup });
113 return { ok: true };
114 };
115
116 await bot.handleMessage({ chat: { id: 1 }, from: { id: 1 }, text: '/start' });
117 const quickKeyboard = sent[0].replyMarkup.keyboard.flat().map(button => button.text);
118 assert.ok(quickKeyboard.includes('📘 راهنما'));
119
120 sent.length = 0;
121 await bot.handleMessage({ chat: { id: 1 }, from: { id: 1 }, text: '📘 راهنما' });
122 assert.match(sent[0].text, /راهنمای Nexa Dev.*V2\.1/);
123 });
124
125 it('keeps README aligned with the deployed V2.1 architecture', () => {
126 const readme = readFileSync(new URL('../README.md', import.meta.url), 'utf8');
127 for (const label of ['Workspace Editor', 'WORKSPACE_STORE', 'APPROVAL_REPLAY_GUARD', 'Ops Console', 'پیکربندی', 'Worker Preview', 'Mini App', '/status']) {
128 assert.ok(readme.includes(label), `README missing ${label}`);
129 }
130 assert.doesNotMatch(readme, /ناوبری callback به‌صورت stateless/);
131 });
132 });