Personal Telegram developer console for GitHub

phase2-20261005-w
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 200 lines 5.59 KB
Raw
1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { PluginRegistry } from '../src/core/plugin-registry.js';
4 import { ActionPolicy } from '../src/core/action-policy.js';
5 import { PluginRouter } from '../src/core/router.js';
6
7 function auditCollector() {
8 const events = [];
9 return { events, logger: { log: event => events.push(event) } };
10 }
11
12 test('PluginRouter dispatches the first matching READ command after policy evaluation', async () => {
13 let executed = 0;
14 const first = {
15 manifest: { id: 'first', actions: {} },
16 resolveCommand: () => null
17 };
18 const second = {
19 manifest: {
20 id: 'second',
21 actions: { 'second.read': { risk: 'READ' } }
22 },
23 resolveCommand: command => command === '/go'
24 ? {
25 actionId: 'second.read',
26 execute: async () => {
27 executed += 1;
28 return { view: 'ok' };
29 }
30 }
31 : null
32 };
33 const third = {
34 manifest: {
35 id: 'third',
36 actions: { 'third.read': { risk: 'READ' } }
37 },
38 resolveCommand: () => ({
39 actionId: 'third.read',
40 execute: async () => {
41 throw new Error('must not run');
42 }
43 })
44 };
45 const audit = auditCollector();
46 const router = new PluginRouter({
47 registry: new PluginRegistry([first, second, third]),
48 policy: new ActionPolicy(),
49 audit: audit.logger
50 });
51
52 const result = await router.dispatchCommand('/go', { isOwner: true });
53
54 assert.deepEqual(result, { view: 'ok' });
55 assert.equal(executed, 1);
56 assert.equal(audit.events[0].event, 'action_attempt');
57 assert.equal(audit.events[0].outcome, 'allowed');
58 assert.equal(audit.events[1].event, 'action_result');
59 assert.equal(audit.events[1].outcome, 'success');
60 });
61
62 test('PluginRouter dispatches callbacks through the same policy boundary', async () => {
63 let executed = 0;
64 const plugin = {
65 manifest: {
66 id: 'sample',
67 actions: { 'sample.callback.read': { risk: 'READ' } }
68 },
69 resolveCallback: data => data === 'sample:1'
70 ? {
71 actionId: 'sample.callback.read',
72 execute: async () => {
73 executed += 1;
74 return { callback: 'ok' };
75 }
76 }
77 : null
78 };
79 const router = new PluginRouter({
80 registry: new PluginRegistry([plugin]),
81 policy: new ActionPolicy(),
82 audit: { log() {} }
83 });
84
85 assert.deepEqual(
86 await router.dispatchCallback('sample:1', { isOwner: true }),
87 { callback: 'ok' }
88 );
89 assert.equal(executed, 1);
90 });
91
92 test('PluginRouter returns null when no plugin owns the route', async () => {
93 const plugin = {
94 manifest: { id: 'sample', actions: {} },
95 resolveCommand: () => null,
96 resolveCallback: () => null
97 };
98 const router = new PluginRouter({
99 registry: new PluginRegistry([plugin]),
100 policy: new ActionPolicy(),
101 audit: { log() {} }
102 });
103
104 assert.equal(await router.dispatchCommand('/unknown', { isOwner: true }), null);
105 assert.equal(await router.dispatchCallback('unknown', { isOwner: true }), null);
106 });
107
108 test('PluginRouter denies undeclared actions without executing plugin code', async () => {
109 let executed = 0;
110 const plugin = {
111 manifest: { id: 'sample', actions: {} },
112 resolveCommand: () => ({
113 actionId: 'sample.missing',
114 execute: async () => {
115 executed += 1;
116 }
117 })
118 };
119 const router = new PluginRouter({
120 registry: new PluginRegistry([plugin]),
121 policy: new ActionPolicy(),
122 audit: { log() {} }
123 });
124
125 const result = await router.dispatchCommand('/go', { isOwner: true });
126
127 assert.equal(result.denied, true);
128 assert.equal(result.requiresApproval, false);
129 assert.equal(result.reason, 'unknown_action');
130 assert.equal(executed, 0);
131 });
132
133 test('PluginRouter never executes WRITE or DESTRUCTIVE actions before approval', async () => {
134 for (const risk of ['WRITE', 'DESTRUCTIVE']) {
135 let executed = 0;
136 const actionId = `sample.${risk.toLowerCase()}`;
137 const plugin = {
138 manifest: {
139 id: 'sample',
140 actions: { [actionId]: { risk } }
141 },
142 resolveCommand: () => ({
143 actionId,
144 execute: async () => {
145 executed += 1;
146 }
147 })
148 };
149 const router = new PluginRouter({
150 registry: new PluginRegistry([plugin]),
151 policy: new ActionPolicy(),
152 audit: { log() {} }
153 });
154
155 const result = await router.dispatchCommand('/danger', { isOwner: true });
156
157 assert.equal(result.requiresApproval, true);
158 assert.equal(result.denied, false);
159 assert.equal(result.risk, risk);
160 assert.equal(executed, 0);
161 }
162 });
163
164 test('PluginRouter executes an approved owner WRITE action exactly once', async () => {
165 let executed = 0;
166 const audit = auditCollector();
167 const plugin = {
168 manifest: {
169 id: 'sample',
170 actions: { 'sample.write': { risk: 'WRITE' } }
171 },
172 resolveCallback: data => data === 'write:1'
173 ? {
174 actionId: 'sample.write',
175 execute: async () => {
176 executed += 1;
177 return { ok: true, view: 'done' };
178 }
179 }
180 : null
181 };
182 const router = new PluginRouter({
183 registry: new PluginRegistry([plugin]),
184 policy: new ActionPolicy(),
185 audit: audit.logger
186 });
187
188 const result = await router.dispatchCallback('write:1', {
189 isOwner: true,
190 approved: true
191 });
192
193 assert.deepEqual(result, { ok: true, view: 'done' });
194 assert.equal(executed, 1);
195 assert.equal(audit.events[0].reason, 'owner_write_approved');
196 assert.equal(audit.events[0].outcome, 'allowed');
197 assert.equal(audit.events[1].event, 'action_result');
198 assert.equal(audit.events[1].outcome, 'success');
199 assert.equal(JSON.stringify(audit.events).includes('token'), false);
200 });