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,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
// S61/T47 tests: lib/worktree-changes.js — the shared pending-changes
|
|
3
|
-
// helper (dirty summary + safe copy). Real isolated git repos;
|
|
4
|
-
//
|
|
3
|
+
// helper (dirty summary + safe copy). Real isolated git repos; the helper
|
|
4
|
+
// shells out to git only. Every assertion goes through the public functions,
|
|
5
5
|
// never internals.
|
|
6
6
|
|
|
7
7
|
const { test, describe, after } = require('node:test');
|
|
@@ -321,9 +321,8 @@ describe('copyChanges', { concurrency: false }, () => {
|
|
|
321
321
|
// PENDING edit must still travel there — and the source branch's COMMITTED
|
|
322
322
|
// delta must not: diffing the destination HEAD against the source working tree
|
|
323
323
|
// would import it and overwrite destination-only content. Both consumers (the
|
|
324
|
-
// human `/
|
|
325
|
-
//
|
|
326
|
-
// regression evidence for both.
|
|
324
|
+
// human `/warp` command and the `worktree_create` tool) go through this one
|
|
325
|
+
// helper, so these cases are the regression evidence for both.
|
|
327
326
|
describe('copyChanges onto a destination built from another base', { concurrency: false }, () => {
|
|
328
327
|
const EIGHT = 'l1\nl2\nl3\nl4\nl5\nl6\nl7\nl8\n';
|
|
329
328
|
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The core of `worktree_create`: where a worktree goes, which branch it takes, which
|
|
3
|
+
// ref it starts from, what Git is asked and what a reader sees. Decision cases use an
|
|
4
|
+
// injected Git seam; creation cases use real temporary clones.
|
|
5
|
+
//
|
|
6
|
+
// S3: nothing is stored. The destination directory `<repo-name>-worktrees/<odd>` is the
|
|
7
|
+
// whole record, so the create writes no document and a create followed by a list leaves
|
|
8
|
+
// the clone exactly as Git left it.
|
|
9
|
+
|
|
10
|
+
const assert = require('node:assert/strict');
|
|
11
|
+
const { execFileSync } = require('node:child_process');
|
|
12
|
+
const { existsSync, mkdirSync, mkdtempSync, readdirSync, realpathSync, rmSync, writeFileSync } = require('node:fs');
|
|
13
|
+
const { tmpdir } = require('node:os');
|
|
14
|
+
const { basename, join } = require('node:path');
|
|
15
|
+
const test = require('node:test');
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
WORKTREE_NOT_A_REPOSITORY,
|
|
19
|
+
WORKTREE_SEGMENT_HINT,
|
|
20
|
+
executeWorktreeCreatePlan,
|
|
21
|
+
planWorktreeCreate,
|
|
22
|
+
worktreeCreateView,
|
|
23
|
+
worktreeDestinationPath,
|
|
24
|
+
} = require('../lib/worktree-create.js');
|
|
25
|
+
|
|
26
|
+
const MAIN_ROOT = '/dev/projects/repo';
|
|
27
|
+
const DESTINATION = '/dev/projects/repo-worktrees/worktree-tools';
|
|
28
|
+
const BASE_SHA = '0123456789abcdef0123456789abcdef01234567';
|
|
29
|
+
const OTHER_SHA = 'fedcba9876543210fedcba9876543210fedcba98';
|
|
30
|
+
const SHORT_BASE = BASE_SHA.slice(0, 7);
|
|
31
|
+
|
|
32
|
+
// ---- An injected Git seam ----
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* `refs` maps every ref the clone has to the SHA it resolves to; `originHead` and
|
|
36
|
+
* `initDefaultBranch` answer the two configuration queries; `holder` is the worktree
|
|
37
|
+
* Git already lists for a branch.
|
|
38
|
+
*/
|
|
39
|
+
function gitStub(overrides = {}) {
|
|
40
|
+
const refs = overrides.refs ?? { 'refs/heads/main': BASE_SHA };
|
|
41
|
+
const calls = [];
|
|
42
|
+
const git = async (cwd, args) => {
|
|
43
|
+
calls.push({ cwd, args });
|
|
44
|
+
const [command, ...rest] = args;
|
|
45
|
+
if (command === 'rev-parse' && rest[0] === '--verify') {
|
|
46
|
+
const sha = refs[rest[rest.length - 1]];
|
|
47
|
+
return sha === undefined ? { code: 1, stdout: '' } : { code: 0, stdout: `${sha}\n` };
|
|
48
|
+
}
|
|
49
|
+
if (command === 'symbolic-ref') {
|
|
50
|
+
return overrides.originHead === undefined ? { code: 1, stdout: '' } : { code: 0, stdout: `${overrides.originHead}\n` };
|
|
51
|
+
}
|
|
52
|
+
if (command === 'config') {
|
|
53
|
+
return overrides.initDefaultBranch === undefined
|
|
54
|
+
? { code: 1, stdout: '' }
|
|
55
|
+
: { code: 0, stdout: `${overrides.initDefaultBranch}\n` };
|
|
56
|
+
}
|
|
57
|
+
if (command === 'worktree' && rest[0] === 'list') {
|
|
58
|
+
let text = 'worktree /dev/projects/repo\0branch refs/heads/main\0\0';
|
|
59
|
+
if (overrides.holder) text += `worktree ${overrides.holder.path}\0branch refs/heads/${overrides.holder.branch}\0\0`;
|
|
60
|
+
return { code: 0, stdout: text };
|
|
61
|
+
}
|
|
62
|
+
if (command === 'worktree' && rest[0] === 'add') return { code: overrides.addCode ?? 0, stdout: '' };
|
|
63
|
+
return undefined;
|
|
64
|
+
};
|
|
65
|
+
return { git, calls };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function seamsFor(git, existing = []) {
|
|
69
|
+
const existsCalls = [];
|
|
70
|
+
return {
|
|
71
|
+
seams: {
|
|
72
|
+
git,
|
|
73
|
+
exists: (path) => {
|
|
74
|
+
existsCalls.push(path);
|
|
75
|
+
return existing.includes(path);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
existsCalls,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const REPOSITORY = { mainRoot: MAIN_ROOT };
|
|
83
|
+
const REQUEST = { odd: 'worktree-tools', branch: 'feat/worktree-tools' };
|
|
84
|
+
|
|
85
|
+
async function expectedPlan(request, repository, seams) {
|
|
86
|
+
const decision = await planWorktreeCreate(request, repository, seams);
|
|
87
|
+
if (decision.ok === false) assert.fail(`expected a plan, got ${decision.error.code}: ${decision.error.message}`);
|
|
88
|
+
return decision.plan;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function expectedError(request, repository, seams) {
|
|
92
|
+
const decision = await planWorktreeCreate(request, repository, seams);
|
|
93
|
+
if (decision.ok === true) assert.fail(`expected a refusal, got the plan for ${decision.plan.path}`);
|
|
94
|
+
return decision.error;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ---- A real clone ----
|
|
98
|
+
|
|
99
|
+
/** A real clone with an isolated HOME and Git configuration, removed in teardown. */
|
|
100
|
+
function repositoryFixture(t, initialBranch = 'main') {
|
|
101
|
+
const fixture = realpathSync(mkdtempSync(join(tmpdir(), 'worktree-create-')));
|
|
102
|
+
t.after(() => rmSync(fixture, { recursive: true, force: true }));
|
|
103
|
+
const home = join(fixture, 'home');
|
|
104
|
+
const template = join(fixture, 'template');
|
|
105
|
+
const emptyConfig = join(fixture, 'gitconfig');
|
|
106
|
+
mkdirSync(home);
|
|
107
|
+
mkdirSync(template);
|
|
108
|
+
writeFileSync(emptyConfig, '');
|
|
109
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('GIT_')));
|
|
110
|
+
Object.assign(env, { HOME: home, GIT_CONFIG_GLOBAL: emptyConfig, GIT_CONFIG_NOSYSTEM: '1' });
|
|
111
|
+
const git = (cwd, args) =>
|
|
112
|
+
execFileSync(
|
|
113
|
+
'git',
|
|
114
|
+
['-C', cwd, '-c', `core.hooksPath=${template}`, '-c', 'commit.gpgsign=false', ...args],
|
|
115
|
+
{ env, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] },
|
|
116
|
+
);
|
|
117
|
+
const root = join(fixture, 'repo');
|
|
118
|
+
git(fixture, ['init', `--initial-branch=${initialBranch}`, `--template=${template}`, root]);
|
|
119
|
+
writeFileSync(join(root, 'tracked.txt'), 'fixture\n');
|
|
120
|
+
git(root, ['add', 'tracked.txt']);
|
|
121
|
+
git(root, ['-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.invalid', 'commit', '-m', 'Fixture']);
|
|
122
|
+
const commonDir = realpathSync(git(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']).trim());
|
|
123
|
+
/** The asynchronous seam the plan and execute steps take, recording every invocation. */
|
|
124
|
+
const seam = (exitCodes = {}) => {
|
|
125
|
+
const calls = [];
|
|
126
|
+
const runner = async (cwd, args) => {
|
|
127
|
+
calls.push({ cwd, args });
|
|
128
|
+
const key = args.join(' ');
|
|
129
|
+
if (Object.prototype.hasOwnProperty.call(exitCodes, key)) return { code: exitCodes[key], stdout: '' };
|
|
130
|
+
try {
|
|
131
|
+
return { code: 0, stdout: git(cwd, [...args]) };
|
|
132
|
+
} catch (error) {
|
|
133
|
+
const failure = error;
|
|
134
|
+
return { code: failure.status ?? 1, stdout: typeof failure.stdout === 'string' ? failure.stdout : '' };
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
return { git: runner, calls };
|
|
138
|
+
};
|
|
139
|
+
return { root, commonDir, git, seam };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ---- S1: destination layout ----
|
|
143
|
+
|
|
144
|
+
test('S1: the destination sits beside the canonical main worktree', async () => {
|
|
145
|
+
assert.equal(worktreeDestinationPath(MAIN_ROOT, 'worktree-tools'), DESTINATION);
|
|
146
|
+
const plan = await expectedPlan(REQUEST, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
147
|
+
assert.equal(plan.path, DESTINATION);
|
|
148
|
+
assert.deepEqual(plan.args, ['worktree', 'add', '-b', 'feat/worktree-tools', DESTINATION, 'refs/heads/main']);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('S7: the directory is the ODD, whatever the branch says', async () => {
|
|
152
|
+
const plan = await expectedPlan({ odd: 'login-ui', branch: 'feat/whatever' }, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
153
|
+
assert.equal(plan.path, '/dev/projects/repo-worktrees/login-ui');
|
|
154
|
+
assert.equal(basename(plan.path), 'login-ui');
|
|
155
|
+
assert.equal(plan.odd, 'login-ui');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// ---- S5: the request's refusals ----
|
|
159
|
+
|
|
160
|
+
test("S27: the outside-a-repository sentence is the contract's exact text", () => {
|
|
161
|
+
assert.equal(WORKTREE_NOT_A_REPOSITORY, 'not inside a Git worktree, so there is no repository to create a worktree from');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('S7: the ODD segment vocabulary is the one rule and the one sentence', async () => {
|
|
165
|
+
const { isWorktreeSegment } = require('../lib/worktree-create.js');
|
|
166
|
+
for (const good of ['worktree-tools', 'login_ui', 'v1.2', 'a']) assert.equal(isWorktreeSegment(good), true, good);
|
|
167
|
+
for (const bad of ['', ' ', 'a/b', 'a\\b', '..', '/abs', undefined, 'a\u0000b']) {
|
|
168
|
+
assert.equal(isWorktreeSegment(bad), false, JSON.stringify(bad));
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('S5: the ODD is one path segment, refused before anything is touched', async () => {
|
|
173
|
+
const stub = gitStub();
|
|
174
|
+
const error = await expectedError({ odd: 'a/b', branch: 'feat/x' }, REPOSITORY, seamsFor(stub.git).seams);
|
|
175
|
+
assert.deepEqual(error, {
|
|
176
|
+
code: 'invalid-odd',
|
|
177
|
+
message: `invalid odd name: "a/b"\n${WORKTREE_SEGMENT_HINT}`,
|
|
178
|
+
});
|
|
179
|
+
assert.deepEqual(stub.calls, [], 'no Git command ran');
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('S7: an omitted odd is refused with the segment sentence, before Git runs', async () => {
|
|
183
|
+
const stub = gitStub();
|
|
184
|
+
const { seams, existsCalls } = seamsFor(stub.git);
|
|
185
|
+
const error = await expectedError({ branch: 'feat/worktree-tools' }, REPOSITORY, seams);
|
|
186
|
+
|
|
187
|
+
assert.deepEqual(error, { code: 'invalid-odd', message: `invalid odd name: undefined\n${WORKTREE_SEGMENT_HINT}` });
|
|
188
|
+
assert.deepEqual(stub.calls, [], 'no Git command ran');
|
|
189
|
+
assert.deepEqual(existsCalls, [], 'the filesystem was not touched');
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// ---- S2: base resolution and branch handling ----
|
|
193
|
+
|
|
194
|
+
test('S2: base resolution walks main, origin/HEAD and init.defaultBranch', async () => {
|
|
195
|
+
const local = await expectedPlan(REQUEST, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
196
|
+
assert.equal(local.base, 'main');
|
|
197
|
+
assert.equal(local.startRef, 'refs/heads/main');
|
|
198
|
+
|
|
199
|
+
const origin = await expectedPlan(REQUEST, REPOSITORY, seamsFor(gitStub({
|
|
200
|
+
originHead: 'origin/trunk',
|
|
201
|
+
refs: { 'refs/remotes/origin/trunk': BASE_SHA },
|
|
202
|
+
}).git).seams);
|
|
203
|
+
assert.equal(origin.base, 'trunk');
|
|
204
|
+
|
|
205
|
+
const configured = await expectedPlan(REQUEST, REPOSITORY, seamsFor(gitStub({
|
|
206
|
+
initDefaultBranch: 'develop',
|
|
207
|
+
refs: { 'refs/heads/develop': BASE_SHA },
|
|
208
|
+
}).git).seams);
|
|
209
|
+
assert.equal(configured.base, 'develop');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('S2: no base at all is refused with its own sentence', async () => {
|
|
213
|
+
const error = await expectedError(REQUEST, REPOSITORY, seamsFor(gitStub({ refs: {} }).git).seams);
|
|
214
|
+
assert.equal(error.code, 'no-base-branch');
|
|
215
|
+
assert.equal(error.message, 'could not resolve a base branch: tried main, origin/HEAD, init.defaultBranch');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('S2: the base branch itself is refused as the worktree branch', async () => {
|
|
219
|
+
const error = await expectedError({ odd: 'x', branch: 'main' }, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
220
|
+
assert.equal(error.code, 'base-branch-is-target');
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// ---- An explicit base: any branch the worktree should start from ----
|
|
224
|
+
|
|
225
|
+
test('base: an explicit base starts the new branch from that branch, not from main', async () => {
|
|
226
|
+
const stub = gitStub({ refs: { 'refs/heads/main': BASE_SHA, 'refs/heads/dev': OTHER_SHA } });
|
|
227
|
+
const plan = await expectedPlan({ ...REQUEST, base: 'dev' }, REPOSITORY, seamsFor(stub.git).seams);
|
|
228
|
+
assert.equal(plan.base, 'dev');
|
|
229
|
+
assert.equal(plan.startRef, 'refs/heads/dev');
|
|
230
|
+
assert.equal(plan.baseSha, OTHER_SHA);
|
|
231
|
+
assert.deepEqual(plan.args, ['worktree', 'add', '-b', 'feat/worktree-tools', DESTINATION, 'refs/heads/dev']);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('base: a base that only exists on origin is used, and a local one wins over it', async () => {
|
|
235
|
+
const remoteOnly = await expectedPlan({ ...REQUEST, base: 'dev' }, REPOSITORY, seamsFor(gitStub({
|
|
236
|
+
refs: { 'refs/heads/main': BASE_SHA, 'refs/remotes/origin/dev': OTHER_SHA },
|
|
237
|
+
}).git).seams);
|
|
238
|
+
assert.equal(remoteOnly.startRef, 'refs/remotes/origin/dev');
|
|
239
|
+
assert.equal(remoteOnly.baseSha, OTHER_SHA);
|
|
240
|
+
|
|
241
|
+
const both = await expectedPlan({ ...REQUEST, base: 'dev' }, REPOSITORY, seamsFor(gitStub({
|
|
242
|
+
refs: { 'refs/heads/main': BASE_SHA, 'refs/heads/dev': OTHER_SHA, 'refs/remotes/origin/dev': BASE_SHA },
|
|
243
|
+
}).git).seams);
|
|
244
|
+
assert.equal(both.startRef, 'refs/heads/dev');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('base: omitting it, or passing undefined, keeps the main-first resolution unchanged', async () => {
|
|
248
|
+
const stub = gitStub({ refs: { 'refs/heads/main': BASE_SHA, 'refs/heads/dev': OTHER_SHA } });
|
|
249
|
+
const omitted = await expectedPlan(REQUEST, REPOSITORY, seamsFor(stub.git).seams);
|
|
250
|
+
const undefinedBase = await expectedPlan({ ...REQUEST, base: undefined }, REPOSITORY, seamsFor(stub.git).seams);
|
|
251
|
+
assert.equal(omitted.base, 'main');
|
|
252
|
+
assert.deepEqual(undefinedBase, omitted);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('base: an unknown base is refused with its own sentence and nothing is created', async () => {
|
|
256
|
+
const stub = gitStub();
|
|
257
|
+
const error = await expectedError({ ...REQUEST, base: 'nope' }, REPOSITORY, seamsFor(stub.git).seams);
|
|
258
|
+
assert.deepEqual(error, { code: 'base-not-found', message: 'could not resolve base branch nope: tried nope, origin/nope' });
|
|
259
|
+
assert.equal(stub.calls.some((call) => call.args[0] === 'worktree' && call.args[1] === 'add'), false);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test('base: a value that cannot name a branch is refused before Git runs', async () => {
|
|
263
|
+
for (const bad of ['', ' ', 42, null, '-x', 'a\nb']) {
|
|
264
|
+
const stub = gitStub();
|
|
265
|
+
const error = await expectedError({ ...REQUEST, base: bad }, REPOSITORY, seamsFor(stub.git).seams);
|
|
266
|
+
assert.equal(error.code, 'invalid-base', JSON.stringify(bad));
|
|
267
|
+
assert.match(error.message, /^invalid base: /, JSON.stringify(bad));
|
|
268
|
+
assert.deepEqual(stub.calls, [], `${JSON.stringify(bad)} asked Git nothing`);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('base: the base itself is still refused as the worktree branch', async () => {
|
|
273
|
+
const stub = gitStub({ refs: { 'refs/heads/main': BASE_SHA, 'refs/heads/dev': OTHER_SHA } });
|
|
274
|
+
const error = await expectedError({ odd: 'x', branch: 'dev', base: 'dev' }, REPOSITORY, seamsFor(stub.git).seams);
|
|
275
|
+
assert.equal(error.code, 'base-branch-is-target');
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test('base: it only applies when the branch is created, so an existing branch with a base is refused', async () => {
|
|
279
|
+
const stub = gitStub({ refs: { 'refs/heads/main': BASE_SHA, 'refs/heads/dev': OTHER_SHA, 'refs/heads/feat/worktree-tools': BASE_SHA } });
|
|
280
|
+
const error = await expectedError({ ...REQUEST, base: 'dev' }, REPOSITORY, seamsFor(stub.git).seams);
|
|
281
|
+
assert.deepEqual(error, {
|
|
282
|
+
code: 'base-on-existing-branch',
|
|
283
|
+
message: 'branch feat/worktree-tools already exists, so it is checked out as it is; base only applies when the branch is created',
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test('base: the create text names the base the branch started from', async () => {
|
|
288
|
+
const stub = gitStub({ refs: { 'refs/heads/main': BASE_SHA, 'refs/heads/dev': OTHER_SHA } });
|
|
289
|
+
const plan = await expectedPlan({ ...REQUEST, base: 'dev' }, REPOSITORY, seamsFor(stub.git).seams);
|
|
290
|
+
const view = worktreeCreateView({ plan, registered: true });
|
|
291
|
+
assert.match(view.text, new RegExp(`^base: dev@${OTHER_SHA.slice(0, 7)}$`, 'm'));
|
|
292
|
+
assert.equal(view.details.base, 'dev');
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('S3: an existing branch is adopted and a held one names its holder', async () => {
|
|
296
|
+
const adopted = await expectedPlan(REQUEST, REPOSITORY, seamsFor(gitStub({
|
|
297
|
+
refs: { 'refs/heads/main': BASE_SHA, 'refs/heads/feat/worktree-tools': OTHER_SHA },
|
|
298
|
+
}).git).seams);
|
|
299
|
+
assert.equal(adopted.branchState, 'existing');
|
|
300
|
+
assert.deepEqual(adopted.args, ['worktree', 'add', DESTINATION, 'feat/worktree-tools']);
|
|
301
|
+
|
|
302
|
+
const holderPath = '/dev/projects/repo-worktrees/file-picker';
|
|
303
|
+
const error = await expectedError({ odd: 'x', branch: 'feat/file-picker' }, REPOSITORY, seamsFor(gitStub({
|
|
304
|
+
holder: { path: holderPath, branch: 'feat/file-picker' },
|
|
305
|
+
}).git).seams);
|
|
306
|
+
assert.deepEqual(error, {
|
|
307
|
+
code: 'branch-in-use',
|
|
308
|
+
message: `branch feat/file-picker is already checked out in ${holderPath}\nUse a different branch, or work in that worktree.`,
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('S3: no plan and no executed command ever passes --force', async () => {
|
|
313
|
+
const stub = gitStub({ refs: { 'refs/heads/main': BASE_SHA, 'refs/heads/feat/worktree-tools': OTHER_SHA } });
|
|
314
|
+
const plan = await expectedPlan(REQUEST, REPOSITORY, seamsFor(stub.git).seams);
|
|
315
|
+
assert.ok(!plan.args.includes('--force'));
|
|
316
|
+
const execution = await executeWorktreeCreatePlan({ plan, git: stub.git });
|
|
317
|
+
assert.equal(execution.ok, true);
|
|
318
|
+
assert.ok(stub.calls.every((call) => !call.args.includes('--force')), 'no Git invocation forces anything');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test('S7: a second create for the same ODD is refused by the ODD path, whatever its branch', async () => {
|
|
322
|
+
const stub = gitStub();
|
|
323
|
+
const error = await expectedError({ odd: 'login-ui', branch: 'fix/login' }, REPOSITORY, seamsFor(stub.git, ['/dev/projects/repo-worktrees/login-ui']).seams);
|
|
324
|
+
assert.deepEqual(error, {
|
|
325
|
+
code: 'path-exists',
|
|
326
|
+
message: 'worktree path already exists: /dev/projects/repo-worktrees/login-ui\nRemove it or pass a different odd.',
|
|
327
|
+
});
|
|
328
|
+
assert.ok(!stub.calls.some((call) => call.args[1] === 'add'), 'nothing was created');
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test('S4: an occupied destination is refused without asking Git to create it', async () => {
|
|
332
|
+
const stub = gitStub();
|
|
333
|
+
const error = await expectedError(REQUEST, REPOSITORY, seamsFor(stub.git, [DESTINATION]).seams);
|
|
334
|
+
assert.deepEqual(error, {
|
|
335
|
+
code: 'path-exists',
|
|
336
|
+
message: `worktree path already exists: ${DESTINATION}\nRemove it or pass a different odd.`,
|
|
337
|
+
});
|
|
338
|
+
assert.ok(!stub.calls.some((call) => call.args[1] === 'add'), 'nothing was created');
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// ---- S3: executing the plan ----
|
|
342
|
+
|
|
343
|
+
test('S3: executing a plan creates the worktree and writes nothing else', async () => {
|
|
344
|
+
const stub = gitStub();
|
|
345
|
+
const plan = await expectedPlan(REQUEST, REPOSITORY, seamsFor(stub.git).seams);
|
|
346
|
+
const execution = await executeWorktreeCreatePlan({ plan, git: stub.git });
|
|
347
|
+
|
|
348
|
+
assert.deepEqual(execution, { ok: true, result: {} });
|
|
349
|
+
assert.deepEqual(stub.calls.at(-1), { cwd: MAIN_ROOT, args: plan.args }, 'the planned `git worktree add` runs verbatim');
|
|
350
|
+
assert.equal(
|
|
351
|
+
stub.calls.filter((call) => call.args[0] === 'rev-parse' && call.args.includes('--git-dir')).length,
|
|
352
|
+
0,
|
|
353
|
+
'no administrative-directory read follows it',
|
|
354
|
+
);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test('S7: a Git seam that answers nothing is reported without a result', async () => {
|
|
358
|
+
const plan = await expectedPlan(REQUEST, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
359
|
+
const execution = await executeWorktreeCreatePlan({ plan, git: async () => undefined });
|
|
360
|
+
assert.deepEqual(execution, {
|
|
361
|
+
ok: false,
|
|
362
|
+
error: { code: 'git-failed', message: `could not create the worktree at ${DESTINATION}: git worktree add exited without a result` },
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test('S7: a failed git worktree add reports the backend exit', async () => {
|
|
367
|
+
const stub = gitStub({ addCode: 128 });
|
|
368
|
+
const plan = await expectedPlan(REQUEST, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
369
|
+
const execution = await executeWorktreeCreatePlan({ plan, git: stub.git });
|
|
370
|
+
assert.deepEqual(execution, {
|
|
371
|
+
ok: false,
|
|
372
|
+
error: { code: 'git-failed', message: `could not create the worktree at ${DESTINATION}: git worktree add exited 128` },
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
// ---- S1/S3: the create output ----
|
|
377
|
+
|
|
378
|
+
test('S16: the create text is the fixed line order, with no hooks part and no setup part', async () => {
|
|
379
|
+
const plan = await expectedPlan(REQUEST, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
380
|
+
const view = worktreeCreateView({ plan, registered: true });
|
|
381
|
+
|
|
382
|
+
assert.equal(
|
|
383
|
+
view.text,
|
|
384
|
+
[
|
|
385
|
+
`worktree created: ${DESTINATION}`,
|
|
386
|
+
'branch: feat/worktree-tools (created)',
|
|
387
|
+
'odd: worktree-tools',
|
|
388
|
+
`base: main@${SHORT_BASE}`,
|
|
389
|
+
'worktree register in session',
|
|
390
|
+
].join('\n'),
|
|
391
|
+
);
|
|
392
|
+
// S1: the hooks part and the setup part are gone — at call time the create knows
|
|
393
|
+
// neither which hooks were skipped nor how the background chain went.
|
|
394
|
+
const withHooks = worktreeCreateView({ plan, registered: true, hooks: [
|
|
395
|
+
{ name: 'submodules', status: 'skipped', detail: 'no submodules' },
|
|
396
|
+
{ name: 'symlink .turbo', status: 'failed', detail: 'could not link .turbo: EPERM' },
|
|
397
|
+
] });
|
|
398
|
+
assert.equal(withHooks.text, view.text, 'the hooks part never reaches the output');
|
|
399
|
+
assert.doesNotMatch(withHooks.text, /hooks|setup|metadata:/);
|
|
400
|
+
assert.deepEqual(view.details, {
|
|
401
|
+
path: DESTINATION,
|
|
402
|
+
name: 'worktree-tools',
|
|
403
|
+
branch: 'feat/worktree-tools',
|
|
404
|
+
branchState: 'created',
|
|
405
|
+
base: 'main',
|
|
406
|
+
baseSha: BASE_SHA,
|
|
407
|
+
odd: 'worktree-tools',
|
|
408
|
+
registered: true,
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
test('S16/S17: a refused registration is reported, never claimed', async () => {
|
|
413
|
+
const plan = await expectedPlan(REQUEST, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
414
|
+
const view = worktreeCreateView({ plan, registered: false });
|
|
415
|
+
assert.equal(view.text.split('\n').at(-1), 'worktree register failed');
|
|
416
|
+
assert.equal(view.details.registered, false);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
test('S18: the copy_changes line is the only extra line, and its count reaches the details', async () => {
|
|
420
|
+
const plan = await expectedPlan({ ...REQUEST, copy_changes: true }, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
421
|
+
assert.equal(plan.copyChanges, true);
|
|
422
|
+
const hooks = [{ name: 'copy_changes', status: 'applied', copyChanges: { copied: 3, failed: [] } }];
|
|
423
|
+
const view = worktreeCreateView({ plan, registered: true, hooks });
|
|
424
|
+
|
|
425
|
+
assert.deepEqual(view.text.split('\n').slice(5), ['copy_changes: 3 changes copied']);
|
|
426
|
+
assert.deepEqual(view.details.copyChanges, { copied: 3, failed: [] });
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
test('S18: a conflict is reported with its failing paths in the copy_changes line', async () => {
|
|
430
|
+
const plan = await expectedPlan({ ...REQUEST, copy_changes: true }, REPOSITORY, seamsFor(gitStub().git).seams);
|
|
431
|
+
const hooks = [{ name: 'copy_changes', status: 'failed', detail: 'could not copy: conflict.txt', copyChanges: { copied: 1, failed: ['conflict.txt'] } }];
|
|
432
|
+
const view = worktreeCreateView({ plan, registered: true, hooks });
|
|
433
|
+
|
|
434
|
+
assert.deepEqual(view.text.split('\n').slice(5), [
|
|
435
|
+
'copy_changes: 1 changes copied; failed: conflict.txt',
|
|
436
|
+
]);
|
|
437
|
+
assert.deepEqual(view.details.copyChanges, { copied: 1, failed: ['conflict.txt'] });
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
// ---- Creation cases in real clones ----
|
|
441
|
+
|
|
442
|
+
test('base: a real clone starts the new branch from the base branch\'s commit, not main\'s', async (t) => {
|
|
443
|
+
const repository = repositoryFixture(t);
|
|
444
|
+
const identity = ['-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.invalid'];
|
|
445
|
+
repository.git(repository.root, ['switch', '-q', '-c', 'dev']);
|
|
446
|
+
writeFileSync(join(repository.root, 'dev-only.txt'), 'only on dev\n');
|
|
447
|
+
repository.git(repository.root, ['add', 'dev-only.txt']);
|
|
448
|
+
repository.git(repository.root, [...identity, 'commit', '-m', 'Dev work']);
|
|
449
|
+
const devSha = repository.git(repository.root, ['rev-parse', 'HEAD']).trim();
|
|
450
|
+
repository.git(repository.root, ['switch', '-q', 'main']);
|
|
451
|
+
const mainSha = repository.git(repository.root, ['rev-parse', 'HEAD']).trim();
|
|
452
|
+
assert.notEqual(devSha, mainSha, 'the fixture really has two different tips');
|
|
453
|
+
|
|
454
|
+
const stub = repository.seam();
|
|
455
|
+
const seams = { git: stub.git, exists: (path) => existsSync(path) };
|
|
456
|
+
const fromDev = await planWorktreeCreate({ ...REQUEST, base: 'dev' }, { mainRoot: repository.root }, seams);
|
|
457
|
+
if (fromDev.ok === false) assert.fail(fromDev.error.message);
|
|
458
|
+
const execution = await executeWorktreeCreatePlan({ plan: fromDev.plan, git: stub.git });
|
|
459
|
+
if (execution.ok === false) assert.fail(execution.error.message);
|
|
460
|
+
assert.equal(repository.git(fromDev.plan.path, ['rev-parse', 'HEAD']).trim(), devSha, 'the worktree starts at dev');
|
|
461
|
+
assert.equal(existsSync(join(fromDev.plan.path, 'dev-only.txt')), true, 'and carries dev\'s files');
|
|
462
|
+
assert.match(worktreeCreateView({ plan: fromDev.plan, registered: true }).text, new RegExp(`^base: dev@${devSha.slice(0, 7)}$`, 'm'));
|
|
463
|
+
|
|
464
|
+
// Without a base the same clone still starts from main.
|
|
465
|
+
const fromMain = await planWorktreeCreate({ odd: 'other', branch: 'feat/other' }, { mainRoot: repository.root }, seams);
|
|
466
|
+
if (fromMain.ok === false) assert.fail(fromMain.error.message);
|
|
467
|
+
assert.equal(fromMain.plan.baseSha, mainSha);
|
|
468
|
+
assert.equal(fromMain.plan.base, 'main');
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
test('S1/S3: a real clone creates the worktree, its branch, and no document at all', async (t) => {
|
|
472
|
+
const repository = repositoryFixture(t);
|
|
473
|
+
const stub = repository.seam();
|
|
474
|
+
const seams = { git: stub.git, exists: (path) => existsSync(path) };
|
|
475
|
+
const decision = await planWorktreeCreate(REQUEST, { mainRoot: repository.root }, seams);
|
|
476
|
+
if (decision.ok === false) assert.fail(decision.error.message);
|
|
477
|
+
const execution = await executeWorktreeCreatePlan({ plan: decision.plan, git: stub.git });
|
|
478
|
+
if (execution.ok === false) assert.fail(execution.error.message);
|
|
479
|
+
|
|
480
|
+
assert.equal(existsSync(decision.plan.path), true, 'the checkout exists');
|
|
481
|
+
assert.ok(repository.git(repository.root, ['branch', '--format=%(refname:short)']).split('\n').includes('feat/worktree-tools'));
|
|
482
|
+
assert.ok(repository.git(repository.root, ['worktree', 'list', '--porcelain']).includes(decision.plan.path));
|
|
483
|
+
// S3: the clone keeps no document. The only files `.git` gained are Git's own.
|
|
484
|
+
assert.equal(existsSync(join(repository.commonDir, 'pi-worktrees.json')), false, 'no list file is written');
|
|
485
|
+
assert.equal(existsSync(join(repository.commonDir, 'pi-worktrees.lock')), false, 'no lock file is written');
|
|
486
|
+
assert.equal(existsSync(join(repository.commonDir, 'gentle-ai', 'worktrees.json')), false, 'no second document is written');
|
|
487
|
+
const gitEntries = readdirSync(repository.commonDir).sort();
|
|
488
|
+
assert.deepEqual(gitEntries.filter((name) => /worktrees?\.(json|lock)$/.test(name)), [], 'nothing list-shaped under .git');
|
|
489
|
+
});
|