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.
Files changed (160) hide show
  1. package/README.md +54 -319
  2. package/extensions/odd-worktree-tools.ts +4182 -2539
  3. package/lib/bash-activity.js +1166 -0
  4. package/lib/bash-design.js +684 -0
  5. package/lib/bash-destructive.js +559 -0
  6. package/lib/bash-frame.js +205 -0
  7. package/lib/card-content.js +23 -0
  8. package/lib/card-style.js +175 -0
  9. package/lib/checkout-facts.js +30 -70
  10. package/lib/codegraph-card-preview.js +628 -0
  11. package/lib/codegraph-card.js +515 -0
  12. package/lib/codegraph-compaction.js +76 -0
  13. package/lib/codegraph-daemon.js +246 -0
  14. package/lib/codegraph-edit-sync.js +182 -0
  15. package/lib/codegraph-guard-target.js +337 -0
  16. package/lib/codegraph-guard.js +211 -0
  17. package/lib/codegraph-index.js +1020 -0
  18. package/lib/codegraph-lock.js +607 -0
  19. package/lib/codegraph-mcp-config.js +134 -0
  20. package/lib/codegraph-mcp.js +123 -0
  21. package/lib/codegraph-paths.js +69 -0
  22. package/lib/codegraph-prompt/explore.md +11 -0
  23. package/lib/codegraph-prompt/fix.md +6 -0
  24. package/lib/codegraph-prompt/generic.md +8 -0
  25. package/lib/codegraph-prompt/judge.md +9 -0
  26. package/lib/codegraph-prompt/orchestrator.md +17 -0
  27. package/lib/codegraph-prompt/verify.md +10 -0
  28. package/lib/codegraph-prompt/worker.md +7 -0
  29. package/lib/codegraph-role.js +55 -0
  30. package/lib/codegraph-rules.js +146 -0
  31. package/lib/codegraph-session.js +303 -383
  32. package/lib/codegraph-warmup.js +139 -0
  33. package/lib/file-card-markdown.js +141 -0
  34. package/lib/file-card-resolver.js +245 -0
  35. package/lib/file-card.js +659 -0
  36. package/lib/files-index.js +387 -0
  37. package/lib/files-insert.js +81 -0
  38. package/lib/files-orders.js +326 -0
  39. package/lib/files-picker-view.js +1421 -0
  40. package/lib/files-preview.js +338 -0
  41. package/lib/files-scope-detail.js +171 -0
  42. package/lib/files-scope-view.js +507 -0
  43. package/lib/gh-issues.js +323 -15
  44. package/lib/issue-preview.js +26 -7
  45. package/lib/issues-bash-mutation.js +206 -0
  46. package/lib/issues-cache-store.js +261 -0
  47. package/lib/issues-section.js +710 -0
  48. package/lib/issues-view.js +649 -52
  49. package/lib/odd-prompt/odd-worktrees.md +21 -0
  50. package/lib/odd-worktrees-prompt.js +10 -28
  51. package/lib/related-issues-cache.js +210 -0
  52. package/lib/shell-card.js +825 -0
  53. package/lib/skill-odd-card.js +183 -0
  54. package/lib/tui-paint.js +4 -5
  55. package/lib/warp-create-panel.js +538 -250
  56. package/lib/warp-create-picker.js +56 -9
  57. package/lib/warp-delete-confirm.js +19 -28
  58. package/lib/warp-selector-view.js +160 -82
  59. package/lib/which-command.js +90 -0
  60. package/lib/worktree-card.js +267 -897
  61. package/lib/worktree-cards.js +383 -0
  62. package/lib/worktree-create.js +287 -0
  63. package/lib/worktree-git.js +3 -3
  64. package/lib/worktree-guard.js +548 -0
  65. package/lib/worktree-hooks.js +421 -712
  66. package/lib/worktree-list.js +120 -0
  67. package/lib/worktree-registry.js +162 -879
  68. package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
  69. package/lib/worktree-setup-runner.js +376 -0
  70. package/lib/worktree-setup.js +140 -0
  71. package/lib/worktree-warp-busy.js +462 -85
  72. package/lib/worktree-warp-sessions.js +1 -2
  73. package/package.json +2 -2
  74. package/tools/bash-activity.test.js +1420 -0
  75. package/tools/bash-design.test.js +1093 -0
  76. package/tools/bash-destructive.test.js +139 -0
  77. package/tools/card-content.test.js +44 -0
  78. package/tools/card-style.test.js +298 -0
  79. package/tools/codegraph-card-preview.test.js +254 -0
  80. package/tools/codegraph-card.test.js +1080 -0
  81. package/tools/codegraph-compaction.test.js +378 -0
  82. package/tools/codegraph-daemon.test.js +248 -0
  83. package/tools/codegraph-edit-sync.test.js +295 -0
  84. package/tools/codegraph-guard-target.test.js +174 -0
  85. package/tools/codegraph-guard.test.js +238 -0
  86. package/tools/codegraph-index.test.js +1948 -0
  87. package/tools/codegraph-lock.test.js +932 -0
  88. package/tools/codegraph-mcp-config.test.js +181 -0
  89. package/tools/codegraph-mcp.test.js +194 -0
  90. package/tools/codegraph-paths.test.js +44 -0
  91. package/tools/codegraph-role.test.js +30 -0
  92. package/tools/codegraph-rules.test.js +250 -0
  93. package/tools/codegraph-session.test.js +660 -391
  94. package/tools/codegraph-warmup.test.js +316 -0
  95. package/tools/commands.test.js +510 -31
  96. package/tools/file-card-markdown.test.js +188 -0
  97. package/tools/file-card.test.js +1289 -0
  98. package/tools/files-bridge.test.js +575 -0
  99. package/tools/files-command.test.js +613 -0
  100. package/tools/files-index.test.js +473 -0
  101. package/tools/files-insert.test.js +139 -0
  102. package/tools/files-orders.test.js +597 -0
  103. package/tools/files-picker-view.test.js +1889 -0
  104. package/tools/files-preview.test.js +452 -0
  105. package/tools/files-scope-detail.test.js +264 -0
  106. package/tools/files-scope-view.test.js +614 -0
  107. package/tools/fixtures/card-codegraph-outputs.js +110 -0
  108. package/tools/fixtures/codegraph-cli-stub.js +16 -0
  109. package/tools/fixtures/codegraph-init-process.js +28 -0
  110. package/tools/fixtures/codegraph-lock-worker.js +117 -0
  111. package/tools/fixtures/daemon-fake.js +98 -0
  112. package/tools/fixtures/daemon-mcp-server.js +39 -0
  113. package/tools/fixtures/daemon-warmup-worker.js +12 -0
  114. package/tools/fixtures/load-extension.js +136 -3
  115. package/tools/gh-issues-feedback.test.js +31 -7
  116. package/tools/gh-issues.test.js +417 -1
  117. package/tools/issue-preview.test.js +44 -7
  118. package/tools/issues-bash-mutation.test.js +101 -0
  119. package/tools/issues-cache-store.test.js +222 -0
  120. package/tools/issues-command.test.js +1517 -67
  121. package/tools/issues-open-guard.test.js +1096 -0
  122. package/tools/issues-section.test.js +4235 -0
  123. package/tools/issues-seed-query-regression.test.js +67 -0
  124. package/tools/issues-view.test.js +1489 -60
  125. package/tools/odd-worktrees-prompt.test.js +98 -65
  126. package/tools/package-surface.test.js +431 -36
  127. package/tools/related-issues-cache.test.js +324 -0
  128. package/tools/shell-card.test.js +834 -0
  129. package/tools/skill-odd-card.test.js +200 -0
  130. package/tools/t5-session-identity.test.js +44 -22
  131. package/tools/warp-busy-guard.test.js +2565 -309
  132. package/tools/warp-create-panel.test.js +499 -74
  133. package/tools/warp-create-picker.test.js +101 -5
  134. package/tools/warp-delete-confirm.test.js +49 -15
  135. package/tools/warp-empty-session.test.js +0 -1
  136. package/tools/warp-fallback-regression.test.js +533 -0
  137. package/tools/warp-selector-view.test.js +460 -196
  138. package/tools/which-command.test.js +126 -0
  139. package/tools/worktree-card.test.js +551 -0
  140. package/tools/worktree-cards.test.js +845 -0
  141. package/tools/worktree-changes.test.js +4 -5
  142. package/tools/worktree-create.test.js +489 -0
  143. package/tools/worktree-guard.test.js +823 -0
  144. package/tools/worktree-hooks.test.js +905 -0
  145. package/tools/worktree-list.test.js +170 -0
  146. package/tools/worktree-registry.test.js +89 -230
  147. package/tools/worktree-remove-async.test.js +318 -0
  148. package/tools/worktree-setup-runner.test.js +276 -0
  149. package/tools/worktree-setup.test.js +140 -0
  150. package/tools/worktree-tools.test.js +419 -199
  151. package/lib/codegraph-commands.js +0 -165
  152. package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
  153. package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
  154. package/lib/worktree-model-result.js +0 -291
  155. package/tools/codegraph-commands.test.js +0 -371
  156. package/tools/herdr-free-create.test.js +0 -161
  157. package/tools/worktree-close-herdr-async.test.js +0 -204
  158. package/tools/worktree-odd-migration.test.js +0 -224
  159. package/tools/worktree-registry-cache.test.js +0 -163
  160. package/tools/worktree-registry-odd.test.js +0 -231
@@ -0,0 +1,452 @@
1
+ 'use strict';
2
+ // T5 (S11, S12): the pure preview pane of `/files`. It reads no file and paints
3
+ // nothing itself: `previewRows` turns one `readFilePreview` result into the exact
4
+ // rows and cells the view draws, at a given pane width and height, with the
5
+ // gutter, the `line/total` position, the ANSI-aware wrap of a highlighted line
6
+ // and every plain-text degradation of the injected highlighter.
7
+ //
8
+ // Asserted through the public output only: cell text and role, the row count,
9
+ // `boxed` and `maxScroll`. No module-internal state is read.
10
+
11
+ const { test, describe } = require('node:test');
12
+ const assert = require('node:assert/strict');
13
+
14
+ const { previewRows } = require('../lib/files-preview.js');
15
+
16
+ const ANSI = /\x1b\[[0-9;]*m/g;
17
+ const stripAnsi = (value) => String(value).replace(ANSI, '');
18
+ const textOf = (row) => row.cells.map((cell) => cell.text).join('');
19
+ const plainOf = (row) => stripAnsi(textOf(row));
20
+ const plainRows = (result) => result.rows.map(plainOf);
21
+
22
+ // The injected measurement seam the host provides. The test copy measures ANSI
23
+ // as zero width and counts code points, so an assertion can state the PAINTED
24
+ // width without importing the host package (CI installs nothing).
25
+ function createMetrics() {
26
+ return {
27
+ visibleWidth(text) {
28
+ return [...stripAnsi(text)].length;
29
+ },
30
+ truncateToWidth(text, width, ellipsis = '…') {
31
+ if (width <= 0) return '';
32
+ const value = String(text);
33
+ if (this.visibleWidth(value) <= width) return value;
34
+ const mark = ellipsis === undefined ? '' : String(ellipsis);
35
+ const room = Math.max(0, width - [...stripAnsi(mark)].length);
36
+ return [...stripAnsi(value)].slice(0, room).join('') + mark;
37
+ },
38
+ wrapTextWithAnsi(text, width) {
39
+ return plainChunks(text, width);
40
+ },
41
+ };
42
+ }
43
+
44
+ const METRICS = createMetrics();
45
+
46
+ function plainChunks(text, width) {
47
+ if (width <= 0) return [text];
48
+ const characters = [...text];
49
+ const rows = [];
50
+ for (let index = 0; index < characters.length; index += width) {
51
+ rows.push(characters.slice(index, index + width).join(''));
52
+ }
53
+ return rows.length > 0 ? rows : [''];
54
+ }
55
+
56
+ function render(preview, options) {
57
+ return previewRows(preview, {
58
+ width: 16,
59
+ height: 6,
60
+ scroll: 0,
61
+ metrics: METRICS,
62
+ ...options,
63
+ });
64
+ }
65
+
66
+ const TEXT_PREVIEW = { kind: 'text', lines: ['alpha', 'beta', 'gamma'], truncated: false };
67
+
68
+ describe('the preview paints its rounded box, gutter and position (S11)', () => {
69
+ test('a text preview fills the pane as a box with one numbered row per line', () => {
70
+ const out = render(TEXT_PREVIEW);
71
+
72
+ assert.equal(out.boxed, true);
73
+ assert.equal(out.maxScroll, 0);
74
+ assert.equal(out.rows.length, 6);
75
+ assert.deepEqual(plainRows(out), [
76
+ '╭────────── 1/3╮',
77
+ '│1 alpha │',
78
+ '│2 beta │',
79
+ '│3 gamma │',
80
+ '│ │',
81
+ '╰──────────────╯',
82
+ ]);
83
+
84
+ // The position is embedded at the right of the TOP border: one gap after the
85
+ // dashes, then the label, then the closing corner.
86
+ assert.deepEqual(out.rows[0].cells, [
87
+ { text: '╭', role: 'border' },
88
+ { text: '──────────', role: 'border' },
89
+ { text: ' 1/3', role: 'text' },
90
+ { text: '╮', role: 'border' },
91
+ ]);
92
+ // The number is the dim gutter, the text is plain text, one gap between them.
93
+ assert.deepEqual(out.rows[1].cells, [
94
+ { text: '│', role: 'border' },
95
+ { text: '1', role: 'dim' },
96
+ { text: ' alpha'.padEnd(13), role: 'text' },
97
+ { text: '│', role: 'border' },
98
+ ]);
99
+ // A row past the end of the file is an empty boxed row, not a short one.
100
+ assert.deepEqual(out.rows[4].cells, [
101
+ { text: '│', role: 'border' },
102
+ { text: ' ', role: 'dim' },
103
+ { text: ' '.repeat(13), role: 'text' },
104
+ { text: '│', role: 'border' },
105
+ ]);
106
+ assert.deepEqual(out.rows[5].cells, [
107
+ { text: '╰', role: 'border' },
108
+ { text: '──────────────', role: 'border' },
109
+ { text: '╯', role: 'border' },
110
+ ]);
111
+ });
112
+
113
+ test('the position names the top visible line and follows the scroll', () => {
114
+ const lines = Array.from({ length: 10 }, (_, index) => `line${index + 1}`);
115
+ const preview = { kind: 'text', lines, truncated: false };
116
+
117
+ const top = render(preview, { width: 12, height: 5 });
118
+ assert.equal(top.boxed, true);
119
+ assert.equal(top.maxScroll, 7);
120
+ assert.deepEqual(plainRows(top), [
121
+ '╭───── 1/10╮',
122
+ '│ 1 line1 │',
123
+ '│ 2 line2 │',
124
+ '│ 3 line3 │',
125
+ '╰──────────╯',
126
+ ]);
127
+
128
+ const middle = render(preview, { width: 12, height: 5, scroll: 2 });
129
+ assert.deepEqual(plainRows(middle), [
130
+ '╭───── 3/10╮',
131
+ '│ 3 line3 │',
132
+ '│ 4 line4 │',
133
+ '│ 5 line5 │',
134
+ '╰──────────╯',
135
+ ]);
136
+
137
+ const end = render(preview, { width: 12, height: 5, scroll: 999 });
138
+ assert.deepEqual(plainRows(end), [
139
+ '╭───── 8/10╮',
140
+ '│ 8 line8 │',
141
+ '│ 9 line9 │',
142
+ '│10 line10 │',
143
+ '╰──────────╯',
144
+ ]);
145
+ });
146
+ });
147
+
148
+ describe('a long line wraps under the same text column (S11)', () => {
149
+ test('a wrapped line is numbered once and its continuation keeps the column', () => {
150
+ const out = render({ kind: 'text', lines: ['abcdefghij'], truncated: false }, { width: 12, height: 5 });
151
+
152
+ assert.equal(out.boxed, true);
153
+ assert.equal(out.maxScroll, 0);
154
+ assert.deepEqual(plainRows(out), [
155
+ '╭────── 1/1╮',
156
+ '│1 abcdefgh│',
157
+ '│ ij │',
158
+ '│ │',
159
+ '╰──────────╯',
160
+ ]);
161
+ // The continuation row leaves its gutter blank and starts its text in the
162
+ // same column as the first row's text.
163
+ assert.deepEqual(out.rows[2].cells, [
164
+ { text: '│', role: 'border' },
165
+ { text: ' ', role: 'dim' },
166
+ { text: ' ij'.padEnd(9), role: 'text' },
167
+ { text: '│', role: 'border' },
168
+ ]);
169
+ });
170
+
171
+ test('a scroll that stops inside a wrapped line still reports that line', () => {
172
+ const preview = { kind: 'text', lines: ['abcdefghij', 'second'], truncated: false };
173
+ const out = render(preview, { width: 12, height: 4, scroll: 1 });
174
+
175
+ assert.equal(out.maxScroll, 1);
176
+ assert.equal(plainRows(out)[0], '╭────── 1/2╮');
177
+ assert.deepEqual(out.rows[1].cells, [
178
+ { text: '│', role: 'border' },
179
+ { text: ' ', role: 'dim' },
180
+ { text: ' ij'.padEnd(9), role: 'text' },
181
+ { text: '│', role: 'border' },
182
+ ]);
183
+ });
184
+ });
185
+
186
+ describe('the injected highlighter colours the preview (S12)', () => {
187
+ const PREVIEW = { kind: 'text', lines: ['abcdefghij'], truncated: false };
188
+
189
+ test('a highlighted line goes through the ANSI-aware wrapper, once per call', () => {
190
+ const highlightCalls = [];
191
+ const wrapperCalls = [];
192
+ const highlight = (code, lang) => {
193
+ highlightCalls.push({ code, lang });
194
+ return ['\x1b[31mabcdefghij\x1b[0m'];
195
+ };
196
+ const metrics = {
197
+ ...METRICS,
198
+ wrapTextWithAnsi(text, width) {
199
+ wrapperCalls.push({ text, width });
200
+ return ['\x1b[31mabcdefgh', 'ij\x1b[0m'];
201
+ },
202
+ };
203
+
204
+ const out = render(PREVIEW, {
205
+ width: 12,
206
+ height: 5,
207
+ highlight,
208
+ languageForPath: () => 'txt',
209
+ path: 'a.txt',
210
+ metrics,
211
+ });
212
+
213
+ assert.deepEqual(highlightCalls, [{ code: 'abcdefghij', lang: 'txt' }]);
214
+ assert.deepEqual(wrapperCalls, [{ text: '\x1b[31mabcdefghij\x1b[0m', width: 8 }]);
215
+ assert.deepEqual(out.rows[1].cells, [
216
+ { text: '│', role: 'border' },
217
+ { text: '1', role: 'dim' },
218
+ { text: ' \x1b[31mabcdefgh', role: 'text' },
219
+ { text: '│', role: 'border' },
220
+ ]);
221
+ assert.deepEqual(out.rows[2].cells, [
222
+ { text: '│', role: 'border' },
223
+ { text: ' ', role: 'dim' },
224
+ { text: ' ij\x1b[0m'.padEnd(13), role: 'text' },
225
+ { text: '│', role: 'border' },
226
+ ]);
227
+ // The gutter keeps its dim tone and the colour arrives on the text role only.
228
+ for (const row of out.rows) assert.equal(METRICS.visibleWidth(textOf(row)), 12);
229
+ });
230
+
231
+ test('without a highlighter the plain path never touches the ANSI wrapper', () => {
232
+ const metrics = {
233
+ ...METRICS,
234
+ wrapTextWithAnsi() {
235
+ throw new Error('the plain path must not use the ANSI wrapper');
236
+ },
237
+ };
238
+ const out = render({ kind: 'text', lines: ['alpha'], truncated: false }, { width: 12, height: 5, metrics });
239
+
240
+ assert.equal(textOf(out.rows[1]).includes('\x1b'), false);
241
+ assert.deepEqual(out.rows[1].cells, [
242
+ { text: '│', role: 'border' },
243
+ { text: '1', role: 'dim' },
244
+ { text: ' alpha'.padEnd(9), role: 'text' },
245
+ { text: '│', role: 'border' },
246
+ ]);
247
+ });
248
+
249
+ test('a highlighter that paints the text unchanged keeps the plain preview', () => {
250
+ const plain = render({ kind: 'text', lines: ['alpha', 'beta'], truncated: false }, { width: 20, height: 5 });
251
+ const out = render({ kind: 'text', lines: ['alpha', 'beta'], truncated: false }, {
252
+ width: 20,
253
+ height: 5,
254
+ highlight: (code) => code.split('\n'),
255
+ languageForPath: () => 'txt',
256
+ path: 'a.txt',
257
+ });
258
+ assert.deepEqual(out, plain);
259
+ });
260
+
261
+ test('every highlighter failure degrades to the same plain preview', () => {
262
+ const preview = { kind: 'text', lines: ['alpha', 'beta'], truncated: false };
263
+ const base = render(preview, { width: 20, height: 5 });
264
+ const failures = [
265
+ {
266
+ name: 'the highlighter throws',
267
+ options: { highlight: () => { throw new Error('no theme'); }, languageForPath: () => 'js', path: 'a.js' },
268
+ },
269
+ {
270
+ name: 'the highlighter answers something that is not a list',
271
+ options: { highlight: () => 'not a list', languageForPath: () => 'js', path: 'a.js' },
272
+ },
273
+ {
274
+ name: 'the highlighter answers fewer lines than the file',
275
+ options: { highlight: () => ['only one'], languageForPath: () => 'js', path: 'a.js' },
276
+ },
277
+ {
278
+ name: 'the highlighter answers a non-string line',
279
+ options: { highlight: () => ['one', undefined], languageForPath: () => 'js', path: 'a.js' },
280
+ },
281
+ {
282
+ name: 'the language is unknown',
283
+ options: { highlight: () => ['one', 'two'], languageForPath: () => undefined, path: 'a.unknown' },
284
+ },
285
+ {
286
+ name: 'the language is empty',
287
+ options: { highlight: () => ['one', 'two'], languageForPath: () => '', path: 'a.unknown' },
288
+ },
289
+ {
290
+ name: 'the language resolver throws',
291
+ options: { highlight: () => ['one', 'two'], languageForPath: () => { throw new Error('no theme'); }, path: 'a.js' },
292
+ },
293
+ {
294
+ name: 'there is no language resolver',
295
+ options: { highlight: () => ['one', 'two'], path: 'a.js' },
296
+ },
297
+ {
298
+ name: 'there is no path to resolve',
299
+ options: { highlight: () => ['one', 'two'], languageForPath: () => 'js' },
300
+ },
301
+ ];
302
+ for (const failure of failures) {
303
+ assert.deepEqual(render(preview, { width: 20, height: 5, ...failure.options }), base, failure.name);
304
+ }
305
+ });
306
+
307
+ test('an unknown language never calls the highlighter at all', () => {
308
+ let calls = 0;
309
+ const out = render({ kind: 'text', lines: ['alpha'], truncated: false }, {
310
+ width: 20,
311
+ height: 5,
312
+ highlight: () => {
313
+ calls += 1;
314
+ return ['painted'];
315
+ },
316
+ languageForPath: () => undefined,
317
+ path: 'a.unknown',
318
+ });
319
+ assert.equal(calls, 0);
320
+ assert.deepEqual(out, render({ kind: 'text', lines: ['alpha'], truncated: false }, { width: 20, height: 5 }));
321
+ });
322
+ });
323
+
324
+ describe('a binary, an error and a truncation are notices (S11)', () => {
325
+ test('a binary preview paints its message instead of bytes, with no position label', () => {
326
+ const out = render(
327
+ { kind: 'binary', message: 'Binary file — preview not available.' },
328
+ { width: 24, height: 4 }
329
+ );
330
+
331
+ assert.equal(out.boxed, true);
332
+ assert.equal(out.maxScroll, 0);
333
+ assert.deepEqual(plainRows(out), [
334
+ '╭──────────────────────╮',
335
+ '│ Binary file — previe│',
336
+ '│ w not available. │',
337
+ '╰──────────────────────╯',
338
+ ]);
339
+ assert.deepEqual(out.rows[1].cells, [
340
+ { text: '│', role: 'border' },
341
+ { text: ' ', role: 'dim' },
342
+ { text: ' Binary file — previe', role: 'text' },
343
+ { text: '│', role: 'border' },
344
+ ]);
345
+ });
346
+
347
+ test('an error preview paints the reader message, not an empty pane', () => {
348
+ const out = render(
349
+ { kind: 'error', message: 'Cannot read nope.txt (ENOENT).' },
350
+ { width: 24, height: 4 }
351
+ );
352
+
353
+ assert.equal(out.boxed, true);
354
+ assert.equal(out.maxScroll, 0);
355
+ assert.equal(plainOf(out.rows[0]).includes('/'), false);
356
+ assert.equal(out.rows[0].cells.some((cell) => cell.role === 'text'), false);
357
+ assert.equal(plainOf(out.rows[1]).includes('Cannot read nope.txt'), true);
358
+ assert.deepEqual(out.rows[1].cells[2], { text: ' Cannot read nope.txt', role: 'text' });
359
+ });
360
+
361
+ test('a truncated preview paints the notice row and marks the position', () => {
362
+ const out = render({ kind: 'text', lines: ['alpha', 'beta'], truncated: true });
363
+
364
+ assert.equal(out.maxScroll, 0);
365
+ assert.deepEqual(plainRows(out), [
366
+ '╭───────── 1/2+╮',
367
+ '│1 alpha │',
368
+ '│2 beta │',
369
+ '│ … preview tr│',
370
+ '│ uncated. │',
371
+ '╰──────────────╯',
372
+ ]);
373
+ // The notice is not a file line: its gutter stays blank.
374
+ assert.deepEqual(out.rows[3].cells, [
375
+ { text: '│', role: 'border' },
376
+ { text: ' ', role: 'dim' },
377
+ { text: ' … preview tr', role: 'text' },
378
+ { text: '│', role: 'border' },
379
+ ]);
380
+ assert.deepEqual(out.rows[4].cells, [
381
+ { text: '│', role: 'border' },
382
+ { text: ' ', role: 'dim' },
383
+ { text: ' uncated.'.padEnd(13), role: 'text' },
384
+ { text: '│', role: 'border' },
385
+ ]);
386
+ });
387
+ });
388
+
389
+ describe('the scroll is clamped to the preview (S11)', () => {
390
+ const lines = Array.from({ length: 10 }, (_, index) => `line${index + 1}`);
391
+ const preview = { kind: 'text', lines, truncated: false };
392
+
393
+ test('a negative scroll paints the first page and an oversized one the last', () => {
394
+ const zero = render(preview, { width: 12, height: 5, scroll: 0 });
395
+ assert.deepEqual(render(preview, { width: 12, height: 5, scroll: -4 }), zero);
396
+
397
+ const end = render(preview, { width: 12, height: 5, scroll: 999 });
398
+ assert.equal(end.maxScroll, 7);
399
+ assert.equal(plainRows(end)[0], '╭───── 8/10╮');
400
+ assert.equal(plainOf(end.rows[1]).includes('line8'), true);
401
+ });
402
+
403
+ test('a fractional scroll is truncated and an unknown one falls to the top', () => {
404
+ assert.equal(plainRows(render(preview, { width: 12, height: 5, scroll: 2.9 }))[0], '╭───── 3/10╮');
405
+ assert.deepEqual(
406
+ render(preview, { width: 12, height: 5, scroll: Number.NaN }),
407
+ render(preview, { width: 12, height: 5, scroll: 0 })
408
+ );
409
+ });
410
+ });
411
+
412
+ describe('a short body paints the preview unbordered (S11)', () => {
413
+ test('two rows paint the position row and one content row with no frame', () => {
414
+ const out = render({ kind: 'text', lines: ['alpha'], truncated: false }, { width: 16, height: 2 });
415
+
416
+ assert.equal(out.boxed, false);
417
+ assert.deepEqual(plainRows(out), [' '.repeat(13) + '1/1', '1' + ' alpha'.padEnd(15)]);
418
+ assert.deepEqual(out.rows[1].cells, [
419
+ { text: '1', role: 'dim' },
420
+ { text: ' alpha'.padEnd(15), role: 'text' },
421
+ ]);
422
+ assert.equal(plainRows(out).some((row) => /[╭╮╰╯│─]/.test(row)), false);
423
+ });
424
+
425
+ test('one row paints only the position row', () => {
426
+ const out = render({ kind: 'text', lines: ['alpha'], truncated: false }, { width: 16, height: 1 });
427
+
428
+ assert.equal(out.boxed, false);
429
+ assert.deepEqual(plainRows(out), [' '.repeat(13) + '1/1']);
430
+ assert.equal(out.maxScroll, 1);
431
+ });
432
+
433
+ test('a pane narrower than the box frame keeps the content unbordered', () => {
434
+ const out = render({ kind: 'text', lines: ['alpha'], truncated: false }, { width: 2, height: 4 });
435
+
436
+ assert.equal(out.boxed, false);
437
+ assert.equal(out.rows.length, 4);
438
+ assert.equal(plainRows(out).some((row) => /[╭╮╰╯│─]/.test(row)), false);
439
+ });
440
+ });
441
+
442
+ describe('preview text is painted as terminal-safe plain text (S11)', () => {
443
+ test('an escape sequence is stripped and a tab becomes two cells', () => {
444
+ const out = render(
445
+ { kind: 'text', lines: ['\u001b[31mred\u001b[0m\tx'], truncated: false },
446
+ { width: 20, height: 5 }
447
+ );
448
+
449
+ assert.equal(textOf(out.rows[1]).includes('\u001b'), false);
450
+ assert.equal(plainOf(out.rows[1]).includes('red x'), true);
451
+ });
452
+ });