pi-odd-worktree 3.9.2 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -40
- package/extensions/odd-worktree-tools.ts +859 -12
- package/lib/gh-issues.js +65 -10
- package/lib/gh-prs.js +2011 -0
- package/lib/issue-preview.js +70 -4
- package/lib/issues-cache-store.js +4 -1
- package/lib/issues-section.js +346 -23
- package/lib/issues-view.js +116 -5
- package/lib/pr-preview.js +353 -0
- package/lib/prs-rail-store.js +317 -0
- package/lib/prs-view.js +2896 -0
- package/package.json +1 -1
- package/tools/files-bridge.test.js +2 -2
- package/tools/files-command.test.js +1 -1
- package/tools/fixtures/gh-pr-connection-page.json +84 -0
- package/tools/fixtures/gh-pr-metadata.json +29 -0
- package/tools/fixtures/gh-pr-rail.json +61 -0
- package/tools/fixtures/gh-pr-search-page.json +82 -0
- package/tools/fixtures/gh-pr-view.json +159 -0
- package/tools/gh-issues.test.js +4 -2
- package/tools/gh-prs.test.js +1828 -0
- package/tools/issue-preview.test.js +119 -0
- package/tools/issues-cache-store.test.js +2 -2
- package/tools/issues-command.test.js +10 -3
- package/tools/issues-open-guard.test.js +15 -0
- package/tools/issues-section.test.js +618 -9
- package/tools/issues-view.test.js +297 -0
- package/tools/package-surface.test.js +18 -4
- package/tools/pr-preview.test.js +281 -0
- package/tools/prs-command.test.js +1280 -0
- package/tools/prs-rail-store.test.js +343 -0
- package/tools/prs-t10-safety.test.js +326 -0
- package/tools/prs-t12-safety.test.js +348 -0
- package/tools/prs-t13-independent.test.js +378 -0
- package/tools/prs-t14-safety.test.js +340 -0
- package/tools/prs-t15-independent.test.js +259 -0
- package/tools/prs-t18-safety.test.js +217 -0
- package/tools/prs-t7-safety.test.js +127 -0
- package/tools/prs-view.test.js +1462 -0
|
@@ -0,0 +1,1828 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// T1 (prs-panel S1-S3): tests for lib/gh-prs.js, the `gh` client of the `/prs`
|
|
3
|
+
// panel. It is the pull request sibling of lib/gh-issues.js, so it keeps the
|
|
4
|
+
// same contract: fixed argv (never a shell string), `--json`/GraphQL data
|
|
5
|
+
// parsed and normalized, repository identity pinned and validated, and every
|
|
6
|
+
// call answering `{ok:true, ...}` or `{ok:false, error}` without ever throwing.
|
|
7
|
+
//
|
|
8
|
+
// The runner seam (`setGhRunner`) means no test invokes the real `gh`. The
|
|
9
|
+
// fixtures under tools/fixtures/gh-pr-*.json carry payloads in the EXACT shapes
|
|
10
|
+
// `gh pr view --json …` and `gh api graphql` answer with (fields recorded from
|
|
11
|
+
// gh's documented `--json` set and the GraphQL schema); they are not dumps of a
|
|
12
|
+
// live run, because no authenticated `gh` is available in this environment.
|
|
13
|
+
|
|
14
|
+
const { test, describe, beforeEach, after } = require('node:test');
|
|
15
|
+
const assert = require('node:assert/strict');
|
|
16
|
+
const fs = require('node:fs');
|
|
17
|
+
const os = require('node:os');
|
|
18
|
+
const path = require('node:path');
|
|
19
|
+
const { execFileSync } = require('node:child_process');
|
|
20
|
+
|
|
21
|
+
const ghIssues = require('../lib/gh-issues.js');
|
|
22
|
+
const ghPrsModule = require('../lib/gh-prs.js');
|
|
23
|
+
// The client is built with the issue module INJECTED (the extension passes its
|
|
24
|
+
// own `libRequire('gh-issues.js')` instance in T5); no lib module may require it.
|
|
25
|
+
const ghPrs = ghPrsModule.bindIssuesClient(ghIssues);
|
|
26
|
+
|
|
27
|
+
const FIXTURES = path.join(__dirname, 'fixtures');
|
|
28
|
+
function fixture(name) {
|
|
29
|
+
return fs.readFileSync(path.join(FIXTURES, name), 'utf8');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function okJson(stdout) {
|
|
33
|
+
return { status: 0, stdout, stderr: '', error: null };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Every non-scope test binds the repository explicitly, so the identity lookup
|
|
37
|
+
// costs no `gh repo view` child and each assertion counts exactly the children
|
|
38
|
+
// the call under test runs.
|
|
39
|
+
const PINNED = { scope: 'octo/repo' };
|
|
40
|
+
|
|
41
|
+
// Recorder: captures (bin, argv) and answers from a script of outcomes.
|
|
42
|
+
function makeRunner(script) {
|
|
43
|
+
const calls = [];
|
|
44
|
+
const queue = Array.isArray(script) ? script.slice() : [script];
|
|
45
|
+
const runner = (bin, argv, runOpts) => {
|
|
46
|
+
calls.push({ bin, argv: argv.slice(), runOpts: { ...(runOpts || {}) } });
|
|
47
|
+
const next = queue.length > 1 ? queue.shift() : queue[0];
|
|
48
|
+
if (typeof next === 'function') return next(calls[calls.length - 1]);
|
|
49
|
+
return Promise.resolve({ status: 0, stdout: '', stderr: '', error: null, ...(next || {}) });
|
|
50
|
+
};
|
|
51
|
+
return { runner, calls };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The GraphQL query a child carries (`-f query=…`).
|
|
55
|
+
function queryOf(call) {
|
|
56
|
+
const at = call.argv.indexOf('-f');
|
|
57
|
+
return at >= 0 ? String(call.argv[at + 1]).replace(/^query=/, '') : '';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// A GraphQL variable the child carries (`-F name=value`), or null.
|
|
61
|
+
function fieldOf(call, name) {
|
|
62
|
+
for (let at = 0; at < call.argv.length - 1; at += 1) {
|
|
63
|
+
if (call.argv[at] === '-F' && String(call.argv[at + 1]).startsWith(`${name}=`)) {
|
|
64
|
+
return String(call.argv[at + 1]).slice(name.length + 1);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A metadata/permission answer shaped like the real `viewerPermission` query.
|
|
71
|
+
function pullRequestGraphql({
|
|
72
|
+
permission = 'WRITE', merge = true, squash = true, rebase = false, isDraft = false, viewer = 'octocat',
|
|
73
|
+
} = {}) {
|
|
74
|
+
const calls = [];
|
|
75
|
+
const runner = async (_bin, argv) => {
|
|
76
|
+
calls.push(argv.slice());
|
|
77
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
78
|
+
const query = queryOf({ argv });
|
|
79
|
+
if (query.includes('viewer { login }')) {
|
|
80
|
+
// S2/D31: the assignee read names the pull request too, so its state
|
|
81
|
+
// rides the same round trip.
|
|
82
|
+
return okJson(JSON.stringify({
|
|
83
|
+
data: {
|
|
84
|
+
repository: { viewerPermission: permission, pullRequest: { state: 'OPEN' } },
|
|
85
|
+
viewer: { login: viewer },
|
|
86
|
+
},
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
return okJson(JSON.stringify({
|
|
90
|
+
data: {
|
|
91
|
+
repository: {
|
|
92
|
+
viewerPermission: permission,
|
|
93
|
+
mergeCommitAllowed: merge,
|
|
94
|
+
squashMergeAllowed: squash,
|
|
95
|
+
rebaseMergeAllowed: rebase,
|
|
96
|
+
pullRequest: {
|
|
97
|
+
isDraft,
|
|
98
|
+
state: 'OPEN',
|
|
99
|
+
closingIssuesReferences: { nodes: [], pageInfo: { hasNextPage: false } },
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
return okJson('');
|
|
106
|
+
};
|
|
107
|
+
return { runner, calls };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// A repository-permission answer shaped like the client's own role read. The
|
|
111
|
+
// pull request state rides the same answer (S2/D20), so a write's own gate sees
|
|
112
|
+
// both facts in one round trip.
|
|
113
|
+
function okPermission(permission = 'WRITE', state = 'OPEN') {
|
|
114
|
+
return okJson(JSON.stringify({ data: { repository: { viewerPermission: permission, pullRequest: { state } } } }));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function argvStartingWith(calls, first, second) {
|
|
118
|
+
return calls.find((argv) => argv[0] === first && argv[1] === second);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const NO_CAPABILITIES = {
|
|
122
|
+
canEditLabels: false,
|
|
123
|
+
canCreateLabels: false,
|
|
124
|
+
canEditAssignees: false,
|
|
125
|
+
canClosePullRequests: false,
|
|
126
|
+
canMerge: false,
|
|
127
|
+
canEditLinkedIssues: false,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
beforeEach(() => {
|
|
131
|
+
ghPrs.setGhRunner(null);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// S1: the three scoped buckets read through the search API, exactly like the
|
|
136
|
+
// issues panel's buckets, and the caller's typed query rides that same search.
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
describe('the three buckets read through the repository search', () => {
|
|
139
|
+
test('the mine bucket asks for my open pull requests and normalizes every row', async () => {
|
|
140
|
+
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-search-page.json')));
|
|
141
|
+
ghPrs.setGhRunner(runner);
|
|
142
|
+
|
|
143
|
+
const res = await ghPrs.getPullRequestPage({ bucket: 'mine', pageSize: 30 }, PINNED);
|
|
144
|
+
|
|
145
|
+
assert.equal(res.ok, true, res.error);
|
|
146
|
+
assert.equal(calls.length, 1, 'one GraphQL request');
|
|
147
|
+
const call = calls[0];
|
|
148
|
+
assert.deepEqual(call.argv.slice(0, 2), ['api', 'graphql']);
|
|
149
|
+
assert.match(queryOf(call), /search\(query: \$search, type: ISSUE/);
|
|
150
|
+
assert.equal(fieldOf(call, 'search'), 'repo:octo/repo is:pr is:open author:@me sort:updated-desc');
|
|
151
|
+
assert.equal(fieldOf(call, 'first'), '30');
|
|
152
|
+
assert.equal(fieldOf(call, 'cursor'), null, 'the first page starts the connection');
|
|
153
|
+
|
|
154
|
+
assert.equal(res.totalCount, 2, 'the search reports its exact match count');
|
|
155
|
+
assert.equal(res.hasMore, false);
|
|
156
|
+
assert.equal(res.cursor, null);
|
|
157
|
+
assert.equal(res.rows.length, 2);
|
|
158
|
+
|
|
159
|
+
const row = res.rows[0];
|
|
160
|
+
assert.equal(row.number, 87);
|
|
161
|
+
assert.equal(row.title, 'feat: the prs panel');
|
|
162
|
+
assert.equal(row.state, 'open');
|
|
163
|
+
assert.equal(row.isDraft, false);
|
|
164
|
+
assert.equal(row.author, 'jonasotoaguilar');
|
|
165
|
+
assert.deepEqual(row.labels, [{ name: 'enhancement', color: 'a2eeef', description: 'New feature or request' }]);
|
|
166
|
+
assert.deepEqual(row.assignees, ['octocat']);
|
|
167
|
+
assert.equal(row.commentsCount, 2);
|
|
168
|
+
assert.equal(row.reviewDecision, 'REVIEW_REQUIRED');
|
|
169
|
+
assert.equal(row.createdAt, '2026-10-18T04:21:27Z');
|
|
170
|
+
assert.equal(row.updatedAt, '2026-10-19T08:00:00Z');
|
|
171
|
+
assert.equal(row.url, 'https://github.com/jonasotoaguilar/herdr-gentle-shell/pull/87');
|
|
172
|
+
assert.deepEqual(row.reactions, { total: 3, plusOne: 0 });
|
|
173
|
+
assert.equal(row.isPullRequest, true);
|
|
174
|
+
assert.equal(row.body, '', 'the list never asks for bodies');
|
|
175
|
+
assert.equal(row.cursor, 'Y3Vyc29yOnYyOpK5MjAyNi0xMC0xOVQwODowMDowMFo', 'every row keeps its own cursor');
|
|
176
|
+
|
|
177
|
+
assert.equal(res.rows[1].number, 86);
|
|
178
|
+
assert.equal(res.rows[1].isDraft, true);
|
|
179
|
+
assert.equal(res.rows[1].reviewDecision, '');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('the review and involved buckets carry their own qualifier', async () => {
|
|
183
|
+
for (const [bucket, qualifier] of [['review', 'review-requested:@me'], ['involved', 'involves:@me']]) {
|
|
184
|
+
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-search-page.json')));
|
|
185
|
+
ghPrs.setGhRunner(runner);
|
|
186
|
+
|
|
187
|
+
const res = await ghPrs.getPullRequestPage({ bucket }, PINNED);
|
|
188
|
+
|
|
189
|
+
assert.equal(res.ok, true, res.error);
|
|
190
|
+
assert.equal(fieldOf(calls[0], 'search'), `repo:octo/repo is:pr is:open ${qualifier} sort:updated-desc`);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('a typed query rides the bucket search and an explicit sort is never doubled', async () => {
|
|
195
|
+
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-search-page.json')));
|
|
196
|
+
ghPrs.setGhRunner(runner);
|
|
197
|
+
|
|
198
|
+
const res = await ghPrs.getPullRequestPage({ bucket: 'mine', query: 'label:bug sort:created-asc' }, PINNED);
|
|
199
|
+
|
|
200
|
+
assert.equal(res.ok, true, res.error);
|
|
201
|
+
assert.equal(fieldOf(calls[0], 'search'),
|
|
202
|
+
'repo:octo/repo is:pr is:open author:@me label:bug sort:created-asc');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('a cursor page continues from the endCursor the previous page handed back', async () => {
|
|
206
|
+
const page = (edges, { issueCount, hasNextPage, endCursor }) => okJson(JSON.stringify({
|
|
207
|
+
data: {
|
|
208
|
+
search: {
|
|
209
|
+
issueCount,
|
|
210
|
+
pageInfo: { hasNextPage, endCursor },
|
|
211
|
+
edges: edges.map(([cursor, number]) => ({ cursor, node: { number, title: `pr ${number}`, state: 'OPEN' } })),
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
}));
|
|
215
|
+
const { runner, calls } = makeRunner([
|
|
216
|
+
page([['c1', 87], ['c2', 86]], { issueCount: 3, hasNextPage: true, endCursor: 'p1' }),
|
|
217
|
+
page([['c3', 85]], { issueCount: 3, hasNextPage: false, endCursor: null }),
|
|
218
|
+
]);
|
|
219
|
+
ghPrs.setGhRunner(runner);
|
|
220
|
+
|
|
221
|
+
const firstPage = await ghPrs.getPullRequestPage({ bucket: 'mine', pageSize: 3 }, PINNED);
|
|
222
|
+
|
|
223
|
+
assert.equal(firstPage.ok, true, firstPage.error);
|
|
224
|
+
assert.equal(firstPage.rows.length, 2, 'a short server page is a valid page, never filled by a second request');
|
|
225
|
+
assert.equal(firstPage.hasMore, true);
|
|
226
|
+
assert.equal(firstPage.cursor, 'p1');
|
|
227
|
+
|
|
228
|
+
const secondPage = await ghPrs.getPullRequestPage(
|
|
229
|
+
{ bucket: 'mine', pageSize: 3, cursor: firstPage.cursor }, PINNED,
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
assert.equal(secondPage.ok, true, secondPage.error);
|
|
233
|
+
assert.deepEqual(secondPage.rows.map((row) => row.number), [85]);
|
|
234
|
+
assert.equal(secondPage.hasMore, false);
|
|
235
|
+
assert.equal(secondPage.cursor, null);
|
|
236
|
+
assert.equal(fieldOf(calls[1], 'cursor'), 'p1', 'the next request resumes at the handed-back cursor');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('an invalid bucket, page size or cursor is refused without a child', async () => {
|
|
240
|
+
const { runner, calls } = makeRunner(okJson('{}'));
|
|
241
|
+
ghPrs.setGhRunner(runner);
|
|
242
|
+
|
|
243
|
+
const invalid = [
|
|
244
|
+
await ghPrs.getPullRequestPage({ bucket: 'bogus' }, PINNED),
|
|
245
|
+
await ghPrs.getPullRequestPage({ bucket: 'mine', pageSize: 0 }, PINNED),
|
|
246
|
+
await ghPrs.getPullRequestPage({ bucket: 'mine', pageSize: 1001 }, PINNED),
|
|
247
|
+
await ghPrs.getPullRequestPage({ bucket: 'mine', cursor: '' }, PINNED),
|
|
248
|
+
];
|
|
249
|
+
|
|
250
|
+
for (const res of invalid) assert.equal(res.ok, false);
|
|
251
|
+
assert.match(String(invalid[0].error), /invalid bucket "bogus": want mine, review, involved or all/);
|
|
252
|
+
assert.match(String(invalid[1].error), /pageSize must be 1\.\.1000/);
|
|
253
|
+
assert.match(String(invalid[3].error), /pageSize must be 1\.\.1000/);
|
|
254
|
+
assert.equal(calls.length, 0, 'no child runs for a rejected page');
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test('a search past GitHub\'s 1000-match cap fails honestly instead of truncating', async () => {
|
|
258
|
+
const { runner } = makeRunner(okJson(JSON.stringify({
|
|
259
|
+
data: { search: { issueCount: 1200, pageInfo: { hasNextPage: false, endCursor: null }, edges: [] } },
|
|
260
|
+
})));
|
|
261
|
+
ghPrs.setGhRunner(runner);
|
|
262
|
+
|
|
263
|
+
const res = await ghPrs.getPullRequestPage({ bucket: 'involved' }, PINNED);
|
|
264
|
+
|
|
265
|
+
assert.equal(res.ok, false);
|
|
266
|
+
assert.equal(res.truncated, true);
|
|
267
|
+
assert.match(String(res.error), /exceeds 1000 matches/);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test('a malformed search page fails closed', async () => {
|
|
271
|
+
const { runner } = makeRunner(okJson(JSON.stringify({ data: { search: {} } })));
|
|
272
|
+
ghPrs.setGhRunner(runner);
|
|
273
|
+
|
|
274
|
+
const res = await ghPrs.getPullRequestPage({ bucket: 'mine' }, PINNED);
|
|
275
|
+
|
|
276
|
+
assert.equal(res.ok, false);
|
|
277
|
+
assert.match(String(res.error), /invalid pull request page/);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// ---------------------------------------------------------------------------
|
|
282
|
+
// S1: the lazy `all prs` bucket is the repository CONNECTION, pageable to its
|
|
283
|
+
// exact total, and a typed query there stays a capped search.
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
describe('the All bucket reads the repository connection', () => {
|
|
286
|
+
test('getPullRequestConnectionPage asks for open pull requests with their exact total', async () => {
|
|
287
|
+
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-connection-page.json')));
|
|
288
|
+
ghPrs.setGhRunner(runner);
|
|
289
|
+
|
|
290
|
+
const res = await ghPrs.getPullRequestConnectionPage({ pageSize: 30 }, PINNED);
|
|
291
|
+
|
|
292
|
+
assert.equal(res.ok, true, res.error);
|
|
293
|
+
assert.equal(calls.length, 1);
|
|
294
|
+
const call = calls[0];
|
|
295
|
+
assert.match(queryOf(call), /pullRequests\(states: OPEN, first: \$first, after: \$cursor/);
|
|
296
|
+
assert.match(queryOf(call), /orderBy: \{field: UPDATED_AT, direction: DESC\}/);
|
|
297
|
+
assert.equal(fieldOf(call, 'owner'), 'octo');
|
|
298
|
+
assert.equal(fieldOf(call, 'name'), 'repo');
|
|
299
|
+
assert.equal(fieldOf(call, 'first'), '30');
|
|
300
|
+
assert.equal(res.totalCount, 2);
|
|
301
|
+
assert.equal(res.hasMore, false);
|
|
302
|
+
assert.equal(res.cursor, null);
|
|
303
|
+
assert.deepEqual(res.rows.map((row) => row.number), [87, 86]);
|
|
304
|
+
assert.equal(res.rows[0].isDraft, false);
|
|
305
|
+
assert.equal(res.rows[1].isDraft, true);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test('the all bucket without search text is the connection, and its short page keeps its boundary', async () => {
|
|
309
|
+
const { runner, calls } = makeRunner(okJson(JSON.stringify({
|
|
310
|
+
data: {
|
|
311
|
+
repository: {
|
|
312
|
+
pullRequests: {
|
|
313
|
+
totalCount: 5,
|
|
314
|
+
pageInfo: { hasNextPage: true, endCursor: 'p1' },
|
|
315
|
+
edges: [
|
|
316
|
+
{ cursor: 'c1', node: { number: 87, title: 'pr 87', state: 'OPEN' } },
|
|
317
|
+
{ cursor: 'c2', node: { number: 86, title: 'pr 86', state: 'OPEN' } },
|
|
318
|
+
],
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
})));
|
|
323
|
+
ghPrs.setGhRunner(runner);
|
|
324
|
+
|
|
325
|
+
const res = await ghPrs.getPullRequestPage({ bucket: 'all', pageSize: 3 }, PINNED);
|
|
326
|
+
|
|
327
|
+
assert.equal(res.ok, true, res.error);
|
|
328
|
+
assert.match(queryOf(calls[0]), /pullRequests\(states: OPEN/);
|
|
329
|
+
assert.equal(res.rows.length, 2);
|
|
330
|
+
assert.equal(res.hasMore, true, 'the connection still has pages after this short one');
|
|
331
|
+
assert.equal(res.cursor, 'p1');
|
|
332
|
+
assert.equal(res.totalCount, 5);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
test('the all bucket with typed text stays a capped search with no bucket qualifier', async () => {
|
|
336
|
+
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-search-page.json')));
|
|
337
|
+
ghPrs.setGhRunner(runner);
|
|
338
|
+
|
|
339
|
+
const res = await ghPrs.getPullRequestPage({ bucket: 'all', query: 'review:approved' }, PINNED);
|
|
340
|
+
|
|
341
|
+
assert.equal(res.ok, true, res.error);
|
|
342
|
+
assert.equal(fieldOf(calls[0], 'search'), 'repo:octo/repo is:pr is:open review:approved sort:updated-desc');
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// ---------------------------------------------------------------------------
|
|
347
|
+
// S1/S3: the detail read plus the metadata read — checks rollup, reviewers,
|
|
348
|
+
// linked issues, the merge methods the repository allows and GitHub's own merge
|
|
349
|
+
// proposals.
|
|
350
|
+
// ---------------------------------------------------------------------------
|
|
351
|
+
describe('getPullRequest: detail and metadata', () => {
|
|
352
|
+
test('the pane payload carries every fact the summary draws', async () => {
|
|
353
|
+
const { runner, calls } = makeRunner([
|
|
354
|
+
okJson(fixture('gh-pr-view.json')),
|
|
355
|
+
okJson(fixture('gh-pr-metadata.json')),
|
|
356
|
+
]);
|
|
357
|
+
ghPrs.setGhRunner(runner);
|
|
358
|
+
|
|
359
|
+
const res = await ghPrs.getPullRequest(87, { includeMetadata: true }, PINNED);
|
|
360
|
+
|
|
361
|
+
assert.equal(res.ok, true, res.error);
|
|
362
|
+
assert.equal(calls.length, 2, 'one detail read and one metadata read');
|
|
363
|
+
assert.deepEqual(calls[0].argv.slice(0, 3), ['pr', 'view', '87']);
|
|
364
|
+
assert.ok(calls[0].argv.includes('--json'));
|
|
365
|
+
|
|
366
|
+
const pr = res.pullRequest;
|
|
367
|
+
assert.equal(pr.number, 87);
|
|
368
|
+
assert.equal(pr.state, 'open');
|
|
369
|
+
assert.equal(pr.isDraft, false);
|
|
370
|
+
assert.equal(pr.author, 'jonasotoaguilar');
|
|
371
|
+
assert.deepEqual(pr.assignees, ['octocat']);
|
|
372
|
+
assert.equal(pr.body, JSON.parse(fixture('gh-pr-view.json')).body, 'the body arrives byte for byte');
|
|
373
|
+
assert.deepEqual(pr.reactions, { total: 3, plusOne: 0 });
|
|
374
|
+
assert.equal(pr.commentsCount, 2);
|
|
375
|
+
assert.equal(pr.baseRefName, 'main');
|
|
376
|
+
assert.equal(pr.headRefName, 'feat/prs-panel');
|
|
377
|
+
assert.equal(pr.additions, 412);
|
|
378
|
+
assert.equal(pr.deletions, 31);
|
|
379
|
+
assert.equal(pr.changedFiles, 9);
|
|
380
|
+
assert.equal(pr.commits, 2, 'the commit count is the commit list length');
|
|
381
|
+
assert.equal(pr.committedAt, '2026-10-19T07:30:00Z', 'the newest commit date');
|
|
382
|
+
assert.equal(pr.mergeable, 'MERGEABLE');
|
|
383
|
+
assert.equal(pr.mergeStateStatus, 'BLOCKED');
|
|
384
|
+
assert.equal(pr.reviewDecision, 'REVIEW_REQUIRED');
|
|
385
|
+
assert.deepEqual(pr.reviewers, [
|
|
386
|
+
{ login: 'reviewer-two', state: 'REQUESTED' },
|
|
387
|
+
{ login: 'reviewer-one', state: 'APPROVED' },
|
|
388
|
+
], 'an outstanding request is REQUESTED and a submitted review keeps its state');
|
|
389
|
+
assert.deepEqual(pr.linkedIssues, [14, 63], 'closingIssuesReferences, deduplicated and sorted');
|
|
390
|
+
assert.equal(pr.linkedIssuesTruncated, false);
|
|
391
|
+
assert.deepEqual(pr.checks, {
|
|
392
|
+
total: 5, passed: 3, failed: 1, pending: 1, state: 'FAILURE', failing: ['build'],
|
|
393
|
+
});
|
|
394
|
+
assert.deepEqual(pr.mergeMethods, { merge: true, squash: true }, 'only the methods the repository allows');
|
|
395
|
+
assert.deepEqual(pr.mergeDefaults, {
|
|
396
|
+
merge: {
|
|
397
|
+
subject: 'Merge pull request #87 from jonasotoaguilar/feat/prs-panel',
|
|
398
|
+
body: 'feat: the prs panel',
|
|
399
|
+
},
|
|
400
|
+
squash: { subject: 'feat: the prs panel', body: '' },
|
|
401
|
+
});
|
|
402
|
+
assert.deepEqual(pr.permissions, {
|
|
403
|
+
canEditLabels: true,
|
|
404
|
+
canCreateLabels: true,
|
|
405
|
+
canEditAssignees: true,
|
|
406
|
+
canClosePullRequests: true,
|
|
407
|
+
canMerge: true,
|
|
408
|
+
canEditLinkedIssues: true,
|
|
409
|
+
});
|
|
410
|
+
assert.equal(pr.permissions.canCreateLabels, true,
|
|
411
|
+
'the metadata carries the label-creation capability the picker needs');
|
|
412
|
+
assert.equal(pr.metadataError, null);
|
|
413
|
+
assert.deepEqual(pr.unavailable, []);
|
|
414
|
+
|
|
415
|
+
assert.equal(res.comments.length, 2);
|
|
416
|
+
assert.equal(res.comments[0].author, 'reviewer-one');
|
|
417
|
+
assert.equal(res.comments[0].body, 'Looks good to me');
|
|
418
|
+
assert.deepEqual(res.comments[0].reactions, { total: 2, plusOne: 2 });
|
|
419
|
+
assert.equal(res.comments[1].id, 'IC_kwDOA2');
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
test('a lost metadata read fails closed and names what is missing', async () => {
|
|
423
|
+
const { runner } = makeRunner([
|
|
424
|
+
okJson(fixture('gh-pr-view.json')),
|
|
425
|
+
{ status: 1, stdout: '', stderr: 'permission read failed', error: null },
|
|
426
|
+
]);
|
|
427
|
+
ghPrs.setGhRunner(runner);
|
|
428
|
+
|
|
429
|
+
const res = await ghPrs.getPullRequest(87, { includeMetadata: true }, PINNED);
|
|
430
|
+
|
|
431
|
+
assert.equal(res.ok, true, 'the detail read still answers');
|
|
432
|
+
const pr = res.pullRequest;
|
|
433
|
+
assert.deepEqual(pr.permissions, NO_CAPABILITIES, 'nothing is confirmed without a permission read');
|
|
434
|
+
assert.deepEqual(pr.mergeMethods, {}, 'no method is claimed for a read that failed');
|
|
435
|
+
assert.deepEqual(pr.mergeDefaults, {});
|
|
436
|
+
assert.match(String(pr.metadataError), /permission read failed/);
|
|
437
|
+
assert.deepEqual(pr.unavailable, ['permissions', 'merge methods']);
|
|
438
|
+
assert.deepEqual(pr.linkedIssues, [14, 63], 'the detail read already carried the linked issues');
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
test('a draft pull request cannot be merged, whatever the permission', async () => {
|
|
442
|
+
const { runner } = makeRunner([
|
|
443
|
+
okJson(fixture('gh-pr-view.json')),
|
|
444
|
+
okJson(JSON.stringify({
|
|
445
|
+
data: {
|
|
446
|
+
repository: {
|
|
447
|
+
viewerPermission: 'WRITE',
|
|
448
|
+
mergeCommitAllowed: true,
|
|
449
|
+
squashMergeAllowed: true,
|
|
450
|
+
rebaseMergeAllowed: true,
|
|
451
|
+
pullRequest: {
|
|
452
|
+
isDraft: true,
|
|
453
|
+
closingIssuesReferences: { nodes: [], pageInfo: { hasNextPage: false } },
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
})),
|
|
458
|
+
]);
|
|
459
|
+
ghPrs.setGhRunner(runner);
|
|
460
|
+
|
|
461
|
+
const res = await ghPrs.getPullRequest(87, { includeMetadata: true }, PINNED);
|
|
462
|
+
|
|
463
|
+
assert.equal(res.ok, true, res.error);
|
|
464
|
+
assert.equal(res.pullRequest.permissions.canMerge, false);
|
|
465
|
+
assert.equal(res.pullRequest.permissions.canClosePullRequests, true);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
test('a repository that allows no merge method offers none', async () => {
|
|
469
|
+
const { runner } = makeRunner([
|
|
470
|
+
okJson(fixture('gh-pr-view.json')),
|
|
471
|
+
okJson(JSON.stringify({
|
|
472
|
+
data: {
|
|
473
|
+
repository: {
|
|
474
|
+
viewerPermission: 'ADMIN',
|
|
475
|
+
mergeCommitAllowed: false,
|
|
476
|
+
squashMergeAllowed: false,
|
|
477
|
+
rebaseMergeAllowed: false,
|
|
478
|
+
pullRequest: {
|
|
479
|
+
isDraft: false,
|
|
480
|
+
closingIssuesReferences: { nodes: [], pageInfo: { hasNextPage: false } },
|
|
481
|
+
},
|
|
482
|
+
},
|
|
483
|
+
},
|
|
484
|
+
})),
|
|
485
|
+
]);
|
|
486
|
+
ghPrs.setGhRunner(runner);
|
|
487
|
+
|
|
488
|
+
const res = await ghPrs.getPullRequest(87, { includeMetadata: true }, PINNED);
|
|
489
|
+
|
|
490
|
+
assert.equal(res.ok, true, res.error);
|
|
491
|
+
assert.deepEqual(res.pullRequest.mergeMethods, {});
|
|
492
|
+
assert.deepEqual(res.pullRequest.mergeDefaults, {});
|
|
493
|
+
assert.equal(res.pullRequest.permissions.canMerge, false);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
test('a truncated linked-issue page is marked instead of passed off as whole', async () => {
|
|
497
|
+
const { runner } = makeRunner([
|
|
498
|
+
okJson(fixture('gh-pr-view.json')),
|
|
499
|
+
okJson(JSON.stringify({
|
|
500
|
+
data: {
|
|
501
|
+
repository: {
|
|
502
|
+
viewerPermission: 'WRITE',
|
|
503
|
+
mergeCommitAllowed: true,
|
|
504
|
+
squashMergeAllowed: false,
|
|
505
|
+
rebaseMergeAllowed: false,
|
|
506
|
+
pullRequest: {
|
|
507
|
+
isDraft: false,
|
|
508
|
+
closingIssuesReferences: { nodes: [{ number: 5 }], pageInfo: { hasNextPage: true } },
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
},
|
|
512
|
+
})),
|
|
513
|
+
]);
|
|
514
|
+
ghPrs.setGhRunner(runner);
|
|
515
|
+
|
|
516
|
+
const res = await ghPrs.getPullRequest(87, { includeMetadata: true }, PINNED);
|
|
517
|
+
|
|
518
|
+
assert.equal(res.ok, true, res.error);
|
|
519
|
+
assert.deepEqual(res.pullRequest.linkedIssues, [5]);
|
|
520
|
+
assert.equal(res.pullRequest.linkedIssuesTruncated, true);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
test('a detail read without metadata keeps the fail-closed shape', async () => {
|
|
524
|
+
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-view.json')));
|
|
525
|
+
ghPrs.setGhRunner(runner);
|
|
526
|
+
|
|
527
|
+
const res = await ghPrs.getPullRequest(87, {}, PINNED);
|
|
528
|
+
|
|
529
|
+
assert.equal(res.ok, true, res.error);
|
|
530
|
+
assert.equal(calls.length, 1, 'no metadata child');
|
|
531
|
+
assert.deepEqual(res.pullRequest.permissions, NO_CAPABILITIES);
|
|
532
|
+
assert.deepEqual(res.pullRequest.mergeMethods, {});
|
|
533
|
+
assert.deepEqual(res.pullRequest.mergeDefaults, {});
|
|
534
|
+
assert.deepEqual(res.pullRequest.linkedIssues, [14, 63]);
|
|
535
|
+
assert.equal(res.pullRequest.metadataError, null);
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// ---------------------------------------------------------------------------
|
|
540
|
+
// S2 + invariant 7: the capability map. Only a literal permitted role yields a
|
|
541
|
+
// capability, and merge additionally needs a non-draft pull request and at
|
|
542
|
+
// least one method the repository allows.
|
|
543
|
+
// ---------------------------------------------------------------------------
|
|
544
|
+
describe('pullRequestPermissions fails closed', () => {
|
|
545
|
+
test('the roles that may edit a pull request, and the ones that may not', () => {
|
|
546
|
+
const nonDraft = { isDraft: false, mergeMethods: { merge: true } };
|
|
547
|
+
|
|
548
|
+
assert.deepEqual(ghPrs.pullRequestPermissions('WRITE', nonDraft), {
|
|
549
|
+
canEditLabels: true,
|
|
550
|
+
canCreateLabels: true,
|
|
551
|
+
canEditAssignees: true,
|
|
552
|
+
canClosePullRequests: true,
|
|
553
|
+
canMerge: true,
|
|
554
|
+
canEditLinkedIssues: true,
|
|
555
|
+
});
|
|
556
|
+
for (const role of ['MAINTAIN', 'ADMIN']) {
|
|
557
|
+
assert.equal(ghPrs.pullRequestPermissions(role, nonDraft).canMerge, true, `${role} may merge`);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// TRIAGE may manage labels and assignees; it may not close, merge, create a
|
|
561
|
+
// repository label or rewrite the body of somebody else's pull request.
|
|
562
|
+
assert.deepEqual(ghPrs.pullRequestPermissions('TRIAGE', nonDraft), {
|
|
563
|
+
canEditLabels: true,
|
|
564
|
+
canCreateLabels: false,
|
|
565
|
+
canEditAssignees: true,
|
|
566
|
+
canClosePullRequests: false,
|
|
567
|
+
canMerge: false,
|
|
568
|
+
canEditLinkedIssues: false,
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
test('label creation is write-level, confirmed at WRITE and up alone', () => {
|
|
573
|
+
for (const role of ['WRITE', 'MAINTAIN', 'ADMIN']) {
|
|
574
|
+
assert.equal(ghPrs.pullRequestPermissions(role).canCreateLabels, true, `${role} may create a label`);
|
|
575
|
+
}
|
|
576
|
+
for (const role of ['TRIAGE', 'READ', 'NONE', 'write', null, undefined, true, {}]) {
|
|
577
|
+
assert.equal(ghPrs.pullRequestPermissions(role).canCreateLabels, false,
|
|
578
|
+
`${JSON.stringify(role)} confirms no label creation`);
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
test('read access, an unknown role and a missing role all confirm nothing', () => {
|
|
583
|
+
const nonDraft = { isDraft: false, mergeMethods: { merge: true, squash: true, rebase: true } };
|
|
584
|
+
for (const role of ['READ', 'NONE', 'write', 'TRIAGE ', null, undefined, true, {}]) {
|
|
585
|
+
assert.deepEqual(ghPrs.pullRequestPermissions(role, nonDraft), NO_CAPABILITIES,
|
|
586
|
+
`${JSON.stringify(role)} confirms no capability`);
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
test('merge needs a non-draft pull request and an allowed method', () => {
|
|
591
|
+
assert.equal(ghPrs.pullRequestPermissions('ADMIN', { isDraft: true, mergeMethods: { merge: true } }).canMerge, false);
|
|
592
|
+
assert.equal(ghPrs.pullRequestPermissions('ADMIN', { isDraft: false, mergeMethods: {} }).canMerge, false);
|
|
593
|
+
assert.equal(ghPrs.pullRequestPermissions('ADMIN').canMerge, false,
|
|
594
|
+
'a caller with no pull request facts confirms no merge');
|
|
595
|
+
});
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
// ---------------------------------------------------------------------------
|
|
599
|
+
// S2: every mutation's argv, one element per value, never a shell string.
|
|
600
|
+
// ---------------------------------------------------------------------------
|
|
601
|
+
describe('mutations: their exact argv', () => {
|
|
602
|
+
test('commentPullRequest passes the body as one argv element', async () => {
|
|
603
|
+
const { runner, calls } = makeRunner(okJson(''));
|
|
604
|
+
ghPrs.setGhRunner(runner);
|
|
605
|
+
|
|
606
|
+
const res = await ghPrs.commentPullRequest(87, 'looks good; $(rm -rf /) `id`', PINNED);
|
|
607
|
+
|
|
608
|
+
assert.equal(res.ok, true, res.error);
|
|
609
|
+
assert.deepEqual(calls[0].argv, ['pr', 'comment', '87', '--body', 'looks good; $(rm -rf /) `id`']);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
test('an empty comment body and a non-integer number are refused without a child', async () => {
|
|
613
|
+
const { runner, calls } = makeRunner(okJson(''));
|
|
614
|
+
ghPrs.setGhRunner(runner);
|
|
615
|
+
|
|
616
|
+
const empty = await ghPrs.commentPullRequest(87, ' ', PINNED);
|
|
617
|
+
const invalid = await ghPrs.commentPullRequest('abc', 'hi', PINNED);
|
|
618
|
+
|
|
619
|
+
assert.equal(empty.ok, false);
|
|
620
|
+
assert.match(String(empty.error), /comment body must be a non-empty string/);
|
|
621
|
+
assert.equal(invalid.ok, false);
|
|
622
|
+
assert.match(String(invalid.error), /invalid pull request number "abc": want a positive integer/);
|
|
623
|
+
assert.equal(calls.length, 0);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
test('editLabels applies and removes labels through the pull request surface', async () => {
|
|
627
|
+
const { runner, calls } = makeRunner([okPermission(), okJson('')]);
|
|
628
|
+
ghPrs.setGhRunner(runner);
|
|
629
|
+
|
|
630
|
+
const res = await ghPrs.editLabels(87, { add: ['bug'], remove: ['wontfix'] }, PINNED);
|
|
631
|
+
|
|
632
|
+
assert.equal(res.ok, true, res.error);
|
|
633
|
+
assert.deepEqual(argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit'),
|
|
634
|
+
['pr', 'edit', '87', '--add-label', 'bug', '--remove-label', 'wontfix']);
|
|
635
|
+
assert.match(queryOf(calls[0]), /viewerPermission/, 'the role is read before the write');
|
|
636
|
+
const noop = await ghPrs.editLabels(87, {}, PINNED);
|
|
637
|
+
assert.equal(noop.ok, true);
|
|
638
|
+
assert.equal(calls.length, 2, 'an empty edit runs no child');
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
test('listLabels and createLabel are repository-level and mirrored here', async () => {
|
|
642
|
+
const { runner, calls } = makeRunner([
|
|
643
|
+
okJson(fixture('gh-label-list.json')), okPermission(), okJson('{"name":"triage"}'),
|
|
644
|
+
]);
|
|
645
|
+
ghPrs.setGhRunner(runner);
|
|
646
|
+
|
|
647
|
+
const labels = await ghPrs.listLabels(PINNED);
|
|
648
|
+
assert.equal(labels.ok, true, labels.error);
|
|
649
|
+
assert.ok(labels.labels.length >= 1);
|
|
650
|
+
const created = await ghPrs.createLabel({ name: 'triage', color: 'FBCA04' }, PINNED);
|
|
651
|
+
|
|
652
|
+
assert.equal(created.ok, true, created.error);
|
|
653
|
+
assert.deepEqual(calls[0].argv.slice(0, 2), ['label', 'list']);
|
|
654
|
+
assert.match(queryOf(calls[1]), /viewerPermission/, 'creating a label reads the role first');
|
|
655
|
+
assert.deepEqual(calls[2].argv, ['label', 'create', 'triage', '--color', 'FBCA04']);
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
test('closePullRequest closes exactly one pull request', async () => {
|
|
659
|
+
const { runner, calls } = makeRunner([okPermission(), okJson('')]);
|
|
660
|
+
ghPrs.setGhRunner(runner);
|
|
661
|
+
|
|
662
|
+
const res = await ghPrs.closePullRequest(87, PINNED);
|
|
663
|
+
|
|
664
|
+
assert.equal(res.ok, true, res.error);
|
|
665
|
+
assert.match(queryOf(calls[0]), /viewerPermission/, 'the role is read before the write');
|
|
666
|
+
assert.deepEqual(argvStartingWith(calls.map((call) => call.argv), 'pr', 'close'), ['pr', 'close', '87']);
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
test('mergePullRequest pins the method flag and the proposals it was given', async () => {
|
|
670
|
+
const fake = pullRequestGraphql({ merge: true, squash: true, rebase: false });
|
|
671
|
+
ghPrs.setGhRunner(fake.runner);
|
|
672
|
+
|
|
673
|
+
const res = await ghPrs.mergePullRequest(
|
|
674
|
+
87, { method: 'merge', subject: 'Merge pull request #87', body: 'feat: the prs panel' }, PINNED,
|
|
675
|
+
);
|
|
676
|
+
|
|
677
|
+
assert.equal(res.ok, true, res.error);
|
|
678
|
+
assert.deepEqual(argvStartingWith(fake.calls, 'pr', 'merge'),
|
|
679
|
+
['pr', 'merge', '87', '--merge', '--subject', 'Merge pull request #87', '--body', 'feat: the prs panel']);
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
test('squash carries no proposal when none was given, and rebase takes neither', async () => {
|
|
683
|
+
const squash = pullRequestGraphql({ merge: false, squash: true, rebase: false });
|
|
684
|
+
ghPrs.setGhRunner(squash.runner);
|
|
685
|
+
const squashed = await ghPrs.mergePullRequest(87, { method: 'squash' }, PINNED);
|
|
686
|
+
assert.equal(squashed.ok, true, squashed.error);
|
|
687
|
+
assert.deepEqual(argvStartingWith(squash.calls, 'pr', 'merge'), ['pr', 'merge', '87', '--squash']);
|
|
688
|
+
|
|
689
|
+
const rebase = pullRequestGraphql({ merge: false, squash: false, rebase: true });
|
|
690
|
+
ghPrs.setGhRunner(rebase.runner);
|
|
691
|
+
const rebased = await ghPrs.mergePullRequest(87, { method: 'rebase', subject: 'ignored', body: 'ignored' }, PINNED);
|
|
692
|
+
assert.equal(rebased.ok, true, rebased.error);
|
|
693
|
+
assert.deepEqual(argvStartingWith(rebase.calls, 'pr', 'merge'), ['pr', 'merge', '87', '--rebase'],
|
|
694
|
+
'a rebase merge takes neither a subject nor a body');
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
test('merge refuses a method the repository does not allow', async () => {
|
|
698
|
+
const fake = pullRequestGraphql({ merge: true, squash: false, rebase: false });
|
|
699
|
+
ghPrs.setGhRunner(fake.runner);
|
|
700
|
+
|
|
701
|
+
const res = await ghPrs.mergePullRequest(87, { method: 'squash' }, PINNED);
|
|
702
|
+
|
|
703
|
+
assert.equal(res.ok, false);
|
|
704
|
+
assert.match(String(res.error), /the repository does not allow the "squash" merge method/);
|
|
705
|
+
assert.equal(argvStartingWith(fake.calls, 'pr', 'merge'), undefined, 'no merge child runs');
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
test('merge refuses a draft pull request', async () => {
|
|
709
|
+
const fake = pullRequestGraphql({ isDraft: true });
|
|
710
|
+
ghPrs.setGhRunner(fake.runner);
|
|
711
|
+
|
|
712
|
+
const res = await ghPrs.mergePullRequest(87, { method: 'merge' }, PINNED);
|
|
713
|
+
|
|
714
|
+
assert.equal(res.ok, false);
|
|
715
|
+
assert.match(String(res.error), /pull request #87 is a draft/);
|
|
716
|
+
assert.equal(argvStartingWith(fake.calls, 'pr', 'merge'), undefined);
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
test('merge refuses a repository that allows no method and a viewer who may not merge', async () => {
|
|
720
|
+
const none = pullRequestGraphql({ merge: false, squash: false, rebase: false });
|
|
721
|
+
ghPrs.setGhRunner(none.runner);
|
|
722
|
+
const noMethod = await ghPrs.mergePullRequest(87, { method: 'merge' }, PINNED);
|
|
723
|
+
assert.equal(noMethod.ok, false);
|
|
724
|
+
assert.match(String(noMethod.error), /allows no merge method/);
|
|
725
|
+
|
|
726
|
+
const readOnly = pullRequestGraphql({ permission: 'READ' });
|
|
727
|
+
ghPrs.setGhRunner(readOnly.runner);
|
|
728
|
+
const denied = await ghPrs.mergePullRequest(87, { method: 'merge' }, PINNED);
|
|
729
|
+
assert.equal(denied.ok, false);
|
|
730
|
+
assert.match(String(denied.error), /Repository permission does not allow merging pull requests/);
|
|
731
|
+
assert.equal(argvStartingWith(readOnly.calls, 'pr', 'merge'), undefined);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
test('an unknown merge method is refused before any child runs', async () => {
|
|
735
|
+
const { runner, calls } = makeRunner(okJson(''));
|
|
736
|
+
ghPrs.setGhRunner(runner);
|
|
737
|
+
|
|
738
|
+
const res = await ghPrs.mergePullRequest(87, { method: 'fast-forward' }, PINNED);
|
|
739
|
+
|
|
740
|
+
assert.equal(res.ok, false);
|
|
741
|
+
assert.match(String(res.error), /invalid merge method "fast-forward": want merge, squash or rebase/);
|
|
742
|
+
assert.equal(calls.length, 0);
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
test('editAssignees checks the permission and then toggles the viewer', async () => {
|
|
746
|
+
const fake = pullRequestGraphql({ permission: 'WRITE', viewer: 'octocat' });
|
|
747
|
+
ghPrs.setGhRunner(fake.runner);
|
|
748
|
+
|
|
749
|
+
const res = await ghPrs.editAssignees(87, { add: ['octocat'], remove: ['someone'] }, PINNED);
|
|
750
|
+
|
|
751
|
+
assert.equal(res.ok, true, res.error);
|
|
752
|
+
assert.equal(res.self, true, 'the toggle names the authenticated viewer');
|
|
753
|
+
assert.deepEqual(argvStartingWith(fake.calls, 'pr', 'edit'),
|
|
754
|
+
['pr', 'edit', '87', '--add-assignee', 'octocat', '--remove-assignee', 'someone']);
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
test('editAssignees refuses a denied permission and a malformed login', async () => {
|
|
758
|
+
const readOnly = pullRequestGraphql({ permission: 'READ' });
|
|
759
|
+
ghPrs.setGhRunner(readOnly.runner);
|
|
760
|
+
const denied = await ghPrs.editAssignees(87, { add: ['octocat'] }, PINNED);
|
|
761
|
+
assert.equal(denied.ok, false);
|
|
762
|
+
assert.match(String(denied.error), /does not allow changing pull request assignees/);
|
|
763
|
+
assert.equal(argvStartingWith(readOnly.calls, 'pr', 'edit'), undefined);
|
|
764
|
+
|
|
765
|
+
const { runner, calls } = makeRunner(okJson(''));
|
|
766
|
+
ghPrs.setGhRunner(runner);
|
|
767
|
+
const malformed = await ghPrs.editAssignees(87, { add: ['not a login!'] }, PINNED);
|
|
768
|
+
assert.equal(malformed.ok, false);
|
|
769
|
+
assert.match(String(malformed.error), /invalid assignee changes/);
|
|
770
|
+
assert.equal(calls.length, 0);
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
test('a failing mutation reports gh\'s own words', async () => {
|
|
774
|
+
const { runner } = makeRunner({ status: 1, stdout: '', stderr: 'Could not resolve to a PullRequest', error: null });
|
|
775
|
+
ghPrs.setGhRunner(runner);
|
|
776
|
+
|
|
777
|
+
const closed = await ghPrs.closePullRequest(87, PINNED);
|
|
778
|
+
const commented = await ghPrs.commentPullRequest(87, 'hi', PINNED);
|
|
779
|
+
const merged = await ghPrs.mergePullRequest(87, { method: 'merge' }, PINNED);
|
|
780
|
+
|
|
781
|
+
for (const res of [closed, commented, merged]) {
|
|
782
|
+
assert.equal(res.ok, false);
|
|
783
|
+
assert.match(String(res.error), /Could not resolve/);
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
// ---------------------------------------------------------------------------
|
|
789
|
+
// S2 (D2): a capability is read AGAIN by the client itself, so a pane painted
|
|
790
|
+
// from a lost permission still never issues a write child. Read access keeps
|
|
791
|
+
// the one ungated write S2 names: the comment.
|
|
792
|
+
// ---------------------------------------------------------------------------
|
|
793
|
+
describe('every write re-reads the repository role before it runs', () => {
|
|
794
|
+
const WRITES = [
|
|
795
|
+
['closePullRequest', 'does not allow closing pull requests', (client) => client.closePullRequest(87, PINNED)],
|
|
796
|
+
['createLabel', 'does not allow creating labels', (client) => client.createLabel({ name: 'needs-work' }, PINNED)],
|
|
797
|
+
['editLabels', 'does not allow editing pull request labels',
|
|
798
|
+
(client) => client.editLabels(87, { add: ['bug'] }, PINNED)],
|
|
799
|
+
['editLinkedIssues', 'does not allow editing pull request linked issues',
|
|
800
|
+
(client) => client.editLinkedIssues(87, { add: [12] }, PINNED)],
|
|
801
|
+
];
|
|
802
|
+
|
|
803
|
+
for (const [name, sentence, call] of WRITES) {
|
|
804
|
+
test(`${name} fails closed on READ access and names the missing permission`, async () => {
|
|
805
|
+
const { runner, calls } = makeRunner(okPermission('READ'));
|
|
806
|
+
ghPrs.setGhRunner(runner);
|
|
807
|
+
|
|
808
|
+
const res = await call(ghPrs);
|
|
809
|
+
|
|
810
|
+
assert.equal(res.ok, false, `${name} is refused`);
|
|
811
|
+
assert.match(String(res.error), new RegExp(sentence));
|
|
812
|
+
assert.equal(calls.length, 1, 'the role read is the only child');
|
|
813
|
+
assert.match(queryOf(calls[0]), /viewerPermission/);
|
|
814
|
+
const write = calls.find((entry) => !(entry.argv[0] === 'api' && entry.argv[1] === 'graphql'));
|
|
815
|
+
assert.equal(write, undefined, `${name} spawns no write child`);
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
test('a TRIAGE role may label but may not close, create or rewrite the body', async () => {
|
|
820
|
+
const triage = pullRequestGraphql({ permission: 'TRIAGE' });
|
|
821
|
+
ghPrs.setGhRunner(triage.runner);
|
|
822
|
+
|
|
823
|
+
const labelled = await ghPrs.editLabels(87, { add: ['bug'] }, PINNED);
|
|
824
|
+
assert.equal(labelled.ok, true, labelled.error);
|
|
825
|
+
const created = await ghPrs.createLabel({ name: 'needs-work' }, PINNED);
|
|
826
|
+
const closed = await ghPrs.closePullRequest(87, PINNED);
|
|
827
|
+
const linked = await ghPrs.editLinkedIssues(87, { add: [12] }, PINNED);
|
|
828
|
+
|
|
829
|
+
for (const res of [created, closed, linked]) assert.equal(res.ok, false);
|
|
830
|
+
assert.match(String(created.error), /does not allow creating labels/);
|
|
831
|
+
assert.match(String(closed.error), /does not allow closing pull requests/);
|
|
832
|
+
assert.match(String(linked.error), /does not allow editing pull request linked issues/);
|
|
833
|
+
assert.equal(argvStartingWith(triage.calls, 'pr', 'close'), undefined);
|
|
834
|
+
assert.equal(argvStartingWith(triage.calls, 'label', 'create'), undefined);
|
|
835
|
+
assert.equal(triage.calls.filter((argv) => argv[0] === 'pr' && argv[1] === 'edit').length, 1,
|
|
836
|
+
'the one write that ran is the label edit');
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
test('a comment stays ungated, exactly like the issue client', async () => {
|
|
840
|
+
const { runner, calls } = makeRunner(okJson(''));
|
|
841
|
+
ghPrs.setGhRunner(runner);
|
|
842
|
+
|
|
843
|
+
const res = await ghPrs.commentPullRequest(87, 'hi', PINNED);
|
|
844
|
+
|
|
845
|
+
assert.equal(res.ok, true, res.error);
|
|
846
|
+
assert.deepEqual(calls.map((call) => call.argv), [['pr', 'comment', '87', '--body', 'hi']],
|
|
847
|
+
'no role read and no gate stands in front of a comment');
|
|
848
|
+
});
|
|
849
|
+
});
|
|
850
|
+
|
|
851
|
+
// ---------------------------------------------------------------------------
|
|
852
|
+
// S2 (D13): a write and the role read that authorizes it share ONE resolved
|
|
853
|
+
// repository scope. The checkout is resolved once, and every child of the write
|
|
854
|
+
// — the role read included — runs under the identity it proved, so a remote
|
|
855
|
+
// that moves between the two children cannot authorize one repository and write
|
|
856
|
+
// under another.
|
|
857
|
+
// ---------------------------------------------------------------------------
|
|
858
|
+
describe('a write shares one resolved scope with its role read', () => {
|
|
859
|
+
const CALLS = [
|
|
860
|
+
['closePullRequest', (client, opts) => client.closePullRequest(87, opts),
|
|
861
|
+
(argv) => argv[0] === 'pr' && argv[1] === 'close'],
|
|
862
|
+
['editLabels', (client, opts) => client.editLabels(87, { add: ['bug'] }, opts),
|
|
863
|
+
(argv) => argv[0] === 'pr' && argv[1] === 'edit' && argv.includes('--add-label')],
|
|
864
|
+
['editAssignees', (client, opts) => client.editAssignees(87, { add: ['octocat'] }, opts),
|
|
865
|
+
(argv) => argv[0] === 'pr' && argv[1] === 'edit' && argv.includes('--add-assignee')],
|
|
866
|
+
['editLinkedIssues', (client, opts) => client.editLinkedIssues(87, { add: [99] }, opts),
|
|
867
|
+
(argv) => argv[0] === 'pr' && argv[1] === 'edit' && argv.includes('--body')],
|
|
868
|
+
['mergePullRequest', (client, opts) => client.mergePullRequest(87, { method: 'merge' }, opts),
|
|
869
|
+
(argv) => argv[0] === 'pr' && argv[1] === 'merge'],
|
|
870
|
+
];
|
|
871
|
+
|
|
872
|
+
// A checkout whose remote MOVES: every resolution hands back a new repository,
|
|
873
|
+
// so a child that resolves on its own writes somewhere the role read never saw.
|
|
874
|
+
function movingCheckout() {
|
|
875
|
+
const resolved = [];
|
|
876
|
+
const children = [];
|
|
877
|
+
const checkoutRepoScope = async () => {
|
|
878
|
+
resolved.push(`github.com/octo/repo-${resolved.length + 1}`);
|
|
879
|
+
return { ok: true, identity: resolved.at(-1), nameWithOwner: `octo/repo-${resolved.length}` };
|
|
880
|
+
};
|
|
881
|
+
const runGh = async (argv, opts = {}) => {
|
|
882
|
+
let identity = null;
|
|
883
|
+
if (opts.scope !== undefined) {
|
|
884
|
+
identity = opts.scope === null || opts.scope === '' ? null : String(opts.scope);
|
|
885
|
+
} else if (typeof opts.cwd === 'string' && opts.cwd !== '') {
|
|
886
|
+
const scope = await checkoutRepoScope({ ...opts, fresh: opts.freshScope === true });
|
|
887
|
+
if (scope.ok !== true) return { status: null, stdout: '', stderr: '', error: scope.error };
|
|
888
|
+
identity = scope.identity;
|
|
889
|
+
}
|
|
890
|
+
children.push({ argv: argv.slice(), identity });
|
|
891
|
+
if (argv[0] === 'repo') return okJson(JSON.stringify({ nameWithOwner: 'octo/base' }));
|
|
892
|
+
if (argv[0] === 'api' && queryOf({ argv }).includes('viewer { login }')) {
|
|
893
|
+
return okJson(JSON.stringify({
|
|
894
|
+
data: {
|
|
895
|
+
repository: { viewerPermission: 'WRITE', pullRequest: { state: 'OPEN' } },
|
|
896
|
+
viewer: { login: 'octocat' },
|
|
897
|
+
},
|
|
898
|
+
}));
|
|
899
|
+
}
|
|
900
|
+
if (argv[0] === 'api') {
|
|
901
|
+
return okJson(JSON.stringify({
|
|
902
|
+
data: {
|
|
903
|
+
repository: {
|
|
904
|
+
viewerPermission: 'WRITE',
|
|
905
|
+
mergeCommitAllowed: true,
|
|
906
|
+
squashMergeAllowed: false,
|
|
907
|
+
rebaseMergeAllowed: false,
|
|
908
|
+
pullRequest: {
|
|
909
|
+
isDraft: false,
|
|
910
|
+
state: 'OPEN',
|
|
911
|
+
closingIssuesReferences: { nodes: [], pageInfo: { hasNextPage: false } },
|
|
912
|
+
},
|
|
913
|
+
},
|
|
914
|
+
},
|
|
915
|
+
}));
|
|
916
|
+
}
|
|
917
|
+
// The body read answers the pull request STATE with the body (S2/T18).
|
|
918
|
+
if (argv[0] === 'pr' && argv[1] === 'view') return okJson(JSON.stringify({ body: 'Closes #12', state: 'OPEN' }));
|
|
919
|
+
return okJson('');
|
|
920
|
+
};
|
|
921
|
+
return { runGh, checkoutRepoScope, children, resolved };
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
for (const [name, call, isWrite] of CALLS) {
|
|
925
|
+
test(`${name} authorizes and writes in the same resolved repository`, async () => {
|
|
926
|
+
const checkout = movingCheckout();
|
|
927
|
+
const client = ghPrsModule.createPrsClient({ issues: checkout });
|
|
928
|
+
|
|
929
|
+
const res = await call(client, { cwd: '/checkout' });
|
|
930
|
+
|
|
931
|
+
assert.equal(res.ok, true, res.error);
|
|
932
|
+
assert.equal(checkout.resolved.length, 1, 'the checkout is resolved once for the whole write');
|
|
933
|
+
const writes = checkout.children.filter((child) => isWrite(child.argv));
|
|
934
|
+
assert.equal(writes.length, 1, `${name} spawns exactly one write child`);
|
|
935
|
+
assert.equal(writes[0].identity, 'github.com/octo/repo-1',
|
|
936
|
+
`${name} wrote under the repository the role read proved`);
|
|
937
|
+
for (const child of checkout.children.filter((entry) => entry.argv[0] !== 'repo')) {
|
|
938
|
+
assert.equal(child.identity, writes[0].identity,
|
|
939
|
+
`${child.argv.slice(0, 2).join(' ')} ran under ${child.identity}, not the write's identity`);
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
test('an unprovable checkout refuses before the role read or the write runs', async () => {
|
|
945
|
+
const children = [];
|
|
946
|
+
const client = ghPrsModule.createPrsClient({
|
|
947
|
+
issues: {
|
|
948
|
+
runGh: async (argv) => { children.push(argv.slice()); return okJson(''); },
|
|
949
|
+
checkoutRepoScope: async () => ({ ok: false, error: 'cannot resolve the repository' }),
|
|
950
|
+
},
|
|
951
|
+
});
|
|
952
|
+
|
|
953
|
+
const res = await client.closePullRequest(87, { cwd: '/checkout' });
|
|
954
|
+
|
|
955
|
+
assert.equal(res.ok, false);
|
|
956
|
+
assert.match(String(res.error), /cannot resolve the repository/);
|
|
957
|
+
assert.deepEqual(children, [], 'nothing runs against a repository it could not prove');
|
|
958
|
+
});
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
// ---------------------------------------------------------------------------
|
|
962
|
+
// S2: GitHub has no mutation for the Development panel, so a linked issue is a
|
|
963
|
+
// `Closes #N` line in the body — appended or removed, with every other byte of
|
|
964
|
+
// the body preserved exactly.
|
|
965
|
+
// ---------------------------------------------------------------------------
|
|
966
|
+
describe('editLinkedIssues rewrites only the closing lines', () => {
|
|
967
|
+
test('adding a linked issue appends one marked Closes line and keeps the body byte for byte', async () => {
|
|
968
|
+
// The body is read twice (prepare, then re-read before the write), so the
|
|
969
|
+
// fixture answers both reads and the edit is the last child.
|
|
970
|
+
const { runner, calls } = makeRunner([
|
|
971
|
+
okPermission(), okJson(fixture('gh-pr-view.json')), okJson(fixture('gh-pr-view.json')), okJson(''),
|
|
972
|
+
]);
|
|
973
|
+
ghPrs.setGhRunner(runner);
|
|
974
|
+
const original = JSON.parse(fixture('gh-pr-view.json')).body;
|
|
975
|
+
|
|
976
|
+
const res = await ghPrs.editLinkedIssues(87, { add: [71] }, PINNED);
|
|
977
|
+
|
|
978
|
+
assert.equal(res.ok, true, res.error);
|
|
979
|
+
assert.equal(res.changed, true);
|
|
980
|
+
assert.match(queryOf(calls[0]), /viewerPermission/, 'the role is read before the body edit');
|
|
981
|
+
// S2/D27: the body is read once to prepare the edit and once more right
|
|
982
|
+
// before the write, so the edit is the fourth child.
|
|
983
|
+
const argv = calls[3].argv;
|
|
984
|
+
assert.deepEqual(argv.slice(0, 4), ['pr', 'edit', '87', '--body']);
|
|
985
|
+
const body = argv[argv.indexOf('--body') + 1];
|
|
986
|
+
assert.equal(body, `${original}\n\nCloses #71 ${MARK}\n`);
|
|
987
|
+
assert.ok(body.startsWith(original), 'the original body is untouched');
|
|
988
|
+
assert.equal(res.body, body);
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
test('removing a marked linked issue keeps CRLF endings and every other byte', async () => {
|
|
992
|
+
// S2/D27: a removal only ever deletes a line this panel wrote, so the
|
|
993
|
+
// fixture carries its marker. S2/T18: that line is the EXACT one this panel
|
|
994
|
+
// writes — a variant keyword case is a look-alike and is refused — and the
|
|
995
|
+
// re-read before the write answers the state with the body.
|
|
996
|
+
const original = `Summary line\r\n\r\nCloses #14 ${MARK}\r\nCloses #63\r\nTrailing words`;
|
|
997
|
+
const { runner, calls } = makeRunner([
|
|
998
|
+
okPermission(),
|
|
999
|
+
okJson(JSON.stringify({ body: original, state: 'OPEN' })),
|
|
1000
|
+
okJson(JSON.stringify({ body: original, state: 'OPEN' })),
|
|
1001
|
+
okJson(''),
|
|
1002
|
+
]);
|
|
1003
|
+
ghPrs.setGhRunner(runner);
|
|
1004
|
+
|
|
1005
|
+
const res = await ghPrs.editLinkedIssues(87, { remove: [14] }, PINNED);
|
|
1006
|
+
|
|
1007
|
+
assert.equal(res.ok, true, res.error);
|
|
1008
|
+
const body = calls[3].argv[calls[3].argv.indexOf('--body') + 1];
|
|
1009
|
+
assert.equal(body, 'Summary line\r\n\r\nCloses #63\r\nTrailing words');
|
|
1010
|
+
assert.equal(res.changed, true);
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
test('a declaration this panel did not write is refused, never rewritten', async () => {
|
|
1014
|
+
const original = 'Summary line\n\nCloses #63\n';
|
|
1015
|
+
const { runner, calls } = makeRunner([okPermission(), okJson(JSON.stringify({ body: original }))]);
|
|
1016
|
+
ghPrs.setGhRunner(runner);
|
|
1017
|
+
|
|
1018
|
+
const res = await ghPrs.editLinkedIssues(87, { remove: [63] }, PINNED);
|
|
1019
|
+
|
|
1020
|
+
assert.deepEqual(res, { ok: false, error: 'that link was not added by this panel; remove it on GitHub' });
|
|
1021
|
+
assert.equal(argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit'), undefined);
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
test('a number already declared changes nothing and runs no edit child', async () => {
|
|
1025
|
+
const { runner, calls } = makeRunner([okPermission(), okJson(fixture('gh-pr-view.json'))]);
|
|
1026
|
+
ghPrs.setGhRunner(runner);
|
|
1027
|
+
|
|
1028
|
+
const res = await ghPrs.editLinkedIssues(87, { add: [63] }, PINNED);
|
|
1029
|
+
|
|
1030
|
+
assert.equal(res.ok, true, res.error);
|
|
1031
|
+
assert.equal(res.changed, false);
|
|
1032
|
+
assert.equal(calls.length, 2, 'the role and the body read ran; no edit child did');
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
test('invalid linked-issue changes are refused without a child', async () => {
|
|
1036
|
+
const { runner, calls } = makeRunner(okJson(''));
|
|
1037
|
+
ghPrs.setGhRunner(runner);
|
|
1038
|
+
|
|
1039
|
+
for (const changes of [
|
|
1040
|
+
{ add: [0] },
|
|
1041
|
+
{ add: ['71'] },
|
|
1042
|
+
{ add: [71], remove: [71] },
|
|
1043
|
+
{ add: [-3] },
|
|
1044
|
+
]) {
|
|
1045
|
+
const res = await ghPrs.editLinkedIssues(87, changes, PINNED);
|
|
1046
|
+
assert.equal(res.ok, false, `${JSON.stringify(changes)} is refused`);
|
|
1047
|
+
assert.match(String(res.error), /invalid linked-issue changes: supply distinct positive issue numbers/);
|
|
1048
|
+
}
|
|
1049
|
+
assert.equal(calls.length, 0);
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
test('an unreadable body is reported instead of being overwritten', async () => {
|
|
1053
|
+
const { runner, calls } = makeRunner([
|
|
1054
|
+
okPermission(),
|
|
1055
|
+
{ status: 1, stdout: '', stderr: 'Could not resolve to a PullRequest', error: null },
|
|
1056
|
+
]);
|
|
1057
|
+
ghPrs.setGhRunner(runner);
|
|
1058
|
+
|
|
1059
|
+
const res = await ghPrs.editLinkedIssues(87, { add: [71] }, PINNED);
|
|
1060
|
+
|
|
1061
|
+
assert.equal(res.ok, false);
|
|
1062
|
+
assert.match(String(res.error), /cannot read the body of pull request #87/);
|
|
1063
|
+
assert.equal(calls.length, 2, 'no edit runs on a body that could not be read');
|
|
1064
|
+
assert.equal(argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit'), undefined);
|
|
1065
|
+
});
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
// ---------------------------------------------------------------------------
|
|
1069
|
+
// S2 (D4, D5): only the lines that really declare a closing issue may change,
|
|
1070
|
+
// and a merge refuses rather than sending facts GitHub never confirmed or a
|
|
1071
|
+
// message the reader cleared.
|
|
1072
|
+
// ---------------------------------------------------------------------------
|
|
1073
|
+
describe('merge and the body edit fail closed on missing facts', () => {
|
|
1074
|
+
test('a code example survives the removal of the panel\'s own marked line', async () => {
|
|
1075
|
+
// S2/D27: the fenced example carries no marker, so it is never a candidate;
|
|
1076
|
+
// only the marked declaration of the OTHER number is removed, and the
|
|
1077
|
+
// example's bytes stay exactly as they were.
|
|
1078
|
+
const body = `Intro\n\`\`\`text\nCloses #19\n\`\`\`\nCloses #12 ${MARK}\nKeep me`;
|
|
1079
|
+
const read = okJson(JSON.stringify({ body, state: 'OPEN' }));
|
|
1080
|
+
const { runner, calls } = makeRunner([okPermission(), read, read, okJson('')]);
|
|
1081
|
+
ghPrs.setGhRunner(runner);
|
|
1082
|
+
|
|
1083
|
+
const res = await ghPrs.editLinkedIssues(87, { remove: [12] }, PINNED);
|
|
1084
|
+
|
|
1085
|
+
assert.equal(res.ok, true, res.error);
|
|
1086
|
+
assert.equal(res.changed, true);
|
|
1087
|
+
const written = calls[3].argv[calls[3].argv.indexOf('--body') + 1];
|
|
1088
|
+
assert.equal(written, 'Intro\n```text\nCloses #19\n```\nKeep me',
|
|
1089
|
+
'the example inside the fence is untouched');
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
test('a removal deletes only the panel\'s own line and leaves a human declaration alone', async () => {
|
|
1093
|
+
// S2/D27: only a marked line is ever deleted. A declaration the human wrote
|
|
1094
|
+
// stays exactly where it is, even for the same number.
|
|
1095
|
+
const body = `Intro\nCloses #12\nCloses #12 ${MARK}\nKeep me\n`;
|
|
1096
|
+
const read = okJson(JSON.stringify({ body, state: 'OPEN' }));
|
|
1097
|
+
const { runner, calls } = makeRunner([okPermission(), read, read, okJson('')]);
|
|
1098
|
+
ghPrs.setGhRunner(runner);
|
|
1099
|
+
|
|
1100
|
+
const res = await ghPrs.editLinkedIssues(87, { remove: [12] }, PINNED);
|
|
1101
|
+
|
|
1102
|
+
assert.equal(res.ok, true, res.error);
|
|
1103
|
+
const edit = argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit');
|
|
1104
|
+
assert.equal(edit[edit.indexOf('--body') + 1], 'Intro\nCloses #12\nKeep me\n');
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
test('a column-0 declaration declares the number wherever it sits, so nothing is added', async () => {
|
|
1108
|
+
// S2/D27: the rewrite no longer decides what is code — a column-0
|
|
1109
|
+
// declaration declares its number, so the add changes nothing at all.
|
|
1110
|
+
const body = 'Example:\n~~~\nCloses #71\n~~~';
|
|
1111
|
+
const { runner, calls } = makeRunner([okPermission(), okJson(JSON.stringify({ body }))]);
|
|
1112
|
+
ghPrs.setGhRunner(runner);
|
|
1113
|
+
|
|
1114
|
+
const res = await ghPrs.editLinkedIssues(87, { add: [71] }, PINNED);
|
|
1115
|
+
|
|
1116
|
+
assert.equal(res.ok, true, res.error);
|
|
1117
|
+
assert.equal(res.changed, false);
|
|
1118
|
+
assert.equal(argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit'), undefined);
|
|
1119
|
+
});
|
|
1120
|
+
|
|
1121
|
+
test('a body that ends inside an unclosed fence is refused, not appended to', async () => {
|
|
1122
|
+
const body = '```\nCloses #12\nmore code';
|
|
1123
|
+
const { runner, calls } = makeRunner([okPermission(), okJson(JSON.stringify({ body }))]);
|
|
1124
|
+
ghPrs.setGhRunner(runner);
|
|
1125
|
+
|
|
1126
|
+
const res = await ghPrs.editLinkedIssues(87, { remove: [12] }, PINNED);
|
|
1127
|
+
|
|
1128
|
+
assert.deepEqual(res, { ok: false, error: 'the pull request body ends inside an unclosed code fence or comment' });
|
|
1129
|
+
assert.equal(argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit'), undefined);
|
|
1130
|
+
});
|
|
1131
|
+
|
|
1132
|
+
test('merge refuses a metadata read that never carried the draft state', async () => {
|
|
1133
|
+
const { runner, calls } = makeRunner(okJson(JSON.stringify({
|
|
1134
|
+
data: {
|
|
1135
|
+
repository: {
|
|
1136
|
+
viewerPermission: 'WRITE',
|
|
1137
|
+
mergeCommitAllowed: true,
|
|
1138
|
+
squashMergeAllowed: true,
|
|
1139
|
+
rebaseMergeAllowed: false,
|
|
1140
|
+
pullRequest: { closingIssuesReferences: { nodes: [], pageInfo: { hasNextPage: false } } },
|
|
1141
|
+
},
|
|
1142
|
+
},
|
|
1143
|
+
})));
|
|
1144
|
+
ghPrs.setGhRunner(runner);
|
|
1145
|
+
|
|
1146
|
+
const res = await ghPrs.mergePullRequest(87, { method: 'merge' }, PINNED);
|
|
1147
|
+
|
|
1148
|
+
assert.equal(res.ok, false, 'a missing draft fact is never read as "not a draft"');
|
|
1149
|
+
assert.match(String(res.error), /the draft state is missing/);
|
|
1150
|
+
assert.equal(argvStartingWith(calls.map((call) => call.argv), 'pr', 'merge'), undefined);
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
test('a cleared description is sent empty and a cleared commit message is refused', async () => {
|
|
1154
|
+
const fake = pullRequestGraphql({ merge: true, squash: false, rebase: false });
|
|
1155
|
+
ghPrs.setGhRunner(fake.runner);
|
|
1156
|
+
|
|
1157
|
+
const cleared = await ghPrs.mergePullRequest(87, { method: 'merge', subject: 'Merge it', body: '' }, PINNED);
|
|
1158
|
+
|
|
1159
|
+
assert.equal(cleared.ok, true, cleared.error);
|
|
1160
|
+
assert.deepEqual(argvStartingWith(fake.calls, 'pr', 'merge'),
|
|
1161
|
+
['pr', 'merge', '87', '--merge', '--subject', 'Merge it', '--body', ''],
|
|
1162
|
+
'an explicitly cleared description reaches gh as empty');
|
|
1163
|
+
|
|
1164
|
+
const blank = pullRequestGraphql({ merge: true, squash: false, rebase: false });
|
|
1165
|
+
ghPrs.setGhRunner(blank.runner);
|
|
1166
|
+
const refused = await ghPrs.mergePullRequest(87, { method: 'merge', subject: ' ', body: 'kept' }, PINNED);
|
|
1167
|
+
|
|
1168
|
+
assert.equal(refused.ok, false);
|
|
1169
|
+
assert.match(String(refused.error), /the merge commit message must not be empty/);
|
|
1170
|
+
assert.equal(blank.calls.length, 0, 'the refusal happens before any child runs');
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
test('rebase ignores both fields, cleared or not', async () => {
|
|
1174
|
+
const fake = pullRequestGraphql({ merge: false, squash: false, rebase: true });
|
|
1175
|
+
ghPrs.setGhRunner(fake.runner);
|
|
1176
|
+
|
|
1177
|
+
const res = await ghPrs.mergePullRequest(87, { method: 'rebase', subject: '', body: '' }, PINNED);
|
|
1178
|
+
|
|
1179
|
+
assert.equal(res.ok, true, res.error);
|
|
1180
|
+
assert.deepEqual(argvStartingWith(fake.calls, 'pr', 'merge'), ['pr', 'merge', '87', '--rebase']);
|
|
1181
|
+
});
|
|
1182
|
+
});
|
|
1183
|
+
|
|
1184
|
+
// ---------------------------------------------------------------------------
|
|
1185
|
+
// S5 (T4's read): ONE aliased GraphQL answers the rail's two buckets with their
|
|
1186
|
+
// EXACT match counts, so the header's `n pr` is never a count of the rows it
|
|
1187
|
+
// happened to fetch.
|
|
1188
|
+
// ---------------------------------------------------------------------------
|
|
1189
|
+
describe('listRailPullRequests: one aliased read', () => {
|
|
1190
|
+
test('the rail read asks twice in one request and reports exact counts', async () => {
|
|
1191
|
+
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-rail.json')));
|
|
1192
|
+
ghPrs.setGhRunner(runner);
|
|
1193
|
+
|
|
1194
|
+
const res = await ghPrs.listRailPullRequests(PINNED);
|
|
1195
|
+
|
|
1196
|
+
assert.equal(res.ok, true, res.error);
|
|
1197
|
+
assert.equal(calls.length, 1, 'ONE gh child');
|
|
1198
|
+
const query = queryOf(calls[0]);
|
|
1199
|
+
assert.match(query, /mine: search\(query: "repo:octo\/repo is:pr is:open author:@me sort:updated-desc"/);
|
|
1200
|
+
assert.match(query, /review: search\(query: "repo:octo\/repo is:pr is:open review-requested:@me sort:updated-desc"/);
|
|
1201
|
+
assert.match(query, /issueCount/);
|
|
1202
|
+
assert.match(query, /closingIssuesReferences/);
|
|
1203
|
+
assert.deepEqual(res.counts, { mine: 3, review: 1 });
|
|
1204
|
+
assert.deepEqual(res.mine, [
|
|
1205
|
+
{ number: 87, linkedIssues: [14, 63] },
|
|
1206
|
+
{ number: 86, linkedIssues: [] },
|
|
1207
|
+
{ number: 85, linkedIssues: [70] },
|
|
1208
|
+
]);
|
|
1209
|
+
assert.deepEqual(res.review, [{ number: 86, linkedIssues: [] }]);
|
|
1210
|
+
});
|
|
1211
|
+
|
|
1212
|
+
test('an invalid window is refused without a child', async () => {
|
|
1213
|
+
const { runner, calls } = makeRunner(okJson('{}'));
|
|
1214
|
+
ghPrs.setGhRunner(runner);
|
|
1215
|
+
|
|
1216
|
+
const res = await ghPrs.listRailPullRequests({ first: 0 }, PINNED);
|
|
1217
|
+
|
|
1218
|
+
assert.equal(res.ok, false);
|
|
1219
|
+
assert.match(String(res.error), /invalid first 0: want an integer 1\.\.100/);
|
|
1220
|
+
assert.equal(calls.length, 0);
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
test('a missing alias, a malformed count and a numberless node all fail closed', async () => {
|
|
1224
|
+
const shapes = [
|
|
1225
|
+
JSON.stringify({ data: { mine: { issueCount: 0, nodes: [] } } }),
|
|
1226
|
+
JSON.stringify({ data: { mine: { issueCount: 'x', nodes: [] }, review: { issueCount: 0, nodes: [] } } }),
|
|
1227
|
+
JSON.stringify({ data: { mine: { issueCount: 1, nodes: [{ number: 0 }] }, review: { issueCount: 0, nodes: [] } } }),
|
|
1228
|
+
];
|
|
1229
|
+
for (const stdout of shapes) {
|
|
1230
|
+
const { runner } = makeRunner(okJson(stdout));
|
|
1231
|
+
ghPrs.setGhRunner(runner);
|
|
1232
|
+
const res = await ghPrs.listRailPullRequests(PINNED);
|
|
1233
|
+
assert.equal(res.ok, false, `${stdout} is refused`);
|
|
1234
|
+
assert.ok(String(res.error).length > 0);
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
});
|
|
1238
|
+
|
|
1239
|
+
// ---------------------------------------------------------------------------
|
|
1240
|
+
// invariant 6: the identity the panel displayed is pinned and validated, and a
|
|
1241
|
+
// call whose pin the live environment cannot honour fails closed before any
|
|
1242
|
+
// child runs. The checkout scope itself is resolved by the caller (the issue
|
|
1243
|
+
// client owns that read; a `lib/` module may not pull it), so a call without a
|
|
1244
|
+
// pin runs gh in the named checkout and lets gh resolve.
|
|
1245
|
+
// ---------------------------------------------------------------------------
|
|
1246
|
+
describe('repository identity pinning', () => {
|
|
1247
|
+
const roots = [];
|
|
1248
|
+
after(() => {
|
|
1249
|
+
for (const dir of roots) fs.rmSync(dir, { recursive: true, force: true });
|
|
1250
|
+
});
|
|
1251
|
+
|
|
1252
|
+
function git(cwd, args) {
|
|
1253
|
+
return execFileSync('git', args, {
|
|
1254
|
+
cwd,
|
|
1255
|
+
encoding: 'utf8',
|
|
1256
|
+
env: { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_SYSTEM: '/dev/null' },
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
// A real fork checkout, only so a case can prove the pin does not depend on
|
|
1261
|
+
// what that checkout's remotes currently say. gh's own `repo view` answers
|
|
1262
|
+
// the BASE repository of a fork.
|
|
1263
|
+
function makeCheckout() {
|
|
1264
|
+
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gh-prs-scope-')));
|
|
1265
|
+
roots.push(dir);
|
|
1266
|
+
git(dir, ['init']);
|
|
1267
|
+
git(dir, ['config', 'user.email', 'test@example.com']);
|
|
1268
|
+
git(dir, ['config', 'user.name', 'Test']);
|
|
1269
|
+
git(dir, ['commit', '--allow-empty', '-m', 'init']);
|
|
1270
|
+
git(dir, ['remote', 'add', 'origin', 'git@github.com:myfork/project.git']);
|
|
1271
|
+
git(dir, ['remote', 'add', 'upstream', 'git@github.com:original/project.git']);
|
|
1272
|
+
return dir;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
// gh's own behavior: `repo view` answers the BASE repository of a fork, while
|
|
1276
|
+
// repo-scoped commands honour GH_REPO.
|
|
1277
|
+
function githubFake({ base = 'original/project' } = {}) {
|
|
1278
|
+
const calls = [];
|
|
1279
|
+
const runner = async (bin, argv, runOpts) => {
|
|
1280
|
+
const env = (runOpts && runOpts.env) || {};
|
|
1281
|
+
const scoped = typeof env.GH_REPO === 'string' && env.GH_REPO !== '';
|
|
1282
|
+
calls.push({
|
|
1283
|
+
bin,
|
|
1284
|
+
argv: argv.slice(),
|
|
1285
|
+
repo: scoped ? env.GH_REPO : base,
|
|
1286
|
+
scoped,
|
|
1287
|
+
cwd: runOpts ? runOpts.cwd : undefined,
|
|
1288
|
+
});
|
|
1289
|
+
if (argv[0] === 'repo' && argv[1] === 'view') return okJson(JSON.stringify({ nameWithOwner: base }));
|
|
1290
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
1291
|
+
const query = queryOf({ argv });
|
|
1292
|
+
if (query.includes('pullRequests(')) return okJson(fixture('gh-pr-connection-page.json'));
|
|
1293
|
+
return okJson(fixture('gh-pr-search-page.json'));
|
|
1294
|
+
}
|
|
1295
|
+
if (argv[0] === 'pr' && argv[1] === 'view') return okJson(fixture('gh-pr-view.json'));
|
|
1296
|
+
return okJson('');
|
|
1297
|
+
};
|
|
1298
|
+
return { runner, calls };
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
test('every read and write carries the checkout fork, never the base gh resolves', async () => {
|
|
1302
|
+
const checkout = makeCheckout();
|
|
1303
|
+
const gh = githubFake();
|
|
1304
|
+
ghPrs.setGhRunner(gh.runner);
|
|
1305
|
+
|
|
1306
|
+
const res = await ghPrs.getPullRequestPage({ bucket: 'mine' }, { cwd: checkout });
|
|
1307
|
+
|
|
1308
|
+
assert.equal(res.ok, true, res.error);
|
|
1309
|
+
const scoped = gh.calls.filter((call) => !(call.argv[0] === 'repo' && call.argv[1] === 'view'));
|
|
1310
|
+
assert.ok(scoped.length > 0, 'the read reached gh');
|
|
1311
|
+
for (const call of scoped) assert.equal(call.repo, 'github.com/myfork/project');
|
|
1312
|
+
assert.ok(gh.calls.every((call) => call.cwd === checkout), 'every child runs in the named checkout');
|
|
1313
|
+
const searches = gh.calls.flatMap((call) => call.argv).filter((value) => value.startsWith('search=repo:'));
|
|
1314
|
+
assert.equal(searches[0], 'search=repo:myfork/project is:pr is:open author:@me sort:updated-desc');
|
|
1315
|
+
assert.ok(!gh.calls.some((call) => call.argv.some((value) => String(value).includes('original/project'))),
|
|
1316
|
+
'no call is scoped to the upstream base');
|
|
1317
|
+
});
|
|
1318
|
+
|
|
1319
|
+
test('a pinned identity keeps reads and writes on the displayed repository after the remote moved', async () => {
|
|
1320
|
+
const checkout = makeCheckout();
|
|
1321
|
+
const gh = githubFake();
|
|
1322
|
+
ghPrs.setGhRunner(gh.runner);
|
|
1323
|
+
const pin = 'github.com/myfork/project';
|
|
1324
|
+
git(checkout, ['remote', 'set-url', 'origin', 'git@github.com:otherfork/project.git']);
|
|
1325
|
+
|
|
1326
|
+
const res = await ghPrs.getPullRequestPage({ bucket: 'mine' }, { cwd: checkout, scope: pin });
|
|
1327
|
+
|
|
1328
|
+
assert.equal(res.ok, true, res.error);
|
|
1329
|
+
assert.ok(gh.calls.length > 0);
|
|
1330
|
+
for (const call of gh.calls) assert.equal(call.repo, pin, 'the pin answers, never the moved remote');
|
|
1331
|
+
const searches = gh.calls.flatMap((call) => call.argv).filter((value) => value.startsWith('search=repo:'));
|
|
1332
|
+
assert.equal(searches[0], 'search=repo:myfork/project is:pr is:open author:@me sort:updated-desc');
|
|
1333
|
+
|
|
1334
|
+
const comment = await ghPrs.commentPullRequest(87, 'hello', { cwd: checkout, scope: pin });
|
|
1335
|
+
|
|
1336
|
+
assert.equal(comment.ok, true, comment.error);
|
|
1337
|
+
assert.equal(gh.calls.find((call) => call.argv[0] === 'pr' && call.argv[1] === 'comment').repo, pin);
|
|
1338
|
+
assert.ok(!gh.calls.some((call) => call.repo.includes('otherfork')), 'nothing reached the new remote');
|
|
1339
|
+
});
|
|
1340
|
+
|
|
1341
|
+
test('a pin the live environment cannot honour is refused before any child runs', async () => {
|
|
1342
|
+
const checkout = makeCheckout();
|
|
1343
|
+
const gh = githubFake();
|
|
1344
|
+
ghPrs.setGhRunner(gh.runner);
|
|
1345
|
+
const env = { ...process.env, GH_HOST: 'acme.ghe.com' };
|
|
1346
|
+
|
|
1347
|
+
const read = await ghPrs.getPullRequestPage(
|
|
1348
|
+
{ bucket: 'mine' }, { cwd: checkout, scope: 'github.com/myfork/project', env },
|
|
1349
|
+
);
|
|
1350
|
+
const close = await ghPrs.closePullRequest(87, { cwd: checkout, scope: 'github.com/myfork/project', env });
|
|
1351
|
+
const merged = await ghPrs.mergePullRequest(87, { method: 'merge' }, {
|
|
1352
|
+
cwd: checkout, scope: 'github.com/myfork/project', env,
|
|
1353
|
+
});
|
|
1354
|
+
|
|
1355
|
+
assert.equal(read.ok, false, 'the pin is refused, never redirected');
|
|
1356
|
+
assert.match(String(read.error), /GH_HOST selects acme\.ghe\.com/);
|
|
1357
|
+
assert.equal(close.ok, false);
|
|
1358
|
+
assert.equal(merged.ok, false);
|
|
1359
|
+
assert.equal(gh.calls.length, 0, 'no gh command ran for a redirectable pin');
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
test('an ambient GH_REPO never overrides the pinned identity', async () => {
|
|
1363
|
+
const checkout = makeCheckout();
|
|
1364
|
+
const gh = githubFake();
|
|
1365
|
+
ghPrs.setGhRunner(gh.runner);
|
|
1366
|
+
|
|
1367
|
+
const res = await ghPrs.getPullRequestPage(
|
|
1368
|
+
{ bucket: 'mine' },
|
|
1369
|
+
{ cwd: checkout, scope: 'github.com/myfork/project', env: { ...process.env, GH_REPO: 'ambient/other' } },
|
|
1370
|
+
);
|
|
1371
|
+
|
|
1372
|
+
assert.equal(res.ok, true, res.error);
|
|
1373
|
+
assert.ok(gh.calls.length > 0);
|
|
1374
|
+
assert.ok(gh.calls.every((call) => call.repo === 'github.com/myfork/project'),
|
|
1375
|
+
'every call carries the pin, never the ambient GH_REPO');
|
|
1376
|
+
});
|
|
1377
|
+
|
|
1378
|
+
test('a checkout whose remote moved somewhere unprovable fails closed, and the pin still answers', async () => {
|
|
1379
|
+
const checkout = makeCheckout();
|
|
1380
|
+
const gh = githubFake();
|
|
1381
|
+
ghPrs.setGhRunner(gh.runner);
|
|
1382
|
+
const first = await ghPrs.getPullRequestPage({ bucket: 'mine' }, { cwd: checkout });
|
|
1383
|
+
assert.equal(first.ok, true, first.error);
|
|
1384
|
+
|
|
1385
|
+
git(checkout, ['remote', 'set-url', 'origin', '/srv/git/project.git']);
|
|
1386
|
+
const before = gh.calls.length;
|
|
1387
|
+
|
|
1388
|
+
const close = await ghPrs.closePullRequest(87, { cwd: checkout });
|
|
1389
|
+
|
|
1390
|
+
assert.equal(close.ok, false, 'a write never falls back to gh base resolution');
|
|
1391
|
+
assert.match(String(close.error), /local path, not a GitHub repository/);
|
|
1392
|
+
assert.equal(gh.calls.length, before, 'the write is refused before any child runs');
|
|
1393
|
+
|
|
1394
|
+
const pinned = await ghPrs.getPullRequestPage(
|
|
1395
|
+
{ bucket: 'mine' }, { cwd: checkout, scope: 'github.com/myfork/project' },
|
|
1396
|
+
);
|
|
1397
|
+
assert.equal(pinned.ok, true, 'the identity already displayed still answers reads');
|
|
1398
|
+
assert.ok(gh.calls.slice(before).every((call) => call.repo === 'github.com/myfork/project'));
|
|
1399
|
+
});
|
|
1400
|
+
|
|
1401
|
+
test('a pin naming a server that is not GitHub fails closed', async () => {
|
|
1402
|
+
const gh = githubFake();
|
|
1403
|
+
ghPrs.setGhRunner(gh.runner);
|
|
1404
|
+
|
|
1405
|
+
const res = await ghPrs.getPullRequestPage({ bucket: 'mine' }, { scope: 'gitlab.com/myfork/project', env: {} });
|
|
1406
|
+
|
|
1407
|
+
assert.equal(res.ok, false);
|
|
1408
|
+
assert.match(String(res.error), /not a GitHub host/);
|
|
1409
|
+
assert.equal(gh.calls.length, 0, 'no gh command runs for an unprovable host');
|
|
1410
|
+
});
|
|
1411
|
+
|
|
1412
|
+
test('the module never builds a shell string for gh', () => {
|
|
1413
|
+
const src = fs.readFileSync(path.join(__dirname, '..', 'lib', 'gh-prs.js'), 'utf8');
|
|
1414
|
+
assert.ok(!/exec\s*\(\s*['"`]/.test(src), 'no child_process.exec with a shell string');
|
|
1415
|
+
assert.ok(!/\bexecSync\s*\(/.test(src), 'no child_process.execSync');
|
|
1416
|
+
assert.ok(!/shell\s*:\s*true/.test(src), 'no shell:true spawn option');
|
|
1417
|
+
assert.ok(!/\bspawnSync\s*\(/.test(src), 'the host event loop is never blocked');
|
|
1418
|
+
});
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
// ---------------------------------------------------------------------------
|
|
1422
|
+
// The client is a factory over the INJECTED issue module, so the extension owns
|
|
1423
|
+
// the single instance of that module and this one only borrows its seams.
|
|
1424
|
+
// ---------------------------------------------------------------------------
|
|
1425
|
+
describe('createPrsClient over an injected issue module', () => {
|
|
1426
|
+
test('the injected module supplies the seams the client calls', async () => {
|
|
1427
|
+
const calls = [];
|
|
1428
|
+
const injected = {
|
|
1429
|
+
setGhRunner(fn) { injected.injectedRunner = fn; },
|
|
1430
|
+
normalizeScopeIdentity: () => ({ ok: false, error: 'is on a server this client refuses' }),
|
|
1431
|
+
runGh: async (argv) => {
|
|
1432
|
+
calls.push(argv.slice());
|
|
1433
|
+
return okJson(fixture('gh-pr-search-page.json'));
|
|
1434
|
+
},
|
|
1435
|
+
};
|
|
1436
|
+
const client = ghPrsModule.createPrsClient({ issues: injected });
|
|
1437
|
+
|
|
1438
|
+
const refused = await client.getPullRequestPage({ bucket: 'mine' }, { scope: 'octo/repo' });
|
|
1439
|
+
|
|
1440
|
+
assert.equal(refused.ok, false);
|
|
1441
|
+
assert.match(String(refused.error), /is on a server this client refuses/);
|
|
1442
|
+
assert.equal(calls.length, 0, 'a refused pin spawns nothing, through the injected runGh too');
|
|
1443
|
+
|
|
1444
|
+
// With a loader that accepts the pin, the reads travel through the injected
|
|
1445
|
+
// `runGh` (the module's own child seam) and the injected `setGhRunner`.
|
|
1446
|
+
const client2 = ghPrsModule.createPrsClient({
|
|
1447
|
+
issues: {
|
|
1448
|
+
...injected,
|
|
1449
|
+
normalizeScopeIdentity: () => ({
|
|
1450
|
+
ok: true, host: 'github.com', nameWithOwner: 'octo/repo', identity: 'github.com/octo/repo',
|
|
1451
|
+
}),
|
|
1452
|
+
},
|
|
1453
|
+
});
|
|
1454
|
+
const injectedRunner = () => Promise.resolve(okJson(''));
|
|
1455
|
+
client2.setGhRunner(injectedRunner);
|
|
1456
|
+
assert.equal(injected.injectedRunner, injectedRunner, 'the client forwards its runner to the injected module');
|
|
1457
|
+
|
|
1458
|
+
const page = await client2.getPullRequestPage({ bucket: 'mine' }, { scope: 'octo/repo' });
|
|
1459
|
+
assert.equal(page.ok, true, page.error);
|
|
1460
|
+
assert.equal(calls.length, 1);
|
|
1461
|
+
assert.deepEqual(calls[0].slice(0, 2), ['api', 'graphql']);
|
|
1462
|
+
});
|
|
1463
|
+
test('a client whose module exports no such seam falls back to the local copy', async () => {
|
|
1464
|
+
const calls = [];
|
|
1465
|
+
let clientRunner = null;
|
|
1466
|
+
const client = ghPrsModule.createPrsClient({
|
|
1467
|
+
issues: {
|
|
1468
|
+
setGhRunner(fn) { clientRunner = fn; },
|
|
1469
|
+
runGh: async (argv) => {
|
|
1470
|
+
calls.push(argv.slice());
|
|
1471
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
1472
|
+
return okJson(JSON.stringify({ nameWithOwner: 'octo/repo' }));
|
|
1473
|
+
}
|
|
1474
|
+
return okJson(fixture('gh-pr-search-page.json'));
|
|
1475
|
+
},
|
|
1476
|
+
},
|
|
1477
|
+
});
|
|
1478
|
+
|
|
1479
|
+
// `scope: null` asks for gh's OWN answer, which the local fallback reads
|
|
1480
|
+
// with the same `gh repo view` child the issue client runs.
|
|
1481
|
+
const res = await client.getPullRequestPage({ bucket: 'mine' }, { scope: null });
|
|
1482
|
+
|
|
1483
|
+
assert.equal(res.ok, true, res.error);
|
|
1484
|
+
// S2/D28: the repository lookup also answers the URL its host comes from.
|
|
1485
|
+
assert.deepEqual(calls[0], ['repo', 'view', '--json', 'nameWithOwner,url']);
|
|
1486
|
+
assert.equal(fieldOf({ argv: calls[1] }, 'search'),
|
|
1487
|
+
'repo:octo/repo is:pr is:open author:@me sort:updated-desc');
|
|
1488
|
+
client.setGhRunner(null);
|
|
1489
|
+
assert.equal(clientRunner, null, 'the local seam still forwards to the injected module');
|
|
1490
|
+
});
|
|
1491
|
+
});
|
|
1492
|
+
|
|
1493
|
+
// ---------------------------------------------------------------------------
|
|
1494
|
+
// Every failure shape is `{ ok: false }`, never a throw.
|
|
1495
|
+
// ---------------------------------------------------------------------------
|
|
1496
|
+
describe('failure shapes: nothing throws', () => {
|
|
1497
|
+
test('a missing gh CLI fails closed on every read and write', async () => {
|
|
1498
|
+
const { runner } = makeRunner({ status: null, stdout: '', stderr: '', error: 'spawn gh ENOENT: gh CLI is not available' });
|
|
1499
|
+
ghPrs.setGhRunner(runner);
|
|
1500
|
+
|
|
1501
|
+
const results = [
|
|
1502
|
+
await ghPrs.getPullRequestPage({ bucket: 'mine' }, PINNED),
|
|
1503
|
+
await ghPrs.getPullRequestConnectionPage({}, PINNED),
|
|
1504
|
+
await ghPrs.getPullRequest(87, { includeMetadata: true }, PINNED),
|
|
1505
|
+
await ghPrs.listRailPullRequests(PINNED),
|
|
1506
|
+
await ghPrs.commentPullRequest(87, 'hi', PINNED),
|
|
1507
|
+
await ghPrs.closePullRequest(87, PINNED),
|
|
1508
|
+
await ghPrs.editLinkedIssues(87, { add: [71] }, PINNED),
|
|
1509
|
+
await ghPrs.listLabels(PINNED),
|
|
1510
|
+
];
|
|
1511
|
+
|
|
1512
|
+
for (const res of results) {
|
|
1513
|
+
assert.equal(res.ok, false);
|
|
1514
|
+
assert.match(String(res.error), /ENOENT/i);
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
|
|
1518
|
+
test('an unauthenticated gh reports the auth failure', async () => {
|
|
1519
|
+
const { runner } = makeRunner({ status: 1, stdout: '', stderr: 'To authenticate, please run `gh auth login`.', error: null });
|
|
1520
|
+
ghPrs.setGhRunner(runner);
|
|
1521
|
+
|
|
1522
|
+
const res = await ghPrs.getPullRequest(87, {}, PINNED);
|
|
1523
|
+
|
|
1524
|
+
assert.equal(res.ok, false);
|
|
1525
|
+
assert.match(String(res.error), /gh auth login/);
|
|
1526
|
+
});
|
|
1527
|
+
|
|
1528
|
+
test('malformed JSON and an empty body fail closed', async () => {
|
|
1529
|
+
for (const stdout of ['not json at all{{{', '']) {
|
|
1530
|
+
const { runner } = makeRunner(okJson(stdout));
|
|
1531
|
+
ghPrs.setGhRunner(runner);
|
|
1532
|
+
const page = await ghPrs.getPullRequestPage({ bucket: 'mine' }, PINNED);
|
|
1533
|
+
const detail = await ghPrs.getPullRequest(87, {}, PINNED);
|
|
1534
|
+
assert.equal(page.ok, false);
|
|
1535
|
+
assert.equal(detail.ok, false);
|
|
1536
|
+
assert.ok(String(page.error).length > 0);
|
|
1537
|
+
assert.ok(String(detail.error).length > 0);
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1540
|
+
|
|
1541
|
+
test('a throwing or rejecting runner still answers { ok: false }', async () => {
|
|
1542
|
+
ghPrs.setGhRunner(() => Promise.reject(new Error('boom')));
|
|
1543
|
+
const rejected = await ghPrs.getPullRequestPage({ bucket: 'mine' }, PINNED);
|
|
1544
|
+
assert.equal(rejected.ok, false);
|
|
1545
|
+
assert.match(String(rejected.error), /boom/);
|
|
1546
|
+
|
|
1547
|
+
ghPrs.setGhRunner(() => { throw new Error('sync boom'); });
|
|
1548
|
+
const thrown = await ghPrs.getPullRequest(87, {}, PINNED);
|
|
1549
|
+
assert.equal(thrown.ok, false);
|
|
1550
|
+
assert.match(String(thrown.error), /sync boom/);
|
|
1551
|
+
});
|
|
1552
|
+
|
|
1553
|
+
test('a non-integer pull request number is refused without a child', async () => {
|
|
1554
|
+
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-view.json')));
|
|
1555
|
+
ghPrs.setGhRunner(runner);
|
|
1556
|
+
|
|
1557
|
+
const res = await ghPrs.getPullRequest('87a', { includeMetadata: true }, PINNED);
|
|
1558
|
+
|
|
1559
|
+
assert.equal(res.ok, false);
|
|
1560
|
+
assert.match(String(res.error), /invalid pull request number "87a": want a positive integer/);
|
|
1561
|
+
assert.equal(calls.length, 0);
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
test('a pull request detail payload of the wrong shape fails closed', async () => {
|
|
1565
|
+
const { runner } = makeRunner(okJson('{"title":"no number here"}'));
|
|
1566
|
+
ghPrs.setGhRunner(runner);
|
|
1567
|
+
|
|
1568
|
+
const res = await ghPrs.getPullRequest(87, {}, PINNED);
|
|
1569
|
+
|
|
1570
|
+
assert.equal(res.ok, false);
|
|
1571
|
+
assert.match(String(res.error), /returned an unexpected shape/);
|
|
1572
|
+
});
|
|
1573
|
+
});
|
|
1574
|
+
|
|
1575
|
+
// ---------------------------------------------------------------------------
|
|
1576
|
+
// S2 (D27): the Development relation is this panel's own convention. It no
|
|
1577
|
+
// longer interprets Markdown: every line it writes carries a marker comment,
|
|
1578
|
+
// only a marked line is ever removed, an unreadable body refuses both edits, and
|
|
1579
|
+
// the body is read once more immediately before the write.
|
|
1580
|
+
// ---------------------------------------------------------------------------
|
|
1581
|
+
const MARK = '<!-- odd-worktree:linked -->';
|
|
1582
|
+
|
|
1583
|
+
// A runner that answers by argv shape: the role read, the body read (from a
|
|
1584
|
+
// mutable holder, so a re-read can be made to differ) and every write.
|
|
1585
|
+
function bodyRunner(holder) {
|
|
1586
|
+
return (call) => {
|
|
1587
|
+
if (call.argv[0] === 'api' && call.argv[1] === 'graphql') return okPermission();
|
|
1588
|
+
if (call.argv[0] === 'pr' && call.argv[1] === 'view') {
|
|
1589
|
+
const body = typeof holder.body === 'function' ? holder.body() : holder.body;
|
|
1590
|
+
// The body read answers the pull request STATE with the body (S2/T18): a
|
|
1591
|
+
// re-read that proves no state is refused, so every fixture answers OPEN.
|
|
1592
|
+
return okJson(JSON.stringify({ body, state: 'OPEN' }));
|
|
1593
|
+
}
|
|
1594
|
+
return okJson('');
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
describe('D27: the linked-issue body edit is marker-based', () => {
|
|
1599
|
+
test('adding a link appends a marked line on a line of its own', async () => {
|
|
1600
|
+
const original = 'Summary line\n\nBody words';
|
|
1601
|
+
const { runner, calls } = makeRunner([bodyRunner({ body: original })]);
|
|
1602
|
+
ghPrs.setGhRunner(runner);
|
|
1603
|
+
|
|
1604
|
+
const res = await ghPrs.editLinkedIssues(87, { add: [71] }, PINNED);
|
|
1605
|
+
|
|
1606
|
+
assert.equal(res.ok, true, res.error);
|
|
1607
|
+
assert.equal(res.changed, true);
|
|
1608
|
+
const edit = argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit');
|
|
1609
|
+
assert.ok(edit, 'the body edit ran');
|
|
1610
|
+
assert.equal(edit[edit.indexOf('--body') + 1], `${original}\n\nCloses #71 ${MARK}\n`);
|
|
1611
|
+
assert.equal(res.body, `${original}\n\nCloses #71 ${MARK}\n`);
|
|
1612
|
+
});
|
|
1613
|
+
|
|
1614
|
+
test('adding a link to a body that already ends with a blank line adds no second one', async () => {
|
|
1615
|
+
const original = 'Summary line\n';
|
|
1616
|
+
const { runner, calls } = makeRunner([bodyRunner({ body: original })]);
|
|
1617
|
+
ghPrs.setGhRunner(runner);
|
|
1618
|
+
|
|
1619
|
+
const res = await ghPrs.editLinkedIssues(87, { add: [71] }, PINNED);
|
|
1620
|
+
|
|
1621
|
+
assert.equal(res.ok, true, res.error);
|
|
1622
|
+
const edit = argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit');
|
|
1623
|
+
assert.equal(edit[edit.indexOf('--body') + 1], `Summary line\n\nCloses #71 ${MARK}\n`);
|
|
1624
|
+
});
|
|
1625
|
+
|
|
1626
|
+
test('adding a link a column-0 declaration already names writes nothing', async () => {
|
|
1627
|
+
const body = 'Summary\n\nfixes #71\n';
|
|
1628
|
+
const { runner, calls } = makeRunner([bodyRunner({ body })]);
|
|
1629
|
+
ghPrs.setGhRunner(runner);
|
|
1630
|
+
|
|
1631
|
+
const res = await ghPrs.editLinkedIssues(87, { add: [71] }, PINNED);
|
|
1632
|
+
|
|
1633
|
+
assert.equal(res.ok, true, res.error);
|
|
1634
|
+
assert.equal(res.changed, false, 'any closing keyword already declares it');
|
|
1635
|
+
assert.equal(argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit'), undefined);
|
|
1636
|
+
});
|
|
1637
|
+
|
|
1638
|
+
test('removing a link this panel did not add is refused, and nothing is written', async () => {
|
|
1639
|
+
const body = 'Summary\n\nCloses #14\n';
|
|
1640
|
+
const { runner, calls } = makeRunner([bodyRunner({ body })]);
|
|
1641
|
+
ghPrs.setGhRunner(runner);
|
|
1642
|
+
|
|
1643
|
+
const res = await ghPrs.editLinkedIssues(87, { remove: [14] }, PINNED);
|
|
1644
|
+
|
|
1645
|
+
assert.deepEqual(res, { ok: false, error: 'that link was not added by this panel; remove it on GitHub' });
|
|
1646
|
+
assert.equal(argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit'), undefined);
|
|
1647
|
+
});
|
|
1648
|
+
|
|
1649
|
+
test('removing a marked link deletes exactly that line and keeps every other byte', async () => {
|
|
1650
|
+
const original = `Summary line\r\n\r\nCloses #14 ${MARK}\r\nTrailing words`;
|
|
1651
|
+
const { runner, calls } = makeRunner([bodyRunner({ body: original })]);
|
|
1652
|
+
ghPrs.setGhRunner(runner);
|
|
1653
|
+
|
|
1654
|
+
const res = await ghPrs.editLinkedIssues(87, { remove: [14] }, PINNED);
|
|
1655
|
+
|
|
1656
|
+
assert.equal(res.ok, true, res.error);
|
|
1657
|
+
const edit = argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit');
|
|
1658
|
+
assert.equal(edit[edit.indexOf('--body') + 1], 'Summary line\r\n\r\nTrailing words');
|
|
1659
|
+
});
|
|
1660
|
+
|
|
1661
|
+
test('unpaired fences and unbalanced comments refuse the edit for add and remove alike', async () => {
|
|
1662
|
+
for (const body of ['Intro\n```\nCloses #14\n', 'Intro\n<!--\nCloses #14\n-->\n<!--\n']) {
|
|
1663
|
+
for (const changes of [{ add: [71] }, { remove: [14] }]) {
|
|
1664
|
+
const { runner, calls } = makeRunner([bodyRunner({ body })]);
|
|
1665
|
+
ghPrs.setGhRunner(runner);
|
|
1666
|
+
|
|
1667
|
+
const res = await ghPrs.editLinkedIssues(87, changes, PINNED);
|
|
1668
|
+
|
|
1669
|
+
assert.deepEqual(res, { ok: false, error: 'the pull request body ends inside an unclosed code fence or comment' });
|
|
1670
|
+
assert.equal(argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit'), undefined);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
|
|
1675
|
+
test('a body that changed while the edit was prepared is refused, never overwritten', async () => {
|
|
1676
|
+
let read = 0;
|
|
1677
|
+
const { runner, calls } = makeRunner([bodyRunner({
|
|
1678
|
+
body: () => (++read === 1 ? 'Summary\n' : 'Summary\nAuthor added this meanwhile.\n'),
|
|
1679
|
+
})]);
|
|
1680
|
+
ghPrs.setGhRunner(runner);
|
|
1681
|
+
|
|
1682
|
+
const res = await ghPrs.editLinkedIssues(87, { add: [71] }, PINNED);
|
|
1683
|
+
|
|
1684
|
+
assert.deepEqual(res, { ok: false, error: 'the pull request body changed while it was being edited' });
|
|
1685
|
+
assert.equal(argvStartingWith(calls.map((call) => call.argv), 'pr', 'edit'), undefined);
|
|
1686
|
+
});
|
|
1687
|
+
});
|
|
1688
|
+
|
|
1689
|
+
// ---------------------------------------------------------------------------
|
|
1690
|
+
// S2 (D28): every `api` child names its host explicitly — github.com included —
|
|
1691
|
+
// and the ambient fallback takes the host from the repository lookup itself.
|
|
1692
|
+
// ---------------------------------------------------------------------------
|
|
1693
|
+
describe('D28: the host travels with every child', () => {
|
|
1694
|
+
test('a github.com scope names github.com on its api children and GH_HOST', async () => {
|
|
1695
|
+
const { runner, calls } = makeRunner([okPermission(), okJson('')]);
|
|
1696
|
+
ghPrs.setGhRunner(runner);
|
|
1697
|
+
|
|
1698
|
+
const res = await ghPrs.closePullRequest(87, { scope: 'github.com/octo/repo' });
|
|
1699
|
+
|
|
1700
|
+
assert.equal(res.ok, true, res.error);
|
|
1701
|
+
const graphqlCall = calls.find((call) => call.argv[0] === 'api' && call.argv[1] === 'graphql');
|
|
1702
|
+
assert.equal(graphqlCall.argv[graphqlCall.argv.indexOf('--hostname') + 1], 'github.com');
|
|
1703
|
+
assert.equal(graphqlCall.runOpts.env.GH_HOST, 'github.com');
|
|
1704
|
+
const closeCall = argvStartingWith(calls.map((call) => call.argv), 'pr', 'close');
|
|
1705
|
+
assert.ok(closeCall, 'the close child ran');
|
|
1706
|
+
assert.equal(calls[calls.length - 1].runOpts.env.GH_HOST, 'github.com');
|
|
1707
|
+
});
|
|
1708
|
+
|
|
1709
|
+
test('the injected issue module\'s repository answer supplies the host too', async () => {
|
|
1710
|
+
const writes = [];
|
|
1711
|
+
const client = ghPrsModule.createPrsClient({
|
|
1712
|
+
issues: {
|
|
1713
|
+
// The extension injects its own issue module; that module answers the
|
|
1714
|
+
// repository AND the host gh resolved for it (S2/D28).
|
|
1715
|
+
reportedRepoName: async () => ({ ok: true, nameWithOwner: 'amber/widget', host: 'github.company.example' }),
|
|
1716
|
+
},
|
|
1717
|
+
});
|
|
1718
|
+
client.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
1719
|
+
const env = runOpts.env || {};
|
|
1720
|
+
if (argv.slice(0, 2).join(' ') === 'api graphql') {
|
|
1721
|
+
return okJson(JSON.stringify({ data: { repository: { viewerPermission: 'WRITE', pullRequest: { state: 'OPEN' } } } }));
|
|
1722
|
+
}
|
|
1723
|
+
writes.push({ argv: argv.slice(), repo: env.GH_REPO, host: env.GH_HOST });
|
|
1724
|
+
return okJson('');
|
|
1725
|
+
});
|
|
1726
|
+
|
|
1727
|
+
const res = await client.closePullRequest(87);
|
|
1728
|
+
client.setGhRunner(null);
|
|
1729
|
+
|
|
1730
|
+
assert.equal(res.ok, true, res.error);
|
|
1731
|
+
assert.deepEqual(writes.map((write) => [write.repo, write.host]), [
|
|
1732
|
+
['github.company.example/amber/widget', 'github.company.example'],
|
|
1733
|
+
]);
|
|
1734
|
+
});
|
|
1735
|
+
|
|
1736
|
+
test('an ambient enterprise repository pins the host its own URL names', async () => {
|
|
1737
|
+
const writes = [];
|
|
1738
|
+
const client = ghPrsModule.createPrsClient({});
|
|
1739
|
+
client.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
1740
|
+
const env = runOpts.env || {};
|
|
1741
|
+
if (argv.slice(0, 2).join(' ') === 'repo view') {
|
|
1742
|
+
return okJson(JSON.stringify({
|
|
1743
|
+
nameWithOwner: 'amber/widget',
|
|
1744
|
+
url: 'https://github.company.example/amber/widget',
|
|
1745
|
+
}));
|
|
1746
|
+
}
|
|
1747
|
+
if (argv.slice(0, 2).join(' ') === 'api graphql') {
|
|
1748
|
+
return okJson(JSON.stringify({ data: { repository: { viewerPermission: 'WRITE', pullRequest: { state: 'OPEN' } } } }));
|
|
1749
|
+
}
|
|
1750
|
+
writes.push({ argv: argv.slice(), repo: env.GH_REPO, host: env.GH_HOST });
|
|
1751
|
+
return okJson('');
|
|
1752
|
+
});
|
|
1753
|
+
|
|
1754
|
+
const res = await client.closePullRequest(87);
|
|
1755
|
+
client.setGhRunner(null);
|
|
1756
|
+
|
|
1757
|
+
assert.equal(res.ok, true, res.error);
|
|
1758
|
+
assert.deepEqual(writes.map((write) => [write.repo, write.host]), [
|
|
1759
|
+
['github.company.example/amber/widget', 'github.company.example'],
|
|
1760
|
+
]);
|
|
1761
|
+
});
|
|
1762
|
+
});
|
|
1763
|
+
|
|
1764
|
+
// ---------------------------------------------------------------------------
|
|
1765
|
+
// S2/S6 (D29): a Development reference is identified by repository AND number.
|
|
1766
|
+
// ---------------------------------------------------------------------------
|
|
1767
|
+
describe('D29: only this repository\'s linked issues are targets', () => {
|
|
1768
|
+
test('a closing reference of another repository never becomes a linked issue', async () => {
|
|
1769
|
+
const { runner } = makeRunner((call) => {
|
|
1770
|
+
if (call.argv[0] === 'pr' && call.argv[1] === 'view') {
|
|
1771
|
+
return Promise.resolve(okJson(JSON.stringify({ number: 87, title: 'T', state: 'OPEN', body: '' })));
|
|
1772
|
+
}
|
|
1773
|
+
return Promise.resolve(okJson(JSON.stringify({
|
|
1774
|
+
data: {
|
|
1775
|
+
repository: {
|
|
1776
|
+
viewerPermission: 'WRITE',
|
|
1777
|
+
mergeCommitAllowed: true,
|
|
1778
|
+
pullRequest: {
|
|
1779
|
+
isDraft: false,
|
|
1780
|
+
state: 'OPEN',
|
|
1781
|
+
closingIssuesReferences: {
|
|
1782
|
+
nodes: [
|
|
1783
|
+
{ number: 12, repository: { nameWithOwner: 'oak/payroll' } },
|
|
1784
|
+
{ number: 13, repository: { nameWithOwner: 'octo/repo' } },
|
|
1785
|
+
],
|
|
1786
|
+
pageInfo: { hasNextPage: false },
|
|
1787
|
+
},
|
|
1788
|
+
},
|
|
1789
|
+
},
|
|
1790
|
+
},
|
|
1791
|
+
})));
|
|
1792
|
+
});
|
|
1793
|
+
ghPrs.setGhRunner(runner);
|
|
1794
|
+
|
|
1795
|
+
const res = await ghPrs.getPullRequest(87, { includeMetadata: true }, PINNED);
|
|
1796
|
+
|
|
1797
|
+
assert.equal(res.ok, true, res.error);
|
|
1798
|
+
assert.deepEqual(res.pullRequest.linkedIssues, [13], 'the foreign reference is not a target of this pane');
|
|
1799
|
+
});
|
|
1800
|
+
});
|
|
1801
|
+
|
|
1802
|
+
// ---------------------------------------------------------------------------
|
|
1803
|
+
// S2 (D31): the metadata read is the newest state, and it wins.
|
|
1804
|
+
// ---------------------------------------------------------------------------
|
|
1805
|
+
describe('D31: the GraphQL state wins over a stale pr view', () => {
|
|
1806
|
+
test('a CLOSED metadata answer closes a detail read that still says open', async () => {
|
|
1807
|
+
const { runner } = makeRunner((call) => {
|
|
1808
|
+
if (call.argv[0] === 'pr' && call.argv[1] === 'view') {
|
|
1809
|
+
return Promise.resolve(okJson(JSON.stringify({ number: 87, title: 'T', state: 'OPEN', body: '' })));
|
|
1810
|
+
}
|
|
1811
|
+
return Promise.resolve(okJson(JSON.stringify({
|
|
1812
|
+
data: {
|
|
1813
|
+
repository: {
|
|
1814
|
+
viewerPermission: 'WRITE',
|
|
1815
|
+
mergeCommitAllowed: true,
|
|
1816
|
+
pullRequest: { isDraft: false, state: 'CLOSED', closingIssuesReferences: { nodes: [], pageInfo: { hasNextPage: false } } },
|
|
1817
|
+
},
|
|
1818
|
+
},
|
|
1819
|
+
})));
|
|
1820
|
+
});
|
|
1821
|
+
ghPrs.setGhRunner(runner);
|
|
1822
|
+
|
|
1823
|
+
const res = await ghPrs.getPullRequest(87, { includeMetadata: true }, PINNED);
|
|
1824
|
+
|
|
1825
|
+
assert.equal(res.ok, true, res.error);
|
|
1826
|
+
assert.equal(res.pullRequest.state, 'closed');
|
|
1827
|
+
});
|
|
1828
|
+
});
|