pi-odd-worktree 3.9.1 → 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.
Files changed (41) hide show
  1. package/README.md +63 -40
  2. package/extensions/odd-worktree-tools.ts +859 -12
  3. package/lib/gh-issues.js +65 -10
  4. package/lib/gh-prs.js +2011 -0
  5. package/lib/issue-preview.js +70 -4
  6. package/lib/issues-cache-store.js +4 -1
  7. package/lib/issues-section.js +346 -23
  8. package/lib/issues-view.js +116 -5
  9. package/lib/modules.js +5 -0
  10. package/lib/pr-preview.js +353 -0
  11. package/lib/prs-rail-store.js +317 -0
  12. package/lib/prs-view.js +2896 -0
  13. package/package.json +1 -1
  14. package/tools/files-bridge.test.js +2 -2
  15. package/tools/files-command.test.js +1 -1
  16. package/tools/fixtures/gh-pr-connection-page.json +84 -0
  17. package/tools/fixtures/gh-pr-metadata.json +29 -0
  18. package/tools/fixtures/gh-pr-rail.json +61 -0
  19. package/tools/fixtures/gh-pr-search-page.json +82 -0
  20. package/tools/fixtures/gh-pr-view.json +159 -0
  21. package/tools/gh-issues.test.js +4 -2
  22. package/tools/gh-prs.test.js +1828 -0
  23. package/tools/issue-preview.test.js +119 -0
  24. package/tools/issues-cache-store.test.js +2 -2
  25. package/tools/issues-command.test.js +10 -3
  26. package/tools/issues-open-guard.test.js +15 -0
  27. package/tools/issues-section.test.js +618 -9
  28. package/tools/issues-view.test.js +297 -0
  29. package/tools/modules-wiring.test.js +5 -0
  30. package/tools/package-surface.test.js +18 -4
  31. package/tools/pr-preview.test.js +281 -0
  32. package/tools/prs-command.test.js +1280 -0
  33. package/tools/prs-rail-store.test.js +343 -0
  34. package/tools/prs-t10-safety.test.js +326 -0
  35. package/tools/prs-t12-safety.test.js +348 -0
  36. package/tools/prs-t13-independent.test.js +378 -0
  37. package/tools/prs-t14-safety.test.js +340 -0
  38. package/tools/prs-t15-independent.test.js +259 -0
  39. package/tools/prs-t18-safety.test.js +217 -0
  40. package/tools/prs-t7-safety.test.js +127 -0
  41. package/tools/prs-view.test.js +1462 -0
@@ -251,3 +251,122 @@ describe('the preview title follows the shared palette (S13)', () => {
251
251
  'a ready read paints no pending word');
252
252
  });
253
253
  });
254
+
255
+ // S6 (prs cross-links): the pane's `linked PRs:` row is a set of INDEPENDENT
256
+ // click ranges the caller owns. The formatter reports each number it printed
257
+ // with the row it landed on (wrapping included) and its own plain columns, so a
258
+ // click can never open the whole line, a separator, or the truncation ellipsis.
259
+ // The collector is optional: without it the returned rows are byte for byte the
260
+ // ones this preview always produced.
261
+ describe('linked PR click ranges (S6)', () => {
262
+ function rangesOf(detail, options = {}) {
263
+ const ranges = [];
264
+ const lines = issueDetailLines(detail, [], {
265
+ width: 80,
266
+ paint: plain,
267
+ emphasis: bold,
268
+ now: NOW,
269
+ ranges,
270
+ ...options,
271
+ });
272
+ return { lines, ranges };
273
+ }
274
+
275
+ test('each linked PR number is one range, on the row that carries it', () => {
276
+ const { lines, ranges } = rangesOf(FULL);
277
+ assert.deepEqual(ranges.map((range) => range.number), [69, 77], 'every number, in print order');
278
+ assert.ok(ranges.every((range) => range.kind === 'pullRequest'), 'the range names the relation it opens');
279
+ for (const range of ranges) {
280
+ assert.equal(lines[range.line].slice(range.start, range.end), `#${range.number}`,
281
+ `the range covers exactly #${range.number} and nothing else`);
282
+ }
283
+ assert.equal(ranges[0].line, ranges[1].line, 'the wide pane prints both numbers on their one row');
284
+ });
285
+
286
+ test('the truncation ellipsis is not a range', () => {
287
+ const { lines, ranges } = rangesOf({
288
+ ...FULL,
289
+ linkedPullRequests: [69],
290
+ linkedPullRequestsTruncated: true,
291
+ });
292
+ assert.deepEqual(ranges.map((range) => range.number), [69], 'only the number is clickable');
293
+ const row = lines[ranges[0].line];
294
+ assert.match(row, /, …$/, 'the capped page still ends with the ellipsis');
295
+ assert.ok(ranges.every((range) => !row.slice(range.start, range.end).includes('…')), 'the ellipsis carries no range');
296
+ });
297
+
298
+ test('a wrapped row keeps each range on the row its own number landed on', () => {
299
+ const { lines, ranges } = rangesOf(FULL, { width: 6 });
300
+ assert.equal(ranges.length, 2);
301
+ assert.notEqual(ranges[0].line, ranges[1].line, 'the narrow pane wraps the two numbers onto two rows');
302
+ for (const range of ranges) {
303
+ assert.equal(lines[range.line].slice(range.start, range.end), `#${range.number}`,
304
+ `#${range.number} is range-mapped on the row it was printed on`);
305
+ }
306
+ });
307
+
308
+ test('the body, the title and a pending read carry no range', () => {
309
+ const withBody = rangesOf({ ...FULL, title: '#69 title', body: 'linked PRs: #69, #77' });
310
+ assert.deepEqual(withBody.ranges.map((range) => range.number), [69, 77],
311
+ 'only the linked row produces ranges, never the title or the body text');
312
+ assert.ok(
313
+ withBody.ranges.every((range) => withBody.lines[range.line].startsWith('linked PRs:')),
314
+ 'every range lives on the one relation row',
315
+ );
316
+ const pending = rangesOf(FULL, { pending: true });
317
+ assert.deepEqual(pending.ranges, [], 'a pending read has not painted the relation row yet');
318
+ });
319
+
320
+ test('a caller that passes no collector gets exactly the rows it always did', () => {
321
+ const collected = rangesOf(FULL);
322
+ const plainRows = issueDetailLines(FULL, [], { width: 80, paint: plain, emphasis: bold, now: NOW });
323
+ assert.deepEqual(collected.lines, plainRows, 'the collector changes nothing about the painted rows');
324
+ });
325
+ });
326
+
327
+ // S6/D29: a linked pull request is identified by REPOSITORY and number. One of
328
+ // another repository is painted with the repository it belongs to — never as a
329
+ // bare `#N` that would read as this repository's number — and it owns no click
330
+ // range, because this panel cannot open a pull request it has no identity for.
331
+ describe('a linked PR of another repository (D29)', () => {
332
+ function rangesOf(detail, options = {}) {
333
+ const ranges = [];
334
+ const lines = issueDetailLines(detail, [], {
335
+ width: 80,
336
+ paint: plain,
337
+ emphasis: bold,
338
+ now: NOW,
339
+ ranges,
340
+ ...options,
341
+ });
342
+ return { lines, ranges };
343
+ }
344
+
345
+ test('renders as plain owner/repo#N and owns no click range', () => {
346
+ const { lines, ranges } = rangesOf({
347
+ ...FULL,
348
+ linkedPullRequests: [69],
349
+ linkedPullRequestsForeign: [{ repository: 'oak/payroll', number: 381 }],
350
+ });
351
+ const row = lines.find((line) => line.includes('linked PRs:'));
352
+ assert.ok(row, 'the relation row is painted');
353
+ assert.equal(row.trim(), 'linked PRs: #69, oak/payroll#381',
354
+ 'the foreign link names its repository, so it cannot read as this one');
355
+ assert.deepEqual(ranges.map((range) => range.number), [69], 'only the same-repository number is a target');
356
+ });
357
+
358
+ test('a foreign link with the same number as a linked one is still not a target', () => {
359
+ const { ranges } = rangesOf({
360
+ ...FULL,
361
+ linkedPullRequests: [69],
362
+ linkedPullRequestsForeign: [{ repository: 'oak/payroll', number: 69 }],
363
+ });
364
+ assert.equal(ranges.length, 1, 'the bare #69 is the only range');
365
+ assert.equal(ranges[0].number, 69);
366
+ });
367
+
368
+ test('an absent foreign list paints nothing extra', () => {
369
+ const text = render(FULL, []);
370
+ assert.match(text, /linked PRs: #69, #77/);
371
+ });
372
+ });
@@ -94,7 +94,7 @@ test('S4: an entry round-trips through ONE small versioned document', async () =
94
94
 
95
95
  assert.deepEqual(fs.readdirSync(dir), [FILE], 'exactly one document, no stray file');
96
96
  const doc = documentAt(dir);
97
- assert.equal(doc.version, 1, 'the document is versioned');
97
+ assert.equal(doc.version, 2, 'the document is versioned');
98
98
  assert.equal(doc.identities.length, 1);
99
99
  assert.equal(doc.identities[0].identity, IDENTITY, 'the entry is keyed by the repository identity');
100
100
  });
@@ -166,7 +166,7 @@ test('S4: a wrong version is silence, and the next save writes the current one',
166
166
  const cache = store(dir);
167
167
  assert.equal(await cache.load(IDENTITY), null, 'a version this module does not know is never read');
168
168
  assert.equal(await cache.save(IDENTITY, snapshot()), true);
169
- assert.equal(documentAt(dir).version, 1);
169
+ assert.equal(documentAt(dir).version, 2);
170
170
  });
171
171
 
172
172
  test('S4: a hostile entry is dropped and every other identity still answers', async () => {
@@ -52,6 +52,13 @@ after(() => {
52
52
  }
53
53
  });
54
54
 
55
+
56
+ // The header may also carry the rail's pull-request segment (`· M pr`), which this
57
+ // suite does not read: only the issues number and the `· stale` mark are asserted.
58
+ function issuesCount(text) {
59
+ return String(text).replace(/ · \d+ pr/, '');
60
+ }
61
+
55
62
  function track(dir) {
56
63
  roots.push(dir);
57
64
  return dir;
@@ -2595,7 +2602,7 @@ describe('/issues reflects a self-assignment on the panel and the rail (S21/T17)
2595
2602
  const root = makeRepo({ tag: 'issues-self-assign' });
2596
2603
  const state = repoState();
2597
2604
  const { loaded, gh, section, ctx } = await warmRail(root, state);
2598
- assert.equal(section.meta(ctx), '2 issues', 'the rail starts with both rows');
2605
+ assert.equal(issuesCount(section.meta(ctx)), '2 issues', 'the rail starts with both rows');
2599
2606
 
2600
2607
  const { component } = await mountPanel(loaded, root);
2601
2608
  // `Assigned` is where the viewer's own row lives; the tab reads it on entry.
@@ -2633,7 +2640,7 @@ describe('/issues reflects a self-assignment on the panel and the rail (S21/T17)
2633
2640
  assert.ok(await waitFor(() => railReads(gh).length >= 2), 'the write started a rail read of its own');
2634
2641
  assert.match(railQuery(railReads(gh)[1]), /first: 100/,
2635
2642
  'the dropped entry makes the next rail read the full size, so a removal can land');
2636
- assert.ok(await waitFor(() => section.meta(ctx) === '1 issues'), 'the rail count follows the removal');
2643
+ assert.ok(await waitFor(() => issuesCount(section.meta(ctx)) === '1 issues'), 'the rail count follows the removal');
2637
2644
  assert.deepEqual(section.lines(ctx).map((row) => row.label), ['#12 Mine twelve'],
2638
2645
  'and the merged rows are the ones the full read answered');
2639
2646
  });
@@ -2660,7 +2667,7 @@ describe('/issues reflects a self-assignment on the panel and the rail (S21/T17)
2660
2667
  await tick();
2661
2668
  assert.equal(component.state.mode, 'assignees', 'the editor keeps the draft');
2662
2669
  assert.equal(railReads(gh).length, before, 'a failed write invalidates nothing, so no rail read starts');
2663
- assert.equal(section.meta(ctx), '2 issues', 'the rail keeps the pre-write count');
2670
+ assert.equal(issuesCount(section.meta(ctx)), '2 issues', 'the rail keeps the pre-write count');
2664
2671
  assert.match(frameOf(component), /Assigned \(1\)/, 'and the panel keeps the pre-write count');
2665
2672
  assert.ok(frameOf(component).includes('Assigned twenty-one'), 'the row never left');
2666
2673
  });
@@ -338,6 +338,20 @@ async function waitForRows(section, ctx) {
338
338
  throw new Error('the section never left loading');
339
339
  }
340
340
 
341
+ // T5 (prs): the rail's SECOND read — the pull-request count — starts as soon as
342
+ // the issues read proves the repository, so a test that snapshots the children
343
+ // before a click must let that background read settle first. It is the RAIL's
344
+ // read, not the open's, and it would otherwise land inside the window a click
345
+ // measures (a single-remote checkout resolves its identity with `gh repo view`).
346
+ async function waitForBackgroundReads(calls, quietMs = 100) {
347
+ let last = -1;
348
+ for (let round = 0; round < 40; round += 1) {
349
+ if (calls.length === last) return;
350
+ last = calls.length;
351
+ await new Promise((resolve) => realSetTimeout(resolve, quietMs));
352
+ }
353
+ }
354
+
341
355
  // `draw: false` runs the session in a SECOND checkout: the startup `gh` probe
342
356
  // warms nothing in the fixture checkout under test, so a numbered open there meets
343
357
  // a COLD scope cache and has to prove the identity — the pattern the command tests
@@ -367,6 +381,7 @@ async function harness({
367
381
  await fireSessionStart(loaded.hooks, ctx);
368
382
  const section = registered[0];
369
383
  const rows = draw && section ? await waitForRows(section, ctx) : [];
384
+ if (draw && section) await waitForBackgroundReads(gh.calls);
370
385
  return { checkout, loaded, gh, identity, registered, section, rows, sent, notices, repaints, ctx };
371
386
  }
372
387