Personal Telegram developer console for GitHub
test: define operational menu contract
davoodmehraban89 committed
Oct 4, 2026 at 14:01 UTC
4babd9eb4024a79e543fbca66038b96f7a2fb4d6
1 file changed
+123
-29
test/ops-console.test.js
+123
-29
@@ -1,6 +1,7 @@
1
import { describe, it } from 'node:test';
2
import assert from 'node:assert/strict';
3
import { RuntimeDiagnostics } from '../src/core/runtime-diagnostics.js';
4
+import { OpsMenuManager } from '../src/ops-menu.js';
5
6
function fakeRegistry() {
7
return {
@@ -18,16 +19,43 @@ function fakeRegistry() {
19
};
20
}
21
22
+function fullEnv() {
23
+ return {
24
+ TELEGRAM_BOT_TOKEN: 'tg-secret-value',
25
+ TELEGRAM_WEBHOOK_SECRET: 'webhook-secret-value',
26
+ GITHUB_TOKEN: 'github-secret-value',
27
+ OWNER_TELEGRAM_ID: '123',
28
+ APPROVAL_SIGNING_SECRET: 'approval-secret-value',
29
+ GITHUB_OWNER: 'davoodmehraban89'
30
+ };
31
+}
32
+
33
+function diagnosticsForMenus({ githubFailure = false } = {}) {
34
+ const github = {
35
+ owner: 'davoodmehraban89',
36
+ async listRepositories() {
37
+ if (githubFailure) throw new Error('GitHub 403 permission denied');
38
+ return [{ id: 1 }, { id: 2 }];
39
+ }
40
+ };
41
+ const diagnostics = new RuntimeDiagnostics({
42
+ env: fullEnv(),
43
+ github,
44
+ registry: fakeRegistry(),
45
+ replayStore: { isConfigured: () => true },
46
+ workspaceStore: { isConfigured: () => true },
47
+ approvals: { isReplayProtected: () => true }
48
+ });
49
+ return { github, diagnostics };
50
+}
51
+
52
+function callbacks(view) {
53
+ return (view.reply_markup?.inline_keyboard || []).flat().map(button => button.callback_data).filter(Boolean);
54
+}
55
+
56
describe('Nexa Dev Bot - operational diagnostics', () => {
57
it('reports configuration presence and plugin counts without exposing secret values', () => {
23
- const env = {
24
- TELEGRAM_BOT_TOKEN: 'tg-secret-value',
25
- TELEGRAM_WEBHOOK_SECRET: 'webhook-secret-value',
26
- GITHUB_TOKEN: 'github-secret-value',
27
- OWNER_TELEGRAM_ID: '123',
28
- APPROVAL_SIGNING_SECRET: 'approval-secret-value',
29
- GITHUB_OWNER: 'davoodmehraban89'
30
- };
58
+ const env = fullEnv();
59
const diagnostics = new RuntimeDiagnostics({
60
env,
61
github: { owner: 'davoodmehraban89' },
@@ -56,36 +84,18 @@ describe('Nexa Dev Bot - operational diagnostics', () => {
84
});
85
86
it('performs a bounded live GitHub READ probe and reports provider failure explicitly', async () => {
59
- const success = new RuntimeDiagnostics({
60
- env: { GITHUB_TOKEN: 'configured' },
61
- github: {
62
- owner: 'davoodmehraban89',
63
- async listRepositories() {
64
- return [{ id: 1 }, { id: 2 }];
65
- }
66
- },
67
- registry: fakeRegistry()
68
- });
87
+ const success = diagnosticsForMenus().diagnostics;
88
assert.deepEqual(await success.probeGitHub(), {
89
ok: true,
90
owner: 'davoodmehraban89',
91
repositoryCount: 2
92
});
93
75
- const failed = new RuntimeDiagnostics({
76
- env: { GITHUB_TOKEN: 'configured' },
77
- github: {
78
- owner: 'davoodmehraban89',
79
- async listRepositories() {
80
- throw new Error('GitHub 403 permission denied');
81
- }
82
- },
83
- registry: fakeRegistry()
84
- });
94
+ const failed = diagnosticsForMenus({ githubFailure: true }).diagnostics;
95
const failure = await failed.probeGitHub();
96
assert.equal(failure.ok, false);
97
assert.match(failure.error, /403/);
88
- assert.doesNotMatch(failure.error, /configured/);
98
+ assert.doesNotMatch(failure.error, /github-secret-value/);
99
});
100
101
it('self-check is fail-closed when required bindings are missing', async () => {
@@ -109,3 +119,87 @@ describe('Nexa Dev Bot - operational diagnostics', () => {
119
}
120
});
121
});
122
+
123
+describe('Nexa Dev Bot - operational menu surfaces', () => {
124
+ it('turns Development Tools into useful READ-only diagnostics', async () => {
125
+ const { github, diagnostics } = diagnosticsForMenus();
126
+ const menu = new OpsMenuManager(github, diagnostics);
127
+ const view = menu.getToolsView();
128
+ const values = callbacks(view);
129
+ for (const callback of ['ops:selfcheck', 'ops:github', 'ops:runtime', 'ops:plugins', 'tool:ping']) {
130
+ assert.ok(values.includes(callback), `missing ${callback}`);
131
+ }
132
+ assert.match(view.text, /تشخیص|Diagnostics|عیب.?یابی/);
133
+ });
134
+
135
+ it('renders source-backed live service status and explicit provider failure', async () => {
136
+ const okContext = diagnosticsForMenus();
137
+ const okMenu = new OpsMenuManager(okContext.github, okContext.diagnostics);
138
+ const okView = await okMenu.getServiceStatusView();
139
+ assert.match(okView.text, /GitHub.*✅|✅.*GitHub/s);
140
+ assert.match(okView.text, /2/);
141
+ assert.match(okView.text, /Workspace|Durable/);
142
+ assert.doesNotMatch(okView.text, /99\.9|100% SLA|ms latency/i);
143
+
144
+ const badContext = diagnosticsForMenus({ githubFailure: true });
145
+ const badMenu = new OpsMenuManager(badContext.github, badContext.diagnostics);
146
+ const badView = await badMenu.getServiceStatusView();
147
+ assert.match(badView.text, /GitHub.*❌|❌.*GitHub/s);
148
+ assert.match(badView.text, /403/);
149
+ });
150
+
151
+ it('provides a real Security Center and read-only Configuration Center', async () => {
152
+ const { github, diagnostics } = diagnosticsForMenus();
153
+ const menu = new OpsMenuManager(github, diagnostics);
154
+
155
+ const security = menu.getSecurityView();
156
+ for (const callback of ['security:selfcheck', 'security:policy', 'security:approval']) {
157
+ assert.ok(callbacks(security).includes(callback), `missing ${callback}`);
158
+ }
159
+ assert.match(security.text, /مرکز امنیت/);
160
+
161
+ const config = menu.getSettingsView();
162
+ assert.match(config.text, /پیکربندی/);
163
+ assert.doesNotMatch(config.text, /تنظیمات Nexa Dev/);
164
+ for (const callback of ['config:runtime', 'config:providers', 'config:editor', 'config:plugins']) {
165
+ assert.ok(callbacks(config).includes(callback), `missing ${callback}`);
166
+ }
167
+ });
168
+
169
+ it('routes every operational drill-down and keeps Telegram payloads bounded', async () => {
170
+ const { github, diagnostics } = diagnosticsForMenus();
171
+ const menu = new OpsMenuManager(github, diagnostics);
172
+ const encoder = new TextEncoder();
173
+ const routes = [
174
+ 'menu:status', 'menu:tools', 'menu:security', 'menu:settings',
175
+ 'ops:selfcheck', 'ops:github', 'ops:runtime', 'ops:plugins',
176
+ 'security:selfcheck', 'security:policy', 'security:approval',
177
+ 'config:runtime', 'config:providers', 'config:editor', 'config:plugins'
178
+ ];
179
+
180
+ for (const route of routes) {
181
+ const view = await menu.renderByCallback(route);
182
+ assert.ok(view?.text, `${route} returned no text`);
183
+ assert.ok(view.text.length <= 4096, `${route} exceeds Telegram message limit`);
184
+ for (const callback of callbacks(view)) {
185
+ assert.ok(encoder.encode(callback).length <= 64, `${callback} exceeds callback limit`);
186
+ }
187
+ }
188
+ });
189
+
190
+ it('never renders configured secrets in operational pages', async () => {
191
+ const { github, diagnostics } = diagnosticsForMenus();
192
+ const menu = new OpsMenuManager(github, diagnostics);
193
+ const pages = await Promise.all([
194
+ menu.getServiceStatusView(),
195
+ menu.renderByCallback('ops:selfcheck'),
196
+ menu.renderByCallback('ops:runtime'),
197
+ menu.renderByCallback('security:selfcheck'),
198
+ menu.renderByCallback('config:providers')
199
+ ]);
200
+ const combined = pages.map(page => page.text).join('\n');
201
+ for (const secret of ['tg-secret-value', 'webhook-secret-value', 'github-secret-value', 'approval-secret-value']) {
202
+ assert.ok(!combined.includes(secret), `operational page leaked ${secret}`);
203
+ }
204
+ });
205
+});