Personal Telegram developer console for GitHub
test: use full head SHA in PR merge contract
davoodmehraban89 committed
Oct 5, 2026 at 04:56 UTC
651ddafe32e9c63c0e2c5e790dffbcff34b3b9c4
1 file changed
+9
-33
test/github-pr-merge.test.js
+9
-33
@@ -3,47 +3,23 @@ import assert from 'node:assert/strict';
3
import { GitHubService } from '../src/github.js';
4
import { githubPluginManifest } from '../src/plugins/github/manifest.js';
5
6
+const HEAD_SHA = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
7
+
8
test('PR merge is a DESTRUCTIVE GitHub action', () => {
9
assert.deepEqual(githubPluginManifest.actions['github.pull_request.merge'], { risk: 'DESTRUCTIVE' });
10
});
11
10
-test('mergePullRequest binds mutation to the expected PR head SHA', async () => {
11
- const calls = [];
12
- const fetchImpl = async (url, options = {}) => {
13
- calls.push({ url: String(url), options });
14
- return new Response(JSON.stringify({ merged: true, sha: 'merge-sha', message: 'Pull Request successfully merged' }), {
15
- status: 200,
16
- headers: { 'content-type': 'application/json' }
17
- });
18
- };
19
- const github = new GitHubService({ token: 'token', fetchImpl });
20
- const result = await github.mergePullRequest('owner/repo', 42, {
21
- expectedHeadSha: 'abc123',
22
- mergeMethod: 'squash'
23
- });
24
- assert.equal(result.merged, true);
25
- assert.equal(calls.length, 1);
26
- assert.match(calls[0].url, /repos\/owner\/repo\/pulls\/42\/merge$/);
27
- assert.equal(calls[0].options.method, 'PUT');
28
- const body = JSON.parse(calls[0].options.body);
29
- assert.equal(body.sha, 'abc123');
30
- assert.equal(body.merge_method, 'squash');
12
+test('mergePullRequest requires an exact full PR head SHA', async () => {
13
+ const github = new GitHubService('token', 'owner');
14
+ await assert.rejects(github.mergePullRequest('repo', 42, { expectedHeadSha: 'abc123', mergeMethod: 'squash' }), /head sha|required|expected|invalid/i);
15
});
16
17
test('mergePullRequest rejects missing exact-head binding before provider mutation', async () => {
34
- let called = false;
35
- const github = new GitHubService({ token: 'token', fetchImpl: async () => { called = true; throw new Error('must not call'); } });
36
- await assert.rejects(
37
- github.mergePullRequest('owner/repo', 42, { mergeMethod: 'squash' }),
38
- /head sha|required|expected/i
39
- );
40
- assert.equal(called, false);
18
+ const github = new GitHubService('token', 'owner');
19
+ await assert.rejects(github.mergePullRequest('repo', 42, { mergeMethod: 'squash' }), /head sha|required|expected/i);
20
});
21
22
test('mergePullRequest only accepts supported merge methods', async () => {
44
- const github = new GitHubService({ token: 'token', fetchImpl: async () => { throw new Error('must not call'); } });
45
- await assert.rejects(
46
- github.mergePullRequest('owner/repo', 42, { expectedHeadSha: 'abc123', mergeMethod: 'octopus' }),
47
- /merge method|unsupported/i
48
- );
23
+ const github = new GitHubService('token', 'owner');
24
+ await assert.rejects(github.mergePullRequest('repo', 42, { expectedHeadSha: HEAD_SHA, mergeMethod: 'octopus' }), /merge method|unsupported/i);
25
});