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,419 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// T8 (odd-rail-section S8, S9): the extension's wiring of lib/odd-session.js.
|
|
3
|
+
//
|
|
4
|
+
// What the host registers, through the fake host only (the events the host really
|
|
5
|
+
// sends, the entries it really receives):
|
|
6
|
+
// - ONE `tool_result` observation that records a `write` or an `edit` landing on an
|
|
7
|
+
// `odd/tasks/*.md` document against THIS session and persists it as ONE
|
|
8
|
+
// `odd-worktree.odd-touch` entry (S8). `read`, `bash` and `grep` never do, and
|
|
9
|
+
// neither does a document outside `odd/tasks` or nested below it.
|
|
10
|
+
// - It is NOT behind `Worktrees+`: the ODD rail only exists with that module on, so the
|
|
11
|
+
// attribution has to be recording already when it is OFF, and a case here proves the
|
|
12
|
+
// touch is still registered and persisted with the module off while the existing
|
|
13
|
+
// worktree observations keep their own gate.
|
|
14
|
+
// - A FAILED result records nothing and appends nothing: `tool_result` is
|
|
15
|
+
// observed, not `tool_call`, so a write that never landed leaves no phantom row.
|
|
16
|
+
// - The persisted entry is the one shape Pi documents for a CustomEntry and the
|
|
17
|
+
// shape this package's other readers filter on, it is painted NOWHERE (no entry
|
|
18
|
+
// renderer is registered, so the transcript gains no line — verified in
|
|
19
|
+
// docs/extensions.md: a custom entry renders only when paired with
|
|
20
|
+
// `registerEntryRenderer`), and `session_start` restores them for a new and for a
|
|
21
|
+
// resumed session, so a resumed session remembers what it touched.
|
|
22
|
+
// - A registered touch asks the injected refresh callback for ONE immediate
|
|
23
|
+
// refresh; with no callback set that request is a no-op, and a touch never
|
|
24
|
+
// depends on it.
|
|
25
|
+
// - A host without an `appendEntry` seam, or one that throws, still records the
|
|
26
|
+
// touch and reports nothing.
|
|
27
|
+
// - The existing `tool_call` observations of a write on an `odd/tasks` document are
|
|
28
|
+
// unchanged (no block, no phantom entry).
|
|
29
|
+
//
|
|
30
|
+
// A SUBAGENT's write never reaches this handler — it runs in its own session — which
|
|
31
|
+
// is by design (S9): no event, no touch, and the filesystem scan is what covers it.
|
|
32
|
+
// The last case documents that rather than working around it.
|
|
33
|
+
//
|
|
34
|
+
// No fs fixture, no git: the rule is lexical, and every `cwd` below is a path that
|
|
35
|
+
// does not exist on purpose, so a git probe an existing observer makes answers
|
|
36
|
+
// "not a repository" instead of reading this machine.
|
|
37
|
+
|
|
38
|
+
const { test, describe, afterEach } = require('node:test');
|
|
39
|
+
const assert = require('node:assert/strict');
|
|
40
|
+
const fs = require('node:fs');
|
|
41
|
+
const os = require('node:os');
|
|
42
|
+
const path = require('node:path');
|
|
43
|
+
const { pathToFileURL } = require('node:url');
|
|
44
|
+
|
|
45
|
+
const {
|
|
46
|
+
BRIDGE_SLOT,
|
|
47
|
+
LIB_DIR,
|
|
48
|
+
defaultBridge,
|
|
49
|
+
loadExtension,
|
|
50
|
+
stubbedSource,
|
|
51
|
+
withGhPath,
|
|
52
|
+
} = require('./fixtures/load-extension.js');
|
|
53
|
+
|
|
54
|
+
const CWD = '/odd-session-wiring/checkout';
|
|
55
|
+
const ENTRY_TYPE = 'odd-worktree.odd-touch';
|
|
56
|
+
const TASKS = path.join(CWD, 'odd', 'tasks');
|
|
57
|
+
|
|
58
|
+
const savedBridge = globalThis[BRIDGE_SLOT];
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
if (savedBridge === undefined) delete globalThis[BRIDGE_SLOT];
|
|
61
|
+
else globalThis[BRIDGE_SLOT] = savedBridge;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// A bridge whose `modules` document is the one handed in (everything else on), which is
|
|
65
|
+
// how the Tools page turns `Worktrees+` off; `undefined` keeps the default document.
|
|
66
|
+
function publishBridge(modules) {
|
|
67
|
+
const bridge = defaultBridge();
|
|
68
|
+
if (modules !== undefined) {
|
|
69
|
+
bridge.api.createStore = () => ({
|
|
70
|
+
get: (key, fallback) => (key === 'modules' ? modules : fallback),
|
|
71
|
+
set: () => {},
|
|
72
|
+
delete: () => {},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
globalThis[BRIDGE_SLOT] = bridge.api;
|
|
76
|
+
return bridge;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// The extension's own module namespace, which the shared fixture's loader does not
|
|
80
|
+
// return: the record lives on module scope (`oddSession`), like this package's other
|
|
81
|
+
// test seams (`libModule`, `setWarpTuiLoader`, ...), so the assertions read it there.
|
|
82
|
+
// Everything else is the fixture's setup — the same stubbed source, the same lib
|
|
83
|
+
// override and the same published bridge.
|
|
84
|
+
async function loadModule(options = {}) {
|
|
85
|
+
const opts = options !== null && typeof options === 'object' ? options : {};
|
|
86
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'odd-session-wiring-'));
|
|
87
|
+
try {
|
|
88
|
+
const copy = path.join(dir, 'odd-worktree-tools.mjs');
|
|
89
|
+
fs.writeFileSync(copy, stubbedSource());
|
|
90
|
+
process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
|
|
91
|
+
const mod = await import(pathToFileURL(copy).href);
|
|
92
|
+
const hooks = [];
|
|
93
|
+
const entries = [];
|
|
94
|
+
const entryRenderers = new Map();
|
|
95
|
+
const host = {
|
|
96
|
+
registerCommand: () => {},
|
|
97
|
+
registerTool: () => {},
|
|
98
|
+
registerMessageRenderer: () => {},
|
|
99
|
+
registerEntryRenderer: (type, renderer) => { entryRenderers.set(type, renderer); },
|
|
100
|
+
on: (event, handler) => { hooks.push([event, handler]); },
|
|
101
|
+
};
|
|
102
|
+
// T8: the guard `warpAppendQueueEntry` uses — a host may have no seam, and a seam
|
|
103
|
+
// that throws is the same "nothing to persist" — is only observable if the host
|
|
104
|
+
// can be built without one.
|
|
105
|
+
if (opts.appendEntry !== 'absent') {
|
|
106
|
+
host.appendEntry = (customType, data) => {
|
|
107
|
+
if (opts.appendEntry === 'throwing') throw new Error('no entry for you');
|
|
108
|
+
entries.push({ customType, data });
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
mod.default(host);
|
|
112
|
+
return { mod, host, hooks, entries, entryRenderers };
|
|
113
|
+
} finally {
|
|
114
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// The fixture's own `gh` PATH switch, so the presence probe is deterministic and no case
|
|
119
|
+
// depends on the machine it runs on (this suite registers no `gh` surface, but the load
|
|
120
|
+
// does run that probe).
|
|
121
|
+
const presentGh = (run) => withGhPath('present', run);
|
|
122
|
+
|
|
123
|
+
const handlersOf = (loaded, event) => loaded.hooks.filter(([name]) => name === event).map(([, handler]) => handler);
|
|
124
|
+
|
|
125
|
+
function ctxOf(entries = [], calls = []) {
|
|
126
|
+
return {
|
|
127
|
+
cwd: CWD,
|
|
128
|
+
hasUI: false,
|
|
129
|
+
ui: { notify: () => {} },
|
|
130
|
+
sessionManager: {
|
|
131
|
+
getEntries: () => {
|
|
132
|
+
calls.push('getEntries');
|
|
133
|
+
return entries;
|
|
134
|
+
},
|
|
135
|
+
getSessionFile: () => undefined,
|
|
136
|
+
getSessionId: () => 'session-1',
|
|
137
|
+
getLeafId: () => null,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// The host's own delivery: every handler of that event, in registration order, one at
|
|
143
|
+
// a time, awaited the way the host awaits them.
|
|
144
|
+
async function fire(loaded, event, payload, ctx) {
|
|
145
|
+
const results = [];
|
|
146
|
+
for (const handler of handlersOf(loaded, event)) {
|
|
147
|
+
results.push(await handler(payload, ctx));
|
|
148
|
+
}
|
|
149
|
+
return results;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const writeEvent = (target = 'odd/tasks/alpha.md', extra = {}) => ({
|
|
153
|
+
toolName: 'write',
|
|
154
|
+
toolCallId: 'call-1',
|
|
155
|
+
input: { path: target, content: '# alpha' },
|
|
156
|
+
isError: false,
|
|
157
|
+
...extra,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const touches = (loaded) => (loaded.mod.oddSession === null ? [] : loaded.mod.oddSession.touched());
|
|
161
|
+
const touchEntries = (loaded) => loaded.entries.filter((entry) => entry.customType === ENTRY_TYPE);
|
|
162
|
+
|
|
163
|
+
describe('a write or an edit on an odd/tasks document (S8)', () => {
|
|
164
|
+
test('is recorded against this session and persisted as ONE entry that paints nothing', async () => {
|
|
165
|
+
await presentGh(async () => {
|
|
166
|
+
publishBridge(undefined);
|
|
167
|
+
const loaded = await loadModule();
|
|
168
|
+
assert.ok(loaded.mod.oddSession, 'the record exists once the worktree module registers');
|
|
169
|
+
assert.equal(loaded.entryRenderers.has(ENTRY_TYPE), false, 'an unrendered entry draws no transcript line');
|
|
170
|
+
|
|
171
|
+
await fire(loaded, 'tool_result', writeEvent(), ctxOf());
|
|
172
|
+
|
|
173
|
+
const persisted = touchEntries(loaded);
|
|
174
|
+
assert.equal(persisted.length, 1);
|
|
175
|
+
assert.deepEqual(Object.keys(persisted[0]).sort(), ['customType', 'data']);
|
|
176
|
+
assert.deepEqual(Object.keys(persisted[0].data).sort(), ['at', 'path']);
|
|
177
|
+
assert.equal(persisted[0].data.path, path.join(TASKS, 'alpha.md'));
|
|
178
|
+
assert.equal(Number.isFinite(persisted[0].data.at), true);
|
|
179
|
+
assert.deepEqual(touches(loaded), [
|
|
180
|
+
{ path: path.join(TASKS, 'alpha.md'), name: 'alpha', at: persisted[0].data.at },
|
|
181
|
+
]);
|
|
182
|
+
|
|
183
|
+
await fire(loaded, 'tool_result', { ...writeEvent('odd/tasks/beta.md'), toolName: 'edit' }, ctxOf());
|
|
184
|
+
assert.deepEqual(touches(loaded).map((touch) => touch.name), ['beta', 'alpha']);
|
|
185
|
+
assert.deepEqual(touchEntries(loaded).map((entry) => entry.data.path), [
|
|
186
|
+
path.join(TASKS, 'alpha.md'),
|
|
187
|
+
path.join(TASKS, 'beta.md'),
|
|
188
|
+
]);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('a relative target is persisted absolute, resolved against the call’s cwd', async () => {
|
|
193
|
+
await presentGh(async () => {
|
|
194
|
+
publishBridge(undefined);
|
|
195
|
+
const loaded = await loadModule();
|
|
196
|
+
await fire(loaded, 'tool_result', writeEvent('./odd/tasks/../tasks/alpha.md'), ctxOf());
|
|
197
|
+
assert.deepEqual(touchEntries(loaded).map((entry) => entry.data.path), [path.join(TASKS, 'alpha.md')]);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('a re-touch moves the document to the front while the record keeps one row per document', async () => {
|
|
202
|
+
await presentGh(async () => {
|
|
203
|
+
publishBridge(undefined);
|
|
204
|
+
const loaded = await loadModule();
|
|
205
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/alpha.md'), ctxOf());
|
|
206
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/beta.md'), ctxOf());
|
|
207
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/alpha.md'), ctxOf());
|
|
208
|
+
assert.deepEqual(touches(loaded).map((touch) => touch.name), ['alpha', 'beta']);
|
|
209
|
+
// ONE entry per observation: the persisted sequence lets a later `restore`
|
|
210
|
+
// keep the newest `at`, which is why the record itself never repeats a path.
|
|
211
|
+
assert.deepEqual(touchEntries(loaded).map((entry) => entry.data.path), [
|
|
212
|
+
path.join(TASKS, 'alpha.md'),
|
|
213
|
+
path.join(TASKS, 'beta.md'),
|
|
214
|
+
path.join(TASKS, 'alpha.md'),
|
|
215
|
+
]);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('every other tool and every non-document target registers nothing', async () => {
|
|
220
|
+
await presentGh(async () => {
|
|
221
|
+
publishBridge(undefined);
|
|
222
|
+
const loaded = await loadModule();
|
|
223
|
+
for (const toolName of ['read', 'bash', 'grep', 'find', 'ls', 'worktree_create']) {
|
|
224
|
+
await fire(loaded, 'tool_result', { ...writeEvent(), toolName }, ctxOf());
|
|
225
|
+
}
|
|
226
|
+
for (const target of ['docs/alpha.md', 'odd/alpha.md', 'odd/tasks/nested/alpha.md', 'odd/tasks/.alpha.md', 'odd/tasks/alpha.txt']) {
|
|
227
|
+
await fire(loaded, 'tool_result', writeEvent(target), ctxOf());
|
|
228
|
+
}
|
|
229
|
+
assert.deepEqual(touches(loaded), []);
|
|
230
|
+
assert.deepEqual(loaded.entries, []);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('a FAILED write leaves no row and no entry', async () => {
|
|
235
|
+
await presentGh(async () => {
|
|
236
|
+
publishBridge(undefined);
|
|
237
|
+
const loaded = await loadModule();
|
|
238
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/alpha.md', { isError: true }), ctxOf());
|
|
239
|
+
assert.deepEqual(touches(loaded), []);
|
|
240
|
+
assert.deepEqual(loaded.entries, []);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('asks for one immediate refresh, and an unset callback is a no-op', async () => {
|
|
245
|
+
await presentGh(async () => {
|
|
246
|
+
publishBridge(undefined);
|
|
247
|
+
const loaded = await loadModule();
|
|
248
|
+
// No callback set: the touch still lands.
|
|
249
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/alpha.md'), ctxOf());
|
|
250
|
+
assert.equal(touches(loaded).length, 1);
|
|
251
|
+
|
|
252
|
+
const requested = [];
|
|
253
|
+
loaded.mod.setOddSessionRefresh(() => requested.push('refresh'));
|
|
254
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/beta.md'), ctxOf());
|
|
255
|
+
await fire(loaded, 'tool_result', { ...writeEvent('odd/tasks/gamma.md'), toolName: 'read' }, ctxOf());
|
|
256
|
+
assert.equal(requested.length, 1);
|
|
257
|
+
// Unsetting it is the same no-op as never setting it.
|
|
258
|
+
loaded.mod.setOddSessionRefresh(null);
|
|
259
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/delta.md'), ctxOf());
|
|
260
|
+
assert.equal(requested.length, 1);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test('a host without the appendEntry seam, or one that throws, still records the touch', async () => {
|
|
265
|
+
await presentGh(async () => {
|
|
266
|
+
for (const seam of ['absent', 'throwing']) {
|
|
267
|
+
publishBridge(undefined);
|
|
268
|
+
const loaded = await loadModule({ appendEntry: seam });
|
|
269
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/alpha.md'), ctxOf());
|
|
270
|
+
assert.deepEqual(touches(loaded).map((touch) => touch.name), ['alpha'], seam);
|
|
271
|
+
assert.deepEqual(loaded.entries, [], seam);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe('the session boundary (S8/S9)', () => {
|
|
278
|
+
// Pi's CustomEntry shape (docs/session-format.md), which is what every reader in
|
|
279
|
+
// this package filters on: `type === "custom"`, `customType`, `data`.
|
|
280
|
+
const touchEntry = (id, file, at) => ({
|
|
281
|
+
type: 'custom',
|
|
282
|
+
id,
|
|
283
|
+
parentId: null,
|
|
284
|
+
timestamp: new Date(at).toISOString(),
|
|
285
|
+
customType: ENTRY_TYPE,
|
|
286
|
+
data: { path: path.join(TASKS, file), at },
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('a resumed session remembers what it touched, and a new one restores the same way', async () => {
|
|
290
|
+
await presentGh(async () => {
|
|
291
|
+
publishBridge(undefined);
|
|
292
|
+
const loaded = await loadModule();
|
|
293
|
+
assert.deepEqual(touches(loaded), []);
|
|
294
|
+
const persisted = [
|
|
295
|
+
{ type: 'message', id: 'm', role: 'user' },
|
|
296
|
+
touchEntry('a', 'alpha.md', 1000),
|
|
297
|
+
{ type: 'custom', customType: 'odd-worktree.other', data: { path: '/x/odd/tasks/nope.md', at: 2000 } },
|
|
298
|
+
touchEntry('b', 'beta.md', 3000),
|
|
299
|
+
];
|
|
300
|
+
const calls = [];
|
|
301
|
+
await fire(loaded, 'session_start', { reason: 'resume' }, ctxOf(persisted, calls));
|
|
302
|
+
assert.deepEqual(touches(loaded).map((touch) => touch.name), ['beta', 'alpha']);
|
|
303
|
+
assert.ok(calls.length > 0, 'the handler reads the session manager’s own entries');
|
|
304
|
+
|
|
305
|
+
loaded.mod.oddSession.clear();
|
|
306
|
+
assert.deepEqual(touches(loaded), []);
|
|
307
|
+
await fire(loaded, 'session_start', { reason: 'new' }, ctxOf(persisted, calls));
|
|
308
|
+
assert.deepEqual(touches(loaded).map((touch) => touch.name), ['beta', 'alpha']);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('a resumed session then records a new touch on top of the restored ones', async () => {
|
|
313
|
+
await presentGh(async () => {
|
|
314
|
+
publishBridge(undefined);
|
|
315
|
+
const loaded = await loadModule();
|
|
316
|
+
await fire(loaded, 'session_start', { reason: 'resume' }, ctxOf([touchEntry('a', 'alpha.md', 1000)]));
|
|
317
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/gamma.md'), ctxOf());
|
|
318
|
+
assert.deepEqual(touches(loaded).map((touch) => touch.name), ['gamma', 'alpha']);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
test('a session manager that cannot answer restores nothing and throws nothing', async () => {
|
|
323
|
+
await presentGh(async () => {
|
|
324
|
+
publishBridge(undefined);
|
|
325
|
+
const loaded = await loadModule();
|
|
326
|
+
const broken = {
|
|
327
|
+
cwd: CWD,
|
|
328
|
+
ui: { notify: () => {} },
|
|
329
|
+
sessionManager: {
|
|
330
|
+
getEntries: () => {
|
|
331
|
+
throw new Error('no entries');
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
await fire(loaded, 'session_start', { reason: 'resume' }, broken);
|
|
336
|
+
assert.deepEqual(touches(loaded), []);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
describe('a subagent’s write (S9)', () => {
|
|
342
|
+
test('never reaches this session’s record: no event, no touch', async () => {
|
|
343
|
+
await presentGh(async () => {
|
|
344
|
+
publishBridge(undefined);
|
|
345
|
+
const loaded = await loadModule();
|
|
346
|
+
// A subagent runs in its OWN session, so its `write` of an `odd/tasks` document
|
|
347
|
+
// is observed by its own handler and by nobody else. The parent's record grows
|
|
348
|
+
// only from an event the parent's own host delivers — there is none here — and
|
|
349
|
+
// the document is covered by the filesystem scan, which is the source of truth
|
|
350
|
+
// for existence, location and recency (S9).
|
|
351
|
+
await fire(loaded, 'session_start', { reason: 'startup' }, ctxOf([]));
|
|
352
|
+
assert.deepEqual(touches(loaded), []);
|
|
353
|
+
assert.deepEqual(loaded.entries, []);
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
describe('the module switch and the neighbouring observations', () => {
|
|
359
|
+
test('with Worktrees+ OFF a write or an edit of an odd/tasks document is STILL recorded and persisted', async () => {
|
|
360
|
+
await presentGh(async () => {
|
|
361
|
+
publishBridge({ worktrees: false });
|
|
362
|
+
const loaded = await loadModule();
|
|
363
|
+
// The ODD rail is `Worktrees+`'s surface, so the attribution of what this session
|
|
364
|
+
// writes cannot be behind that switch: the record exists and grows with the module
|
|
365
|
+
// off, and a resumed session restores it there too.
|
|
366
|
+
assert.ok(loaded.mod.oddSession, 'the record exists with the worktree module off');
|
|
367
|
+
await fire(loaded, 'tool_result', writeEvent('odd/tasks/alpha.md'), ctxOf());
|
|
368
|
+
await fire(loaded, 'tool_result', { ...writeEvent('odd/tasks/beta.md'), toolName: 'edit' }, ctxOf());
|
|
369
|
+
assert.deepEqual(touches(loaded).map((touch) => touch.name), ['beta', 'alpha']);
|
|
370
|
+
assert.deepEqual(touchEntries(loaded).map((entry) => entry.data.path), [
|
|
371
|
+
path.join(TASKS, 'alpha.md'),
|
|
372
|
+
path.join(TASKS, 'beta.md'),
|
|
373
|
+
]);
|
|
374
|
+
await fire(loaded, 'session_start', { reason: 'resume' }, ctxOf([
|
|
375
|
+
{
|
|
376
|
+
type: 'custom',
|
|
377
|
+
id: 'a',
|
|
378
|
+
parentId: null,
|
|
379
|
+
timestamp: new Date(1000).toISOString(),
|
|
380
|
+
customType: ENTRY_TYPE,
|
|
381
|
+
data: { path: path.join(TASKS, 'gamma.md'), at: 1000 },
|
|
382
|
+
},
|
|
383
|
+
]));
|
|
384
|
+
assert.deepEqual(touches(loaded).map((touch) => touch.name), ['gamma']);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// The shared fixture's own fake host, which is what a suite that asserts the
|
|
389
|
+
// registered surface uses.
|
|
390
|
+
test('only the existing worktree observations stay behind the switch: the touch one does not', async () => {
|
|
391
|
+
await presentGh(async () => {
|
|
392
|
+
publishBridge(undefined);
|
|
393
|
+
const on = await loadExtension({});
|
|
394
|
+
publishBridge({ worktrees: false });
|
|
395
|
+
const off = await loadExtension({});
|
|
396
|
+
const onToolResult = handlersOf(on, 'tool_result').length;
|
|
397
|
+
const offToolResult = handlersOf(off, 'tool_result').length;
|
|
398
|
+
// Exactly ONE `tool_result` observation is the worktree half's: the ODD-naming
|
|
399
|
+
// observer. The touch observation and the issues one are NOT, so the gap is one.
|
|
400
|
+
assert.equal(onToolResult - offToolResult, 1);
|
|
401
|
+
assert.ok(offToolResult >= 2, 'the touch observation is still registered with the module off');
|
|
402
|
+
|
|
403
|
+
const ctx = ctxOf();
|
|
404
|
+
for (const handler of handlersOf(off, 'tool_result')) await handler(writeEvent(), ctx);
|
|
405
|
+
assert.deepEqual(off.entries.map((entry) => entry.customType), [ENTRY_TYPE]);
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test('a write on an odd/tasks document reaches the existing tool_call observations unchanged', async () => {
|
|
410
|
+
await presentGh(async () => {
|
|
411
|
+
publishBridge(undefined);
|
|
412
|
+
const loaded = await loadModule();
|
|
413
|
+
const results = await fire(loaded, 'tool_call', writeEvent(), ctxOf());
|
|
414
|
+
assert.ok(results.length >= 4, 'the naming observer and the guards are all still there');
|
|
415
|
+
for (const result of results) assert.equal(result, undefined, 'nothing blocks a write on an odd document');
|
|
416
|
+
assert.deepEqual(touches(loaded), [], 'a call that has not finished is not a touch');
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
});
|