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
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// S9: a successful edit or write asks for one background sync of the edited file's checkout, debounced, never while a daemon
|
|
3
|
+
// watches that checkout, never in a read-only role, never without the CLI or an index. Timers, git and the sync are injected.
|
|
4
|
+
const { test } = require('node:test');
|
|
5
|
+
const assert = require('node:assert/strict');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { createEditSync } = require('../lib/codegraph-edit-sync.js');
|
|
8
|
+
|
|
9
|
+
function harness(overrides = {}) {
|
|
10
|
+
const timers = [];
|
|
11
|
+
const calls = { sync: [], toplevel: [] };
|
|
12
|
+
const deps = {
|
|
13
|
+
cwd: '/work/repo',
|
|
14
|
+
available: () => true,
|
|
15
|
+
role: undefined,
|
|
16
|
+
toplevel: async (dir) => {
|
|
17
|
+
calls.toplevel.push(dir);
|
|
18
|
+
return dir.startsWith('/work/repo/wt') ? '/work/repo/wt' : '/work/repo';
|
|
19
|
+
},
|
|
20
|
+
hasIndex: () => true,
|
|
21
|
+
daemonLive: () => false,
|
|
22
|
+
sync: async (root) => {
|
|
23
|
+
calls.sync.push(root);
|
|
24
|
+
return { status: 'synced' };
|
|
25
|
+
},
|
|
26
|
+
setTimer: (fn, ms) => {
|
|
27
|
+
const timer = { fn, ms, cleared: false };
|
|
28
|
+
timers.push(timer);
|
|
29
|
+
return timer;
|
|
30
|
+
},
|
|
31
|
+
clearTimer: (timer) => {
|
|
32
|
+
timer.cleared = true;
|
|
33
|
+
},
|
|
34
|
+
...overrides,
|
|
35
|
+
};
|
|
36
|
+
const editSync = createEditSync(deps);
|
|
37
|
+
const fire = async () => {
|
|
38
|
+
for (const timer of timers.splice(0)) if (!timer.cleared) await timer.fn();
|
|
39
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
40
|
+
};
|
|
41
|
+
return { editSync, calls, timers, fire };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const edit = (file, toolName = 'edit', extra = {}) => ({ toolName, input: { path: file }, isError: false, ...extra });
|
|
45
|
+
|
|
46
|
+
test('one edit asks for one sync of its checkout after the debounce window', async () => {
|
|
47
|
+
const { editSync, calls, timers, fire } = harness();
|
|
48
|
+
await editSync.onToolResult(edit('/work/repo/src/a.js'));
|
|
49
|
+
assert.deepEqual(calls.sync, [], 'nothing runs before the window ends');
|
|
50
|
+
assert.equal(timers.length, 1);
|
|
51
|
+
await fire();
|
|
52
|
+
assert.deepEqual(calls.sync, ['/work/repo']);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('quick edits of one checkout collapse into one sync, and a relative path resolves against the session cwd', async () => {
|
|
56
|
+
const { editSync, calls, fire } = harness();
|
|
57
|
+
await editSync.onToolResult(edit('src/a.js'));
|
|
58
|
+
await editSync.onToolResult(edit('src/b.js', 'write'));
|
|
59
|
+
await editSync.onToolResult(edit('/work/repo/src/c.js'));
|
|
60
|
+
await fire();
|
|
61
|
+
assert.deepEqual(calls.sync, ['/work/repo']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('the checkout of the edited file is the target: a worktree syncs that worktree, and each root has its own window', async () => {
|
|
65
|
+
const { editSync, calls, fire } = harness();
|
|
66
|
+
await editSync.onToolResult(edit('/work/repo/src/a.js'));
|
|
67
|
+
await editSync.onToolResult(edit('/work/repo/wt/src/b.js'));
|
|
68
|
+
await fire();
|
|
69
|
+
assert.deepEqual(calls.sync.sort(), ['/work/repo', '/work/repo/wt']);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('the git toplevel is read once per directory', async () => {
|
|
73
|
+
const { editSync, calls } = harness();
|
|
74
|
+
await editSync.onToolResult(edit('/work/repo/src/a.js'));
|
|
75
|
+
await editSync.onToolResult(edit('/work/repo/src/b.js'));
|
|
76
|
+
assert.deepEqual(calls.toplevel, [path.dirname('/work/repo/src/a.js')]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('a failed edit, another tool, or an event with no path asks for nothing', async () => {
|
|
80
|
+
const { editSync, timers } = harness();
|
|
81
|
+
await editSync.onToolResult(edit('/work/repo/a.js', 'edit', { isError: true }));
|
|
82
|
+
await editSync.onToolResult(edit('/work/repo/a.js', 'bash'));
|
|
83
|
+
await editSync.onToolResult({ toolName: 'edit', input: {}, isError: false });
|
|
84
|
+
await editSync.onToolResult(undefined);
|
|
85
|
+
assert.equal(timers.length, 0);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('no index, a live daemon, a read-only role, a missing CLI or no git checkout each skip silently', async () => {
|
|
89
|
+
for (const override of [
|
|
90
|
+
{ hasIndex: () => false },
|
|
91
|
+
{ daemonLive: () => true },
|
|
92
|
+
{ role: 'read-only' },
|
|
93
|
+
{ available: () => false },
|
|
94
|
+
{ toplevel: async () => undefined },
|
|
95
|
+
]) {
|
|
96
|
+
const { editSync, timers } = harness(override);
|
|
97
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
98
|
+
assert.equal(timers.length, 0, JSON.stringify(Object.keys(override)));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('an edit during a running sync asks for exactly one more when it ends', async () => {
|
|
103
|
+
let release;
|
|
104
|
+
const gate = new Promise((resolve) => {
|
|
105
|
+
release = resolve;
|
|
106
|
+
});
|
|
107
|
+
const started = [];
|
|
108
|
+
const { editSync, fire } = harness({
|
|
109
|
+
sync: async (root) => {
|
|
110
|
+
started.push(root);
|
|
111
|
+
if (started.length === 1) await gate;
|
|
112
|
+
return { status: 'synced' };
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
116
|
+
const firing = fire();
|
|
117
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
118
|
+
await editSync.onToolResult(edit('/work/repo/b.js'));
|
|
119
|
+
await editSync.onToolResult(edit('/work/repo/c.js'));
|
|
120
|
+
await fire();
|
|
121
|
+
assert.equal(started.length, 1, 'no second sync starts while the first runs');
|
|
122
|
+
release();
|
|
123
|
+
await firing;
|
|
124
|
+
await fire();
|
|
125
|
+
await fire();
|
|
126
|
+
assert.equal(started.length, 2, 'exactly one follow-up');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('a throwing git, index check or sync never reaches the caller', async () => {
|
|
130
|
+
for (const override of [
|
|
131
|
+
{ toplevel: async () => { throw new Error('git'); } },
|
|
132
|
+
{ hasIndex: () => { throw new Error('fs'); } },
|
|
133
|
+
{ sync: async () => { throw new Error('sync'); } },
|
|
134
|
+
]) {
|
|
135
|
+
const { editSync, fire } = harness(override);
|
|
136
|
+
await assert.doesNotReject(async () => {
|
|
137
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
138
|
+
await fire();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('dispose clears every pending window', async () => {
|
|
144
|
+
const { editSync, timers } = harness();
|
|
145
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
146
|
+
await editSync.onToolResult(edit('/work/repo/wt/b.js'));
|
|
147
|
+
editSync.dispose();
|
|
148
|
+
assert.ok(timers.every((timer) => timer.cleared));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// ---- S2: the bounded join (T6) ----
|
|
152
|
+
//
|
|
153
|
+
// A search that arrives while a window writes the index may join it: `whenIdle(root, budgetMs)` settles when
|
|
154
|
+
// the running sync and the one follow-up it owes have finished, at once when nothing is in flight, and never
|
|
155
|
+
// later than the budget. It starts nothing, and `inFlight(root)` answers synchronously so a caller that finds
|
|
156
|
+
// nothing to join can decline to wait at all. Debounce and budget differ here so the fake timers tell them apart.
|
|
157
|
+
|
|
158
|
+
const DEBOUNCE = 7;
|
|
159
|
+
const BUDGET = 5000;
|
|
160
|
+
|
|
161
|
+
/** Fires the fake timers armed for one duration only, so a test can end a window without ending a budget. */
|
|
162
|
+
async function fireMs(timers, ms) {
|
|
163
|
+
for (const timer of timers.filter((one) => one.ms === ms && !one.cleared)) {
|
|
164
|
+
timers.splice(timers.indexOf(timer), 1);
|
|
165
|
+
await timer.fn();
|
|
166
|
+
}
|
|
167
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function gateOf() {
|
|
171
|
+
let release;
|
|
172
|
+
const gate = new Promise((resolve) => {
|
|
173
|
+
release = resolve;
|
|
174
|
+
});
|
|
175
|
+
return { gate, release: () => release(undefined) };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
test('S2: whenIdle settles when the sync already running finishes, and starts none', async () => {
|
|
179
|
+
const gate = gateOf();
|
|
180
|
+
const started = [];
|
|
181
|
+
const { editSync, timers } = harness({
|
|
182
|
+
debounceMs: DEBOUNCE,
|
|
183
|
+
sync: async (root) => {
|
|
184
|
+
started.push(root);
|
|
185
|
+
await gate.gate;
|
|
186
|
+
return { status: 'synced' };
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
190
|
+
assert.equal(editSync.inFlight('/work/repo'), false, 'a debounced window is scheduled, not in flight');
|
|
191
|
+
const firing = fireMs(timers, DEBOUNCE);
|
|
192
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
193
|
+
assert.equal(editSync.inFlight('/work/repo'), true);
|
|
194
|
+
let settled;
|
|
195
|
+
const joined = editSync.whenIdle('/work/repo', BUDGET).then((why) => {
|
|
196
|
+
settled = why;
|
|
197
|
+
});
|
|
198
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
199
|
+
assert.equal(settled, undefined, 'the join waits for the sync in flight');
|
|
200
|
+
gate.release();
|
|
201
|
+
await firing;
|
|
202
|
+
await joined;
|
|
203
|
+
assert.equal(settled, 'done');
|
|
204
|
+
assert.equal(editSync.inFlight('/work/repo'), false);
|
|
205
|
+
assert.deepEqual(started, ['/work/repo'], 'joining starts no sync of its own');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('S2: whenIdle also waits for the one follow-up sync a running window owes', async () => {
|
|
209
|
+
const gate = gateOf();
|
|
210
|
+
const started = [];
|
|
211
|
+
const { editSync, timers } = harness({
|
|
212
|
+
debounceMs: DEBOUNCE,
|
|
213
|
+
sync: async (root) => {
|
|
214
|
+
started.push(root);
|
|
215
|
+
if (started.length === 1) await gate.gate;
|
|
216
|
+
return { status: 'synced' };
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
220
|
+
const firing = fireMs(timers, DEBOUNCE);
|
|
221
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
222
|
+
await editSync.onToolResult(edit('/work/repo/b.js'));
|
|
223
|
+
let settled;
|
|
224
|
+
const joined = editSync.whenIdle('/work/repo', BUDGET).then((why) => {
|
|
225
|
+
settled = why;
|
|
226
|
+
});
|
|
227
|
+
gate.release();
|
|
228
|
+
await firing;
|
|
229
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
230
|
+
assert.equal(settled, undefined, 'the follow-up the window owes is part of the join');
|
|
231
|
+
await fireMs(timers, DEBOUNCE);
|
|
232
|
+
await joined;
|
|
233
|
+
assert.equal(settled, 'done');
|
|
234
|
+
assert.equal(started.length, 2, 'the window still runs exactly one follow-up');
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('S2: whenIdle settles at once when nothing is in flight, and arms no timer', async () => {
|
|
238
|
+
const { editSync, timers } = harness({ debounceMs: DEBOUNCE });
|
|
239
|
+
assert.equal(await editSync.whenIdle('/work/repo', BUDGET), 'idle');
|
|
240
|
+
assert.equal(timers.length, 0, 'no budget is armed when there is nothing to join');
|
|
241
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
242
|
+
assert.equal(await editSync.whenIdle('/work/repo', BUDGET), 'idle', 'waiting out a debounce is not a join');
|
|
243
|
+
assert.equal(await editSync.whenIdle('/work/never-seen', BUDGET), 'idle');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('S2: whenIdle never outlasts its budget, and a zero budget joins nothing', async () => {
|
|
247
|
+
const { editSync, timers } = harness({ debounceMs: DEBOUNCE, sync: () => new Promise(() => {}) });
|
|
248
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
249
|
+
void fireMs(timers, DEBOUNCE);
|
|
250
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
251
|
+
assert.equal(editSync.inFlight('/work/repo'), true);
|
|
252
|
+
const joined = editSync.whenIdle('/work/repo', BUDGET);
|
|
253
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
254
|
+
await fireMs(timers, BUDGET);
|
|
255
|
+
assert.equal(await joined, 'budget', 'the budget ends the wait, not the sync');
|
|
256
|
+
assert.equal(await editSync.whenIdle('/work/repo', 0), 'budget', 'a zero budget waits for nothing');
|
|
257
|
+
assert.equal(await editSync.whenIdle('/work/repo', Number.NaN), 'budget', 'nor does a budget that is not a number');
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('S2: dispose releases a joined search instead of leaving it waiting', async () => {
|
|
261
|
+
const gate = gateOf();
|
|
262
|
+
const { editSync, timers } = harness({ debounceMs: DEBOUNCE, sync: () => gate.gate });
|
|
263
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
264
|
+
void fireMs(timers, DEBOUNCE);
|
|
265
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
266
|
+
const joined = editSync.whenIdle('/work/repo', BUDGET);
|
|
267
|
+
editSync.dispose();
|
|
268
|
+
assert.equal(await joined, 'disposed', 'shutdown ends the wait of a search that joined');
|
|
269
|
+
gate.release();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('S2: a join changes nothing about the window it waits on', async () => {
|
|
273
|
+
const gate = gateOf();
|
|
274
|
+
const started = [];
|
|
275
|
+
const { editSync, timers } = harness({
|
|
276
|
+
debounceMs: DEBOUNCE,
|
|
277
|
+
sync: async (root) => {
|
|
278
|
+
started.push(root);
|
|
279
|
+
if (started.length === 1) await gate.gate;
|
|
280
|
+
return { status: 'synced' };
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
await editSync.onToolResult(edit('/work/repo/a.js'));
|
|
284
|
+
const firing = fireMs(timers, DEBOUNCE);
|
|
285
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
286
|
+
const joined = editSync.whenIdle('/work/repo', BUDGET);
|
|
287
|
+
await editSync.onToolResult(edit('/work/repo/b.js'));
|
|
288
|
+
await editSync.onToolResult(edit('/work/repo/c.js'));
|
|
289
|
+
gate.release();
|
|
290
|
+
await firing;
|
|
291
|
+
await fireMs(timers, DEBOUNCE);
|
|
292
|
+
await joined;
|
|
293
|
+
assert.equal(started.length, 2, 'one follow-up, exactly as without a join');
|
|
294
|
+
assert.equal(editSync.inFlight('/work/repo'), false);
|
|
295
|
+
});
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// T2 (S3, S4, S8): which checkout a finished grep/find/ls/read/bash call went to. The paths and the
|
|
3
|
+
// `cd` targets are read from the call alone, the code-file filter applies to `read`, and the git
|
|
4
|
+
// toplevel of a directory is read once and cached. Git is a fake map here: no child runs.
|
|
5
|
+
const { test } = require('node:test');
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
const {
|
|
8
|
+
createCheckoutResolver,
|
|
9
|
+
callCheckout,
|
|
10
|
+
isCodeFile,
|
|
11
|
+
searchCall,
|
|
12
|
+
} = require('../lib/codegraph-guard-target.js');
|
|
13
|
+
|
|
14
|
+
const CWD = '/home/dev/projects/example';
|
|
15
|
+
|
|
16
|
+
const event = (toolName, input) => ({ toolName, input, isError: false, content: [] });
|
|
17
|
+
|
|
18
|
+
// ---- the code-file filter (S3) ----
|
|
19
|
+
|
|
20
|
+
test('read counts for code, not for the docs and configs the rule exempts', () => {
|
|
21
|
+
for (const file of ['a.ts', 'a.js', 'Makefile', 'lib/codegraph-guard.js', 'a.tsx', 'a.py']) {
|
|
22
|
+
assert.equal(isCodeFile(file), true, file);
|
|
23
|
+
}
|
|
24
|
+
for (const file of ['a.md', 'a.json', 'a.yml', 'a.yaml', 'a.toml', 'a.txt', 'A.MD', 'docs/README.md']) {
|
|
25
|
+
assert.equal(isCodeFile(file), false, file);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// ---- the built-in search tools (S3) ----
|
|
30
|
+
|
|
31
|
+
test('grep, find and ls name their path, and default to the session checkout', () => {
|
|
32
|
+
assert.deepEqual(searchCall(event('grep', { pattern: 'x' }), CWD), { tool: 'grep', paths: [CWD] });
|
|
33
|
+
assert.deepEqual(searchCall(event('grep', { pattern: 'x', path: 'src' }), CWD), { tool: 'grep', paths: [`${CWD}/src`] });
|
|
34
|
+
assert.deepEqual(searchCall(event('find', { pattern: '*.ts', path: '/other/src' }), CWD), { tool: 'find', paths: ['/other/src'] });
|
|
35
|
+
assert.deepEqual(searchCall(event('ls', {}), CWD), { tool: 'ls', paths: [CWD] });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('read names the file it opened, and only when it is code', () => {
|
|
39
|
+
assert.deepEqual(searchCall(event('read', { path: 'src/a.ts' }), CWD), { tool: 'read', paths: [`${CWD}/src`] });
|
|
40
|
+
assert.deepEqual(searchCall(event('read', { path: '/other/a.ts' }), CWD), { tool: 'read', paths: ['/other'] });
|
|
41
|
+
assert.equal(searchCall(event('read', { path: 'package.json' }), CWD), undefined);
|
|
42
|
+
assert.equal(searchCall(event('read', { path: 'docs/reference.md' }), CWD), undefined);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('anything else is not a search call', () => {
|
|
46
|
+
for (const toolName of ['edit', 'write', 'worktree_create', 'codegraph', 'mcp__codegraph__codegraph_explore']) {
|
|
47
|
+
assert.equal(searchCall(event(toolName, { path: 'src/a.ts' }), CWD), undefined, toolName);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// ---- bash (S3) ----
|
|
52
|
+
|
|
53
|
+
test('the shell session that cd-ed into another project is a call into that project', () => {
|
|
54
|
+
const command = 'cd /home/jona/dev/projects/gentle-shell-bridge && cat package.json 2>/dev/null | head -60 && echo "---FILES---" && find . -type f -not -path \'./.git/*\' -not -path \'./node_modules/*\' | head -80';
|
|
55
|
+
const call = searchCall(event('bash', { command }), CWD);
|
|
56
|
+
assert.equal(call.tool, 'bash');
|
|
57
|
+
assert.ok(call.paths.includes('/home/jona/dev/projects/gentle-shell-bridge'), 'the cd target is named');
|
|
58
|
+
assert.deepEqual(call.paths, ['/home/jona/dev/projects/gentle-shell-bridge'], 'and nothing of the session checkout survives the cd');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('a chain of reads with no other path stays in the session checkout', () => {
|
|
62
|
+
const command = 'sed -n 150,230p src/types.ts && echo "=====CONTRACT 523-620=====" && sed -n 523,620p docs/contract.md';
|
|
63
|
+
assert.deepEqual(searchCall(event('bash', { command }), CWD), { tool: 'bash', paths: [CWD] });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('an absolute path argument of a read verb names the checkout it reads', () => {
|
|
67
|
+
const call = searchCall(event('bash', { command: 'grep -rn "explore" /other/src' }), CWD);
|
|
68
|
+
assert.ok(call.paths.includes('/other/src'));
|
|
69
|
+
assert.ok(call.paths.includes(CWD), 'the session checkout is still where the shell is');
|
|
70
|
+
const cat = searchCall(event('bash', { command: 'cat /other/src/a.ts > /tmp/out' }), CWD);
|
|
71
|
+
assert.ok(cat.paths.includes('/other/src/a.ts'));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('a command that only mentions a checkout is not a call into it', () => {
|
|
75
|
+
for (const command of [
|
|
76
|
+
'git -C /other/src log --oneline',
|
|
77
|
+
'curl /other/src/api',
|
|
78
|
+
'echo /other/src',
|
|
79
|
+
'npm view /other/src',
|
|
80
|
+
]) {
|
|
81
|
+
const call = searchCall(event('bash', { command }), CWD);
|
|
82
|
+
assert.equal(call, undefined, command);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('a quoted string is never a command of its own', () => {
|
|
87
|
+
assert.equal(searchCall(event('bash', { command: 'echo "cat /other/src/a.ts"' }), CWD), undefined);
|
|
88
|
+
assert.deepEqual(searchCall(event('bash', { command: 'grep "a|b" .' }), CWD), { tool: 'bash', paths: [CWD] });
|
|
89
|
+
assert.deepEqual(searchCall(event('bash', { command: 'cd /other && grep x a.ts' }), CWD), { tool: 'bash', paths: ['/other'] });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// ---- the git toplevel (S4, S8) ----
|
|
93
|
+
|
|
94
|
+
const ROOTS = {
|
|
95
|
+
'/repo': '/repo',
|
|
96
|
+
'/repo/src': '/repo',
|
|
97
|
+
'/other': '/other',
|
|
98
|
+
'/other/src': '/other',
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
function countingToplevel() {
|
|
102
|
+
const calls = [];
|
|
103
|
+
const toplevel = async (dir) => {
|
|
104
|
+
calls.push(dir);
|
|
105
|
+
return ROOTS[dir];
|
|
106
|
+
};
|
|
107
|
+
return { calls, toplevel };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
test('the git toplevel of a directory is read once and cached', async () => {
|
|
111
|
+
const { calls, toplevel } = countingToplevel();
|
|
112
|
+
const resolver = createCheckoutResolver({ toplevel });
|
|
113
|
+
assert.equal(await resolver.rootOf('/repo/src'), '/repo');
|
|
114
|
+
assert.equal(await resolver.rootOf('/repo/src'), '/repo');
|
|
115
|
+
assert.deepEqual(calls, ['/repo/src'], 'one read per directory');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('a file resolves through its directory, with one git read and no repeat', async () => {
|
|
119
|
+
const { calls, toplevel } = countingToplevel();
|
|
120
|
+
const resolver = createCheckoutResolver({ toplevel, isDirectory: (dir) => dir === '/other/src' });
|
|
121
|
+
assert.equal(await resolver.rootOfPath('/other/src/a.ts'), '/other');
|
|
122
|
+
assert.deepEqual(calls, ['/other/src'], 'one local stat decides, then one git read');
|
|
123
|
+
assert.equal(await resolver.rootOfPath('/other/src/a.ts'), '/other');
|
|
124
|
+
assert.equal(await resolver.rootOfPath('/other/src/b.ts'), '/other');
|
|
125
|
+
assert.equal(await resolver.rootOfPath('/other/src'), '/other');
|
|
126
|
+
assert.deepEqual(calls, ['/other/src'], 'the directory is what git answered, once');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('a directory outside any checkout is no checkout, and a failing git is not an error', async () => {
|
|
130
|
+
const { toplevel } = countingToplevel();
|
|
131
|
+
const resolver = createCheckoutResolver({
|
|
132
|
+
toplevel: async (dir) => {
|
|
133
|
+
if (dir === '/tmp') throw new Error('git is gone');
|
|
134
|
+
return toplevel(dir);
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
assert.equal(await resolver.rootOf('/tmp'), undefined);
|
|
138
|
+
assert.equal(await resolver.rootOfPath('/nothing.ts'), undefined);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('a call went to the checkout its paths resolve to, and the session checkout is not another one', async () => {
|
|
142
|
+
const { toplevel } = countingToplevel();
|
|
143
|
+
const resolver = createCheckoutResolver({ toplevel });
|
|
144
|
+
const other = await callCheckout({ tool: 'grep', paths: ['/other/src'] }, { rootOfPath: resolver.rootOfPath, ownRoot: '/repo' });
|
|
145
|
+
assert.deepEqual(other, { root: '/other', other: true });
|
|
146
|
+
const own = await callCheckout({ tool: 'grep', paths: ['/repo/src'] }, { rootOfPath: resolver.rootOfPath, ownRoot: '/repo' });
|
|
147
|
+
assert.deepEqual(own, { root: '/repo', other: false });
|
|
148
|
+
const none = await callCheckout({ tool: 'ls', paths: ['/tmp'] }, { rootOfPath: resolver.rootOfPath, ownRoot: '/repo' });
|
|
149
|
+
assert.equal(none, undefined, 'a path outside every checkout triggers nothing');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('the first path in another checkout decides, whatever comes after it', async () => {
|
|
153
|
+
const { toplevel } = countingToplevel();
|
|
154
|
+
const resolver = createCheckoutResolver({ toplevel });
|
|
155
|
+
const found = await callCheckout({ tool: 'bash', paths: ['/repo/src', '/other/src'] }, { rootOfPath: resolver.rootOfPath, ownRoot: '/repo' });
|
|
156
|
+
assert.deepEqual(found, { root: '/other', other: true });
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('a verb after a pipe filters the previous command and is not a read of its own', () => {
|
|
160
|
+
const bash = (command) => searchCall({ toolName: 'bash', input: { command } }, '/work/repo');
|
|
161
|
+
for (const command of [
|
|
162
|
+
'curl -s https://example.com | head -5',
|
|
163
|
+
'ps aux | grep node',
|
|
164
|
+
'git log --oneline | tail -3',
|
|
165
|
+
'npm view left-pad versions | sed -n 1,3p',
|
|
166
|
+
]) {
|
|
167
|
+
assert.equal(bash(command), undefined, command);
|
|
168
|
+
}
|
|
169
|
+
// The command that does the reading still counts, with or without a filter behind it.
|
|
170
|
+
assert.ok(bash('cat src/a.ts | head -5'), 'cat reads, head filters');
|
|
171
|
+
assert.ok(bash('find . -name "*.ts" | grep foo'), 'find reads, grep filters');
|
|
172
|
+
assert.ok(bash('grep -rn foo src | head -20'), 'grep with a path reads');
|
|
173
|
+
assert.equal(bash('echo hi && curl -s x | head -2'), undefined, 'a later pipeline filters too');
|
|
174
|
+
});
|