pi-odd-worktree 3.11.1 → 3.12.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 +6 -4
- package/extensions/odd-worktree-tools.ts +1205 -40
- package/lib/odd-group.js +655 -0
- package/lib/odd-listing.js +349 -0
- package/lib/odd-rail-model.js +150 -0
- package/lib/odd-rail-section.js +453 -0
- package/lib/odd-session.js +231 -0
- package/lib/odd-view.js +500 -46
- package/lib/user-prompt-card.js +68 -10
- package/package.json +1 -1
- package/tools/commands.test.js +58 -0
- package/tools/issues-command.test.js +13 -2
- package/tools/issues-open-guard.test.js +7 -1
- package/tools/issues-section.test.js +11 -2
- package/tools/odd-group.test.js +950 -0
- package/tools/odd-listing.test.js +504 -0
- package/tools/odd-panel-wiring.test.js +1868 -0
- package/tools/odd-rail-model.test.js +184 -0
- package/tools/odd-rail-section.test.js +524 -0
- package/tools/odd-rail-wiring.test.js +572 -0
- package/tools/odd-session-wiring.test.js +419 -0
- package/tools/odd-session.test.js +282 -0
- package/tools/odd-view.test.js +407 -1
- package/tools/package-surface.test.js +22 -6
- package/tools/prs-command.test.js +1 -1
- package/tools/user-prompt-card.test.js +173 -6
package/tools/odd-view.test.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
const { test, describe } = require('node:test');
|
|
14
14
|
const assert = require('node:assert/strict');
|
|
15
15
|
|
|
16
|
-
const { createOddView } = require('../lib/odd-view.js');
|
|
16
|
+
const { createOddView, RELOAD_SUPERSEDED } = require('../lib/odd-view.js');
|
|
17
17
|
const layout = require('../lib/view-layout.js');
|
|
18
18
|
|
|
19
19
|
function strip(value) {
|
|
@@ -2139,6 +2139,31 @@ describe('createOddView shortcut round (S8,S9,S10)', () => {
|
|
|
2139
2139
|
assert.match(footerOf(lines), /(^|· )r failed( ·|$)/, `the failure is named in the footer: ${footerOf(lines)}`);
|
|
2140
2140
|
});
|
|
2141
2141
|
|
|
2142
|
+
// D2 (T6): a reload seam may answer RELOAD_SUPERSEDED for a request a later one
|
|
2143
|
+
// has already replaced. That answer must be INERT — the frame, the reading
|
|
2144
|
+
// position and the footer token stay exactly as the reader left them — and it is
|
|
2145
|
+
// never a failure, because nothing was read: the answer belongs to a request the
|
|
2146
|
+
// panel is no longer showing.
|
|
2147
|
+
test('D2: a superseded reload answer changes nothing at all', async () => {
|
|
2148
|
+
let answer = () => ({ ok: true, docs: [doc('alpha'), doc('beta')] });
|
|
2149
|
+
const view = build({ reloadDocs: () => answer() });
|
|
2150
|
+
await tick();
|
|
2151
|
+
view.handleInput('end');
|
|
2152
|
+
const before = view.render(80);
|
|
2153
|
+
const scroll = view.state.scroll;
|
|
2154
|
+
assert.ok(scroll > 0, 'the premise: the reading position is scrolled');
|
|
2155
|
+
assert.match(footerOf(before), /(^|· )r( ·|$)/, 'the premise: the footer still offers the plain r');
|
|
2156
|
+
|
|
2157
|
+
answer = () => RELOAD_SUPERSEDED;
|
|
2158
|
+
view.handleInput('r');
|
|
2159
|
+
await tick();
|
|
2160
|
+
|
|
2161
|
+
const after = view.render(80);
|
|
2162
|
+
assert.equal(view.state.scroll, scroll, 'the reading position does not move');
|
|
2163
|
+
assert.deepEqual(after, before, 'the frame is byte-identical');
|
|
2164
|
+
assert.equal(footerOf(after), footerOf(before), 'not even the reload token changes');
|
|
2165
|
+
});
|
|
2166
|
+
|
|
2142
2167
|
// S9 at the reported width: the reader who saw `r` in the compact legend and
|
|
2143
2168
|
// then reloaded is on a ~60-column terminal. The idle token fits there, so the
|
|
2144
2169
|
// outcome must fit too instead of being pruned away as if nothing happened.
|
|
@@ -2326,3 +2351,384 @@ describe('createOddView two-step listing (S21)', () => {
|
|
|
2326
2351
|
assert.equal(closed, null, 'esc still closes the view');
|
|
2327
2352
|
});
|
|
2328
2353
|
});
|
|
2354
|
+
|
|
2355
|
+
// S6: a sidebar row clicks into the viewer, so the panel can be OPENED on one
|
|
2356
|
+
// requested document instead of always on the newest one. The request is a
|
|
2357
|
+
// STRING: an absolute `path` first (the document may live in ANY checkout), then
|
|
2358
|
+
// the name the list paints, and today's first-document open when nothing matches.
|
|
2359
|
+
describe('createOddView positional open (S6)', () => {
|
|
2360
|
+
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
2361
|
+
const listCells = (lines) => lines.slice(2, -2).map((line) => strip(line).split('│')[1] || '');
|
|
2362
|
+
const filled = (lines) => listCells(lines).filter((cell) => cell.trim() !== '');
|
|
2363
|
+
const rowName = (cell) => cell.trim().replace(/^▸\s*/, '');
|
|
2364
|
+
const focusedName = (lines) => {
|
|
2365
|
+
const cell = filled(lines).find((entry) => entry.includes('▸'));
|
|
2366
|
+
return cell === undefined ? null : rowName(cell);
|
|
2367
|
+
};
|
|
2368
|
+
const bodyOf = (lines) => strip(lines.join('\n'));
|
|
2369
|
+
|
|
2370
|
+
// These documents do not all live in one checkout: the viewer is handed a
|
|
2371
|
+
// path from somebody else's worktree, which is the shape the rail produces.
|
|
2372
|
+
const docs = [
|
|
2373
|
+
doc('alpha'),
|
|
2374
|
+
{ name: 'bravo', file: 'bravo.md', path: '/other-worktree/odd/tasks/bravo.md' },
|
|
2375
|
+
doc('charlie'),
|
|
2376
|
+
];
|
|
2377
|
+
|
|
2378
|
+
function build({ initialDoc } = {}) {
|
|
2379
|
+
const reads = [];
|
|
2380
|
+
const options = {
|
|
2381
|
+
docs,
|
|
2382
|
+
loadDoc: (entry) => {
|
|
2383
|
+
reads.push(entry.path || entry.name);
|
|
2384
|
+
return { ok: true, text: `# ${entry.name}\n\nbody of ${entry.name}\n` };
|
|
2385
|
+
},
|
|
2386
|
+
helpers,
|
|
2387
|
+
theme: plainTheme,
|
|
2388
|
+
rowsAvailable: () => 20,
|
|
2389
|
+
requestRender: () => {},
|
|
2390
|
+
done: () => {},
|
|
2391
|
+
};
|
|
2392
|
+
if (initialDoc !== undefined) options.initialDoc = initialDoc;
|
|
2393
|
+
const view = createOddView(options);
|
|
2394
|
+
return { view, reads };
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
test('opens on the document whose absolute path is requested, loaded before any key press', async () => {
|
|
2398
|
+
const { view, reads } = build({ initialDoc: '/other-worktree/odd/tasks/bravo.md' });
|
|
2399
|
+
// The body is read while the view is mounted, not on the first render.
|
|
2400
|
+
assert.deepEqual(reads, ['/other-worktree/odd/tasks/bravo.md'], 'the requested document is the one loaded on open');
|
|
2401
|
+
await tick();
|
|
2402
|
+
assert.equal(view.state.index, 1, 'the selection starts on the requested document');
|
|
2403
|
+
const lines = view.render(80);
|
|
2404
|
+
assert.equal(focusedName(lines), 'bravo', 'the highlight is on the requested document row');
|
|
2405
|
+
assert.match(bodyOf(lines), /body of bravo/, 'the right pane starts on the requested document');
|
|
2406
|
+
assert.equal(view.state.scroll, 0, 'and at the top of it');
|
|
2407
|
+
});
|
|
2408
|
+
|
|
2409
|
+
test('falls back to the document name when no path matches the request', async () => {
|
|
2410
|
+
const { view, reads } = build({ initialDoc: 'charlie' });
|
|
2411
|
+
assert.deepEqual(reads, ['/checkout/odd/tasks/charlie.md'], 'the named document is the one loaded on open');
|
|
2412
|
+
await tick();
|
|
2413
|
+
assert.equal(view.state.index, 2, 'the selection starts on the named document');
|
|
2414
|
+
const lines = view.render(80);
|
|
2415
|
+
assert.equal(focusedName(lines), 'charlie', 'the highlight is on the named row');
|
|
2416
|
+
assert.match(bodyOf(lines), /body of charlie/, 'the right pane shows the named document');
|
|
2417
|
+
});
|
|
2418
|
+
|
|
2419
|
+
test('an unknown request opens on the first document, exactly like no request at all', async () => {
|
|
2420
|
+
const requested = build({ initialDoc: '/somewhere/else/odd/tasks/november.md' });
|
|
2421
|
+
const plain = build();
|
|
2422
|
+
assert.deepEqual(requested.reads, plain.reads, 'the same document is loaded on open');
|
|
2423
|
+
await tick();
|
|
2424
|
+
assert.equal(requested.view.state.index, 0, 'an unknown request selects the first document');
|
|
2425
|
+
assert.equal(requested.view.state.index, plain.view.state.index, 'the same index as today');
|
|
2426
|
+
const lines = requested.view.render(80);
|
|
2427
|
+
assert.equal(focusedName(lines), 'alpha', 'the highlight is on the first row');
|
|
2428
|
+
assert.match(bodyOf(lines), /body of alpha/, 'the right pane shows the first document');
|
|
2429
|
+
assert.equal(requested.view.state.scroll, 0);
|
|
2430
|
+
});
|
|
2431
|
+
|
|
2432
|
+
test('no initialDoc keeps today\'s open: the first document, at the top, highlighted first', async () => {
|
|
2433
|
+
const { view, reads } = build();
|
|
2434
|
+
assert.deepEqual(reads, ['/checkout/odd/tasks/alpha.md'], 'the first document is still the one loaded on open');
|
|
2435
|
+
await tick();
|
|
2436
|
+
assert.equal(view.state.index, 0, 'the selection is still the first document');
|
|
2437
|
+
assert.equal(view.state.scroll, 0, 'the pane is still at the top');
|
|
2438
|
+
const lines = view.render(80);
|
|
2439
|
+
assert.deepEqual(filled(lines).map(rowName), ['alpha', 'bravo', 'charlie'], 'the list is unchanged');
|
|
2440
|
+
assert.equal(focusedName(lines), 'alpha', 'the highlight is still on the first row');
|
|
2441
|
+
assert.match(bodyOf(lines), /body of alpha/, 'the right pane still starts on the first document');
|
|
2442
|
+
// Byte-identical to the same view opened with an explicitly empty request.
|
|
2443
|
+
const empty = build({ initialDoc: '' });
|
|
2444
|
+
await tick();
|
|
2445
|
+
assert.deepEqual(empty.view.render(80), lines, 'an empty request paints the very same frame');
|
|
2446
|
+
});
|
|
2447
|
+
});
|
|
2448
|
+
|
|
2449
|
+
// ---------------------------------------------------------------------------
|
|
2450
|
+
// T9 (S10,S11,S13): the panel groups its documents by checkout, like the
|
|
2451
|
+
// gentle-shell CHANGES panel. The loader hands it `groups` — one entry per
|
|
2452
|
+
// checkout, each carrying the documents that checkout owns — and the view
|
|
2453
|
+
// paints a header row per checkout followed by its documents. The main group is
|
|
2454
|
+
// always drawn; a worktree group is drawn ONLY when it has documents, and when
|
|
2455
|
+
// every worktree group is empty the panel is the ordinary main-only flat listing
|
|
2456
|
+
// with no header at all (S13: never an empty worktree group, never group chrome
|
|
2457
|
+
// that says nothing). A header is focusable: Enter toggles it. `a` flips the
|
|
2458
|
+
// listing between the session's checkouts and every worktree, and the CALLER
|
|
2459
|
+
// reloads the groups when it does.
|
|
2460
|
+
// ---------------------------------------------------------------------------
|
|
2461
|
+
describe('createOddView grouped listing (T9: S10,S11,S13)', () => {
|
|
2462
|
+
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
2463
|
+
// The grouped model names a document's absolute location `docPath`
|
|
2464
|
+
// (lib/odd-group.js); the older `path` spelling keeps working.
|
|
2465
|
+
const groupDoc = (name, root = '/wt/main') => ({ name, docPath: `${root}/odd/tasks/${name}.md`, mtimeMs: 1 });
|
|
2466
|
+
const checkout = (checkoutName, checkoutRoot, isMain, docs) => ({ checkoutName, checkoutRoot, isMain, docs });
|
|
2467
|
+
const MAIN = checkout('main', '/wt/main', true, [groupDoc('alpha'), groupDoc('bravo')]);
|
|
2468
|
+
const RAIL = checkout('odd-rail', '/wt/odd-rail', false, [groupDoc('delta', '/wt/odd-rail')]);
|
|
2469
|
+
const listCells = (lines) => lines.slice(2, -2).map((line) => strip(line).split('│')[1] || '');
|
|
2470
|
+
// The rows the list pane paints, with the focus cursor removed so a row reads
|
|
2471
|
+
// the same whether the cursor is on it or not.
|
|
2472
|
+
const rowsOf = (lines) => listCells(lines)
|
|
2473
|
+
.map((cell) => cell.trim().replace(/^▸\s*/, ''))
|
|
2474
|
+
.filter((cell) => cell !== '');
|
|
2475
|
+
const focusedRow = (lines) => {
|
|
2476
|
+
const cell = listCells(lines).map((value) => value.trim()).find((value) => value.startsWith('▸'));
|
|
2477
|
+
return cell === undefined ? null : cell.replace(/^▸\s*/, '');
|
|
2478
|
+
};
|
|
2479
|
+
const bodyOf = (lines) => strip(lines.join('\n'));
|
|
2480
|
+
const footerOf = (lines) => strip(lines[lines.length - 2]);
|
|
2481
|
+
|
|
2482
|
+
function build({ groups, docs, initialDoc, onToggleAll, rows = 14, load } = {}) {
|
|
2483
|
+
const options = {
|
|
2484
|
+
loadDoc: load || ((entry) => ({ ok: true, text: `# ${entry.name}\n\nbody of ${entry.name}\n` })),
|
|
2485
|
+
helpers,
|
|
2486
|
+
theme: plainTheme,
|
|
2487
|
+
rowsAvailable: () => rows,
|
|
2488
|
+
requestRender: () => {},
|
|
2489
|
+
done: () => {},
|
|
2490
|
+
};
|
|
2491
|
+
if (docs !== undefined) options.docs = docs;
|
|
2492
|
+
if (groups !== undefined) options.groups = groups;
|
|
2493
|
+
if (initialDoc !== undefined) options.initialDoc = initialDoc;
|
|
2494
|
+
if (onToggleAll !== undefined) options.onToggleAll = onToggleAll;
|
|
2495
|
+
return createOddView(options);
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
// The pinned contract: with NO `groups` the panel is exactly the viewer of
|
|
2499
|
+
// before this unit — one flat list from `docs`, the same order, the same keys
|
|
2500
|
+
// and the same first frame. The literal below was captured from the viewer
|
|
2501
|
+
// BEFORE grouping existed, so it proves the flat path did not move.
|
|
2502
|
+
const FLAT_FRAME = [
|
|
2503
|
+
'╭─ ✎ Odd · 2 documents ────────────────────────────────────────────────────────────────────────────╮',
|
|
2504
|
+
'│ › Search 3/3 │',
|
|
2505
|
+
'│ ▸ alpha │ ▌ alpha │',
|
|
2506
|
+
'│ beta │ │',
|
|
2507
|
+
'│ │ body of alpha │',
|
|
2508
|
+
'│ │ │',
|
|
2509
|
+
'│ │ │',
|
|
2510
|
+
'│ │ │',
|
|
2511
|
+
'│ │ │',
|
|
2512
|
+
'│ │ │',
|
|
2513
|
+
'│ │ │',
|
|
2514
|
+
'│ │ │',
|
|
2515
|
+
'│ ↑↓ select · ctrl+j/k scroll · s sort: recent · t search · r reload · o open · esc close │',
|
|
2516
|
+
'╰──────────────────────────────────────────────────────────────────────────────────────────────────╯',
|
|
2517
|
+
];
|
|
2518
|
+
|
|
2519
|
+
test('no groups still paints today\'s exact flat frame', async () => {
|
|
2520
|
+
const view = build({ docs: [doc('alpha'), doc('beta')] });
|
|
2521
|
+
await tick();
|
|
2522
|
+
assert.deepEqual(view.render(100), FLAT_FRAME, 'the flat listing is byte-identical to the pre-grouping frame');
|
|
2523
|
+
});
|
|
2524
|
+
|
|
2525
|
+
test('S13: every worktree group empty keeps the ordinary main-only listing, with no header at all', async () => {
|
|
2526
|
+
const flat = build({ docs: [doc('alpha'), doc('beta')] });
|
|
2527
|
+
const grouped = build({
|
|
2528
|
+
groups: [
|
|
2529
|
+
checkout('main', '/wt/main', true, [groupDoc('alpha'), groupDoc('beta')]),
|
|
2530
|
+
checkout('odd-fix', '/wt/odd-fix', false, []),
|
|
2531
|
+
],
|
|
2532
|
+
});
|
|
2533
|
+
await tick();
|
|
2534
|
+
const flatFrame = flat.render(100);
|
|
2535
|
+
const groupedFrame = grouped.render(100);
|
|
2536
|
+
assert.deepEqual(groupedFrame, flatFrame, 'the very same frame: no header, no group chrome');
|
|
2537
|
+
assert.ok(!bodyOf(groupedFrame).includes('odd-fix'), 'an empty worktree is never named');
|
|
2538
|
+
assert.ok(!bodyOf(groupedFrame).includes('▾'), 'and no header is painted');
|
|
2539
|
+
});
|
|
2540
|
+
|
|
2541
|
+
test('S10: a header row per checkout, in order, each followed by its own documents', async () => {
|
|
2542
|
+
const view = build({ groups: [MAIN, RAIL] });
|
|
2543
|
+
await tick();
|
|
2544
|
+
const lines = view.render(100);
|
|
2545
|
+
assert.deepEqual(rowsOf(lines), ['▾ main', 'alpha', 'bravo', '▾ odd-rail', 'delta'],
|
|
2546
|
+
'the main group, its documents, then the worktree group and its documents');
|
|
2547
|
+
assert.equal(focusedRow(lines), 'alpha', 'the first DOCUMENT is focused, not the header');
|
|
2548
|
+
assert.match(bodyOf(lines), /body of alpha/, 'and its document is the one painted');
|
|
2549
|
+
assert.match(bodyOf(lines), /✎ Odd · 3 documents/, 'the title counts the listed documents');
|
|
2550
|
+
});
|
|
2551
|
+
|
|
2552
|
+
test('S13: a worktree group with no documents of its own is dropped', async () => {
|
|
2553
|
+
const view = build({ groups: [MAIN, RAIL, checkout('odd-fix', '/wt/odd-fix', false, [])] });
|
|
2554
|
+
await tick();
|
|
2555
|
+
const lines = view.render(100);
|
|
2556
|
+
assert.deepEqual(rowsOf(lines), ['▾ main', 'alpha', 'bravo', '▾ odd-rail', 'delta'],
|
|
2557
|
+
'the empty worktree contributes neither header nor rows');
|
|
2558
|
+
assert.ok(!bodyOf(lines).includes('odd-fix'), 'and it is never named');
|
|
2559
|
+
});
|
|
2560
|
+
|
|
2561
|
+
test('S10: Enter on a header collapses the group, hides its documents and keeps the focus on it', async () => {
|
|
2562
|
+
const view = build({ groups: [MAIN, RAIL] });
|
|
2563
|
+
await tick();
|
|
2564
|
+
// Rows: [header main, alpha, bravo, header odd-rail, delta]; the mount
|
|
2565
|
+
// focuses alpha (index 1), so two steps reach the worktree header.
|
|
2566
|
+
for (let step = 0; step < 2; step += 1) view.handleInput('down');
|
|
2567
|
+
assert.equal(focusedRow(view.render(100)), '▾ odd-rail', 'the premise: the header is focused');
|
|
2568
|
+
view.handleInput('enter');
|
|
2569
|
+
const collapsed = view.render(100);
|
|
2570
|
+
assert.deepEqual(rowsOf(collapsed), ['▾ main', 'alpha', 'bravo', '▸ odd-rail'],
|
|
2571
|
+
'the header stays and its documents are gone');
|
|
2572
|
+
assert.equal(focusedRow(collapsed), '▸ odd-rail', 'the focus stays on the header');
|
|
2573
|
+
assert.equal(view.state.index, 3, 'and so does its row');
|
|
2574
|
+
assert.ok(!bodyOf(collapsed).includes('delta'), 'the collapsed documents are hidden');
|
|
2575
|
+
view.handleInput('enter');
|
|
2576
|
+
assert.deepEqual(rowsOf(view.render(100)), ['▾ main', 'alpha', 'bravo', '▾ odd-rail', 'delta'],
|
|
2577
|
+
'Enter again reopens it');
|
|
2578
|
+
});
|
|
2579
|
+
|
|
2580
|
+
test('Enter on a document keeps today\'s no-op: nothing folds and nothing moves', async () => {
|
|
2581
|
+
const view = build({ groups: [MAIN, RAIL] });
|
|
2582
|
+
await tick();
|
|
2583
|
+
view.handleInput('down');
|
|
2584
|
+
const before = view.render(100);
|
|
2585
|
+
assert.equal(focusedRow(before), 'bravo', 'the premise: a document is focused');
|
|
2586
|
+
view.handleInput('enter');
|
|
2587
|
+
const after = view.render(100);
|
|
2588
|
+
assert.deepEqual(rowsOf(after), rowsOf(before), 'no group folded around the focused document');
|
|
2589
|
+
assert.equal(view.state.index, 2, 'and the selection did not move');
|
|
2590
|
+
});
|
|
2591
|
+
|
|
2592
|
+
test('S11: a flips the mode, tells the caller once with the new value and the hint names the mode', async () => {
|
|
2593
|
+
const calls = [];
|
|
2594
|
+
const view = build({ groups: [MAIN, RAIL], onToggleAll: (all) => calls.push(all) });
|
|
2595
|
+
await tick();
|
|
2596
|
+
const sessionFooter = footerOf(view.render(200));
|
|
2597
|
+
assert.match(sessionFooter, /a all worktrees/, `the session mode offers every worktree: ${sessionFooter}`);
|
|
2598
|
+
view.handleInput('a');
|
|
2599
|
+
assert.deepEqual(calls, [true], 'the caller is told once, with the new value');
|
|
2600
|
+
const allFooter = footerOf(view.render(200));
|
|
2601
|
+
assert.match(allFooter, /a session only/, `the all-worktrees mode offers the session back: ${allFooter}`);
|
|
2602
|
+
assert.notEqual(allFooter, sessionFooter, 'the hint changes with the mode');
|
|
2603
|
+
view.handleInput('a');
|
|
2604
|
+
assert.deepEqual(calls, [true, false], 'a again returns to the session checkouts');
|
|
2605
|
+
assert.match(footerOf(view.render(200)), /a all worktrees/, 'and the hint comes back');
|
|
2606
|
+
});
|
|
2607
|
+
|
|
2608
|
+
test('S11: a failed async toggle rolls the request back, so the next press asks the same scope', async () => {
|
|
2609
|
+
const asked = [];
|
|
2610
|
+
const view = build({
|
|
2611
|
+
groups: [MAIN, RAIL],
|
|
2612
|
+
onToggleAll: (all) => {
|
|
2613
|
+
asked.push(all);
|
|
2614
|
+
return Promise.resolve(false);
|
|
2615
|
+
},
|
|
2616
|
+
});
|
|
2617
|
+
await tick();
|
|
2618
|
+
const sessionFooter = footerOf(view.render(200));
|
|
2619
|
+
assert.match(sessionFooter, /a all worktrees/, 'the premise: the session mode is applied');
|
|
2620
|
+
|
|
2621
|
+
// The load resolves `false`: nothing was applied, so the hint may not move.
|
|
2622
|
+
view.handleInput('a');
|
|
2623
|
+
await tick();
|
|
2624
|
+
assert.equal(footerOf(view.render(200)), sessionFooter, 'a failed load never moves the hint');
|
|
2625
|
+
|
|
2626
|
+
// The request was rolled back, so pressing again asks for the SAME scope.
|
|
2627
|
+
view.handleInput('a');
|
|
2628
|
+
await tick();
|
|
2629
|
+
assert.deepEqual(asked, [true, true], 'the retry asks for the scope the failed press asked for');
|
|
2630
|
+
assert.equal(footerOf(view.render(200)), sessionFooter, 'and the hint still describes the drawn mode');
|
|
2631
|
+
|
|
2632
|
+
// A load the caller really applied is what moves the mode and its hint.
|
|
2633
|
+
view.applyGroups([MAIN, RAIL], { all: true });
|
|
2634
|
+
assert.match(footerOf(view.render(200)), /a session only/, 'the applied scope is the one named');
|
|
2635
|
+
});
|
|
2636
|
+
|
|
2637
|
+
test('S11: a rejected toggle load also rolls the request back', async () => {
|
|
2638
|
+
const asked = [];
|
|
2639
|
+
const view = build({
|
|
2640
|
+
groups: [MAIN, RAIL],
|
|
2641
|
+
onToggleAll: (all) => {
|
|
2642
|
+
asked.push(all);
|
|
2643
|
+
return Promise.reject(new Error('read failed'));
|
|
2644
|
+
},
|
|
2645
|
+
});
|
|
2646
|
+
await tick();
|
|
2647
|
+
const sessionFooter = footerOf(view.render(200));
|
|
2648
|
+
view.handleInput('a');
|
|
2649
|
+
await tick();
|
|
2650
|
+
assert.equal(footerOf(view.render(200)), sessionFooter, 'a rejection leaves the hint alone');
|
|
2651
|
+
view.handleInput('a');
|
|
2652
|
+
await tick();
|
|
2653
|
+
assert.deepEqual(asked, [true, true], 'the retry asks for the same scope again');
|
|
2654
|
+
});
|
|
2655
|
+
|
|
2656
|
+
test('S11: without onToggleAll the key does nothing and its hint is never listed', async () => {
|
|
2657
|
+
const view = build({ groups: [MAIN, RAIL] });
|
|
2658
|
+
await tick();
|
|
2659
|
+
const before = view.render(100);
|
|
2660
|
+
assert.ok(!bodyOf(before).includes('worktrees'), `no hint for a key that cannot work: ${footerOf(before)}`);
|
|
2661
|
+
view.handleInput('a');
|
|
2662
|
+
assert.deepEqual(view.render(100), before, 'the key changes nothing at all');
|
|
2663
|
+
});
|
|
2664
|
+
|
|
2665
|
+
test('S11: the reloaded grouping re-applies the selection when the document is still there', async () => {
|
|
2666
|
+
const view = build({ groups: [MAIN, RAIL], onToggleAll: () => {} });
|
|
2667
|
+
await tick();
|
|
2668
|
+
for (let step = 0; step < 3; step += 1) view.handleInput('down');
|
|
2669
|
+
assert.equal(focusedRow(view.render(100)), 'delta', 'the premise: delta is the document being read');
|
|
2670
|
+
// The caller answered the `a` toggle with every worktree: delta is still
|
|
2671
|
+
// there, in a different place of a longer listing.
|
|
2672
|
+
view.applyGroups([
|
|
2673
|
+
MAIN,
|
|
2674
|
+
checkout('odd-rail', '/wt/odd-rail', false, [
|
|
2675
|
+
groupDoc('zulu', '/wt/odd-rail'),
|
|
2676
|
+
groupDoc('delta', '/wt/odd-rail'),
|
|
2677
|
+
]),
|
|
2678
|
+
]);
|
|
2679
|
+
await tick();
|
|
2680
|
+
const lines = view.render(100);
|
|
2681
|
+
assert.deepEqual(rowsOf(lines), ['▾ main', 'alpha', 'bravo', '▾ odd-rail', 'zulu', 'delta']);
|
|
2682
|
+
assert.equal(focusedRow(lines), 'delta', 'the reader keeps the SAME document');
|
|
2683
|
+
assert.match(bodyOf(lines), /body of delta/, 'and its pane is still the one being read');
|
|
2684
|
+
});
|
|
2685
|
+
|
|
2686
|
+
test('S6/S10: initialDoc finds its document inside a group, before any key press', async () => {
|
|
2687
|
+
const reads = [];
|
|
2688
|
+
const view = createOddView({
|
|
2689
|
+
groups: [
|
|
2690
|
+
checkout('main', '/wt/main', true, [{ name: 'alpha', path: '/wt/main/odd/tasks/alpha.md', mtimeMs: 2 }]),
|
|
2691
|
+
RAIL,
|
|
2692
|
+
],
|
|
2693
|
+
initialDoc: '/wt/odd-rail/odd/tasks/delta.md',
|
|
2694
|
+
loadDoc: (entry) => {
|
|
2695
|
+
reads.push(entry.docPath || entry.path || entry.name);
|
|
2696
|
+
return { ok: true, text: `# ${entry.name}\n\nbody of ${entry.name}\n` };
|
|
2697
|
+
},
|
|
2698
|
+
helpers,
|
|
2699
|
+
theme: plainTheme,
|
|
2700
|
+
rowsAvailable: () => 14,
|
|
2701
|
+
requestRender: () => {},
|
|
2702
|
+
done: () => {},
|
|
2703
|
+
});
|
|
2704
|
+
assert.deepEqual(reads, ['/wt/odd-rail/odd/tasks/delta.md'], 'the requested document is read on mount');
|
|
2705
|
+
await tick();
|
|
2706
|
+
const lines = view.render(100);
|
|
2707
|
+
assert.equal(focusedRow(lines), 'delta', 'the highlight is on the requested document row');
|
|
2708
|
+
assert.equal(view.state.index, 3, 'across the group it lives in');
|
|
2709
|
+
assert.match(bodyOf(lines), /body of delta/, 'the right pane starts on the requested document');
|
|
2710
|
+
assert.equal(view.state.scroll, 0, 'and at the top of it');
|
|
2711
|
+
});
|
|
2712
|
+
});
|
|
2713
|
+
|
|
2714
|
+
// ---------------------------------------------------------------------------
|
|
2715
|
+
// T12 (D2, S11): the preview clamp and the frame it paints must agree on ONE
|
|
2716
|
+
// viewport. The host's row source is not a constant — a resize between two reads
|
|
2717
|
+
// of the same frame is exactly what a real terminal does — so the clamp has to
|
|
2718
|
+
// measure the body this frame paints, never a second live sample.
|
|
2719
|
+
// ---------------------------------------------------------------------------
|
|
2720
|
+
// T6: the preview clamp must use the same viewport as this frame.
|
|
2721
|
+
test('T6 independent: a row-count change cannot omit the end of the preview', () => {
|
|
2722
|
+
let flip = false;
|
|
2723
|
+
let reads = 0;
|
|
2724
|
+
const text = Array.from({ length: 180 }, (_, i) => `Unique paragraph ${i}\n\n`).join('');
|
|
2725
|
+
const v = createOddView({
|
|
2726
|
+
docs: [{ name: 'long', path: '/tmp/long.md' }], helpers,
|
|
2727
|
+
loadDoc: () => ({ ok: true, text }),
|
|
2728
|
+
rowsAvailable: () => !flip || reads++ === 0 ? 8 : 34,
|
|
2729
|
+
});
|
|
2730
|
+
v.handleInput('\x1b[F');
|
|
2731
|
+
assert.match(v.render(120).join('\n'), /Unique paragraph 179/);
|
|
2732
|
+
flip = true;
|
|
2733
|
+
assert.match(v.render(120).join('\n'), /Unique paragraph 179/);
|
|
2734
|
+
});
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
// worktree↔issue association.
|
|
14
14
|
//
|
|
15
15
|
// The bash activity is not a preference here: it is a design on gentle-shell-bridge's
|
|
16
|
-
// own `Card activity` line, so the shipped surface is exactly five commands, two tools,
|
|
17
|
-
// sidebar
|
|
16
|
+
// own `Card activity` line, so the shipped surface is exactly five commands, two tools, TWO
|
|
17
|
+
// sidebar sections, one tools design and the one `Cards` row group the two file-card
|
|
18
18
|
// switches carry.
|
|
19
19
|
//
|
|
20
20
|
// Everything here reads the observable surface: the registered command and
|
|
@@ -121,11 +121,25 @@ describe('registration', () => {
|
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
test('the bridge is never imported, and the surface reaches it through its published object', () => {
|
|
124
|
+
test('the bridge is never imported, and the surface reaches it through its published object', async () => {
|
|
125
125
|
const source = stubbedSource();
|
|
126
126
|
assert.equal(/from\s+["']gentle-shell-bridge/.test(source), false, 'no import of the bridge package anywhere');
|
|
127
127
|
assert.equal(/require\(\s*["']gentle-shell-bridge/.test(source), false, 'no require of the bridge package anywhere');
|
|
128
|
-
assert.equal(source.split('api.registerSection(').length - 1,
|
|
128
|
+
assert.equal(source.split('api.registerSection(').length - 1, 2, 'exactly two sidebar sections are contributed');
|
|
129
|
+
// T5 (S1): the count alone would drift silently, so the ids are asserted through
|
|
130
|
+
// the bridge that received them: one `GITHUB` and one `ODD`, and nothing else.
|
|
131
|
+
const bridge = defaultBridge();
|
|
132
|
+
const previous = globalThis[BRIDGE_SLOT];
|
|
133
|
+
globalThis[BRIDGE_SLOT] = bridge.api;
|
|
134
|
+
try {
|
|
135
|
+
await loadExtension({});
|
|
136
|
+
assert.deepEqual(bridge.sections.map((section) => section.id).sort(),
|
|
137
|
+
['odd-worktree.issues', 'odd-worktree.odd-rail'],
|
|
138
|
+
'the two sections are the issues rail and the ODD rail');
|
|
139
|
+
} finally {
|
|
140
|
+
if (previous === undefined) delete globalThis[BRIDGE_SLOT];
|
|
141
|
+
else globalThis[BRIDGE_SLOT] = previous;
|
|
142
|
+
}
|
|
129
143
|
});
|
|
130
144
|
|
|
131
145
|
test('the bash design is wired through exactly one registration and adds no name', async () => {
|
|
@@ -333,8 +347,10 @@ describe('removed surface', () => {
|
|
|
333
347
|
assert.ok(source.includes('createPrsClient'), 'the client is built with the issues client INJECTED');
|
|
334
348
|
assert.ok(source.includes('libRequire("prs-view.js")'), 'the reader mounts the migrated pull-request view');
|
|
335
349
|
// S4 (T5): the rail's pull-request count is a SECOND READ on the one
|
|
336
|
-
// GITHUB section, never a second section.
|
|
337
|
-
|
|
350
|
+
// GITHUB section, never a second section. The package's other section is the
|
|
351
|
+
// ODD rail (odd-rail-section T5, S1), so the count is two and the pull
|
|
352
|
+
// requests still add no third one.
|
|
353
|
+
assert.equal(source.split('api.registerSection(').length - 1, 2, 'the two sections are the GITHUB rail and the ODD rail, and the PR count is no third one');
|
|
338
354
|
assert.ok(source.includes('loadPullRequests'), 'the one section reads pull requests for its header');
|
|
339
355
|
assert.ok(source.includes('libRequire("prs-rail-store.js")'), 'the count is persisted by the loader');
|
|
340
356
|
});
|
|
@@ -905,7 +905,7 @@ describe('S4/S5: the one section counts and routes pull requests', () => {
|
|
|
905
905
|
// that answer lands, so the assertion waits for it instead of the first frame.
|
|
906
906
|
await waitFor(() => section.meta(ctx) === '2 issues · 2 pr');
|
|
907
907
|
assert.equal(section.meta(ctx), '2 issues · 2 pr', 'the distinct union of mine and review counts once');
|
|
908
|
-
assert.equal(registered.length, 1, 'the count is not a second section');
|
|
908
|
+
assert.equal(registered.filter((section) => section && section.id === 'odd-worktree.issues').length, 1, 'the count is not a second GITHUB section');
|
|
909
909
|
});
|
|
910
910
|
|
|
911
911
|
test('a row whose issue links a PR opens the PR panel with the review bucket hint', async () => {
|