pi-odd-worktree 3.11.0 → 3.11.2
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/extensions/odd-worktree-tools.ts +111 -40
- package/lib/gh-prs.js +4 -1
- package/lib/issue-preview.js +53 -10
- package/lib/issues-view.js +55 -21
- package/lib/pr-preview.js +36 -5
- package/lib/prs-view.js +398 -65
- package/lib/user-prompt-card.js +68 -10
- package/package.json +1 -1
- package/tools/gh-prs.test.js +5 -1
- package/tools/issue-preview.test.js +113 -0
- package/tools/issues-command.test.js +8 -5
- package/tools/issues-view.test.js +130 -0
- package/tools/pr-preview.test.js +134 -0
- package/tools/prs-command.test.js +49 -0
- package/tools/prs-view.test.js +350 -5
- package/tools/user-prompt-card.test.js +173 -6
package/lib/user-prompt-card.js
CHANGED
|
@@ -11,11 +11,15 @@
|
|
|
11
11
|
// from Pi, so a stub class is enough to exercise all of it.
|
|
12
12
|
//
|
|
13
13
|
// WHAT IT DRAWS, and what it never touches:
|
|
14
|
-
// * THE HEADING is `✿ You
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
14
|
+
// * THE HEADING is `✿ You · 14:32`: the mark and the name in the theme's `accent` role (the
|
|
15
|
+
// card's `titleRole`), then the substrate's `SEPARATOR` and the prompt's clock in `muted`
|
|
16
|
+
// (the subtitle path `lib/shell-card.js` already has, `SUBTITLE_ROLE`). The clock is the
|
|
17
|
+
// host's own `timestamp` when it set one, else the moment of the card's FIRST paint, held
|
|
18
|
+
// per component so a live prompt does not drift frame by frame; with neither, the heading is
|
|
19
|
+
// `✿ You` alone and nothing is invented. The whole closed box still wears the `accent` role
|
|
20
|
+
// (`railRole`) — corners, lead, rule, sides, rail and bottom. That one role around the entire
|
|
21
|
+
// frame is what tells this card apart from the tool cards, which paint their tone.
|
|
22
|
+
// No glyph override is made (the `✿` is the substrate's default mark).
|
|
19
23
|
// * THE BODY is Pi's own rendering of the prompt. The component's Markdown child is
|
|
20
24
|
// rebuilt from its OWN constructor with the user message background dropped
|
|
21
25
|
// (`bgColor: undefined`), no side padding (the frame is the padding) and the host's own
|
|
@@ -66,8 +70,8 @@ const { ACTIVITY_DESIGN_ID, bridgeApi } = require('./file-card-resolver.js');
|
|
|
66
70
|
const { themeFor } = require('./file-card.js');
|
|
67
71
|
|
|
68
72
|
// The one heading this card wears: the mark is the substrate's default `✿`, the name is the
|
|
69
|
-
// person, and the role is the accent for the name and for the whole closed box.
|
|
70
|
-
//
|
|
73
|
+
// person, and the role is the accent for the name and for the whole closed box. The clock is NOT
|
|
74
|
+
// part of it — it belongs to the component being drawn, so `cardParts` adds it per paint (S1).
|
|
71
75
|
const IDENTITY = Object.freeze({
|
|
72
76
|
title: 'You',
|
|
73
77
|
tone: CARD_TONE.INFO,
|
|
@@ -265,6 +269,53 @@ const sameRows = (a, b) => a === b || (a.length === b.length && a.every((row, in
|
|
|
265
269
|
const cloneMemo = new WeakMap();
|
|
266
270
|
/** The per-component card memo: (requested width, drawn width, paint, rendered rows) in, parts out. */
|
|
267
271
|
const cardMemo = new WeakMap();
|
|
272
|
+
/** The per-component clock memo: the raw source read (`timestamp`, else `undefined`) and its `HH:MM`. */
|
|
273
|
+
const clockMemo = new WeakMap();
|
|
274
|
+
|
|
275
|
+
// ---- the heading's clock (S1) ----
|
|
276
|
+
|
|
277
|
+
/** Two digits, zero padded: the clock's only formatting rule. */
|
|
278
|
+
const twoDigits = (value) => String(value).padStart(2, '0');
|
|
279
|
+
|
|
280
|
+
/** One instant as local 24-hour `HH:MM`: no seconds, no date, no relative wording. */
|
|
281
|
+
function clockText(at) {
|
|
282
|
+
const instant = new Date(at);
|
|
283
|
+
return `${twoDigits(instant.getHours())}:${twoDigits(instant.getMinutes())}`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* The clock the heading carries for `self`, or `undefined` when there is none to state.
|
|
288
|
+
*
|
|
289
|
+
* The source, in this order (S1):
|
|
290
|
+
* 1. the component's OWN `timestamp` when it is a string — what Pi sets when it rebuilds a
|
|
291
|
+
* prompt from a session entry, so a restored transcript shows when the prompt was sent;
|
|
292
|
+
* 2. otherwise a clock captured ONCE, at the component's first paint, so a prompt sent live
|
|
293
|
+
* shows its arrival time too and a later frame never drifts;
|
|
294
|
+
* 3. with neither, nothing: the heading keeps `✿ You` and no time is invented (an unparseable
|
|
295
|
+
* `timestamp` is not a clock, and a host clock that answers no number is not one either).
|
|
296
|
+
*
|
|
297
|
+
* The memo is keyed on the SOURCE, so the formatting runs once per component (or once per
|
|
298
|
+
* `timestamp` the host sets) and every later paint reads the string it already made — a steady
|
|
299
|
+
* frame formats nothing and reads no file, no store and no bridge.
|
|
300
|
+
*/
|
|
301
|
+
function headingClock(self) {
|
|
302
|
+
const field = asObject(self).timestamp;
|
|
303
|
+
const source = typeof field === 'string' ? field : undefined;
|
|
304
|
+
const key = self !== null && typeof self === 'object' ? self : undefined;
|
|
305
|
+
const remembered = key === undefined ? undefined : clockMemo.get(key);
|
|
306
|
+
if (remembered !== undefined && remembered.source === source) return remembered.clock;
|
|
307
|
+
let clock;
|
|
308
|
+
if (source !== undefined) {
|
|
309
|
+
const at = Date.parse(source);
|
|
310
|
+
if (Number.isFinite(at)) clock = clockText(at);
|
|
311
|
+
}
|
|
312
|
+
if (clock === undefined) {
|
|
313
|
+
const now = Date.now();
|
|
314
|
+
clock = Number.isFinite(now) ? clockText(now) : undefined;
|
|
315
|
+
}
|
|
316
|
+
if (key !== undefined) clockMemo.set(key, { source, clock });
|
|
317
|
+
return clock;
|
|
318
|
+
}
|
|
268
319
|
|
|
269
320
|
/**
|
|
270
321
|
* One component's card parts for one draw — `{ head, body, bottom }`, the shape `floatRows`
|
|
@@ -285,6 +336,10 @@ function cardParts(self, markdown, target, inner, paint, metrics) {
|
|
|
285
336
|
const width = cardInnerWidth(inner);
|
|
286
337
|
const rows = renderedRows(markdown, width);
|
|
287
338
|
if (rows === undefined) return undefined;
|
|
339
|
+
// The clock is part of the memo key ONLY as the string it formats to: it cannot change between
|
|
340
|
+
// paints except through the component's own `timestamp` or the theme, and a steady frame pays
|
|
341
|
+
// one memo read rather than a second format.
|
|
342
|
+
const clock = headingClock(self);
|
|
288
343
|
const remembered = cardMemo.get(self);
|
|
289
344
|
if (
|
|
290
345
|
remembered !== undefined
|
|
@@ -292,17 +347,20 @@ function cardParts(self, markdown, target, inner, paint, metrics) {
|
|
|
292
347
|
&& remembered.target === target
|
|
293
348
|
&& remembered.inner === inner
|
|
294
349
|
&& remembered.paint === paint
|
|
350
|
+
&& remembered.clock === clock
|
|
295
351
|
&& sameRows(remembered.rows, rows)
|
|
296
352
|
) return remembered.parts;
|
|
297
|
-
|
|
353
|
+
// The clock rides the substrate's subtitle path: the heading states `✿ You`, then the
|
|
354
|
+
// separator and the clock in `muted` (`SUBTITLE_ROLE`). No clock, no subtitle at all.
|
|
355
|
+
const card = clock === undefined ? { ...IDENTITY } : { ...IDENTITY, subtitle: clock };
|
|
298
356
|
const parts = {
|
|
299
357
|
head: cardTopRows(card, paint, inner, undefined, metrics),
|
|
300
358
|
// The body is never clipped: a prompt is not a preview, so every row is drawn.
|
|
301
359
|
body: cardPaintedRows(rows, IDENTITY.tone, paint, inner, { expanded: true }, metrics),
|
|
302
|
-
// No content rides the closing rule: the
|
|
360
|
+
// No content rides the closing rule: the prompt's clock belongs to the heading alone.
|
|
303
361
|
bottom: cardBottom(IDENTITY.tone, paint, inner, undefined, metrics),
|
|
304
362
|
};
|
|
305
|
-
cardMemo.set(self, { markdown, target, inner, paint, rows, parts });
|
|
363
|
+
cardMemo.set(self, { markdown, target, inner, paint, clock, rows, parts });
|
|
306
364
|
return parts;
|
|
307
365
|
}
|
|
308
366
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.2",
|
|
4
4
|
"description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
package/tools/gh-prs.test.js
CHANGED
|
@@ -180,7 +180,11 @@ describe('the three buckets read through the repository search', () => {
|
|
|
180
180
|
});
|
|
181
181
|
|
|
182
182
|
test('the review and involved buckets carry their own qualifier', async () => {
|
|
183
|
-
|
|
183
|
+
// S1: `involved` excludes what you AUTHORED, exactly as the issues reader
|
|
184
|
+
// does (`involves:@me -author:@me`). GitHub's `involves:@me` includes your
|
|
185
|
+
// own pull requests, and repeating them under `Involved` hides the ones you
|
|
186
|
+
// are merely part of.
|
|
187
|
+
for (const [bucket, qualifier] of [['review', 'review-requested:@me'], ['involved', 'involves:@me -author:@me']]) {
|
|
184
188
|
const { runner, calls } = makeRunner(okJson(fixture('gh-pr-search-page.json')));
|
|
185
189
|
ghPrs.setGhRunner(runner);
|
|
186
190
|
|
|
@@ -370,3 +370,116 @@ describe('a linked PR of another repository (D29)', () => {
|
|
|
370
370
|
assert.match(text, /linked PRs: #69, #77/);
|
|
371
371
|
});
|
|
372
372
|
});
|
|
373
|
+
|
|
374
|
+
// The reading pane separates its blocks with the horizontal rule the ODD reader
|
|
375
|
+
// already draws (`lib/odd-markdown.js` paints `'─'.repeat(width)`), as wide as
|
|
376
|
+
// the pane and in the muted role: the metadata block from the body, the body
|
|
377
|
+
// from the comments and each comment from the next. No rule before the first
|
|
378
|
+
// row, none after the last, and none for a block the issue does not have.
|
|
379
|
+
describe('the pane separates its blocks with a full-width rule', () => {
|
|
380
|
+
const WIDTH = 40;
|
|
381
|
+
const RULE = '─'.repeat(WIDTH);
|
|
382
|
+
|
|
383
|
+
function painted(detail, comments, options = {}) {
|
|
384
|
+
const calls = [];
|
|
385
|
+
const paint = (role, text) => {
|
|
386
|
+
calls.push({ role, text: String(text) });
|
|
387
|
+
return String(text);
|
|
388
|
+
};
|
|
389
|
+
const lines = issueDetailLines(detail, comments, {
|
|
390
|
+
width: WIDTH,
|
|
391
|
+
paint,
|
|
392
|
+
emphasis: bold,
|
|
393
|
+
now: NOW,
|
|
394
|
+
...options,
|
|
395
|
+
});
|
|
396
|
+
return { lines, calls };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const ruleRows = (lines) => lines.reduce((found, line, at) => (line === RULE ? [...found, at] : found), []);
|
|
400
|
+
|
|
401
|
+
test('the metadata block, the body and each comment are separated by one rule', () => {
|
|
402
|
+
const { lines, calls } = painted(FULL, [
|
|
403
|
+
{ author: 'ana', body: 'first comment', createdAt: '2026-02-27T00:00:00.000Z' },
|
|
404
|
+
{ author: 'beto', body: 'second comment', createdAt: '2026-02-28T00:00:00.000Z' },
|
|
405
|
+
]);
|
|
406
|
+
const at = (needle) => {
|
|
407
|
+
const index = lines.findIndex((line) => line.includes(needle));
|
|
408
|
+
assert.notEqual(index, -1, `not painted: ${needle}`);
|
|
409
|
+
return index;
|
|
410
|
+
};
|
|
411
|
+
assert.equal(lines[0], '#77 parity title', 'no rule before the first row');
|
|
412
|
+
assert.equal(lines.at(-1), '(end of issue)', 'no rule after the last row');
|
|
413
|
+
assert.equal(lines[at('the body') - 1], RULE, 'the metadata block and the body are separated');
|
|
414
|
+
assert.equal(lines[at('─ ana') - 1], RULE, 'the body and the comments are separated');
|
|
415
|
+
assert.equal(lines[at('─ beto') - 1], RULE, 'each comment is separated from the next');
|
|
416
|
+
assert.deepEqual(ruleRows(lines), [at('the body') - 1, at('─ ana') - 1, at('─ beto') - 1],
|
|
417
|
+
'exactly those three rows carry a rule and no two rules are adjacent');
|
|
418
|
+
const paintedRules = calls.filter((call) => call.text === RULE);
|
|
419
|
+
assert.equal(paintedRules.length, 3, 'each rule is painted through the caller seam');
|
|
420
|
+
assert.ok(paintedRules.every((call) => call.role === 'muted'), 'the rule takes the muted role');
|
|
421
|
+
assert.equal([...RULE].length, WIDTH, 'the rule spans the whole pane');
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
test('a comment-free issue draws only the rule before the body', () => {
|
|
425
|
+
const { lines } = painted({ ...FULL, body: '' }, []);
|
|
426
|
+
const body = lines.indexOf('(no description)');
|
|
427
|
+
assert.notEqual(body, -1, 'the placeholder is still the body block');
|
|
428
|
+
assert.deepEqual(ruleRows(lines), [body - 1], 'nothing separates a body from no comments');
|
|
429
|
+
assert.equal(lines.at(-1), '(end of issue)');
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('a pending read separates nothing it has not painted', () => {
|
|
433
|
+
const { lines } = painted({ number: 12, title: 'pending read' }, [], { pending: true });
|
|
434
|
+
assert.ok(!lines.includes(RULE), 'a pane with no body and no comments draws no rule');
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
test('the rule is exactly the pane width at any width', () => {
|
|
438
|
+
for (const width of [12, 40, 121]) {
|
|
439
|
+
const rule = '─'.repeat(width);
|
|
440
|
+
const lines = issueDetailLines(FULL, [], { width, paint: plain, emphasis: bold, now: NOW });
|
|
441
|
+
assert.deepEqual(lines.reduce((found, line, at) => (line === rule ? [...found, at] : found), []),
|
|
442
|
+
[lines.indexOf('the body') - 1], `one full-width rule at ${width}`);
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
// The hover highlight paints the linked number the pointer is over, through the
|
|
448
|
+
// same role the rail uses for a hovered row, and changes nothing about the
|
|
449
|
+
// published click geometry.
|
|
450
|
+
describe('the hovered linked PR is the one painted as the target', () => {
|
|
451
|
+
function paintedCalls(hover) {
|
|
452
|
+
const calls = [];
|
|
453
|
+
const ranges = [];
|
|
454
|
+
const paint = (role, text) => {
|
|
455
|
+
calls.push({ role, text: String(text) });
|
|
456
|
+
return String(text);
|
|
457
|
+
};
|
|
458
|
+
const lines = issueDetailLines(FULL, [], {
|
|
459
|
+
width: 80,
|
|
460
|
+
paint,
|
|
461
|
+
emphasis: bold,
|
|
462
|
+
now: NOW,
|
|
463
|
+
ranges,
|
|
464
|
+
hover,
|
|
465
|
+
});
|
|
466
|
+
return { calls, lines, ranges };
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
test('only the hovered number takes the hover role', () => {
|
|
470
|
+
const { calls, lines } = paintedCalls(77);
|
|
471
|
+
const targets = calls.filter((call) => call.role === 'accent').map((call) => call.text);
|
|
472
|
+
assert.ok(targets.includes('#77'), 'the hovered number is painted as the target');
|
|
473
|
+
assert.ok(!targets.includes('#69'), 'the other number keeps its plain text');
|
|
474
|
+
assert.match(lines.find((line) => line.includes('linked PRs:')), /#69, #77/,
|
|
475
|
+
'the painted row still carries both numbers');
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
test('no hover paints no target, and the click geometry is identical either way', () => {
|
|
479
|
+
const hovered = paintedCalls(77);
|
|
480
|
+
const plainRun = paintedCalls(null);
|
|
481
|
+
assert.ok(!plainRun.calls.some((call) => call.role === 'accent' && call.text === '#77'),
|
|
482
|
+
'without hover no number takes the switch role');
|
|
483
|
+
assert.deepEqual(hovered.ranges, plainRun.ranges, 'hover never moves a click range');
|
|
484
|
+
});
|
|
485
|
+
});
|
|
@@ -1209,11 +1209,14 @@ describe('/issues actions (S3,S4)', () => {
|
|
|
1209
1209
|
['issue', 'view', '76', '--web', '-R', 'github.com/jonasotoaguilar/herdr-gentle-shell']);
|
|
1210
1210
|
assert.equal(gitCalls[0].cwd, root, 'the opener runs in this checkout');
|
|
1211
1211
|
assert.ok(!gitCalls[0].argv.join(' ').includes('xdg-open'), 'never an invented opener');
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1212
|
+
// Regression: the opener used to stop the host TUI and start it again. `gh`
|
|
1213
|
+
// here runs on pipes and never touches the terminal, and in Pi the
|
|
1214
|
+
// stop/start pair left the render loop dead (the screen kept the plain shell
|
|
1215
|
+
// and stopped repainting). Opening a browser is not an interactive child, so
|
|
1216
|
+
// the TUI is never suspended for it.
|
|
1217
|
+
assert.deepEqual(run.host.lifecycle, [], 'the browser opener never stops or restarts the TUI');
|
|
1218
|
+
assert.deepEqual(run.host.stops, [], 'nothing suspends the screen to open a URL');
|
|
1219
|
+
assert.deepEqual(run.host.paints, [], 'no resume repaint is needed because nothing was suspended');
|
|
1217
1220
|
});
|
|
1218
1221
|
|
|
1219
1222
|
test('r re-reads the current page fresh, and the removed state toggle reads nothing', async () => {
|
|
@@ -6125,3 +6125,133 @@ describe('S6: each linked PR is its own click range', () => {
|
|
|
6125
6125
|
assert.deepEqual(calls, []);
|
|
6126
6126
|
});
|
|
6127
6127
|
});
|
|
6128
|
+
|
|
6129
|
+
// S6 follow-up: the same link geometry answers the pointer. Pi's TUI delivers
|
|
6130
|
+
// `type: "move"` events to `handleMouse`, so hovering a linked PR number paints
|
|
6131
|
+
// exactly that number in the role the rail gives a hovered row, moving off
|
|
6132
|
+
// clears it, and a repaint happens only when the target actually changes.
|
|
6133
|
+
describe('S6: a move over a linked PR number highlights it', () => {
|
|
6134
|
+
const PANE_START = (width) => 5 + readerPanes(width).left;
|
|
6135
|
+
const BODY_TOP = 4;
|
|
6136
|
+
|
|
6137
|
+
function moveEvent(overrides = {}) {
|
|
6138
|
+
return {
|
|
6139
|
+
type: 'move',
|
|
6140
|
+
button: 'none',
|
|
6141
|
+
x: 0,
|
|
6142
|
+
y: 0,
|
|
6143
|
+
width: 120,
|
|
6144
|
+
height: 24,
|
|
6145
|
+
shift: false,
|
|
6146
|
+
alt: false,
|
|
6147
|
+
ctrl: false,
|
|
6148
|
+
...overrides,
|
|
6149
|
+
};
|
|
6150
|
+
}
|
|
6151
|
+
|
|
6152
|
+
// The frame cell of `needle` inside the RIGHT pane, read off the frame the
|
|
6153
|
+
// view just painted, so the test never assumes the pane's columns or rows.
|
|
6154
|
+
function cellOf(view, width, needle, offset = 0) {
|
|
6155
|
+
const lines = view.render(width);
|
|
6156
|
+
const panes = readerPanes(width);
|
|
6157
|
+
for (let y = BODY_TOP; y < lines.length - 2; y += 1) {
|
|
6158
|
+
const pane = [...strip(lines[y])].slice(PANE_START(width), PANE_START(width) + panes.right).join('');
|
|
6159
|
+
const at = pane.indexOf(needle);
|
|
6160
|
+
if (at < 0) continue;
|
|
6161
|
+
return { x: PANE_START(width) + at + offset, y, width, height: lines.length };
|
|
6162
|
+
}
|
|
6163
|
+
assert.fail(`no pane row carries ${JSON.stringify(needle)}`);
|
|
6164
|
+
}
|
|
6165
|
+
|
|
6166
|
+
function hoverView() {
|
|
6167
|
+
const theme = recordingTheme();
|
|
6168
|
+
const calls = [];
|
|
6169
|
+
const rows = [issue(7)];
|
|
6170
|
+
const made = makeView({
|
|
6171
|
+
rows: 24,
|
|
6172
|
+
theme,
|
|
6173
|
+
pages: pagesOf([rows, [], []]),
|
|
6174
|
+
issues: rows,
|
|
6175
|
+
loadIssue: () => ({
|
|
6176
|
+
ok: true,
|
|
6177
|
+
issue: issue(7, { title: 'linked issue', linkedPullRequests: [69, 77], body: 'the body' }),
|
|
6178
|
+
comments: [],
|
|
6179
|
+
}),
|
|
6180
|
+
actions: { openLinked: (target) => calls.push(target) },
|
|
6181
|
+
});
|
|
6182
|
+
return { view: made.view, paints: made.paints, theme, calls };
|
|
6183
|
+
}
|
|
6184
|
+
|
|
6185
|
+
// The roles the LAST render asked for, so an assertion is about this frame.
|
|
6186
|
+
function hoveredNumbers(view, theme, width = 120) {
|
|
6187
|
+
const mark = theme.calls.length;
|
|
6188
|
+
const lines = view.render(width);
|
|
6189
|
+
const roles = theme.calls.slice(mark)
|
|
6190
|
+
.filter((call) => call.role === 'accent' && /^#\d+$/.test(call.text))
|
|
6191
|
+
.map((call) => call.text);
|
|
6192
|
+
return { roles, lines };
|
|
6193
|
+
}
|
|
6194
|
+
|
|
6195
|
+
test('a move over one number paints exactly that range, and moving off clears it', async () => {
|
|
6196
|
+
const { view, theme } = hoverView();
|
|
6197
|
+
await tick();
|
|
6198
|
+
const linked = cellOf(view, 120, '#69');
|
|
6199
|
+
assert.deepEqual(view.handleMouse(moveEvent(linked)), { handled: true, render: true },
|
|
6200
|
+
'the move is consumed and asks for a repaint');
|
|
6201
|
+
|
|
6202
|
+
let hovered = hoveredNumbers(view, theme);
|
|
6203
|
+
assert.deepEqual(hovered.roles, ['#69'], 'only the hovered number takes the hover role');
|
|
6204
|
+
const row = hovered.lines.find((line) => strip(line).includes('linked PRs:'));
|
|
6205
|
+
assert.ok(row.includes('\x1b[96m#69'), 'the hovered number is painted with the accent role');
|
|
6206
|
+
assert.ok(!row.includes('\x1b[96m#77'), 'the other number keeps its plain text');
|
|
6207
|
+
assert.match(strip(row), /linked PRs: #69, #77/, 'painting never changes the row the click expects');
|
|
6208
|
+
|
|
6209
|
+
const off = cellOf(view, 120, 'linked PRs:');
|
|
6210
|
+
assert.deepEqual(view.handleMouse(moveEvent(off)), { handled: true, render: true },
|
|
6211
|
+
'moving onto the row label is a change of target');
|
|
6212
|
+
hovered = hoveredNumbers(view, theme);
|
|
6213
|
+
assert.deepEqual(hovered.roles, [], 'nothing is highlighted once the pointer leaves the number');
|
|
6214
|
+
});
|
|
6215
|
+
|
|
6216
|
+
test('a move to another number moves the highlight with it', async () => {
|
|
6217
|
+
const { view, theme } = hoverView();
|
|
6218
|
+
await tick();
|
|
6219
|
+
assert.deepEqual(view.handleMouse(moveEvent(cellOf(view, 120, '#69'))), { handled: true, render: true });
|
|
6220
|
+
assert.deepEqual(hoveredNumbers(view, theme).roles, ['#69']);
|
|
6221
|
+
assert.deepEqual(view.handleMouse(moveEvent(cellOf(view, 120, '#77'))), { handled: true, render: true });
|
|
6222
|
+
assert.deepEqual(hoveredNumbers(view, theme).roles, ['#77'], 'the highlight follows the pointer');
|
|
6223
|
+
});
|
|
6224
|
+
|
|
6225
|
+
test('the same target twice does not repaint, and a move outside clears the hover', async () => {
|
|
6226
|
+
const { view, theme, paints } = hoverView();
|
|
6227
|
+
await tick();
|
|
6228
|
+
const linked = cellOf(view, 120, '#69');
|
|
6229
|
+
view.handleMouse(moveEvent(linked));
|
|
6230
|
+
const painted = paints.length;
|
|
6231
|
+
assert.deepEqual(view.handleMouse(moveEvent(linked)), { handled: true, render: false },
|
|
6232
|
+
'the hovered target did not change, so no repaint is asked for');
|
|
6233
|
+
assert.equal(paints.length, painted, 'and none is issued');
|
|
6234
|
+
|
|
6235
|
+
assert.deepEqual(view.handleMouse(moveEvent({ x: 3, y: linked.y })), { handled: true, render: true },
|
|
6236
|
+
'a move onto the list column lands on no link and clears the hover');
|
|
6237
|
+
assert.deepEqual(hoveredNumbers(view, theme).roles, []);
|
|
6238
|
+
assert.deepEqual(view.handleMouse(moveEvent({ width: 100 })), { handled: true, render: false },
|
|
6239
|
+
'a move from another frame geometry lands nowhere and changes nothing');
|
|
6240
|
+
});
|
|
6241
|
+
|
|
6242
|
+
test('the same geometry serves the click and the hover', async () => {
|
|
6243
|
+
const { view, calls, theme } = hoverView();
|
|
6244
|
+
await tick();
|
|
6245
|
+
const linked = cellOf(view, 120, '#69');
|
|
6246
|
+
assert.deepEqual(view.handleMouse(moveEvent(linked)), { handled: true, render: true });
|
|
6247
|
+
// The cell the pointer highlighted is exactly the cell that opens #69.
|
|
6248
|
+
assert.deepEqual(view.handleMouse({ ...moveEvent(linked), type: 'click', button: 'left' }),
|
|
6249
|
+
{ handled: true, render: false });
|
|
6250
|
+
assert.deepEqual(calls, [{ kind: 'pullRequest', number: 69 }]);
|
|
6251
|
+
// And the separator right after the number is neither hovered nor clicked:
|
|
6252
|
+
// leaving the number clears the highlight with a repaint.
|
|
6253
|
+
assert.deepEqual(view.handleMouse(moveEvent({ ...linked, x: linked.x + 3 })), { handled: true, render: true },
|
|
6254
|
+
'a move onto the separator clears the hover');
|
|
6255
|
+
assert.deepEqual(hoveredNumbers(view, theme).roles, [], 'no number is left highlighted');
|
|
6256
|
+
});
|
|
6257
|
+
});
|
package/tools/pr-preview.test.js
CHANGED
|
@@ -279,3 +279,137 @@ describe('linked issue click ranges (S6)', () => {
|
|
|
279
279
|
assert.deepEqual(emptyLinks, []);
|
|
280
280
|
});
|
|
281
281
|
});
|
|
282
|
+
|
|
283
|
+
// The reading pane separates its blocks with the horizontal rule the ODD reader
|
|
284
|
+
// already draws (`lib/odd-markdown.js` paints `'─'.repeat(width)`), as wide as
|
|
285
|
+
// the pane and in the muted role: the metadata block (the `Changes` and `Checks`
|
|
286
|
+
// summaries included) from the body, the body from the comments and each
|
|
287
|
+
// comment from the next. No rule before the first row, none after the last, and
|
|
288
|
+
// none for a block the pull request does not have.
|
|
289
|
+
describe('the pane separates its blocks with a full-width rule', () => {
|
|
290
|
+
const WIDTH = 40;
|
|
291
|
+
const RULE = '─'.repeat(WIDTH);
|
|
292
|
+
|
|
293
|
+
function painted(pullRequest, comments, options = {}) {
|
|
294
|
+
const calls = [];
|
|
295
|
+
const paint = (role, text) => {
|
|
296
|
+
calls.push({ role, text: String(text) });
|
|
297
|
+
return String(text);
|
|
298
|
+
};
|
|
299
|
+
const lines = pullRequestDetailLines(pullRequest, comments, {
|
|
300
|
+
width: WIDTH,
|
|
301
|
+
paint,
|
|
302
|
+
emphasis: bold,
|
|
303
|
+
now: NOW,
|
|
304
|
+
...options,
|
|
305
|
+
});
|
|
306
|
+
return { lines, calls };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const ruleRows = (lines) => lines.reduce((found, line, at) => (line === RULE ? [...found, at] : found), []);
|
|
310
|
+
|
|
311
|
+
test('the metadata block, the body and each comment are separated by one rule', () => {
|
|
312
|
+
const { lines, calls } = painted(FULL, [
|
|
313
|
+
{ author: 'ana', body: 'first comment', createdAt: '2026-02-28T00:00:00.000Z' },
|
|
314
|
+
{ author: 'beto', body: 'second comment', createdAt: '2026-02-28T12:00:00.000Z' },
|
|
315
|
+
]);
|
|
316
|
+
const at = (needle) => {
|
|
317
|
+
const index = lines.findIndex((line) => line.includes(needle));
|
|
318
|
+
assert.notEqual(index, -1, `not painted: ${needle}`);
|
|
319
|
+
return index;
|
|
320
|
+
};
|
|
321
|
+
assert.equal(lines[0], '#87 parity title', 'no rule before the first row');
|
|
322
|
+
assert.equal(lines.at(-1), '(end of pull request)', 'no rule after the last row');
|
|
323
|
+
assert.equal(lines[at('the body') - 1], RULE, 'the metadata block and the body are separated');
|
|
324
|
+
assert.equal(lines[at('─ ana') - 1], RULE, 'the body and the comments are separated');
|
|
325
|
+
assert.equal(lines[at('─ beto') - 1], RULE, 'each comment is separated from the next');
|
|
326
|
+
assert.deepEqual(ruleRows(lines), [at('the body') - 1, at('─ ana') - 1, at('─ beto') - 1],
|
|
327
|
+
'exactly those three rows carry a rule and no two rules are adjacent');
|
|
328
|
+
// The two summaries belong to the metadata block, so no rule splits them.
|
|
329
|
+
assert.ok(at('Changes') < ruleRows(lines)[0], 'Changes stays inside the metadata block');
|
|
330
|
+
assert.ok(at('Checks') < ruleRows(lines)[0], 'Checks stays inside the metadata block');
|
|
331
|
+
assert.ok(at('failing: build') < ruleRows(lines)[0], 'the last summary row stays above the rule');
|
|
332
|
+
const paintedRules = calls.filter((call) => call.text === RULE);
|
|
333
|
+
assert.equal(paintedRules.length, 3, 'each rule is painted through the caller seam');
|
|
334
|
+
assert.ok(paintedRules.every((call) => call.role === 'muted'), 'the rule takes the muted role');
|
|
335
|
+
assert.equal([...RULE].length, WIDTH, 'the rule spans the whole pane');
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('a comment-free pull request draws only the rule before the body', () => {
|
|
339
|
+
const { lines } = painted({ ...FULL, body: '' }, []);
|
|
340
|
+
const body = lines.indexOf('(no description)');
|
|
341
|
+
assert.notEqual(body, -1, 'the placeholder is still the body block');
|
|
342
|
+
assert.deepEqual(ruleRows(lines), [body - 1], 'nothing separates a body from no comments');
|
|
343
|
+
assert.equal(lines.at(-1), '(end of pull request)');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test('a pull request with neither summary block still draws that one rule', () => {
|
|
347
|
+
const bare = {
|
|
348
|
+
number: 5,
|
|
349
|
+
title: 'bare',
|
|
350
|
+
additions: undefined,
|
|
351
|
+
deletions: undefined,
|
|
352
|
+
changedFiles: undefined,
|
|
353
|
+
commits: undefined,
|
|
354
|
+
committedAt: undefined,
|
|
355
|
+
checks: undefined,
|
|
356
|
+
body: '',
|
|
357
|
+
};
|
|
358
|
+
const { lines } = painted(bare, []);
|
|
359
|
+
assert.deepEqual(ruleRows(lines), [lines.indexOf('(no description)') - 1],
|
|
360
|
+
'the absent summaries add no pair of rules');
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test('a pending read separates nothing it has not painted', () => {
|
|
364
|
+
const { lines } = painted({ number: 12, title: 'pending read' }, [], { pending: true });
|
|
365
|
+
assert.ok(!lines.includes(RULE), 'a pane with no body and no comments draws no rule');
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test('the rule is exactly the pane width at any width', () => {
|
|
369
|
+
for (const width of [12, 40, 121]) {
|
|
370
|
+
const rule = '─'.repeat(width);
|
|
371
|
+
const lines = linesOf(FULL, [], { width });
|
|
372
|
+
assert.deepEqual(lines.reduce((found, line, at) => (line === rule ? [...found, at] : found), []),
|
|
373
|
+
[lines.indexOf('the body') - 1], `one full-width rule at ${width}`);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// The hover highlight paints the linked issue the pointer is over, through the
|
|
379
|
+
// same role the rail uses for a hovered row, and changes nothing about the
|
|
380
|
+
// published click geometry.
|
|
381
|
+
describe('the hovered linked issue is the one painted as the target', () => {
|
|
382
|
+
function paintedCalls(hover) {
|
|
383
|
+
const calls = [];
|
|
384
|
+
const links = [];
|
|
385
|
+
const paint = (role, text) => {
|
|
386
|
+
calls.push({ role, text: String(text) });
|
|
387
|
+
return String(text);
|
|
388
|
+
};
|
|
389
|
+
const lines = pullRequestDetailLines(FULL, [], {
|
|
390
|
+
width: 80,
|
|
391
|
+
paint,
|
|
392
|
+
emphasis: bold,
|
|
393
|
+
now: NOW,
|
|
394
|
+
links,
|
|
395
|
+
hover,
|
|
396
|
+
});
|
|
397
|
+
return { calls, lines, links };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
test('only the hovered number takes the hover role', () => {
|
|
401
|
+
const { calls, lines } = paintedCalls(14);
|
|
402
|
+
const targets = calls.filter((call) => call.role === 'accent' && call.text.startsWith('#')).map((call) => call.text);
|
|
403
|
+
assert.deepEqual(targets, ['#14'], 'exactly the hovered number is painted as the target');
|
|
404
|
+
assert.match(lines.find((line) => line.includes('linked issues:')), /#12, #14/,
|
|
405
|
+
'the painted row still carries both numbers');
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test('no hover paints no target, and the click geometry is identical either way', () => {
|
|
409
|
+
const hovered = paintedCalls(14);
|
|
410
|
+
const plainRun = paintedCalls(null);
|
|
411
|
+
assert.ok(!plainRun.calls.some((call) => call.role === 'accent' && call.text.startsWith('#')),
|
|
412
|
+
'without hover no number takes the switch role');
|
|
413
|
+
assert.deepEqual(hovered.links, plainRun.links, 'hover never moves a click range');
|
|
414
|
+
});
|
|
415
|
+
});
|
|
@@ -652,6 +652,32 @@ describe('/prs overlay and reads (S1, S3)', () => {
|
|
|
652
652
|
assert.equal(b.gh.calls[b.gh.calls.length - 1].repo, 'github.com/myfork/project', 'the pinned identity binds the page');
|
|
653
653
|
});
|
|
654
654
|
|
|
655
|
+
test('S8/T22: the rail cache seeds the first frame, so /prs opens as fast as /issues', async () => {
|
|
656
|
+
const b = await boot({ railMine: [{ number: 69, title: 'mine sixty-nine' }], railReview: [{ number: 70, title: 'review seventy' }] });
|
|
657
|
+
const { registered } = installBridge();
|
|
658
|
+
await warmGate(b.loaded);
|
|
659
|
+
const root = makeCheckout();
|
|
660
|
+
const ctx = sessionCtx(root);
|
|
661
|
+
// The first start publishes the surface; the second is the session whose rail
|
|
662
|
+
// reads, which is the in-memory entry `/prs` seeds from. Nothing is opened in
|
|
663
|
+
// between, so this is exactly the state a click on the rail finds.
|
|
664
|
+
await fireSessionStart(b.loaded.hooks, sessionCtx(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-prs-seed-')))));
|
|
665
|
+
await fireSessionStart(b.loaded.hooks, ctx);
|
|
666
|
+
await drawSection(registered[0], ctx);
|
|
667
|
+
await waitFor(() => String(registered[0].meta(ctx)).includes(' pr'));
|
|
668
|
+
|
|
669
|
+
const capture = captureView(b.loaded.mod, 'prs-view.js', 'createPrsView');
|
|
670
|
+
await mountCommand(b.loaded, 'prs', '', ctx, { capture });
|
|
671
|
+
|
|
672
|
+
const pages = capture.options.pages;
|
|
673
|
+
const mine = pages.find((page) => page.id === 'mine');
|
|
674
|
+
const review = pages.find((page) => page.id === 'review');
|
|
675
|
+
assert.deepEqual(mine.rows.map((row) => row.number), [69], 'the authored bucket paints the rail row it already read');
|
|
676
|
+
assert.deepEqual(review.rows.map((row) => row.number), [70], 'and so does the review bucket');
|
|
677
|
+
assert.equal(mine.total, 1, 'the seeded page carries the count it can prove');
|
|
678
|
+
assert.equal(pages.find((page) => page.id === 'involved').rows, null, 'a bucket the rail never read keeps its own read');
|
|
679
|
+
});
|
|
680
|
+
|
|
655
681
|
test('the lazy all bucket reads the repository connection', async () => {
|
|
656
682
|
installBridge();
|
|
657
683
|
const b = await boot();
|
|
@@ -686,6 +712,29 @@ describe('/prs overlay and reads (S1, S3)', () => {
|
|
|
686
712
|
assert.equal(view.repo, 'github.com/myfork/project');
|
|
687
713
|
});
|
|
688
714
|
|
|
715
|
+
test('T20: the linked-issues candidate seam asks the pinned repository\'s open issues', async () => {
|
|
716
|
+
installBridge();
|
|
717
|
+
const b = await boot();
|
|
718
|
+
await warmGate(b.loaded);
|
|
719
|
+
const root = makeCheckout();
|
|
720
|
+
const capture = captureView(b.loaded.mod, 'prs-view.js', 'createPrsView');
|
|
721
|
+
const { ctx } = makeCtx(root);
|
|
722
|
+
await mountCommand(b.loaded, 'prs', '', ctx, { capture });
|
|
723
|
+
assert.equal(typeof capture.options.loadIssueCandidates, 'function', 'the view is wired to a candidate seam');
|
|
724
|
+
const page = await capture.options.loadIssueCandidates({ after: null, pageSize: 2 });
|
|
725
|
+
assert.equal(page.ok, true);
|
|
726
|
+
assert.deepEqual(page.rows, [
|
|
727
|
+
{ number: 1, title: 'One', state: 'open' },
|
|
728
|
+
{ number: 2, title: 'Two', state: 'open' },
|
|
729
|
+
]);
|
|
730
|
+
const call = b.gh.calls[b.gh.calls.length - 1];
|
|
731
|
+
const search = gqlField(call.argv, 'search');
|
|
732
|
+
assert.ok(search.includes('repo:myfork/project'), `the read is scoped to the pinned repository (saw ${search})`);
|
|
733
|
+
assert.ok(search.includes('is:issue') && search.includes('is:open'), 'only open issues are candidates');
|
|
734
|
+
assert.ok(search.includes('sort:updated-desc'), 'the list is hottest-updated first');
|
|
735
|
+
assert.equal(call.repo, 'github.com/myfork/project', 'the pinned identity binds the read');
|
|
736
|
+
});
|
|
737
|
+
|
|
689
738
|
test('the o opener runs gh pr view <n> --web -R <pinned>', async () => {
|
|
690
739
|
installBridge();
|
|
691
740
|
const b = await boot();
|