pi-odd-worktree 3.9.2 → 3.11.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/LICENSE +21 -0
- package/README.md +68 -40
- package/extensions/odd-worktree-tools.ts +1028 -17
- 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/lib/user-prompt-card.js +477 -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 +21 -5
- 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
- package/tools/user-prompt-card.test.js +963 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// T12 (prs-panel S2): the defects the T11 independent verification recorded —
|
|
3
|
+
// D16 (a fence nested in a list container, and a body that ENDS inside an
|
|
4
|
+
// unclosed one), D17 (the merge and close highlight losing its captured row),
|
|
5
|
+
// D18 (the composer never naming its own pull request), D19 (the fallback write
|
|
6
|
+
// scope dropping an enterprise host) and D20 (a stale capability, or a target
|
|
7
|
+
// that is no longer open, reaching a confirmation's write seam).
|
|
8
|
+
//
|
|
9
|
+
// Every case reproduces the defect through a public seam — the client's
|
|
10
|
+
// exported writes, or the panel's keys and the frame it paints — and never
|
|
11
|
+
// through the modules' internal storage.
|
|
12
|
+
|
|
13
|
+
const { test } = require('node:test');
|
|
14
|
+
const assert = require('node:assert/strict');
|
|
15
|
+
const { createPrsClient } = require('../lib/gh-prs');
|
|
16
|
+
const { createPrsView } = require('../lib/prs-view');
|
|
17
|
+
|
|
18
|
+
const pin = { scope: 'github.com/octo/repo' };
|
|
19
|
+
const ENTERPRISE = 'github.company.example/amber/widget';
|
|
20
|
+
const ok = (x) => ({ status: 0, stdout: JSON.stringify(x), stderr: '', error: null });
|
|
21
|
+
const tick = () => new Promise((resolve) => setImmediate(resolve));
|
|
22
|
+
const row = (number, extra = {}) => ({ number, title: `PR ${number}`, state: 'open', isDraft: false, ...extra });
|
|
23
|
+
const strip = (line) => String(line).replace(/\x1b\[[0-9;]*m/g, '');
|
|
24
|
+
const frame = (view) => view.render(140).map(strip).join('\n');
|
|
25
|
+
const leftPane = (view) => view.render(140).map((line) => strip(line).split('│')[1] || '').join('\n');
|
|
26
|
+
const send = (view, ...keys) => keys.forEach((key) => view.handleInput(key));
|
|
27
|
+
|
|
28
|
+
// A `gh` double that answers the role/state reads and records every write child
|
|
29
|
+
// with the scope and the environment it was spawned with.
|
|
30
|
+
function clientMock({ permission = 'WRITE', state = 'OPEN', body = 'PR body', reported = 'amber/widget' } = {}) {
|
|
31
|
+
const writes = [];
|
|
32
|
+
const children = [];
|
|
33
|
+
// The injected child seam, resolving a call exactly like lib/gh-issues.js:
|
|
34
|
+
// an explicit pin wins and a bare `owner/name` is qualified with the default
|
|
35
|
+
// host, otherwise the environment's own GH_REPO stands.
|
|
36
|
+
const runGh = async (argv, opts = {}) => {
|
|
37
|
+
const env = opts.env || {};
|
|
38
|
+
const scoped = typeof opts.scope === 'string' && opts.scope !== '';
|
|
39
|
+
const repo = scoped
|
|
40
|
+
? (opts.scope.split('/').length === 3 ? opts.scope : `github.com/${opts.scope}`)
|
|
41
|
+
: (typeof env.GH_REPO === 'string' && env.GH_REPO !== '' ? env.GH_REPO : null);
|
|
42
|
+
children.push({ argv: argv.slice(), scope: opts.scope, repo });
|
|
43
|
+
if (argv[0] === 'repo' && argv[1] === 'view') return ok({ nameWithOwner: reported });
|
|
44
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
45
|
+
return ok({
|
|
46
|
+
data: {
|
|
47
|
+
repository: {
|
|
48
|
+
viewerPermission: permission,
|
|
49
|
+
mergeCommitAllowed: true,
|
|
50
|
+
squashMergeAllowed: false,
|
|
51
|
+
rebaseMergeAllowed: false,
|
|
52
|
+
pullRequest: {
|
|
53
|
+
state,
|
|
54
|
+
isDraft: false,
|
|
55
|
+
closingIssuesReferences: { nodes: [], pageInfo: { hasNextPage: false } },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
viewer: { login: 'octocat' },
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// The body read answers the pull request STATE with the body (S2/T18).
|
|
63
|
+
if (argv[0] === 'pr' && argv[1] === 'view') return ok({ body, state: 'OPEN' });
|
|
64
|
+
writes.push(argv.slice());
|
|
65
|
+
return ok('');
|
|
66
|
+
};
|
|
67
|
+
return { client: createPrsClient({ issues: { runGh } }), writes, children };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// D16 (S2), amended by D27: the body edit no longer reads Markdown. A line the
|
|
72
|
+
// panel wrote carries its marker and is the only line a removal may delete, and
|
|
73
|
+
// a body whose fence runs do not pair up is refused rather than appended to.
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
const MARK = '<!-- odd-worktree:linked -->';
|
|
76
|
+
test('S2: a fence nested in a list item is code, so its example survives a removal', async () => {
|
|
77
|
+
const body = [
|
|
78
|
+
'Intro',
|
|
79
|
+
'- item:',
|
|
80
|
+
'',
|
|
81
|
+
' ```text',
|
|
82
|
+
' Closes #915',
|
|
83
|
+
' ```',
|
|
84
|
+
'',
|
|
85
|
+
`Closes #915 ${MARK}`,
|
|
86
|
+
].join('\n');
|
|
87
|
+
const { client, writes } = clientMock({ body });
|
|
88
|
+
|
|
89
|
+
const res = await client.editLinkedIssues(87, { remove: [915] }, pin);
|
|
90
|
+
|
|
91
|
+
assert.equal(res.ok, true, res.error);
|
|
92
|
+
assert.deepEqual(writes, [[
|
|
93
|
+
'pr',
|
|
94
|
+
'edit',
|
|
95
|
+
'87',
|
|
96
|
+
'--body',
|
|
97
|
+
'Intro\n- item:\n\n ```text\n Closes #915\n ```\n\n',
|
|
98
|
+
]], 'only the marked line outside the list container is removed');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('S2: adding a closing line to a body that ends inside an unclosed fence is refused', async () => {
|
|
102
|
+
const body = 'Intro\n```text\nCloses #12';
|
|
103
|
+
const { client, writes } = clientMock({ body });
|
|
104
|
+
|
|
105
|
+
const res = await client.editLinkedIssues(87, { add: [14] }, pin);
|
|
106
|
+
|
|
107
|
+
assert.equal(res.ok, false, 'a line appended inside the code block is never written');
|
|
108
|
+
assert.equal(res.error, 'the pull request body ends inside an unclosed code fence or comment');
|
|
109
|
+
assert.deepEqual(writes, [], 'nothing is written at all');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
// D17 (S2): the list window follows the number a confirmation captured, even
|
|
114
|
+
// when a reload moved it out of the visible slice.
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
test('S2: the close confirmation\'s row stays visible when a reload moves it away', async () => {
|
|
117
|
+
const rows = Array.from({ length: 40 }, (_, at) => row(100 + at));
|
|
118
|
+
let calls = 0;
|
|
119
|
+
let finish;
|
|
120
|
+
const closed = [];
|
|
121
|
+
const view = createPrsView({
|
|
122
|
+
loadPullRequestPage: () => (++calls === 1
|
|
123
|
+
? { ok: true, rows }
|
|
124
|
+
: new Promise((resolve) => { finish = resolve; })),
|
|
125
|
+
loadPullRequest: (number) => ({
|
|
126
|
+
ok: true,
|
|
127
|
+
pullRequest: { ...row(number), permissions: { canClosePullRequests: true } },
|
|
128
|
+
}),
|
|
129
|
+
actions: { close: (number) => { closed.push(number); return { ok: true }; } },
|
|
130
|
+
rowsAvailable: () => 20,
|
|
131
|
+
});
|
|
132
|
+
await tick();
|
|
133
|
+
send(view, 'end');
|
|
134
|
+
send(view, 'r');
|
|
135
|
+
send(view, 'x');
|
|
136
|
+
assert.match(frame(view), /Confirm close #139/);
|
|
137
|
+
finish({ ok: true, rows: rows.slice().reverse() });
|
|
138
|
+
await tick();
|
|
139
|
+
assert.match(frame(view), /Confirm close #139/, 'the confirmation still names the captured number');
|
|
140
|
+
assert.match(leftPane(view), /▸ PR 139/, 'the window scrolled to the row that will close');
|
|
141
|
+
send(view, 'enter');
|
|
142
|
+
await tick();
|
|
143
|
+
assert.deepEqual(closed, [139]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('S2: a confirmation whose row left the list still names the captured number', async () => {
|
|
147
|
+
const rows = [row(139), row(138)];
|
|
148
|
+
let calls = 0;
|
|
149
|
+
let finish;
|
|
150
|
+
const view = createPrsView({
|
|
151
|
+
loadPullRequestPage: () => (++calls === 1
|
|
152
|
+
? { ok: true, rows }
|
|
153
|
+
: new Promise((resolve) => { finish = resolve; })),
|
|
154
|
+
loadPullRequest: (number) => ({
|
|
155
|
+
ok: true,
|
|
156
|
+
pullRequest: { ...row(number), permissions: { canClosePullRequests: true } },
|
|
157
|
+
}),
|
|
158
|
+
actions: {},
|
|
159
|
+
rowsAvailable: () => 20,
|
|
160
|
+
});
|
|
161
|
+
await tick();
|
|
162
|
+
send(view, 'r');
|
|
163
|
+
send(view, 'x');
|
|
164
|
+
// The reload drops the captured row from the list altogether.
|
|
165
|
+
finish({ ok: true, rows: [rows[1]] });
|
|
166
|
+
await tick();
|
|
167
|
+
assert.match(frame(view), /Confirm close #139/, 'the step still names the row the list lost');
|
|
168
|
+
assert.doesNotMatch(leftPane(view), /139/, 'no row claims to be the captured pull request');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
// D18 (S2): the composer names its own pull request and highlights its row, so
|
|
173
|
+
// what the reader sees is where the comment goes.
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
test('S2: the comment composer names and highlights the number it will post to', async () => {
|
|
176
|
+
const rows = Array.from({ length: 40 }, (_, at) => row(100 + at));
|
|
177
|
+
let calls = 0;
|
|
178
|
+
let finish;
|
|
179
|
+
const view = createPrsView({
|
|
180
|
+
loadPullRequestPage: () => (++calls === 1
|
|
181
|
+
? { ok: true, rows }
|
|
182
|
+
: new Promise((resolve) => { finish = resolve; })),
|
|
183
|
+
loadPullRequest: (number) => ({ ok: true, pullRequest: { ...row(number) } }),
|
|
184
|
+
actions: {},
|
|
185
|
+
rowsAvailable: () => 20,
|
|
186
|
+
});
|
|
187
|
+
await tick();
|
|
188
|
+
send(view, 'end');
|
|
189
|
+
send(view, 'r');
|
|
190
|
+
send(view, 'c');
|
|
191
|
+
finish({ ok: true, rows: rows.slice().reverse() });
|
|
192
|
+
await tick();
|
|
193
|
+
assert.match(frame(view), /Comment on #139/, 'the composer names the captured number');
|
|
194
|
+
assert.match(leftPane(view), /▸ PR 139/, 'the composer highlights the row it will post to');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
// D19 (S2): with no pin and no checkout the fallback scope keeps the host the
|
|
199
|
+
// environment named, for every write.
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
test('S2: an enterprise-host GH_REPO reaches every write of the fallback scope', async () => {
|
|
202
|
+
const writes = {
|
|
203
|
+
close: (client) => client.closePullRequest(64, { env: { GH_REPO: ENTERPRISE } }),
|
|
204
|
+
merge: (client) => client.mergePullRequest(64, { method: 'merge' }, { env: { GH_REPO: ENTERPRISE } }),
|
|
205
|
+
labels: (client) => client.editLabels(64, { add: ['needs-work'] }, { env: { GH_REPO: ENTERPRISE } }),
|
|
206
|
+
assignees: (client) => client.editAssignees(64, { remove: ['alice'] }, { env: { GH_REPO: ENTERPRISE } }),
|
|
207
|
+
linked: (client) => client.editLinkedIssues(64, { add: [12] }, { env: { GH_REPO: ENTERPRISE } }),
|
|
208
|
+
};
|
|
209
|
+
for (const [name, call] of Object.entries(writes)) {
|
|
210
|
+
const { client, children } = clientMock();
|
|
211
|
+
const res = await call(client);
|
|
212
|
+
assert.equal(res.ok, true, `${name}: ${res.error}`);
|
|
213
|
+
const spawned = children.filter((child) => !(child.argv[0] === 'repo' && child.argv[1] === 'view'));
|
|
214
|
+
assert.ok(spawned.length > 0, `${name} spawned nothing`);
|
|
215
|
+
for (const child of spawned) {
|
|
216
|
+
assert.equal(child.repo, ENTERPRISE,
|
|
217
|
+
`${name}: ${child.argv.slice(0, 2).join(' ')} kept the enterprise host, not ${child.repo}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// ---------------------------------------------------------------------------
|
|
223
|
+
// D20 (S2): the captured number's own detail is re-read before its confirm or
|
|
224
|
+
// save proceeds, so a reload can never write with another pull request's
|
|
225
|
+
// capability, and a target that is no longer open writes nothing.
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
const CAPTURED_STEPS = [
|
|
228
|
+
{
|
|
229
|
+
name: 'close',
|
|
230
|
+
key: 'x',
|
|
231
|
+
capability: 'canClosePullRequests',
|
|
232
|
+
opened: /Confirm close #42/,
|
|
233
|
+
save: 'enter',
|
|
234
|
+
seam: 'close',
|
|
235
|
+
refusal: 'pull requests cannot be closed: this repository permission is missing',
|
|
236
|
+
notOpen: (number) => `pull request #${number} is not open; it cannot be closed`,
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: 'merge',
|
|
240
|
+
key: 'm',
|
|
241
|
+
capability: 'canMerge',
|
|
242
|
+
opened: /Confirm merge #42/,
|
|
243
|
+
save: 'ctrl+s',
|
|
244
|
+
seam: 'merge',
|
|
245
|
+
refusal: 'pull requests cannot be merged: this repository permission is missing',
|
|
246
|
+
notOpen: (number) => `pull request #${number} is not open; it cannot be merged`,
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: 'linked issues',
|
|
250
|
+
key: 'i',
|
|
251
|
+
capability: 'canEditLinkedIssues',
|
|
252
|
+
opened: /Linked issues/,
|
|
253
|
+
save: 'ctrl+s',
|
|
254
|
+
seam: 'editLinkedIssues',
|
|
255
|
+
refusal: 'linked issues cannot be edited: this repository permission is missing',
|
|
256
|
+
notOpen: (number) => `pull request #${number} is not open; its linked issues cannot be edited`,
|
|
257
|
+
},
|
|
258
|
+
];
|
|
259
|
+
|
|
260
|
+
// A server-mode view whose first page lands, whose reload is HELD, and whose
|
|
261
|
+
// detail answers each number with the capability and state the case sets.
|
|
262
|
+
function capturedView(step, { permission = () => true, state = () => 'open' } = {}) {
|
|
263
|
+
const rows = [row(42), row(43)];
|
|
264
|
+
const writes = [];
|
|
265
|
+
const reads = [];
|
|
266
|
+
let calls = 0;
|
|
267
|
+
let finish;
|
|
268
|
+
const view = createPrsView({
|
|
269
|
+
loadPullRequestPage: () => (++calls === 1
|
|
270
|
+
? { ok: true, rows }
|
|
271
|
+
: new Promise((resolve) => { finish = resolve; })),
|
|
272
|
+
loadPullRequest: (number) => {
|
|
273
|
+
reads.push(number);
|
|
274
|
+
return {
|
|
275
|
+
ok: true,
|
|
276
|
+
pullRequest: {
|
|
277
|
+
...row(number, { state: state(number) }),
|
|
278
|
+
permissions: { [step.capability]: permission(number) },
|
|
279
|
+
mergeMethods: { merge: true },
|
|
280
|
+
mergeDefaults: { merge: { subject: 'S', body: 'B' } },
|
|
281
|
+
linkedIssues: [],
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
},
|
|
285
|
+
actions: { [step.seam]: (...args) => { writes.push(args); return { ok: true }; } },
|
|
286
|
+
rowsAvailable: () => 30,
|
|
287
|
+
});
|
|
288
|
+
return { view, writes, reads, reload: () => finish({ ok: true, rows: [rows[1], rows[0]] }) };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
292
|
+
|
|
293
|
+
for (const step of CAPTURED_STEPS) {
|
|
294
|
+
test(`S2: ${step.name} re-reads the captured number before it writes`, async () => {
|
|
295
|
+
let allowed = true;
|
|
296
|
+
const run = capturedView(step, { permission: (number) => allowed || number !== 42 });
|
|
297
|
+
await tick();
|
|
298
|
+
send(run.view, 'r');
|
|
299
|
+
send(run.view, step.key);
|
|
300
|
+
assert.match(frame(run.view), step.opened, `${step.name}: the step opened on the captured number`);
|
|
301
|
+
// The capability the pane painted lapses while the reload reorders the rows.
|
|
302
|
+
allowed = false;
|
|
303
|
+
run.reload();
|
|
304
|
+
await tick();
|
|
305
|
+
send(run.view, step.save);
|
|
306
|
+
await tick();
|
|
307
|
+
assert.deepEqual(run.writes, [], `${step.name}: a lapsed capability reaches no seam`);
|
|
308
|
+
assert.match(frame(run.view), new RegExp(escape(step.refusal)),
|
|
309
|
+
`${step.name}: the refusal names the capability`);
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test(`S2: ${step.name} refuses a captured number that is no longer open`, async () => {
|
|
313
|
+
let fresh = 'open';
|
|
314
|
+
const run = capturedView(step, { state: (number) => (number === 42 ? fresh : 'open') });
|
|
315
|
+
await tick();
|
|
316
|
+
send(run.view, 'r');
|
|
317
|
+
send(run.view, step.key);
|
|
318
|
+
assert.match(frame(run.view), step.opened, `${step.name}: the step opened on the captured number`);
|
|
319
|
+
fresh = 'MERGED';
|
|
320
|
+
run.reload();
|
|
321
|
+
await tick();
|
|
322
|
+
send(run.view, step.save);
|
|
323
|
+
await tick();
|
|
324
|
+
assert.deepEqual(run.writes, [], `${step.name}: a merged pull request reaches no seam`);
|
|
325
|
+
assert.match(frame(run.view), new RegExp(escape(step.notOpen(42))),
|
|
326
|
+
`${step.name}: the refusal names the state`);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
test('S2: the client refuses a close, a merge and a linked edit of a non-open pull request', async () => {
|
|
331
|
+
const calls = {
|
|
332
|
+
close: (client) => client.closePullRequest(64, pin),
|
|
333
|
+
merge: (client) => client.mergePullRequest(64, { method: 'merge' }, pin),
|
|
334
|
+
linked: (client) => client.editLinkedIssues(64, { add: [12] }, pin),
|
|
335
|
+
};
|
|
336
|
+
const sentences = {
|
|
337
|
+
close: 'pull request #64 is not open; it cannot be closed',
|
|
338
|
+
merge: 'pull request #64 is not open; it cannot be merged',
|
|
339
|
+
linked: 'pull request #64 is not open; its linked issues cannot be edited',
|
|
340
|
+
};
|
|
341
|
+
for (const [name, call] of Object.entries(calls)) {
|
|
342
|
+
const { client, writes } = clientMock({ state: 'MERGED' });
|
|
343
|
+
const res = await call(client);
|
|
344
|
+
assert.equal(res.ok, false, `${name}: a merged pull request is not written`);
|
|
345
|
+
assert.equal(res.error, sentences[name]);
|
|
346
|
+
assert.deepEqual(writes, [], `${name}: no write child ran`);
|
|
347
|
+
}
|
|
348
|
+
});
|