pi-odd-worktree 3.4.0 → 3.6.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 +3 -2
- package/extensions/odd-worktree-tools.ts +64 -3
- package/lib/depth-launch.js +70 -0
- package/lib/depth-prompt/depth.md +53 -0
- package/lib/depth-task.js +76 -0
- 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/package.json +1 -1
- package/tools/depth-command.test.js +66 -0
- package/tools/depth-launch.test.js +123 -0
- package/tools/depth-task.test.js +76 -0
- package/tools/files-bridge.test.js +2 -2
- package/tools/files-command.test.js +117 -5
- 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/package-surface.test.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `/depth` through the registered command (S4, S5, S6): the extension's one new command starts the explorer by itself,
|
|
3
|
+
// through the host's `subagent_run` tool, and answers with one notice. The launch rules are in tools/depth-launch.test.js;
|
|
4
|
+
// this suite proves the command is wired to them in the loaded extension, behind the same gate as the others.
|
|
5
|
+
const { test } = require('node:test');
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
const { loadExtension } = require('./fixtures/load-extension.js');
|
|
8
|
+
|
|
9
|
+
function makeCtx({ tools = [{ name: 'subagent_run' }], outcome = { content: [{ type: 'text', text: 'Started gentle-ai-explore in the background as task t-1.' }] } } = {}) {
|
|
10
|
+
const calls = [];
|
|
11
|
+
const notes = [];
|
|
12
|
+
const ctx = {
|
|
13
|
+
tools,
|
|
14
|
+
executeTool: async (name, args) => {
|
|
15
|
+
calls.push({ name, args });
|
|
16
|
+
return outcome;
|
|
17
|
+
},
|
|
18
|
+
ui: { notify: (message, level) => notes.push({ message, level }) },
|
|
19
|
+
};
|
|
20
|
+
return { ctx, calls, notes };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test('/depth is a registered command that says what it does', async () => {
|
|
24
|
+
const { commands } = await loadExtension({});
|
|
25
|
+
const depth = commands.get('depth');
|
|
26
|
+
assert.ok(depth, '/depth is registered');
|
|
27
|
+
assert.equal(typeof depth.handler, 'function');
|
|
28
|
+
assert.match(depth.description, /background/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('/depth <request> starts one background explorer with the request verbatim and says so', async () => {
|
|
32
|
+
const { commands } = await loadExtension({});
|
|
33
|
+
const { ctx, calls, notes } = makeCtx();
|
|
34
|
+
await commands.get('depth').handler(' make the error messages clearer ', ctx);
|
|
35
|
+
|
|
36
|
+
assert.equal(calls.length, 1);
|
|
37
|
+
assert.equal(calls[0].name, 'subagent_run');
|
|
38
|
+
assert.equal(calls[0].args.agent, 'gentle-ai-explore');
|
|
39
|
+
assert.equal(calls[0].args.mode, 'background');
|
|
40
|
+
assert.ok(calls[0].args.task.endsWith('## Request\n\nmake the error messages clearer'));
|
|
41
|
+
assert.deepEqual(notes, [
|
|
42
|
+
{ message: 'Exploring in the background (depth: make the error messages clearer). The handoff arrives in this session when it finishes.', level: 'info' },
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('/depth with no request starts nothing and shows the usage as an error', async () => {
|
|
47
|
+
const { commands } = await loadExtension({});
|
|
48
|
+
const { ctx, calls, notes } = makeCtx();
|
|
49
|
+
await commands.get('depth').handler('', ctx);
|
|
50
|
+
assert.equal(calls.length, 0);
|
|
51
|
+
assert.equal(notes.length, 1);
|
|
52
|
+
assert.equal(notes[0].level, 'error');
|
|
53
|
+
assert.match(notes[0].message, /^\/depth needs a request: \/depth <request>\./);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('/depth without the host tool says so, and a context with no ui does not throw', async () => {
|
|
57
|
+
const { commands } = await loadExtension({});
|
|
58
|
+
const { ctx, calls, notes } = makeCtx({ tools: [] });
|
|
59
|
+
await commands.get('depth').handler('fix the login', ctx);
|
|
60
|
+
assert.equal(calls.length, 0);
|
|
61
|
+
assert.match(notes[0].message, /subagent_run/);
|
|
62
|
+
assert.equal(notes[0].level, 'error');
|
|
63
|
+
|
|
64
|
+
await assert.doesNotReject(commands.get('depth').handler('fix the login', { tools: [], executeTool: async () => ({}) }));
|
|
65
|
+
await assert.doesNotReject(commands.get('depth').handler(undefined, undefined));
|
|
66
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `/depth`'s launch (S4, S5, S8): the command starts ONE background `gentle-ai-explore` through the host's own
|
|
3
|
+
// `subagent_run` tool, with the Depth task and nothing else. Progress, cancellation and the delivery of the handoff are
|
|
4
|
+
// gentle-agents', so this module has no widget, no timer and no message of its own; it only decides whether the launch can
|
|
5
|
+
// happen and says in one sentence what did or did not.
|
|
6
|
+
const { test } = require('node:test');
|
|
7
|
+
const assert = require('node:assert/strict');
|
|
8
|
+
const { launchDepth, DEPTH_AGENT, DEPTH_TOOL } = require('../lib/depth-launch.js');
|
|
9
|
+
const { DEPTH_RETURN_HEADINGS } = require('../lib/depth-task.js');
|
|
10
|
+
|
|
11
|
+
const STARTED = {
|
|
12
|
+
content: [{ type: 'text', text: 'Started gentle-ai-explore in the background as task abc-1.' }],
|
|
13
|
+
details: {},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function host({ outcome = STARTED, tools = [{ name: 'subagent_run' }, { name: 'job_list' }], throws } = {}) {
|
|
17
|
+
const calls = [];
|
|
18
|
+
const ctx = {
|
|
19
|
+
tools,
|
|
20
|
+
executeTool: async (name, args) => {
|
|
21
|
+
calls.push({ name, args });
|
|
22
|
+
if (throws) throw throws;
|
|
23
|
+
return outcome;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
return { ctx, calls };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('the names the launch depends on are the host agent and tool', () => {
|
|
30
|
+
assert.equal(DEPTH_AGENT, 'gentle-ai-explore');
|
|
31
|
+
assert.equal(DEPTH_TOOL, 'subagent_run');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('it starts one background explorer, with exactly the arguments the host tool accepts', async () => {
|
|
35
|
+
const { ctx, calls } = host();
|
|
36
|
+
const request = 'make the error messages clearer\n\n- keep «exactly» this';
|
|
37
|
+
const result = await launchDepth(request, ctx);
|
|
38
|
+
|
|
39
|
+
assert.equal(calls.length, 1);
|
|
40
|
+
assert.equal(calls[0].name, 'subagent_run');
|
|
41
|
+
// `subagent_run` rejects any other key (additionalProperties: false), so the set is closed.
|
|
42
|
+
assert.deepEqual(Object.keys(calls[0].args).sort(), ['agent', 'label', 'mode', 'task']);
|
|
43
|
+
assert.equal(calls[0].args.agent, 'gentle-ai-explore');
|
|
44
|
+
assert.equal(calls[0].args.mode, 'background');
|
|
45
|
+
assert.equal(calls[0].args.label, 'depth: make the error messages clearer');
|
|
46
|
+
assert.ok(calls[0].args.task.endsWith(`## Request\n\n${request}`), 'the request goes in verbatim, last');
|
|
47
|
+
for (const heading of DEPTH_RETURN_HEADINGS) assert.ok(calls[0].args.task.includes(heading), heading);
|
|
48
|
+
|
|
49
|
+
assert.deepEqual(result, {
|
|
50
|
+
ok: true,
|
|
51
|
+
level: 'info',
|
|
52
|
+
message: 'Exploring in the background (depth: make the error messages clearer). The handoff arrives in this session when it finishes.',
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('a blank request starts nothing and says how to use the command', async () => {
|
|
57
|
+
for (const blank of ['', ' \n', undefined, null]) {
|
|
58
|
+
const { ctx, calls } = host();
|
|
59
|
+
const result = await launchDepth(blank, ctx);
|
|
60
|
+
assert.equal(calls.length, 0);
|
|
61
|
+
assert.equal(result.ok, false);
|
|
62
|
+
assert.equal(result.level, 'error');
|
|
63
|
+
assert.match(result.message, /^\/depth needs a request: \/depth <request>\./);
|
|
64
|
+
assert.match(result.message, /does not see this chat/);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('without the host tool nothing starts, and the sentence names the tool', async () => {
|
|
69
|
+
const noTool = { executeTool: async () => assert.fail('must not be called') };
|
|
70
|
+
const cases = [
|
|
71
|
+
{ ...noTool },
|
|
72
|
+
{ ...noTool, tools: [] },
|
|
73
|
+
{ ...noTool, tools: [{ name: 'job_list' }] },
|
|
74
|
+
{ ...noTool, tools: 'subagent_run' },
|
|
75
|
+
{ tools: [{ name: 'subagent_run' }] },
|
|
76
|
+
undefined,
|
|
77
|
+
null,
|
|
78
|
+
];
|
|
79
|
+
for (const ctx of cases) {
|
|
80
|
+
const result = await launchDepth('fix the login', ctx);
|
|
81
|
+
assert.equal(result.ok, false);
|
|
82
|
+
assert.equal(result.level, 'error');
|
|
83
|
+
assert.match(result.message, /subagent_run/);
|
|
84
|
+
assert.match(result.message, /does not offer it/);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('a refusal from the host tool is shown with its own words', async () => {
|
|
89
|
+
const { ctx, calls } = host({ outcome: { isError: true, content: [{ type: 'text', text: 'Background subagents need an interactive session.' }] } });
|
|
90
|
+
const result = await launchDepth('fix the login', ctx);
|
|
91
|
+
assert.equal(calls.length, 1);
|
|
92
|
+
assert.deepEqual(result, {
|
|
93
|
+
ok: false,
|
|
94
|
+
level: 'error',
|
|
95
|
+
message: "/depth couldn't start the explorer: Background subagents need an interactive session.",
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('a refusal with no text, a thrown error and an empty answer each become one sentence', async () => {
|
|
100
|
+
const silent = await launchDepth('x', host({ outcome: { isError: true, content: [] } }).ctx);
|
|
101
|
+
assert.equal(silent.message, "/depth couldn't start the explorer: the subagent_run tool reported an error.");
|
|
102
|
+
|
|
103
|
+
const thrown = await launchDepth('x', host({ throws: new Error('boom') }).ctx);
|
|
104
|
+
assert.equal(thrown.ok, false);
|
|
105
|
+
assert.equal(thrown.message, "/depth couldn't start the explorer: boom");
|
|
106
|
+
|
|
107
|
+
// `null`, not `undefined`: the double's default parameter would turn `undefined` into a successful start.
|
|
108
|
+
const empty = await launchDepth('x', host({ outcome: null }).ctx);
|
|
109
|
+
assert.equal(empty.ok, false);
|
|
110
|
+
assert.match(empty.message, /^\/depth couldn't start the explorer:/);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('a hostile context never makes it throw', async () => {
|
|
114
|
+
const hostile = {
|
|
115
|
+
get tools() {
|
|
116
|
+
throw new Error('no tools for you');
|
|
117
|
+
},
|
|
118
|
+
executeTool: async () => STARTED,
|
|
119
|
+
};
|
|
120
|
+
const result = await launchDepth('fix the login', hostile);
|
|
121
|
+
assert.equal(result.ok, false);
|
|
122
|
+
assert.match(result.message, /subagent_run/);
|
|
123
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The task `/depth` hands the explorer: the instructions of `lib/depth-prompt/depth.md`, then the request exactly as the
|
|
3
|
+
// person typed it (S1, S3, S8). The explorer has no chat, so the request is the only thing it will ever know of the
|
|
4
|
+
// person's words, and it comes back first in the handoff (S8, L8).
|
|
5
|
+
const { test } = require('node:test');
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
const { buildDepthTask, depthLabel, DEPTH_RETURN_HEADINGS, DEPTH_BANNER, DEPTH_FOR_PARENT } = require('../lib/depth-task.js');
|
|
8
|
+
|
|
9
|
+
const REQUEST = 'make the error messages clearer\n\n- keep «exactly» this: `/x failed:`\n- no retries';
|
|
10
|
+
|
|
11
|
+
test('the task is the instructions, then the request exactly as typed', () => {
|
|
12
|
+
const task = buildDepthTask(REQUEST, { read: () => 'INSTRUCTIONS' });
|
|
13
|
+
assert.ok(task.startsWith('INSTRUCTIONS'), 'the instructions lead');
|
|
14
|
+
assert.ok(task.endsWith(`## Request\n\n${REQUEST}`), 'the request closes the task, byte for byte');
|
|
15
|
+
assert.equal(task.split('## Request').length - 1, 1, 'one request section');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('only the ends of the request are trimmed, never its inside', () => {
|
|
19
|
+
const task = buildDepthTask('\n a\n\n b \n\n', { read: () => 'I' });
|
|
20
|
+
assert.ok(task.endsWith('## Request\n\na\n\n b'));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('a blank or non-string request builds no task', () => {
|
|
24
|
+
for (const blank of ['', ' ', '\n\t\n', undefined, null, 5, {}]) {
|
|
25
|
+
assert.equal(buildDepthTask(blank, { read: () => 'I' }), null);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('a missing or empty instructions file still gives a task that names every section', () => {
|
|
30
|
+
const unreadable = () => {
|
|
31
|
+
throw new Error('ENOENT');
|
|
32
|
+
};
|
|
33
|
+
for (const read of [unreadable, () => '', () => ' \n', () => undefined]) {
|
|
34
|
+
const task = buildDepthTask(REQUEST, { read });
|
|
35
|
+
assert.ok(task.endsWith(`## Request\n\n${REQUEST}`));
|
|
36
|
+
for (const heading of DEPTH_RETURN_HEADINGS) assert.ok(task.includes(heading), `fallback names ${heading}`);
|
|
37
|
+
assert.match(task, /Never carry the request out/);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('the shipped instructions name the return sections in order, and the parent closes them', () => {
|
|
42
|
+
const task = buildDepthTask('x');
|
|
43
|
+
let at = -1;
|
|
44
|
+
for (const heading of DEPTH_RETURN_HEADINGS) {
|
|
45
|
+
const next = task.indexOf(`\n${heading}\n`, at + 1);
|
|
46
|
+
assert.ok(next > at, `${heading} appears after the previous section`);
|
|
47
|
+
at = next;
|
|
48
|
+
}
|
|
49
|
+
assert.equal(DEPTH_RETURN_HEADINGS[0], '## Original request', 'the verbatim request leads the handoff');
|
|
50
|
+
assert.equal(DEPTH_RETURN_HEADINGS.at(-1), '## For the parent', 'the line for the parent closes it');
|
|
51
|
+
assert.match(task, /Do not implement/);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('the label is one short line that starts with the command', () => {
|
|
55
|
+
assert.equal(depthLabel('fix the login'), 'depth: fix the login');
|
|
56
|
+
const long = depthLabel(`${'x'.repeat(200)}\nsecond line`);
|
|
57
|
+
assert.ok(long.startsWith('depth: xxx') && long.endsWith('…') && !long.includes('\n'));
|
|
58
|
+
assert.ok(long.length <= 60, `short enough, got ${long.length}`);
|
|
59
|
+
assert.equal(depthLabel('first\nsecond'), 'depth: first');
|
|
60
|
+
for (const blank of ['', ' ', undefined, 5]) assert.equal(depthLabel(blank), 'depth');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('the parent is guarded at both ends: an opening line and the closing paragraph, in the shipped file and in the fallback', () => {
|
|
64
|
+
// The parent wakes on the handoff alone and may start implementing, so the instruction not to must not depend on one
|
|
65
|
+
// section a cheap model can drop (a real run dropped `## For the parent` and translated the headings).
|
|
66
|
+
assert.equal(typeof DEPTH_BANNER, 'string');
|
|
67
|
+
assert.equal(typeof DEPTH_FOR_PARENT, 'string');
|
|
68
|
+
assert.match(DEPTH_BANNER, /nothing was implemented/);
|
|
69
|
+
assert.match(DEPTH_FOR_PARENT, /^Do not implement this request\./);
|
|
70
|
+
for (const read of [undefined, () => '']) {
|
|
71
|
+
const task = buildDepthTask('x', read === undefined ? {} : { read });
|
|
72
|
+
assert.ok(task.includes(DEPTH_BANNER), 'the opening line is asked for');
|
|
73
|
+
assert.ok(task.includes(DEPTH_FOR_PARENT), 'the closing paragraph is given');
|
|
74
|
+
assert.match(task, /character for character/);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
@@ -433,8 +433,8 @@ test('S18/S19 (T14): the ready announcement registers the whole surface, exactly
|
|
|
433
433
|
const bridge = installBridge();
|
|
434
434
|
for (const entry of ready) entry.handler();
|
|
435
435
|
|
|
436
|
-
assert.deepEqual([...loaded.commands.keys()].sort(), ['files', 'issues', 'odd', 'warp'],
|
|
437
|
-
'the
|
|
436
|
+
assert.deepEqual([...loaded.commands.keys()].sort(), ['depth', 'files', 'issues', 'odd', 'warp'],
|
|
437
|
+
'the five commands arrive with the bridge');
|
|
438
438
|
assert.deepEqual([...loaded.tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'the two tools');
|
|
439
439
|
assert.deepEqual([...loaded.messageRenderers.keys()], ['worktree-warp'], 'the message renderer');
|
|
440
440
|
assert.deepEqual([...loaded.entryRenderers.keys()].sort(), ['odd-worktree-issues-refusal', 'odd-worktree-warp-queue'],
|
|
@@ -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
|
}
|
|
@@ -244,7 +244,7 @@ const agentStub = {
|
|
|
244
244
|
describe('/files registration (S17)', () => {
|
|
245
245
|
test('the file picker is registered beside the other three panels', async () => {
|
|
246
246
|
const { commands } = await loadExtension({});
|
|
247
|
-
assert.deepEqual([...commands.keys()].sort(), ['files', 'issues', 'odd', 'warp']);
|
|
247
|
+
assert.deepEqual([...commands.keys()].sort(), ['depth', 'files', 'issues', 'odd', 'warp']);
|
|
248
248
|
const files = commands.get('files');
|
|
249
249
|
assert.equal(typeof files.handler, 'function', 'the command carries its handler');
|
|
250
250
|
assert.ok(files.description.includes('files'), 'the description says what it browses');
|
|
@@ -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();
|