Personal Telegram developer console for GitHub
fix: restore Phase 2 add-file callback routing (#56)
* test: reproduce add-file callback routing failure * fix: register multi-file workspace callback actions * fix: harden multi-file picker repository binding * test: cover workspace picker repository binding
davoodmehraban89 committed
Oct 7, 2026 at 01:30 UTC
ad7d3b3f8ab993c8fed9b1f3dc8dbc6876c5e2dc
3 files changed
+21
-1
src/plugins/github/manifest.js
+3
@@ -32,6 +32,9 @@ export const githubPluginManifest = Object.freeze({
32
'github.workspace.navigate': Object.freeze({ risk: 'READ' }),
33
'github.workspace.create': Object.freeze({ risk: 'READ' }),
34
'github.workspace.view': Object.freeze({ risk: 'READ' }),
35
+ 'github.workspace.file.pick': Object.freeze({ risk: 'READ' }),
36
+ 'github.workspace.file.add': Object.freeze({ risk: 'READ' }),
37
+ 'github.workspace.file.remove': Object.freeze({ risk: 'READ' }),
38
'github.workspace.input.prepare': Object.freeze({ risk: 'READ' }),
39
'github.workspace.input.apply': Object.freeze({ risk: 'READ' }),
40
'github.workspace.diff': Object.freeze({ risk: 'READ' }),
src/plugins/github/workspace.js
+3
-1
@@ -217,7 +217,9 @@ export function createWorkspaceController({ github, workspaces, editorUrl = DEFA
217
218
const pickWorkspaceFile = async (workspaceId, repoId, ownerId) => {
219
const workspace = await requireWorkspace(workspaceId, ownerId);
220
- const items = (await github.listFiles(repoId, '')).filter(item => item.type === 'file' && !(workspace.files || []).some(file => file.path === item.path)).slice(0, 20);
220
+ if (Number(workspace.repoId) !== Number(repoId)) throw new Error('Workspace repository mismatch');
221
+ const existingPaths = new Set((Array.isArray(workspace.files) && workspace.files.length ? workspace.files : [{ path: workspace.path }]).map(file => file.path));
222
+ const items = (await github.listFiles(repoId, '')).filter(item => item.type === 'file' && !existingPaths.has(item.path)).slice(0, 20);
223
const refs = await workspaces.createNavigationRefs({ ownerId, refs: items.map(item => ({ repoId, workspaceId, path:item.path, type:'workspace-add', sha:item.sha })) });
224
return { text:`➕ <b>افزودن فایل به Change Set</b>\n${items.length ? 'یک فایل را انتخاب کنید.' : 'فایل قابل افزودن دیگری در این نما نیست.'}`, reply_markup:{inline_keyboard:items.map((item,i)=>[{text:`📄 ${short(item.path,42)}`,callback_data:`wadd:${refs[i].refId}`}]).concat([[{text:'↩️ Workspace',callback_data:`ws:${workspaceId}`} ]])} };
225
};
test/phase2-controller.test.js
+15
@@ -28,3 +28,18 @@ test('removing a change-set file uses opaque ref and durable remove', async()=>{
28
const v=await c.resolveCallback('wremove:R000000001',{ownerId:'42'}).execute();
29
assert.equal(removed,'src/a.js'); assert.match(v.text,/README\.md/);
30
});
31
+
32
+
33
+test('add-file callback actions are declared READ in the GitHub manifest', async()=>{
34
+ const { githubPluginManifest } = await import('../src/plugins/github/manifest.js');
35
+ for (const action of ['github.workspace.file.pick','github.workspace.file.add','github.workspace.file.remove']) {
36
+ assert.equal(githubPluginManifest.actions[action]?.risk, 'READ', action + ' must be routed as owner-only READ');
37
+ }
38
+});
39
+
40
+
41
+test('file picker rejects a repo id that is not bound to the workspace', async()=>{
42
+ const workspaces={async getWorkspace(){return structuredClone(ws)}};
43
+ const c=createWorkspaceController({github:{async listFiles(){throw new Error('must not read mismatched repo')}},workspaces});
44
+ await assert.rejects(()=>c.resolveCallback('wfiles:W000000001:2',{ownerId:'42'}).execute(),/repository mismatch/i);
45
+});