Personal Telegram developer console for GitHub

test: harden workspace file upload UX and retry paths

davoodmehraban89 committed Oct 3, 2026 at 14:43 UTC 02ad1f9db33749eabdbf21801d86dc82d3bb74f5
1 file changed +50 -1
test/github-workspace-file-upload.test.js
+50 -1
@@ -80,7 +80,9 @@ test('workspace exposes a primary file-upload input route with Telegram-safe cal
80 const route = plugin.resolveCallback(upload.callback_data, { ownerId: OWNER });
81 assert.equal(route.actionId, 'github.workspace.input.prepare');
82 const prompt = await route.execute();
83 - assert.match(prompt.text, /12,?000|12000|UTF-?8|فایل/i);
83 + assert.match(prompt.text, /12,?000|12000/);
84 + assert.match(prompt.text, /3,?000|3000/);
85 + assert.match(prompt.text, /UTF-?8|فایل/i);
86 assert.deepEqual(await workspaces.getPendingInput({ ownerId: OWNER }), {
87 workspaceId: WORKSPACE_ID,
88 mode: 'draft_file'
@@ -145,4 +147,51 @@ test('bot downloads a pending workspace document and dispatches its decoded file
147 byteLength: 22
148 });
149 assert.deepEqual(dispatch[2], { isOwner: true, ownerId: OWNER });
150 +});
151 +
152 +test('wrong message type while file upload is pending does not dispatch or consume the workspace input', async () => {
153 + const bot = new NexaDevBot({});
154 + let dispatches = 0;
155 + bot.workspaceStore = {
156 + isConfigured: () => true,
157 + async getPendingInput() { return { workspaceId: WORKSPACE_ID, mode: 'draft_file' }; }
158 + };
159 + bot.telegram = {
160 + async sendMessage() { return { ok: true }; },
161 + async downloadTextFile() { throw new Error('must not download'); }
162 + };
163 + bot.router = {
164 + async dispatchMessage() { dispatches += 1; return null; }
165 + };
166 +
167 + const result = await bot.handleMessage({ chat: { id: 7 }, from: { id: 42 }, text: 'not a file' });
168 + assert.equal(result.workspaceInput, true);
169 + assert.equal(result.inputRequired, 'document');
170 + assert.equal(dispatches, 0);
171 +});
172 +
173 +test('oversized Telegram document is rejected before download or workspace dispatch so owner can retry', async () => {
174 + const bot = new NexaDevBot({});
175 + let downloads = 0;
176 + let dispatches = 0;
177 + bot.workspaceStore = {
178 + isConfigured: () => true,
179 + async getPendingInput() { return { workspaceId: WORKSPACE_ID, mode: 'draft_file' }; }
180 + };
181 + bot.telegram = {
182 + async sendMessage() { return { ok: true }; },
183 + async downloadTextFile() { downloads += 1; return { text: 'unexpected', byteLength: 10 }; }
184 + };
185 + bot.router = {
186 + async dispatchMessage() { dispatches += 1; return null; }
187 + };
188 +
189 + const result = await bot.handleMessage({
190 + chat: { id: 7 },
191 + from: { id: 42 },
192 + document: { file_id: 'HUGE', file_name: 'huge.txt', file_size: 12001 }
193 + });
194 + assert.equal(result.inputRejected, true);
195 + assert.equal(downloads, 0);
196 + assert.equal(dispatches, 0);
197 });
\ No newline at end of file