pi-odd-worktree 2.1.0 → 3.0.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 +54 -319
- package/extensions/odd-worktree-tools.ts +4182 -2539
- package/lib/bash-activity.js +1166 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1421 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +323 -15
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -712
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1420 -0
- package/tools/bash-design.test.js +1093 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +613 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1889 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +417 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1517 -67
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4235 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2565 -309
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +419 -199
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// T4 (S10, S23): the listing orders. These tests pin the pure row builder the
|
|
3
|
+
// panel composes: `files` is one flat list, `tree` a folder tree and `ext` one
|
|
4
|
+
// level of extension groups, each foldable through the view's per-order fold set
|
|
5
|
+
// and forced open by a query. Everything is asserted through the public surface
|
|
6
|
+
// (`ORDERS`, `nextOrder`, `buildRows`, `groupKey`, `holderGroup`, `toggleFold`,
|
|
7
|
+
// `holderKeys`, `foldsFor`, `everyGroupFolded`, `toggleEveryFold`): no painting, no
|
|
8
|
+
// filesystem, no module-internal state.
|
|
9
|
+
//
|
|
10
|
+
// S23 renamed the folder order from `path` to `tree` — the id, the cycle and the
|
|
11
|
+
// row builder — so every assertion here names `tree`; what it paints did not
|
|
12
|
+
// change. S33 renamed the flat order from `modified` to `files`, and S29/S30 added
|
|
13
|
+
// the fold rules: every group folded by default, and only the focused file's groups
|
|
14
|
+
// open when an order is chosen. S39 replaced S34's "every other group" toggle with
|
|
15
|
+
// ONE toggle over every group, which `everyGroupFolded` states the direction of.
|
|
16
|
+
|
|
17
|
+
const { test, describe } = require('node:test');
|
|
18
|
+
const assert = require('node:assert/strict');
|
|
19
|
+
|
|
20
|
+
const {
|
|
21
|
+
ORDERS,
|
|
22
|
+
nextOrder,
|
|
23
|
+
buildRows,
|
|
24
|
+
groupKey,
|
|
25
|
+
holderGroup,
|
|
26
|
+
toggleFold,
|
|
27
|
+
holderKeys,
|
|
28
|
+
foldsFor,
|
|
29
|
+
everyGroupFolded,
|
|
30
|
+
toggleEveryFold,
|
|
31
|
+
} = require('../lib/files-orders.js');
|
|
32
|
+
|
|
33
|
+
function entry(path, state, mtimeMs) {
|
|
34
|
+
const value = { path, state };
|
|
35
|
+
if (mtimeMs !== undefined) value.mtimeMs = mtimeMs;
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Deliberately NOT in the listing's own order: the builder owns the `files`
|
|
40
|
+
// order, so it is asserted against an unsorted input.
|
|
41
|
+
const ENTRIES = [
|
|
42
|
+
entry('lib/view-layout.js', 'updated', 3000),
|
|
43
|
+
entry('README.md', 'clean', 1500),
|
|
44
|
+
entry('lib/files-orders.js', 'new', 5000),
|
|
45
|
+
entry('AGENTS.md', 'clean', 1000),
|
|
46
|
+
entry('lib/odd-prompt/odd-worktrees.md', 'clean', 2000),
|
|
47
|
+
entry('docs/reference.md', 'updated', 4000),
|
|
48
|
+
entry('tools/files-orders.test.js', 'new', 3500),
|
|
49
|
+
entry('LICENSE', 'clean', 800),
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
// One observable line per row: its indentation, its label or path, whether a
|
|
53
|
+
// group paints folded and whether a file carries its directory.
|
|
54
|
+
function shape(rows) {
|
|
55
|
+
return rows.map((row) => {
|
|
56
|
+
const indent = ' '.repeat(row.depth);
|
|
57
|
+
if (row.kind === 'group') return `${indent}[${row.label}]${row.folded ? ' folded' : ''}`;
|
|
58
|
+
return `${indent}${row.entry.path}${row.showDirectory ? ' (dir)' : ''}`;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function paths(rows) {
|
|
63
|
+
return rows.filter((row) => row.kind === 'file').map((row) => row.entry.path);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
describe('the order cycle (S10, S33)', () => {
|
|
67
|
+
test('cycles files -> tree -> ext and back', () => {
|
|
68
|
+
assert.deepEqual(ORDERS, ['files', 'tree', 'ext']);
|
|
69
|
+
assert.equal(nextOrder('files'), 'tree');
|
|
70
|
+
assert.equal(nextOrder('tree'), 'ext');
|
|
71
|
+
assert.equal(nextOrder('ext'), 'files');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('an order it does not know starts the cycle at files', () => {
|
|
75
|
+
assert.equal(nextOrder('bogus'), 'files');
|
|
76
|
+
assert.equal(nextOrder(''), 'files');
|
|
77
|
+
assert.equal(nextOrder(undefined), 'files');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('S33: the flat order is named files, and the old name is not an order', () => {
|
|
81
|
+
assert.equal(ORDERS.includes('modified'), false, 'the order is not called modified anywhere');
|
|
82
|
+
assert.equal(nextOrder('modified'), 'files', 'the old id starts the cycle at the default');
|
|
83
|
+
assert.deepEqual(
|
|
84
|
+
buildRows(ENTRIES, { order: 'modified' }),
|
|
85
|
+
buildRows(ENTRIES, { order: 'files' }),
|
|
86
|
+
'the old id falls back to the flat listing it always painted',
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('files: one flat file list (S10, S33)', () => {
|
|
92
|
+
test('changed files come first by recency, then clean files, ties by path', () => {
|
|
93
|
+
const rows = buildRows(ENTRIES, { order: 'files' });
|
|
94
|
+
assert.deepEqual(paths(rows), [
|
|
95
|
+
'lib/files-orders.js',
|
|
96
|
+
'docs/reference.md',
|
|
97
|
+
'tools/files-orders.test.js',
|
|
98
|
+
'lib/view-layout.js',
|
|
99
|
+
'AGENTS.md',
|
|
100
|
+
'LICENSE',
|
|
101
|
+
'README.md',
|
|
102
|
+
'lib/odd-prompt/odd-worktrees.md',
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('a file row is flat, at the root depth and shows its parent directory', () => {
|
|
107
|
+
const rows = buildRows(ENTRIES, { order: 'files' });
|
|
108
|
+
assert.deepEqual(shape(rows), [
|
|
109
|
+
'lib/files-orders.js (dir)',
|
|
110
|
+
'docs/reference.md (dir)',
|
|
111
|
+
'tools/files-orders.test.js (dir)',
|
|
112
|
+
'lib/view-layout.js (dir)',
|
|
113
|
+
'AGENTS.md (dir)',
|
|
114
|
+
'LICENSE (dir)',
|
|
115
|
+
'README.md (dir)',
|
|
116
|
+
'lib/odd-prompt/odd-worktrees.md (dir)',
|
|
117
|
+
]);
|
|
118
|
+
for (const row of rows) {
|
|
119
|
+
assert.equal(row.kind, 'file');
|
|
120
|
+
assert.equal(row.depth, 0);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('a changed file without an mtime sorts after the timed changes and before clean files', () => {
|
|
125
|
+
const rows = buildRows([
|
|
126
|
+
entry('b.md', 'clean'),
|
|
127
|
+
entry('x.js', 'updated'),
|
|
128
|
+
entry('a.js', 'new', 100),
|
|
129
|
+
entry('y.js', 'updated', 200),
|
|
130
|
+
], { order: 'files' });
|
|
131
|
+
assert.deepEqual(paths(rows), ['y.js', 'a.js', 'x.js', 'b.md']);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('no group is ever painted, and fold keys are inert', () => {
|
|
135
|
+
const unfolded = buildRows(ENTRIES, { order: 'files' });
|
|
136
|
+
const folded = buildRows(ENTRIES, { order: 'files', folded: new Set(['lib', 'docs', 'AGENTS.md']) });
|
|
137
|
+
assert.deepEqual(folded, unfolded);
|
|
138
|
+
assert.equal(unfolded.some((row) => row.kind === 'group'), false);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('tree: the folder tree (S10, S23)', () => {
|
|
143
|
+
test('subfolders come first and then the folder own files, root folders before root files', () => {
|
|
144
|
+
const rows = buildRows(ENTRIES, { order: 'tree' });
|
|
145
|
+
assert.deepEqual(shape(rows), [
|
|
146
|
+
'[docs]',
|
|
147
|
+
' docs/reference.md',
|
|
148
|
+
'[lib]',
|
|
149
|
+
' [odd-prompt]',
|
|
150
|
+
' lib/odd-prompt/odd-worktrees.md',
|
|
151
|
+
' lib/files-orders.js',
|
|
152
|
+
' lib/view-layout.js',
|
|
153
|
+
'[tools]',
|
|
154
|
+
' tools/files-orders.test.js',
|
|
155
|
+
'AGENTS.md',
|
|
156
|
+
'LICENSE',
|
|
157
|
+
'README.md',
|
|
158
|
+
]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('a file row does not repeat the directory the tree already shows', () => {
|
|
162
|
+
for (const row of buildRows(ENTRIES, { order: 'tree' })) {
|
|
163
|
+
if (row.kind === 'file') assert.equal(row.showDirectory, false);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('a root file paints at depth 0 and one inside a folder one level deeper', () => {
|
|
168
|
+
const rows = buildRows(ENTRIES, { order: 'tree' });
|
|
169
|
+
const byPath = new Map(rows.filter((row) => row.kind === 'file').map((row) => [row.entry.path, row.depth]));
|
|
170
|
+
assert.equal(byPath.get('AGENTS.md'), 0);
|
|
171
|
+
assert.equal(byPath.get('docs/reference.md'), 1);
|
|
172
|
+
assert.equal(byPath.get('lib/files-orders.js'), 1);
|
|
173
|
+
assert.equal(byPath.get('lib/odd-prompt/odd-worktrees.md'), 2);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('folding a folder keeps its group row, marks it folded and hides its descendants', () => {
|
|
177
|
+
const rows = buildRows(ENTRIES, { order: 'tree', folded: new Set(['lib']) });
|
|
178
|
+
assert.deepEqual(shape(rows), [
|
|
179
|
+
'[docs]',
|
|
180
|
+
' docs/reference.md',
|
|
181
|
+
'[lib] folded',
|
|
182
|
+
'[tools]',
|
|
183
|
+
' tools/files-orders.test.js',
|
|
184
|
+
'AGENTS.md',
|
|
185
|
+
'LICENSE',
|
|
186
|
+
'README.md',
|
|
187
|
+
]);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('a nested folder folds on its own full path key', () => {
|
|
191
|
+
const rows = buildRows(ENTRIES, { order: 'tree', folded: new Set(['lib/odd-prompt']) });
|
|
192
|
+
assert.deepEqual(shape(rows), [
|
|
193
|
+
'[docs]',
|
|
194
|
+
' docs/reference.md',
|
|
195
|
+
'[lib]',
|
|
196
|
+
' [odd-prompt] folded',
|
|
197
|
+
' lib/files-orders.js',
|
|
198
|
+
' lib/view-layout.js',
|
|
199
|
+
'[tools]',
|
|
200
|
+
' tools/files-orders.test.js',
|
|
201
|
+
'AGENTS.md',
|
|
202
|
+
'LICENSE',
|
|
203
|
+
'README.md',
|
|
204
|
+
]);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test('every group paints expanded until its key is folded', () => {
|
|
208
|
+
const rows = buildRows(ENTRIES, { order: 'tree' });
|
|
209
|
+
for (const row of rows) {
|
|
210
|
+
if (row.kind === 'group') assert.equal(row.folded, false);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe('ext: one level of extension groups (S10)', () => {
|
|
216
|
+
test('one group per extension, named with its dot, and the extensionless group last', () => {
|
|
217
|
+
const rows = buildRows(ENTRIES, { order: 'ext' });
|
|
218
|
+
assert.deepEqual(shape(rows), [
|
|
219
|
+
'[.js]',
|
|
220
|
+
' lib/files-orders.js (dir)',
|
|
221
|
+
' lib/view-layout.js (dir)',
|
|
222
|
+
' tools/files-orders.test.js (dir)',
|
|
223
|
+
'[.md]',
|
|
224
|
+
' AGENTS.md (dir)',
|
|
225
|
+
' README.md (dir)',
|
|
226
|
+
' docs/reference.md (dir)',
|
|
227
|
+
' lib/odd-prompt/odd-worktrees.md (dir)',
|
|
228
|
+
'[(none)]',
|
|
229
|
+
' LICENSE (dir)',
|
|
230
|
+
]);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('files inside a group are alphabetical by path and paint their directory', () => {
|
|
234
|
+
const rows = buildRows(ENTRIES, { order: 'ext' });
|
|
235
|
+
assert.deepEqual(paths(rows).slice(0, 3), [
|
|
236
|
+
'lib/files-orders.js',
|
|
237
|
+
'lib/view-layout.js',
|
|
238
|
+
'tools/files-orders.test.js',
|
|
239
|
+
]);
|
|
240
|
+
for (const row of rows.filter((value) => value.kind === 'file')) {
|
|
241
|
+
assert.equal(row.showDirectory, true);
|
|
242
|
+
assert.equal(row.depth, 1);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('a folded extension keeps its group row and hides its files', () => {
|
|
247
|
+
const rows = buildRows(ENTRIES, { order: 'ext', folded: new Set(['md']) });
|
|
248
|
+
assert.deepEqual(shape(rows), [
|
|
249
|
+
'[.js]',
|
|
250
|
+
' lib/files-orders.js (dir)',
|
|
251
|
+
' lib/view-layout.js (dir)',
|
|
252
|
+
' tools/files-orders.test.js (dir)',
|
|
253
|
+
'[.md] folded',
|
|
254
|
+
'[(none)]',
|
|
255
|
+
' LICENSE (dir)',
|
|
256
|
+
]);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('the extensionless group folds on its own empty key', () => {
|
|
260
|
+
const rows = buildRows(ENTRIES, { order: 'ext', folded: new Set(['']) });
|
|
261
|
+
assert.deepEqual(shape(rows).slice(-1), ['[(none)] folded']);
|
|
262
|
+
assert.equal(paths(rows).includes('LICENSE'), false);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test('a dotfile is extensionless and a compound name groups under its last suffix', () => {
|
|
266
|
+
const rows = buildRows([
|
|
267
|
+
entry('.gitignore', 'clean'),
|
|
268
|
+
entry('archive.tar.gz', 'clean'),
|
|
269
|
+
entry('a.js', 'clean'),
|
|
270
|
+
], { order: 'ext' });
|
|
271
|
+
assert.deepEqual(shape(rows), [
|
|
272
|
+
'[.gz]',
|
|
273
|
+
' archive.tar.gz (dir)',
|
|
274
|
+
'[.js]',
|
|
275
|
+
' a.js (dir)',
|
|
276
|
+
'[(none)]',
|
|
277
|
+
' .gitignore (dir)',
|
|
278
|
+
]);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('fold state is per order (S10)', () => {
|
|
283
|
+
test('a tree key does not fold an extension group', () => {
|
|
284
|
+
const unfolded = buildRows(ENTRIES, { order: 'ext' });
|
|
285
|
+
assert.deepEqual(buildRows(ENTRIES, { order: 'ext', folded: new Set(['lib', 'docs']) }), unfolded);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('a fold key from one order does not touch the tree either', () => {
|
|
289
|
+
const unfolded = buildRows(ENTRIES, { order: 'tree' });
|
|
290
|
+
assert.deepEqual(buildRows(ENTRIES, { order: 'tree', folded: new Set(['md']) }), unfolded);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test('toggleFold adds and removes the focused group key in that order set', () => {
|
|
294
|
+
const group = { kind: 'group', key: 'lib', label: 'lib', depth: 0, folded: false };
|
|
295
|
+
const folded = new Set();
|
|
296
|
+
assert.equal(toggleFold(group, folded), true);
|
|
297
|
+
assert.deepEqual([...folded], ['lib']);
|
|
298
|
+
assert.equal(toggleFold(group, folded), true);
|
|
299
|
+
assert.equal(folded.has('lib'), false);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test('toggleFold does nothing for a file row or no set', () => {
|
|
303
|
+
const file = { kind: 'file', entry: ENTRIES[0], depth: 0, showDirectory: true };
|
|
304
|
+
const folded = new Set();
|
|
305
|
+
assert.equal(toggleFold(file, folded), false);
|
|
306
|
+
assert.equal(folded.size, 0);
|
|
307
|
+
assert.equal(toggleFold({ kind: 'group', key: 'lib' }, undefined), false);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('holderGroup names the group row that holds a file row (S24)', () => {
|
|
311
|
+
for (const order of ['tree', 'ext']) {
|
|
312
|
+
const rows = buildRows(ENTRIES, { order });
|
|
313
|
+
const byPath = new Map(rows.map((row, index) => [row, index]));
|
|
314
|
+
for (const [row, index] of byPath) {
|
|
315
|
+
if (row.kind !== 'file' || row.depth === 0) continue;
|
|
316
|
+
const holder = holderGroup(rows, index);
|
|
317
|
+
// The file's parent folder (tree) or its extension group (ext) is the
|
|
318
|
+
// nearest group row above it, one depth shallower.
|
|
319
|
+
assert.equal(holder.kind, 'group', `${order}: ${row.entry.path} has a holder`);
|
|
320
|
+
assert.equal(holder.depth, row.depth - 1, `${order}: ${row.entry.path} holder depth`);
|
|
321
|
+
const above = rows.slice(0, index).filter((value) => value.kind === 'group' && value.depth === row.depth - 1);
|
|
322
|
+
assert.equal(holder, above[above.length - 1], `${order}: ${row.entry.path} holder is the nearest one above`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
test('holderGroup answers the extension group in ext and the folder in tree', () => {
|
|
328
|
+
const tree = buildRows(ENTRIES, { order: 'tree' });
|
|
329
|
+
const nested = tree.findIndex((row) => row.kind === 'file' && row.entry.path === 'lib/odd-prompt/odd-worktrees.md');
|
|
330
|
+
assert.equal(holderGroup(tree, nested).key, 'lib/odd-prompt');
|
|
331
|
+
const root = tree.findIndex((row) => row.kind === 'file' && row.entry.path === 'README.md');
|
|
332
|
+
assert.equal(holderGroup(tree, root), null, 'a root file has no folder to fold');
|
|
333
|
+
|
|
334
|
+
const ext = buildRows(ENTRIES, { order: 'ext' });
|
|
335
|
+
const markdown = ext.findIndex((row) => row.kind === 'file' && row.entry.path === 'README.md');
|
|
336
|
+
assert.equal(holderGroup(ext, markdown).key, 'md');
|
|
337
|
+
const license = ext.findIndex((row) => row.kind === 'file' && row.entry.path === 'LICENSE');
|
|
338
|
+
assert.equal(holderGroup(ext, license).key, '', 'the extensionless group is a holder too');
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test('holderGroup has no holder for a group row, no rows or no index', () => {
|
|
342
|
+
const rows = buildRows(ENTRIES, { order: 'tree' });
|
|
343
|
+
assert.equal(holderGroup(rows, 0), null, 'a group row holds no group');
|
|
344
|
+
assert.equal(holderGroup(rows, 99), null);
|
|
345
|
+
assert.equal(holderGroup([], 0), null);
|
|
346
|
+
assert.equal(holderGroup(undefined, 0), null);
|
|
347
|
+
const flat = buildRows(ENTRIES, { order: 'files' });
|
|
348
|
+
assert.equal(holderGroup(flat, 0), null, 'the flat list has no groups at all');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test('groupKey names a group row and nothing else', () => {
|
|
352
|
+
assert.equal(groupKey({ kind: 'group', key: 'lib/odd-prompt', label: 'odd-prompt', depth: 1, folded: false }), 'lib/odd-prompt');
|
|
353
|
+
assert.equal(groupKey({ kind: 'file', entry: ENTRIES[0], depth: 0, showDirectory: true }), null);
|
|
354
|
+
assert.equal(groupKey(undefined), null);
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
describe('the query filters files and forces groups open (S10)', () => {
|
|
359
|
+
test('the query matches the path case-insensitively', () => {
|
|
360
|
+
assert.deepEqual(paths(buildRows(ENTRIES, { order: 'files', query: 'ReAdMe' })), ['README.md']);
|
|
361
|
+
assert.deepEqual(paths(buildRows(ENTRIES, { order: 'files', query: 'REFERENCE' })), ['docs/reference.md']);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test('it filters on the whole path, not the file name', () => {
|
|
365
|
+
const rows = buildRows(ENTRIES, { order: 'tree', query: 'odd-prompt/' });
|
|
366
|
+
assert.deepEqual(shape(rows), [
|
|
367
|
+
'[lib]',
|
|
368
|
+
' [odd-prompt]',
|
|
369
|
+
' lib/odd-prompt/odd-worktrees.md',
|
|
370
|
+
]);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
test('a non-empty query reopens a folded tree group', () => {
|
|
374
|
+
const rows = buildRows(ENTRIES, {
|
|
375
|
+
order: 'tree',
|
|
376
|
+
folded: new Set(['lib', 'tools']),
|
|
377
|
+
query: 'orders',
|
|
378
|
+
});
|
|
379
|
+
assert.deepEqual(shape(rows), [
|
|
380
|
+
'[lib]',
|
|
381
|
+
' lib/files-orders.js',
|
|
382
|
+
'[tools]',
|
|
383
|
+
' tools/files-orders.test.js',
|
|
384
|
+
]);
|
|
385
|
+
assert.equal(rows.every((row) => row.kind !== 'group' || row.folded === false), true);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test('a non-empty query reopens a folded extension group', () => {
|
|
389
|
+
const rows = buildRows(ENTRIES, { order: 'ext', folded: new Set(['md', '']), query: 'license' });
|
|
390
|
+
assert.deepEqual(shape(rows), [
|
|
391
|
+
'[(none)]',
|
|
392
|
+
' LICENSE (dir)',
|
|
393
|
+
]);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
test('an empty query is the unfolded listing, and clears the filter', () => {
|
|
397
|
+
const unfolded = buildRows(ENTRIES, { order: 'tree', folded: new Set(['lib']) });
|
|
398
|
+
assert.deepEqual(buildRows(ENTRIES, { order: 'tree', folded: new Set(['lib']), query: '' }), unfolded);
|
|
399
|
+
assert.deepEqual(buildRows(ENTRIES, { order: 'tree', folded: new Set(['lib']), query: undefined }), unfolded);
|
|
400
|
+
assert.equal(paths(buildRows(ENTRIES, { order: 'files', query: '' })).length, ENTRIES.length);
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
describe('the row builder is pure (S10)', () => {
|
|
405
|
+
test('it never mutates the entries, the options or the fold set', () => {
|
|
406
|
+
const frozenEntries = Object.freeze(ENTRIES.map((value) => Object.freeze({ ...value })));
|
|
407
|
+
const folded = new Set(['lib']);
|
|
408
|
+
const options = { order: 'tree', folded, query: '' };
|
|
409
|
+
const before = JSON.stringify({ entries: frozenEntries, order: options.order, query: options.query, folded: [...folded] });
|
|
410
|
+
buildRows(frozenEntries, options);
|
|
411
|
+
buildRows(frozenEntries, { order: 'ext', folded, query: 'md' });
|
|
412
|
+
buildRows(frozenEntries, { order: 'files' });
|
|
413
|
+
const after = JSON.stringify({ entries: frozenEntries, order: options.order, query: options.query, folded: [...folded] });
|
|
414
|
+
assert.equal(after, before);
|
|
415
|
+
assert.deepEqual([...folded], ['lib']);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test('it reuses the entries by reference and returns a fresh row list per call', () => {
|
|
419
|
+
const rows = buildRows(ENTRIES, { order: 'files' });
|
|
420
|
+
assert.equal(rows[0].entry, ENTRIES.find((value) => value.path === 'lib/files-orders.js'));
|
|
421
|
+
assert.notEqual(buildRows(ENTRIES, { order: 'tree' }), buildRows(ENTRIES, { order: 'tree' }));
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
test('a row carries exactly the documented fields and no painted text', () => {
|
|
425
|
+
for (const order of ORDERS) {
|
|
426
|
+
for (const row of buildRows(ENTRIES, { order })) {
|
|
427
|
+
const keys = Object.keys(row).sort();
|
|
428
|
+
if (row.kind === 'group') assert.deepEqual(keys, ['depth', 'folded', 'key', 'kind', 'label']);
|
|
429
|
+
else assert.deepEqual(keys, ['depth', 'entry', 'kind', 'showDirectory']);
|
|
430
|
+
}
|
|
431
|
+
assert.equal(JSON.stringify(buildRows(ENTRIES, { order })).includes('\u001b'), false);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test('an empty listing paints no rows in every order', () => {
|
|
436
|
+
for (const order of ORDERS) assert.deepEqual(buildRows([], { order }), []);
|
|
437
|
+
assert.deepEqual(buildRows(undefined, { order: 'tree' }), []);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test('an unknown order falls back to the default files list', () => {
|
|
441
|
+
assert.deepEqual(buildRows(ENTRIES, { order: 'bogus' }), buildRows(ENTRIES, { order: 'files' }));
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
describe('the group keys that hold a file (S30)', () => {
|
|
446
|
+
test('tree: every folder on the way down, the top one first', () => {
|
|
447
|
+
assert.deepEqual(holderKeys('src/web/test.ts', 'tree'), ['src', 'src/web']);
|
|
448
|
+
assert.deepEqual(holderKeys('lib/view-layout.js', 'tree'), ['lib']);
|
|
449
|
+
assert.deepEqual(holderKeys('AGENTS.md', 'tree'), [], 'a repository-root file expands no group');
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
test('ext: only the extension group, the empty key for an extensionless file', () => {
|
|
453
|
+
assert.deepEqual(holderKeys('src/web/test.ts', 'ext'), ['ts']);
|
|
454
|
+
assert.deepEqual(holderKeys('LICENSE', 'ext'), ['']);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
test('the flat files order holds no group, and neither does a missing path', () => {
|
|
458
|
+
assert.deepEqual(holderKeys('src/web/test.ts', 'files'), []);
|
|
459
|
+
assert.deepEqual(holderKeys('src/web/test.ts', undefined), []);
|
|
460
|
+
assert.deepEqual(holderKeys(undefined, 'tree'), []);
|
|
461
|
+
assert.deepEqual(holderKeys('', 'ext'), []);
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
describe('the fold set an order opens with (S29, S30)', () => {
|
|
466
|
+
const keysOf = (order) => buildRows(ENTRIES, { order }).filter((row) => row.kind === 'group').map((row) => row.key);
|
|
467
|
+
|
|
468
|
+
test('every group is folded when no file is focused', () => {
|
|
469
|
+
for (const order of ['tree', 'ext']) {
|
|
470
|
+
const folded = foldsFor(ENTRIES, order, undefined);
|
|
471
|
+
assert.deepEqual([...folded].sort(), keysOf(order).sort(), `${order}: every group key is folded`);
|
|
472
|
+
const groups = buildRows(ENTRIES, { order, folded }).filter((row) => row.kind === 'group');
|
|
473
|
+
assert.equal(groups.every((row) => row.folded === true), true, `${order}: every group row paints folded`);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
test('tree: only the folders holding the focused file stay open', () => {
|
|
478
|
+
const rows = buildRows(ENTRIES, {
|
|
479
|
+
order: 'tree',
|
|
480
|
+
folded: foldsFor(ENTRIES, 'tree', 'lib/odd-prompt/odd-worktrees.md'),
|
|
481
|
+
});
|
|
482
|
+
assert.deepEqual(shape(rows), [
|
|
483
|
+
'[docs] folded',
|
|
484
|
+
'[lib]',
|
|
485
|
+
' [odd-prompt]',
|
|
486
|
+
' lib/odd-prompt/odd-worktrees.md',
|
|
487
|
+
' lib/files-orders.js',
|
|
488
|
+
' lib/view-layout.js',
|
|
489
|
+
'[tools] folded',
|
|
490
|
+
'AGENTS.md',
|
|
491
|
+
'LICENSE',
|
|
492
|
+
'README.md',
|
|
493
|
+
]);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
test('ext: only the extension group holding the focused file stays open', () => {
|
|
497
|
+
const rows = buildRows(ENTRIES, {
|
|
498
|
+
order: 'ext',
|
|
499
|
+
folded: foldsFor(ENTRIES, 'ext', 'lib/files-orders.js'),
|
|
500
|
+
});
|
|
501
|
+
assert.deepEqual(shape(rows), [
|
|
502
|
+
'[.js]',
|
|
503
|
+
' lib/files-orders.js (dir)',
|
|
504
|
+
' lib/view-layout.js (dir)',
|
|
505
|
+
' tools/files-orders.test.js (dir)',
|
|
506
|
+
'[.md] folded',
|
|
507
|
+
'[(none)] folded',
|
|
508
|
+
]);
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
test('a repository-root file opens no group in tree, and only its extension in ext', () => {
|
|
512
|
+
const tree = buildRows(ENTRIES, { order: 'tree', folded: foldsFor(ENTRIES, 'tree', 'README.md') });
|
|
513
|
+
const treeGroups = tree.filter((row) => row.kind === 'group');
|
|
514
|
+
assert.ok(treeGroups.length > 0, 'the tree listing has groups');
|
|
515
|
+
assert.equal(treeGroups.every((row) => row.folded === true), true, 'tree: every group stays folded');
|
|
516
|
+
assert.equal(paths(tree).includes('README.md'), true, 'the root file still paints at the top level');
|
|
517
|
+
|
|
518
|
+
// `ext` groups by extension, not by folder, so a root file still has a group.
|
|
519
|
+
const ext = buildRows(ENTRIES, { order: 'ext', folded: foldsFor(ENTRIES, 'ext', 'README.md') });
|
|
520
|
+
assert.deepEqual(shape(ext), [
|
|
521
|
+
'[.js] folded',
|
|
522
|
+
'[.md]',
|
|
523
|
+
' AGENTS.md (dir)',
|
|
524
|
+
' README.md (dir)',
|
|
525
|
+
' docs/reference.md (dir)',
|
|
526
|
+
' lib/odd-prompt/odd-worktrees.md (dir)',
|
|
527
|
+
'[(none)] folded',
|
|
528
|
+
]);
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
test('the flat files order has no group to fold, and an empty listing either', () => {
|
|
532
|
+
assert.equal(foldsFor(ENTRIES, 'files', 'README.md').size, 0);
|
|
533
|
+
assert.equal(foldsFor(ENTRIES, 'files', undefined).size, 0);
|
|
534
|
+
assert.equal(foldsFor([], 'tree', 'README.md').size, 0);
|
|
535
|
+
assert.equal(foldsFor(undefined, 'ext', undefined).size, 0);
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
describe('shift+space toggles every group at once (S39, S40)', () => {
|
|
540
|
+
const treeKeys = () => buildRows(ENTRIES, { order: 'tree' })
|
|
541
|
+
.filter((row) => row.kind === 'group')
|
|
542
|
+
.map((row) => row.key)
|
|
543
|
+
.sort();
|
|
544
|
+
const extKeys = () => buildRows(ENTRIES, { order: 'ext' })
|
|
545
|
+
.filter((row) => row.kind === 'group')
|
|
546
|
+
.map((row) => row.key)
|
|
547
|
+
.sort();
|
|
548
|
+
|
|
549
|
+
test('a tree with any group still expanded collapses EVERY group, the focused file folders included', () => {
|
|
550
|
+
const folded = foldsFor(ENTRIES, 'tree', 'lib/odd-prompt/odd-worktrees.md');
|
|
551
|
+
assert.equal(folded.has('lib'), false, 'the focused file folders start open');
|
|
552
|
+
assert.equal(toggleEveryFold(ENTRIES, 'tree', folded), true);
|
|
553
|
+
assert.deepEqual([...folded].sort(), treeKeys(), 'every group is folded, holders included');
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
test('a tree whose every group is collapsed expands every group instead', () => {
|
|
557
|
+
const folded = new Set(treeKeys());
|
|
558
|
+
assert.equal(toggleEveryFold(ENTRIES, 'tree', folded), true);
|
|
559
|
+
assert.equal(folded.size, 0, 'no group is left folded');
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
test('a mixed tree collapses on the first press and expands on the second', () => {
|
|
563
|
+
const folded = new Set(['docs']);
|
|
564
|
+
assert.equal(toggleEveryFold(ENTRIES, 'tree', folded), true);
|
|
565
|
+
assert.deepEqual([...folded].sort(), treeKeys(), 'the first press collapses everything');
|
|
566
|
+
assert.equal(toggleEveryFold(ENTRIES, 'tree', folded), true);
|
|
567
|
+
assert.equal(folded.size, 0, 'the second press expands everything');
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
test('ext is one level and toggles the same way', () => {
|
|
571
|
+
const folded = foldsFor(ENTRIES, 'ext', 'lib/files-orders.js');
|
|
572
|
+
assert.equal(folded.has('js'), false);
|
|
573
|
+
assert.equal(toggleEveryFold(ENTRIES, 'ext', folded), true);
|
|
574
|
+
assert.deepEqual([...folded].sort(), extKeys(), 'the focused extension group collapses too');
|
|
575
|
+
assert.equal(toggleEveryFold(ENTRIES, 'ext', folded), true);
|
|
576
|
+
assert.equal(folded.size, 0, 'every extension group is open again');
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
test('it never touches the flat files order, no set, or a listing with no group', () => {
|
|
580
|
+
const folded = new Set();
|
|
581
|
+
assert.equal(toggleEveryFold(ENTRIES, 'files', folded), false);
|
|
582
|
+
assert.equal(folded.size, 0);
|
|
583
|
+
assert.equal(toggleEveryFold(ENTRIES, 'tree', undefined), false);
|
|
584
|
+
assert.equal(toggleEveryFold([], 'tree', folded), false);
|
|
585
|
+
assert.equal(toggleEveryFold([entry('README.md', 'clean')], 'tree', folded), false, 'a root file is no group');
|
|
586
|
+
assert.equal(folded.size, 0);
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
test('everyGroupFolded names the direction the legend paints (S40)', () => {
|
|
590
|
+
assert.equal(everyGroupFolded(ENTRIES, 'tree', new Set(treeKeys())), true, 'every group collapsed');
|
|
591
|
+
assert.equal(everyGroupFolded(ENTRIES, 'tree', foldsFor(ENTRIES, 'tree', 'lib/files-orders.js')), false,
|
|
592
|
+
'the focused file folders open');
|
|
593
|
+
assert.equal(everyGroupFolded(ENTRIES, 'ext', new Set(extKeys())), true);
|
|
594
|
+
assert.equal(everyGroupFolded(ENTRIES, 'ext', new Set(['md'])), false);
|
|
595
|
+
assert.equal(everyGroupFolded(ENTRIES, 'files', new Set()), true, 'the flat order paints no group, so none is open');
|
|
596
|
+
});
|
|
597
|
+
});
|