pi-odd-worktree 2.0.0 → 3.0.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 +54 -311
- package/extensions/odd-worktree-tools.ts +4149 -2447
- package/lib/bash-activity.js +1164 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1416 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +308 -14
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -711
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1419 -0
- package/tools/bash-design.test.js +1091 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +610 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1871 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +391 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1512 -66
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4195 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2569 -308
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +477 -93
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
// S2/S4 behavior of the
|
|
3
|
-
// tool objects against a real temporary repository
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
2
|
+
// S2/S4 behavior of the two registered checkout tools, exercised through the
|
|
3
|
+
// REGISTERED tool objects against a real temporary repository, plus the shared
|
|
4
|
+
// removal the warp panel's ctrl+d drives (`executeWorktreeClose`) — the agent
|
|
5
|
+
// tool that used to wrap it is unregistered (T6/S4), so the close cases call it
|
|
6
|
+
// directly.
|
|
7
7
|
const { test, describe, before, after } = require('node:test');
|
|
8
8
|
const assert = require('node:assert/strict');
|
|
9
9
|
const crypto = require('node:crypto');
|
|
@@ -11,7 +11,8 @@ const fs = require('node:fs');
|
|
|
11
11
|
const os = require('node:os');
|
|
12
12
|
const path = require('node:path');
|
|
13
13
|
const { spawnSync } = require('node:child_process');
|
|
14
|
-
const {
|
|
14
|
+
const { pathToFileURL } = require('node:url');
|
|
15
|
+
const { LIB_DIR, stubbedSource, installDefaultBridge } = require('./fixtures/load-extension.js');
|
|
15
16
|
|
|
16
17
|
const scratch = [];
|
|
17
18
|
function track(dir) {
|
|
@@ -30,12 +31,9 @@ after(() => {
|
|
|
30
31
|
}
|
|
31
32
|
});
|
|
32
33
|
|
|
33
|
-
//
|
|
34
|
+
// An empty bin directory ahead of PATH keeps a create off the developer's
|
|
34
35
|
// PATH-dependent tooling; the rest of PATH is preserved so git still resolves.
|
|
35
36
|
const HOOK_BIN = path.resolve(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-wt-hookbin-'))));
|
|
36
|
-
fs.writeFileSync(path.join(HOOK_BIN, 'codegraph'), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
|
37
|
-
// No Herdr workspace can be created from this path: it does not exist.
|
|
38
|
-
const NO_HERDR = path.join(os.tmpdir(), 'odd-worktree-no-such-herdr-binary');
|
|
39
37
|
|
|
40
38
|
function git(cwd, args) {
|
|
41
39
|
const out = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
@@ -86,6 +84,17 @@ function branches(root) {
|
|
|
86
84
|
return git(root, ['branch', '--format=%(refname:short)']).split('\n').filter(Boolean).sort();
|
|
87
85
|
}
|
|
88
86
|
|
|
87
|
+
// S3/S4: the document this package used to keep, named so a test can assert it was
|
|
88
|
+
// never written.
|
|
89
|
+
function cloneDocument(root) {
|
|
90
|
+
return path.join(git(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']), 'pi-worktrees.json');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// The abbreviation the ported listing and the create both print for the base commit.
|
|
94
|
+
function shortHead(root) {
|
|
95
|
+
return git(root, ['rev-parse', '--short=7', 'HEAD']);
|
|
96
|
+
}
|
|
97
|
+
|
|
89
98
|
// S7/S8/S9: the active-session guard reads Gentle Shell's published presence
|
|
90
99
|
// store. Pin it to a throwaway agent home so no test can see (or be blocked by)
|
|
91
100
|
// the developer's real sessions, and publish synthetic records into it.
|
|
@@ -168,28 +177,62 @@ function makeUiCtx(repoRoot, thread = 'thread-1') {
|
|
|
168
177
|
}
|
|
169
178
|
|
|
170
179
|
let tools;
|
|
180
|
+
let extensionMod;
|
|
181
|
+
let extensionHooks;
|
|
171
182
|
before(async () => {
|
|
172
|
-
process.env.HERDR_BIN_PATH = NO_HERDR;
|
|
173
183
|
process.env.GENTLE_WORKTREE_THREAD = 'thread-1';
|
|
174
184
|
process.env.PATH = `${HOOK_BIN}${path.delimiter}${savedEnv.PATH || ''}`;
|
|
175
185
|
delete process.env.GENTLE_PI_AGENT_HOME;
|
|
176
186
|
process.env.PI_CODING_AGENT_DIR = AGENT_HOME;
|
|
177
|
-
({ tools } = await
|
|
187
|
+
({ tools, mod: extensionMod, hooks: extensionHooks } = await loadExtensionWithModule({}));
|
|
178
188
|
});
|
|
179
189
|
|
|
190
|
+
// The create is instant on BOTH fronts, and its setup runs on the ported
|
|
191
|
+
// `lib/worktree-setup-runner.js` task rather than on any seam this file could
|
|
192
|
+
// reach; this file therefore loads the extension itself — same stubs, same lib
|
|
193
|
+
// override, same fake host as the shared fixture — and keeps the registrations.
|
|
194
|
+
async function loadExtensionWithModule(pi) {
|
|
195
|
+
// S18 (T14): the extension loads nothing without gentle-shell-bridge, so this
|
|
196
|
+
// file's own host publishes the shared fixture's bridge before the factory runs —
|
|
197
|
+
// the same object the rest of the suite loads against.
|
|
198
|
+
installDefaultBridge();
|
|
199
|
+
process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
|
|
200
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'odd-wt-ext-'));
|
|
201
|
+
try {
|
|
202
|
+
const copy = path.join(dir, 'odd-worktree-tools.mjs');
|
|
203
|
+
fs.writeFileSync(copy, stubbedSource());
|
|
204
|
+
const mod = await import(pathToFileURL(copy).href);
|
|
205
|
+
const commands = new Map();
|
|
206
|
+
const tools = new Map();
|
|
207
|
+
const hooks = [];
|
|
208
|
+
mod.default({
|
|
209
|
+
registerCommand: (name, handler) => { commands.set(name, handler); },
|
|
210
|
+
registerTool: (tool) => { tools.set(tool.name, tool); },
|
|
211
|
+
registerMessageRenderer: () => {},
|
|
212
|
+
on: (event, handler) => { hooks.push([event, handler]); },
|
|
213
|
+
...pi,
|
|
214
|
+
});
|
|
215
|
+
return { mod, commands, tools, hooks };
|
|
216
|
+
} finally {
|
|
217
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
180
221
|
describe('worktree_list', () => {
|
|
181
222
|
test('a fresh repository lists its principal checkout only', async () => {
|
|
182
223
|
const repo = makeRepo();
|
|
183
224
|
const { ctx } = makeCtx(repo);
|
|
184
225
|
const result = await tools.get('worktree_list').execute('call-1', {}, undefined, undefined, ctx);
|
|
185
226
|
assert.notEqual(result.isError, true, resultText(result));
|
|
186
|
-
assert.
|
|
187
|
-
|
|
188
|
-
`
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
assert.
|
|
227
|
+
assert.deepEqual(resultText(result).split('\n'), [
|
|
228
|
+
`project: ${path.basename(repo)}`,
|
|
229
|
+
`path: ${fs.realpathSync(repo)}`,
|
|
230
|
+
`base: main@${shortHead(repo)}`,
|
|
231
|
+
]);
|
|
232
|
+
assert.equal(result.details.worktrees.length, 1);
|
|
192
233
|
assert.equal(result.details.worktrees[0].path, fs.realpathSync(repo));
|
|
234
|
+
assert.equal(result.details.hiddenOutside, 0);
|
|
235
|
+
assert.equal('hiddenGone' in result.details, false, 'no stored row can be gone any more');
|
|
193
236
|
});
|
|
194
237
|
|
|
195
238
|
test('a directory outside a repository is refused by the help text', async () => {
|
|
@@ -203,119 +246,229 @@ describe('worktree_list', () => {
|
|
|
203
246
|
|
|
204
247
|
describe('worktree_create', () => {
|
|
205
248
|
for (const existing of [false, true]) {
|
|
206
|
-
test(`
|
|
249
|
+
test(`reports branchState ${existing ? 'existing' : 'created'} for a ${existing ? 'pre-existing' : 'new'} branch`, async () => {
|
|
207
250
|
const repo = makeRepo();
|
|
208
251
|
const branch = existing ? 'feat/existing' : 'feat/new';
|
|
209
252
|
if (existing) git(repo, ['branch', branch]);
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return original(bin, ...args);
|
|
216
|
-
};
|
|
217
|
-
try {
|
|
218
|
-
const { ctx } = makeCtx(repo);
|
|
219
|
-
const result = await tools.get('worktree_create').execute('no-herdr', { branch, changes: 'none' }, undefined, undefined, ctx);
|
|
220
|
-
assert.notEqual(result.isError, true, resultText(result));
|
|
221
|
-
assert.equal(result.details.branchCreated, !existing);
|
|
222
|
-
assert.ok(binaries.includes('git'));
|
|
223
|
-
assert.ok(!binaries.includes(NO_HERDR), `unexpected Herdr execution: ${binaries}`);
|
|
224
|
-
} finally {
|
|
225
|
-
gitLib.runArgvAsync = original;
|
|
226
|
-
}
|
|
253
|
+
const { ctx } = makeCtx(repo);
|
|
254
|
+
const result = await tools.get('worktree_create').execute('call-branch', { branch, odd: 'odd-branch' }, undefined, undefined, ctx);
|
|
255
|
+
assert.notEqual(result.isError, true, resultText(result));
|
|
256
|
+
assert.equal(result.details.branchState, existing ? 'existing' : 'created');
|
|
257
|
+
assert.ok(branches(repo).includes(branch), 'the branch exists');
|
|
227
258
|
});
|
|
228
259
|
}
|
|
229
|
-
test('creates the checkout and
|
|
260
|
+
test('creates the checkout and writes nothing: the directory is the whole record', async () => {
|
|
230
261
|
const repo = makeRepo();
|
|
231
262
|
const { ctx } = makeCtx(repo);
|
|
232
263
|
const result = await tools.get('worktree_create').execute(
|
|
233
264
|
'call-3',
|
|
234
|
-
{ branch: 'feat/x',
|
|
265
|
+
{ branch: 'feat/x', odd: 'odd-x' },
|
|
235
266
|
undefined,
|
|
236
267
|
undefined,
|
|
237
268
|
ctx,
|
|
238
269
|
);
|
|
239
270
|
assert.notEqual(result.isError, true, resultText(result));
|
|
240
|
-
|
|
241
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
242
|
-
assert.
|
|
243
|
-
|
|
244
|
-
|
|
271
|
+
// S7: the checkout IS the ODD, so the branch (`feat/x`) names nothing on disk.
|
|
272
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'odd-x');
|
|
273
|
+
assert.deepEqual(resultText(result).split('\n'), [
|
|
274
|
+
`worktree created: ${target}`,
|
|
275
|
+
'branch: feat/x (created)',
|
|
276
|
+
'odd: odd-x',
|
|
277
|
+
`base: main@${shortHead(repo)}`,
|
|
278
|
+
'worktree register failed',
|
|
279
|
+
]);
|
|
280
|
+
assert.equal(result.details.name, 'odd-x', 'the printed name is the directory basename');
|
|
245
281
|
assert.ok(fs.existsSync(target), 'the checkout exists on disk');
|
|
246
282
|
assert.ok(listWorktreePaths(repo).includes(target), 'git knows the checkout');
|
|
247
283
|
assert.ok(branches(repo).includes('feat/x'), 'the branch exists');
|
|
248
284
|
|
|
285
|
+
// S3/S4: no document, no row, no record. A create followed by a list leaves the
|
|
286
|
+
// clone exactly as Git left it.
|
|
287
|
+
assert.equal(fs.existsSync(cloneDocument(repo)), false, 'no list document is written');
|
|
288
|
+
assert.equal(fs.existsSync(path.join(git(repo, ['rev-parse', '--path-format=absolute', '--git-common-dir']), 'pi-worktrees.lock')), false, 'no lock file is written');
|
|
289
|
+
|
|
249
290
|
const listed = await tools.get('worktree_list').execute('call-4', {}, undefined, undefined, ctx);
|
|
291
|
+
assert.deepEqual(resultText(listed).split('\n'), [
|
|
292
|
+
`project: ${path.basename(repo)}`,
|
|
293
|
+
`path: ${fs.realpathSync(repo)}`,
|
|
294
|
+
`base: main@${shortHead(repo)}`,
|
|
295
|
+
'1 odd-x · feat/x',
|
|
296
|
+
]);
|
|
297
|
+
assert.equal(listed.details.worktrees[1].name, 'odd-x', 'the ODD is the directory basename');
|
|
298
|
+
assert.equal('odd' in listed.details.worktrees[1], false, 'the output carries no odd field');
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
test('an omitted odd is refused with the odd segment sentence and writes nothing', async () => {
|
|
302
|
+
const repo = makeRepo();
|
|
303
|
+
const { ctx } = makeCtx(repo);
|
|
304
|
+
const before = { paths: listWorktreePaths(repo), branches: branches(repo) };
|
|
305
|
+
const result = await tools.get('worktree_create').execute('call-nodd', { branch: 'feat/no-odd' }, undefined, undefined, ctx);
|
|
306
|
+
assert.equal(result.isError, true);
|
|
307
|
+
assert.equal(
|
|
308
|
+
resultText(result),
|
|
309
|
+
'invalid odd name: undefined\nodd must be a single path segment (letters, digits, dash, underscore, dot)',
|
|
310
|
+
);
|
|
311
|
+
assert.deepEqual({ paths: listWorktreePaths(repo), branches: branches(repo) }, before, 'nothing was created');
|
|
312
|
+
assert.equal(fs.existsSync(path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'no-odd')), false);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test('a refused odd writes neither section of the clone document', async () => {
|
|
316
|
+
const repo = makeRepo();
|
|
317
|
+
const { ctx } = makeCtx(repo);
|
|
318
|
+
const result = await tools.get('worktree_create').execute('call-nodd-doc', { branch: 'feat/no-odd-doc', odd: 'a/b' }, undefined, undefined, ctx);
|
|
319
|
+
assert.equal(result.isError, true);
|
|
250
320
|
assert.equal(
|
|
251
|
-
resultText(
|
|
252
|
-
|
|
321
|
+
resultText(result),
|
|
322
|
+
'invalid odd name: "a/b"\nodd must be a single path segment (letters, digits, dash, underscore, dot)',
|
|
253
323
|
);
|
|
324
|
+
assert.equal(fs.existsSync(cloneDocument(repo)), false, 'no document is written');
|
|
325
|
+
assert.equal(fs.existsSync(path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`)), false, 'no checkout directory');
|
|
254
326
|
});
|
|
255
327
|
|
|
256
|
-
test('
|
|
328
|
+
test('the registration line only prints when the host tool accepted the path', async () => {
|
|
329
|
+
const repo = makeRepo();
|
|
330
|
+
const { ctx } = makeCtx(repo);
|
|
331
|
+
const registered = [];
|
|
332
|
+
const hostCtx = {
|
|
333
|
+
...ctx,
|
|
334
|
+
tools: [{ name: 'session_worktree_register' }],
|
|
335
|
+
executeTool: async (name, args) => {
|
|
336
|
+
registered.push([name, args]);
|
|
337
|
+
return { isError: false };
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
const result = await tools.get('worktree_create').execute('call-reg', { branch: 'feat/reg', odd: 'reg' }, undefined, undefined, hostCtx);
|
|
341
|
+
assert.notEqual(result.isError, true, resultText(result));
|
|
342
|
+
assert.match(resultText(result), /^worktree register in session$/m);
|
|
343
|
+
assert.equal(result.details.registered, true);
|
|
344
|
+
assert.deepEqual(registered, [
|
|
345
|
+
['session_worktree_register', { path: path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'reg') }],
|
|
346
|
+
]);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test('refuses an odd that is not one path segment, and writes nothing', async () => {
|
|
257
350
|
const repo = makeRepo();
|
|
258
351
|
const { ctx } = makeCtx(repo);
|
|
259
352
|
const before = { paths: listWorktreePaths(repo), branches: branches(repo) };
|
|
260
353
|
const result = await tools.get('worktree_create').execute(
|
|
261
354
|
'call-5',
|
|
262
|
-
{ branch: '
|
|
355
|
+
{ branch: 'feat/login', odd: '../escape' },
|
|
263
356
|
undefined,
|
|
264
357
|
undefined,
|
|
265
358
|
ctx,
|
|
266
359
|
);
|
|
267
360
|
assert.equal(result.isError, true);
|
|
268
|
-
assert.
|
|
361
|
+
assert.equal(
|
|
362
|
+
resultText(result),
|
|
363
|
+
'invalid odd name: "../escape"\nodd must be a single path segment (letters, digits, dash, underscore, dot)',
|
|
364
|
+
);
|
|
269
365
|
assert.deepEqual({ paths: listWorktreePaths(repo), branches: branches(repo) }, before);
|
|
270
366
|
});
|
|
271
367
|
|
|
272
|
-
test('refuses
|
|
368
|
+
test('refuses the base branch as the worktree branch and writes nothing', async () => {
|
|
273
369
|
const repo = makeRepo();
|
|
274
370
|
const { ctx } = makeCtx(repo);
|
|
275
|
-
const
|
|
371
|
+
const before = { paths: listWorktreePaths(repo), branches: branches(repo) };
|
|
372
|
+
const result = await tools.get('worktree_create').execute('call-6', { branch: 'main', odd: 'base' }, undefined, undefined, ctx);
|
|
276
373
|
assert.equal(result.isError, true);
|
|
277
|
-
assert.
|
|
278
|
-
assert.
|
|
374
|
+
assert.equal(resultText(result), 'branch main is the base branch; pick the branch this worktree should work on');
|
|
375
|
+
assert.deepEqual({ paths: listWorktreePaths(repo), branches: branches(repo) }, before);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test('copy_changes carries the principal checkout\u2019s uncommitted changes when the call is made there', async () => {
|
|
379
|
+
const repo = makeRepo();
|
|
380
|
+
fs.writeFileSync(path.join(repo, 'pending.txt'), 'pending\n');
|
|
381
|
+
const { ctx } = makeCtx(repo);
|
|
382
|
+
const result = await tools.get('worktree_create').execute(
|
|
383
|
+
'call-copy-principal',
|
|
384
|
+
{ branch: 'feat/copy-principal', odd: 'copy-principal', copy_changes: true },
|
|
385
|
+
undefined,
|
|
386
|
+
undefined,
|
|
387
|
+
ctx,
|
|
388
|
+
);
|
|
389
|
+
assert.notEqual(result.isError, true, resultText(result));
|
|
390
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'copy-principal');
|
|
391
|
+
assert.equal(fs.readFileSync(path.join(target, 'pending.txt'), 'utf8'), 'pending\n', 'the principal\u2019s uncommitted file travelled');
|
|
392
|
+
assert.match(resultText(result), /^copy_changes: 1 changes copied$/m);
|
|
393
|
+
assert.equal(fs.readFileSync(path.join(repo, 'pending.txt'), 'utf8'), 'pending\n', 'the source checkout keeps its change');
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
test('copy_changes carries the calling checkout\u2019s changes and never the principal\u2019s', async () => {
|
|
397
|
+
const repo = makeRepo();
|
|
398
|
+
const calling = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'calling');
|
|
399
|
+
fs.mkdirSync(path.dirname(calling), { recursive: true });
|
|
400
|
+
git(repo, ['worktree', 'add', '-b', 'feat/calling', calling]);
|
|
401
|
+
fs.writeFileSync(path.join(repo, 'principal-only.txt'), 'principal\n');
|
|
402
|
+
fs.writeFileSync(path.join(calling, 'calling-only.txt'), 'calling\n');
|
|
403
|
+
const { ctx } = makeCtx(calling);
|
|
404
|
+
const result = await tools.get('worktree_create').execute(
|
|
405
|
+
'call-copy-calling',
|
|
406
|
+
{ branch: 'feat/copy-calling', odd: 'copy-calling', copy_changes: true },
|
|
407
|
+
undefined,
|
|
408
|
+
undefined,
|
|
409
|
+
ctx,
|
|
410
|
+
);
|
|
411
|
+
assert.notEqual(result.isError, true, resultText(result));
|
|
412
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'copy-calling');
|
|
413
|
+
assert.equal(fs.readFileSync(path.join(target, 'calling-only.txt'), 'utf8'), 'calling\n', 'the calling checkout\u2019s uncommitted file travelled');
|
|
414
|
+
assert.equal(
|
|
415
|
+
fs.existsSync(path.join(target, 'principal-only.txt')),
|
|
416
|
+
false,
|
|
417
|
+
'the principal\u2019s uncommitted file stays where it belongs',
|
|
418
|
+
);
|
|
419
|
+
assert.equal(fs.readFileSync(path.join(calling, 'calling-only.txt'), 'utf8'), 'calling\n', 'the calling checkout keeps its change');
|
|
420
|
+
assert.equal(fs.readFileSync(path.join(repo, 'principal-only.txt'), 'utf8'), 'principal\n', 'the principal keeps its change');
|
|
279
421
|
});
|
|
280
422
|
});
|
|
281
423
|
|
|
282
|
-
describe('
|
|
424
|
+
describe('the shared close the panel deletion drives', () => {
|
|
283
425
|
test('removes the checkout and keeps the branch', async () => {
|
|
284
426
|
const repo = makeRepo();
|
|
285
427
|
const { ctx } = makeCtx(repo);
|
|
286
428
|
const created = await tools.get('worktree_create').execute(
|
|
287
429
|
'call-7',
|
|
288
|
-
{ branch: 'feat/close-me',
|
|
430
|
+
{ branch: 'feat/close-me', odd: 'close-me' },
|
|
289
431
|
undefined,
|
|
290
432
|
undefined,
|
|
291
433
|
ctx,
|
|
292
434
|
);
|
|
293
435
|
assert.notEqual(created.isError, true, resultText(created));
|
|
294
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
436
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'close-me');
|
|
295
437
|
|
|
296
|
-
const closed = await
|
|
438
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-close-me' }, ctx);
|
|
297
439
|
assert.notEqual(closed.isError, true, resultText(closed));
|
|
298
440
|
assert.equal(
|
|
299
441
|
resultText(closed),
|
|
300
|
-
|
|
442
|
+
'removed: feat-close-me · feat/close-me\nbranch kept',
|
|
443
|
+
'the close reports the removal and the kept branch in its own words',
|
|
444
|
+
);
|
|
445
|
+
assert.deepEqual(
|
|
446
|
+
{ path: closed.details.path, branch: closed.details.branch, removed: closed.details.removed, branchKept: closed.details.branchKept },
|
|
447
|
+
{ path: target, branch: 'feat/close-me', removed: true, branchKept: true },
|
|
301
448
|
);
|
|
302
449
|
assert.equal(fs.existsSync(target), false, 'the checkout is gone');
|
|
303
450
|
assert.equal(listWorktreePaths(repo).includes(target), false);
|
|
304
451
|
assert.ok(branches(repo).includes('feat/close-me'), 'the branch is kept');
|
|
305
452
|
|
|
306
453
|
const listed = await tools.get('worktree_list').execute('call-9', {}, undefined, undefined, ctx);
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
454
|
+
// S3: the listing writes nothing and there is no record to go stale — a directory
|
|
455
|
+
// that does not exist is simply not listed.
|
|
456
|
+
assert.deepEqual(resultText(listed).split('\n'), [
|
|
457
|
+
`project: ${path.basename(repo)}`,
|
|
458
|
+
`path: ${fs.realpathSync(repo)}`,
|
|
459
|
+
`base: main@${shortHead(repo)}`,
|
|
460
|
+
]);
|
|
311
461
|
});
|
|
312
462
|
|
|
313
463
|
test('an unknown name is refused and leaves the repository untouched', async () => {
|
|
314
464
|
const repo = makeRepo();
|
|
315
465
|
const { ctx } = makeCtx(repo);
|
|
316
|
-
const result = await
|
|
466
|
+
const result = await extensionMod.executeWorktreeClose({ name: 'nope' }, ctx);
|
|
317
467
|
assert.equal(result.isError, true);
|
|
318
|
-
assert.equal(
|
|
468
|
+
assert.equal(
|
|
469
|
+
resultText(result),
|
|
470
|
+
`no registered worktree for "nope": closest worktrees: 'main' (branch 'main') at ${fs.realpathSync(repo)}`,
|
|
471
|
+
);
|
|
319
472
|
assert.equal(listWorktreePaths(repo).length, 1);
|
|
320
473
|
});
|
|
321
474
|
|
|
@@ -325,12 +478,12 @@ describe('worktree_delete', () => {
|
|
|
325
478
|
test('another live Gentle Shell session in the target refuses the close', async () => {
|
|
326
479
|
const repo = makeRepo();
|
|
327
480
|
const { ctx } = makeCtx(repo);
|
|
328
|
-
const created = await tools.get('worktree_create').execute('call-s1', { branch: 'feat/busy',
|
|
481
|
+
const created = await tools.get('worktree_create').execute('call-s1', { branch: 'feat/busy', odd: 'busy' }, undefined, undefined, ctx);
|
|
329
482
|
assert.notEqual(created.isError, true, resultText(created));
|
|
330
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
483
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'busy');
|
|
331
484
|
const sessionHash = publishSession({ sessionId: 'worker-9', label: 'Worker', workspace: target });
|
|
332
485
|
|
|
333
|
-
const closed = await
|
|
486
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-busy' }, ctx);
|
|
334
487
|
assert.equal(closed.isError, true, 'a live session blocks the close');
|
|
335
488
|
const text = resultText(closed);
|
|
336
489
|
assert.match(text, /working in that checkout/);
|
|
@@ -343,19 +496,19 @@ describe('worktree_delete', () => {
|
|
|
343
496
|
assert.ok(listWorktreePaths(repo).includes(target), 'git still knows the checkout');
|
|
344
497
|
assert.ok(branches(repo).includes('feat/busy'), 'the branch is untouched');
|
|
345
498
|
const listed = await tools.get('worktree_list').execute('call-s3', {}, undefined, undefined, ctx);
|
|
346
|
-
assert.equal(resultText(listed).split('\n').length,
|
|
499
|
+
assert.equal(resultText(listed).split('\n').length, 4, 'the registry row is kept and still listed');
|
|
347
500
|
});
|
|
348
501
|
|
|
349
502
|
test('this session\u2019s own checkout is refused with a warp instruction, never auto-warped', async () => {
|
|
350
503
|
const repo = makeRepo();
|
|
351
504
|
const { ctx: creator } = makeCtx(repo);
|
|
352
|
-
const created = await tools.get('worktree_create').execute('call-s4', { branch: 'feat/mine',
|
|
505
|
+
const created = await tools.get('worktree_create').execute('call-s4', { branch: 'feat/mine', odd: 'mine' }, undefined, undefined, creator);
|
|
353
506
|
assert.notEqual(created.isError, true, resultText(created));
|
|
354
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
507
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'mine');
|
|
355
508
|
// The session now STANDS in the checkout: no presence record is needed for
|
|
356
509
|
// the deterministic cwd check to catch it.
|
|
357
510
|
const { ctx } = makeCtx(target);
|
|
358
|
-
const closed = await
|
|
511
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-mine' }, ctx);
|
|
359
512
|
assert.equal(closed.isError, true);
|
|
360
513
|
const text = resultText(closed);
|
|
361
514
|
assert.match(text, /this session is working in that checkout/);
|
|
@@ -369,11 +522,11 @@ describe('worktree_delete', () => {
|
|
|
369
522
|
test('a blocked close never asks for approval', async () => {
|
|
370
523
|
const repo = makeRepo();
|
|
371
524
|
const { ctx: creator } = makeCtx(repo);
|
|
372
|
-
await tools.get('worktree_create').execute('call-s6', { branch: 'feat/blocked-ui',
|
|
373
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
525
|
+
await tools.get('worktree_create').execute('call-s6', { branch: 'feat/blocked-ui', odd: 'blocked-ui' }, undefined, undefined, creator);
|
|
526
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'blocked-ui');
|
|
374
527
|
publishSession({ sessionId: 'ui-worker', label: 'UI Worker', workspace: target, incarnationIndex: 2 });
|
|
375
528
|
const { ctx, confirmations } = makeUiCtx(repo);
|
|
376
|
-
const closed = await
|
|
529
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat/blocked-ui' }, ctx);
|
|
377
530
|
assert.equal(closed.isError, true);
|
|
378
531
|
assert.equal(confirmations.length, 0, 'the session check runs before the approval question');
|
|
379
532
|
assert.ok(fs.existsSync(target));
|
|
@@ -382,10 +535,10 @@ describe('worktree_delete', () => {
|
|
|
382
535
|
test('a live session in another checkout does not block', async () => {
|
|
383
536
|
const repo = makeRepo();
|
|
384
537
|
const { ctx } = makeCtx(repo);
|
|
385
|
-
await tools.get('worktree_create').execute('call-s8', { branch: 'feat/free',
|
|
386
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
538
|
+
await tools.get('worktree_create').execute('call-s8', { branch: 'feat/free', odd: 'free' }, undefined, undefined, ctx);
|
|
539
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'free');
|
|
387
540
|
publishSession({ sessionId: 'other-worker', label: 'Other', workspace: repo, incarnationIndex: 3 });
|
|
388
|
-
const closed = await
|
|
541
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-free' }, ctx);
|
|
389
542
|
assert.notEqual(closed.isError, true, resultText(closed));
|
|
390
543
|
assert.equal(fs.existsSync(target), false);
|
|
391
544
|
});
|
|
@@ -393,12 +546,12 @@ describe('worktree_delete', () => {
|
|
|
393
546
|
test('the refusal names the RAW session id joined from the transport registry', async () => {
|
|
394
547
|
const repo = makeRepo();
|
|
395
548
|
const { ctx } = makeCtx(repo);
|
|
396
|
-
await tools.get('worktree_create').execute('call-s12', { branch: 'feat/joined',
|
|
397
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
549
|
+
await tools.get('worktree_create').execute('call-s12', { branch: 'feat/joined', odd: 'joined' }, undefined, undefined, ctx);
|
|
550
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'joined');
|
|
398
551
|
const sessionHash = publishSession({ sessionId: 'raw-worker-9', label: 'Raw', workspace: target, incarnationIndex: 7 });
|
|
399
552
|
publishTransport({ sessionId: 'raw-worker-9' });
|
|
400
553
|
|
|
401
|
-
const closed = await
|
|
554
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-joined' }, ctx);
|
|
402
555
|
assert.equal(closed.isError, true);
|
|
403
556
|
const text = resultText(closed);
|
|
404
557
|
assert.ok(text.includes('id raw-worker-9'), text);
|
|
@@ -411,11 +564,11 @@ describe('worktree_delete', () => {
|
|
|
411
564
|
test('without a transport record the refusal discloses that the id could not be resolved', async () => {
|
|
412
565
|
const repo = makeRepo();
|
|
413
566
|
const { ctx } = makeCtx(repo);
|
|
414
|
-
await tools.get('worktree_create').execute('call-s14', { branch: 'feat/unjoined',
|
|
415
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
567
|
+
await tools.get('worktree_create').execute('call-s14', { branch: 'feat/unjoined', odd: 'unjoined' }, undefined, undefined, ctx);
|
|
568
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'unjoined');
|
|
416
569
|
const sessionHash = publishSession({ sessionId: 'unjoined-worker', label: 'Unjoined', workspace: target, incarnationIndex: 8 });
|
|
417
570
|
|
|
418
|
-
const closed = await
|
|
571
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-unjoined' }, ctx);
|
|
419
572
|
assert.equal(closed.isError, true);
|
|
420
573
|
const text = resultText(closed);
|
|
421
574
|
assert.ok(text.includes(sessionHash.slice(0, 12)), text);
|
|
@@ -427,32 +580,263 @@ describe('worktree_delete', () => {
|
|
|
427
580
|
test('live-but-unattributable evidence is disclosed in the close output and never blocks', async () => {
|
|
428
581
|
const repo = makeRepo();
|
|
429
582
|
const { ctx } = makeCtx(repo);
|
|
430
|
-
await tools.get('worktree_create').execute('call-s16', { branch: 'feat/advisory',
|
|
431
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
583
|
+
await tools.get('worktree_create').execute('call-s16', { branch: 'feat/advisory', odd: 'advisory' }, undefined, undefined, ctx);
|
|
584
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'advisory');
|
|
432
585
|
publishSession({ sessionId: 'legacy-peer', label: 'Legacy', workspace: null, heartbeat: Date.now(), incarnationIndex: 9, discovery: false });
|
|
433
586
|
|
|
434
|
-
const closed = await
|
|
587
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-advisory' }, ctx);
|
|
435
588
|
assert.notEqual(closed.isError, true, resultText(closed));
|
|
436
|
-
assert.
|
|
437
|
-
|
|
589
|
+
assert.deepEqual(
|
|
590
|
+
closed.details.warnings.filter((warning) => /published no workspace|best effort/.test(warning)).length,
|
|
591
|
+
closed.details.warnings.filter((warning) => /published no workspace/.test(warning)).length,
|
|
592
|
+
`every caveat says it is best effort: ${JSON.stringify(closed.details.warnings)}`,
|
|
593
|
+
);
|
|
594
|
+
assert.ok(closed.details.warnings.some((warning) => /published no workspace/.test(warning)), JSON.stringify(closed.details.warnings));
|
|
438
595
|
assert.equal(fs.existsSync(target), false, 'the unattributable record does not block removal');
|
|
439
596
|
});
|
|
440
597
|
|
|
441
598
|
test('a stale record is disclosed as best effort and does not block', async () => {
|
|
442
599
|
const repo = makeRepo();
|
|
443
600
|
const { ctx } = makeCtx(repo);
|
|
444
|
-
await tools.get('worktree_create').execute('call-s10', { branch: 'feat/stale',
|
|
445
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
601
|
+
await tools.get('worktree_create').execute('call-s10', { branch: 'feat/stale', odd: 'stale' }, undefined, undefined, ctx);
|
|
602
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'stale');
|
|
446
603
|
publishSession({
|
|
447
604
|
sessionId: 'crashed-worker', label: 'Crashed', workspace: target,
|
|
448
605
|
heartbeat: Date.now() - 10 * 60 * 1000, incarnationIndex: 4,
|
|
449
606
|
});
|
|
450
|
-
const closed = await
|
|
607
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-stale' }, ctx);
|
|
451
608
|
assert.notEqual(closed.isError, true, resultText(closed));
|
|
452
|
-
const
|
|
453
|
-
assert.
|
|
454
|
-
assert.
|
|
609
|
+
const caveats = closed.details.warnings || [];
|
|
610
|
+
assert.ok(caveats.some((warning) => /stale Gentle Shell presence record ignored/.test(warning)), JSON.stringify(caveats));
|
|
611
|
+
assert.ok(caveats.some((warning) => /best effort/.test(warning)), JSON.stringify(caveats));
|
|
455
612
|
assert.equal(fs.existsSync(target), false);
|
|
456
613
|
assert.ok(branches(repo).includes('feat/stale'), 'the branch is kept');
|
|
457
614
|
});
|
|
458
615
|
});
|
|
616
|
+
|
|
617
|
+
// ---------------------------------------------------------------------------
|
|
618
|
+
// S4/S22: the create starts the setup chain on this package's own tracked task.
|
|
619
|
+
// The tool returns in milliseconds, the record already says `running`, and the
|
|
620
|
+
// ported table's command finishes afterwards. The tool front never notifies a UI
|
|
621
|
+
// its call did not ask for.
|
|
622
|
+
// ---------------------------------------------------------------------------
|
|
623
|
+
describe('the create starts its setup behind the answer and persists no state', { concurrency: false }, () => {
|
|
624
|
+
function binWith(name, script) {
|
|
625
|
+
const dir = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-wt-bin-')));
|
|
626
|
+
fs.writeFileSync(path.join(dir, name), script, { mode: 0o755 });
|
|
627
|
+
return dir;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
test('a lockfile starts the ported install, and the create returns before it finishes', async () => {
|
|
631
|
+
const repo = makeRepo();
|
|
632
|
+
const markerDir = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-wt-marker-')));
|
|
633
|
+
const argvLog = path.join(markerDir, 'argv.log');
|
|
634
|
+
const doneLog = path.join(markerDir, 'done.log');
|
|
635
|
+
fs.writeFileSync(path.join(repo, 'package-lock.json'), '{}\n');
|
|
636
|
+
git(repo, ['add', 'package-lock.json']);
|
|
637
|
+
git(repo, ['commit', '-m', 'lockfile']);
|
|
638
|
+
// The shim records its argv at once, then sleeps, so "finished" is an
|
|
639
|
+
// observation about the child, not about a string that happens to match.
|
|
640
|
+
const bin = binWith('npm', [
|
|
641
|
+
'#!/bin/sh',
|
|
642
|
+
`printf '%s\\n' "$*" >> '${argvLog}'`,
|
|
643
|
+
"printf 'npm starting\\n'",
|
|
644
|
+
'sleep 1',
|
|
645
|
+
"printf 'npm done\\n'",
|
|
646
|
+
`printf '%s\\n' "$*" >> '${doneLog}'`,
|
|
647
|
+
'',
|
|
648
|
+
].join('\n'));
|
|
649
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'setup');
|
|
650
|
+
const savedPath = process.env.PATH;
|
|
651
|
+
process.env.PATH = `${bin}${path.delimiter}${savedPath}`;
|
|
652
|
+
try {
|
|
653
|
+
const { ctx, notifications } = makeCtx(repo);
|
|
654
|
+
const created = await tools.get('worktree_create').execute('setup-1', { branch: 'feat/setup', odd: 'setup' }, undefined, undefined, ctx);
|
|
655
|
+
assert.notEqual(created.isError, true, resultText(created));
|
|
656
|
+
|
|
657
|
+
// S1: the create prints no setup line at all; at call time it cannot know.
|
|
658
|
+
assert.doesNotMatch(resultText(created), /setup:/, 'the create reports no setup state');
|
|
659
|
+
assert.equal('setup' in created.details, false);
|
|
660
|
+
|
|
661
|
+
// Observed ordering: the command has NOT finished when the call returns.
|
|
662
|
+
assert.equal(fs.existsSync(doneLog), false, 'the install was still running when the create returned');
|
|
663
|
+
|
|
664
|
+
// S8: the chain still runs, and its log lands under the system temp
|
|
665
|
+
// directory — never inside either checkout — while the clone keeps no record.
|
|
666
|
+
const deadline = Date.now() + 10_000;
|
|
667
|
+
while (!fs.existsSync(doneLog) && Date.now() < deadline) {
|
|
668
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
669
|
+
}
|
|
670
|
+
assert.equal(fs.existsSync(doneLog), true, 'the install finished in the background');
|
|
671
|
+
assert.deepEqual(fs.readFileSync(argvLog, 'utf8').trim().split('\n'), ['ci'], 'one npm invocation, argv ci');
|
|
672
|
+
assert.equal(fs.readFileSync(doneLog, 'utf8').trim(), 'ci', 'the command completed exactly once');
|
|
673
|
+
const setupLogs = fs.readdirSync(os.tmpdir()).filter((name) => name.startsWith('odd-worktree-setup-'));
|
|
674
|
+
assert.ok(setupLogs.length > 0, 'the task wrote its log under the system temp directory');
|
|
675
|
+
for (const name of setupLogs) {
|
|
676
|
+
const logPath = path.join(os.tmpdir(), name);
|
|
677
|
+
assert.equal(fs.readFileSync(path.join(logPath, 'step-1.log'), 'utf8').includes('npm done'), true, 'the log carries the command output');
|
|
678
|
+
assert.equal(logPath.startsWith(`${repo}${path.sep}`), false, 'the log is never inside the main checkout');
|
|
679
|
+
assert.equal(logPath.startsWith(`${target}${path.sep}`), false, 'the log is never inside the created checkout');
|
|
680
|
+
track(logPath);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// S3/S4: nothing about the chain is stored anywhere in the clone.
|
|
684
|
+
assert.equal(fs.existsSync(cloneDocument(repo)), false, 'no setup state is persisted');
|
|
685
|
+
assert.deepEqual(notifications, [], 'the tool front never notifies a UI its call did not ask for');
|
|
686
|
+
} finally {
|
|
687
|
+
process.env.PATH = savedPath;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
test('a root with no lockfile starts nothing and prints no setup line', async () => {
|
|
692
|
+
const repo = makeRepo();
|
|
693
|
+
const { ctx } = makeCtx(repo);
|
|
694
|
+
const created = await tools.get('worktree_create').execute('setup-2', { branch: 'feat/plain', odd: 'plain' }, undefined, undefined, ctx);
|
|
695
|
+
assert.notEqual(created.isError, true, resultText(created));
|
|
696
|
+
assert.doesNotMatch(resultText(created), /setup/, 'a skipped chain is not reported by the create either');
|
|
697
|
+
assert.equal(fs.existsSync(cloneDocument(repo)), false, 'and nothing is stored to remember the skip');
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
// ---- S5: the two tools draw their own cards ----
|
|
702
|
+
//
|
|
703
|
+
// The card module and the substrate have their own suites; this block proves the
|
|
704
|
+
// WIRING. The registered `worktree_create` and `worktree_list` definitions the
|
|
705
|
+
// host received must carry both render hooks, and each hook must draw its own
|
|
706
|
+
// tool's card at the requested width. Measurement is the host's
|
|
707
|
+
// `@earendil-works/pi-tui` seam, injected here exactly as the extension injects
|
|
708
|
+
// it at render time. With no metrics the same hooks answer plain text: a host
|
|
709
|
+
// without that package still shows the tool's own answer and never throws.
|
|
710
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
711
|
+
const stripAnsi = (value) => String(value).replace(ANSI, '');
|
|
712
|
+
const cardColumns = (value) => [...stripAnsi(value)].length;
|
|
713
|
+
|
|
714
|
+
// The same plain-ASCII text seam tools/worktree-cards.test.js injects: this
|
|
715
|
+
// package ships no node_modules, so measurement is always a seam.
|
|
716
|
+
const cardMetrics = {
|
|
717
|
+
visibleWidth: (value) => cardColumns(value),
|
|
718
|
+
truncateToWidth(value, width, ellipsis = '') {
|
|
719
|
+
if (width <= 0) return '';
|
|
720
|
+
const chars = [...stripAnsi(value)];
|
|
721
|
+
if (chars.length <= width) return value;
|
|
722
|
+
const tail = ellipsis ?? '';
|
|
723
|
+
return chars.slice(0, Math.max(0, width - [...tail].length)).join('') + tail;
|
|
724
|
+
},
|
|
725
|
+
wrapTextWithAnsi(value, width) {
|
|
726
|
+
const words = stripAnsi(value).split(' ');
|
|
727
|
+
if (width <= 0) return [stripAnsi(value)];
|
|
728
|
+
const lines = [];
|
|
729
|
+
let current = '';
|
|
730
|
+
for (const word of words) {
|
|
731
|
+
const candidate = current === '' ? word : `${current} ${word}`;
|
|
732
|
+
if ([...candidate].length <= width) {
|
|
733
|
+
current = candidate;
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
if (current !== '') {
|
|
737
|
+
lines.push(current);
|
|
738
|
+
current = '';
|
|
739
|
+
}
|
|
740
|
+
if ([...word].length <= width) {
|
|
741
|
+
current = word;
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
const rest = [...word];
|
|
745
|
+
while (rest.length > width) lines.push(rest.splice(0, width).join(''));
|
|
746
|
+
current = rest.join('');
|
|
747
|
+
}
|
|
748
|
+
lines.push(current);
|
|
749
|
+
return lines;
|
|
750
|
+
},
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
const CARD_THEME = { fg: (_role, value) => value };
|
|
754
|
+
|
|
755
|
+
function assertCardFrame(rows, width) {
|
|
756
|
+
assert.ok(rows.length >= 2, 'a card draws at least a top and a bottom row');
|
|
757
|
+
for (const row of rows) {
|
|
758
|
+
assert.equal(cardColumns(row), width, `"${stripAnsi(row)}" is not ${width} columns wide`);
|
|
759
|
+
}
|
|
760
|
+
assert.ok(stripAnsi(rows[0]).startsWith('╭'), 'the card opens with a rounded frame');
|
|
761
|
+
assert.ok(stripAnsi(rows[rows.length - 1]).startsWith('╰'), 'the card closes with a rounded frame');
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function assertResultFrame(rows, width) {
|
|
765
|
+
for (const row of rows) {
|
|
766
|
+
assert.equal(cardColumns(row), width, `"${stripAnsi(row)}" is not ${width} columns wide`);
|
|
767
|
+
}
|
|
768
|
+
assert.ok(stripAnsi(rows[0]).startsWith('│'), 'the result body sits inside the frame the call opened');
|
|
769
|
+
assert.ok(stripAnsi(rows[rows.length - 1]).startsWith('╰'), 'the result closes the card');
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
describe('the two tools draw their own card (S5)', { concurrency: false }, () => {
|
|
773
|
+
after(() => { extensionMod.setWorktreeToolCardMetrics(undefined); });
|
|
774
|
+
|
|
775
|
+
test('both registered definitions carry the call and result hooks', () => {
|
|
776
|
+
for (const name of ['worktree_create', 'worktree_list']) {
|
|
777
|
+
const tool = tools.get(name);
|
|
778
|
+
assert.equal(typeof tool.renderCall, 'function', `${name} renders its call`);
|
|
779
|
+
assert.equal(typeof tool.renderResult, 'function', `${name} renders its result`);
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
test('worktree_create renders its call and result as a framed card', async () => {
|
|
784
|
+
const repo = makeRepo();
|
|
785
|
+
const { ctx } = makeCtx(repo);
|
|
786
|
+
const result = await tools.get('worktree_create').execute('card-create', { branch: 'feat/card', odd: 'card' }, undefined, undefined, ctx);
|
|
787
|
+
assert.notEqual(result.isError, true, resultText(result));
|
|
788
|
+
|
|
789
|
+
extensionMod.setWorktreeToolCardMetrics(cardMetrics);
|
|
790
|
+
const tool = tools.get('worktree_create');
|
|
791
|
+
const state = {};
|
|
792
|
+
const callRows = tool.renderCall({ branch: 'feat/card' }, CARD_THEME, { state }).render(60);
|
|
793
|
+
assertCardFrame(callRows, 60);
|
|
794
|
+
assert.match(stripAnsi(callRows[0]), /worktree create/);
|
|
795
|
+
assert.match(stripAnsi(callRows[0]), /feat\/card/);
|
|
796
|
+
|
|
797
|
+
const resultRows = tool.renderResult(result, { expanded: false }, CARD_THEME, { state, durationMs: 1234 }).render(60);
|
|
798
|
+
assertResultFrame(resultRows, 60);
|
|
799
|
+
assert.ok(
|
|
800
|
+
stripAnsi(resultRows.join('\n')).includes('worktree created:'),
|
|
801
|
+
'the card body is the tool’s own answer, never a reformat',
|
|
802
|
+
);
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
test('worktree_list renders its call and result as a framed card', async () => {
|
|
806
|
+
const repo = makeRepo();
|
|
807
|
+
const { ctx } = makeCtx(repo);
|
|
808
|
+
const result = await tools.get('worktree_list').execute('card-list', {}, undefined, undefined, ctx);
|
|
809
|
+
assert.notEqual(result.isError, true, resultText(result));
|
|
810
|
+
|
|
811
|
+
extensionMod.setWorktreeToolCardMetrics(cardMetrics);
|
|
812
|
+
const tool = tools.get('worktree_list');
|
|
813
|
+
const state = {};
|
|
814
|
+
const callRows = tool.renderCall({}, CARD_THEME, { state }).render(60);
|
|
815
|
+
assertCardFrame(callRows, 60);
|
|
816
|
+
assert.match(stripAnsi(callRows[0]), /worktree list/);
|
|
817
|
+
|
|
818
|
+
const resultRows = tool.renderResult(result, { expanded: true }, CARD_THEME, { state, durationMs: 250 }).render(60);
|
|
819
|
+
assertResultFrame(resultRows, 60);
|
|
820
|
+
assert.ok(
|
|
821
|
+
stripAnsi(resultRows.join('\n')).includes(`project: ${path.basename(repo)}`),
|
|
822
|
+
'the card body is the tool’s own answer, never a reformat',
|
|
823
|
+
);
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
test('without host metrics both hooks fall back to plain text and never throw', () => {
|
|
827
|
+
extensionMod.setWorktreeToolCardMetrics(null);
|
|
828
|
+
const tool = tools.get('worktree_list');
|
|
829
|
+
assert.deepEqual(
|
|
830
|
+
tool.renderCall({ all: true }, CARD_THEME, { state: {} }).render(60),
|
|
831
|
+
['worktree list all'],
|
|
832
|
+
'the plain call names the tool and its one argument',
|
|
833
|
+
);
|
|
834
|
+
const result = { content: [{ type: 'text', text: 'project: demo\npath: /tmp/demo' }], details: {} };
|
|
835
|
+
assert.deepEqual(
|
|
836
|
+
tool.renderResult(result, { expanded: false }, CARD_THEME, { state: {} }).render(60),
|
|
837
|
+
['project: demo', 'path: /tmp/demo'],
|
|
838
|
+
'the plain result IS the tool text',
|
|
839
|
+
);
|
|
840
|
+
});
|
|
841
|
+
});
|
|
842
|
+
|