pi-odd-worktree 3.5.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/extensions/odd-worktree-tools.ts +35 -3
- package/lib/file-card.js +29 -12
- package/lib/files-index.js +99 -5
- package/lib/files-orders.js +1 -1
- package/lib/files-picker-view.js +45 -7
- package/lib/files-scope-detail.js +13 -6
- package/lib/skill-odd-card.js +33 -8
- package/package.json +1 -1
- package/tools/file-card.test.js +172 -15
- package/tools/files-command.test.js +116 -4
- package/tools/files-index.test.js +254 -13
- package/tools/files-orders.test.js +4 -4
- package/tools/files-picker-view.test.js +55 -2
- package/tools/files-scope-detail.test.js +6 -3
- package/tools/files-scope-view.test.js +3 -1
- package/tools/skill-odd-card.test.js +45 -3
package/tools/file-card.test.js
CHANGED
|
@@ -1146,21 +1146,178 @@ test('a failed call and a non-Markdown file keep their plain rows (S8)', () => {
|
|
|
1146
1146
|
assert.deepEqual(json.slice(0, -1).map(bodyText), ['{"a":1}'], 'a non-Markdown file is drawn as it is');
|
|
1147
1147
|
});
|
|
1148
1148
|
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1149
|
+
// ---- S1/S2/S3/S4/S5/S6: an edit states the fragment it leaves, drawn as a document ----
|
|
1150
|
+
|
|
1151
|
+
// The two shapes an `edit` call arrives in: the `edits` array the harness folds a legacy
|
|
1152
|
+
// pair into (one entry per replacement), and the flat top-level pair itself.
|
|
1153
|
+
const EDITS = [{ oldText: '# Old heading', newText: '# Handoff\n\nBody text' }, { oldText: 'x', newText: '```\nconst a = 1;\n```' }];
|
|
1154
|
+
const FRAGMENT = ['# Handoff', '', 'Body text', '```', 'const a = 1;', '```'].join('\n');
|
|
1155
|
+
// The host's own rows for that call: a hunk header, the removed lines and the added ones.
|
|
1156
|
+
const EDIT_DIFF = ['@@ -2,3 +2,3 @@', '-# Old heading', '-removed line', '+# Handoff', '+Body text'].join('\n');
|
|
1157
|
+
const editResult = () => textResult('Edited', { details: { diff: EDIT_DIFF } });
|
|
1158
|
+
|
|
1159
|
+
test('an edit of a Markdown skill or ODD artifact draws the fragment it leaves (S1)', () => {
|
|
1160
|
+
const resolver = documentResolver();
|
|
1161
|
+
const rows = resultRows(resolver, 'edit', { path: ODD, edits: EDITS }, editResult(), { expanded: true, isPartial: false }, taggedTheme, 60);
|
|
1162
|
+
const body = rows.slice(0, -1).join('\n');
|
|
1163
|
+
// The fragment is a document, drawn in the renderer's own roles.
|
|
1164
|
+
assert.equal(body.includes('<mdHeading>Handoff</mdHeading>'), true, `the fragment's heading is drawn as a heading: ${body}`);
|
|
1165
|
+
assert.equal(body.includes('<mdCodeBlock>const a = 1;</mdCodeBlock>'), true, 'so is its fenced block');
|
|
1166
|
+
// None of the host's diff rows are left: no hunk header, no gutter, no `+`/`-` marker,
|
|
1167
|
+
// and no line the edit removed.
|
|
1168
|
+
const text = unpaint(body);
|
|
1169
|
+
assert.equal(text.includes('@@'), false, 'no hunk header');
|
|
1170
|
+
assert.equal(text.includes('removed line'), false, 'a line the edit removed is never shown');
|
|
1171
|
+
assert.equal(text.includes('-# Old heading'), false, 'no removed marker');
|
|
1172
|
+
assert.equal(text.includes('+# Handoff'), false, 'no added marker');
|
|
1173
|
+
assert.doesNotMatch(text, /^\s*\d+ │/mu, 'no line-number gutter');
|
|
1174
|
+
// A host diff that carries a gutter row of its own reaches the body no more than the
|
|
1175
|
+
// rest of it does: no digit ever stands beside the diff's own bar.
|
|
1176
|
+
const gutted = resultRows(
|
|
1177
|
+
resolver,
|
|
1178
|
+
'edit',
|
|
1179
|
+
{ path: ODD, edits: EDITS },
|
|
1180
|
+
textResult('Edited', { details: { diff: ['@@ -1,1 +1,1 @@', ' 12 │ -old line', ' 12 │ +new line'].join('\n') } }),
|
|
1181
|
+
{ expanded: true, isPartial: false },
|
|
1182
|
+
taggedTheme,
|
|
1183
|
+
60,
|
|
1184
|
+
);
|
|
1185
|
+
assert.doesNotMatch(unpaint(gutted.slice(0, -1).join('\n')), /\d+\s*│|│\s*\d+/u, 'a gutter row is never drawn');
|
|
1186
|
+
// The same rows a read of the resulting text draws, exactly.
|
|
1187
|
+
const read = resultRows(resolver, 'read', { path: ODD }, textResult(FRAGMENT), { expanded: true, isPartial: false }, taggedTheme, 60);
|
|
1188
|
+
assert.deepEqual(rows, read, 'the fragment is drawn exactly as a read of it is');
|
|
1189
|
+
|
|
1190
|
+
// The legacy flat shape is the same call, so it draws the same fragment.
|
|
1191
|
+
const flat = resultRows(
|
|
1192
|
+
resolver,
|
|
1193
|
+
'edit',
|
|
1194
|
+
{ path: ODD, oldText: '# Old heading', newText: FRAGMENT },
|
|
1195
|
+
editResult(),
|
|
1196
|
+
{ expanded: true, isPartial: false },
|
|
1197
|
+
taggedTheme,
|
|
1198
|
+
60,
|
|
1199
|
+
);
|
|
1200
|
+
assert.deepEqual(flat, rows, 'either call shape states the same fragment');
|
|
1201
|
+
|
|
1202
|
+
// A skill's Markdown file is the same card: the claim is the identity, not the tool. The
|
|
1203
|
+
// rows must be the ones a read of that same fragment on that same skill path draws, so a
|
|
1204
|
+
// skill card that fell back to its raw source, or to the diff, cannot pass.
|
|
1205
|
+
const skillEdit = resultRows(resolver, 'edit', { path: SKILL, edits: EDITS }, editResult(), { expanded: true, isPartial: false }, taggedTheme, 60);
|
|
1206
|
+
const skillRead = resultRows(resolver, 'read', { path: SKILL }, textResult(FRAGMENT), { expanded: true, isPartial: false }, taggedTheme, 60);
|
|
1207
|
+
assert.deepEqual(skillEdit, skillRead, 'a skill edit draws exactly a read of its fragment');
|
|
1208
|
+
const skillBody = skillEdit.slice(0, -1).join('\n');
|
|
1209
|
+
const skillText = unpaint(skillBody);
|
|
1210
|
+
assert.equal(skillBody.includes('<mdHeading>Handoff</mdHeading>'), true, 'in the renderer\'s own roles');
|
|
1211
|
+
assert.equal(skillBody.includes('<mdCodeBlock>const a = 1;</mdCodeBlock>'), true, 'fenced block included');
|
|
1212
|
+
assert.equal(skillText.includes('@@'), false, 'and never the diff');
|
|
1213
|
+
assert.equal(skillText.includes('-# Old heading'), false, 'no removed marker');
|
|
1214
|
+
assert.equal(skillText.includes('+# Handoff'), false, 'no added marker');
|
|
1215
|
+
assert.doesNotMatch(skillText, /\d+\s*│|│\s*\d+/u, 'no line-number gutter');
|
|
1216
|
+
});
|
|
1217
|
+
|
|
1218
|
+
// The array is the whole source when it is present: only an ABSENT or non-array `edits`
|
|
1219
|
+
// falls back to the legacy pair, so a pair beside an empty array states nothing.
|
|
1220
|
+
test('an `edits` array, even an empty one, is the whole source (S2)', () => {
|
|
1221
|
+
const resolver = documentResolver();
|
|
1222
|
+
const args = { path: ODD, edits: [], newText: '# Competing legacy text' };
|
|
1223
|
+
const rows = resultRows(resolver, 'edit', args, editResult(), { expanded: true, isPartial: false }, taggedTheme, 60);
|
|
1224
|
+
assert.deepEqual(rows.slice(0, -1).map(bodyText), EDIT_DIFF.split('\n'), 'the diff rows, not the legacy fragment beside the array');
|
|
1225
|
+
assert.equal(rows.slice(0, -1).join('\n').includes('Competing legacy text'), false, 'the pair is not drawn at all');
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1228
|
+
test('a pure deletion keeps the edit\'s rows, with no invented placeholder (S3)', () => {
|
|
1229
|
+
const resolver = documentResolver();
|
|
1230
|
+
// Longer than the preview budget, so the collapsed and the expanded case draw different
|
|
1231
|
+
// amounts of the same diff.
|
|
1232
|
+
const lines = ['@@ -1,4 +1,0 @@', '-# Design', '-Body text', '-More body', '-Last body'];
|
|
1233
|
+
const result = textResult('Edited', { details: { diff: lines.join('\n') } });
|
|
1234
|
+
for (const edits of [[{ oldText: '# Design\nBody text', newText: '' }], [{ oldText: 'a', newText: ' \n ' }]]) {
|
|
1235
|
+
const collapsed = resultRows(resolver, 'edit', { path: ODD, edits }, result, { isPartial: false }, taggedTheme, 60);
|
|
1236
|
+
assert.deepEqual(collapsed.slice(0, -1).map(bodyText), lines.slice(0, PREVIEW_ROWS), 'collapsed: the first rows of the diff, capped as any body is');
|
|
1237
|
+
const expanded = resultRows(resolver, 'edit', { path: ODD, edits }, result, { expanded: true, isPartial: false }, taggedTheme, 60);
|
|
1238
|
+
assert.deepEqual(expanded.slice(0, -1).map(bodyText), lines, 'expanded: the whole diff, row for row, never a document');
|
|
1239
|
+
assert.equal(bodyPaint(expanded.slice(0, -1).join('\n')).includes('<mdHeading>'), false, 'and none of it is drawn as Markdown');
|
|
1240
|
+
}
|
|
1241
|
+
// A result that carries no diff is its own text, exactly as before.
|
|
1242
|
+
const plain = resultRows(resolver, 'edit', { path: ODD, edits: [{ newText: '' }] }, textResult('Edited 2 lines'), { isPartial: false }, plainTheme, 60);
|
|
1243
|
+
assert.deepEqual(plain.slice(0, -1).map(bodyText), ['Edited 2 lines'], 'no wording is invented for the deleted fragment');
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
test('a failed edit keeps its error rows, and no other path becomes a document (S4)', () => {
|
|
1247
|
+
const resolver = documentResolver();
|
|
1248
|
+
const failed = resultRows(resolver, 'edit', { path: ODD, edits: EDITS }, textResult('ENOENT: no such file', { isError: true }), { expanded: true, isPartial: false }, taggedTheme, 60);
|
|
1249
|
+
assert.deepEqual(failed.slice(0, -1).map(bodyText), ['ENOENT: no such file'], 'exactly the error, with no body row of its own');
|
|
1250
|
+
const failedBody = failed.slice(0, -1).join('\n');
|
|
1251
|
+
assert.equal(failedBody.includes('<mdHeading>'), false, 'a failed edit is never a document');
|
|
1252
|
+
assert.match(failed[0], /^<error>│/u, 'and it wears the error role');
|
|
1253
|
+
|
|
1254
|
+
// A non-Markdown ODD artifact keeps its diff.
|
|
1255
|
+
const json = resultRows(resolver, 'edit', { path: 'odd/tasks/data.json', edits: [{ newText: '## Handoff' }] }, editResult(), { isPartial: false }, plainTheme, 60);
|
|
1256
|
+
assert.deepEqual(json.slice(0, -1).map(bodyText), ['@@ -2,3 +2,3 @@', '-# Old heading', '-removed line'], 'a non-Markdown path keeps its diff rows');
|
|
1257
|
+
|
|
1258
|
+
// A path with no skill or ODD identity is no row of this card at all: the chain keeps it.
|
|
1259
|
+
const forwarded = resolver('edit', () => HOST_EDIT)
|
|
1260
|
+
.renderResult(editResult(), { isPartial: false }, plainTheme, { args: { path: 'docs/notes.md', edits: EDITS } })
|
|
1261
|
+
.render(60);
|
|
1262
|
+
assert.deepEqual(forwarded, ['host edit result'], 'an ordinary Markdown file is the chain\'s row');
|
|
1263
|
+
});
|
|
1264
|
+
|
|
1265
|
+
test('without a Markdown renderer the edit body is the same fragment, never the diff (S6)', () => {
|
|
1266
|
+
const drawsNothing = class { render() { return []; } invalidate() {} };
|
|
1267
|
+
const throws = class { render() { throw new Error('renderer exploded'); } invalidate() {} };
|
|
1268
|
+
const cases = [['no renderer', null], ['a renderer that throws', throws], ['a renderer that draws nothing', drawsNothing]];
|
|
1269
|
+
// The fragment's own lines are all such a host can draw: its first PREVIEW_ROWS collapsed,
|
|
1270
|
+
// every one of them expanded. Asserted exactly, so a dropped heading or fence row fails.
|
|
1271
|
+
const lines = FRAGMENT.split('\n');
|
|
1272
|
+
for (const [label, markdownClass] of cases) {
|
|
1273
|
+
const resolver = fileResolver({ markdownClass });
|
|
1274
|
+
const args = { path: ODD, edits: EDITS };
|
|
1275
|
+
for (const options of [{ isPartial: false }, { expanded: true, isPartial: false }]) {
|
|
1276
|
+
const rows = resultRows(resolver, 'edit', args, editResult(), options, taggedTheme, 60);
|
|
1277
|
+
const expected = options.expanded === true ? lines : lines.slice(0, PREVIEW_ROWS);
|
|
1278
|
+
assert.deepEqual(rows.slice(0, -1).map(bodyText), expected, `${label}: every fragment row it draws, in order`);
|
|
1279
|
+
assert.match(unpaint(rows.at(-1)), /^╰.*╯$/u, `${label}: and its own closing rule`);
|
|
1280
|
+
assert.equal(bodyPaint(rows.slice(0, -1).join('\n')).includes('<mdHeading>'), false, `${label}: as plain source, in no Markdown role`);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
test('a collapsed edit previews the fragment exactly like a write of it (S5)', () => {
|
|
1286
|
+
const resolver = documentResolver();
|
|
1287
|
+
const args = { path: ODD, edits: [{ newText: DOCUMENT }] };
|
|
1288
|
+
const collapsed = resultRows(resolver, 'edit', args, editResult(), { isPartial: false }, taggedTheme, 60);
|
|
1289
|
+
const write = resultRows(resolver, 'write', { path: ODD, content: DOCUMENT }, textResult('Wrote 42 bytes'), { isPartial: false }, taggedTheme, 60);
|
|
1290
|
+
assert.equal(collapsed.length, PREVIEW_ROWS + 1, 'three preview rows and the closing rule');
|
|
1291
|
+
assert.deepEqual(collapsed.slice(0, PREVIEW_ROWS), write.slice(0, PREVIEW_ROWS), 'the same preview a write of the document draws');
|
|
1292
|
+
const preview = collapsed.slice(0, PREVIEW_ROWS).join('\n');
|
|
1293
|
+
assert.equal(preview.includes('<mdHeading>Design</mdHeading>'), true, `the preview starts at the fragment's top: ${preview}`);
|
|
1294
|
+
assert.equal(preview.includes('<mdCodeBlock>const a = 1;</mdCodeBlock>'), false, 'the preview stops at its budget');
|
|
1295
|
+
|
|
1296
|
+
// Expanded, all of it: exactly the rows a write of the same document draws, so a row
|
|
1297
|
+
// dropped from the middle cannot pass, and every drawn row of the document is there.
|
|
1298
|
+
const expanded = resultRows(resolver, 'edit', args, editResult(), { expanded: true, isPartial: false }, taggedTheme, 60);
|
|
1299
|
+
const expandedWrite = resultRows(resolver, 'write', { path: ODD, content: DOCUMENT }, textResult('Wrote 42 bytes'), { expanded: true, isPartial: false }, taggedTheme, 60);
|
|
1300
|
+
assert.deepEqual(expanded, expandedWrite, 'expanding an edit is the whole document, row for row');
|
|
1301
|
+
assert.ok(expanded.length > PREVIEW_ROWS + 1, 'and it is more than the collapsed preview draws');
|
|
1302
|
+
assert.equal(unpaint(expanded.slice(0, -1).join('\n')).includes('@@'), false, 'and no diff row anywhere');
|
|
1303
|
+
|
|
1304
|
+
// `minimal` draws the call alone: the heading above it is still the call's, and the
|
|
1305
|
+
// result is its closing rule with no body under it.
|
|
1306
|
+
globalThis[CARD_CONTENT_SLOT] = 'minimal';
|
|
1307
|
+
try {
|
|
1308
|
+
const call = callRows(resolver, 'edit', args, taggedTheme, 60);
|
|
1309
|
+
assert.equal(call.length, 1, 'the call is its one heading row at either level');
|
|
1310
|
+
assert.match(unpaint(call[0]), /📑 odd/u, 'and it still heads as the ODD artifact');
|
|
1311
|
+
assert.match(unpaint(call[0]), /edit/u, 'naming the tool');
|
|
1312
|
+
assert.match(unpaint(call[0]), /cards-skill-odd\.md/u, 'and the file');
|
|
1313
|
+
const minimal = resultRows(resolver, 'edit', args, editResult(), { isPartial: false }, taggedTheme, 60);
|
|
1314
|
+
assert.equal(minimal.length, 1, 'the closing rule alone');
|
|
1315
|
+
assert.match(unpaint(minimal[0]), /^╰.*╯$/u, 'with no body above it');
|
|
1316
|
+
assert.doesNotMatch(unpaint(minimal[0]), /Design|quoted|```/u, 'and nothing of the document on it');
|
|
1317
|
+
assertFramed(minimal, 60);
|
|
1318
|
+
} finally {
|
|
1319
|
+
delete globalThis[CARD_CONTENT_SLOT];
|
|
1320
|
+
}
|
|
1164
1321
|
});
|
|
1165
1322
|
|
|
1166
1323
|
test('a failed result keeps its error rows and the error tone', () => {
|
|
@@ -42,9 +42,9 @@ function git(cwd, args) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/** A real repository: `main`, one commit and one tracked file. */
|
|
45
|
-
function makeRepo() {
|
|
45
|
+
function makeRepo({ branch = 'main' } = {}) {
|
|
46
46
|
const dir = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-files-repo-')));
|
|
47
|
-
git(dir, ['init', '-b',
|
|
47
|
+
git(dir, ['init', '-b', branch]);
|
|
48
48
|
git(dir, ['config', 'user.email', 'test@example.test']);
|
|
49
49
|
git(dir, ['config', 'user.name', 'Test']);
|
|
50
50
|
fs.writeFileSync(path.join(dir, 'a.js'), 'const x = 1;\n');
|
|
@@ -55,10 +55,10 @@ function makeRepo() {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/** One checkout this package owns, at the canonical directory, one file short of committed. */
|
|
58
|
-
function addOwnedWorktree(repo, odd, branch) {
|
|
58
|
+
function addOwnedWorktree(repo, odd, branch, base = 'main') {
|
|
59
59
|
const parent = path.dirname(repo);
|
|
60
60
|
const target = path.join(parent, `${path.basename(repo)}-worktrees`, odd);
|
|
61
|
-
git(repo, ['worktree', 'add', '-b', branch, target,
|
|
61
|
+
git(repo, ['worktree', 'add', '-b', branch, target, base]);
|
|
62
62
|
fs.writeFileSync(path.join(target, 'x.js'), 'const y = 2;\n');
|
|
63
63
|
return fs.realpathSync(target);
|
|
64
64
|
}
|
|
@@ -537,6 +537,118 @@ describe('several checkouts: the scope step (S9)', () => {
|
|
|
537
537
|
});
|
|
538
538
|
});
|
|
539
539
|
|
|
540
|
+
describe('the badges of a scope (S1-S4)', () => {
|
|
541
|
+
// The row a `/files` list paints for one file: `<name> … <badge> <age> │`, the
|
|
542
|
+
// badge right-aligned against the pane's rule. Ages are `s`/`h`/`d`, so a badge
|
|
543
|
+
// is only ever a letter followed by one.
|
|
544
|
+
const badgeOf = (text, name) => {
|
|
545
|
+
const found = text.match(new RegExp(`${name.replace('.', '\\.')} +([AMU])(?: +\\d+[smhd])?(?= *│)`));
|
|
546
|
+
return found === null ? null : found[1];
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
test('a worktree reads its own commits, so committing keeps the badges', async () => {
|
|
550
|
+
const repo = makeRepo();
|
|
551
|
+
// One file added and one tracked file modified, both COMMITTED: the working
|
|
552
|
+
// tree no longer knows about them, which is exactly what used to erase the
|
|
553
|
+
// badges. `x.js` stays uncommitted, so the union with the status read is
|
|
554
|
+
// proved by the same browse.
|
|
555
|
+
const worktree = addOwnedWorktree(repo, 'with-commits', 'feat/commits');
|
|
556
|
+
fs.writeFileSync(path.join(worktree, 'committed.js'), 'const c = 1;\n');
|
|
557
|
+
git(worktree, ['add', 'committed.js']);
|
|
558
|
+
git(worktree, ['commit', '-m', 'add committed.js']);
|
|
559
|
+
fs.writeFileSync(path.join(worktree, 'a.js'), 'const x = 2;\n');
|
|
560
|
+
git(worktree, ['commit', '-am', 'touch a.js']);
|
|
561
|
+
|
|
562
|
+
const { mod, commands } = await loadFilesExtension();
|
|
563
|
+
mod.setFilesTuiLoader(async () => helpers);
|
|
564
|
+
const host = mountHost();
|
|
565
|
+
const running = commands.get('files').handler('', ctxFor(repo, host.ui, { registeredRoots: [worktree] }));
|
|
566
|
+
|
|
567
|
+
await waitFor(() => host.mounts.length >= 1, 'the scope mount');
|
|
568
|
+
const step = host.mounts[0].component;
|
|
569
|
+
await waitFor(() => textOf(step).includes('with-commits · feat/commits'), 'the worktree row');
|
|
570
|
+
step.handleInput('\u001b[B');
|
|
571
|
+
step.handleInput('\r');
|
|
572
|
+
|
|
573
|
+
await waitFor(() => host.mounts.length >= 2, 'the picker over the worktree');
|
|
574
|
+
const picker = host.mounts[1].component;
|
|
575
|
+
await waitFor(() => textOf(picker).includes('committed.js'), 'the worktree listing');
|
|
576
|
+
const text = textOf(picker);
|
|
577
|
+
// S44: the title names the distance ahead, and only ahead — the two commits are
|
|
578
|
+
// what the badges are measured against.
|
|
579
|
+
assert.match(text, /^╭─ ✿ Files · .*with-commits · ↑2 main /m,
|
|
580
|
+
'the title carries the commits ahead of the principal branch');
|
|
581
|
+
assert.ok(!/↓\d+ /.test(text), 'behind is never painted beside ahead');
|
|
582
|
+
assert.equal(badgeOf(text, 'committed.js'), 'A', 'a file the branch added reads A');
|
|
583
|
+
assert.equal(badgeOf(text, 'a.js'), 'M', 'a file the branch modified reads M');
|
|
584
|
+
assert.equal(badgeOf(text, 'x.js'), 'U', 'uncommitted work is still marked');
|
|
585
|
+
assert.equal(badgeOf(text, 'README.md'), null, 'a file the branch never touched reads nothing');
|
|
586
|
+
|
|
587
|
+
// The scope row above the picker counts the same set, so the number and the
|
|
588
|
+
// badges can never disagree.
|
|
589
|
+
assert.match(textOf(step), /with-commits · feat\/commits +±3 files/, 'the row counts the same set the badges mark');
|
|
590
|
+
|
|
591
|
+
picker.handleInput('\u001b');
|
|
592
|
+
await running;
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
test('a repository whose principal branch is not `main` still marks its worktrees', async () => {
|
|
596
|
+
// S2: the comparison is the branch the PRINCIPAL checkout has, not a constant,
|
|
597
|
+
// so a `master` repository does not end up diffing against a `main` that does
|
|
598
|
+
// not exist — which would fail the read and leave the picker with no listing.
|
|
599
|
+
const repo = makeRepo({ branch: 'master' });
|
|
600
|
+
const worktree = addOwnedWorktree(repo, 'on-master', 'feat/on-master', 'master');
|
|
601
|
+
git(worktree, ['add', 'x.js']);
|
|
602
|
+
git(worktree, ['commit', '-m', 'commit x.js']);
|
|
603
|
+
|
|
604
|
+
const { mod, commands } = await loadFilesExtension();
|
|
605
|
+
mod.setFilesTuiLoader(async () => helpers);
|
|
606
|
+
const host = mountHost();
|
|
607
|
+
const running = commands.get('files').handler('', ctxFor(repo, host.ui, { registeredRoots: [worktree] }));
|
|
608
|
+
|
|
609
|
+
await waitFor(() => host.mounts.length >= 1, 'the scope mount');
|
|
610
|
+
const step = host.mounts[0].component;
|
|
611
|
+
await waitFor(() => textOf(step).includes('on-master · feat/on-master'), 'the worktree row');
|
|
612
|
+
step.handleInput('\u001b[B');
|
|
613
|
+
step.handleInput('\r');
|
|
614
|
+
|
|
615
|
+
await waitFor(() => host.mounts.length >= 2, 'the picker over the worktree');
|
|
616
|
+
const picker = host.mounts[1].component;
|
|
617
|
+
await waitFor(() => textOf(picker).includes('x.js'), 'the worktree listing');
|
|
618
|
+
const text = textOf(picker);
|
|
619
|
+
assert.equal(badgeOf(text, 'x.js'), 'A', 'the committed file is marked against `master`');
|
|
620
|
+
assert.equal(badgeOf(text, 'a.js'), null);
|
|
621
|
+
|
|
622
|
+
picker.handleInput('\u001b');
|
|
623
|
+
await running;
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
test('the main scope still reads its own status: a commit there clears the badge', async () => {
|
|
627
|
+
const repo = makeRepo();
|
|
628
|
+
fs.writeFileSync(path.join(repo, 'a.js'), 'const x = 9;\n');
|
|
629
|
+
git(repo, ['commit', '-am', 'touch a.js']);
|
|
630
|
+
fs.appendFileSync(path.join(repo, 'README.md'), 'dirty\n');
|
|
631
|
+
|
|
632
|
+
const { mod, commands } = await loadFilesExtension();
|
|
633
|
+
mod.setFilesTuiLoader(async () => helpers);
|
|
634
|
+
const host = mountHost();
|
|
635
|
+
const running = commands.get('files').handler('', ctxFor(repo, host.ui));
|
|
636
|
+
|
|
637
|
+
await waitFor(() => host.mounts.length >= 1, 'the scope mount');
|
|
638
|
+
host.mounts[0].component.handleInput('\r');
|
|
639
|
+
|
|
640
|
+
await waitFor(() => host.mounts.length >= 2, 'the picker over main');
|
|
641
|
+
const picker = host.mounts[1].component;
|
|
642
|
+
await waitFor(() => textOf(picker).includes('a.js'), 'the main listing');
|
|
643
|
+
const text = textOf(picker);
|
|
644
|
+
assert.equal(badgeOf(text, 'a.js'), null, 'a committed change in the principal checkout paints nothing');
|
|
645
|
+
assert.equal(badgeOf(text, 'README.md'), 'M', 'its uncommitted change still reads M');
|
|
646
|
+
|
|
647
|
+
picker.handleInput('\u001b');
|
|
648
|
+
await running;
|
|
649
|
+
});
|
|
650
|
+
});
|
|
651
|
+
|
|
540
652
|
describe('the preview and the editor (S12, S14)', () => {
|
|
541
653
|
test('the injected highlighter reaches the pane through the command’s own seams (S12)', async () => {
|
|
542
654
|
const repo = makeRepo();
|