Personal Telegram developer console for GitHub

test(github): cover exact-head destructive merge approval

davoodmehraban89 committed Oct 5, 2026 at 05:03 UTC c1fe933a1b52f6a93a7479c73d0e6fbdf199c422
1 file changed +15
test/github-pr-merge.test.js
+15
@@ -2,9 +2,15 @@ import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { GitHubService } from '../src/github.js';
4 import { githubPluginManifest } from '../src/plugins/github/manifest.js';
5 +import { ApprovalService } from '../src/core/approval.js';
6
7 const HEAD_SHA = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
8
9 +function replayStore() {
10 + const used = new Set();
11 + return { async consume({ ownerId, nonce }) { const key = `${ownerId}:${nonce}`; if (used.has(key)) return false; used.add(key); return true; } };
12 +}
13 +
14 test('PR merge is a DESTRUCTIVE GitHub action', () => {
15 assert.deepEqual(githubPluginManifest.actions['github.pull_request.merge'], { risk: 'DESTRUCTIVE' });
16 });
@@ -23,3 +29,12 @@ test('mergePullRequest only accepts supported merge methods', async () => {
29 const github = new GitHubService('token', 'owner');
30 await assert.rejects(github.mergePullRequest('repo', 42, { expectedHeadSha: HEAD_SHA, mergeMethod: 'octopus' }), /merge method|unsupported/i);
31 });
32 +
33 +test('destructive merge approval is owner/action/risk/repo/PR/head bound and replay-safe', async () => {
34 + const service = new ApprovalService({ secret: 'test-secret', now: () => 1700000000000, replayStore: replayStore() });
35 + const token = await service.issue({ pluginId: 'github', actionId: 'github.pull_request.merge', risk: 'DESTRUCTIVE', ownerId: '42', input: { repoId: 7, prNumber: 39, headSha: HEAD_SHA } });
36 + assert.ok(`approve:${token}`.length <= 64);
37 + const payload = await service.consume(token, { ownerId: '42', pluginId: 'github', actionId: 'github.pull_request.merge', risk: 'DESTRUCTIVE' });
38 + assert.deepEqual(payload.input, { repoId: 7, prNumber: 39, headSha: HEAD_SHA });
39 + await assert.rejects(() => service.consume(token, { ownerId: '42' }), /already used/i);
40 +});