pi-odd-worktree 2.1.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 -319
- package/extensions/odd-worktree-tools.ts +4145 -2529
- 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 -712
- 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 +2565 -309
- 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 +419 -199
- 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');
|
|
@@ -12,7 +12,7 @@ const os = require('node:os');
|
|
|
12
12
|
const path = require('node:path');
|
|
13
13
|
const { spawnSync } = require('node:child_process');
|
|
14
14
|
const { pathToFileURL } = require('node:url');
|
|
15
|
-
const { LIB_DIR, stubbedSource } = require('./fixtures/load-extension.js');
|
|
15
|
+
const { LIB_DIR, stubbedSource, installDefaultBridge } = require('./fixtures/load-extension.js');
|
|
16
16
|
|
|
17
17
|
const scratch = [];
|
|
18
18
|
function track(dir) {
|
|
@@ -31,12 +31,9 @@ after(() => {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
//
|
|
34
|
+
// An empty bin directory ahead of PATH keeps a create off the developer's
|
|
35
35
|
// PATH-dependent tooling; the rest of PATH is preserved so git still resolves.
|
|
36
36
|
const HOOK_BIN = path.resolve(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-wt-hookbin-'))));
|
|
37
|
-
fs.writeFileSync(path.join(HOOK_BIN, 'codegraph'), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
|
38
|
-
// No Herdr workspace can be created from this path: it does not exist.
|
|
39
|
-
const NO_HERDR = path.join(os.tmpdir(), 'odd-worktree-no-such-herdr-binary');
|
|
40
37
|
|
|
41
38
|
function git(cwd, args) {
|
|
42
39
|
const out = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
@@ -87,6 +84,17 @@ function branches(root) {
|
|
|
87
84
|
return git(root, ['branch', '--format=%(refname:short)']).split('\n').filter(Boolean).sort();
|
|
88
85
|
}
|
|
89
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
|
+
|
|
90
98
|
// S7/S8/S9: the active-session guard reads Gentle Shell's published presence
|
|
91
99
|
// store. Pin it to a throwaway agent home so no test can see (or be blocked by)
|
|
92
100
|
// the developer's real sessions, and publish synthetic records into it.
|
|
@@ -172,7 +180,6 @@ let tools;
|
|
|
172
180
|
let extensionMod;
|
|
173
181
|
let extensionHooks;
|
|
174
182
|
before(async () => {
|
|
175
|
-
process.env.HERDR_BIN_PATH = NO_HERDR;
|
|
176
183
|
process.env.GENTLE_WORKTREE_THREAD = 'thread-1';
|
|
177
184
|
process.env.PATH = `${HOOK_BIN}${path.delimiter}${savedEnv.PATH || ''}`;
|
|
178
185
|
delete process.env.GENTLE_PI_AGENT_HOME;
|
|
@@ -180,12 +187,15 @@ before(async () => {
|
|
|
180
187
|
({ tools, mod: extensionMod, hooks: extensionHooks } = await loadExtensionWithModule({}));
|
|
181
188
|
});
|
|
182
189
|
|
|
183
|
-
// The create is instant on BOTH fronts, and its
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
//
|
|
187
|
-
// the shared fixture — and keeps the module namespace beside the registrations.
|
|
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.
|
|
188
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();
|
|
189
199
|
process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
|
|
190
200
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'odd-wt-ext-'));
|
|
191
201
|
try {
|
|
@@ -214,13 +224,15 @@ describe('worktree_list', () => {
|
|
|
214
224
|
const { ctx } = makeCtx(repo);
|
|
215
225
|
const result = await tools.get('worktree_list').execute('call-1', {}, undefined, undefined, ctx);
|
|
216
226
|
assert.notEqual(result.isError, true, resultText(result));
|
|
217
|
-
assert.
|
|
218
|
-
|
|
219
|
-
`
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
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);
|
|
223
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');
|
|
224
236
|
});
|
|
225
237
|
|
|
226
238
|
test('a directory outside a repository is refused by the help text', async () => {
|
|
@@ -234,119 +246,229 @@ describe('worktree_list', () => {
|
|
|
234
246
|
|
|
235
247
|
describe('worktree_create', () => {
|
|
236
248
|
for (const existing of [false, true]) {
|
|
237
|
-
test(`
|
|
249
|
+
test(`reports branchState ${existing ? 'existing' : 'created'} for a ${existing ? 'pre-existing' : 'new'} branch`, async () => {
|
|
238
250
|
const repo = makeRepo();
|
|
239
251
|
const branch = existing ? 'feat/existing' : 'feat/new';
|
|
240
252
|
if (existing) git(repo, ['branch', branch]);
|
|
241
|
-
const
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return original(bin, ...args);
|
|
247
|
-
};
|
|
248
|
-
try {
|
|
249
|
-
const { ctx } = makeCtx(repo);
|
|
250
|
-
const result = await tools.get('worktree_create').execute('no-herdr', { branch, changes: 'none' }, undefined, undefined, ctx);
|
|
251
|
-
assert.notEqual(result.isError, true, resultText(result));
|
|
252
|
-
assert.equal(result.details.branchCreated, !existing);
|
|
253
|
-
assert.ok(binaries.includes('git'));
|
|
254
|
-
assert.ok(!binaries.includes(NO_HERDR), `unexpected Herdr execution: ${binaries}`);
|
|
255
|
-
} finally {
|
|
256
|
-
gitLib.runArgvAsync = original;
|
|
257
|
-
}
|
|
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');
|
|
258
258
|
});
|
|
259
259
|
}
|
|
260
|
-
test('creates the checkout and
|
|
260
|
+
test('creates the checkout and writes nothing: the directory is the whole record', async () => {
|
|
261
261
|
const repo = makeRepo();
|
|
262
262
|
const { ctx } = makeCtx(repo);
|
|
263
263
|
const result = await tools.get('worktree_create').execute(
|
|
264
264
|
'call-3',
|
|
265
|
-
{ branch: 'feat/x',
|
|
265
|
+
{ branch: 'feat/x', odd: 'odd-x' },
|
|
266
266
|
undefined,
|
|
267
267
|
undefined,
|
|
268
268
|
ctx,
|
|
269
269
|
);
|
|
270
270
|
assert.notEqual(result.isError, true, resultText(result));
|
|
271
|
-
|
|
272
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
273
|
-
assert.
|
|
274
|
-
|
|
275
|
-
|
|
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');
|
|
276
281
|
assert.ok(fs.existsSync(target), 'the checkout exists on disk');
|
|
277
282
|
assert.ok(listWorktreePaths(repo).includes(target), 'git knows the checkout');
|
|
278
283
|
assert.ok(branches(repo).includes('feat/x'), 'the branch exists');
|
|
279
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
|
+
|
|
280
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);
|
|
281
307
|
assert.equal(
|
|
282
|
-
resultText(
|
|
283
|
-
|
|
308
|
+
resultText(result),
|
|
309
|
+
'invalid odd name: undefined\nodd must be a single path segment (letters, digits, dash, underscore, dot)',
|
|
284
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);
|
|
320
|
+
assert.equal(
|
|
321
|
+
resultText(result),
|
|
322
|
+
'invalid odd name: "a/b"\nodd must be a single path segment (letters, digits, dash, underscore, dot)',
|
|
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');
|
|
326
|
+
});
|
|
327
|
+
|
|
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
|
+
]);
|
|
285
347
|
});
|
|
286
348
|
|
|
287
|
-
test('refuses an
|
|
349
|
+
test('refuses an odd that is not one path segment, and writes nothing', async () => {
|
|
288
350
|
const repo = makeRepo();
|
|
289
351
|
const { ctx } = makeCtx(repo);
|
|
290
352
|
const before = { paths: listWorktreePaths(repo), branches: branches(repo) };
|
|
291
353
|
const result = await tools.get('worktree_create').execute(
|
|
292
354
|
'call-5',
|
|
293
|
-
{ branch: '
|
|
355
|
+
{ branch: 'feat/login', odd: '../escape' },
|
|
294
356
|
undefined,
|
|
295
357
|
undefined,
|
|
296
358
|
ctx,
|
|
297
359
|
);
|
|
298
360
|
assert.equal(result.isError, true);
|
|
299
|
-
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
|
+
);
|
|
300
365
|
assert.deepEqual({ paths: listWorktreePaths(repo), branches: branches(repo) }, before);
|
|
301
366
|
});
|
|
302
367
|
|
|
303
|
-
test('refuses
|
|
368
|
+
test('refuses the base branch as the worktree branch and writes nothing', async () => {
|
|
304
369
|
const repo = makeRepo();
|
|
305
370
|
const { ctx } = makeCtx(repo);
|
|
306
|
-
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);
|
|
307
373
|
assert.equal(result.isError, true);
|
|
308
|
-
assert.
|
|
309
|
-
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');
|
|
310
421
|
});
|
|
311
422
|
});
|
|
312
423
|
|
|
313
|
-
describe('
|
|
424
|
+
describe('the shared close the panel deletion drives', () => {
|
|
314
425
|
test('removes the checkout and keeps the branch', async () => {
|
|
315
426
|
const repo = makeRepo();
|
|
316
427
|
const { ctx } = makeCtx(repo);
|
|
317
428
|
const created = await tools.get('worktree_create').execute(
|
|
318
429
|
'call-7',
|
|
319
|
-
{ branch: 'feat/close-me',
|
|
430
|
+
{ branch: 'feat/close-me', odd: 'close-me' },
|
|
320
431
|
undefined,
|
|
321
432
|
undefined,
|
|
322
433
|
ctx,
|
|
323
434
|
);
|
|
324
435
|
assert.notEqual(created.isError, true, resultText(created));
|
|
325
|
-
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');
|
|
326
437
|
|
|
327
|
-
const closed = await
|
|
438
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-close-me' }, ctx);
|
|
328
439
|
assert.notEqual(closed.isError, true, resultText(closed));
|
|
329
440
|
assert.equal(
|
|
330
441
|
resultText(closed),
|
|
331
|
-
|
|
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 },
|
|
332
448
|
);
|
|
333
449
|
assert.equal(fs.existsSync(target), false, 'the checkout is gone');
|
|
334
450
|
assert.equal(listWorktreePaths(repo).includes(target), false);
|
|
335
451
|
assert.ok(branches(repo).includes('feat/close-me'), 'the branch is kept');
|
|
336
452
|
|
|
337
453
|
const listed = await tools.get('worktree_list').execute('call-9', {}, undefined, undefined, ctx);
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
+
]);
|
|
342
461
|
});
|
|
343
462
|
|
|
344
463
|
test('an unknown name is refused and leaves the repository untouched', async () => {
|
|
345
464
|
const repo = makeRepo();
|
|
346
465
|
const { ctx } = makeCtx(repo);
|
|
347
|
-
const result = await
|
|
466
|
+
const result = await extensionMod.executeWorktreeClose({ name: 'nope' }, ctx);
|
|
348
467
|
assert.equal(result.isError, true);
|
|
349
|
-
assert.equal(
|
|
468
|
+
assert.equal(
|
|
469
|
+
resultText(result),
|
|
470
|
+
`no registered worktree for "nope": closest worktrees: 'main' (branch 'main') at ${fs.realpathSync(repo)}`,
|
|
471
|
+
);
|
|
350
472
|
assert.equal(listWorktreePaths(repo).length, 1);
|
|
351
473
|
});
|
|
352
474
|
|
|
@@ -356,12 +478,12 @@ describe('worktree_delete', () => {
|
|
|
356
478
|
test('another live Gentle Shell session in the target refuses the close', async () => {
|
|
357
479
|
const repo = makeRepo();
|
|
358
480
|
const { ctx } = makeCtx(repo);
|
|
359
|
-
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);
|
|
360
482
|
assert.notEqual(created.isError, true, resultText(created));
|
|
361
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
483
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'busy');
|
|
362
484
|
const sessionHash = publishSession({ sessionId: 'worker-9', label: 'Worker', workspace: target });
|
|
363
485
|
|
|
364
|
-
const closed = await
|
|
486
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-busy' }, ctx);
|
|
365
487
|
assert.equal(closed.isError, true, 'a live session blocks the close');
|
|
366
488
|
const text = resultText(closed);
|
|
367
489
|
assert.match(text, /working in that checkout/);
|
|
@@ -374,19 +496,19 @@ describe('worktree_delete', () => {
|
|
|
374
496
|
assert.ok(listWorktreePaths(repo).includes(target), 'git still knows the checkout');
|
|
375
497
|
assert.ok(branches(repo).includes('feat/busy'), 'the branch is untouched');
|
|
376
498
|
const listed = await tools.get('worktree_list').execute('call-s3', {}, undefined, undefined, ctx);
|
|
377
|
-
assert.equal(resultText(listed).split('\n').length,
|
|
499
|
+
assert.equal(resultText(listed).split('\n').length, 4, 'the registry row is kept and still listed');
|
|
378
500
|
});
|
|
379
501
|
|
|
380
502
|
test('this session\u2019s own checkout is refused with a warp instruction, never auto-warped', async () => {
|
|
381
503
|
const repo = makeRepo();
|
|
382
504
|
const { ctx: creator } = makeCtx(repo);
|
|
383
|
-
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);
|
|
384
506
|
assert.notEqual(created.isError, true, resultText(created));
|
|
385
|
-
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, '
|
|
507
|
+
const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'mine');
|
|
386
508
|
// The session now STANDS in the checkout: no presence record is needed for
|
|
387
509
|
// the deterministic cwd check to catch it.
|
|
388
510
|
const { ctx } = makeCtx(target);
|
|
389
|
-
const closed = await
|
|
511
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-mine' }, ctx);
|
|
390
512
|
assert.equal(closed.isError, true);
|
|
391
513
|
const text = resultText(closed);
|
|
392
514
|
assert.match(text, /this session is working in that checkout/);
|
|
@@ -400,11 +522,11 @@ describe('worktree_delete', () => {
|
|
|
400
522
|
test('a blocked close never asks for approval', async () => {
|
|
401
523
|
const repo = makeRepo();
|
|
402
524
|
const { ctx: creator } = makeCtx(repo);
|
|
403
|
-
await tools.get('worktree_create').execute('call-s6', { branch: 'feat/blocked-ui',
|
|
404
|
-
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');
|
|
405
527
|
publishSession({ sessionId: 'ui-worker', label: 'UI Worker', workspace: target, incarnationIndex: 2 });
|
|
406
528
|
const { ctx, confirmations } = makeUiCtx(repo);
|
|
407
|
-
const closed = await
|
|
529
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat/blocked-ui' }, ctx);
|
|
408
530
|
assert.equal(closed.isError, true);
|
|
409
531
|
assert.equal(confirmations.length, 0, 'the session check runs before the approval question');
|
|
410
532
|
assert.ok(fs.existsSync(target));
|
|
@@ -413,10 +535,10 @@ describe('worktree_delete', () => {
|
|
|
413
535
|
test('a live session in another checkout does not block', async () => {
|
|
414
536
|
const repo = makeRepo();
|
|
415
537
|
const { ctx } = makeCtx(repo);
|
|
416
|
-
await tools.get('worktree_create').execute('call-s8', { branch: 'feat/free',
|
|
417
|
-
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');
|
|
418
540
|
publishSession({ sessionId: 'other-worker', label: 'Other', workspace: repo, incarnationIndex: 3 });
|
|
419
|
-
const closed = await
|
|
541
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-free' }, ctx);
|
|
420
542
|
assert.notEqual(closed.isError, true, resultText(closed));
|
|
421
543
|
assert.equal(fs.existsSync(target), false);
|
|
422
544
|
});
|
|
@@ -424,12 +546,12 @@ describe('worktree_delete', () => {
|
|
|
424
546
|
test('the refusal names the RAW session id joined from the transport registry', async () => {
|
|
425
547
|
const repo = makeRepo();
|
|
426
548
|
const { ctx } = makeCtx(repo);
|
|
427
|
-
await tools.get('worktree_create').execute('call-s12', { branch: 'feat/joined',
|
|
428
|
-
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');
|
|
429
551
|
const sessionHash = publishSession({ sessionId: 'raw-worker-9', label: 'Raw', workspace: target, incarnationIndex: 7 });
|
|
430
552
|
publishTransport({ sessionId: 'raw-worker-9' });
|
|
431
553
|
|
|
432
|
-
const closed = await
|
|
554
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-joined' }, ctx);
|
|
433
555
|
assert.equal(closed.isError, true);
|
|
434
556
|
const text = resultText(closed);
|
|
435
557
|
assert.ok(text.includes('id raw-worker-9'), text);
|
|
@@ -442,11 +564,11 @@ describe('worktree_delete', () => {
|
|
|
442
564
|
test('without a transport record the refusal discloses that the id could not be resolved', async () => {
|
|
443
565
|
const repo = makeRepo();
|
|
444
566
|
const { ctx } = makeCtx(repo);
|
|
445
|
-
await tools.get('worktree_create').execute('call-s14', { branch: 'feat/unjoined',
|
|
446
|
-
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');
|
|
447
569
|
const sessionHash = publishSession({ sessionId: 'unjoined-worker', label: 'Unjoined', workspace: target, incarnationIndex: 8 });
|
|
448
570
|
|
|
449
|
-
const closed = await
|
|
571
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-unjoined' }, ctx);
|
|
450
572
|
assert.equal(closed.isError, true);
|
|
451
573
|
const text = resultText(closed);
|
|
452
574
|
assert.ok(text.includes(sessionHash.slice(0, 12)), text);
|
|
@@ -458,165 +580,263 @@ describe('worktree_delete', () => {
|
|
|
458
580
|
test('live-but-unattributable evidence is disclosed in the close output and never blocks', async () => {
|
|
459
581
|
const repo = makeRepo();
|
|
460
582
|
const { ctx } = makeCtx(repo);
|
|
461
|
-
await tools.get('worktree_create').execute('call-s16', { branch: 'feat/advisory',
|
|
462
|
-
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');
|
|
463
585
|
publishSession({ sessionId: 'legacy-peer', label: 'Legacy', workspace: null, heartbeat: Date.now(), incarnationIndex: 9, discovery: false });
|
|
464
586
|
|
|
465
|
-
const closed = await
|
|
587
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-advisory' }, ctx);
|
|
466
588
|
assert.notEqual(closed.isError, true, resultText(closed));
|
|
467
|
-
assert.
|
|
468
|
-
|
|
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));
|
|
469
595
|
assert.equal(fs.existsSync(target), false, 'the unattributable record does not block removal');
|
|
470
596
|
});
|
|
471
597
|
|
|
472
598
|
test('a stale record is disclosed as best effort and does not block', async () => {
|
|
473
599
|
const repo = makeRepo();
|
|
474
600
|
const { ctx } = makeCtx(repo);
|
|
475
|
-
await tools.get('worktree_create').execute('call-s10', { branch: 'feat/stale',
|
|
476
|
-
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');
|
|
477
603
|
publishSession({
|
|
478
604
|
sessionId: 'crashed-worker', label: 'Crashed', workspace: target,
|
|
479
605
|
heartbeat: Date.now() - 10 * 60 * 1000, incarnationIndex: 4,
|
|
480
606
|
});
|
|
481
|
-
const closed = await
|
|
607
|
+
const closed = await extensionMod.executeWorktreeClose({ name: 'feat-stale' }, ctx);
|
|
482
608
|
assert.notEqual(closed.isError, true, resultText(closed));
|
|
483
|
-
const
|
|
484
|
-
assert.
|
|
485
|
-
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));
|
|
486
612
|
assert.equal(fs.existsSync(target), false);
|
|
487
613
|
assert.ok(branches(repo).includes('feat/stale'), 'the branch is kept');
|
|
488
614
|
});
|
|
489
615
|
});
|
|
490
616
|
|
|
491
617
|
// ---------------------------------------------------------------------------
|
|
492
|
-
//
|
|
493
|
-
//
|
|
494
|
-
//
|
|
495
|
-
//
|
|
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.
|
|
496
622
|
// ---------------------------------------------------------------------------
|
|
497
|
-
describe('
|
|
498
|
-
// A `codegraph` that is visibly SLOW: it records that it started, waits, then
|
|
499
|
-
// records that it finished. A create that awaited the setup could never return
|
|
500
|
-
// between the two lines.
|
|
501
|
-
function slowCodegraph(markerPath) {
|
|
502
|
-
const dir = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-wt-slowbin-')));
|
|
503
|
-
fs.writeFileSync(
|
|
504
|
-
path.join(dir, 'codegraph'),
|
|
505
|
-
`#!/bin/sh\nprintf 'started\\n' >> '${markerPath}'\nsleep 0.5\nprintf 'finished\\n' >> '${markerPath}'\n`,
|
|
506
|
-
{ mode: 0o755 },
|
|
507
|
-
);
|
|
508
|
-
return dir;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function markerFile() {
|
|
512
|
-
return path.join(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-wt-marker-'))), 'codegraph.log');
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
function readMarker(marker) {
|
|
516
|
-
return fs.existsSync(marker) ? fs.readFileSync(marker, 'utf8') : '';
|
|
517
|
-
}
|
|
518
|
-
|
|
623
|
+
describe('the create starts its setup behind the answer and persists no state', { concurrency: false }, () => {
|
|
519
624
|
function binWith(name, script) {
|
|
520
625
|
const dir = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-wt-bin-')));
|
|
521
626
|
fs.writeFileSync(path.join(dir, name), script, { mode: 0o755 });
|
|
522
627
|
return dir;
|
|
523
628
|
}
|
|
524
629
|
|
|
525
|
-
test('
|
|
630
|
+
test('a lockfile starts the ported install, and the create returns before it finishes', async () => {
|
|
526
631
|
const repo = makeRepo();
|
|
527
|
-
const
|
|
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');
|
|
528
650
|
const savedPath = process.env.PATH;
|
|
529
|
-
process.env.PATH = `${
|
|
651
|
+
process.env.PATH = `${bin}${path.delimiter}${savedPath}`;
|
|
530
652
|
try {
|
|
531
653
|
const { ctx, notifications } = makeCtx(repo);
|
|
532
|
-
const created = await tools.get('worktree_create').execute('
|
|
654
|
+
const created = await tools.get('worktree_create').execute('setup-1', { branch: 'feat/setup', odd: 'setup' }, undefined, undefined, ctx);
|
|
533
655
|
assert.notEqual(created.isError, true, resultText(created));
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
assert.
|
|
537
|
-
assert.
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
assert.
|
|
541
|
-
|
|
542
|
-
//
|
|
543
|
-
//
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
assert.
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
`the
|
|
557
|
-
|
|
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');
|
|
558
685
|
assert.deepEqual(notifications, [], 'the tool front never notifies a UI its call did not ask for');
|
|
559
686
|
} finally {
|
|
560
687
|
process.env.PATH = savedPath;
|
|
561
688
|
}
|
|
562
689
|
});
|
|
563
690
|
|
|
564
|
-
test('
|
|
691
|
+
test('a root with no lockfile starts nothing and prints no setup line', async () => {
|
|
565
692
|
const repo = makeRepo();
|
|
566
693
|
const { ctx } = makeCtx(repo);
|
|
567
|
-
const
|
|
568
|
-
const notify = (message, level) => { notes.push([level, message]); };
|
|
569
|
-
const created = await extensionMod.executeWorktreeCreate(
|
|
570
|
-
{ branch: 'feat/notified', changes: 'none' },
|
|
571
|
-
ctx,
|
|
572
|
-
{ backgroundHooks: true, notify },
|
|
573
|
-
);
|
|
694
|
+
const created = await tools.get('worktree_create').execute('setup-2', { branch: 'feat/plain', odd: 'plain' }, undefined, undefined, ctx);
|
|
574
695
|
assert.notEqual(created.isError, true, resultText(created));
|
|
575
|
-
|
|
576
|
-
assert.
|
|
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
|
+
});
|
|
577
700
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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`);
|
|
598
780
|
}
|
|
599
781
|
});
|
|
600
782
|
|
|
601
|
-
test('
|
|
783
|
+
test('worktree_create renders its call and result as a framed card', async () => {
|
|
602
784
|
const repo = makeRepo();
|
|
603
785
|
const { ctx } = makeCtx(repo);
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
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
|
+
);
|
|
621
840
|
});
|
|
622
841
|
});
|
|
842
|
+
|