Personal Telegram developer console for GitHub

test: define runtime diagnostics contract

davoodmehraban89 committed Oct 4, 2026 at 13:59 UTC 4932f5d546164048977e5049befab11f67f4ebd3
1 file changed +111
test/ops-console.test.js new
+111
@@ -0,0 +1,111 @@
1 +import { describe, it } from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { RuntimeDiagnostics } from '../src/core/runtime-diagnostics.js';
4 +
5 +function fakeRegistry() {
6 + return {
7 + getPlugins() {
8 + return [{
9 + manifest: {
10 + id: 'github',
11 + actions: {
12 + 'github.repos.list': { risk: 'READ' },
13 + 'github.workspace.commit_branch': { risk: 'WRITE' }
14 + }
15 + }
16 + }];
17 + }
18 + };
19 +}
20 +
21 +describe('Nexa Dev Bot - operational diagnostics', () => {
22 + 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 + };
31 + const diagnostics = new RuntimeDiagnostics({
32 + env,
33 + github: { owner: 'davoodmehraban89' },
34 + registry: fakeRegistry(),
35 + replayStore: { isConfigured: () => true },
36 + workspaceStore: { isConfigured: () => true },
37 + approvals: { isReplayProtected: () => true }
38 + });
39 +
40 + const snapshot = diagnostics.getSnapshot();
41 + assert.equal(snapshot.telegramConfigured, true);
42 + assert.equal(snapshot.webhookSecretConfigured, true);
43 + assert.equal(snapshot.ownerConfigured, true);
44 + assert.equal(snapshot.githubConfigured, true);
45 + assert.equal(snapshot.replayGuardConfigured, true);
46 + assert.equal(snapshot.workspaceStoreConfigured, true);
47 + assert.equal(snapshot.approvalSignerConfigured, true);
48 + assert.equal(snapshot.githubOwner, 'davoodmehraban89');
49 + assert.equal(snapshot.pluginCount, 1);
50 + assert.equal(snapshot.actionCount, 2);
51 +
52 + const serialized = JSON.stringify(snapshot);
53 + for (const secret of Object.values(env).filter(value => String(value).includes('secret'))) {
54 + assert.ok(!serialized.includes(secret), `snapshot leaked ${secret}`);
55 + }
56 + });
57 +
58 + 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 + });
69 + assert.deepEqual(await success.probeGitHub(), {
70 + ok: true,
71 + owner: 'davoodmehraban89',
72 + repositoryCount: 2
73 + });
74 +
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 + });
85 + const failure = await failed.probeGitHub();
86 + assert.equal(failure.ok, false);
87 + assert.match(failure.error, /403/);
88 + assert.doesNotMatch(failure.error, /configured/);
89 + });
90 +
91 + it('self-check is fail-closed when required bindings are missing', async () => {
92 + const diagnostics = new RuntimeDiagnostics({
93 + env: {},
94 + github: {
95 + owner: 'davoodmehraban89',
96 + async listRepositories() { throw new Error('GITHUB_TOKEN is missing'); }
97 + },
98 + registry: fakeRegistry(),
99 + replayStore: { isConfigured: () => false },
100 + workspaceStore: { isConfigured: () => false },
101 + approvals: { isReplayProtected: () => false }
102 + });
103 +
104 + const report = await diagnostics.runSelfCheck();
105 + assert.equal(report.ok, false);
106 + const byId = Object.fromEntries(report.checks.map(check => [check.id, check]));
107 + for (const id of ['telegram', 'webhook', 'owner', 'github-token', 'replay-guard', 'workspace-store', 'approval-signer', 'github-live']) {
108 + assert.equal(byId[id]?.ok, false, `${id} should fail closed`);
109 + }
110 + });
111 +});