pi-odd-worktree 3.11.2 → 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.
@@ -0,0 +1,1868 @@
1
+ 'use strict';
2
+ // T4 (S6, S10, S11, S13): the `/odd` command's half of the grouped panel. The
3
+ // view (`lib/odd-view.js`) and the model (`lib/odd-group.js`) have their own
4
+ // suites; this one mounts the REGISTERED command against a real git checkout and
5
+ // a fake host, so what it asserts is what the wiring actually hands over:
6
+ //
7
+ // * the model reaches the view, scoped to the worktrees the SESSION registered
8
+ // — read from the same `gentle-pi.session-worktree/v1` entries the files
9
+ // panel reads — so an unregistered checkout costs no git read at all;
10
+ // * a registered worktree with nothing of its own draws no group chrome;
11
+ // * `a` reloads every owned worktree, and `a` again reloads the registered set;
12
+ // * a valid absolute target and a bare ODD name open the panel ON that
13
+ // document, while refused shapes keep the sentence they always had;
14
+ // * none of it depends on the Worktrees+ module, because the ODD surfaces
15
+ // follow the session's registered worktrees (corrected S7).
16
+ //
17
+ // The git reads are observed through the module instance THIS load uses
18
+ // (`libModule('worktree-git.js').runArgvAsync`, the seam every async git read in
19
+ // the extension goes through), so the argv and the checkout each read ran in are
20
+ // the evidence, never a count the source could satisfy some other way.
21
+
22
+ const { test, describe, after } = require('node:test');
23
+ const assert = require('node:assert/strict');
24
+ const fs = require('node:fs');
25
+ const os = require('node:os');
26
+ const path = require('node:path');
27
+ const { pathToFileURL } = require('node:url');
28
+ const { spawnSync } = require('node:child_process');
29
+ const {
30
+ BRIDGE_SLOT,
31
+ LIB_DIR,
32
+ defaultBridge,
33
+ stubbedSource,
34
+ withGhPath,
35
+ } = require('./fixtures/load-extension.js');
36
+
37
+ const scratch = [];
38
+ function track(dir) {
39
+ scratch.push(dir);
40
+ return dir;
41
+ }
42
+ after(() => {
43
+ for (const dir of scratch) {
44
+ try { fs.rmSync(dir, { recursive: true, force: true }); } catch {}
45
+ }
46
+ });
47
+
48
+ function git(cwd, args) {
49
+ const out = spawnSync('git', args, { cwd, encoding: 'utf8' });
50
+ if (out.status !== 0) throw new Error(`git ${args.join(' ')} failed: ${out.stderr}`);
51
+ return out.stdout.trim();
52
+ }
53
+
54
+ const SESSION_WORKTREE_CUSTOM_TYPE = 'gentle-pi.session-worktree/v1';
55
+
56
+ // A repository whose `odd/tasks` holds two documents with deliberately distinct
57
+ // mtimes and distinct bodies, so a test can tell from the rendered frame which
58
+ // one the panel is reading.
59
+ function makeRepo() {
60
+ const dir = fs.realpathSync(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-panel-repo-'))));
61
+ git(dir, ['init', '-b', 'main']);
62
+ git(dir, ['config', 'user.email', 'test@example.test']);
63
+ git(dir, ['config', 'user.name', 'Test']);
64
+ const tasks = path.join(dir, 'odd', 'tasks');
65
+ fs.mkdirSync(tasks, { recursive: true });
66
+ fs.writeFileSync(path.join(tasks, 'main-one.md'), '# body of main-one\n');
67
+ fs.writeFileSync(path.join(tasks, 'main-two.md'), '# body of main-two\n');
68
+ const now = Date.now() / 1000;
69
+ fs.utimesSync(path.join(tasks, 'main-one.md'), now - 200, now - 200);
70
+ fs.utimesSync(path.join(tasks, 'main-two.md'), now - 100, now - 100);
71
+ git(dir, ['add', '-A']);
72
+ git(dir, ['commit', '-m', 'init']);
73
+ return dir;
74
+ }
75
+
76
+ // The worktree directory the package owns (`<repo-parent>/<repo-name>-worktrees`),
77
+ // so the same fixture answers BOTH scopes: registered roots, and the `a` mode's
78
+ // every-owned-worktree one.
79
+ function addWorktree(repo, name) {
80
+ const owned = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`);
81
+ fs.mkdirSync(owned, { recursive: true });
82
+ const root = path.join(owned, name);
83
+ git(repo, ['worktree', 'add', '-b', `feat/${name}`, root, 'main']);
84
+ return root;
85
+ }
86
+
87
+ function writeTask(root, name, body) {
88
+ const tasks = path.join(root, 'odd', 'tasks');
89
+ fs.mkdirSync(tasks, { recursive: true });
90
+ fs.writeFileSync(path.join(tasks, `${name}.md`), body);
91
+ return path.join(tasks, `${name}.md`);
92
+ }
93
+
94
+ const theme = { fg: (_role, text) => String(text), bg: (_role, text) => String(text), bold: (text) => String(text) };
95
+
96
+ function stripAnsi(text) {
97
+ return String(text).replace(/\x1b\[[0-9;]*m/g, '');
98
+ }
99
+
100
+ const helpers = {
101
+ visibleWidth: (value) => [...stripAnsi(value)].length,
102
+ truncateToWidth: (value, width) => {
103
+ const chars = [...String(value)];
104
+ return chars.length > width ? chars.slice(0, width).join('') : String(value);
105
+ },
106
+ matchesKey: (key, name) => key === name,
107
+ isKeyRelease: () => false,
108
+ };
109
+
110
+ // The frame the human sees: every line stripped of its escapes and trimmed, at a
111
+ // width that fits the whole footer legend.
112
+ function renderedRows(component, width = 120) {
113
+ return component.render(width).map((line) => stripAnsi(line).trimEnd());
114
+ }
115
+
116
+ const frameText = (component) => renderedRows(component).join('\n');
117
+
118
+ // The fake host: `custom` mounts the panel factory and stays pending until the
119
+ // view closes, exactly like Pi's overlay, so a test can drive the component it
120
+ // got and read the frames it paints.
121
+ function mountHost() {
122
+ const mounts = [];
123
+ const notifications = [];
124
+ const renders = [];
125
+ const tui = { terminal: { rows: 30 }, requestRender: () => { renders.push(1); } };
126
+ const ui = {
127
+ notify: (text, level) => { notifications.push([level, text]); },
128
+ custom: (factory, options) => new Promise((resolve) => {
129
+ const component = factory(tui, theme, {}, (value) => resolve(value));
130
+ mounts.push({ options, component });
131
+ }),
132
+ };
133
+ return { tui, ui, mounts, notifications, renders };
134
+ }
135
+
136
+ function ctxFor(repo, host, registeredRoots = []) {
137
+ return {
138
+ cwd: repo,
139
+ hasUI: true,
140
+ mode: 'tui',
141
+ sessionManager: {
142
+ getSessionId: () => 'thread-1',
143
+ getEntries: () => registeredRoots.map((root) => ({
144
+ type: 'custom',
145
+ customType: SESSION_WORKTREE_CUSTOM_TYPE,
146
+ data: { sessionId: 'thread-1', root, evidence: 'session:tool' },
147
+ })),
148
+ },
149
+ ui: host.ui,
150
+ };
151
+ }
152
+
153
+ async function waitFor(predicate, label) {
154
+ const deadline = Date.now() + 20_000;
155
+ while (Date.now() < deadline) {
156
+ if (predicate()) return;
157
+ await new Promise((resolve) => setTimeout(resolve, 10));
158
+ }
159
+ throw new Error(`timed out waiting for ${label}`);
160
+ }
161
+
162
+ // One extension load per test. `modules` is the bridge's own store document, so
163
+ // `{ worktrees: false }` is exactly the Worktrees+ switch a host would have.
164
+ let loads = 0;
165
+ async function load(modules) {
166
+ const bridge = defaultBridge();
167
+ const document = modules === undefined ? undefined : { ...modules };
168
+ bridge.api.createStore = () => ({
169
+ get: (key, fallback) => (key === 'modules' && document !== undefined ? document : fallback),
170
+ set: () => {},
171
+ delete: () => {},
172
+ });
173
+ globalThis[BRIDGE_SLOT] = bridge.api;
174
+ return withGhPath('present', async () => {
175
+ process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
176
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'odd-panel-ext-'));
177
+ try {
178
+ const copy = path.join(dir, 'odd-worktree-tools.mjs');
179
+ fs.writeFileSync(copy, stubbedSource());
180
+ loads += 1;
181
+ const mod = await import(`${pathToFileURL(copy).href}?load=${loads}`);
182
+ const commands = new Map();
183
+ const hooks = [];
184
+ const host = {
185
+ registerCommand: (name, handler) => commands.set(name, handler),
186
+ registerTool: () => {},
187
+ registerMessageRenderer: () => {},
188
+ registerEntryRenderer: () => {},
189
+ appendEntry: () => {},
190
+ on: (event, handler) => { hooks.push([event, handler]); },
191
+ };
192
+ mod.default(host);
193
+ // The viewer's TUI helpers: the documented loader seam, answered with the
194
+ // cell-measuring double the view's own suite uses. `a`, the group headers
195
+ // and the preview all paint through them.
196
+ mod.setOddTuiLoader(() => Promise.resolve(helpers));
197
+ return { mod, commands, host };
198
+ } finally {
199
+ fs.rmSync(dir, { recursive: true, force: true });
200
+ }
201
+ });
202
+ }
203
+
204
+ // Every async git read this load makes, with the checkout it ran in. The
205
+ // extension reaches git through `libRunner(git)` → `runArgvAsync`, so replacing
206
+ // that one function observes all of it.
207
+ function observeGit(mod) {
208
+ const gitLib = mod.libModule('worktree-git.js');
209
+ const real = gitLib.runArgvAsync;
210
+ const calls = [];
211
+ gitLib.runArgvAsync = (bin, argv, options) => {
212
+ const call = { argv: [...argv], cwd: options && options.cwd, settled: false };
213
+ calls.push(call);
214
+ const pending = real.call(gitLib, bin, argv, options);
215
+ // Settlement is recorded, so a test can wait for the RANKED listing (the
216
+ // one that lands after the first frame) instead of guessing at a delay.
217
+ return Promise.resolve(pending).then(
218
+ (value) => { call.settled = true; return value; },
219
+ (err) => { call.settled = true; throw err; },
220
+ );
221
+ };
222
+ return {
223
+ calls,
224
+ clear: () => { calls.length = 0; },
225
+ // The reads that name one checkout's own ODD documents: the merge base with
226
+ // main, then the diff/status of that checkout. `worktree list` names none.
227
+ readsIn: (cwd) => calls.filter((call) => call.cwd === cwd
228
+ && (call.argv.includes('merge-base')
229
+ || (call.argv.includes('diff') && call.argv.includes('--name-status'))
230
+ || (call.argv.includes('status') && call.argv.includes('--porcelain=v1')))),
231
+ listing: () => calls.filter((call) => call.argv.includes('worktree') && call.argv.includes('list')),
232
+ restore: () => { gitLib.runArgvAsync = real; },
233
+ };
234
+ }
235
+
236
+ // The git-ranked listing that replaces the first frame: `listOddDocsAsync` ends
237
+ // its walk with `status --porcelain -z` in the checkout it listed, so a SETTLED
238
+ // call of that shape is the proof the ranked order has arrived. One short tick
239
+ // afterwards lets the promise chain apply it and repaint.
240
+ async function waitForRankedListing(observed, roots) {
241
+ await waitFor(() => observed.calls.some((call) => call.settled === true
242
+ && roots.includes(call.cwd)
243
+ && call.argv.includes('status')
244
+ && call.argv.includes('--porcelain')), 'the ranked listing settles');
245
+ await new Promise((resolve) => setTimeout(resolve, 80));
246
+ }
247
+
248
+ // S11/S13: the grouped READ, held open. The extension reaches the model through
249
+ // this one module instance, so replacing its `groupOddDocs` with a queue of
250
+ // promises is exactly the two reloads a human can start faster than the disk
251
+ // answers them — and the test decides which one lands first.
252
+ function deferGroups(mod) {
253
+ const group = mod.libModule('odd-group.js');
254
+ const real = group.groupOddDocs;
255
+ const pending = [];
256
+ let armed = false;
257
+ group.groupOddDocs = (input) => {
258
+ if (!armed) return real.call(group, input);
259
+ return new Promise((resolve, reject) => { pending.push({ input, resolve, reject }); });
260
+ };
261
+ return {
262
+ real: (input) => real.call(group, input),
263
+ arm: () => { armed = true; },
264
+ pending,
265
+ restore: () => { group.groupOddDocs = real; },
266
+ };
267
+ }
268
+
269
+ // The handler stays pending until the view closes, exactly like a real overlay:
270
+ // `esc` finishes it through the factory's own `done`.
271
+ async function closePanel(host, pending) {
272
+ const mount = host.mounts[host.mounts.length - 1];
273
+ if (mount) mount.component.handleInput('\x1b');
274
+ try { await pending; } catch {}
275
+ }
276
+
277
+ describe('the grouped listing the panel draws (S10, S13)', () => {
278
+ test('groups reach the panel scoped to the session’s registered worktrees, and only those cost git', async () => {
279
+ const loaded = await load();
280
+ const observed = observeGit(loaded.mod);
281
+ try {
282
+ const repo = makeRepo();
283
+ const registered = addWorktree(repo, 'wt-a');
284
+ const foreign = addWorktree(repo, 'wt-b');
285
+ writeTask(registered, 'a-only', '# body of a-only\n');
286
+ writeTask(foreign, 'b-only', '# body of b-only\n');
287
+ const host = mountHost();
288
+ const ctx = ctxFor(repo, host, [registered]);
289
+
290
+ const pending = loaded.commands.get('odd').handler('', ctx);
291
+ pending.catch(() => {});
292
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
293
+
294
+ const text = frameText(host.mounts[0].component);
295
+ // S10/S13: main always carries every ODD of main; a registered worktree
296
+ // carries only what it has that main does not.
297
+ assert.match(text, /\u25be main/, 'main is a group of its own');
298
+ assert.match(text, /\u25be wt-a/, 'the registered worktree is a group');
299
+ assert.match(text, /a-only/);
300
+ assert.ok(!text.includes('wt-b'), `an unregistered worktree is not a group\n${text}`);
301
+ assert.ok(!text.includes('b-only'), `nor is one of its documents listed\n${text}`);
302
+ assert.match(text, /3 documents/, 'main’s two plus the worktree’s one');
303
+
304
+ // The unregistered checkout was never asked anything: no worktree listing
305
+ // of its own, no merge-base, no diff, no status.
306
+ assert.equal(observed.listing().length, 1, 'the grouping enumerated the checkouts once');
307
+ assert.deepEqual(observed.readsIn(foreign), [],
308
+ 'an unregistered worktree costs no git read at all');
309
+ assert.ok(observed.readsIn(registered).length > 0, 'the registered one was compared with main');
310
+
311
+ await closePanel(host, pending);
312
+ } finally {
313
+ observed.restore();
314
+ }
315
+ });
316
+
317
+ test('a registered worktree with no difference from main draws no group chrome', async () => {
318
+ const loaded = await load();
319
+ const observed = observeGit(loaded.mod);
320
+ try {
321
+ const repo = makeRepo();
322
+ const registered = addWorktree(repo, 'wt-same');
323
+ // Byte-identical copies: nothing new, nothing modified.
324
+ for (const name of ['main-one', 'main-two']) {
325
+ writeTask(registered, name, fs.readFileSync(path.join(repo, 'odd', 'tasks', `${name}.md`), 'utf8'));
326
+ }
327
+ const host = mountHost();
328
+ const ctx = ctxFor(repo, host, [registered]);
329
+
330
+ const pending = loaded.commands.get('odd').handler('', ctx);
331
+ pending.catch(() => {});
332
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
333
+
334
+ const rows = renderedRows(host.mounts[0].component);
335
+ const text = rows.join('\n');
336
+ // A drawn group always paints an EXPANDED header on a fresh mount (`▾`);
337
+ // `▸` alone would be ambiguous, because that is also the selection mark of
338
+ // the focused row.
339
+ assert.ok(!rows.some((row) => row.includes('\u25be')),
340
+ `no group chrome is drawn for an empty delta\n${text}`);
341
+ assert.ok(!text.includes('wt-same'), `the unchanged worktree is never named\n${text}`);
342
+ assert.match(text, /2 documents/, 'the ordinary main-only count');
343
+ assert.match(text, /main-one/);
344
+ assert.match(text, /main-two/);
345
+
346
+ await closePanel(host, pending);
347
+ } finally {
348
+ observed.restore();
349
+ }
350
+ });
351
+
352
+ test('`a` reloads every owned worktree and `a` again returns to the session’s', async () => {
353
+ const loaded = await load();
354
+ const observed = observeGit(loaded.mod);
355
+ try {
356
+ const repo = makeRepo();
357
+ const registered = addWorktree(repo, 'wt-a');
358
+ const other = addWorktree(repo, 'wt-b');
359
+ writeTask(registered, 'a-only', '# body of a-only\n');
360
+ writeTask(other, 'b-only', '# body of b-only\n');
361
+ const host = mountHost();
362
+ const ctx = ctxFor(repo, host, [registered]);
363
+
364
+ const pending = loaded.commands.get('odd').handler('', ctx);
365
+ pending.catch(() => {});
366
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
367
+ const component = host.mounts[0].component;
368
+ assert.match(frameText(component), /a all worktrees/, 'the hint names the mode it is in');
369
+
370
+ // `a`: the reload is UNscoped, so the unregistered worktree is compared now.
371
+ observed.clear();
372
+ component.handleInput('a');
373
+ await waitFor(() => observed.readsIn(other).length > 0, 'the unscoped reload compared wt-b');
374
+ await waitFor(() => frameText(component).includes('wt-b'), 'the second group is drawn');
375
+ assert.equal(observed.listing().length, 1, 'one grouped reload, one worktree listing');
376
+ assert.match(frameText(component), /a session only/, 'the hint follows the mode');
377
+ assert.match(frameText(component), /\u25be wt-b/);
378
+ assert.match(frameText(component), /b-only/);
379
+
380
+ // `a` again: back to the session's registered set only.
381
+ observed.clear();
382
+ component.handleInput('a');
383
+ await waitFor(() => !frameText(component).includes('wt-b'), 'the unregistered group goes');
384
+ assert.deepEqual(observed.readsIn(other), [],
385
+ 'the registered reload never asks an unregistered worktree anything');
386
+ assert.equal(observed.listing().length, 1, 'and it re-enumerates the checkouts once');
387
+ assert.match(frameText(component), /a all worktrees/, 'the hint returns with the mode');
388
+ assert.match(frameText(component), /\u25be wt-a/);
389
+
390
+ await closePanel(host, pending);
391
+ } finally {
392
+ observed.restore();
393
+ }
394
+ });
395
+ });
396
+
397
+ describe('main is the checkout the panel ranks (S6, S10, S12, S13)', () => {
398
+ test('a click on a main-only ODD keeps it selected after the ranked refresh settles', async () => {
399
+ const loaded = await load();
400
+ const observed = observeGit(loaded.mod);
401
+ try {
402
+ const repo = makeRepo();
403
+ // The session runs INSIDE a linked worktree, and that worktree is not
404
+ // registered: main is the only loaded group, so main's documents are the
405
+ // only documents the panel may draw.
406
+ const worktree = addWorktree(repo, 'wt-a');
407
+ // The session's checkout holds ONE document of its own and none of main's,
408
+ // so a main-only ODD has nowhere to be found in it.
409
+ fs.rmSync(path.join(worktree, 'odd'), { recursive: true, force: true });
410
+ writeTask(worktree, 'a-only', '# body of a-only\n');
411
+ const target = path.join(repo, 'odd', 'tasks', 'main-one.md');
412
+ const host = mountHost();
413
+ const ctx = ctxFor(worktree, host, []);
414
+
415
+ const pending = loaded.commands.get('odd').handler(target, ctx);
416
+ pending.catch(() => {});
417
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
418
+ const component = host.mounts[0].component;
419
+ assert.match(frameText(component), /body of main-one/, 'the target opens on its own document');
420
+
421
+ await waitForRankedListing(observed, [repo, worktree]);
422
+ const text = frameText(component);
423
+ assert.match(text, /body of main-one/,
424
+ `the ranked refresh keeps the document the target opened\n${text}`);
425
+ assert.ok(!text.includes('a-only'),
426
+ `the session checkout's documents never become main's\n${text}`);
427
+
428
+ await closePanel(host, pending);
429
+ } finally {
430
+ observed.restore();
431
+ }
432
+ });
433
+
434
+ test('bare /odd in an empty session worktree mounts when main has documents', async () => {
435
+ const loaded = await load();
436
+ const observed = observeGit(loaded.mod);
437
+ try {
438
+ const repo = makeRepo();
439
+ const worktree = addWorktree(repo, 'wt-a');
440
+ // Nothing of its own in the session's checkout: the worktree checks out
441
+ // main's tree, so its `odd/tasks` is removed to make the session checkout
442
+ // the empty one.
443
+ fs.rmSync(path.join(worktree, 'odd'), { recursive: true, force: true });
444
+ assert.equal(fs.existsSync(path.join(worktree, 'odd', 'tasks')), false,
445
+ 'the session checkout holds no odd/tasks of its own');
446
+ const host = mountHost();
447
+ const ctx = ctxFor(worktree, host, []);
448
+
449
+ const pending = loaded.commands.get('odd').handler('', ctx);
450
+ pending.catch(() => {});
451
+ await waitFor(() => host.mounts.length === 1 || host.notifications.length > 0,
452
+ 'the command answers the empty session checkout');
453
+ assert.deepEqual(host.notifications, [],
454
+ 'a non-empty main is not "nothing under odd/tasks"');
455
+ assert.equal(host.mounts.length, 1, 'the panel mounts over main\u2019s documents');
456
+ const text = frameText(host.mounts[0].component);
457
+ assert.match(text, /main-one/);
458
+ assert.match(text, /main-two/);
459
+ assert.match(text, /2 documents/, 'main’s own two documents');
460
+
461
+ await closePanel(host, pending);
462
+ } finally {
463
+ observed.restore();
464
+ }
465
+ });
466
+
467
+ test('`r` never lists a document no loaded group carries', async () => {
468
+ const loaded = await load();
469
+ const observed = observeGit(loaded.mod);
470
+ try {
471
+ const repo = makeRepo();
472
+ const worktree = addWorktree(repo, 'wt-a');
473
+ writeTask(worktree, 'a-only', '# body of a-only\n');
474
+ const host = mountHost();
475
+ const ctx = ctxFor(worktree, host, []);
476
+
477
+ const pending = loaded.commands.get('odd').handler('', ctx);
478
+ pending.catch(() => {});
479
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
480
+ const component = host.mounts[0].component;
481
+ const before = renderedRows(component).join('\n');
482
+ assert.ok(!before.includes('a-only'), `the mount lists only the loaded group\n${before}`);
483
+
484
+ // `r` reloads from the session's checkout: whatever it answers, the panel
485
+ // draws the loaded model, so a worktree the session never registered can
486
+ // never appear in it.
487
+ observed.clear();
488
+ component.handleInput('r');
489
+ await waitForRankedListing(observed, [repo, worktree]);
490
+ const after = renderedRows(component).join('\n');
491
+ assert.ok(!after.includes('a-only'),
492
+ `a document no loaded group carries is never listed\n${after}`);
493
+ assert.match(after, /main-one/);
494
+ assert.match(after, /main-two/);
495
+
496
+ await closePanel(host, pending);
497
+ } finally {
498
+ observed.restore();
499
+ }
500
+ });
501
+ });
502
+
503
+ describe('`a` applies only the latest reload (S11, S13)', () => {
504
+ test('a stale toggle result resolved last never lands on top', async () => {
505
+ const loaded = await load();
506
+ const observed = observeGit(loaded.mod);
507
+ const deferred = deferGroups(loaded.mod);
508
+ try {
509
+ const repo = makeRepo();
510
+ const registered = addWorktree(repo, 'wt-a');
511
+ const other = addWorktree(repo, 'wt-b');
512
+ writeTask(registered, 'a-only', '# body of a-only\n');
513
+ // The unregistered worktree is the ONE thing `a` adds to the listing.
514
+ writeTask(other, 'b-only', '# body of b-only\n');
515
+ const host = mountHost();
516
+ const ctx = ctxFor(repo, host, [registered]);
517
+
518
+ const pending = loaded.commands.get('odd').handler('', ctx);
519
+ pending.catch(() => {});
520
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
521
+ const component = host.mounts[0].component;
522
+
523
+ // Two presses, both reloads held open: the second press is back in the
524
+ // session's mode, so its answer is the ONLY one the drawn listing may carry.
525
+ deferred.arm();
526
+ component.handleInput('a');
527
+ await waitFor(() => deferred.pending.length === 1, 'the first toggle reload starts');
528
+ component.handleInput('a');
529
+ await waitFor(() => deferred.pending.length === 2, 'the second toggle reload starts');
530
+
531
+ // The LATEST request settles first…
532
+ deferred.pending[1].resolve(await deferred.real(deferred.pending[1].input));
533
+ await new Promise((resolve) => setTimeout(resolve, 40));
534
+ assert.ok(!frameText(component).includes('wt-b'), 'the latest answer is what is drawn');
535
+ assert.match(frameText(component), /a all worktrees/, 'and the mode is back to the session\u2019s');
536
+
537
+ // …and the OLD one settles last: it is dropped, never applied.
538
+ deferred.pending[0].resolve(await deferred.real(deferred.pending[0].input));
539
+ await new Promise((resolve) => setTimeout(resolve, 80));
540
+ const text = frameText(component);
541
+ assert.ok(!text.includes('wt-b'), `a stale toggle result never lands on top\n${text}`);
542
+ assert.ok(!text.includes('b-only'), 'nor any of its documents');
543
+ assert.match(text, /a all worktrees/,
544
+ 'the footer still names the mode the key really switched to');
545
+
546
+ await closePanel(host, pending);
547
+ } finally {
548
+ deferred.restore();
549
+ observed.restore();
550
+ }
551
+ });
552
+
553
+ test('a stale `r` result resolved last never replaces the drawn listing', async () => {
554
+ const loaded = await load();
555
+ const observed = observeGit(loaded.mod);
556
+ const deferred = deferGroups(loaded.mod);
557
+ try {
558
+ const repo = makeRepo();
559
+ const other = addWorktree(repo, 'wt-b');
560
+ writeTask(other, 'b-only', '# body of b-only\n');
561
+ const host = mountHost();
562
+ const ctx = ctxFor(repo, host, []);
563
+
564
+ const pending = loaded.commands.get('odd').handler('', ctx);
565
+ pending.catch(() => {});
566
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
567
+ const component = host.mounts[0].component;
568
+
569
+ deferred.arm();
570
+ component.handleInput('r');
571
+ await waitFor(() => deferred.pending.length === 1, 'the first reload starts');
572
+ component.handleInput('r');
573
+ await waitFor(() => deferred.pending.length === 2, 'the second reload starts');
574
+
575
+ // The second `r` answers first, in the session's own scope: its flat listing
576
+ // is the awaited git read, so the rendered outcome is what proves it landed.
577
+ observed.clear();
578
+ deferred.pending[1].resolve(await deferred.real(deferred.pending[1].input));
579
+ await waitForRankedListing(observed, [repo]);
580
+ assert.ok(!frameText(component).includes('wt-b'));
581
+
582
+ // The first `r` answers last with a listing that includes every worktree:
583
+ // its request is superseded, so its model is dropped.
584
+ const everyWorktree = await deferred.real({ repoRoot: repo });
585
+ assert.ok(Array.isArray(everyWorktree) && everyWorktree.length > 1,
586
+ 'the stale fixture really carries a second group');
587
+ deferred.pending[0].resolve(everyWorktree);
588
+ await new Promise((resolve) => setTimeout(resolve, 80));
589
+ const text = frameText(component);
590
+ assert.ok(!text.includes('wt-b'), `a superseded reload is dropped\n${text}`);
591
+
592
+ await closePanel(host, pending);
593
+ } finally {
594
+ deferred.restore();
595
+ observed.restore();
596
+ }
597
+ });
598
+ });
599
+
600
+ describe('`/odd <target>` (S6)', () => {
601
+ test('an absolute target inside a registered worktree opens the panel on it', async () => {
602
+ const loaded = await load();
603
+ const observed = observeGit(loaded.mod);
604
+ try {
605
+ const repo = makeRepo();
606
+ const registered = addWorktree(repo, 'wt-a');
607
+ const target = writeTask(registered, 'a-only', '# body of a-only\n');
608
+ const host = mountHost();
609
+ const ctx = ctxFor(repo, host, [registered]);
610
+
611
+ const pending = loaded.commands.get('odd').handler(target, ctx);
612
+ pending.catch(() => {});
613
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
614
+
615
+ assert.deepEqual(host.notifications, [], 'the target is accepted, not refused');
616
+ const text = frameText(host.mounts[0].component);
617
+ assert.match(text, /\u25be wt-a/, 'its group is unfolded');
618
+ assert.match(text, /body of a-only/, 'and the panel is reading THAT document');
619
+
620
+ await closePanel(host, pending);
621
+ } finally {
622
+ observed.restore();
623
+ }
624
+ });
625
+
626
+ test('an absolute target no loaded group lists is refused, not silently ignored', async () => {
627
+ const loaded = await load();
628
+ const observed = observeGit(loaded.mod);
629
+ try {
630
+ const repo = makeRepo();
631
+ const foreign = addWorktree(repo, 'wt-b');
632
+ writeTask(foreign, 'b-only', '# body of b-only\n');
633
+ const target = path.join(foreign, 'odd', 'tasks', 'b-only.md');
634
+ const host = mountHost();
635
+ const ctx = ctxFor(repo, host, []);
636
+
637
+ let settled = false;
638
+ loaded.commands.get('odd').handler(target, ctx).then(
639
+ () => { settled = true; },
640
+ () => { settled = true; },
641
+ );
642
+ await waitFor(() => settled || host.mounts.length > 0 || host.notifications.length > 0,
643
+ 'the command answers the target');
644
+
645
+ // S6: a document in a worktree the session never registered is in no
646
+ // loaded group, so the target is the unknown option it always was — the
647
+ // panel never opens on some other document instead.
648
+ assert.deepEqual(host.notifications, [['error', `Unknown option "${target}". Use /odd.`]]);
649
+ assert.equal(host.mounts.length, 0, 'nothing is mounted for a refused target');
650
+ } finally {
651
+ observed.restore();
652
+ }
653
+ });
654
+
655
+ test('a bare ODD name is accepted and selected', async () => {
656
+ const loaded = await load();
657
+ const observed = observeGit(loaded.mod);
658
+ try {
659
+ const repo = makeRepo();
660
+ const registered = addWorktree(repo, 'wt-a');
661
+ writeTask(registered, 'a-only', '# body of a-only\n');
662
+ const host = mountHost();
663
+ const ctx = ctxFor(repo, host, [registered]);
664
+
665
+ const pending = loaded.commands.get('odd').handler('a-only', ctx);
666
+ pending.catch(() => {});
667
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
668
+
669
+ assert.deepEqual(host.notifications, []);
670
+ const text = frameText(host.mounts[0].component);
671
+ assert.match(text, /body of a-only/, 'the panel is reading the named ODD');
672
+ assert.match(text, /\u25be wt-a/, 'and its group is unfolded to show it');
673
+
674
+ await closePanel(host, pending);
675
+ } finally {
676
+ observed.restore();
677
+ }
678
+ });
679
+ });
680
+
681
+ describe('`r` still re-lists and re-reads (S9, preserved)', () => {
682
+ test('a document added on disk appears after `r`, with no worktree registered', async () => {
683
+ const loaded = await load();
684
+ const observed = observeGit(loaded.mod);
685
+ try {
686
+ const repo = makeRepo();
687
+ const host = mountHost();
688
+ const ctx = ctxFor(repo, host, []);
689
+
690
+ const pending = loaded.commands.get('odd').handler('', ctx);
691
+ pending.catch(() => {});
692
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
693
+ const component = host.mounts[0].component;
694
+ assert.ok(!frameText(component).includes('later'), 'the new document is not there yet');
695
+
696
+ writeTask(repo, 'later', '# body of later\n');
697
+ component.handleInput('r');
698
+ await waitFor(() => frameText(component).includes('later'), 'the reload lists the new document');
699
+ assert.match(frameText(component), /3 documents/, 'the count follows the reloaded listing');
700
+
701
+ await closePanel(host, pending);
702
+ } finally {
703
+ observed.restore();
704
+ }
705
+ });
706
+ });
707
+
708
+ // T6 (independent verification, HEAD 614da6e): three defects reproduced with
709
+ // real Git through the registered command. Each one is a rule S11/S13/D2 states
710
+ // and the wiring did not keep.
711
+ //
712
+ // * S11: `a` means EVERY worktree of the clone, registered or not. A worktree
713
+ // made with `git worktree add <anywhere>` is not under `<repo>-worktrees`,
714
+ // so the owned-checkout default silently omitted it from the all mode.
715
+ // * S13: every reload reads the session's registered worktrees AT RELOAD TIME;
716
+ // the mount-time read may only answer the first frame, so a worktree
717
+ // registered after the panel opened appears on the next `r`.
718
+ // * D2: a superseded reload is INERT. Its groups were already dropped, but its
719
+ // flat listing was still applied by the view, which reset the preview scroll.
720
+
721
+ describe('T6 verifier regressions (S11, S13, D2)', () => {
722
+ test('T6 verifier: all mode includes an outside-canonical Git worktree (S11)', async () => {
723
+ const loaded = await load();
724
+ const repo = makeRepo();
725
+ const linked = addWorktree(repo, 'wt-t6-local');
726
+ const witness = addWorktree(repo, 'wt-t6-witness');
727
+ writeTask(witness, 't6-witness-odd', '# Owned unregistered worktree\n');
728
+ const outside = path.join(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-t6-'))), 'wt-t6-outside');
729
+ git(repo, ['worktree', 'add', '-b', 'feat/t6-outside', outside, 'main']);
730
+ writeTask(outside, 't6-outside-odd', '# External worktree\n');
731
+ const host = mountHost();
732
+ const pending = loaded.commands.get('odd').handler('', ctxFor(linked, host, [linked]));
733
+ try {
734
+ await waitFor(() => host.mounts.length === 1, 'mount');
735
+ const view = host.mounts[0].component;
736
+ assert.doesNotMatch(frameText(view), /t6-outside-odd/);
737
+ view.handleInput('a');
738
+ // An owned worktree's delta is a witness that this was not just the pre-reload frame.
739
+ await waitFor(() => frameText(view).includes('t6-witness-odd'), 'all-mode reload');
740
+ assert.match(frameText(view), /t6-outside-odd/);
741
+ } finally {
742
+ await closePanel(host, pending);
743
+ }
744
+ });
745
+
746
+ test('T6 verifier: a superseded r cannot reset preview scroll (S11/D2)', async () => {
747
+ const loaded = await load();
748
+ const repo = makeRepo();
749
+ const linked = addWorktree(repo, 'wt-t6-scroll');
750
+ const target = writeTask(linked, 't6-long', '# Long document\n\n'
751
+ + Array.from({ length: 160 }, (_, i) => `Paragraph ${i}\n\n`).join(''));
752
+ const host = mountHost();
753
+ const observed = observeGit(loaded.mod);
754
+ const deferred = deferGroups(loaded.mod);
755
+ const pending = loaded.commands.get('odd').handler(target, ctxFor(linked, host, [linked]));
756
+ try {
757
+ await waitFor(() => host.mounts.length === 1, 'mount');
758
+ await waitForRankedListing(observed, [repo]);
759
+ const view = host.mounts[0].component;
760
+ deferred.arm();
761
+ view.handleInput('r');
762
+ const old = await deferred.real(deferred.pending[0].input);
763
+ view.handleInput('r');
764
+ const fresh = await deferred.real(deferred.pending[1].input);
765
+ observed.clear();
766
+ deferred.pending[1].resolve(fresh);
767
+ await waitForRankedListing(observed, [repo]);
768
+ // T12/F1: the clamp measures the body the LAST frame painted, so a host
769
+ // paints a frame before the reader can press a key — this renders that
770
+ // frame. Pressing `end` against a view no frame ever painted budgets one
771
+ // row, which a real host never does, and the reading position it reports
772
+ // is then corrected by the next frame.
773
+ frameText(view);
774
+ view.handleInput('end');
775
+ const scroll = view.state.scroll;
776
+ const frame = frameText(view);
777
+ assert.ok(scroll > 0);
778
+ deferred.pending[0].resolve(old);
779
+ await new Promise(resolve => setTimeout(resolve, 150));
780
+ assert.equal(view.state.scroll, scroll);
781
+ assert.equal(frameText(view), frame);
782
+ } finally {
783
+ deferred.restore();
784
+ observed.restore();
785
+ await closePanel(host, pending);
786
+ }
787
+ });
788
+
789
+ test('T6 verifier: r reads worktrees registered after the panel opened (S13)', async () => {
790
+ const loaded = await load();
791
+ const repo = makeRepo();
792
+ const linked = addWorktree(repo, 'wt-t6-new-registration');
793
+ writeTask(linked, 'new-t6-odd', '# Newly registered worktree\n');
794
+ const host = mountHost();
795
+ const roots = [];
796
+ const ctx = ctxFor(linked, host, roots);
797
+ const observed = observeGit(loaded.mod);
798
+ const pending = loaded.commands.get('odd').handler('', ctx);
799
+ try {
800
+ await waitFor(() => host.mounts.length === 1, 'mount');
801
+ await waitForRankedListing(observed, [repo]);
802
+ const view = host.mounts[0].component;
803
+ assert.doesNotMatch(frameText(view), /new-t6-odd/);
804
+ roots.push(linked);
805
+ observed.clear();
806
+ view.handleInput('r');
807
+ await waitForRankedListing(observed, [repo]);
808
+ assert.match(frameText(view), /new-t6-odd/);
809
+ } finally {
810
+ observed.restore();
811
+ await closePanel(host, pending);
812
+ }
813
+ });
814
+ });
815
+
816
+ describe('the ODD panel is not gated by Worktrees+ (corrected S7)', () => {
817
+ test('with the module OFF the command, its grouping, `a` and a target all still work', async () => {
818
+ const loaded = await load({ worktrees: false });
819
+ const observed = observeGit(loaded.mod);
820
+ try {
821
+ assert.ok(loaded.commands.has('odd'), '/odd is registered whatever the module says');
822
+ assert.equal(loaded.commands.has('warp'), false, 'the fixture really loaded with Worktrees+ off');
823
+ const repo = makeRepo();
824
+ const registered = addWorktree(repo, 'wt-a');
825
+ const other = addWorktree(repo, 'wt-b');
826
+ const target = writeTask(registered, 'a-only', '# body of a-only\n');
827
+ writeTask(other, 'b-only', '# body of b-only\n');
828
+ const host = mountHost();
829
+ const ctx = ctxFor(repo, host, [registered]);
830
+
831
+ const pending = loaded.commands.get('odd').handler(target, ctx);
832
+ pending.catch(() => {});
833
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
834
+ const component = host.mounts[0].component;
835
+ assert.deepEqual(host.notifications, []);
836
+ assert.match(frameText(component), /\u25be wt-a/);
837
+ assert.match(frameText(component), /body of a-only/);
838
+ assert.ok(!frameText(component).includes('wt-b'), 'the scope is still the registered set');
839
+
840
+ observed.clear();
841
+ component.handleInput('a');
842
+ await waitFor(() => frameText(component).includes('wt-b'), '`a` still shows every worktree');
843
+
844
+ await closePanel(host, pending);
845
+ } finally {
846
+ observed.restore();
847
+ }
848
+ });
849
+ });
850
+
851
+ // T12 (S11): the footer hint describes the listing that is DRAWN. The mode the
852
+ // reader asked for is a request until its git read is APPLIED, so a held all-mode
853
+ // load must not make the footer claim a scope the panel is not showing.
854
+ test('T6 independent: while an all-mode read is held the hint still matches the drawn scope (S11/R2)', async () => {
855
+ const loaded = await load();
856
+ const repo = makeRepo();
857
+ const other = addWorktree(repo, 'held-all');
858
+ writeTask(other, 'visible-in-all', '# Visible in all\n');
859
+ const host = mountHost();
860
+ const pending = loaded.commands.get('odd').handler('', ctxFor(repo, host, []));
861
+ const delayed = deferGroups(loaded.mod);
862
+ try {
863
+ await waitFor(() => host.mounts.length === 1, 'mount');
864
+ const v = host.mounts[0].component;
865
+ delayed.arm();
866
+ v.handleInput('a');
867
+ await waitFor(() => delayed.pending.length === 1, 'held all-mode read');
868
+ assert.doesNotMatch(frameText(v), /visible-in-all/);
869
+ assert.match(frameText(v), /a all worktrees/);
870
+ delayed.pending[0].resolve(await delayed.real(delayed.pending[0].input));
871
+ await waitFor(() => frameText(v).includes('visible-in-all'), 'all-mode result');
872
+ assert.match(frameText(v), /a session only/);
873
+ } finally {
874
+ for (const read of delayed.pending) read.resolve([]);
875
+ delayed.restore();
876
+ await closePanel(host, pending);
877
+ }
878
+ });
879
+
880
+ // T12 (S10, S11): ONE generation orders every load that can land on the panel —
881
+ // the startup ranking included. A rank that started before an `a` reload is
882
+ // superseded by it, so its late answer must not replace the newer listing.
883
+ test('T6 independent: a late initial rank cannot replace a newer all-mode listing (S10/S11/R2)', async () => {
884
+ const loaded = await load();
885
+ const repo = makeRepo();
886
+ const other = addWorktree(repo, 'rank-witness');
887
+ writeTask(other, 'all-witness', '# All mode witness\n');
888
+ const host = mountHost();
889
+ const docs = loaded.mod.libModule('odd-docs.js');
890
+ const original = docs.listOddDocsAsync;
891
+ let release;
892
+ docs.listOddDocsAsync = async (...args) => {
893
+ const old = await original(...args);
894
+ await new Promise(resolve => { release = resolve; });
895
+ return old;
896
+ };
897
+ const pending = loaded.commands.get('odd').handler('', ctxFor(repo, host, []));
898
+ try {
899
+ await waitFor(() => host.mounts.length === 1 && release, 'held initial ranking');
900
+ const v = host.mounts[0].component;
901
+ writeTask(repo, 'late-main', '# Added while ranking\n');
902
+ v.handleInput('a');
903
+ await waitFor(() => /all-witness/.test(frameText(v)) && /late-main/.test(frameText(v)), 'new all-mode frame');
904
+ const before = frameText(v);
905
+ release();
906
+ await new Promise(resolve => setImmediate(resolve));
907
+ assert.equal(frameText(v), before);
908
+ } finally {
909
+ release?.();
910
+ docs.listOddDocsAsync = original;
911
+ await closePanel(host, pending);
912
+ }
913
+ });
914
+
915
+ // T12 (S13): the degraded select menu answers the SAME scope the panel draws —
916
+ // the loaded groups — so a session checkout that is not one of them can never
917
+ // leak its private documents into it.
918
+ test('T6 independent: the select fallback excludes a document in the unregistered current worktree (S13)', async () => {
919
+ const loaded = await load();
920
+ const repo = makeRepo();
921
+ const linked = addWorktree(repo, 'fallback-linked');
922
+ writeTask(linked, 'local-private', '# Only in the linked checkout\n');
923
+ const host = mountHost();
924
+ const menus = [];
925
+ delete host.ui.custom;
926
+ host.ui.select = (title, choices) => { menus.push([title, choices]); };
927
+ await loaded.commands.get('odd').handler('', ctxFor(linked, host, []));
928
+ assert.equal(menus.length, 1);
929
+ assert.equal(menus[0][0], 'Odd documents');
930
+ assert.deepEqual(menus[0][1].slice().sort(), ['main-one', 'main-two']);
931
+ });
932
+
933
+ test('T6 round 4: latest r publishes the hint with the pending a scope (S11)', async () => {
934
+ const e = await load();
935
+ const repo = makeRepo();
936
+ const linked = addWorktree(repo, 'linked');
937
+ writeTask(linked, 'all-witness', '# All-worktree witness\n');
938
+ const host = mountHost();
939
+ const d = deferGroups(e.mod);
940
+ const pending = e.commands.get('odd').handler('', ctxFor(linked, host, []));
941
+ try {
942
+ await waitFor(() => host.mounts.length, 'mount');
943
+ const v = host.mounts[0].component;
944
+ d.arm();
945
+ v.handleInput('a');
946
+ v.handleInput('r');
947
+ await waitFor(() => d.pending.length === 2, 'both requests held');
948
+ d.pending[1].resolve(await d.real(d.pending[1].input));
949
+ await waitFor(() => /all-witness/.test(frameText(v)), 'latest r result');
950
+ assert.match(frameText(v), /a session only/);
951
+ } finally {
952
+ for (const read of d.pending) read.resolve(null);
953
+ d.restore();
954
+ await closePanel(host, pending);
955
+ }
956
+ });
957
+
958
+ test('T6 round 4: a failed all-worktree Git read keeps drawn rows and hint (S11/S13)', async () => {
959
+ const e = await load();
960
+ const repo = makeRepo();
961
+ const linked = addWorktree(repo, 'linked');
962
+ const registered = addWorktree(repo, 'registered');
963
+ writeTask(linked, 'linked-private', '# Private\n');
964
+ writeTask(registered, 'session-witness', '# Registered\n');
965
+ const g = e.mod.libModule('worktree-git.js');
966
+ const run = g.runArgvAsync;
967
+ let failedRead;
968
+ const host = mountHost();
969
+ const observed = observeGit(e.mod);
970
+ const pending = e.commands.get('odd').handler('', ctxFor(linked, host, [registered]));
971
+ try {
972
+ await waitFor(() => host.mounts.length, 'mount');
973
+ await waitForRankedListing(observed, [repo]);
974
+ const v = host.mounts[0].component;
975
+ const before = frameText(v);
976
+ assert.match(before, /session-witness/);
977
+ g.runArgvAsync = (bin, args, opts) => args.includes('worktree') && args.includes('list')
978
+ ? (failedRead = run(bin, ['worktree', 'list', '--t6-invalid-option'], opts))
979
+ : run(bin, args, opts);
980
+ v.handleInput('a');
981
+ await waitFor(() => Boolean(failedRead), 'worktree list started');
982
+ assert.notEqual((await failedRead).status, 0);
983
+ await new Promise(resolve => setImmediate(resolve));
984
+ assert.equal(frameText(v), before);
985
+ } finally {
986
+ g.runArgvAsync = run;
987
+ await closePanel(host, pending);
988
+ }
989
+ });
990
+
991
+ test('T6 round 4: a listed absolute target with a dot component opens that document (S6)', async () => {
992
+ const e = await load();
993
+ const repo = makeRepo();
994
+ const linked = addWorktree(repo, 'linked');
995
+ writeTask(linked, 'precise target', '# Precisely selected body\n');
996
+ const host = mountHost();
997
+ const pending = e.commands.get('odd').handler(`${linked}/./odd/tasks/precise target.md`, ctxFor(repo, host, [linked]));
998
+ try {
999
+ await waitFor(() => host.mounts.length, 'mount');
1000
+ assert.deepEqual(host.notifications, []);
1001
+ assert.match(frameText(host.mounts[0].component), /Precisely selected body/);
1002
+ } finally {
1003
+ await closePanel(host, pending);
1004
+ }
1005
+ });
1006
+
1007
+ test('T6 round 4: selecting a registered duplicate-name fallback entry identifies its path (S6/S13)', async () => {
1008
+ const e = await load();
1009
+ const repo = makeRepo();
1010
+ const linked = addWorktree(repo, 'linked');
1011
+ const target = writeTask(linked, 'main-one', '# Linked copy\n');
1012
+ const host = mountHost();
1013
+ host.ui.custom = () => Promise.reject(new Error('no overlay'));
1014
+ host.ui.select = (_title, choices) => choices[choices.length - 1];
1015
+ await e.commands.get('odd').handler('', ctxFor(linked, host, [linked]));
1016
+ assert.deepEqual(host.notifications, [['info', target]]);
1017
+ });
1018
+
1019
+ // T13 (S11/S13/D2): the ONE-load/ONE-apply invariant, sampled exhaustively
1020
+ // instead of by hand. Every load the panel can land — the startup rank, an `a`, an
1021
+ // `r`, a second `a` — is held, then released in EVERY order. After each release
1022
+ // the drawn rows, the footer hint and the applied scope must describe the same
1023
+ // LATEST applied load, and a superseded answer must change nothing at all.
1024
+ test('T6 round 4: every release order leaves the latest applied load (S11/S13/D2)', async () => {
1025
+ const e = await load();
1026
+ const repo = makeRepo();
1027
+ const registered = addWorktree(repo, 'registered');
1028
+ const other = addWorktree(repo, 'other');
1029
+ writeTask(registered, 'registered-only', '# Registered delta\n');
1030
+ writeTask(other, 'other-only', '# Other delta\n');
1031
+
1032
+ // The two models the panel can apply: the session's registered set and every
1033
+ // worktree. They really differ, so a stale all-mode answer is visible.
1034
+ const model = deferGroups(e.mod);
1035
+ const sessionModel = await model.real({ repoRoot: repo, roots: [registered] });
1036
+ const allModel = await model.real({ repoRoot: repo, all: true });
1037
+ model.restore();
1038
+ assert.equal(sessionModel.length, 2, 'main plus the registered worktree');
1039
+ assert.equal(allModel.length, 3, 'main plus every worktree');
1040
+
1041
+ const permutationsOf = (items) => (items.length <= 1 ? [items] : items.flatMap((item, index) => (
1042
+ permutationsOf([...items.slice(0, index), ...items.slice(index + 1)]).map((rest) => [item, ...rest])
1043
+ )));
1044
+ const plans = [
1045
+ { order: ['rank', 'a1', 'r', 'a2'], latest: 'a2' },
1046
+ { order: ['rank', 'a1', 'r'], latest: 'r' },
1047
+ ].flatMap((plan) => permutationsOf(plan.order).map((order) => ({ order, latest: plan.latest })));
1048
+
1049
+ const started = Date.now();
1050
+ let releases = 0;
1051
+ for (const plan of plans) {
1052
+ const label = plan.order.join('>');
1053
+ const host = mountHost();
1054
+ const deferred = deferGroups(e.mod);
1055
+ const docs = e.mod.libModule('odd-docs.js');
1056
+ const realList = docs.listOddDocsAsync;
1057
+ let releaseRank = null;
1058
+ let rankHeld = true;
1059
+ // The startup rank is the ONE flat listing held; an `r` that survives its
1060
+ // generation must be allowed to finish its own read.
1061
+ docs.listOddDocsAsync = async (...args) => {
1062
+ const result = await realList(...args);
1063
+ if (rankHeld) {
1064
+ rankHeld = false;
1065
+ await new Promise((resolve) => { releaseRank = resolve; });
1066
+ }
1067
+ return result;
1068
+ };
1069
+ const pending = e.commands.get('odd').handler('', ctxFor(repo, host, [registered]));
1070
+ pending.catch(() => {});
1071
+ try {
1072
+ await waitFor(() => host.mounts.length === 1 && releaseRank !== null, `${label}: mount and held rank`);
1073
+ const view = host.mounts[0].component;
1074
+ deferred.arm();
1075
+ view.handleInput('a');
1076
+ await waitFor(() => deferred.pending.length === 1, `${label}: the first a is held`);
1077
+ view.handleInput('r');
1078
+ await waitFor(() => deferred.pending.length === 2, `${label}: the r is held`);
1079
+ if (plan.order.includes('a2')) {
1080
+ view.handleInput('a');
1081
+ await waitFor(() => deferred.pending.length === 3, `${label}: the second a is held`);
1082
+ }
1083
+
1084
+ const release = (kind) => {
1085
+ if (kind === 'rank') {
1086
+ releaseRank();
1087
+ return;
1088
+ }
1089
+ if (kind === 'a1') deferred.pending[0].resolve(allModel);
1090
+ else if (kind === 'r') deferred.pending[1].resolve(allModel);
1091
+ else deferred.pending[2].resolve(sessionModel);
1092
+ };
1093
+
1094
+ let expectedAll = false;
1095
+ for (const kind of plan.order) {
1096
+ const before = frameText(view);
1097
+ release(kind);
1098
+ if (kind === plan.latest) {
1099
+ expectedAll = kind === 'r';
1100
+ await waitFor(() => {
1101
+ const text = frameText(view);
1102
+ return expectedAll
1103
+ ? /other-only/.test(text) && /a session only/.test(text)
1104
+ : !/other-only/.test(text) && /a all worktrees/.test(text);
1105
+ }, `${label}: ${kind} applied`);
1106
+ } else {
1107
+ await new Promise((resolve) => setImmediate(resolve));
1108
+ assert.equal(frameText(view), before, `${label}: the superseded ${kind} changed nothing`);
1109
+ }
1110
+ const text = frameText(view);
1111
+ assert.equal(/other-only/.test(text), expectedAll,
1112
+ `${label}: the drawn rows follow the latest applied load`);
1113
+ assert.match(text, expectedAll ? /a session only/ : /a all worktrees/,
1114
+ `${label}: the hint describes that same applied load`);
1115
+ assert.match(text, /registered-only/, `${label}: the session delta is drawn in both modes`);
1116
+ releases += 1;
1117
+ }
1118
+ await new Promise((resolve) => setImmediate(resolve));
1119
+ const settled = frameText(view);
1120
+ assert.equal(/other-only/.test(settled), expectedAll, `${label}: nothing stale lands afterwards`);
1121
+ assert.match(settled, expectedAll ? /a session only/ : /a all worktrees/, `${label}: the final hint`);
1122
+ } finally {
1123
+ for (const read of deferred.pending) read.resolve(sessionModel);
1124
+ if (releaseRank !== null) releaseRank();
1125
+ deferred.restore();
1126
+ docs.listOddDocsAsync = realList;
1127
+ await closePanel(host, pending);
1128
+ }
1129
+ }
1130
+ const elapsed = Date.now() - started;
1131
+ assert.equal(releases, 114, 'every release of both event sets was checked (24×4 + 6×3)');
1132
+ assert.ok(elapsed < 120_000, `bounded permutations stay fast (${elapsed} ms)`);
1133
+ });
1134
+
1135
+ // ---------------------------------------------------------------------------
1136
+ // T15 (odd-rail-section, L11): the round-5 verifier's RED probes for the three
1137
+ // defects this unit closes. They are ported here with this suite's helper names
1138
+ // and every assertion kept as the verifier wrote it:
1139
+ //
1140
+ // * E1/S11: ONE applied scope. After a failed toggle the retry must ask the
1141
+ // scope that FAILED, in every release order of every event set.
1142
+ // * E2/S13: a cold `/odd` whose `git worktree list` fails offers MAIN's own
1143
+ // documents only — never the session checkout's when that checkout is not
1144
+ // main — and refuses a private target instead of mounting it.
1145
+ // * E5/S13: two registered worktrees sharing a basename draw two distinct
1146
+ // labels and each selection reports its OWN document.
1147
+ // * B4: the degraded menu is `listing.menu` — the panel list flattened, in one
1148
+ // order, with path identity.
1149
+ // ---------------------------------------------------------------------------
1150
+
1151
+ const { AsyncLocalStorage } = require('node:async_hooks');
1152
+ const { setImmediate: tick } = require('node:timers/promises');
1153
+
1154
+ const doOdd = (e, raw, ctx) => e.commands.get('odd').handler(raw, ctx);
1155
+ const isList = (a) => a.includes('worktree') && a.includes('list');
1156
+ const deferred = () => { let release; const p = new Promise((r) => { release = r; }); return { p, release }; };
1157
+
1158
+ // The handler stays pending until the view closes; this opens it and answers the
1159
+ // component it mounted.
1160
+ const openPanel = async (e, host, ctx, raw = '') => {
1161
+ const n = host.notifications.length;
1162
+ const p = doOdd(e, raw, ctx);
1163
+ p.catch(() => {});
1164
+ await waitFor(() => host.mounts.length
1165
+ || host.notifications.slice(n).some(([level]) => level === 'error'), 'overlay or refusal');
1166
+ assert.equal(host.mounts.length, 1, JSON.stringify(host.notifications));
1167
+ return { p, v: host.mounts[0].component };
1168
+ };
1169
+
1170
+ // A worktree Git knows and the package does NOT own: a sibling directory.
1171
+ function outside(repo, prefix, basename, branch) {
1172
+ const parent = path.join(path.dirname(repo), path.basename(repo) + '-' + prefix);
1173
+ fs.mkdirSync(parent, { recursive: true });
1174
+ const root = path.join(parent, basename);
1175
+ git(repo, ['worktree', 'add', '-b', branch, root, 'main']);
1176
+ return root;
1177
+ }
1178
+
1179
+ function perms(plan) {
1180
+ return plan.length
1181
+ ? plan.flatMap((name, i) => perms(plan.filter((_, j) => i !== j)).map((p) => [name, ...p]))
1182
+ : [[]];
1183
+ }
1184
+
1185
+ // The frame the E1 probe measures: the registered witness is always there, the
1186
+ // outside one only in the all-worktrees mode, and the hint names that mode.
1187
+ function markFrame(v, all) {
1188
+ const text = frameText(v);
1189
+ assert.match(text, /registered-witness/);
1190
+ assert.equal(text.includes('outside-witness'), all, text);
1191
+ assert.ok(text.includes(all ? 'a session only' : 'a all worktrees'), text);
1192
+ }
1193
+
1194
+ // The degraded select menu: no overlay, so the command falls back to `select`.
1195
+ async function chooseMenu(e, cwd, roots, select, reject = false) {
1196
+ const h = mountHost();
1197
+ let labels;
1198
+ if (reject) h.ui.custom = () => Promise.reject(new Error('no overlay'));
1199
+ else delete h.ui.custom;
1200
+ h.ui.select = (title, choices) => {
1201
+ assert.equal(title, 'Odd documents');
1202
+ labels = choices.slice();
1203
+ return select(choices);
1204
+ };
1205
+ await doOdd(e, '', ctxFor(cwd, h, roots));
1206
+ return { labels, notifications: h.notifications };
1207
+ }
1208
+
1209
+ test('E1: every release order and latest Git failure, real reads under both CWDs', { timeout: 240000 }, async (t) => {
1210
+ const e = await load();
1211
+ const repo = makeRepo(), reg = addWorktree(repo, 'registered');
1212
+ const other = outside(repo, 'outside', 'elsewhere', 'feat/elsewhere');
1213
+ writeTask(reg, 'registered-witness', '# Registered');
1214
+ writeTask(other, 'outside-witness', '# Outside');
1215
+ const g = e.mod.libModule('worktree-git.js'), realRun = g.runArgvAsync;
1216
+ const vlib = e.mod.libModule('odd-view.js'), realView = vlib.createOddView;
1217
+ const local = new AsyncLocalStorage();
1218
+ const stats = { runs: 0, releases: 0, gitErrors: 0, retries: 0 };
1219
+ const faults = [];
1220
+ let hooks;
1221
+ vlib.createOddView = (o) => {
1222
+ for (const k of ['onToggleAll', 'reloadDocs']) {
1223
+ const real = o[k];
1224
+ o[k] = (...args) => {
1225
+ const h = local.getStore();
1226
+ h.request = args;
1227
+ const p = real(...args);
1228
+ p.then(h.done.release, h.done.release);
1229
+ return p;
1230
+ };
1231
+ }
1232
+ const v = realView(o);
1233
+ const apply = v.applyGroups;
1234
+ v.applyGroups = (groups, scope) => {
1235
+ hooks.applied.push({
1236
+ scope,
1237
+ all: groups.some((q) => q.docs.some((d) => d.name === 'outside-witness')),
1238
+ names: groups.flatMap((q) => q.docs.map((d) => d.name)),
1239
+ });
1240
+ return apply(groups, scope);
1241
+ };
1242
+ return v;
1243
+ };
1244
+ g.runArgvAsync = (bin, args, opts) => {
1245
+ const h = local.getStore();
1246
+ if (!h) return realRun(bin, args, opts);
1247
+ h.calls.push({ args, cwd: opts.cwd });
1248
+ if (h.started) return realRun(bin, args, opts);
1249
+ h.started = true;
1250
+ if (h !== hooks.rank) assert.ok(isList(args), args.join(' '));
1251
+ return h.gate.p.then(async () => {
1252
+ const result = await realRun(bin, h.fail ? ['worktree', 'list', '--invalid-t6-option'] : args, opts);
1253
+ if (h.fail) { assert.notEqual(result.status, 0); stats.gitErrors++; }
1254
+ return result;
1255
+ });
1256
+ };
1257
+ const docs = e.mod.libModule('odd-docs.js'), realDocs = docs.listOddDocsAsync;
1258
+ docs.listOddDocsAsync = async (root, opts) => {
1259
+ const h = local.getStore() ?? hooks?.rank;
1260
+ const result = await realDocs(root, {
1261
+ ...opts,
1262
+ runAsync: (bin, args, cwd) => {
1263
+ if (h === hooks.rank && h && !h.started) {
1264
+ h.started = true;
1265
+ return h.gate.p.then(() => realRun(bin, args, { cwd }));
1266
+ }
1267
+ return realRun(bin, args, { cwd });
1268
+ },
1269
+ });
1270
+ if (h && h === hooks.rank) setImmediate(h.done.release);
1271
+ return result;
1272
+ };
1273
+ const key = (id) => id[0];
1274
+ const hold = (id, fail) => ({ id, fail, calls: [], gate: deferred(), done: deferred() });
1275
+ const schedules = [['rank', 'a1', 'r1', 'a2'], ['a1', 'r1', 'r2'], ['r1', 'a1'], ['a1', 'a2', 'r1', 'r2']];
1276
+ try {
1277
+ for (const cwd of [repo, other]) {
1278
+ for (const plan of schedules) {
1279
+ for (const order of perms(plan)) {
1280
+ for (const failure of [false, true]) {
1281
+ const latest = plan.at(-1);
1282
+ const host = mountHost(), ctx = ctxFor(cwd, host, [reg]);
1283
+ const byId = new Map(plan.map((id) => [id, hold(id, failure && id === latest)]));
1284
+ hooks = { applied: [], rank: byId.get('rank') };
1285
+ const o = await openPanel(e, host, ctx);
1286
+ try {
1287
+ if (!hooks.rank) await waitFor(() => hooks.applied.length === 1, 'unheld startup rank');
1288
+ else await waitFor(() => hooks.rank.started, 'held startup rank');
1289
+ hooks.applied.length = 0;
1290
+ let requested = false;
1291
+ for (const id of plan.filter((x) => x !== 'rank')) {
1292
+ const h = byId.get(id);
1293
+ if (key(id) === 'a') requested = !requested;
1294
+ local.run(h, () => o.v.handleInput(key(id)));
1295
+ await waitFor(() => h.started, 'held ' + id);
1296
+ if (key(id) === 'a') assert.deepEqual(h.request, [requested]);
1297
+ h.all = requested;
1298
+ }
1299
+ markFrame(o.v, false);
1300
+ let all = false;
1301
+ for (const id of order) {
1302
+ const h = byId.get(id), before = frameText(o.v), n = hooks.applied.length;
1303
+ h.gate.release();
1304
+ await h.done.p;
1305
+ await tick();
1306
+ if (id === latest && !failure) {
1307
+ all = h.all;
1308
+ assert.equal(hooks.applied.length, n + 1);
1309
+ assert.deepEqual(hooks.applied.at(-1).scope, { all });
1310
+ assert.equal(hooks.applied.at(-1).all, all);
1311
+ // Verify the scope was exercised by reading the outside checkout itself.
1312
+ assert.equal(h.calls.some((c) => c.cwd === other && c.args.includes('merge-base')), all);
1313
+ } else {
1314
+ assert.equal(hooks.applied.length, n, `unexpected apply after ${id}`);
1315
+ if (!(id === latest && key(id) === 'r')) assert.equal(frameText(o.v), before, `changed after ${id}`);
1316
+ }
1317
+ markFrame(o.v, all);
1318
+ stats.releases++;
1319
+ }
1320
+ if (failure) {
1321
+ const h = hold('retry', false);
1322
+ local.run(h, () => o.v.handleInput(key(latest)));
1323
+ h.gate.release();
1324
+ await h.done.p;
1325
+ await tick();
1326
+ const should = byId.get(latest).all;
1327
+ try {
1328
+ assert.deepEqual(hooks.applied.at(-1)?.scope, { all: should });
1329
+ markFrame(o.v, should);
1330
+ } catch {
1331
+ faults.push(`${path.basename(cwd)} ${plan}/${order}: retry asked ${JSON.stringify(h.request)}, applied ${JSON.stringify(hooks.applied.at(-1)?.scope)}, expected ${should}`);
1332
+ }
1333
+ stats.retries++;
1334
+ }
1335
+ stats.runs++;
1336
+ } finally {
1337
+ await closePanel(host, o.p);
1338
+ }
1339
+ }
1340
+ }
1341
+ }
1342
+ }
1343
+ } finally {
1344
+ docs.listOddDocsAsync = realDocs;
1345
+ g.runArgvAsync = realRun;
1346
+ vlib.createOddView = realView;
1347
+ }
1348
+ t.diagnostic(JSON.stringify(stats));
1349
+ t.diagnostic(`retry violations: ${faults.length}; ${faults.slice(0, 4).join('; ')}`);
1350
+ assert.equal(faults.length, 0);
1351
+ });
1352
+
1353
+ test('E2/S13: overlay startup during a real list failure (separate from legacy select menu)', async (t) => {
1354
+ const e = await load();
1355
+ const repo = makeRepo(), linked = addWorktree(repo, 'unregistered-overlay');
1356
+ writeTask(linked, 'witness-private', '# Distinct private body');
1357
+ const g = e.mod.libModule('worktree-git.js'), run = g.runArgvAsync;
1358
+ let rc;
1359
+ g.runArgvAsync = async (bin, args, opts) => {
1360
+ const r = await run(bin, isList(args) ? ['worktree', 'list', '--strictly-invalid-t6'] : args, opts);
1361
+ if (isList(args)) rc = r.status;
1362
+ return r;
1363
+ };
1364
+ const h = mountHost(), ctx = ctxFor(linked, h, []);
1365
+ const pending = doOdd(e, '', ctx);
1366
+ let answered = false;
1367
+ pending.then(() => { answered = true; });
1368
+ try {
1369
+ await waitFor(() => answered || h.mounts.length, 'failed cold start answer');
1370
+ assert.notEqual(rc, 0);
1371
+ assert.ok(rc !== undefined);
1372
+ if (h.mounts.length) {
1373
+ const text = frameText(h.mounts[0].component);
1374
+ t.diagnostic(`Git exit=${rc}; overlay offered path in linked checkout: ${/witness-private/.test(text)}; private preview: ${/Distinct private body/.test(text)}`);
1375
+ assert.doesNotMatch(text, /witness-private|Distinct private body/);
1376
+ }
1377
+ } finally {
1378
+ g.runArgvAsync = run;
1379
+ await closePanel(h, pending);
1380
+ }
1381
+ });
1382
+
1383
+ test('E2/S13: no model and no main documents opens the empty panel, never this checkout', async () => {
1384
+ const e = await load();
1385
+ const repo = makeRepo(), linked = addWorktree(repo, 'cold-empty');
1386
+ // MAIN holds no document at all, and the session's linked checkout is not
1387
+ // registered, so its private document is the only one on disk.
1388
+ fs.rmSync(path.join(repo, 'odd'), { recursive: true, force: true });
1389
+ writeTask(linked, 'linked-private', '# Private body');
1390
+ const g = e.mod.libModule('worktree-git.js'), run = g.runArgvAsync;
1391
+ g.runArgvAsync = (bin, args, opts) => run(bin, isList(args) ? ['worktree', 'list', '--strictly-invalid-t6'] : args, opts);
1392
+ const h = mountHost();
1393
+ const pending = doOdd(e, '', ctxFor(linked, h, []));
1394
+ try {
1395
+ await waitFor(() => h.mounts.length || h.notifications.length, 'cold answer');
1396
+ assert.deepEqual(h.notifications, [], 'the command is not refused: it opens the empty panel');
1397
+ assert.equal(h.mounts.length, 1);
1398
+ const text = frameText(h.mounts[0].component);
1399
+ assert.doesNotMatch(text, /linked-private|Private body/);
1400
+ assert.match(text, /no odd documents/, 'the view\u2019s own empty copy');
1401
+ assert.match(text, /0 documents/, 'and an empty listing');
1402
+ } finally {
1403
+ g.runArgvAsync = run;
1404
+ await closePanel(h, pending);
1405
+ }
1406
+ });
1407
+
1408
+ // ---------------------------------------------------------------------------
1409
+ // T17/F2 (L11): the PRINCIPAL root is never assumed. A repository whose git dir is
1410
+ // not its checkout (`git init --separate-git-dir`) has a common dir whose basename
1411
+ // is NOT `.git`, so the old derivation fell back to "this session's checkout" — and
1412
+ // a session standing in a LINKED checkout then had that checkout's private document
1413
+ // offered as main's whenever `git worktree list` failed. The principal is now read
1414
+ // from the same listing the model reads, and an undeterminable one is NO main root:
1415
+ // the degraded panel offers main's documents or nothing, never a private copy.
1416
+ //
1417
+ // The standard single-root repository keeps today's answer byte for byte: the
1418
+ // pinned case below (a failed listing still offers MAIN's own documents).
1419
+ // ---------------------------------------------------------------------------
1420
+ function separateMetadataRepo(tag) {
1421
+ const base = fs.realpathSync(track(fs.mkdtempSync(path.join(os.tmpdir(), `odd-panel-meta-${tag}-`))));
1422
+ const meta = path.join(base, 'git-meta');
1423
+ const root = path.join(base, 'checkout');
1424
+ git(base, ['init', '-b', 'main', '--separate-git-dir', meta, root]);
1425
+ git(root, ['config', 'user.email', 'test@example.test']);
1426
+ git(root, ['config', 'user.name', 'Test']);
1427
+ const tasks = path.join(root, 'odd', 'tasks');
1428
+ fs.mkdirSync(tasks, { recursive: true });
1429
+ fs.writeFileSync(path.join(tasks, 'main-one.md'), '# body of main-one\n');
1430
+ git(root, ['add', '-A']);
1431
+ git(root, ['commit', '-m', 'init']);
1432
+ return { base, meta, root };
1433
+ }
1434
+
1435
+ test('F2: a failed listing in a linked checkout of a separate git dir offers no private document', async (t) => {
1436
+ const e = await load();
1437
+ const repo = separateMetadataRepo('linked');
1438
+ const linked = addWorktree(repo.root, 'metadata-linked');
1439
+ const priv = writeTask(linked, 'witness-private', '# Distinct private body');
1440
+ const g = e.mod.libModule('worktree-git.js'), run = g.runArgvAsync;
1441
+ let rc;
1442
+ g.runArgvAsync = async (bin, args, opts) => {
1443
+ const answer = await run(bin, isList(args) ? ['worktree', 'list', '--strictly-invalid-t7'] : args, opts);
1444
+ if (isList(args)) rc = answer.status;
1445
+ return answer;
1446
+ };
1447
+ const listHost = mountHost();
1448
+ const banPending = doOdd(e, '', ctxFor(linked, listHost, []));
1449
+ try {
1450
+ await waitFor(() => listHost.mounts.length || listHost.notifications.length, 'cold answer');
1451
+ assert.equal(rc, 129);
1452
+ assert.equal(listHost.mounts.length, 1, 'the command opens the panel, it is not an error');
1453
+ const text = frameText(listHost.mounts[0].component);
1454
+ t.diagnostic(`overlay in a linked checkout with separate metadata: private offered = ${/witness-private|Distinct private body/.test(text)}`);
1455
+ assert.doesNotMatch(text, /witness-private|Distinct private body/,
1456
+ 'the linked checkout is not main: its private document is neither offered nor previewed');
1457
+ } finally {
1458
+ await closePanel(listHost, banPending);
1459
+ }
1460
+ const targetHost = mountHost();
1461
+ const targetPending = doOdd(e, priv, ctxFor(linked, targetHost, []));
1462
+ try {
1463
+ await waitFor(() => targetHost.mounts.length || targetHost.notifications.length, 'target answer');
1464
+ assert.equal(targetHost.mounts.length, 0, 'and an absolute target to it is not mounted');
1465
+ assert.deepEqual(targetHost.notifications, [['error', `Unknown option "${priv}". Use /odd.`]]);
1466
+ } finally {
1467
+ g.runArgvAsync = run;
1468
+ await closePanel(targetHost, targetPending);
1469
+ }
1470
+ });
1471
+
1472
+ test('F2 preserve: a standard repository still offers MAIN\u2019s documents when the listing fails', async () => {
1473
+ const e = await load();
1474
+ const repo = makeRepo(), linked = addWorktree(repo, 'std-linked');
1475
+ writeTask(linked, 'std-private', '# Linked private');
1476
+ const g = e.mod.libModule('worktree-git.js'), run = g.runArgvAsync;
1477
+ g.runArgvAsync = (bin, args, opts) => run(bin, isList(args) ? ['worktree', 'list', '--strictly-invalid-t7'] : args, opts);
1478
+ const h = mountHost(), menus = [];
1479
+ delete h.ui.custom;
1480
+ h.ui.select = (title, choices) => { menus.push([title, choices]); };
1481
+ try {
1482
+ await doOdd(e, '', ctxFor(linked, h, []));
1483
+ assert.equal(menus.length, 1, 'the degraded menu still answers');
1484
+ assert.deepEqual(menus[0][1].slice().sort(), ['main-one', 'main-two'],
1485
+ 'main\u2019s own documents, never the linked checkout\u2019s');
1486
+ } finally {
1487
+ g.runArgvAsync = run;
1488
+ }
1489
+ });
1490
+
1491
+ // ---------------------------------------------------------------------------
1492
+ // T17/F3 (L11): the panel draws the LISTING's label, not the model's raw name. Two
1493
+ // registered checkouts that share a basename drew `collision` twice (the label the
1494
+ // listing had already made unique never reached the frame), so the human could not
1495
+ // tell the rows apart. The label is derived once, in lib/odd-listing.js, and the
1496
+ // wiring now hands it over with every document; keyboard selection still resolves
1497
+ // each row to its own absolute path, so each copy opens its own body.
1498
+ //
1499
+ // A listing WITHOUT labels keeps the view's current behaviour: the standard
1500
+ // single-root repository paints plain names, exactly as before (pinned below).
1501
+ // ---------------------------------------------------------------------------
1502
+ // The LEFT pane of a frame: the rows between the frame's own chrome — never the
1503
+ // border lines, the search box or the footer legend.
1504
+ const listCells = (component) => renderedRows(component)
1505
+ .filter((line) => /^\u2502/.test(line))
1506
+ .map((line) => (line.split('\u2502')[1] || ''))
1507
+ .filter((cell) => cell.trim() !== '' && !/^\u203a|^\u2191/.test(cell.trim()));
1508
+ const rowLabels = (component) => listCells(component)
1509
+ .map((cell) => cell.trim().replace(/^\u25b8\s*/, ''))
1510
+ .filter((cell) => cell !== '');
1511
+ const focusedLabel = (component) => {
1512
+ const cell = listCells(component).map((value) => value.trim()).find((value) => value.startsWith('\u25b8'));
1513
+ return cell === undefined ? null : cell.replace(/^\u25b8\s*/, '');
1514
+ };
1515
+ async function focusRow(component, label) {
1516
+ let guard = 0;
1517
+ while (focusedLabel(component) !== label && guard < 40) {
1518
+ component.handleInput('down');
1519
+ guard += 1;
1520
+ }
1521
+ assert.equal(focusedLabel(component), label, `the ${JSON.stringify(label)} row is focusable`);
1522
+ }
1523
+
1524
+ test('F3: two registered checkouts sharing a basename paint two different labels, each opening its own body', async (t) => {
1525
+ const e = await load();
1526
+ const repo = makeRepo();
1527
+ // Two checkouts with the SAME basename under one-letter parents, so the labels
1528
+ // the listing derives differ where the list pane can paint them.
1529
+ const base = fs.realpathSync(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-panel-labels-'))));
1530
+ const linkedAt = (parent, branch) => {
1531
+ const dir = path.join(base, parent);
1532
+ fs.mkdirSync(dir, { recursive: true });
1533
+ const root = path.join(dir, 'same checkout');
1534
+ git(repo, ['worktree', 'add', '-b', branch, root, 'main']);
1535
+ return root;
1536
+ };
1537
+ const a = linkedAt('a', 'feat/first-same');
1538
+ const b = linkedAt('b', 'feat/second-same');
1539
+ writeTask(a, 'collision', '# First copy\n');
1540
+ writeTask(b, 'collision', '# Second copy\n');
1541
+ const labelOf = (root) => `collision (${path.basename(path.dirname(root))}/${path.basename(root)})`;
1542
+ const host = mountHost();
1543
+ const pending = doOdd(e, '', ctxFor(repo, host, [a, b]));
1544
+ try {
1545
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
1546
+ const v = host.mounts[0].component;
1547
+ const text = frameText(v);
1548
+ t.diagnostic(`labels: ${JSON.stringify(rowLabels(v))}`);
1549
+ const painted = rowLabels(v).filter((label) => label.startsWith('collision'));
1550
+ assert.equal(painted.length, 2, `both copies are listed\n${text}`);
1551
+ assert.notEqual(painted[0], painted[1], 'the two rows read differently');
1552
+ assert.deepEqual(painted.slice().sort(), [labelOf(a), labelOf(b)].sort(),
1553
+ 'and they are the labels the ONE listing derived');
1554
+ for (const [root, body] of [[a, /First copy/], [b, /Second copy/]]) {
1555
+ await focusRow(v, labelOf(root));
1556
+ assert.match(frameText(v), body, `${path.basename(path.dirname(root))}: its own body is open`);
1557
+ }
1558
+ } finally {
1559
+ await closePanel(host, pending);
1560
+ }
1561
+ });
1562
+
1563
+ test('F3 preserve: a standard single-root repository still paints plain document names', async () => {
1564
+ const e = await load();
1565
+ const repo = makeRepo();
1566
+ const host = mountHost();
1567
+ const pending = doOdd(e, '', ctxFor(repo, host, []));
1568
+ try {
1569
+ await waitFor(() => host.mounts.length === 1, 'the panel mounts');
1570
+ assert.deepEqual(rowLabels(host.mounts[0].component), ['main-two', 'main-one'],
1571
+ 'unique names keep their exact plain text, in the recency order the panel always used');
1572
+ } finally {
1573
+ await closePanel(host, pending);
1574
+ }
1575
+ });
1576
+
1577
+ // ---------------------------------------------------------------------------
1578
+ // T17/F4 (L11): the target grammar RESOLVES before it validates. The parent check
1579
+ // compared the RAW argument's segments with `odd/tasks`, so `<parent>/odd/tasks/./
1580
+ // <name>.md` and `<parent>/odd/tasks/../tasks/<name>.md` were refused although they
1581
+ // name a listed document — `path.resolve` is the same rule the command's own
1582
+ // document test uses. Nothing else moves: a sibling path that resolves outside
1583
+ // `odd/tasks` keeps the verbatim refusal.
1584
+ // ---------------------------------------------------------------------------
1585
+ test('F4: a listed document reached through `.` or `..` segments opens its own body', async (t) => {
1586
+ const e = await load();
1587
+ const repo = makeRepo();
1588
+ const tasks = path.join(repo, 'odd', 'tasks');
1589
+ // Built by CONCATENATION: `path.join` would collapse the very segments under test.
1590
+ const spellings = [`${tasks}/./main-one.md`, `${tasks}/../tasks/main-one.md`];
1591
+ for (const raw of spellings) {
1592
+ assert.equal(path.resolve(raw), path.join(tasks, 'main-one.md'), `${raw} resolves to the listed document`);
1593
+ assert.notEqual(raw, path.join(tasks, 'main-one.md'), `${raw} keeps its own spelling`);
1594
+ const host = mountHost();
1595
+ const pending = doOdd(e, raw, ctxFor(repo, host, []));
1596
+ pending.catch(() => {});
1597
+ try {
1598
+ await waitFor(() => host.mounts.length || host.notifications.length, `${raw}: an answer`);
1599
+ t.diagnostic(`${raw} => ${host.mounts.length} mount(s), ${JSON.stringify(host.notifications)}`);
1600
+ assert.deepEqual(host.notifications, [], `${raw}: accepted, not refused`);
1601
+ assert.equal(host.mounts.length, 1, `${raw}: the panel opens`);
1602
+ assert.match(frameText(host.mounts[0].component), /body of main-one/, `${raw}: its own body is open`);
1603
+ } finally {
1604
+ await closePanel(host, pending);
1605
+ }
1606
+ }
1607
+ });
1608
+
1609
+ test('F4 preserve: a path that resolves outside odd/tasks is still refused verbatim', async () => {
1610
+ const e = await load();
1611
+ const repo = makeRepo();
1612
+ const tasks = path.join(repo, 'odd', 'tasks');
1613
+ const outsideDoc = path.join(repo, 'odd', 'README.md');
1614
+ fs.writeFileSync(outsideDoc, '# Outside the rule\n');
1615
+ // Both spellings RESOLVE to a real document that is not under `odd/tasks`: the
1616
+ // path rule still refuses them, with the sentence every unknown argument gets.
1617
+ for (const raw of [`${tasks}/../README.md`, `${tasks}/../tasks/./../README.md`]) {
1618
+ assert.equal(path.resolve(raw), outsideDoc, `${raw}: the fixture really resolves outside`);
1619
+ const host = mountHost();
1620
+ await doOdd(e, raw, ctxFor(repo, host, []));
1621
+ assert.equal(host.mounts.length, 0, `${raw}: nothing is mounted`);
1622
+ assert.deepEqual(host.notifications, [['error', `Unknown option "${raw}". Use /odd.`]], raw);
1623
+ }
1624
+ });
1625
+
1626
+ test('E2 proof: a failed listing does not let the overlay open a private target (baseline refuses)', async (t) => {
1627
+ const repo = makeRepo(), linked = addWorktree(repo, 'not-in-scope');
1628
+ const target = writeTask(linked, 'private-direct', '# Excluded private preview');
1629
+ const e = await load(), g = e.mod.libModule('worktree-git.js'), run = g.runArgvAsync;
1630
+ const healthy = mountHost();
1631
+ await doOdd(e, target, ctxFor(linked, healthy, []));
1632
+ assert.equal(healthy.mounts.length, 0);
1633
+ assert.deepEqual(healthy.notifications, [['error', `Unknown option "${target}". Use /odd.`]]);
1634
+ t.diagnostic(`candidate with healthy listing: ${healthy.notifications[0][1]}`);
1635
+ let rc;
1636
+ g.runArgvAsync = async (bin, args, opts) => {
1637
+ const answer = await run(bin, isList(args) ? ['worktree', 'list', '--strictly-invalid-t6'] : args, opts);
1638
+ if (isList(args)) rc = answer.status;
1639
+ return answer;
1640
+ };
1641
+ const h = mountHost();
1642
+ const pending = doOdd(e, target, ctxFor(linked, h, []));
1643
+ try {
1644
+ await waitFor(() => h.mounts.length || h.notifications.length, 'direct command answers');
1645
+ assert.equal(rc, 129);
1646
+ if (h.mounts.length) t.diagnostic(`candidate git exit ${rc}: opened private target and read body = ${/Excluded private preview/.test(frameText(h.mounts[0].component))}`);
1647
+ assert.equal(h.mounts.length, 0);
1648
+ assert.deepEqual(h.notifications, [['error', `Unknown option "${target}". Use /odd.`]]);
1649
+ } finally {
1650
+ g.runArgvAsync = run;
1651
+ await closePanel(h, pending);
1652
+ }
1653
+ });
1654
+
1655
+ test('E5: two registered real worktrees with the same basename cannot select each other', async (t) => {
1656
+ const e = await load();
1657
+ const repo = makeRepo();
1658
+ const a = outside(repo, 'one', 'same checkout', 'feat/first-same');
1659
+ const b = outside(repo, 'two', 'same checkout', 'feat/second-same');
1660
+ const pa = writeTask(a, 'collision', '# First copy'), pb = writeTask(b, 'collision', '# Second copy');
1661
+ assert.ok(git(repo, ['worktree', 'list', '--porcelain']).includes(a));
1662
+ assert.ok(git(repo, ['worktree', 'list', '--porcelain']).includes(b));
1663
+ const selections = [];
1664
+ for (const i of [0, 1]) {
1665
+ const result = await chooseMenu(e, repo, [a, b], (choices) => choices.filter((label) => label.startsWith('collision'))[i]);
1666
+ assert.equal(result.labels.filter((label) => label.startsWith('collision')).length, 2);
1667
+ t.diagnostic(`index ${i}: ${JSON.stringify(result.labels)} => ${JSON.stringify(result.notifications)}; registered candidates ${pa}, ${pb}`);
1668
+ selections.push(result.notifications[0]?.[1]);
1669
+ }
1670
+ assert.deepEqual(selections.sort(), [pa, pb].sort());
1671
+ });
1672
+
1673
+ test('E5: literal legacy label and generated main label both selectable', async (t) => {
1674
+ const e = await load();
1675
+ const repo = makeRepo(), a = addWorktree(repo, 'literal-test');
1676
+ const literal = writeTask(repo, 'main-one (main)', '# Literal');
1677
+ writeTask(a, 'main-one', '# Linked');
1678
+ const result = await chooseMenu(e, repo, [a], (choices) => choices.find((x) => x === 'main-one (main)'));
1679
+ t.diagnostic(JSON.stringify(result));
1680
+ assert.equal(result.labels.filter((x) => x === 'main-one (main)').length, 1);
1681
+ assert.deepEqual(result.notifications, [['info', literal]]);
1682
+ });
1683
+
1684
+ test('B4: the degraded menu is `listing.menu`, in that order, reporting that entry path', async (t) => {
1685
+ const e = await load();
1686
+ const repo = makeRepo();
1687
+ // Two registered worktrees that share a basename: the ad-hoc menu labelling this
1688
+ // unit replaces drew the same label twice here, so one label selected both.
1689
+ const a = outside(repo, 'one', 'same checkout', 'feat/b4-first-same');
1690
+ const b = outside(repo, 'two', 'same checkout', 'feat/b4-second-same');
1691
+ writeTask(a, 'collision', '# First copy');
1692
+ writeTask(b, 'collision', '# Second copy');
1693
+ // The model the command reads for this session, and the ONE listing value the
1694
+ // panel and the menu must both draw from. L11/T16: main's group carries
1695
+ // lib/odd-docs.js's rank (commit recency, then display name) and the listing
1696
+ // PRESERVES it, so the model this test lists from is main's group in that ranked
1697
+ // order — both fixture documents come from ONE commit, so the rank is by name.
1698
+ const groups = await e.mod.libModule('odd-group.js').groupOddDocs({ repoRoot: repo, roots: [a, b] });
1699
+ const rankedMain = (await e.mod.libModule('odd-docs.js').listOddDocsAsync(repo)).docs;
1700
+ const rankedGroups = groups.map((group) => (group && group.isMain === true
1701
+ ? { ...group, docs: rankedMain.map((doc, order) => ({ ...doc, order })) }
1702
+ : group));
1703
+ const listing = e.mod.libModule('odd-listing.js').buildListing({ groups: rankedGroups });
1704
+ assert.equal(listing.menu[0].name, 'main-one',
1705
+ 'the fixture really ranks main-one before main-two (one commit, so by name)');
1706
+ assert.equal(new Set(listing.menu.map((row) => row.label)).size, listing.menu.length,
1707
+ 'the listing really disambiguates the repeated basenames');
1708
+ const result = await chooseMenu(e, repo, [a, b], (choices) => choices[0]);
1709
+ assert.deepEqual(result.labels, listing.menu.map((row) => row.label),
1710
+ 'the menu IS the listing: same labels, same order, main first');
1711
+ assert.deepEqual(result.notifications, [['info', listing.menu[0].path]],
1712
+ 'the first entry opens the document the first row names');
1713
+ // Every index maps to its own entry, never to a name another checkout carries.
1714
+ for (let index = 0; index < listing.menu.length; index += 1) {
1715
+ const picked = await chooseMenu(e, repo, [a, b], (choices) => choices[index]);
1716
+ assert.deepEqual(picked.notifications, [['info', listing.menu[index].path]], `index ${index}`);
1717
+ }
1718
+ // A unique name keeps the plain label the baseline had. L11/T16: the sequence is
1719
+ // main's RANK, which for two documents of one commit is by name — 53ae2b2's menu
1720
+ // read main-one first, not the later mtime's main-two.
1721
+ const plain = await chooseMenu(e, repo, [], (choices) => choices[0]);
1722
+ assert.deepEqual(plain.labels, ['main-one', 'main-two'],
1723
+ 'unique names stay undecorated, in the ranked order main first');
1724
+ t.diagnostic(`menu ${JSON.stringify(result.labels)}`);
1725
+ });
1726
+
1727
+ // L11/T16 (regression): 53ae2b2's degraded menu listed a main checkout's documents
1728
+ // in the order lib/odd-docs.js ranks them — commit recency, then display name — and
1729
+ // this fixture's two documents come from the SAME commit while their mtimes differ
1730
+ // (`makeRepo` stamps main-two LATER). A menu that orders them by mtime reads
1731
+ // main-two first, so picking its first entry opens a different file than the
1732
+ // baseline opened. The listing must PRESERVE the rank main's group is handed,
1733
+ // never re-rank it — and this pin builds the fixture itself, so it reads no git
1734
+ // history and no fixed commit.
1735
+ test('T16: the degraded menu keeps the ranked order, not mtime (L11 regression)', async () => {
1736
+ const e = await load();
1737
+ const repo = makeRepo();
1738
+ const mainOne = path.join(repo, 'odd', 'tasks', 'main-one.md');
1739
+ const mainTwo = path.join(repo, 'odd', 'tasks', 'main-two.md');
1740
+ // The fixture really does have the mtime order that used to leak into the menu,
1741
+ // and one commit behind both documents, so the rank ties on recency.
1742
+ const times = [mainOne, mainTwo].map((doc) => fs.statSync(doc).mtimeMs);
1743
+ assert.ok(times[0] < times[1], 'main-two is the LATER mtime, so a mtime sort reads it first');
1744
+ assert.equal(git(repo, ['log', '--format=%H', '--', 'odd/tasks']).split('\n').filter(Boolean).length, 1,
1745
+ 'both documents come from the one commit, so the rank breaks the tie by name');
1746
+
1747
+ const host = mountHost();
1748
+ delete host.ui.custom;
1749
+ const menus = [];
1750
+ host.ui.select = (title, choices) => {
1751
+ menus.push({ title, choices: choices.slice() });
1752
+ return choices[0];
1753
+ };
1754
+ await e.commands.get('odd').handler('', ctxFor(repo, host, []));
1755
+ assert.equal(menus.length, 1, 'the degraded path answers with one menu');
1756
+ assert.equal(menus[0].title, 'Odd documents');
1757
+ assert.deepEqual(menus[0].choices, ['main-one', 'main-two'],
1758
+ 'the ranked sequence (same commit, so by name) — exactly what 53ae2b2 showed');
1759
+ assert.deepEqual(host.notifications, [['info', mainOne]],
1760
+ 'and the first entry opens main-one, the document the baseline opened');
1761
+ });
1762
+
1763
+ // Append to tools/odd-panel-wiring.test.js. S6/S10/S11/S13, L11.
1764
+ test('separated git dir: healthy linked session still lists real main', async () => {
1765
+ const e = await load(), { root } = separateMetadataRepo('healthy-linked');
1766
+ const linked = addWorktree(root, 'private-linked');
1767
+ fs.unlinkSync(path.join(linked, 'odd/tasks/main-one.md'));
1768
+ writeTask(linked, 'private', '# Not in the session scope');
1769
+ const host = mountHost(), pending = doOdd(e, '', ctxFor(linked, host));
1770
+ try {
1771
+ await waitFor(() => host.mounts.length || host.notifications.length, 'reply');
1772
+ assert.deepEqual(host.notifications, []);
1773
+ assert.equal(host.mounts.length, 1);
1774
+ const frame = frameText(host.mounts[0].component);
1775
+ assert.match(frame, /body of main-one/);
1776
+ assert.doesNotMatch(frame, /Not in the session scope/);
1777
+ } finally { await closePanel(host, pending); }
1778
+ });
1779
+
1780
+ test('separated git dir named .git does not admit documents outside a checkout', async () => {
1781
+ const root = makeRepo(), parent = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-meta-parent-')));
1782
+ git(root, ['init', '--separate-git-dir', path.join(parent, '.git')]);
1783
+ const linked = addWorktree(root, 'private-linked'), e = await load();
1784
+ const unrelated = writeTask(parent, 'not-in-main', '# Not a checkout document');
1785
+ const g = e.mod.libModule('worktree-git.js'), real = g.runArgvAsync;
1786
+ const exits = [];
1787
+ g.runArgvAsync = async (bin, args, opts) => {
1788
+ if (!isList(args)) return real(bin, args, opts);
1789
+ const answer = await real(bin, ['worktree', 'list', '--odd-regression-invalid'], opts);
1790
+ exits.push(answer.status);
1791
+ return answer;
1792
+ };
1793
+ const host = mountHost(), pending = doOdd(e, unrelated, ctxFor(linked, host));
1794
+ try {
1795
+ await waitFor(() => host.mounts.length || host.notifications.length, 'target reply');
1796
+ assert.deepEqual([...new Set(exits)], [129]);
1797
+ assert.equal(host.mounts.length, 0);
1798
+ assert.deepEqual(host.notifications, [['error', `Unknown option "${unrelated}". Use /odd.`]]);
1799
+ } finally { g.runArgvAsync = real; await closePanel(host, pending); }
1800
+ });
1801
+
1802
+ test('round-trip scope toggle preserves ranked order with identical rows', async () => {
1803
+ const e = await load(), root = makeRepo(), host = mountHost();
1804
+ addWorktree(root, 'unchanged');
1805
+ const degraded = await chooseMenu(e, root, [], (labels) => labels[0]);
1806
+ const pending = doOdd(e, '', ctxFor(root, host));
1807
+ try {
1808
+ await waitFor(() => host.mounts.length, 'mount');
1809
+ const view = host.mounts[0].component;
1810
+ await waitFor(() => rowLabels(view).join(',') === 'main-one,main-two', 'ranked order');
1811
+ assert.deepEqual(rowLabels(view), degraded.labels);
1812
+ view.handleInput('a');
1813
+ await waitFor(() => frameText(view).includes('a session only'), 'all applied');
1814
+ view.handleInput('a');
1815
+ await waitFor(() => frameText(view).includes('a all worktrees'), 'session applied');
1816
+ assert.deepEqual(rowLabels(view), degraded.labels);
1817
+ } finally { await closePanel(host, pending); }
1818
+ });
1819
+
1820
+ // S6/F4: pin the corrected normalization rule, not byte spelling.
1821
+ test('doubled separators still identify the listed document', async () => {
1822
+ const e = await load(), root = makeRepo(), host = mountHost();
1823
+ const listed = path.join(root, 'odd/tasks/main-one.md'), raw = `${path.dirname(listed)}//main-one.md`;
1824
+ assert.equal(path.resolve(raw), listed);
1825
+ assert.equal(fs.statSync(raw).ino, fs.statSync(listed).ino);
1826
+ const pending = doOdd(e, raw, ctxFor(root, host));
1827
+ try {
1828
+ await waitFor(() => host.mounts.length || host.notifications.length, 'reply');
1829
+ assert.deepEqual(host.notifications, []);
1830
+ assert.equal(host.mounts.length, 1);
1831
+ assert.match(frameText(host.mounts[0].component), /body of main-one/);
1832
+ } finally { await closePanel(host, pending); }
1833
+ });
1834
+
1835
+ // ---------------------------------------------------------------------------
1836
+ // T19 (odd-rail-section, L13): the ONE round-8 finding that is not gated on a
1837
+ // separated git directory. A symlinked directory under `odd/tasks` makes
1838
+ // `<link>/../<name>.md` name ANOTHER tree's inode: `path.resolve` collapses the
1839
+ // `..` lexically, so a lexical comparison against the listing happily opened the
1840
+ // LOCAL document the spelling claims to be, and the command reported success
1841
+ // while the target the reader named was never the one on screen. The document's
1842
+ // identity is its REAL path, so a target the listing does not carry by realpath
1843
+ // is the unknown option it always was, and nothing is mounted.
1844
+ //
1845
+ // The verifier's appendix test (T6 regression, `/tmp/oddv.*/t6-regression-appendix.js`)
1846
+ // is ported here with this suite's helper names and its assertions verbatim. The
1847
+ // separated-git-dir cases in that appendix are NOT ported: L13 declares that
1848
+ // layout out of support.
1849
+ // ---------------------------------------------------------------------------
1850
+ test('T19/F4: a lexical dot-dot match cannot open another inode', async () => {
1851
+ const e = await load(), root = makeRepo();
1852
+ const other = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-distinct-inode-')));
1853
+ const otherDoc = writeTask(other, 'main-one', '# Distinct inode');
1854
+ const sub = path.join(path.dirname(otherDoc), 'sub');
1855
+ fs.mkdirSync(sub);
1856
+ const tasks = path.join(root, 'odd/tasks'), wanted = path.join(tasks, 'main-one.md');
1857
+ fs.symlinkSync(sub, path.join(tasks, 'cross'), 'dir');
1858
+ const raw = `${tasks}/cross/../main-one.md`;
1859
+ assert.equal(path.resolve(raw), wanted);
1860
+ assert.equal(fs.realpathSync.native(raw), otherDoc);
1861
+ assert.notEqual(fs.statSync(raw).ino, fs.statSync(wanted).ino);
1862
+ const h = mountHost(), pending = doOdd(e, raw, ctxFor(root, h));
1863
+ try {
1864
+ await waitFor(() => h.mounts.length || h.notifications.length, 'distinct target reply');
1865
+ assert.equal(h.mounts.length, 0);
1866
+ assert.deepEqual(h.notifications, [['error', `Unknown option "${raw}". Use /odd.`]]);
1867
+ } finally { await closePanel(h, pending); }
1868
+ });