pi-odd-worktree 3.11.2 → 3.12.1
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 +6 -4
- package/extensions/odd-worktree-tools.ts +1175 -39
- package/lib/issues-view.js +21 -4
- package/lib/odd-group.js +655 -0
- package/lib/odd-listing.js +349 -0
- package/lib/odd-rail-model.js +150 -0
- package/lib/odd-rail-section.js +453 -0
- package/lib/odd-session.js +231 -0
- package/lib/odd-view.js +500 -46
- package/lib/prs-view.js +22 -4
- package/package.json +1 -1
- package/tools/commands.test.js +58 -0
- package/tools/issues-command.test.js +13 -2
- package/tools/issues-open-guard.test.js +7 -1
- package/tools/issues-section.test.js +11 -2
- package/tools/issues-view.test.js +46 -0
- package/tools/odd-group.test.js +950 -0
- package/tools/odd-listing.test.js +504 -0
- package/tools/odd-panel-wiring.test.js +1868 -0
- package/tools/odd-rail-model.test.js +184 -0
- package/tools/odd-rail-section.test.js +524 -0
- package/tools/odd-rail-wiring.test.js +572 -0
- package/tools/odd-session-wiring.test.js +419 -0
- package/tools/odd-session.test.js +282 -0
- package/tools/odd-view.test.js +407 -1
- package/tools/package-surface.test.js +22 -6
- package/tools/prs-command.test.js +1 -1
- package/tools/prs-view.test.js +82 -0
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// T4, second half (odd-rail-section S1, S5, S6, S7, S9, S12, S13): the ODD rail
|
|
3
|
+
// section as the HOST sees it, through the fake host and the bridge's published
|
|
4
|
+
// object only.
|
|
5
|
+
//
|
|
6
|
+
// What this asserts, in the order the extension really does it:
|
|
7
|
+
// - The section is registered on the bridge with id `odd-worktree.odd-rail`, title
|
|
8
|
+
// `ODD` and `placement: { after: "agents" }` (S1), and with `Worktrees+` OFF —
|
|
9
|
+
// the corrected S7: registration is what gates the rail, never the module — and
|
|
10
|
+
// with NO bridge nothing is registered at all (the bridge object is the only
|
|
11
|
+
// gate).
|
|
12
|
+
// - The rows come from the grouped model scoped to the SESSION's registered
|
|
13
|
+
// worktrees: one row per ODD name (S12), `meta` naming the copy the click opens
|
|
14
|
+
// (S5), main's whole list when nothing is registered, and nothing from a
|
|
15
|
+
// registered worktree whose delta is empty (S13).
|
|
16
|
+
// - A `write`/`edit` recorded by T8 reorders the touched ODD first and forces an
|
|
17
|
+
// IMMEDIATE refresh — observable without any second draw, because the section's
|
|
18
|
+
// own TTL keeps `lines()` from reading again (S9).
|
|
19
|
+
// - A click dispatches exactly ONE `/odd <path>` message through the one-shot
|
|
20
|
+
// guard, a second click inside the guard window dispatches nothing, and running
|
|
21
|
+
// the command releases the guard (S6).
|
|
22
|
+
// - `session_shutdown` disposes the section: the bridge's unregister runs and the
|
|
23
|
+
// disposed section neither reads nor dispatches again.
|
|
24
|
+
//
|
|
25
|
+
// The git reads are observed through the module instance THIS load uses
|
|
26
|
+
// (`libModule('worktree-git.js').runArgvAsync`), so the evidence is the argv and
|
|
27
|
+
// the checkout each read ran in, never a count the source could satisfy some
|
|
28
|
+
// other way.
|
|
29
|
+
|
|
30
|
+
const { test, describe, after } = require('node:test');
|
|
31
|
+
const assert = require('node:assert/strict');
|
|
32
|
+
const fs = require('node:fs');
|
|
33
|
+
const os = require('node:os');
|
|
34
|
+
const path = require('node:path');
|
|
35
|
+
const { pathToFileURL } = require('node:url');
|
|
36
|
+
const { spawnSync } = require('node:child_process');
|
|
37
|
+
const {
|
|
38
|
+
BRIDGE_SLOT,
|
|
39
|
+
LIB_DIR,
|
|
40
|
+
defaultBridge,
|
|
41
|
+
stubbedSource,
|
|
42
|
+
withGhPath,
|
|
43
|
+
} = require('./fixtures/load-extension.js');
|
|
44
|
+
|
|
45
|
+
const RAIL_ID = 'odd-worktree.odd-rail';
|
|
46
|
+
const SESSION_WORKTREE_CUSTOM_TYPE = 'gentle-pi.session-worktree/v1';
|
|
47
|
+
|
|
48
|
+
const scratch = [];
|
|
49
|
+
function track(dir) {
|
|
50
|
+
scratch.push(dir);
|
|
51
|
+
return dir;
|
|
52
|
+
}
|
|
53
|
+
after(() => {
|
|
54
|
+
for (const dir of scratch) {
|
|
55
|
+
try { fs.rmSync(dir, { recursive: true, force: true }); } catch {}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
function git(cwd, args) {
|
|
60
|
+
const out = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
61
|
+
if (out.status !== 0) throw new Error(`git ${args.join(' ')} failed: ${out.stderr}`);
|
|
62
|
+
return out.stdout.trim();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// A repository whose `odd/tasks` holds two documents with deliberately distinct
|
|
66
|
+
// mtimes, so a frame can tell which order the rail drew them in.
|
|
67
|
+
function makeRepo() {
|
|
68
|
+
const dir = fs.realpathSync(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-rail-wiring-'))));
|
|
69
|
+
git(dir, ['init', '-b', 'main']);
|
|
70
|
+
git(dir, ['config', 'user.email', 'test@example.test']);
|
|
71
|
+
git(dir, ['config', 'user.name', 'Test']);
|
|
72
|
+
const tasks = path.join(dir, 'odd', 'tasks');
|
|
73
|
+
fs.mkdirSync(tasks, { recursive: true });
|
|
74
|
+
fs.writeFileSync(path.join(tasks, 'first.md'), '# body of first\n');
|
|
75
|
+
fs.writeFileSync(path.join(tasks, 'second.md'), '# body of second\n');
|
|
76
|
+
const now = Date.now() / 1000;
|
|
77
|
+
fs.utimesSync(path.join(tasks, 'first.md'), now - 100, now - 100);
|
|
78
|
+
fs.utimesSync(path.join(tasks, 'second.md'), now - 200, now - 200);
|
|
79
|
+
git(dir, ['add', '-A']);
|
|
80
|
+
git(dir, ['commit', '-m', 'init']);
|
|
81
|
+
return dir;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The worktree directory the package owns (`<repo-parent>/<repo-name>-worktrees`),
|
|
85
|
+
// which is the one the grouped model treats as owned.
|
|
86
|
+
function addWorktree(repo, name) {
|
|
87
|
+
const owned = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`);
|
|
88
|
+
fs.mkdirSync(owned, { recursive: true });
|
|
89
|
+
const root = path.join(owned, name);
|
|
90
|
+
git(repo, ['worktree', 'add', '-b', `feat/${name}`, root, 'main']);
|
|
91
|
+
return root;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function writeTask(root, name, body, secondsAgo = 0) {
|
|
95
|
+
const tasks = path.join(root, 'odd', 'tasks');
|
|
96
|
+
fs.mkdirSync(tasks, { recursive: true });
|
|
97
|
+
const file = path.join(tasks, `${name}.md`);
|
|
98
|
+
fs.writeFileSync(file, body);
|
|
99
|
+
if (secondsAgo > 0) {
|
|
100
|
+
const stamp = Date.now() / 1000 - secondsAgo;
|
|
101
|
+
fs.utimesSync(file, stamp, stamp);
|
|
102
|
+
}
|
|
103
|
+
return file;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// One extension load per test with a bridge that records what the rail registers
|
|
107
|
+
// and what it releases. `modules` is the bridge's own store document, so
|
|
108
|
+
// `{ worktrees: false }` is exactly the Worktrees+ switch a host would have.
|
|
109
|
+
let loads = 0;
|
|
110
|
+
async function load(options = {}) {
|
|
111
|
+
const opts = options !== null && typeof options === 'object' ? options : {};
|
|
112
|
+
const bridge = defaultBridge();
|
|
113
|
+
const sections = [];
|
|
114
|
+
const disposers = [];
|
|
115
|
+
const repaints = [];
|
|
116
|
+
const document = opts.modules === undefined ? undefined : { ...opts.modules };
|
|
117
|
+
bridge.api.createStore = () => ({
|
|
118
|
+
get: (key, fallback) => (key === 'modules' && document !== undefined ? document : fallback),
|
|
119
|
+
set: () => {},
|
|
120
|
+
delete: () => {},
|
|
121
|
+
});
|
|
122
|
+
bridge.api.requestRepaint = () => { repaints.push(1); };
|
|
123
|
+
bridge.api.registerSection = (section) => {
|
|
124
|
+
sections.push(section);
|
|
125
|
+
const disposer = () => {
|
|
126
|
+
disposers.push(section.id);
|
|
127
|
+
if (opts.disposerThrows === true) throw new Error('no unregister for you');
|
|
128
|
+
};
|
|
129
|
+
return disposer;
|
|
130
|
+
};
|
|
131
|
+
globalThis[BRIDGE_SLOT] = bridge.api;
|
|
132
|
+
// A host with no bridge registers nothing, so the case below removes the object
|
|
133
|
+
// and then publishes one late, exactly like the plugin's own `ready` event.
|
|
134
|
+
if (opts.noBridge === true) delete globalThis[BRIDGE_SLOT];
|
|
135
|
+
return withGhPath('present', async () => {
|
|
136
|
+
process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
|
|
137
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'odd-rail-ext-'));
|
|
138
|
+
try {
|
|
139
|
+
const copy = path.join(dir, 'odd-worktree-tools.mjs');
|
|
140
|
+
fs.writeFileSync(copy, stubbedSource());
|
|
141
|
+
loads += 1;
|
|
142
|
+
const mod = await import(`${pathToFileURL(copy).href}?load=${loads}`);
|
|
143
|
+
const commands = new Map();
|
|
144
|
+
const tools = new Map();
|
|
145
|
+
const hooks = [];
|
|
146
|
+
const ready = [];
|
|
147
|
+
const messages = [];
|
|
148
|
+
const host = {
|
|
149
|
+
registerCommand: (name, handler) => commands.set(name, handler),
|
|
150
|
+
registerTool: (tool) => tools.set(tool.name, tool),
|
|
151
|
+
registerMessageRenderer: () => {},
|
|
152
|
+
registerEntryRenderer: () => {},
|
|
153
|
+
appendEntry: () => {},
|
|
154
|
+
sendUserMessage: (text, options) => { messages.push({ text, options }); },
|
|
155
|
+
on: (event, handler) => { hooks.push([event, handler]); },
|
|
156
|
+
};
|
|
157
|
+
// A host without the event seam: the rail still registers, and the TTL stays
|
|
158
|
+
// its only refresh.
|
|
159
|
+
if (opts.noEvents !== true) {
|
|
160
|
+
// The bridge announces its publication on ONE event; a host without the
|
|
161
|
+
// seam never subscribes, so the fallback below needs it to exist.
|
|
162
|
+
host.events = {
|
|
163
|
+
on: (event, handler) => {
|
|
164
|
+
if (opts.eventsOnThrows === true) throw new Error('no listeners on this host');
|
|
165
|
+
ready.push({ event, handler });
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
mod.default(host);
|
|
170
|
+
return { mod, host, bridge, sections, disposers, repaints, commands, tools, hooks, ready, messages };
|
|
171
|
+
} finally {
|
|
172
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function sectionOf(loaded) {
|
|
178
|
+
return loaded.sections.find((section) => section && section.id === RAIL_ID);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function ctxFor(repo, registeredRoots = []) {
|
|
182
|
+
return {
|
|
183
|
+
cwd: repo,
|
|
184
|
+
hasUI: true,
|
|
185
|
+
mode: 'tui',
|
|
186
|
+
sessionManager: {
|
|
187
|
+
getSessionId: () => 'thread-1',
|
|
188
|
+
getEntries: () => registeredRoots.map((root) => ({
|
|
189
|
+
type: 'custom',
|
|
190
|
+
customType: SESSION_WORKTREE_CUSTOM_TYPE,
|
|
191
|
+
data: { sessionId: 'thread-1', root, evidence: 'session:tool' },
|
|
192
|
+
})),
|
|
193
|
+
},
|
|
194
|
+
ui: { notify: () => {}, custom: undefined, select: undefined },
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// The session_start hook is what captures the ctx the section's `load` reads.
|
|
199
|
+
function startSession(loaded, ctx) {
|
|
200
|
+
for (const [event, handler] of loaded.hooks) {
|
|
201
|
+
if (event === 'session_start') handler({}, ctx);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function shutdown(loaded, ctx) {
|
|
206
|
+
for (const [event, handler] of loaded.hooks) {
|
|
207
|
+
if (event === 'session_shutdown') handler({}, ctx);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function noteWrite(loaded, ctx, file) {
|
|
212
|
+
for (const [event, handler] of loaded.hooks) {
|
|
213
|
+
if (event !== 'tool_result') continue;
|
|
214
|
+
handler({ toolName: 'write', isError: false, input: { path: file } }, ctx);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// The rows the rail drew, as the host reads them: label, right-hand meta.
|
|
219
|
+
async function waitForRows(section, ctx, count, budgetMs = 20_000) {
|
|
220
|
+
const deadline = Date.now() + budgetMs;
|
|
221
|
+
let rows = [];
|
|
222
|
+
while (Date.now() < deadline) {
|
|
223
|
+
rows = section.lines(ctx) || [];
|
|
224
|
+
if (rows.length === count && rows.every((row) => row.label !== 'loading…')) return rows;
|
|
225
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
226
|
+
}
|
|
227
|
+
throw new Error(`timed out waiting for ${count} rows; last frame was ${JSON.stringify(rows.map((row) => row.label))}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// The same frame, twice: only a FORCED read can change it, because the section's
|
|
231
|
+
// own TTL (a minute) makes `lines()` schedule nothing.
|
|
232
|
+
async function offset(ms) {
|
|
233
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function observeGit(mod) {
|
|
237
|
+
const gitLib = mod.libModule('worktree-git.js');
|
|
238
|
+
const real = gitLib.runArgvAsync;
|
|
239
|
+
const calls = [];
|
|
240
|
+
gitLib.runArgvAsync = (bin, argv, options) => {
|
|
241
|
+
calls.push({ argv: [...argv], cwd: options && options.cwd });
|
|
242
|
+
return real.call(gitLib, bin, argv, options);
|
|
243
|
+
};
|
|
244
|
+
return {
|
|
245
|
+
calls,
|
|
246
|
+
clear: () => { calls.length = 0; },
|
|
247
|
+
listing: () => calls.filter((call) => call.argv.includes('worktree') && call.argv.includes('list')),
|
|
248
|
+
restore: () => { gitLib.runArgvAsync = real; },
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const savedBridge = globalThis[BRIDGE_SLOT];
|
|
253
|
+
after(() => {
|
|
254
|
+
if (savedBridge === undefined) delete globalThis[BRIDGE_SLOT];
|
|
255
|
+
else globalThis[BRIDGE_SLOT] = savedBridge;
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe('registration (S1, corrected S7)', () => {
|
|
259
|
+
test('the rail is registered with Worktrees+ OFF, titled ODD, right after AGENTS', async () => {
|
|
260
|
+
const loaded = await load({ modules: { codegraph: true, worktrees: false } });
|
|
261
|
+
const section = sectionOf(loaded);
|
|
262
|
+
assert.ok(section, 'the ODD rail is a section of its own');
|
|
263
|
+
assert.equal(section.title, 'ODD');
|
|
264
|
+
assert.deepEqual(section.placement, { after: 'agents' });
|
|
265
|
+
assert.equal(typeof section.lines, 'function', 'the host paints it through `lines`');
|
|
266
|
+
// Corrected S7: the rail is not one of the Worktrees+ surfaces. With that
|
|
267
|
+
// module off the worktree TOOLS are gone — and the rail is still there, so
|
|
268
|
+
// nothing it registered read `oddModules.worktrees`.
|
|
269
|
+
assert.deepEqual([...loaded.tools.keys()], [], 'Worktrees+ off registers no worktree tool');
|
|
270
|
+
assert.ok(loaded.commands.has('odd'), 'and `/odd` is still the command a click dispatches');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test('with no bridge nothing is registered, and a late publication registers it', async () => {
|
|
274
|
+
const loaded = await load({ noBridge: true });
|
|
275
|
+
assert.equal(globalThis[BRIDGE_SLOT], undefined, 'the slot really is empty');
|
|
276
|
+
assert.deepEqual(loaded.sections, [], 'nothing is contributed without a bridge');
|
|
277
|
+
|
|
278
|
+
// The plugin publishes afterwards and announces it: the ONE subscription the
|
|
279
|
+
// extension made answers with the section.
|
|
280
|
+
globalThis[BRIDGE_SLOT] = loaded.bridge.api;
|
|
281
|
+
const ready = loaded.ready.filter((entry) => entry.event === 'gentle-shell-bridge:ready');
|
|
282
|
+
assert.equal(ready.length, 1, 'one subscription for the announcement');
|
|
283
|
+
for (const entry of ready) entry.handler();
|
|
284
|
+
assert.equal(loaded.sections.filter((section) => section.id === RAIL_ID).length, 1,
|
|
285
|
+
'the late publication registers the rail once');
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
describe('the rows the rail draws (S5, S12, S13)', () => {
|
|
290
|
+
test('main only when no worktree is registered, and one row per name with `main` as meta', async () => {
|
|
291
|
+
const loaded = await load();
|
|
292
|
+
const repo = makeRepo();
|
|
293
|
+
const ctx = ctxFor(repo, []);
|
|
294
|
+
startSession(loaded, ctx);
|
|
295
|
+
const section = sectionOf(loaded);
|
|
296
|
+
const rows = await waitForRows(section, ctx, 2);
|
|
297
|
+
assert.deepEqual(rows.map((row) => [row.label, row.meta]), [['first', 'main'], ['second', 'main']],
|
|
298
|
+
'newest first, each row naming the checkout the click opens');
|
|
299
|
+
assert.equal(typeof rows[0].onClick, 'function', 'a row is clickable');
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test('a registered worktree contributes its own delta, and the newest copy of a name is elected', async () => {
|
|
303
|
+
const loaded = await load();
|
|
304
|
+
const observed = observeGit(loaded.mod);
|
|
305
|
+
try {
|
|
306
|
+
const repo = makeRepo();
|
|
307
|
+
const worktree = addWorktree(repo, 'wt-a');
|
|
308
|
+
// Byte-identical copies: nothing of its own, so it contributes no row (S13).
|
|
309
|
+
for (const name of ['first', 'second']) {
|
|
310
|
+
writeTask(worktree, name, fs.readFileSync(path.join(repo, 'odd', 'tasks', `${name}.md`), 'utf8'), 300);
|
|
311
|
+
}
|
|
312
|
+
const ctx = ctxFor(repo, [worktree]);
|
|
313
|
+
startSession(loaded, ctx);
|
|
314
|
+
const section = sectionOf(loaded);
|
|
315
|
+
const mainOnly = await waitForRows(section, ctx, 2);
|
|
316
|
+
assert.deepEqual(mainOnly.map((row) => row.meta), ['main', 'main'],
|
|
317
|
+
'a registered worktree with no delta adds no row and no chrome');
|
|
318
|
+
assert.ok(observed.listing().length > 0, 'the grouping ran, so the empty delta is a real answer');
|
|
319
|
+
|
|
320
|
+
// Now the worktree works on one of main's ODDs and on one of its own.
|
|
321
|
+
writeTask(worktree, 'second', '# body of second, changed here\n');
|
|
322
|
+
writeTask(worktree, 'wt-only', '# body of wt-only\n');
|
|
323
|
+
shutdown(loaded, ctx);
|
|
324
|
+
// A fresh load for a fresh projection: the section is a new binding.
|
|
325
|
+
const again = await load();
|
|
326
|
+
const ctxAgain = ctxFor(repo, [worktree]);
|
|
327
|
+
startSession(again, ctxAgain);
|
|
328
|
+
const rows = await waitForRows(sectionOf(again), ctxAgain, 3);
|
|
329
|
+
const byName = new Map(rows.map((row) => [row.label, row]));
|
|
330
|
+
assert.equal(byName.get('second').meta, 'wt-a', 'the newest copy is the worktree’s');
|
|
331
|
+
assert.equal(byName.get('wt-only').meta, 'wt-a', 'a worktree-only ODD is one row of its own');
|
|
332
|
+
assert.equal(byName.get('first').meta, 'main');
|
|
333
|
+
assert.equal(rows.length, 3, 'two main ODDs plus the worktree’s own, one row each');
|
|
334
|
+
assert.ok(rows.some((row) => row.label === 'second' && row.meta === 'wt-a'));
|
|
335
|
+
} finally {
|
|
336
|
+
observed.restore();
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test('the body holds four rows and one inert `N more` line (S2)', async () => {
|
|
341
|
+
const loaded = await load();
|
|
342
|
+
const repo = makeRepo();
|
|
343
|
+
for (const name of ['third', 'fourth', 'fifth', 'sixth']) {
|
|
344
|
+
writeTask(repo, name, `# body of ${name}\n`, 400);
|
|
345
|
+
}
|
|
346
|
+
git(repo, ['add', '-A']);
|
|
347
|
+
git(repo, ['commit', '-m', 'more']);
|
|
348
|
+
const ctx = ctxFor(repo, []);
|
|
349
|
+
startSession(loaded, ctx);
|
|
350
|
+
const section = sectionOf(loaded);
|
|
351
|
+
const deadline = Date.now() + 20_000;
|
|
352
|
+
let rows = [];
|
|
353
|
+
while (Date.now() < deadline) {
|
|
354
|
+
rows = section.lines(ctx) || [];
|
|
355
|
+
if (rows.length === 5 && rows[0].label !== 'loading…') break;
|
|
356
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
357
|
+
}
|
|
358
|
+
assert.equal(rows.length, 5, 'four ODDs and the elision line');
|
|
359
|
+
assert.equal(rows[4].label, '2 more');
|
|
360
|
+
assert.equal(rows[4].tone, 'dim');
|
|
361
|
+
assert.equal(rows[4].onClick, null, 'the elision row is inert');
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
describe('attribution and the click (S6, S9)', () => {
|
|
366
|
+
test('a write recorded by T8 sends its ODD first and forces the refresh', async () => {
|
|
367
|
+
const loaded = await load();
|
|
368
|
+
const repo = makeRepo();
|
|
369
|
+
const ctx = ctxFor(repo, []);
|
|
370
|
+
startSession(loaded, ctx);
|
|
371
|
+
const section = sectionOf(loaded);
|
|
372
|
+
const before = await waitForRows(section, ctx, 2);
|
|
373
|
+
assert.deepEqual(before.map((row) => row.label), ['first', 'second'], 'recency, untouched');
|
|
374
|
+
|
|
375
|
+
// A `write` landing on `second.md`: the record moves it to the front and asks
|
|
376
|
+
// for ONE refresh. Nothing here draws for it — the change must arrive through
|
|
377
|
+
// the forced read, because `lines()` inside the TTL starts no read of its own.
|
|
378
|
+
noteWrite(loaded, ctx, path.join(repo, 'odd', 'tasks', 'second.md'));
|
|
379
|
+
const deadline = Date.now() + 20_000;
|
|
380
|
+
let rows = section.lines(ctx) || [];
|
|
381
|
+
while (Date.now() < deadline) {
|
|
382
|
+
rows = section.lines(ctx) || [];
|
|
383
|
+
if (rows[0] && rows[0].label === 'second') break;
|
|
384
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
385
|
+
}
|
|
386
|
+
assert.deepEqual(rows.map((row) => row.label), ['second', 'first'],
|
|
387
|
+
'the touched ODD is first; the order came from the forced refresh, not a draw');
|
|
388
|
+
assert.ok(loaded.repaints.length > 0, 'the applied read repainted the rail');
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test('a click dispatches ONE /odd message, a second click inside the guard dispatches nothing', async () => {
|
|
392
|
+
const loaded = await load();
|
|
393
|
+
const repo = makeRepo();
|
|
394
|
+
const ctx = ctxFor(repo, []);
|
|
395
|
+
startSession(loaded, ctx);
|
|
396
|
+
const section = sectionOf(loaded);
|
|
397
|
+
const rows = await waitForRows(section, ctx, 2);
|
|
398
|
+
const target = path.join(repo, 'odd', 'tasks', 'first.md');
|
|
399
|
+
|
|
400
|
+
rows[0].onClick();
|
|
401
|
+
rows[0].onClick();
|
|
402
|
+
await offset(30);
|
|
403
|
+
assert.deepEqual(loaded.messages.map((message) => message.text), [`/odd ${target}`],
|
|
404
|
+
'exactly one dispatch, from the row the human clicked');
|
|
405
|
+
assert.deepEqual(loaded.messages[0].options, { expandPromptTemplates: true },
|
|
406
|
+
'dispatched as a prompt-template message, exactly like the issues rail');
|
|
407
|
+
|
|
408
|
+
// Running the command releases the guard, so the next click is a new open.
|
|
409
|
+
const pending = loaded.commands.get('odd').handler(target, ctx);
|
|
410
|
+
pending.catch(() => {});
|
|
411
|
+
try { await pending; } catch {}
|
|
412
|
+
rows[0].onClick();
|
|
413
|
+
await offset(30);
|
|
414
|
+
assert.equal(loaded.messages.length, 2, 'the guard was released when the command ran');
|
|
415
|
+
assert.equal(loaded.messages[1].text, `/odd ${target}`);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test('a path with a space round-trips through the click into the /odd target', async () => {
|
|
419
|
+
const loaded = await load();
|
|
420
|
+
const repo = makeRepo();
|
|
421
|
+
const spaced = writeTask(repo, 'with space', '# body of with space\n');
|
|
422
|
+
const ctx = ctxFor(repo, []);
|
|
423
|
+
startSession(loaded, ctx);
|
|
424
|
+
const section = sectionOf(loaded);
|
|
425
|
+
const deadline = Date.now() + 20_000;
|
|
426
|
+
let rows = [];
|
|
427
|
+
while (Date.now() < deadline) {
|
|
428
|
+
rows = section.lines(ctx) || [];
|
|
429
|
+
if (rows.length === 3 && rows[0].label !== 'loading…') break;
|
|
430
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
431
|
+
}
|
|
432
|
+
const row = rows.find((entry) => entry.label === 'with space');
|
|
433
|
+
assert.ok(row, `the ODD whose name holds a space is a row: ${JSON.stringify(rows.map((r) => r.label))}`);
|
|
434
|
+
row.onClick();
|
|
435
|
+
await offset(30);
|
|
436
|
+
assert.equal(loaded.messages.length, 1);
|
|
437
|
+
const message = loaded.messages[0].text;
|
|
438
|
+
// THE round-trip: the command the host runs receives the argument the same way
|
|
439
|
+
// Pi hands a `/command <args>` message over — the rest of the line, verbatim.
|
|
440
|
+
const args = message.startsWith('/odd ') ? message.slice('/odd '.length) : '';
|
|
441
|
+
assert.equal(args, spaced, 'the absolute document path travels unchanged');
|
|
442
|
+
const notify = [];
|
|
443
|
+
const oddCtx = { ...ctxFor(repo, []), ui: { notify: (text) => { notify.push(text); } } };
|
|
444
|
+
await loaded.commands.get('odd').handler(args, oddCtx);
|
|
445
|
+
// The accepted answer is the viewer's own line (this host has no overlay); a
|
|
446
|
+
// refused target answers the sentence every unknown argument has always got.
|
|
447
|
+
assert.equal(notify.some((line) => /^Unknown option "/.test(line)), false,
|
|
448
|
+
`the command accepted the spaced path instead of refusing it: ${JSON.stringify(notify)}`);
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// A host event the extension subscribed to, fired the way the host fires it.
|
|
453
|
+
function fireEvent(loaded, event) {
|
|
454
|
+
const listeners = loaded.ready.filter((entry) => entry.event === event);
|
|
455
|
+
for (const entry of listeners) entry.handler();
|
|
456
|
+
return listeners.length;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// S13: a session boundary must not leave the previous session's rows on the rail
|
|
460
|
+
// until the one-minute TTL happens to expire.
|
|
461
|
+
describe('the rail follows its session (S13)', () => {
|
|
462
|
+
test('a session_start drops the previous rows, so the next frame reloads', async () => {
|
|
463
|
+
const loaded = await load();
|
|
464
|
+
const repo = makeRepo();
|
|
465
|
+
const ctx = ctxFor(repo, []);
|
|
466
|
+
startSession(loaded, ctx);
|
|
467
|
+
const section = sectionOf(loaded);
|
|
468
|
+
const first = await waitForRows(section, ctx, 2);
|
|
469
|
+
assert.deepEqual(first.map((row) => row.label), ['first', 'second']);
|
|
470
|
+
|
|
471
|
+
// A document that exists only NOW: nothing but a reload can list it, because
|
|
472
|
+
// the section's TTL makes `lines()` schedule nothing for another minute.
|
|
473
|
+
writeTask(repo, 'third', '# body of third\n');
|
|
474
|
+
startSession(loaded, ctx);
|
|
475
|
+
const refreshed = await waitForRows(section, ctx, 3, 3000);
|
|
476
|
+
assert.deepEqual(refreshed.map((row) => row.label), ['third', 'first', 'second'],
|
|
477
|
+
'the new session reads the rail again instead of keeping the old rows');
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
test('a fired worktree-registration event forces a refresh', async () => {
|
|
481
|
+
const loaded = await load();
|
|
482
|
+
const repo = makeRepo();
|
|
483
|
+
const ctx = ctxFor(repo, []);
|
|
484
|
+
startSession(loaded, ctx);
|
|
485
|
+
const section = sectionOf(loaded);
|
|
486
|
+
await waitForRows(section, ctx, 2);
|
|
487
|
+
|
|
488
|
+
writeTask(repo, 'third', '# body of third\n');
|
|
489
|
+
assert.equal(fireEvent(loaded, 'gentle-pi:session-worktree-changed'), 1,
|
|
490
|
+
'the extension listens for the host\u2019s worktree-registration event');
|
|
491
|
+
const rows = await waitForRows(section, ctx, 3, 3000);
|
|
492
|
+
assert.deepEqual(rows.map((row) => row.label), ['third', 'first', 'second'],
|
|
493
|
+
'the event asks the section for one read');
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
test('a host without pi.events still registers the rail and draws its rows', async () => {
|
|
497
|
+
const loaded = await load({ noEvents: true });
|
|
498
|
+
const repo = makeRepo();
|
|
499
|
+
const ctx = ctxFor(repo, []);
|
|
500
|
+
startSession(loaded, ctx);
|
|
501
|
+
const section = sectionOf(loaded);
|
|
502
|
+
assert.ok(section, 'the rail registers on a host with no event seam');
|
|
503
|
+
const rows = await waitForRows(section, ctx, 2);
|
|
504
|
+
assert.deepEqual(rows.map((row) => [row.label, row.meta]), [['first', 'main'], ['second', 'main']],
|
|
505
|
+
'and the TTL keeps it fresh on its own');
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
test('a host whose event seam throws still registers the rail', async () => {
|
|
509
|
+
const loaded = await load({ eventsOnThrows: true });
|
|
510
|
+
const repo = makeRepo();
|
|
511
|
+
const ctx = ctxFor(repo, []);
|
|
512
|
+
startSession(loaded, ctx);
|
|
513
|
+
const section = sectionOf(loaded);
|
|
514
|
+
assert.ok(section, 'a throwing listener registration costs only the listener');
|
|
515
|
+
const rows = await waitForRows(section, ctx, 2);
|
|
516
|
+
assert.deepEqual(rows.map((row) => row.label), ['first', 'second']);
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
describe('teardown (S6, S9)', () => {
|
|
521
|
+
test('session_shutdown disposes the section and stops it reading and dispatching', async () => {
|
|
522
|
+
const loaded = await load();
|
|
523
|
+
const observed = observeGit(loaded.mod);
|
|
524
|
+
try {
|
|
525
|
+
const repo = makeRepo();
|
|
526
|
+
const ctx = ctxFor(repo, []);
|
|
527
|
+
startSession(loaded, ctx);
|
|
528
|
+
const section = sectionOf(loaded);
|
|
529
|
+
const rows = await waitForRows(section, ctx, 2);
|
|
530
|
+
shutdown(loaded, ctx);
|
|
531
|
+
assert.ok(loaded.disposers.includes(RAIL_ID), 'the bridge’s own unregister ran for the rail');
|
|
532
|
+
|
|
533
|
+
observed.clear();
|
|
534
|
+
section.lines(ctx);
|
|
535
|
+
rows[0].onClick();
|
|
536
|
+
noteWrite(loaded, ctx, path.join(repo, 'odd', 'tasks', 'second.md'));
|
|
537
|
+
await offset(40);
|
|
538
|
+
assert.deepEqual(observed.calls, [], 'a disposed section starts no git read');
|
|
539
|
+
assert.deepEqual(loaded.messages, [], 'and dispatches nothing');
|
|
540
|
+
} finally {
|
|
541
|
+
observed.restore();
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
test('T6 round 4: a failed worktree-list refresh never labels an unregistered checkout as main (S13)', async () => {
|
|
547
|
+
const e = await load();
|
|
548
|
+
const repo = makeRepo();
|
|
549
|
+
const linked = addWorktree(repo, 'linked');
|
|
550
|
+
writeTask(linked, 'linked-private', '# Never in session scope\n');
|
|
551
|
+
const ctx = ctxFor(linked, []);
|
|
552
|
+
startSession(e, ctx);
|
|
553
|
+
const section = sectionOf(e);
|
|
554
|
+
const gitLib = e.mod.libModule('worktree-git.js');
|
|
555
|
+
const real = gitLib.runArgvAsync;
|
|
556
|
+
let failedRead;
|
|
557
|
+
try {
|
|
558
|
+
assert.deepEqual((await waitForRows(section, ctx, 2)).map(r => r.label), ['first', 'second']);
|
|
559
|
+
gitLib.runArgvAsync = (bin, args, opts) => args.includes('worktree') && args.includes('list')
|
|
560
|
+
? (failedRead = real(bin, ['worktree', 'list', '--t6-invalid-option'], opts))
|
|
561
|
+
: real(bin, args, opts);
|
|
562
|
+
assert.equal(fireEvent(e, 'gentle-pi:session-worktree-changed'), 1);
|
|
563
|
+
for (let i = 0; !failedRead && i < 200; i += 1) await offset(10);
|
|
564
|
+
assert.ok(failedRead, 'the forced refresh reached its Git read');
|
|
565
|
+
assert.notEqual((await failedRead).status, 0);
|
|
566
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
567
|
+
assert.ok(!(section.lines(ctx) || []).some(r => r.label === 'linked-private'));
|
|
568
|
+
} finally {
|
|
569
|
+
gitLib.runArgvAsync = real;
|
|
570
|
+
shutdown(e, ctx);
|
|
571
|
+
}
|
|
572
|
+
});
|