pi-odd-worktree 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -9
- package/extensions/odd-worktree-tools.ts +68 -3
- package/lib/bash-design.js +161 -38
- package/lib/diff-design.js +706 -0
- package/lib/file-card-resolver.js +19 -9
- package/lib/file-card.js +9 -3
- package/package.json +1 -1
- package/tools/bash-design.test.js +305 -8
- package/tools/diff-design.test.js +635 -0
- package/tools/file-card.test.js +100 -7
- package/tools/package-surface.test.js +25 -5
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The `diff` design (T2, S1/S2/S5/S7/S8): what a caller of the bridge's `registerToolDesign`
|
|
3
|
+
// observes on the second `Card diff` line, and the rows it draws.
|
|
4
|
+
const { test, describe } = require('node:test');
|
|
5
|
+
const assert = require('node:assert/strict');
|
|
6
|
+
const {
|
|
7
|
+
DIFF_DESIGN_ID,
|
|
8
|
+
DIFF_DESIGN_LABEL,
|
|
9
|
+
DIFF_DESIGN_PREVIEW,
|
|
10
|
+
applyDiffDesign,
|
|
11
|
+
bridgeSupportsDiffLine,
|
|
12
|
+
diffColorDesign,
|
|
13
|
+
registerDiffDesign,
|
|
14
|
+
seedDiffDesignSelection,
|
|
15
|
+
} = require('../lib/diff-design.js');
|
|
16
|
+
|
|
17
|
+
const WIDTH = 60;
|
|
18
|
+
// A theme that NAMES the role it was asked for, so a row states its paint instead of an escape.
|
|
19
|
+
const theme = { fg: (role, text) => `<${role}>${text}</${role}>` };
|
|
20
|
+
// The same theme, stripped back to the text a terminal would show: the role tags of the fake theme
|
|
21
|
+
// and the escape sequences the host's own highlighter emits.
|
|
22
|
+
const unpaint = (row) => row.replace(/<\/?[a-z][A-Za-z0-9]*>/gu, '').replace(/\u001b\[[0-9;]*m/gu, '');
|
|
23
|
+
const cols = (row) => Array.from(unpaint(row)).length;
|
|
24
|
+
// The paint Pi's highlighter hands back: an escape sequence around the line's own text.
|
|
25
|
+
const HIGHLIGHT = (line) => `\u001b[36m${line}\u001b[39m`;
|
|
26
|
+
// One frame cell painted in the tone's role, as the host paints it.
|
|
27
|
+
const toneCell = (cell) => `\u001b[32m${cell}\u001b[39m`;
|
|
28
|
+
|
|
29
|
+
// ---- the host's two card halves, as Gentle Shell's quiet tool card draws them -------------
|
|
30
|
+
//
|
|
31
|
+
// The host's card is `renderShell: "self"` and split across the two halves: the CALL rows are the
|
|
32
|
+
// frame's top rule (the heading, and — once the call finished — the host's own expand hint); the
|
|
33
|
+
// RESULT rows are one band row (float only), the body rows between the frame's sides, and the
|
|
34
|
+
// closing rule. Every row below is exactly WIDTH columns.
|
|
35
|
+
|
|
36
|
+
const NEON_PREFIX = `${toneCell('│')} `;
|
|
37
|
+
const NEON_TAIL = ` ${toneCell('│')}`;
|
|
38
|
+
const neonBody = (text) => `${NEON_PREFIX}${text.padEnd(WIDTH - 4)}${NEON_TAIL}`;
|
|
39
|
+
const neonClose = () => `╰${'─'.repeat(WIDTH - 2)}╯`;
|
|
40
|
+
const neonCall = (hint = 'ctrl+o to expand') => {
|
|
41
|
+
const head = '╭─ + write lib/app.js (2 lines) ';
|
|
42
|
+
const tail = ` ${hint} ─╮`;
|
|
43
|
+
return `${head}${'─'.repeat(WIDTH - head.length - tail.length)}${tail}`;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const FLOAT_PREFIX = ' ▎ ';
|
|
47
|
+
const FLOAT_TAIL = ' ';
|
|
48
|
+
const floatBand = () => ` ▎${' '.repeat(WIDTH - 2)}`;
|
|
49
|
+
const floatBody = (text) => `${FLOAT_PREFIX}${text.padEnd(WIDTH - 6)}${FLOAT_TAIL}`;
|
|
50
|
+
const floatClose = floatBand;
|
|
51
|
+
const floatCall = (hint = 'ctrl+o to expand') => [floatBand(), floatBody(`+ write lib/app.js (2 lines) ${hint}`)];
|
|
52
|
+
|
|
53
|
+
const editCard = () => [
|
|
54
|
+
'╭─ edit lib/app.js ─────────────────────╮',
|
|
55
|
+
'│ @@ -12,2 +12,2 @@ │',
|
|
56
|
+
'│ -12 const total = 1 │',
|
|
57
|
+
'│ +12 const total = 2 │',
|
|
58
|
+
'│ 13 return total │',
|
|
59
|
+
'╰───────────────────────────────────────╯',
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
// The seam `extensions/odd-worktree-tools.ts` hands over: Pi's own highlighter and language mapper.
|
|
63
|
+
const seamFor = (languages = { language: 'javascript' }) => {
|
|
64
|
+
const asked = [];
|
|
65
|
+
return {
|
|
66
|
+
asked,
|
|
67
|
+
seam: {
|
|
68
|
+
highlight: (code, language) => {
|
|
69
|
+
asked.push([code, language]);
|
|
70
|
+
if (language === undefined) return undefined;
|
|
71
|
+
return code.split('\n').map((line) => (line === '' ? '' : HIGHLIGHT(line)));
|
|
72
|
+
},
|
|
73
|
+
languageForPath: () => languages.language,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const callCtx = (extra = {}) => ({ tool: 'write', part: 'call', width: WIDTH, theme, ...extra });
|
|
79
|
+
const resultCtx = (extra = {}) => ({ tool: 'write', part: 'result', width: WIDTH, theme, ...extra });
|
|
80
|
+
|
|
81
|
+
// A two-line write, its two host halves, and the design that paints it.
|
|
82
|
+
const WRITE_ARGS = { path: 'lib/app.js', content: 'const x = 1\nconst y = 2' };
|
|
83
|
+
const writeHalves = () => ({ call: [neonCall()], result: [neonBody('✓ wrote 22 bytes'), neonClose()] });
|
|
84
|
+
|
|
85
|
+
describe('the Card diff line (S2)', () => {
|
|
86
|
+
test('one grouped registration over write and edit, labelled `color`', () => {
|
|
87
|
+
const design = diffColorDesign(seamFor().seam);
|
|
88
|
+
assert.equal(design.line, 'diff');
|
|
89
|
+
assert.deepEqual(design.tools, ['write', 'edit']);
|
|
90
|
+
assert.equal(Object.hasOwn(design, 'tool'), false, 'never both shapes');
|
|
91
|
+
assert.equal(design.id, DIFF_DESIGN_ID);
|
|
92
|
+
assert.equal(design.id, 'odd-worktree.diff');
|
|
93
|
+
assert.equal(design.label, DIFF_DESIGN_LABEL);
|
|
94
|
+
assert.equal(design.label, 'color', 'the value the user reads on the Cards row');
|
|
95
|
+
assert.equal(design.name, 'Odd worktree');
|
|
96
|
+
assert.equal(typeof design.description, 'string');
|
|
97
|
+
assert.doesNotMatch(design.description, /[\r\n]/u, 'a description is ONE line');
|
|
98
|
+
assert.equal(typeof design.apply, 'function');
|
|
99
|
+
assert.equal(typeof design.preview, 'function');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('the preview is ONE row, titled after the value', () => {
|
|
103
|
+
const preview = diffColorDesign(seamFor().seam).preview();
|
|
104
|
+
assert.equal(preview.title, `Cards · ${DIFF_DESIGN_LABEL}`);
|
|
105
|
+
assert.equal(preview.title, 'Cards · color');
|
|
106
|
+
assert.equal(preview.sample.split('\n').length, 1, 'one row, like every Cards value');
|
|
107
|
+
assert.deepEqual(preview, DIFF_DESIGN_PREVIEW);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('it registers once, and a second call is the same disposer', () => {
|
|
111
|
+
const seen = [];
|
|
112
|
+
const api = { VERSION: '0.9.0', registerToolDesign: (design) => { seen.push(design); return () => seen.pop(); } };
|
|
113
|
+
const dispose = registerDiffDesign(api, seamFor().seam);
|
|
114
|
+
assert.equal(typeof dispose, 'function');
|
|
115
|
+
assert.equal(seen.length, 1);
|
|
116
|
+
assert.equal(seen[0].line, 'diff');
|
|
117
|
+
assert.equal(registerDiffDesign(api, seamFor().seam), dispose, 'a second call is the same registration');
|
|
118
|
+
dispose();
|
|
119
|
+
dispose();
|
|
120
|
+
assert.equal(seen.length, 0);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('S6: an old or absent bridge registers nothing and never throws', () => {
|
|
125
|
+
test('no bridge member means no registration', () => {
|
|
126
|
+
for (const api of [null, undefined, {}, { registerToolDesign: 'nope' }]) {
|
|
127
|
+
assert.equal(registerDiffDesign(api, seamFor().seam), null, String(api));
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('a release older than the per-(line, tool) claim registers nothing', () => {
|
|
132
|
+
for (const version of ['0.5.0', '0.6.0', '0.8.9', '0.8', 'nightly', '', 'v0.9.0', undefined, 0.9]) {
|
|
133
|
+
const seen = [];
|
|
134
|
+
const api = { VERSION: version, registerToolDesign: (design) => { seen.push(design); return () => {}; } };
|
|
135
|
+
assert.equal(registerDiffDesign(api, seamFor().seam), null, String(version));
|
|
136
|
+
assert.deepEqual(seen, [], `${String(version)}: nothing was offered for a row the bridge would refuse`);
|
|
137
|
+
assert.equal(bridgeSupportsDiffLine(api), false, String(version));
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('every release from 0.9.0 up registers the line', () => {
|
|
142
|
+
for (const version of ['0.9.0', '0.9.1', '0.10.0', '0.9', '1.0.0']) {
|
|
143
|
+
const seen = [];
|
|
144
|
+
const api = { VERSION: version, registerToolDesign: (design) => { seen.push(design); return () => {}; } };
|
|
145
|
+
const dispose = registerDiffDesign(api, seamFor().seam);
|
|
146
|
+
assert.equal(typeof dispose, 'function', version);
|
|
147
|
+
dispose();
|
|
148
|
+
assert.equal(seen.length, 1, version);
|
|
149
|
+
assert.equal(seen[0].line, 'diff', version);
|
|
150
|
+
assert.equal(bridgeSupportsDiffLine(api), true, version);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('a prerelease or a build suffix of the cutoff never meets it, so no diff line is offered', () => {
|
|
155
|
+
// Semver puts a prerelease BELOW its own release, so `0.9.0-rc.1` does not carry the per-(`line`,
|
|
156
|
+
// `tool`) claim 0.9.0 introduced; a build suffix is read the same conservative way, because a
|
|
157
|
+
// refused registration is worse than a missing row.
|
|
158
|
+
for (const version of ['0.9.0-rc.1', '0.9.0+build.7', '0.9.0-rc.1+sha.abc']) {
|
|
159
|
+
const seen = [];
|
|
160
|
+
const api = { VERSION: version, registerToolDesign: (design) => { seen.push(design); return () => {}; } };
|
|
161
|
+
assert.equal(bridgeSupportsDiffLine(api), false, version);
|
|
162
|
+
assert.equal(registerDiffDesign(api, seamFor().seam), null, version);
|
|
163
|
+
assert.deepEqual(seen, [], `${version}: nothing is offered for a row the bridge would refuse`);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('a bridge that refuses the registration is null, never a throw', () => {
|
|
168
|
+
const api = { VERSION: '0.9.0', registerToolDesign: () => { throw new Error('refused'); } };
|
|
169
|
+
assert.doesNotThrow(() => registerDiffDesign(api, seamFor().seam));
|
|
170
|
+
assert.equal(registerDiffDesign(api, seamFor().seam), null);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('the first-run selection (S2)', () => {
|
|
175
|
+
function fakeBridge(files = {}) {
|
|
176
|
+
const writes = [];
|
|
177
|
+
const createStore = (id) => ({
|
|
178
|
+
get: (key, fallback) => (files[id] && Object.hasOwn(files[id], key) ? files[id][key] : fallback),
|
|
179
|
+
set: (key, value) => { writes.push([id, key]); files[id] = { ...files[id], [key]: value }; },
|
|
180
|
+
});
|
|
181
|
+
return { api: { VERSION: '0.9.0', registerToolDesign: () => () => {}, createStore }, files, writes };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
test('a first load with no choice selects color on the line and touches nothing else', () => {
|
|
185
|
+
const { api, files } = fakeBridge({
|
|
186
|
+
'bridge-tool-designs': { selections: { bash: 'odd-worktree.bash-activity', $lines: { tools: 'odd-worktree.bash-activity' } } },
|
|
187
|
+
});
|
|
188
|
+
assert.equal(seedDiffDesignSelection(api), true);
|
|
189
|
+
assert.deepEqual(files['bridge-tool-designs'].selections, {
|
|
190
|
+
bash: 'odd-worktree.bash-activity',
|
|
191
|
+
$lines: { tools: 'odd-worktree.bash-activity', diff: DIFF_DESIGN_ID },
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('a fresh install with no store file at all selects color', () => {
|
|
196
|
+
const { api, files } = fakeBridge();
|
|
197
|
+
assert.equal(seedDiffDesignSelection(api), true);
|
|
198
|
+
assert.deepEqual(files['bridge-tool-designs'].selections, { $lines: { diff: DIFF_DESIGN_ID } });
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('a choice the user already made is never overwritten, default included', () => {
|
|
202
|
+
for (const chosen of ['native', 'someone.else']) {
|
|
203
|
+
const { api, files, writes } = fakeBridge({ 'bridge-tool-designs': { selections: { $lines: { diff: chosen } } } });
|
|
204
|
+
assert.equal(seedDiffDesignSelection(api), false, chosen);
|
|
205
|
+
assert.equal(files['bridge-tool-designs'].selections.$lines.diff, chosen, chosen);
|
|
206
|
+
assert.equal(writes.some(([, key]) => key === 'selections'), false, 'nothing was written');
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('it seeds once: default chosen afterwards stays default on the next load', () => {
|
|
211
|
+
const { api, files } = fakeBridge();
|
|
212
|
+
assert.equal(seedDiffDesignSelection(api), true);
|
|
213
|
+
files['bridge-tool-designs'] = { selections: { $lines: { diff: 'native' } } };
|
|
214
|
+
assert.equal(seedDiffDesignSelection(api), false);
|
|
215
|
+
files['bridge-tool-designs'] = { selections: { $lines: {} } };
|
|
216
|
+
assert.equal(seedDiffDesignSelection(api), false);
|
|
217
|
+
assert.deepEqual(files['bridge-tool-designs'].selections, { $lines: {} });
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('a bridge without createStore, a malformed document or a failing store seeds nothing', () => {
|
|
221
|
+
assert.equal(seedDiffDesignSelection({}), false);
|
|
222
|
+
assert.equal(seedDiffDesignSelection(null), false);
|
|
223
|
+
for (const selections of ['oops', [], null]) {
|
|
224
|
+
const { api } = fakeBridge({ 'bridge-tool-designs': { selections } });
|
|
225
|
+
assert.equal(seedDiffDesignSelection(api), false, JSON.stringify(selections));
|
|
226
|
+
}
|
|
227
|
+
const { api } = fakeBridge({ 'bridge-tool-designs': { selections: { $lines: 'oops' } } });
|
|
228
|
+
assert.equal(seedDiffDesignSelection(api), false);
|
|
229
|
+
const throwing = { createStore: () => { throw new Error('no store'); } };
|
|
230
|
+
assert.doesNotThrow(() => seedDiffDesignSelection(throwing));
|
|
231
|
+
assert.equal(seedDiffDesignSelection(throwing), false);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('the seed follows an ACCEPTED registration only, so a refusal stores nothing', () => {
|
|
235
|
+
const { api, files } = fakeBridge();
|
|
236
|
+
api.registerToolDesign = () => { throw new Error('refused'); };
|
|
237
|
+
assert.equal(registerDiffDesign(api, seamFor().seam), null);
|
|
238
|
+
assert.equal(files['bridge-tool-designs'], undefined, 'no value names a design nobody registered');
|
|
239
|
+
|
|
240
|
+
const accepted = fakeBridge();
|
|
241
|
+
registerDiffDesign(accepted.api, seamFor().seam)();
|
|
242
|
+
assert.equal(accepted.files['bridge-tool-designs'].selections.$lines.diff, DIFF_DESIGN_ID);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('the write card keeps the host frame (S1)', () => {
|
|
247
|
+
test('the call half is the host\'s own rows, so the frame top and the expand hint survive', () => {
|
|
248
|
+
const design = diffColorDesign(seamFor().seam);
|
|
249
|
+
const render = { args: WRITE_ARGS };
|
|
250
|
+
const halves = writeHalves();
|
|
251
|
+
assert.deepEqual(design.apply(halves.call, callCtx({ render })), halves.call);
|
|
252
|
+
assert.match(design.apply(halves.call, callCtx({ render }))[0], /ctrl\+o to expand/u, 'the host\'s affordance');
|
|
253
|
+
// The float style draws the same half as a band row plus a heading row; both are the host's.
|
|
254
|
+
const floats = floatCall();
|
|
255
|
+
assert.deepEqual(design.apply(floats, callCtx({ render })), floats);
|
|
256
|
+
assert.match(unpaint(design.apply(floats, callCtx({ render }))[1]), /ctrl\+o to expand/u);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('the pane is painted INSIDE the frame, on the result half', () => {
|
|
260
|
+
const { seam } = seamFor();
|
|
261
|
+
const halves = writeHalves();
|
|
262
|
+
const rows = diffColorDesign(seam).apply(halves.result, resultCtx({ render: { args: WRITE_ARGS } }));
|
|
263
|
+
assert.equal(rows.length, 3, 'two numbered rows between the frame\'s sides, then the host\'s closing rule');
|
|
264
|
+
// Every pane row wears the host's own frame cells...
|
|
265
|
+
for (const row of rows.slice(0, -1)) {
|
|
266
|
+
assert.ok(row.startsWith(NEON_PREFIX), `"${row}" is not wearing the host's side`);
|
|
267
|
+
assert.ok(row.endsWith(NEON_TAIL), `"${row}" is not wearing the host's rail`);
|
|
268
|
+
}
|
|
269
|
+
// ...and the body is the gutter plus the host's own highlighting.
|
|
270
|
+
assert.ok(rows[0].includes(`<muted> 1</muted> <dim>│</dim> ${HIGHLIGHT('const x = 1')}`), rows[0]);
|
|
271
|
+
assert.ok(rows[1].includes(`<muted> 2</muted> <dim>│</dim> ${HIGHLIGHT('const y = 2')}`), rows[1]);
|
|
272
|
+
// The host's closing rule is untouched, its summary row is what the pane replaces.
|
|
273
|
+
assert.equal(rows.at(-1), halves.result.at(-1));
|
|
274
|
+
assert.equal(unpaint(rows.join('\n')).includes('wrote 22 bytes'), false);
|
|
275
|
+
for (const row of rows) assert.equal(cols(row), WIDTH, `"${unpaint(row)}" is not ${WIDTH} columns`);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test('the host\'s own frame bytes are reused, tone paint and background reset included', () => {
|
|
279
|
+
const painted = (text) => neonBody(text);
|
|
280
|
+
const result = [painted('✓ wrote 22 bytes'), neonClose()];
|
|
281
|
+
const rows = diffColorDesign(seamFor().seam).apply(result, resultCtx({ render: { args: WRITE_ARGS } }));
|
|
282
|
+
for (const row of rows.slice(0, -1)) {
|
|
283
|
+
assert.ok(row.startsWith(NEON_PREFIX), 'the side keeps the host\'s exact bytes');
|
|
284
|
+
assert.ok(row.endsWith(NEON_TAIL), 'and so does the rail');
|
|
285
|
+
}
|
|
286
|
+
assert.equal(cols(rows[0]), WIDTH);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('float: the leading band row and the closing bar are the host\'s, the body wears the band', () => {
|
|
290
|
+
const result = [floatBand(), floatBody('✓ wrote 22 bytes'), floatClose()];
|
|
291
|
+
const rows = diffColorDesign(seamFor().seam).apply(result, resultCtx({ render: { args: WRITE_ARGS } }));
|
|
292
|
+
assert.deepEqual(rows[0], result[0], 'the host\'s band row is kept byte for byte');
|
|
293
|
+
assert.equal(rows.at(-1), result.at(-1), 'and so is its closing bar');
|
|
294
|
+
assert.equal(rows.length, 4, 'the band, two numbered rows and the closing bar');
|
|
295
|
+
for (const row of rows) assert.equal(cols(row), WIDTH, `"${unpaint(row)}" is not ${WIDTH} columns`);
|
|
296
|
+
for (const row of rows.slice(1, -1)) {
|
|
297
|
+
assert.ok(row.startsWith(FLOAT_PREFIX), row);
|
|
298
|
+
assert.ok(row.endsWith(FLOAT_TAIL), row);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test('collapsed keeps the host budget and folds; expanded shows all of it, inside the frame', () => {
|
|
303
|
+
const content = Array.from({ length: 14 }, (_value, index) => `line ${index + 1}`).join('\n');
|
|
304
|
+
const design = diffColorDesign(seamFor().seam);
|
|
305
|
+
const result = [neonBody('✓ wrote 22 bytes'), neonClose()];
|
|
306
|
+
const collapsed = design.apply(result, resultCtx({ render: { args: { path: 'lib/app.js', content } } }));
|
|
307
|
+
assert.equal(collapsed.length, 12, 'ten body rows, the fold row and the closing rule');
|
|
308
|
+
assert.match(unpaint(collapsed.at(-2)), /… \+4 lines/u, 'the rest is stated, not silently dropped');
|
|
309
|
+
assert.equal(unpaint(collapsed.at(-2)).includes('line 11'), false);
|
|
310
|
+
assert.equal(collapsed.at(-1), result.at(-1));
|
|
311
|
+
|
|
312
|
+
const expanded = design.apply(result, resultCtx({ render: { args: { path: 'lib/app.js', content }, expanded: true } }));
|
|
313
|
+
assert.equal(expanded.length, 15, 'every line and the closing rule');
|
|
314
|
+
assert.equal(unpaint(expanded[13]).includes('line 14'), true);
|
|
315
|
+
assert.equal(expanded.at(-1), result.at(-1));
|
|
316
|
+
for (const row of [...collapsed, ...expanded]) assert.equal(cols(row), WIDTH);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test('a clipped line is measured as PLAIN text, so no painted row is ever cut', () => {
|
|
320
|
+
const long = `${'const value = '.repeat(12)}1;`;
|
|
321
|
+
const { seam, asked } = seamFor();
|
|
322
|
+
const result = ['▎ unused'.padEnd(WIDTH - 1), neonClose()];
|
|
323
|
+
const rows = diffColorDesign(seam).apply([neonBody('✓ wrote 22 bytes'), neonClose()], resultCtx({ render: { args: { path: 'lib/app.js', content: long } } }));
|
|
324
|
+
const body = rows[0];
|
|
325
|
+
assert.equal(cols(body), WIDTH);
|
|
326
|
+
assert.ok(unpaint(body).includes('…'), 'the row ends in the ellipsis the clip wrote');
|
|
327
|
+
assert.equal(body.includes('\u001b[36m'), false, 'a clipped line is drawn plain, never cut out of a paint');
|
|
328
|
+
assert.ok(asked.length > 0, 'the highlighter was asked for the whole body');
|
|
329
|
+
assert.equal(result.length, 2);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test('tabs are expanded and trailing blank lines dropped, as the host card does', () => {
|
|
333
|
+
const rows = diffColorDesign(seamFor().seam).apply(
|
|
334
|
+
[neonBody('✓ written'), neonClose()],
|
|
335
|
+
resultCtx({ render: { args: { path: 'a.js', content: 'a\tb\n\n\n' } } }),
|
|
336
|
+
);
|
|
337
|
+
assert.equal(rows.length, 2, 'one numbered row and the closing rule');
|
|
338
|
+
assert.equal(unpaint(rows[0]).includes('a b'), true, 'a tab is three columns');
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test('an error is the card: the host\'s result rows come back byte for byte', () => {
|
|
342
|
+
const lines = [neonBody('ENOENT: no such file'), neonClose()];
|
|
343
|
+
const rows = diffColorDesign(seamFor().seam).apply(lines, resultCtx({ render: { args: WRITE_ARGS, isError: true } }));
|
|
344
|
+
assert.deepEqual(rows, lines);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test('rows with no frame and nothing to draw are the host\'s own', () => {
|
|
348
|
+
const design = diffColorDesign(seamFor().seam);
|
|
349
|
+
assert.deepEqual(design.apply([], resultCtx({ render: { args: WRITE_ARGS } })), []);
|
|
350
|
+
assert.deepEqual(design.apply(undefined, resultCtx({ render: { args: WRITE_ARGS } })), []);
|
|
351
|
+
assert.deepEqual(design.apply(['plain result'], resultCtx({ render: { args: WRITE_ARGS } })), ['plain result']);
|
|
352
|
+
assert.deepEqual(design.apply(['only the closing rule'], resultCtx({ render: { args: WRITE_ARGS } })), ['only the closing rule']);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
test('painted twice is the same rows: the design never stacks its own drawing', () => {
|
|
356
|
+
const ctx = resultCtx({ render: { args: WRITE_ARGS } });
|
|
357
|
+
const design = diffColorDesign(seamFor().seam);
|
|
358
|
+
const once = design.apply(writeHalves().result, ctx);
|
|
359
|
+
assert.deepEqual(design.apply(once, ctx), once);
|
|
360
|
+
const call = writeHalves().call;
|
|
361
|
+
assert.deepEqual(design.apply(design.apply(call, callCtx({ render: { args: WRITE_ARGS } })), callCtx({ render: { args: WRITE_ARGS } })), call);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
describe('a repaint reads the theme and the content of THIS pass (S1/S5)', () => {
|
|
366
|
+
test('a theme switched under the same object repaints the syntax escapes', () => {
|
|
367
|
+
// The host's highlighter resolves the ACTIVE theme on every call, so the escapes it hands back
|
|
368
|
+
// are theme-dependent: a drawing cached on the text alone answers a switched theme with the
|
|
369
|
+
// colours of the old one, which is exactly what this card exists to avoid.
|
|
370
|
+
const live = { palette: 36, fg(_role, text) { return `\u001b[${this.palette}m${text}\u001b[39m`; } };
|
|
371
|
+
const seam = {
|
|
372
|
+
highlight: (code) => code.split('\n').map((line) => (line === '' ? '' : live.fg('syntaxKeyword', line))),
|
|
373
|
+
languageForPath: () => 'javascript',
|
|
374
|
+
};
|
|
375
|
+
const design = diffColorDesign(seam);
|
|
376
|
+
const ctx = { tool: 'write', part: 'result', width: WIDTH, theme: live, render: { args: WRITE_ARGS } };
|
|
377
|
+
const before = design.apply(writeHalves().result, ctx);
|
|
378
|
+
assert.ok(before.some((row) => row.includes('\u001b[36m')), 'the first pass is the first theme');
|
|
379
|
+
live.palette = 34;
|
|
380
|
+
const after = design.apply(writeHalves().result, ctx);
|
|
381
|
+
assert.equal(after.some((row) => row.includes('\u001b[36m')), false, 'no escape of the old theme survives');
|
|
382
|
+
assert.ok(after.some((row) => row.includes('\u001b[34m')), 'the syntax escapes are the new theme\'s');
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
test('two writes of the same length never share a pane: the content is what draws', () => {
|
|
386
|
+
const design = diffColorDesign(seamFor().seam);
|
|
387
|
+
// Pi rewrites `content` on the SAME args object while the call streams, so a key built from its
|
|
388
|
+
// length answers a brand-new body with the pane of the old one.
|
|
389
|
+
const args = { path: 'lib/app.js', content: 'const x = 1' };
|
|
390
|
+
const ctx = { tool: 'write', part: 'result', width: WIDTH, theme, render: { args } };
|
|
391
|
+
const first = design.apply(writeHalves().result, ctx);
|
|
392
|
+
args.content = 'const y = 2';
|
|
393
|
+
const second = design.apply(writeHalves().result, ctx);
|
|
394
|
+
assert.ok(first[0].includes(HIGHLIGHT('const x = 1')), first[0]);
|
|
395
|
+
assert.ok(second[0].includes(HIGHLIGHT('const y = 2')), second[0]);
|
|
396
|
+
assert.notDeepEqual(second, first);
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
describe('a host that draws no frame gets the whole pane (S1)', () => {
|
|
401
|
+
// Pi's own shell wraps the renderer's component, so a design sees the write BODY alone: heading,
|
|
402
|
+
// content rows and the host's own fold row, which carries the expand affordance. This host never
|
|
403
|
+
// reaches a design through gentle-shell-bridge today; the path exists so such a host degrades
|
|
404
|
+
// into a drawn pane instead of an untouched card.
|
|
405
|
+
const plainCall = (hint = '... (12 more lines, 22 total, ctrl+o to expand)') => [
|
|
406
|
+
'+ write lib/app.js (2 lines)',
|
|
407
|
+
'',
|
|
408
|
+
'const x = 1',
|
|
409
|
+
'const y = 2',
|
|
410
|
+
hint,
|
|
411
|
+
];
|
|
412
|
+
|
|
413
|
+
test('the pane is drawn on the call half, with the host\'s own hint row kept after the fold row', () => {
|
|
414
|
+
const content = Array.from({ length: 14 }, (_value, index) => `line ${index + 1}`).join('\n');
|
|
415
|
+
const hint = '... (4 more lines, 14 total, ctrl+o to expand)';
|
|
416
|
+
const call = plainCall(hint);
|
|
417
|
+
const rows = diffColorDesign(seamFor().seam).apply(call, callCtx({ render: { args: { path: 'lib/app.js', content } } }));
|
|
418
|
+
assert.ok(rows.length > call.length, 'the pane was drawn');
|
|
419
|
+
assert.match(rows[0], /^<toolTitle>✎ write<\/toolTitle> <accent>lib\/app\.js<\/accent>/u);
|
|
420
|
+
assert.match(unpaint(rows.at(-2)), /… \+4 lines/u, 'our fold row');
|
|
421
|
+
assert.equal(rows.at(-1), hint, 'then the host\'s own hint row, exactly as it drew it');
|
|
422
|
+
for (const row of rows.slice(0, -1)) assert.equal(cols(row), WIDTH);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
test('no hint is invented when the host drew none', () => {
|
|
426
|
+
const rows = diffColorDesign(seamFor().seam).apply(
|
|
427
|
+
plainCall(null).slice(0, 4),
|
|
428
|
+
callCtx({ render: { args: WRITE_ARGS } }),
|
|
429
|
+
);
|
|
430
|
+
assert.equal(rows.some((row) => /to expand|to collapse/u.test(unpaint(row))), false);
|
|
431
|
+
assert.equal(rows.length, 3, 'the heading and the two numbered lines');
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test('the result half of an unframed host is never painted, so nothing is drawn twice', () => {
|
|
435
|
+
const rows = diffColorDesign(seamFor().seam).apply([], resultCtx({ render: { args: WRITE_ARGS } }));
|
|
436
|
+
assert.deepEqual(rows, []);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
test('a path that is neither a skill nor an ODD still gets the pane', () => {
|
|
440
|
+
const rows = diffColorDesign(seamFor().seam).apply(plainCall(), callCtx({ render: { args: { path: 'lib/oddity.js', content: 'x' } } }));
|
|
441
|
+
assert.match(rows[0], /<accent>lib\/oddity\.js<\/accent>/u);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
describe('the edit diff, recoloured (S1)', () => {
|
|
446
|
+
test('additions, deletions, hunk headers and context wear their roles, text untouched', () => {
|
|
447
|
+
const { seam } = seamFor();
|
|
448
|
+
const rows = diffColorDesign(seam).apply(editCard(), {
|
|
449
|
+
tool: 'edit',
|
|
450
|
+
part: 'call',
|
|
451
|
+
width: WIDTH,
|
|
452
|
+
theme,
|
|
453
|
+
render: { args: { path: 'lib/app.js' } },
|
|
454
|
+
});
|
|
455
|
+
assert.equal(rows.length, 6, 'every row of the host card is still there');
|
|
456
|
+
assert.equal(unpaint(rows[1]).includes('@@ -12,2 +12,2 @@'), true);
|
|
457
|
+
assert.match(rows[1], /<muted>@@ -12,2 \+12,2 @@<\/muted>/u, 'a hunk header is muted');
|
|
458
|
+
assert.match(rows[2], /<toolDiffRemoved>-12 <\/toolDiffRemoved>/u, 'a deletion is toolDiffRemoved');
|
|
459
|
+
assert.match(rows[3], /<toolDiffAdded>\+12 <\/toolDiffAdded>/u, 'an addition is toolDiffAdded');
|
|
460
|
+
// The code of a row is the host's highlighter, with the language the path names.
|
|
461
|
+
assert.ok(rows[2].includes(HIGHLIGHT('const total = 1')), rows[2]);
|
|
462
|
+
assert.ok(rows[3].includes(HIGHLIGHT('const total = 2')), rows[3]);
|
|
463
|
+
// Context is the theme's plain text.
|
|
464
|
+
assert.match(rows[4], /<muted>13 <\/muted>/u);
|
|
465
|
+
assert.ok(rows[4].includes(HIGHLIGHT('return total')), rows[4]);
|
|
466
|
+
// The frame and the row widths are the host's, byte for byte.
|
|
467
|
+
assert.equal(rows[0], editCard()[0]);
|
|
468
|
+
assert.equal(rows.at(-1), editCard().at(-1));
|
|
469
|
+
for (const [index, row] of rows.entries()) assert.equal(cols(row), cols(editCard()[index]), `row ${index} keeps its width`);
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
test('the language comes from the call\'s own path, and nothing but the row\'s text is repainted', () => {
|
|
473
|
+
const heard = [];
|
|
474
|
+
const seam = {
|
|
475
|
+
highlight: (code) => code.split('\n').map((line) => HIGHLIGHT(line)),
|
|
476
|
+
languageForPath: (path) => { heard.push(path); return 'javascript'; },
|
|
477
|
+
};
|
|
478
|
+
const rows = [...editCard(), ' (its own frame)'];
|
|
479
|
+
const out = diffColorDesign(seam).apply(rows, { tool: 'edit', part: 'call', width: WIDTH, theme, render: { args: { path: 'lib/app.js' } } });
|
|
480
|
+
assert.deepEqual(heard, ['lib/app.js']);
|
|
481
|
+
assert.equal(out.length, rows.length);
|
|
482
|
+
assert.ok(out[2].includes(HIGHLIGHT('const total = 1')));
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
test('a row already wearing this paint comes back identical: never painted twice', () => {
|
|
486
|
+
const ctx = { tool: 'edit', part: 'call', width: WIDTH, theme, render: { args: { path: 'lib/app.js' } } };
|
|
487
|
+
const design = diffColorDesign(seamFor().seam);
|
|
488
|
+
const once = design.apply(editCard(), ctx);
|
|
489
|
+
assert.deepEqual(design.apply(once, ctx), once);
|
|
490
|
+
assert.deepEqual(design.apply(editCard(), { ...ctx, part: 'result' }).map(unpaint), once.map(unpaint));
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
test('a heading, a blank row and a fold notice are never mistaken for a diff row', () => {
|
|
494
|
+
const rows = [
|
|
495
|
+
'╭─ edit lib/app.js ─────────────────────╮',
|
|
496
|
+
'',
|
|
497
|
+
' ... (12 more lines, 22 total, ctrl+o to expand)',
|
|
498
|
+
'▎ edit lib/app.js',
|
|
499
|
+
];
|
|
500
|
+
const out = diffColorDesign(seamFor().seam).apply(rows, {
|
|
501
|
+
tool: 'edit',
|
|
502
|
+
part: 'call',
|
|
503
|
+
width: WIDTH,
|
|
504
|
+
theme,
|
|
505
|
+
render: { args: { path: 'lib/app.js' } },
|
|
506
|
+
});
|
|
507
|
+
assert.deepEqual(out, rows);
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
// S8b: a row already wearing this paint comes back BYTE-IDENTICAL. The markup theme above states
|
|
512
|
+
// the role's NAME (`<toolDiffAdded>`), which the parser reads as the row's own text, so it can
|
|
513
|
+
// never show an escape added twice; only a real theme, whose `fg` answers SGR codes, can.
|
|
514
|
+
describe('repainting a row it already painted is a byte-identical no-op (S8b)', () => {
|
|
515
|
+
const SGR_ROLE = { toolDiffAdded: '92', toolDiffRemoved: '91', muted: '90', text: '39' };
|
|
516
|
+
const sgr = (role, text) => `\u001b[${SGR_ROLE[role] ?? '39'}m${text}\u001b[39m`;
|
|
517
|
+
const sgrTheme = { fg: (role, text) => sgr(role, text) };
|
|
518
|
+
// The host's own edit body row: the frame cells painted, the marker and the code its own colour.
|
|
519
|
+
const FRAME = '\u001b[32m│\u001b[39m';
|
|
520
|
+
const hostRow = (text) => `${FRAME} ${text} ${FRAME}`;
|
|
521
|
+
const hostPainted = [
|
|
522
|
+
hostRow('@@ -1,4 +1,4 @@'),
|
|
523
|
+
hostRow('\u001b[91m-4 const stale = 3;\u001b[39m'),
|
|
524
|
+
hostRow('\u001b[92m+4 const fresh = 4;\u001b[39m'),
|
|
525
|
+
hostRow(' 4 const kept = 2;'),
|
|
526
|
+
];
|
|
527
|
+
const escapes = (row) => row.match(/\u001b\[[0-9;]*m/gu) ?? [];
|
|
528
|
+
|
|
529
|
+
for (const [name, seam] of [['no highlighter', undefined], ['a real highlighter', seamFor().seam]]) {
|
|
530
|
+
test(`${name}: a second pass over its own rows adds no escape and no reset`, () => {
|
|
531
|
+
const design = diffColorDesign(seam);
|
|
532
|
+
const ctx = { tool: 'edit', part: 'call', width: WIDTH, theme: sgrTheme, render: { args: { path: 'lib/app.js' } } };
|
|
533
|
+
const once = design.apply(hostPainted, ctx);
|
|
534
|
+
const twice = design.apply(once, ctx);
|
|
535
|
+
assert.deepEqual(twice, once, 'the second application is a byte-identical no-op');
|
|
536
|
+
for (const [index, row] of twice.entries()) {
|
|
537
|
+
assert.equal(unpaint(row), unpaint(hostPainted[index]), `row ${index} states the same text`);
|
|
538
|
+
assert.equal(cols(row), cols(hostPainted[index]), `row ${index} keeps its width`);
|
|
539
|
+
assert.deepEqual(escapes(row), escapes(once[index]), `row ${index} gains no escape`);
|
|
540
|
+
}
|
|
541
|
+
// The defect this pins: the added row's opening code used to survive in the prefix and be
|
|
542
|
+
// issued again, so the second pass read `\u001b[92m\u001b[92m`. No escape is ever issued twice
|
|
543
|
+
// in a row here — the marker's paint is rebuilt, never stacked on the paint already there.
|
|
544
|
+
assert.doesNotMatch(once[2], /\u001b\[([0-9;]*)m\u001b\[\1m/u, once[2]);
|
|
545
|
+
assert.doesNotMatch(once[1], /\u001b\[([0-9;]*)m\u001b\[\1m/u, once[1]);
|
|
546
|
+
// The host's own frame cells keep their paint, on both passes.
|
|
547
|
+
assert.ok(once[2].startsWith(`${FRAME} `), once[2]);
|
|
548
|
+
assert.ok(once[2].endsWith(` ${FRAME}`), once[2]);
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
test('the plainest host row is a no-op too: a real theme never doubles the marker paint', () => {
|
|
553
|
+
const design = diffColorDesign(undefined);
|
|
554
|
+
const ctx = { tool: 'edit', part: 'call', width: WIDTH, theme: sgrTheme, render: { args: { path: 'lib/app.js' } } };
|
|
555
|
+
const rows = ['│ +4 const fresh = 4; │'];
|
|
556
|
+
const once = design.apply(rows, ctx);
|
|
557
|
+
assert.equal(once[0], `│ ${sgr('toolDiffAdded', '+4 ')}${sgr('toolDiffAdded', 'const fresh = 4;')} │`);
|
|
558
|
+
assert.deepEqual(design.apply(once, ctx), once);
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
describe('a skill or an ODD artifact is the file card\'s call (S8)', () => {
|
|
563
|
+
for (const path of ['odd/tasks/card-diff.md', '/repo/skills/gentle-ai/SKILL.md', 'skills\\gentle-ai\\SKILL.md']) {
|
|
564
|
+
test(`${path} comes back byte-identical, both halves, both tools`, () => {
|
|
565
|
+
const design = diffColorDesign(seamFor().seam);
|
|
566
|
+
const content = 'const x = 1';
|
|
567
|
+
const halves = writeHalves();
|
|
568
|
+
for (const tool of ['write', 'edit']) {
|
|
569
|
+
for (const part of ['call', 'result']) {
|
|
570
|
+
const rows = tool === 'edit' ? editCard() : halves[part];
|
|
571
|
+
const ctx = { tool, part, width: WIDTH, theme, render: { args: { path, content } } };
|
|
572
|
+
assert.deepEqual(design.apply(rows, ctx), rows, `${tool}/${part}`);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
describe('a missing or broken highlighter degrades to plain rows', () => {
|
|
580
|
+
const content = 'const x = 1\nconst y = 2';
|
|
581
|
+
const result = () => [neonBody('✓ wrote 22 bytes'), neonClose()];
|
|
582
|
+
|
|
583
|
+
test('no seam at all: the pane is still drawn inside the frame, in the theme\'s text role', () => {
|
|
584
|
+
const rows = diffColorDesign(undefined).apply(result(), resultCtx({ render: { args: { path: 'lib/app.js', content } } }));
|
|
585
|
+
assert.equal(rows.length, 3);
|
|
586
|
+
assert.ok(rows[0].includes('<muted> 1</muted> <dim>│</dim> <text>const x = 1</text>'), rows[0]);
|
|
587
|
+
assert.ok(unpaint(rows[0]).startsWith(`${unpaint(NEON_PREFIX)} 1 │ const x = 1`), unpaint(rows[0]));
|
|
588
|
+
assert.ok(unpaint(rows[0]).endsWith(unpaint(NEON_TAIL)), unpaint(rows[0]));
|
|
589
|
+
for (const row of rows) assert.equal(cols(row), WIDTH);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
test('a highlighter that throws is no highlighter', () => {
|
|
593
|
+
const seam = { highlight: () => { throw new Error('no grammar'); }, languageForPath: () => 'javascript' };
|
|
594
|
+
let rows;
|
|
595
|
+
assert.doesNotThrow(() => { rows = diffColorDesign(seam).apply(result(), resultCtx({ render: { args: { path: 'lib/app.js', content } } })); });
|
|
596
|
+
assert.ok(rows[0].includes('<text>const x = 1</text>'), rows[0]);
|
|
597
|
+
const edit = diffColorDesign(seam).apply(editCard(), { tool: 'edit', part: 'call', width: WIDTH, theme, render: { args: { path: 'a.js' } } });
|
|
598
|
+
assert.match(edit[2], /<toolDiffRemoved>const total = 1<\/toolDiffRemoved>/u, 'the diff role carries the code');
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
test('a highlighter whose paint changes the text is not a paint', () => {
|
|
602
|
+
const seam = { highlight: () => ['<syntaxKeyword>something else</syntaxKeyword>'], languageForPath: () => 'javascript' };
|
|
603
|
+
const rows = diffColorDesign(seam).apply(result(), resultCtx({ render: { args: { path: 'lib/app.js', content: 'const x = 1' } } }));
|
|
604
|
+
assert.ok(rows[0].includes('<text>const x = 1</text>'), rows[0]);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
test('a highlighter that answers the wrong number of lines is not a paint either', () => {
|
|
608
|
+
const seam = { highlight: () => ['<syntaxKeyword>x</syntaxKeyword>'], languageForPath: () => 'javascript' };
|
|
609
|
+
const rows = diffColorDesign(seam).apply(result(), resultCtx({ render: { args: { path: 'lib/app.js', content } } }));
|
|
610
|
+
assert.ok(rows[0].includes('<text>const x = 1</text>'), rows[0]);
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
describe('the shape of the contract (S5)', () => {
|
|
615
|
+
test('apply always hands back a fresh array of strings', () => {
|
|
616
|
+
const design = diffColorDesign(seamFor().seam);
|
|
617
|
+
const frozen = Object.freeze(['host row']);
|
|
618
|
+
const ctx = callCtx({ render: { args: { path: 'lib/app.js', content: 'x' } } });
|
|
619
|
+
assert.doesNotThrow(() => design.apply(frozen, ctx));
|
|
620
|
+
const rows = design.apply(frozen, ctx);
|
|
621
|
+
assert.ok(Array.isArray(rows));
|
|
622
|
+
assert.notEqual(rows, frozen, 'never the caller\'s array');
|
|
623
|
+
assert.ok(rows.every((row) => typeof row === 'string'));
|
|
624
|
+
assert.deepEqual(design.apply(undefined, ctx), []);
|
|
625
|
+
assert.deepEqual(design.apply(frozen, undefined), frozen);
|
|
626
|
+
assert.deepEqual(applyDiffDesign(frozen, null, undefined), frozen);
|
|
627
|
+
assert.deepEqual(design.apply([null], { ...ctx, tool: 'read' }).length, 1);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
test('it never mutates the host\'s rows or the call\'s arguments', () => {
|
|
631
|
+
const args = Object.freeze({ path: 'lib/app.js', content: 'const x = 1' });
|
|
632
|
+
const rows = Object.freeze(['╭─ write lib/app.js ─╮']);
|
|
633
|
+
assert.doesNotThrow(() => diffColorDesign(seamFor().seam).apply(rows, callCtx({ render: { args } })));
|
|
634
|
+
});
|
|
635
|
+
});
|