Personal Telegram developer console for GitHub
test(approval): model durable destructive context
davoodmehraban89 committed
Oct 5, 2026 at 05:07 UTC
f65f5c43c9dddb1a03c8af4721dbf3cbae3ec05b
1 file changed
+10
-24
test/github-pr-merge.test.js
+10
-24
@@ -3,33 +3,19 @@ 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
-
6
const HEAD_SHA = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
8
-
7
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; } };
8
+ const used = new Set(); const payloads = new Map();
9
+ return {
10
+ async put({ ownerId, nonce, payload }) { payloads.set(`${ownerId}:${nonce}`, payload); return true; },
11
+ async peek({ ownerId, nonce }) { return payloads.get(`${ownerId}:${nonce}`) || null; },
12
+ async consume({ ownerId, nonce }) { const key = `${ownerId}:${nonce}`; if (used.has(key)) return false; used.add(key); return true; }
13
+ };
14
}
13
-
14
-test('PR merge is a DESTRUCTIVE GitHub action', () => {
15
- assert.deepEqual(githubPluginManifest.actions['github.pull_request.merge'], { risk: 'DESTRUCTIVE' });
16
-});
17
-
18
-test('mergePullRequest requires an exact full PR head SHA', async () => {
19
- const github = new GitHubService('token', 'owner');
20
- await assert.rejects(github.mergePullRequest('repo', 42, { expectedHeadSha: 'abc123', mergeMethod: 'squash' }), /head sha|required|expected|invalid/i);
21
-});
22
-
23
-test('mergePullRequest rejects missing exact-head binding before provider mutation', async () => {
24
- const github = new GitHubService('token', 'owner');
25
- await assert.rejects(github.mergePullRequest('repo', 42, { mergeMethod: 'squash' }), /head sha|required|expected/i);
26
-});
27
-
28
-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
-
15
+test('PR merge is a DESTRUCTIVE GitHub action', () => { assert.deepEqual(githubPluginManifest.actions['github.pull_request.merge'], { risk: 'DESTRUCTIVE' }); });
16
+test('mergePullRequest requires an exact full PR head SHA', async () => { const github = new GitHubService('token', 'owner'); await assert.rejects(github.mergePullRequest('repo', 42, { expectedHeadSha: 'abc123', mergeMethod: 'squash' }), /head sha|required|expected|invalid/i); });
17
+test('mergePullRequest rejects missing exact-head binding before provider mutation', async () => { const github = new GitHubService('token', 'owner'); await assert.rejects(github.mergePullRequest('repo', 42, { mergeMethod: 'squash' }), /head sha|required|expected/i); });
18
+test('mergePullRequest only accepts supported merge methods', async () => { const github = new GitHubService('token', 'owner'); await assert.rejects(github.mergePullRequest('repo', 42, { expectedHeadSha: HEAD_SHA, mergeMethod: 'octopus' }), /merge method|unsupported/i); });
19
test('destructive merge approval is owner/action/risk/repo/PR/head bound and replay-safe', async () => {
20
const service = new ApprovalService({ secret: 'test-secret', now: () => 1700000000000, replayStore: replayStore() });
21
const token = await service.issue({ pluginId: 'github', actionId: 'github.pull_request.merge', risk: 'DESTRUCTIVE', ownerId: '42', input: { repoId: 7, prNumber: 39, headSha: HEAD_SHA } });