pi-odd-worktree 3.5.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/extensions/odd-worktree-tools.ts +35 -3
- package/lib/file-card.js +29 -12
- package/lib/files-index.js +99 -5
- package/lib/files-orders.js +1 -1
- package/lib/files-picker-view.js +45 -7
- package/lib/files-scope-detail.js +13 -6
- package/lib/skill-odd-card.js +33 -8
- package/package.json +1 -1
- package/tools/file-card.test.js +172 -15
- package/tools/files-command.test.js +116 -4
- package/tools/files-index.test.js +254 -13
- package/tools/files-orders.test.js +4 -4
- package/tools/files-picker-view.test.js +55 -2
- package/tools/files-scope-detail.test.js +6 -3
- package/tools/files-scope-view.test.js +3 -1
- package/tools/skill-odd-card.test.js +45 -3
|
@@ -3,18 +3,22 @@
|
|
|
3
3
|
// each file's change state with its age, and the bounded preview reader.
|
|
4
4
|
//
|
|
5
5
|
// The public surface only: the exact argv the injected runner receives, the
|
|
6
|
-
// classification of
|
|
7
|
-
//
|
|
8
|
-
// and the
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
6
|
+
// classification of a changed file (a .gitignore'd file never appears because Git
|
|
7
|
+
// is asked for the standard exclude set), the recency order and the age labels,
|
|
8
|
+
// and the preview's text / truncation / binary / error paths against real
|
|
9
|
+
// temporary files. Every Git read goes through the fake runner below, EXCEPT the
|
|
10
|
+
// two tests under "against real Git": those spawn Git in a scratch repository,
|
|
11
|
+
// because an ambiguous ref and a partial clone's lazy fetch are properties no
|
|
12
|
+
// fake answer can express. No network is touched, and every temporary directory
|
|
13
|
+
// lives under os.tmpdir() and is removed in after().
|
|
12
14
|
|
|
13
15
|
const { test, after } = require('node:test');
|
|
14
16
|
const assert = require('node:assert/strict');
|
|
17
|
+
const { spawnSync } = require('node:child_process');
|
|
15
18
|
const fs = require('node:fs');
|
|
16
19
|
const os = require('node:os');
|
|
17
20
|
const path = require('node:path');
|
|
21
|
+
const { pathToFileURL } = require('node:url');
|
|
18
22
|
|
|
19
23
|
const {
|
|
20
24
|
listRepositoryEntries,
|
|
@@ -163,7 +167,7 @@ test('no runner at all is a sentence, not a throw', async () => {
|
|
|
163
167
|
|
|
164
168
|
// --- entries: state, recency and age --------------------------------------
|
|
165
169
|
|
|
166
|
-
test('changed files come first — untracked as new, dirty as
|
|
170
|
+
test('changed files come first — untracked as new, dirty as modified, newest first — then the clean ones by path', async () => {
|
|
167
171
|
const root = tempDir();
|
|
168
172
|
const now = Date.parse('2024-05-01T12:00:00Z');
|
|
169
173
|
const dirty = writeFile(root, 'src/a.ts', 'export const a = 1;\n');
|
|
@@ -183,7 +187,7 @@ test('changed files come first — untracked as new, dirty as updated, newest fi
|
|
|
183
187
|
|
|
184
188
|
assert.deepEqual(pairs(result.entries), [
|
|
185
189
|
['notes.md', 'new'],
|
|
186
|
-
['src/a.ts', '
|
|
190
|
+
['src/a.ts', 'modified'],
|
|
187
191
|
['src/b.js', 'clean'],
|
|
188
192
|
['src/clean.ts', 'clean'],
|
|
189
193
|
]);
|
|
@@ -243,15 +247,15 @@ test('an unreadable root or a file that is not on disk removes the age instead o
|
|
|
243
247
|
|
|
244
248
|
const result = await listRepositoryEntries({ run, cwd: '/repo', now: Date.now() });
|
|
245
249
|
|
|
246
|
-
assert.deepEqual(pairs(result.entries), [['present.ts', '
|
|
250
|
+
assert.deepEqual(pairs(result.entries), [['present.ts', 'modified'], ['gone.ts', 'modified']],
|
|
247
251
|
'the timed change comes first, the untimed one after');
|
|
248
252
|
assert.equal(typeof result.entries[0].mtimeMs, 'number');
|
|
249
|
-
assert.deepEqual(result.entries[1], { path: 'gone.ts', state: '
|
|
253
|
+
assert.deepEqual(result.entries[1], { path: 'gone.ts', state: 'modified' }, 'no timestamp, no age');
|
|
250
254
|
|
|
251
255
|
const noRoot = fakeRunner(gitAnswer({ listing: 'present.ts\0', status: ' M present.ts\0', root: undefined }));
|
|
252
256
|
const withoutRoot = await listRepositoryEntries({ run: noRoot.run, cwd: '/repo', now: Date.now() });
|
|
253
|
-
assert.deepEqual(pairs(withoutRoot.entries), [['present.ts', '
|
|
254
|
-
assert.deepEqual(withoutRoot.entries[0], { path: 'present.ts', state: '
|
|
257
|
+
assert.deepEqual(pairs(withoutRoot.entries), [['present.ts', 'modified']], 'a failed rev-parse is not a failed listing');
|
|
258
|
+
assert.deepEqual(withoutRoot.entries[0], { path: 'present.ts', state: 'modified' });
|
|
255
259
|
});
|
|
256
260
|
|
|
257
261
|
test('a rename record skips its original path field', async () => {
|
|
@@ -262,7 +266,7 @@ test('a rename record skips its original path field', async () => {
|
|
|
262
266
|
}));
|
|
263
267
|
|
|
264
268
|
const result = await listRepositoryEntries({ run, cwd: '/repo', now: Date.now() });
|
|
265
|
-
assert.deepEqual(pairs(result.entries), [['src/new.ts', '
|
|
269
|
+
assert.deepEqual(pairs(result.entries), [['src/new.ts', 'modified'], ['src/old.ts', 'clean']],
|
|
266
270
|
'the original path is not a record of its own, so it is not marked changed');
|
|
267
271
|
});
|
|
268
272
|
|
|
@@ -315,6 +319,243 @@ test('every Git read is a fixed read-only argv: nothing stages, commits or check
|
|
|
315
319
|
assert.ok(calls[1].args.includes('--no-optional-locks'), 'status may not write the index back');
|
|
316
320
|
});
|
|
317
321
|
|
|
322
|
+
// --- a worktree scope: the branch's own commits (S2-S5) --------------------
|
|
323
|
+
|
|
324
|
+
// The one read a worktree scope adds: the NET name-status record of what the
|
|
325
|
+
// branch changed against the merge-base with the principal branch. Three dots,
|
|
326
|
+
// so a `main` that moved on since the fork is not read as the branch's work.
|
|
327
|
+
// A bare ref would be ambiguous the moment a tag shares its name, and a file
|
|
328
|
+
// named `<ref>...HEAD` would break the read, so the branch is qualified and the
|
|
329
|
+
// argument list is closed with `--`. `--no-renames` is what keeps the read
|
|
330
|
+
// read-only in a partial clone.
|
|
331
|
+
const COMMIT_ARGV = (comparison) => [
|
|
332
|
+
'diff',
|
|
333
|
+
'--name-status',
|
|
334
|
+
'-z',
|
|
335
|
+
'--no-renames',
|
|
336
|
+
`refs/heads/${comparison}...HEAD`,
|
|
337
|
+
'--',
|
|
338
|
+
];
|
|
339
|
+
|
|
340
|
+
function worktreeAnswer({ listing = '', commits = '', status = '', root } = {}) {
|
|
341
|
+
return (args) => {
|
|
342
|
+
if (args[0] === 'ls-files') return { status: 0, stdout: listing, stderr: '' };
|
|
343
|
+
if (args[0] === 'diff') return { status: 0, stdout: commits, stderr: '' };
|
|
344
|
+
if (args[0] === '--no-optional-locks') return { status: 0, stdout: status, stderr: '' };
|
|
345
|
+
if (args[0] === 'rev-parse') {
|
|
346
|
+
return { status: root === undefined ? 128 : 0, stdout: root === undefined ? '' : `${root}\n`, stderr: '' };
|
|
347
|
+
}
|
|
348
|
+
return { status: 1, stdout: '', stderr: 'unexpected argv' };
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
test('a worktree scope marks the branch\'s commits, one row per path, and keeps its uncommitted work', async () => {
|
|
353
|
+
const root = tempDir();
|
|
354
|
+
const now = Date.parse('2024-05-01T12:00:00Z');
|
|
355
|
+
setMtime(writeFile(root, 'a.txt', 'three\n'), now - 4 * HOUR);
|
|
356
|
+
setMtime(writeFile(root, 'added.txt', 'new\n'), now - 3 * HOUR);
|
|
357
|
+
setMtime(writeFile(root, 'src/moved.txt', 'deep\n'), now - 2 * HOUR);
|
|
358
|
+
setMtime(writeFile(root, 'u.txt', 'untracked\n'), now - HOUR);
|
|
359
|
+
writeFile(root, 'clean.ts', 'clean\n');
|
|
360
|
+
|
|
361
|
+
const { run, calls } = fakeRunner(worktreeAnswer({
|
|
362
|
+
listing: 'a.txt\0added.txt\0src/moved.txt\0clean.ts\0u.txt\0',
|
|
363
|
+
// The branch modified one file, added one, deleted one, renamed one.
|
|
364
|
+
commits: 'M\0a.txt\0A\0added.txt\0D\0b.txt\0R100\0src/deep.txt\0src/moved.txt\0',
|
|
365
|
+
// `a.txt` is dirty on top of its commit, and `u.txt` was never committed.
|
|
366
|
+
status: ' M a.txt\0?? u.txt\0',
|
|
367
|
+
root,
|
|
368
|
+
}));
|
|
369
|
+
|
|
370
|
+
const result = await listRepositoryEntries({ run, cwd: '/repo', now, comparison: 'main' });
|
|
371
|
+
|
|
372
|
+
assert.deepEqual(pairs(result.entries), [
|
|
373
|
+
['u.txt', 'new'],
|
|
374
|
+
['src/moved.txt', 'added'],
|
|
375
|
+
['added.txt', 'added'],
|
|
376
|
+
['a.txt', 'modified'],
|
|
377
|
+
['clean.ts', 'clean'],
|
|
378
|
+
]);
|
|
379
|
+
assert.deepEqual(calls.map((call) => call.args), [LIST_ARGV, COMMIT_ARGV('main'), STATUS_ARGV, ROOT_ARGV],
|
|
380
|
+
'the commit read sits between the listing and the status, one fixed argv each');
|
|
381
|
+
assert.ok(calls.every((call) => call.opts.cwd === '/repo'), 'every read runs in the browsed checkout');
|
|
382
|
+
|
|
383
|
+
assert.equal(result.entries.filter((entry) => entry.path === 'a.txt').length, 1,
|
|
384
|
+
'a path named by a commit and again by status is one row');
|
|
385
|
+
assert.equal(result.entries.find((entry) => entry.path === 'a.txt').state, 'modified',
|
|
386
|
+
'the commit state wins over the dirty one, and both read M');
|
|
387
|
+
assert.equal(result.entries.some((entry) => entry.path === 'b.txt'), false, 'a deleted file is never listed');
|
|
388
|
+
assert.equal(result.entries.some((entry) => entry.path === 'src/deep.txt'), false,
|
|
389
|
+
'a rename\'s original path is not a row of its own');
|
|
390
|
+
assert.equal(result.entries[1].age, formatAge(fs.statSync(path.join(root, 'src/moved.txt')).mtimeMs, now),
|
|
391
|
+
'a committed row keeps the same age label as any other');
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
test('the comparison is the caller\'s, carried verbatim into the one diff read', async () => {
|
|
395
|
+
const { run, calls } = fakeRunner(worktreeAnswer({ listing: 'a.ts\0', commits: 'A\0a.ts\0' }));
|
|
396
|
+
|
|
397
|
+
await listRepositoryEntries({ run, cwd: '/repo', now: 0, comparison: 'trunk' });
|
|
398
|
+
|
|
399
|
+
assert.deepEqual(calls[1].args, COMMIT_ARGV('trunk'),
|
|
400
|
+
'the principal branch is the caller\'s, whatever the repository calls it');
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
test('an empty comparison is the status read alone, exactly as the main scope reads', async () => {
|
|
404
|
+
const { run, calls } = fakeRunner(gitAnswer({
|
|
405
|
+
listing: 'a.ts\0b.ts\0',
|
|
406
|
+
status: '?? b.ts\0',
|
|
407
|
+
root: undefined,
|
|
408
|
+
}));
|
|
409
|
+
|
|
410
|
+
const result = await listRepositoryEntries({ run, cwd: '/repo', now: 0, comparison: '' });
|
|
411
|
+
|
|
412
|
+
assert.deepEqual(pairs(result.entries), [['b.ts', 'new'], ['a.ts', 'clean']]);
|
|
413
|
+
assert.deepEqual(calls.map((call) => call.args), [LIST_ARGV, STATUS_ARGV, ROOT_ARGV],
|
|
414
|
+
'no comparison asks Git nothing about commits');
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
test('a path the branch deleted and the working tree recreated is untracked, never a deleted row', async () => {
|
|
418
|
+
const { run } = fakeRunner(worktreeAnswer({
|
|
419
|
+
listing: 'gone.ts\0',
|
|
420
|
+
commits: 'D\0gone.ts\0',
|
|
421
|
+
status: '?? gone.ts\0',
|
|
422
|
+
}));
|
|
423
|
+
|
|
424
|
+
const result = await listRepositoryEntries({ run, cwd: '/repo', now: 0, comparison: 'main' });
|
|
425
|
+
|
|
426
|
+
assert.deepEqual(pairs(result.entries), [['gone.ts', 'new']],
|
|
427
|
+
'the file exists and Git does not track it, so the row is the honest one');
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test('a copy record names its new path only', async () => {
|
|
431
|
+
const { run } = fakeRunner(worktreeAnswer({
|
|
432
|
+
listing: 'src/copy.ts\0src/orig.ts\0',
|
|
433
|
+
// Git writes the ORIGINAL path first and the path the record is about second
|
|
434
|
+
// (verified against `git diff --name-status -z -M -C --find-copies-harder`).
|
|
435
|
+
commits: 'C100\0src/orig.ts\0src/copy.ts\0M\0src/orig.ts\0',
|
|
436
|
+
}));
|
|
437
|
+
|
|
438
|
+
const result = await listRepositoryEntries({ run, cwd: '/repo', now: 0, comparison: 'main' });
|
|
439
|
+
|
|
440
|
+
assert.deepEqual(pairs(result.entries), [['src/copy.ts', 'added'], ['src/orig.ts', 'modified']],
|
|
441
|
+
'the copy is new at its own path; the original keeps the state its own record gives it');
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
test('a failed commit read is a sentence, never a half listing', async () => {
|
|
445
|
+
const { run, calls } = fakeRunner((args) => {
|
|
446
|
+
if (args[0] === 'ls-files') return { status: 0, stdout: 'a.ts\0', stderr: '' };
|
|
447
|
+
if (args[0] === 'diff') return { status: 128, stdout: '', stderr: "fatal: ambiguous argument 'main...HEAD'" };
|
|
448
|
+
return { status: 0, stdout: '', stderr: '' };
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
assert.deepEqual(await listRepositoryEntries({ run, cwd: '/repo', now: 0, comparison: 'main' }), {
|
|
452
|
+
ok: false,
|
|
453
|
+
message: "Cannot read the branch's commits: fatal: ambiguous argument 'main...HEAD'.",
|
|
454
|
+
});
|
|
455
|
+
assert.deepEqual(calls.map((call) => call.args[0]), ['ls-files', 'diff'],
|
|
456
|
+
'the status read never runs once the commit read failed');
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
// --- against real Git ------------------------------------------------------
|
|
460
|
+
//
|
|
461
|
+
// The only two properties a fake answer cannot express: an ambiguous ref, and a
|
|
462
|
+
// read that must write nothing to the repository (a partial clone is where `-M`
|
|
463
|
+
// used to fetch the missing merge-base blob and leave a pack behind).
|
|
464
|
+
|
|
465
|
+
// A real Git runner with the injected runner's signature, over a scratch
|
|
466
|
+
// repository whose configuration is this test's alone: no system config, no
|
|
467
|
+
// global config, and a temporary HOME.
|
|
468
|
+
function realGit(root) {
|
|
469
|
+
const home = tempDir();
|
|
470
|
+
const env = {
|
|
471
|
+
PATH: process.env.PATH,
|
|
472
|
+
HOME: home,
|
|
473
|
+
TMPDIR: home,
|
|
474
|
+
GIT_CONFIG_NOSYSTEM: '1',
|
|
475
|
+
GIT_CONFIG_GLOBAL: os.devNull,
|
|
476
|
+
GIT_ALLOW_PROTOCOL: 'file',
|
|
477
|
+
};
|
|
478
|
+
const run = (args, opts = {}, extra = {}) => spawnSync('git', args, {
|
|
479
|
+
cwd: opts.cwd === undefined ? root : opts.cwd,
|
|
480
|
+
timeout: opts.timeoutMs === undefined ? 15_000 : opts.timeoutMs,
|
|
481
|
+
encoding: 'utf8',
|
|
482
|
+
env: { ...env, ...extra },
|
|
483
|
+
});
|
|
484
|
+
const git = (...args) => {
|
|
485
|
+
const result = run(args);
|
|
486
|
+
assert.equal(result.status, 0, `git ${args.join(' ')}: ${String(result.stderr)}`);
|
|
487
|
+
return String(result.stdout).trim();
|
|
488
|
+
};
|
|
489
|
+
git('init', '-q', '-b', 'main');
|
|
490
|
+
git('config', 'user.name', 'Files Test');
|
|
491
|
+
git('config', 'user.email', 'files@example.invalid');
|
|
492
|
+
return { git, run };
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
test('S2: a tag or a file spelled like the revision cannot shadow the principal branch', async () => {
|
|
496
|
+
const root = tempDir();
|
|
497
|
+
const { git, run } = realGit(root);
|
|
498
|
+
git('commit', '-q', '--allow-empty', '-m', 'base');
|
|
499
|
+
git('checkout', '-qb', 'feature');
|
|
500
|
+
writeFile(root, 'added.txt', 'branch addition\n');
|
|
501
|
+
git('add', '.');
|
|
502
|
+
git('commit', '-qm', 'feature');
|
|
503
|
+
|
|
504
|
+
// A tag on the tip: a bare `main` would resolve to it and answer "no changes".
|
|
505
|
+
git('tag', 'main');
|
|
506
|
+
const tagged = await listRepositoryEntries({ run, cwd: root, now: 0, comparison: 'main' });
|
|
507
|
+
assert.equal(tagged.ok, true, tagged.message);
|
|
508
|
+
assert.equal(tagged.entries.find((entry) => entry.path === 'added.txt').state, 'added',
|
|
509
|
+
'the local branch is read, never the tag that shares its name');
|
|
510
|
+
|
|
511
|
+
// An ordinary file whose name spells the whole revision: Git would read it as a
|
|
512
|
+
// path and fail the entire read.
|
|
513
|
+
git('tag', '-d', 'main');
|
|
514
|
+
writeFile(root, 'main...HEAD', 'ordinary file\n');
|
|
515
|
+
const shadowed = await listRepositoryEntries({ run, cwd: root, now: 0, comparison: 'main' });
|
|
516
|
+
assert.equal(shadowed.ok, true, shadowed.message);
|
|
517
|
+
assert.equal(shadowed.entries.find((entry) => entry.path === 'added.txt').state, 'added');
|
|
518
|
+
assert.equal(shadowed.entries.find((entry) => entry.path === 'main...HEAD').state, 'new',
|
|
519
|
+
'the file is the untracked row it is, not a broken read');
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
test('S6: marking a partial clone fetches nothing and writes no pack', async () => {
|
|
523
|
+
const origin = tempDir();
|
|
524
|
+
const { git, run } = realGit(origin);
|
|
525
|
+
git('config', 'uploadpack.allowFilter', 'true');
|
|
526
|
+
git('config', 'uploadpack.allowAnySHA1InWant', 'true');
|
|
527
|
+
const body = Array.from({ length: 200 }, (_, index) => `source line ${index}\n`).join('');
|
|
528
|
+
writeFile(origin, 'source.txt', body);
|
|
529
|
+
git('add', '.');
|
|
530
|
+
git('commit', '-qm', 'base');
|
|
531
|
+
const blob = git('rev-parse', 'main:source.txt');
|
|
532
|
+
git('checkout', '-qb', 'feature');
|
|
533
|
+
git('mv', 'source.txt', 'dest.txt');
|
|
534
|
+
writeFile(origin, 'dest.txt', body.replace('line 199', 'line changed'));
|
|
535
|
+
git('commit', '-qam', 'rename with edit');
|
|
536
|
+
|
|
537
|
+
const clone = path.join(tempDir(), 'clone');
|
|
538
|
+
const linked = path.join(tempDir(), 'linked');
|
|
539
|
+
git('clone', '-q', '--filter=blob:none', '--no-checkout', pathToFileURL(origin).href, clone);
|
|
540
|
+
const inClone = (...args) => git('-C', clone, ...args);
|
|
541
|
+
inClone('branch', 'main', 'origin/main');
|
|
542
|
+
inClone('worktree', 'add', '-q', '--detach', linked, 'origin/feature');
|
|
543
|
+
|
|
544
|
+
const missing = () => run(['cat-file', '-e', blob],
|
|
545
|
+
{ cwd: clone, timeoutMs: 15_000 }, { GIT_NO_LAZY_FETCH: '1' }).status;
|
|
546
|
+
const packs = () => fs.readdirSync(path.join(clone, '.git', 'objects', 'pack')).sort();
|
|
547
|
+
assert.equal(missing(), 1, 'the merge-base blob starts absent, which is what a partial clone is');
|
|
548
|
+
const before = packs();
|
|
549
|
+
|
|
550
|
+
const result = await listRepositoryEntries({ run, cwd: linked, now: 0, comparison: 'main' });
|
|
551
|
+
|
|
552
|
+
assert.equal(result.ok, true, result.message);
|
|
553
|
+
assert.equal(result.entries.find((entry) => entry.path === 'dest.txt').state, 'added',
|
|
554
|
+
'an undetected rename still reads as the new path being added');
|
|
555
|
+
assert.equal(missing(), 1, 'the read fetched nothing');
|
|
556
|
+
assert.deepEqual(packs(), before, 'and wrote no pack into the clone');
|
|
557
|
+
});
|
|
558
|
+
|
|
318
559
|
// --- formatAge -------------------------------------------------------------
|
|
319
560
|
|
|
320
561
|
test('formatAge labels one elapsed age in s, m, h and d', () => {
|
|
@@ -39,12 +39,12 @@ function entry(path, state, mtimeMs) {
|
|
|
39
39
|
// Deliberately NOT in the listing's own order: the builder owns the `files`
|
|
40
40
|
// order, so it is asserted against an unsorted input.
|
|
41
41
|
const ENTRIES = [
|
|
42
|
-
entry('lib/view-layout.js', '
|
|
42
|
+
entry('lib/view-layout.js', 'modified', 3000),
|
|
43
43
|
entry('README.md', 'clean', 1500),
|
|
44
44
|
entry('lib/files-orders.js', 'new', 5000),
|
|
45
45
|
entry('AGENTS.md', 'clean', 1000),
|
|
46
46
|
entry('lib/odd-prompt/odd-worktrees.md', 'clean', 2000),
|
|
47
|
-
entry('docs/reference.md', '
|
|
47
|
+
entry('docs/reference.md', 'modified', 4000),
|
|
48
48
|
entry('tools/files-orders.test.js', 'new', 3500),
|
|
49
49
|
entry('LICENSE', 'clean', 800),
|
|
50
50
|
];
|
|
@@ -124,9 +124,9 @@ describe('files: one flat file list (S10, S33)', () => {
|
|
|
124
124
|
test('a changed file without an mtime sorts after the timed changes and before clean files', () => {
|
|
125
125
|
const rows = buildRows([
|
|
126
126
|
entry('b.md', 'clean'),
|
|
127
|
-
entry('x.js', '
|
|
127
|
+
entry('x.js', 'modified'),
|
|
128
128
|
entry('a.js', 'new', 100),
|
|
129
|
-
entry('y.js', '
|
|
129
|
+
entry('y.js', 'modified', 200),
|
|
130
130
|
], { order: 'files' });
|
|
131
131
|
assert.deepEqual(paths(rows), ['y.js', 'a.js', 'x.js', 'b.md']);
|
|
132
132
|
});
|
|
@@ -120,7 +120,7 @@ const SCOPE = { root: '/home/dev/repo-worktrees/files-picker', kind: 'worktree',
|
|
|
120
120
|
// The listing T1 answers: changed first and newest first, then clean by path.
|
|
121
121
|
const FILES = [
|
|
122
122
|
{ path: 'brand-new.ts', state: 'new', mtimeMs: NOW - 5_000, age: '5s' },
|
|
123
|
-
{ path: 'src/cursor.ts', state: '
|
|
123
|
+
{ path: 'src/cursor.ts', state: 'modified', mtimeMs: NOW - 2 * HOUR, age: '2h' },
|
|
124
124
|
{ path: 'README.md', state: 'clean' },
|
|
125
125
|
{ path: 'src/lib/util.ts', state: 'clean' },
|
|
126
126
|
];
|
|
@@ -335,6 +335,44 @@ describe('the card chrome (S1, S15)', () => {
|
|
|
335
335
|
assert.match(afterPath, /^ ─+ esc ╮$/, `only the rule and esc follow the path: ${JSON.stringify(afterPath)}`);
|
|
336
336
|
});
|
|
337
337
|
|
|
338
|
+
test('the commits ahead of the base ride the title, and only ahead is named (S44)', async () => {
|
|
339
|
+
const ahead = {
|
|
340
|
+
...SCOPE,
|
|
341
|
+
detail: { comparison: 'main', ahead: 3, behind: 310, lastCommitSubject: 'fix(warp): the dash' },
|
|
342
|
+
};
|
|
343
|
+
const { view } = await open({ scope: ahead });
|
|
344
|
+
const title = rowsOf(view)[0];
|
|
345
|
+
assert.ok(title.startsWith(`╭─ ✿ Files · ${SCOPE.root} · ↑3 main `),
|
|
346
|
+
`the ahead field is the title's tail, never beside a behind count: ${title}`);
|
|
347
|
+
assert.ok(!title.includes('↓'), 'behind is not painted next to ahead');
|
|
348
|
+
assert.equal(helpers.visibleWidth(title), WIDTH);
|
|
349
|
+
|
|
350
|
+
// Already on top of the base, or never measured: no field at all.
|
|
351
|
+
const level = await open({ scope: { ...SCOPE, detail: { comparison: 'main', ahead: 0, behind: 4 } } });
|
|
352
|
+
assert.ok(rowsOf(level.view)[0].startsWith(`╭─ ✿ Files · ${SCOPE.root} `), 'no ahead, no field');
|
|
353
|
+
const unmeasured = await open({ scope: { ...SCOPE, detail: {} } });
|
|
354
|
+
assert.ok(rowsOf(unmeasured.view)[0].startsWith(`╭─ ✿ Files · ${SCOPE.root} `), 'no detail, no field');
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test('a narrow title keeps the ahead field and gives way with the path (S44)', async () => {
|
|
358
|
+
const { view } = await open({
|
|
359
|
+
scope: { ...SCOPE, detail: { comparison: 'main', ahead: 12, behind: 310 } },
|
|
360
|
+
});
|
|
361
|
+
// 52 columns: 30 for the detail, of which the field takes 9, so the path keeps
|
|
362
|
+
// 21 and still shows the identifying tail.
|
|
363
|
+
const narrow = view.render(52).map(strip)[0];
|
|
364
|
+
assert.equal(narrow, '╭─ ✿ Files · …rktrees/files-picker · ↑12 main esc ╮',
|
|
365
|
+
'the field is never elided; the path gives way to it');
|
|
366
|
+
// Too narrow for a path worth painting: the field keeps the row alone.
|
|
367
|
+
const tiniest = view.render(34).map(strip)[0];
|
|
368
|
+
assert.ok(tiniest.includes('↑12 main'), tiniest);
|
|
369
|
+
assert.ok(!tiniest.includes('…'), `no elided path beside the field at the smallest width: ${tiniest}`);
|
|
370
|
+
assert.ok(!tiniest.includes('files-picker'), 'the path is gone, not truncated into the field');
|
|
371
|
+
for (const width of [52, 34]) {
|
|
372
|
+
assert.equal(helpers.visibleWidth(view.render(width).map(strip)[0]), width, `the row fills ${width}`);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
|
|
338
376
|
test('a narrow card elides the path from its left, so the tail that identifies the checkout survives (S37)', async () => {
|
|
339
377
|
const { view } = await open();
|
|
340
378
|
// 50 columns: the title keeps 30 for the path (50 - 7 for `✿ Files` - 3 for
|
|
@@ -541,10 +579,25 @@ describe('the list rows (S6, S15)', () => {
|
|
|
541
579
|
assert.ok(!bodyText(rows).includes('new '), 'the word badge is never painted');
|
|
542
580
|
});
|
|
543
581
|
|
|
582
|
+
test('a file the branch added paints A, and the three letters are the whole vocabulary', async () => {
|
|
583
|
+
const entries = [
|
|
584
|
+
{ path: 'arrived.ts', state: 'added' },
|
|
585
|
+
{ path: 'edited.ts', state: 'modified' },
|
|
586
|
+
{ path: 'brand-new.ts', state: 'new' },
|
|
587
|
+
{ path: 'plain.ts', state: 'clean' },
|
|
588
|
+
];
|
|
589
|
+
const { view } = await open({ entries, now: NOW });
|
|
590
|
+
const rows = rowsOf(view);
|
|
591
|
+
assert.match(listCell(rows, 'arrived.ts'), /A$/, 'a committed addition reads A, never M');
|
|
592
|
+
assert.match(listCell(rows, 'edited.ts'), /M$/);
|
|
593
|
+
assert.match(listCell(rows, 'brand-new.ts'), /U$/);
|
|
594
|
+
assert.match(listCell(rows, 'plain.ts'), /^\s+plain\.ts *$/, 'a clean row still paints no badge');
|
|
595
|
+
});
|
|
596
|
+
|
|
544
597
|
test('a changed row without an age keeps its letter and falls back to its mtime once', async () => {
|
|
545
598
|
const entries = [
|
|
546
599
|
{ path: 'brand-new.ts', state: 'new' },
|
|
547
|
-
{ path: 'edited.ts', state: '
|
|
600
|
+
{ path: 'edited.ts', state: 'modified', mtimeMs: NOW - 3 * HOUR },
|
|
548
601
|
{ path: 'plain.ts', state: 'clean' },
|
|
549
602
|
];
|
|
550
603
|
const { view } = await open({ entries, now: NOW });
|
|
@@ -96,16 +96,19 @@ describe('countCell (S9)', () => {
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
describe('scopeDetailLine (S9)', () => {
|
|
99
|
-
test('the last commit subject leads, then the count, the age and
|
|
99
|
+
test('the last commit subject leads, then the count, the age and ONE distance', () => {
|
|
100
100
|
const line = scopeDetailLine({
|
|
101
101
|
lastCommitSubject: 'add the scope step',
|
|
102
102
|
changedFiles: 3,
|
|
103
103
|
lastModifiedMs: NOW - 5 * MINUTE,
|
|
104
104
|
ahead: 2,
|
|
105
|
-
behind:
|
|
105
|
+
behind: 310,
|
|
106
106
|
comparison: 'main',
|
|
107
107
|
}, NOW);
|
|
108
|
-
|
|
108
|
+
// A worktree is almost always behind its principal branch, so `↓` beside `↑`
|
|
109
|
+
// is noise that reads as a contradiction (S44): ahead wins when there is any,
|
|
110
|
+
// and behind is painted only when the checkout is merely stale.
|
|
111
|
+
assert.equal(line, 'add the scope step · ±3 files · 5m ago · ↑2 main');
|
|
109
112
|
});
|
|
110
113
|
|
|
111
114
|
test('the main row names the remote ref it is measured against', () => {
|
|
@@ -269,7 +269,9 @@ describe('the focused detail line (S9)', () => {
|
|
|
269
269
|
assert.ok(rowsOf(view)[HEIGHT - 3].includes('main subject'));
|
|
270
270
|
view.handleInput('down');
|
|
271
271
|
const moved = rowsOf(view);
|
|
272
|
-
|
|
272
|
+
// S44: one distance, never two — ahead wins when the checkout has any.
|
|
273
|
+
assert.ok(moved[HEIGHT - 3].includes('add the scope step · ±3 files · 2m ago · ↑2 main'), moved[HEIGHT - 3]);
|
|
274
|
+
assert.ok(!/↓\d+/.test(moved[HEIGHT - 3]), 'behind is not painted beside ahead');
|
|
273
275
|
});
|
|
274
276
|
|
|
275
277
|
test('an absent or empty detail keeps a blank row of the same geometry', () => {
|
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
FILE_CARD_IDENTITY,
|
|
15
15
|
ODD_FILE_CARD,
|
|
16
16
|
SKILL_FILE_CARD,
|
|
17
|
+
editedFragment,
|
|
17
18
|
fileCardIdentity,
|
|
18
19
|
fileCardLineRange,
|
|
19
20
|
fileCardName,
|
|
@@ -175,19 +176,31 @@ test('a read names the line range it asked for, and no other tool states one', (
|
|
|
175
176
|
assert.equal(fileCardLineRange('read', undefined), undefined);
|
|
176
177
|
});
|
|
177
178
|
|
|
179
|
+
// The fragment source itself, as the one answer both the document and its plain fallback
|
|
180
|
+
// are drawn from.
|
|
181
|
+
test('the fragment an edit leaves is every `newText` it states, and nothing else', () => {
|
|
182
|
+
assert.equal(editedFragment({ edits: [{ newText: 'a' }, { newText: 'b' }] }), 'a\nb');
|
|
183
|
+
assert.equal(editedFragment({ newText: 'a' }), 'a');
|
|
184
|
+
assert.equal(editedFragment({ edits: [{ oldText: 'gone', newText: '' }] }), undefined);
|
|
185
|
+
assert.equal(editedFragment(undefined), undefined);
|
|
186
|
+
});
|
|
187
|
+
|
|
178
188
|
// A Markdown document is drawn as a document only when expanded and successful; a read
|
|
179
|
-
// draws what it returned, a write what its call carried,
|
|
180
|
-
|
|
189
|
+
// draws what it returned, a write what its call carried, an edit the fragment it leaves
|
|
190
|
+
// behind, and nothing to draw keeps the rows.
|
|
191
|
+
test('an expanded, successful read, write or edit of a Markdown file draws a document', () => {
|
|
181
192
|
const markdown = '## Handoff\n\nBody.';
|
|
182
193
|
const draw = (tool, args, result, options = {}) =>
|
|
183
194
|
markdownDocumentSource(tool, args, result, { expanded: true, ...options });
|
|
184
195
|
assert.equal(draw('read', { path: 'docs/a.md' }, markdown), markdown);
|
|
185
196
|
assert.equal(draw('write', { path: 'docs/a.md', content: markdown }, 'Successfully wrote 20 bytes'), markdown);
|
|
197
|
+
// An edit's document is the text it leaves behind, never what it removed or its diff.
|
|
198
|
+
assert.equal(draw('edit', { path: 'docs/a.md', oldText: 'a', newText: markdown }, 'Applied'), markdown);
|
|
186
199
|
// Collapsed, failed, non-Markdown and every other tool keep their rows.
|
|
187
200
|
assert.equal(draw('read', { path: 'docs/a.md' }, markdown, { expanded: false }), undefined);
|
|
188
201
|
assert.equal(draw('read', { path: 'docs/a.md' }, markdown, { isError: true }), undefined);
|
|
189
202
|
assert.equal(draw('write', { path: 'docs/a.md', content: markdown }, 'ok', { isError: true }), undefined);
|
|
190
|
-
assert.equal(draw('edit', { path: 'docs/a.md', oldText: 'a', newText: markdown }, 'Applied'), undefined);
|
|
203
|
+
assert.equal(draw('edit', { path: 'docs/a.md', oldText: 'a', newText: markdown }, 'Applied', { isError: true }), undefined);
|
|
191
204
|
assert.equal(draw('grep', { path: 'docs/a.md' }, markdown), undefined);
|
|
192
205
|
assert.equal(draw('read', { path: 'docs/a.txt' }, markdown), undefined);
|
|
193
206
|
assert.equal(draw('write', { path: 'lib/x.ts', content: markdown }, 'ok'), undefined);
|
|
@@ -198,3 +211,32 @@ test('only an expanded, successful read or write of a Markdown file draws a docu
|
|
|
198
211
|
assert.equal(draw('write', { path: 'docs/a.md' }, 'Successfully wrote 0 bytes'), undefined);
|
|
199
212
|
assert.equal(draw('read', undefined, markdown), undefined);
|
|
200
213
|
});
|
|
214
|
+
|
|
215
|
+
// An edit's document is the fragment its call leaves behind: every `newText` it states, in
|
|
216
|
+
// the call's own order, and nothing it removed.
|
|
217
|
+
test('an edit draws the fragment it leaves behind, in either call shape', () => {
|
|
218
|
+
const draw = (args, options = {}) => markdownDocumentSource('edit', args, 'Applied', { expanded: true, ...options });
|
|
219
|
+
// The shape the harness hands over: one `edits` array, joined in its own order.
|
|
220
|
+
assert.equal(
|
|
221
|
+
draw({ path: 'odd/a.md', edits: [{ oldText: 'one', newText: '# One' }, { oldText: 'two', newText: '## Two' }] }),
|
|
222
|
+
'# One\n## Two',
|
|
223
|
+
);
|
|
224
|
+
assert.equal(draw({ path: 'odd/a.md', edits: [{ newText: 'b' }, { newText: 'a' }] }), 'b\na', 'the array order, never a sort');
|
|
225
|
+
// The legacy flat shape: the one pair at the top level.
|
|
226
|
+
assert.equal(draw({ path: 'odd/a.md', oldText: 'one', newText: '# One' }), '# One');
|
|
227
|
+
assert.equal(draw({ path: 'odd/a.md', edits: 'not an array', newText: '# One' }), '# One', 'an `edits` that is not an array is the flat shape');
|
|
228
|
+
// An entry that states no string is skipped, never stringified: the fragment is text.
|
|
229
|
+
assert.equal(
|
|
230
|
+
draw({ path: 'odd/a.md', edits: [{ newText: 7 }, null, 'text', { newText: '# One' }, {}, { newText: ['x'] }] }),
|
|
231
|
+
'# One',
|
|
232
|
+
);
|
|
233
|
+
// A pure deletion leaves no fragment, so there is no document and the rows stay.
|
|
234
|
+
assert.equal(draw({ path: 'odd/a.md', edits: [{ oldText: '# Gone', newText: '' }] }), undefined);
|
|
235
|
+
assert.equal(draw({ path: 'odd/a.md', edits: [{ oldText: '# Gone', newText: ' \n ' }] }), undefined);
|
|
236
|
+
assert.equal(draw({ path: 'odd/a.md', oldText: '# Gone' }), undefined, 'no newText states nothing');
|
|
237
|
+
// A collapsed or failed edit, and a path that is no Markdown, keep their rows too.
|
|
238
|
+
assert.equal(draw({ path: 'odd/a.md', edits: [{ newText: '# One' }] }, { expanded: false }), undefined);
|
|
239
|
+
assert.equal(draw({ path: 'odd/a.json', edits: [{ newText: '# One' }] }), undefined);
|
|
240
|
+
// Nothing to read is no document, and no throw either.
|
|
241
|
+
assert.equal(draw(undefined), undefined);
|
|
242
|
+
});
|