pi-odd-worktree 2.1.0 → 3.0.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 +54 -319
- package/extensions/odd-worktree-tools.ts +4182 -2539
- package/lib/bash-activity.js +1166 -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 +1421 -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 +323 -15
- 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 +1420 -0
- package/tools/bash-design.test.js +1093 -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 +613 -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 +1889 -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 +417 -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 +1517 -67
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4235 -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
|
@@ -29,17 +29,21 @@
|
|
|
29
29
|
// instance the extension loads via GENTLE_WORKTREE_LIB_DIR), so no live `gh`
|
|
30
30
|
// runs and no real GitHub mutation is possible.
|
|
31
31
|
|
|
32
|
-
const { test, describe, after, afterEach } = require('node:test');
|
|
32
|
+
const { test, describe, after, afterEach, beforeEach } = require('node:test');
|
|
33
33
|
const assert = require('node:assert/strict');
|
|
34
34
|
const fs = require('node:fs');
|
|
35
35
|
const os = require('node:os');
|
|
36
36
|
const path = require('node:path');
|
|
37
37
|
const { execFileSync } = require('node:child_process');
|
|
38
38
|
const { pathToFileURL } = require('node:url');
|
|
39
|
-
const { LIB_DIR, stubbedSource } = require('./fixtures/load-extension.js');
|
|
39
|
+
const { LIB_DIR, stubbedSource, installDefaultBridge, withGhPath } = require('./fixtures/load-extension.js');
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
// The client and git seam the extension itself loaded. One extension load compiles
|
|
42
|
+
// its own lib modules, so a fake must reach THAT instance — the extension's
|
|
43
|
+
// `libModule` seam — instead of a separate `require` of the same path. Each load
|
|
44
|
+
// below rebinds these, so a case always patches the instance its handler uses.
|
|
45
|
+
let ghIssues = require('../lib/gh-issues.js');
|
|
46
|
+
let worktreeGit = require('../lib/worktree-git.js');
|
|
43
47
|
|
|
44
48
|
const roots = [];
|
|
45
49
|
after(() => {
|
|
@@ -78,6 +82,22 @@ after(() => {
|
|
|
78
82
|
|
|
79
83
|
afterEach(() => {
|
|
80
84
|
ghIssues.setGhRunner(null);
|
|
85
|
+
ghIssues.setGhWhich(null);
|
|
86
|
+
// S5 (T8): the gate's clock seam and its cache are process state too; every
|
|
87
|
+
// test loads its own extension instance, and a leftover fake clock must not
|
|
88
|
+
// reach the next one.
|
|
89
|
+
if (typeof ghIssues.setGateClock === 'function') ghIssues.setGateClock(null);
|
|
90
|
+
if (typeof ghIssues.clearCachedGhStatus === 'function') ghIssues.clearCachedGhStatus();
|
|
91
|
+
// S8 (T4): the rail's published bridge is process-wide, so no test may leave
|
|
92
|
+
// one behind for the next.
|
|
93
|
+
delete globalThis[Symbol.for('gentle-shell-bridge/api/v1')];
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// S4 (T3): the read cache has a disk half now, so every test gets its own cache
|
|
97
|
+
// directory — no test inherits a warm identity from another, and nothing here can
|
|
98
|
+
// touch the real `$XDG_CACHE_HOME`/home.
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
process.env.XDG_CACHE_HOME = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-cache-')));
|
|
81
101
|
});
|
|
82
102
|
|
|
83
103
|
const FIXTURES = path.join(__dirname, 'fixtures');
|
|
@@ -87,40 +107,75 @@ function fixture(name) {
|
|
|
87
107
|
|
|
88
108
|
// A fresh copy per load: module-level gate state belongs to one runtime load,
|
|
89
109
|
// exactly like the host's rebuilt command registry.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
//
|
|
111
|
+
// S13 (T11): the issues surfaces are registered only when the local presence probe
|
|
112
|
+
// finds `gh`, and that probe reads PATH (the extension compiles its own
|
|
113
|
+
// `lib/gh-issues.js`, so a seam set here would not reach it). The load therefore
|
|
114
|
+
// runs with a PATH that answers the way the case asked — present unless it passes
|
|
115
|
+
// `{ gh: false }` — so the machine the suite runs on decides nothing.
|
|
116
|
+
async function loadExtension(options = {}) {
|
|
117
|
+
// S18 (T14): the extension registers nothing without gentle-shell-bridge, so
|
|
118
|
+
// this file's own host publishes the shared fixture's bridge before the load.
|
|
119
|
+
installDefaultBridge();
|
|
120
|
+
return withGhPath(options && options.gh === false ? 'absent' : 'present', async () => {
|
|
121
|
+
const dir = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-ext-')));
|
|
122
|
+
const copy = path.join(dir, 'odd-worktree-tools.mjs');
|
|
123
|
+
fs.writeFileSync(copy, stubbedSource());
|
|
124
|
+
const commands = new Map();
|
|
125
|
+
const hooks = [];
|
|
126
|
+
const api = {
|
|
127
|
+
registerTool: () => {},
|
|
128
|
+
registerCommand: (name, definition) => { commands.set(name, definition); },
|
|
129
|
+
registerMessageRenderer: () => {},
|
|
130
|
+
on: (event, handler) => { hooks.push([event, handler]); return () => {}; },
|
|
131
|
+
};
|
|
132
|
+
process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
|
|
133
|
+
const mod = await import(pathToFileURL(copy).href);
|
|
134
|
+
const factory = mod.default;
|
|
135
|
+
factory(api);
|
|
136
|
+
ghIssues = mod.libModule('gh-issues.js');
|
|
137
|
+
worktreeGit = mod.libModule('worktree-git.js');
|
|
138
|
+
modsFor.set(hooks, mod);
|
|
139
|
+
return { commands, hooks, api, mod, factory };
|
|
140
|
+
});
|
|
109
141
|
}
|
|
110
142
|
|
|
111
143
|
function sessionStartHandlers(hooks) {
|
|
112
144
|
return hooks.filter(([event]) => event === 'session_start').map(([, handler]) => handler);
|
|
113
145
|
}
|
|
114
146
|
|
|
147
|
+
// The module one load produced, keyed by the hooks it registered: the startup work
|
|
148
|
+
// `session_start` DISPATCHES (never awaits, T1) is reachable only through it.
|
|
149
|
+
const modsFor = new Map();
|
|
150
|
+
|
|
115
151
|
async function fireSessionStart(hooks, ctx) {
|
|
116
152
|
for (const handler of sessionStartHandlers(hooks)) {
|
|
117
153
|
const out = handler({}, ctx);
|
|
118
154
|
if (out && typeof out.then === 'function') await out;
|
|
119
155
|
}
|
|
156
|
+
// S1/S2 (T1): the `gh` gate is no longer on the AWAITED path — it is dispatched
|
|
157
|
+
// as tracked startup work — so a test that asserts on the gate's own answer
|
|
158
|
+
// waits for that work here, the way the host's shutdown barrier does, instead of
|
|
159
|
+
// racing it. The one test that proves the awaited path is free of it fires the
|
|
160
|
+
// handlers itself and never reaches this helper.
|
|
161
|
+
const mod = modsFor.get(hooks);
|
|
162
|
+
if (mod && typeof mod.awaitPendingStartupTasks === 'function') {
|
|
163
|
+
await mod.awaitPendingStartupTasks();
|
|
164
|
+
}
|
|
120
165
|
}
|
|
121
166
|
|
|
167
|
+
// This file is about the `gh` gate and the panel. The missing-bridge hint is another surface
|
|
168
|
+
// (tools/issues-section.test.js owns it) and it fires ONCE per process, so which test here saw it
|
|
169
|
+
// first would depend on execution order: a test that counts notifications passed only because an
|
|
170
|
+
// earlier one had already consumed the hint. The fixtures leave it out, so every count below means
|
|
171
|
+
// the same thing alone or in the full run.
|
|
172
|
+
const BRIDGE_HINT = /gentle-shell-bridge/;
|
|
173
|
+
const recordNote = (notes) => (message, level) => {
|
|
174
|
+
if (!BRIDGE_HINT.test(String(message))) notes.push([message, level]);
|
|
175
|
+
};
|
|
176
|
+
|
|
122
177
|
function gateCtx(cwd, notes) {
|
|
123
|
-
return { cwd, ui: { notify: (
|
|
178
|
+
return { cwd, ui: { notify: recordNote(notes) } };
|
|
124
179
|
}
|
|
125
180
|
|
|
126
181
|
const stubTui = {
|
|
@@ -136,12 +191,14 @@ const stubTui = {
|
|
|
136
191
|
function makeHostTui(rows = 24) {
|
|
137
192
|
const paints = [];
|
|
138
193
|
const lifecycle = [];
|
|
194
|
+
const stops = [];
|
|
139
195
|
return {
|
|
140
196
|
paints,
|
|
141
197
|
lifecycle,
|
|
198
|
+
stops,
|
|
142
199
|
tui: {
|
|
143
200
|
terminal: { rows },
|
|
144
|
-
stop: () => lifecycle.push('stop'),
|
|
201
|
+
stop: (options) => { lifecycle.push('stop'); stops.push(options); },
|
|
145
202
|
start: () => lifecycle.push('start'),
|
|
146
203
|
requestRender: (force) => { lifecycle.push('render'); paints.push(force === true); },
|
|
147
204
|
},
|
|
@@ -155,7 +212,7 @@ function makeCtx({ cwd, customImpl } = {}) {
|
|
|
155
212
|
const ctx = {
|
|
156
213
|
cwd,
|
|
157
214
|
ui: {
|
|
158
|
-
notify: (
|
|
215
|
+
notify: recordNote(notes),
|
|
159
216
|
select: async (title, options) => { selects.push([title, options]); return undefined; },
|
|
160
217
|
},
|
|
161
218
|
};
|
|
@@ -189,16 +246,26 @@ async function waitFor(predicate, timeoutMs = 2000) {
|
|
|
189
246
|
const clean = (value) => String(value).replace(/\x1b\[[0-9;]*m/g, '');
|
|
190
247
|
|
|
191
248
|
// Captures the options the extension mounts the real view with, leaving every
|
|
192
|
-
// client call real and injectable.
|
|
249
|
+
// client call real and injectable. The patched module is the extension's OWN view
|
|
250
|
+
// instance (`attach`), taken from the load that will mount it.
|
|
193
251
|
function captureIssuesView() {
|
|
194
|
-
const lib = require('../lib/issues-view.js');
|
|
195
|
-
const original = lib.createIssuesView;
|
|
196
252
|
const holder = { options: null };
|
|
197
|
-
lib
|
|
198
|
-
|
|
199
|
-
|
|
253
|
+
let lib;
|
|
254
|
+
let original;
|
|
255
|
+
return {
|
|
256
|
+
holder,
|
|
257
|
+
attach(mod) {
|
|
258
|
+
lib = mod.libModule('issues-view.js');
|
|
259
|
+
original = lib.createIssuesView;
|
|
260
|
+
lib.createIssuesView = (options) => {
|
|
261
|
+
holder.options = options;
|
|
262
|
+
return { render: () => [], handleInput: () => {}, invalidate: () => {} };
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
restore() {
|
|
266
|
+
if (lib) lib.createIssuesView = original;
|
|
267
|
+
},
|
|
200
268
|
};
|
|
201
|
-
return { holder, restore: () => { lib.createIssuesView = original; } };
|
|
202
269
|
}
|
|
203
270
|
|
|
204
271
|
// One issue node in the shape both GraphQL page queries ask for.
|
|
@@ -316,7 +383,7 @@ function makeIssuesRunner({ failComment = false, role = 'WRITE', connectionRows
|
|
|
316
383
|
viewerPermission: role,
|
|
317
384
|
issue: {
|
|
318
385
|
assignees: { nodes: [{ login: 'jonasotoaguilar' }], pageInfo: { hasNextPage: false } },
|
|
319
|
-
closedByPullRequestsReferences: {
|
|
386
|
+
closedByPullRequestsReferences: { nodes: [{ number: 69 }, { number: 77 }], pageInfo: { hasNextPage: false } },
|
|
320
387
|
},
|
|
321
388
|
} } }));
|
|
322
389
|
}
|
|
@@ -353,8 +420,11 @@ function registryFile(root) {
|
|
|
353
420
|
// Gate the extension through session_start with a scratch cwd (so the
|
|
354
421
|
// unrelated worktree discovery never touches the fixture repo), then run the
|
|
355
422
|
// command handler against the fixture checkout.
|
|
356
|
-
async function openIssues(root, { runner, rows = 24 } = {}) {
|
|
423
|
+
async function openIssues(root, { runner, rows = 24, prepare, args = '' } = {}) {
|
|
357
424
|
const loaded = await loadExtension();
|
|
425
|
+
// `prepare` receives the load that is about to run the command, so a test's fake
|
|
426
|
+
// lands on the instance the command actually mounts.
|
|
427
|
+
if (typeof prepare === 'function') prepare(loaded.mod);
|
|
358
428
|
ghIssues.setGhRunner(runner || makeIssuesRunner().runner);
|
|
359
429
|
const scratch = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-gate-')));
|
|
360
430
|
await fireSessionStart(loaded.hooks, gateCtx(scratch, []));
|
|
@@ -367,7 +437,7 @@ async function openIssues(root, { runner, rows = 24 } = {}) {
|
|
|
367
437
|
cwd: root,
|
|
368
438
|
customImpl: async (captured) => { factory = captured; return null; },
|
|
369
439
|
});
|
|
370
|
-
await def.handler(
|
|
440
|
+
await def.handler(args, ctx);
|
|
371
441
|
assert.ok(factory, 'the overlay opens');
|
|
372
442
|
const { component, done } = openComponent(factory, host);
|
|
373
443
|
await tick();
|
|
@@ -383,6 +453,7 @@ async function capturedIssuesOptions(root, options = {}) {
|
|
|
383
453
|
const capture = captureIssuesView();
|
|
384
454
|
try {
|
|
385
455
|
const loaded = await loadExtension();
|
|
456
|
+
capture.attach(loaded.mod);
|
|
386
457
|
ghIssues.setGhRunner(injected.runner);
|
|
387
458
|
const scratch = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-gate-')));
|
|
388
459
|
await fireSessionStart(loaded.hooks, gateCtx(scratch, []));
|
|
@@ -393,7 +464,7 @@ async function capturedIssuesOptions(root, options = {}) {
|
|
|
393
464
|
factory(host.tui, {}, {}, () => {});
|
|
394
465
|
return null;
|
|
395
466
|
};
|
|
396
|
-
await loaded.commands.get('issues').handler('', ctx);
|
|
467
|
+
await loaded.commands.get('issues').handler(options.args || '', ctx);
|
|
397
468
|
await tick();
|
|
398
469
|
assert.ok(capture.holder.options, 'the command mounts the view');
|
|
399
470
|
return {
|
|
@@ -428,6 +499,12 @@ describe('/issues gate (S3)', () => {
|
|
|
428
499
|
|
|
429
500
|
test('a missing gh notifies the fix once at startup and again on invocation, opening nothing', async () => {
|
|
430
501
|
const { commands, hooks, mod } = await loadExtension();
|
|
502
|
+
// T11 (S13): the CLI's PRESENCE is pinned here, because this test is about the
|
|
503
|
+
// other failure — a `gh` that is installed and whose own child cannot be
|
|
504
|
+
// spawned (an ENOENT from the runner). The local presence check would
|
|
505
|
+
// otherwise answer first on a machine that has no `gh` at all, which is a
|
|
506
|
+
// different state with its own line.
|
|
507
|
+
ghIssues.setGhWhich(() => '/usr/local/bin/gh');
|
|
431
508
|
ghIssues.setGhRunner(async (bin) => ({
|
|
432
509
|
status: null, stdout: '', stderr: '', error: `spawn ${bin} ENOENT: gh CLI is not available`,
|
|
433
510
|
}));
|
|
@@ -435,6 +512,9 @@ describe('/issues gate (S3)', () => {
|
|
|
435
512
|
const notes = [];
|
|
436
513
|
await fireSessionStart(hooks, gateCtx(root, notes));
|
|
437
514
|
await fireSessionStart(hooks, gateCtx(root, notes));
|
|
515
|
+
// S5 (T8): the gate is decided in the background now, so the session start
|
|
516
|
+
// returns before the verdict lands. The notice still arrives, and still once.
|
|
517
|
+
assert.ok(await waitFor(() => notes.length === 1), 'the startup notification never arrived');
|
|
438
518
|
assert.ok(commands.has('issues'), 'the command stays discoverable');
|
|
439
519
|
assert.equal(notes.length, 1, 'exactly one startup notification per session');
|
|
440
520
|
assert.match(notes[0][0], /gh CLI is not available/, 'the note names what is missing');
|
|
@@ -465,8 +545,359 @@ describe('/issues gate (S3)', () => {
|
|
|
465
545
|
});
|
|
466
546
|
});
|
|
467
547
|
|
|
548
|
+
// ---------------------------------------------------------------------------
|
|
549
|
+
// S13 (T11, corrected): without the `gh` CLI the two issues surfaces are NOT
|
|
550
|
+
// REGISTERED — `/issues` never loads and the `GITHUB` rail section is never added
|
|
551
|
+
// to the rail — so there is no line, notice or refusal for them: nothing appears,
|
|
552
|
+
// because nothing was registered. The decision is a LOCAL presence answer (a PATH
|
|
553
|
+
// walk, no child process, no `gh` invocation to find out whether `gh` exists), and
|
|
554
|
+
// every other surface this package contributes keeps working. A `gh` that is
|
|
555
|
+
// present but unauthenticated is NOT this state and keeps the login fix it always
|
|
556
|
+
// had.
|
|
557
|
+
// ---------------------------------------------------------------------------
|
|
558
|
+
describe('a missing gh CLI registers no issues surface (S13, T11)', () => {
|
|
559
|
+
test('without the CLI neither the command nor the rail section exists', async () => {
|
|
560
|
+
const { commands } = await loadExtension({ gh: false });
|
|
561
|
+
|
|
562
|
+
assert.equal(commands.has('issues'), false, '/issues never loads without the CLI');
|
|
563
|
+
// Everything else is still there: a missing `gh` is not a plugin-wide switch.
|
|
564
|
+
assert.ok(commands.has('warp'), '/warp still registers');
|
|
565
|
+
assert.ok(commands.has('odd'), '/odd still registers');
|
|
566
|
+
assert.ok(commands.has('files'), '/files still registers');
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
test('the decision costs no child process, at load or at session start', async () => {
|
|
570
|
+
const { hooks, mod } = await loadExtension({ gh: false });
|
|
571
|
+
const { runner, calls } = makeIssuesRunner();
|
|
572
|
+
ghIssues.setGhRunner(runner);
|
|
573
|
+
|
|
574
|
+
const root = makeRepo({ tag: 'cli-missing-gate' });
|
|
575
|
+
const notes = [];
|
|
576
|
+
await fireSessionStart(hooks, gateCtx(root, notes));
|
|
577
|
+
|
|
578
|
+
assert.deepEqual(calls, [], 'a missing CLI is answered locally: no gh child is ever spawned');
|
|
579
|
+
assert.deepEqual(notes, [], 'and nothing is said: there is no surface to say it on');
|
|
580
|
+
assert.equal(typeof mod, 'object');
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
test('with the CLI present the command is registered (PRESERVE)', async () => {
|
|
584
|
+
const { commands } = await loadExtension();
|
|
585
|
+
assert.ok(commands.has('issues'), '/issues loads when the CLI is on PATH');
|
|
586
|
+
assert.equal(typeof commands.get('issues').handler, 'function');
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
test('an unauthenticated gh that IS present keeps the login fix (PRESERVE)', async () => {
|
|
590
|
+
const { commands, mod } = await loadExtension();
|
|
591
|
+
ghIssues.setGhWhich(() => '/usr/local/bin/gh');
|
|
592
|
+
ghIssues.setGhRunner(async () => ({
|
|
593
|
+
status: 1, stdout: '', stderr: 'Failed to log in: authentication required', error: null,
|
|
594
|
+
}));
|
|
595
|
+
mod.setIssuesTuiLoader(async () => stubTui);
|
|
596
|
+
|
|
597
|
+
const { ctx, customs, notes } = makeCtx({
|
|
598
|
+
cwd: makeRepo({ tag: 'cli-present-unauth' }),
|
|
599
|
+
customImpl: async () => null,
|
|
600
|
+
});
|
|
601
|
+
await commands.get('issues').handler('', ctx);
|
|
602
|
+
|
|
603
|
+
assert.equal(customs.length, 0, 'no overlay while unauthenticated');
|
|
604
|
+
assert.equal(notes.length, 1);
|
|
605
|
+
assert.match(notes[0][0], /gh auth login/, 'the presence check never intercepts an authentication failure');
|
|
606
|
+
assert.equal(notes[0][1], 'error');
|
|
607
|
+
assert.equal(/not installed/.test(notes[0][0]), false, 'a present gh is never reported as missing');
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
// S1/S2 (T1, T2 of the startup theory): `session_start` must resolve without
|
|
612
|
+
// waiting on any child process or network call. The `gh` gate used to be AWAITED
|
|
613
|
+
// there — `gh api user` (≈485 ms) then `gh repo view` (≈550 ms), serially, on
|
|
614
|
+
// every session start AND every session switch — and `/issues` probes `gh` on
|
|
615
|
+
// demand anyway, so nothing is lost by dispatching it as startup work instead.
|
|
616
|
+
// Outside a repository there is nothing to check at all, so the gate resolves the
|
|
617
|
+
// checkout first and spawns nothing (T2/S3).
|
|
618
|
+
describe('session startup takes no gh call (S1, S2)', () => {
|
|
619
|
+
test('the awaited session_start resolves while the injected gh runner is still pending', async () => {
|
|
620
|
+
const { hooks } = await loadExtension();
|
|
621
|
+
const calls = [];
|
|
622
|
+
let release = null;
|
|
623
|
+
ghIssues.setGhRunner((bin, argv) => {
|
|
624
|
+
calls.push({ bin, argv: argv.slice() });
|
|
625
|
+
return new Promise((resolve) => {
|
|
626
|
+
release = () => resolve({ status: 0, stdout: '{"login":"me"}', stderr: '', error: null });
|
|
627
|
+
});
|
|
628
|
+
});
|
|
629
|
+
const root = makeRepo({ tag: 'startup-nonblocking' });
|
|
630
|
+
// The handlers are fired HERE, not through `fireSessionStart`: that helper
|
|
631
|
+
// waits for the dispatched startup work, and this is precisely the work the
|
|
632
|
+
// awaited path must not wait for.
|
|
633
|
+
const fired = sessionStartHandlers(hooks).map((handler) => Promise.resolve(handler({}, gateCtx(root, []))));
|
|
634
|
+
const settled = await Promise.race([
|
|
635
|
+
Promise.all(fired).then(() => 'resolved'),
|
|
636
|
+
new Promise((resolve) => { setTimeout(() => resolve('blocked'), 500); }),
|
|
637
|
+
]);
|
|
638
|
+
assert.equal(settled, 'resolved',
|
|
639
|
+
'the awaited session_start path never waits on a child process or a network call');
|
|
640
|
+
|
|
641
|
+
// Dispatched, not dropped: the probe is still startup work, so the session's
|
|
642
|
+
// own gate answer still arrives in the background.
|
|
643
|
+
assert.equal(await waitFor(() => calls.length > 0), true,
|
|
644
|
+
'the gh gate still probes, off the awaited path');
|
|
645
|
+
if (typeof release === 'function') release();
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
test('a session outside a repository makes no gh call at startup, and stays silent', async () => {
|
|
649
|
+
const { hooks } = await loadExtension();
|
|
650
|
+
const { runner, calls } = makeIssuesRunner();
|
|
651
|
+
ghIssues.setGhRunner(runner);
|
|
652
|
+
const outside = fs.realpathSync(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-startup-plain-'))));
|
|
653
|
+
const notes = [];
|
|
654
|
+
await fireSessionStart(hooks, gateCtx(outside, notes));
|
|
655
|
+
assert.deepEqual(calls, [], 'outside a repository there is nothing to check, so no gh child runs');
|
|
656
|
+
assert.deepEqual(notes, [], 'and nothing is said: a non-repository cwd is not an error');
|
|
657
|
+
});
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
// S5 (T8): the gate is network work (`gh api user` then `gh repo view`, plus the
|
|
661
|
+
// checkout's own git probes) and the host awaits every `session_start` handler it
|
|
662
|
+
// is handed, so awaiting it there put the first prompt behind the whole probe on
|
|
663
|
+
// every open, resume and switch. What the gate DECIDES is unchanged; only WHEN it
|
|
664
|
+
// runs. These cases drive the registered handlers only.
|
|
665
|
+
describe('S5 (T8): the issues gate never delays session_start', () => {
|
|
666
|
+
const ghOk = (stdout) => ({ status: 0, stdout, stderr: '', error: null });
|
|
667
|
+
const USER_OK = ghOk(JSON.stringify({ login: 'me' }));
|
|
668
|
+
const USER_FAIL = { status: 1, stdout: '', stderr: 'Failed to log in: authentication required', error: null };
|
|
669
|
+
|
|
670
|
+
// A fake `gh` that answers the gate's two commands, records the checkout of
|
|
671
|
+
// every `gh api user` it was asked for, and lets the test decide when that one
|
|
672
|
+
// call answers.
|
|
673
|
+
function gateRunner({ user = () => Promise.resolve(USER_OK) } = {}) {
|
|
674
|
+
const gateCalls = [];
|
|
675
|
+
const runner = (_bin, argv, opts = {}) => {
|
|
676
|
+
if (argv[0] === 'api' && argv[1] === 'user') {
|
|
677
|
+
gateCalls.push(opts.cwd);
|
|
678
|
+
return user(opts.cwd);
|
|
679
|
+
}
|
|
680
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
681
|
+
return Promise.resolve(ghOk(JSON.stringify({ nameWithOwner: 'myfork/project' })));
|
|
682
|
+
}
|
|
683
|
+
return Promise.resolve(ghOk(''));
|
|
684
|
+
};
|
|
685
|
+
return { runner, gateCalls };
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// The gate resolves the CHECKOUT before it asks gh anything (S3/T2), so a
|
|
689
|
+
// session's cwd has to be a real checkout for a probe to run at all: a bare
|
|
690
|
+
// temporary directory is the non-repository state, which by design spawns
|
|
691
|
+
// nothing. What these cases measure — dispatch, the TTL, the shared probe, the
|
|
692
|
+
// generation — is unchanged; only the preconditions of the directory moved.
|
|
693
|
+
function scratchCheckout(tag) {
|
|
694
|
+
return makeRepo({ tag: `gate-${tag}` });
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function sessionShutdownHandlers(hooks) {
|
|
698
|
+
return hooks.filter(([event]) => event === 'session_shutdown').map(([, handler]) => handler);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
async function fireSessionShutdown(hooks, ctx) {
|
|
702
|
+
for (const handler of sessionShutdownHandlers(hooks)) {
|
|
703
|
+
const out = handler({}, ctx);
|
|
704
|
+
if (out && typeof out.then === 'function') await out;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// Fire the host's session_start handlers and give them a bounded window to
|
|
709
|
+
// resolve, so a handler that waits for `gh` fails an assertion below instead of
|
|
710
|
+
// hanging the suite.
|
|
711
|
+
async function fireSessionStartPromptly(hooks, ctx) {
|
|
712
|
+
const pending = sessionStartHandlers(hooks).map((handler) => Promise.resolve(handler({}, ctx)));
|
|
713
|
+
const outcome = await Promise.race([
|
|
714
|
+
Promise.all(pending).then(() => 'returned'),
|
|
715
|
+
new Promise((resolve) => setTimeout(() => resolve('waiting'), 100)),
|
|
716
|
+
]);
|
|
717
|
+
return { outcome, pending };
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// A window in which a NEW probe would have reached the injected `gh` (the client
|
|
721
|
+
// reads the checkout's local git configuration first). Nothing arriving inside it
|
|
722
|
+
// is the evidence that a cached answer was reused.
|
|
723
|
+
const settleWindow = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
724
|
+
|
|
725
|
+
test('session_start returns while the gate is still pending, and the probe still runs', async () => {
|
|
726
|
+
const { hooks } = await loadExtension();
|
|
727
|
+
const held = [];
|
|
728
|
+
ghIssues.setGhRunner(gateRunner({ user: () => new Promise((resolve) => { held.push(resolve); }) }).runner);
|
|
729
|
+
const notes = [];
|
|
730
|
+
const { outcome } = await fireSessionStartPromptly(hooks, gateCtx(scratchCheckout('pending'), notes));
|
|
731
|
+
assert.equal(outcome, 'returned', 'session_start never waits for the network gate');
|
|
732
|
+
assert.ok(await waitFor(() => held.length === 1), 'the probe never ran in the background');
|
|
733
|
+
assert.deepEqual(notes, [], 'and decides nothing before it answers');
|
|
734
|
+
held[0](USER_OK);
|
|
735
|
+
await tick();
|
|
736
|
+
assert.deepEqual(notes, [], 'a usable gh still says nothing, exactly as before');
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
test('a verdict that lands late still notifies the same sentence and still refuses /issues', async () => {
|
|
740
|
+
const { hooks, commands, mod } = await loadExtension();
|
|
741
|
+
const held = [];
|
|
742
|
+
ghIssues.setGhRunner(gateRunner({ user: () => new Promise((resolve) => { held.push(resolve); }) }).runner);
|
|
743
|
+
const root = scratchCheckout('deferred');
|
|
744
|
+
const notes = [];
|
|
745
|
+
const { outcome } = await fireSessionStartPromptly(hooks, gateCtx(root, notes));
|
|
746
|
+
assert.equal(outcome, 'returned', 'the session start does not wait for the verdict');
|
|
747
|
+
assert.deepEqual(notes, [], 'the startup note waits for the verdict');
|
|
748
|
+
assert.ok(await waitFor(() => held.length === 1), 'the probe never ran in the background');
|
|
749
|
+
|
|
750
|
+
held[0]({ status: null, stdout: '', stderr: '', error: 'spawn gh ENOENT: gh CLI is not available' });
|
|
751
|
+
assert.ok(await waitFor(() => notes.length === 1), 'the deferred verdict never notified');
|
|
752
|
+
assert.match(notes[0][0], /gh CLI is not available/, 'the note names what is missing');
|
|
753
|
+
assert.match(notes[0][0], /gh auth login/, 'the note names the command that fixes it');
|
|
754
|
+
assert.match(notes[0][0], /cannot open/, 'the note names the real consequence');
|
|
755
|
+
assert.equal(notes[0][1], 'info');
|
|
756
|
+
|
|
757
|
+
mod.setIssuesTuiLoader(async () => stubTui);
|
|
758
|
+
const { ctx, customs, notes: invokeNotes } = makeCtx({ cwd: root, customImpl: async () => null });
|
|
759
|
+
await commands.get('issues').handler('', ctx);
|
|
760
|
+
assert.equal(customs.length, 0, 'invocation without gh opens nothing');
|
|
761
|
+
assert.equal(invokeNotes.length, 1, 'invocation reports its own, fuller error');
|
|
762
|
+
assert.match(invokeNotes[0][0], /gh auth login/);
|
|
763
|
+
assert.equal(invokeNotes[0][1], 'error');
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
test('concurrent probes share one call and a settled answer is reused inside the TTL', async () => {
|
|
767
|
+
const { hooks } = await loadExtension();
|
|
768
|
+
const held = [];
|
|
769
|
+
const gate = gateRunner({ user: () => new Promise((resolve) => { held.push(resolve); }) });
|
|
770
|
+
ghIssues.setGhRunner(gate.runner);
|
|
771
|
+
const root = scratchCheckout('share');
|
|
772
|
+
const other = scratchCheckout('share-other');
|
|
773
|
+
|
|
774
|
+
// Two session starts for ONE checkout while the first probe is in flight.
|
|
775
|
+
await fireSessionStartPromptly(hooks, gateCtx(root, []));
|
|
776
|
+
await fireSessionStartPromptly(hooks, gateCtx(root, []));
|
|
777
|
+
assert.ok(await waitFor(() => gate.gateCalls.length === 1), 'the gate never probed');
|
|
778
|
+
assert.equal(gate.gateCalls.length, 1, 'concurrent probes for one checkout share one gh call');
|
|
779
|
+
held[0](USER_OK);
|
|
780
|
+
await tick();
|
|
781
|
+
|
|
782
|
+
// A settled success is reused for the rest of its TTL.
|
|
783
|
+
await fireSessionStartPromptly(hooks, gateCtx(root, []));
|
|
784
|
+
await settleWindow();
|
|
785
|
+
assert.equal(gate.gateCalls.length, 1, 'a later session reuses the answer it already paid for');
|
|
786
|
+
|
|
787
|
+
// Another checkout pays for its own.
|
|
788
|
+
await fireSessionStartPromptly(hooks, gateCtx(other, []));
|
|
789
|
+
assert.ok(await waitFor(() => gate.gateCalls.length === 2), 'a different checkout never probed');
|
|
790
|
+
assert.deepEqual(gate.gateCalls, [root, other], 'and the cache is keyed by the checkout');
|
|
791
|
+
held[1](USER_OK);
|
|
792
|
+
await tick();
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
test('a success is reused for minutes, a failure only for seconds', async () => {
|
|
796
|
+
const { hooks } = await loadExtension();
|
|
797
|
+
const clock = { at: 1_000_000 };
|
|
798
|
+
ghIssues.setGateClock(() => clock.at);
|
|
799
|
+
|
|
800
|
+
const okRoot = scratchCheckout('ttl-ok');
|
|
801
|
+
const okGate = gateRunner();
|
|
802
|
+
ghIssues.setGhRunner(okGate.runner);
|
|
803
|
+
await fireSessionStart(hooks, gateCtx(okRoot, []));
|
|
804
|
+
await waitFor(() => okGate.gateCalls.length === 1);
|
|
805
|
+
clock.at += 60_000;
|
|
806
|
+
await fireSessionStart(hooks, gateCtx(okRoot, []));
|
|
807
|
+
await settleWindow();
|
|
808
|
+
assert.equal(okGate.gateCalls.length, 1, 'a success inside its TTL is reused, not re-probed');
|
|
809
|
+
clock.at += 5 * 60_000;
|
|
810
|
+
await fireSessionStart(hooks, gateCtx(okRoot, []));
|
|
811
|
+
await waitFor(() => okGate.gateCalls.length === 2);
|
|
812
|
+
assert.equal(okGate.gateCalls.length, 2, 'past the success TTL the gate probes again');
|
|
813
|
+
|
|
814
|
+
const failRoot = scratchCheckout('ttl-fail');
|
|
815
|
+
const failGate = gateRunner({ user: () => Promise.resolve(USER_FAIL) });
|
|
816
|
+
ghIssues.setGhRunner(failGate.runner);
|
|
817
|
+
await fireSessionStart(hooks, gateCtx(failRoot, []));
|
|
818
|
+
await waitFor(() => failGate.gateCalls.length === 1);
|
|
819
|
+
clock.at += 10_000;
|
|
820
|
+
await fireSessionStart(hooks, gateCtx(failRoot, []));
|
|
821
|
+
await settleWindow();
|
|
822
|
+
assert.equal(failGate.gateCalls.length, 1, 'a failure inside its short TTL is reused');
|
|
823
|
+
clock.at += 30_000;
|
|
824
|
+
await fireSessionStart(hooks, gateCtx(failRoot, []));
|
|
825
|
+
await waitFor(() => failGate.gateCalls.length === 2);
|
|
826
|
+
assert.equal(failGate.gateCalls.length, 2, 'past the short TTL the failure is probed again');
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
test('a verdict from a superseded checkout never applies to the session that replaced it', async () => {
|
|
830
|
+
const { hooks } = await loadExtension();
|
|
831
|
+
const held = new Map();
|
|
832
|
+
ghIssues.setGhRunner(gateRunner({
|
|
833
|
+
user: (cwd) => new Promise((resolve) => { held.set(cwd, resolve); }),
|
|
834
|
+
}).runner);
|
|
835
|
+
const checkoutA = scratchCheckout('supersede-a');
|
|
836
|
+
const checkoutB = scratchCheckout('supersede-b');
|
|
837
|
+
const notesA = [];
|
|
838
|
+
const notesB = [];
|
|
839
|
+
|
|
840
|
+
await fireSessionStartPromptly(hooks, gateCtx(checkoutA, notesA));
|
|
841
|
+
await waitFor(() => held.has(checkoutA));
|
|
842
|
+
await fireSessionStartPromptly(hooks, gateCtx(checkoutB, notesB));
|
|
843
|
+
await waitFor(() => held.has(checkoutB));
|
|
844
|
+
|
|
845
|
+
// The previous checkout's verdict lands now, after its session was superseded.
|
|
846
|
+
held.get(checkoutA)(USER_FAIL);
|
|
847
|
+
await tick();
|
|
848
|
+
await tick();
|
|
849
|
+
assert.deepEqual(notesA, [], 'a superseded verdict never notifies the session it belonged to');
|
|
850
|
+
|
|
851
|
+
held.get(checkoutB)(USER_OK);
|
|
852
|
+
await tick();
|
|
853
|
+
assert.deepEqual(notesB, [], 'the live session keeps its own verdict');
|
|
854
|
+
assert.equal(held.size, 2, 'no extra probe ran');
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
test('session_shutdown drops the gate cache, so the next session probes afresh', async () => {
|
|
858
|
+
const { hooks } = await loadExtension();
|
|
859
|
+
const clock = { at: 2_000_000 };
|
|
860
|
+
ghIssues.setGateClock(() => clock.at);
|
|
861
|
+
const gate = gateRunner();
|
|
862
|
+
ghIssues.setGhRunner(gate.runner);
|
|
863
|
+
const root = scratchCheckout('shutdown');
|
|
864
|
+
const ctx = gateCtx(root, []);
|
|
865
|
+
|
|
866
|
+
await fireSessionStart(hooks, ctx);
|
|
867
|
+
await waitFor(() => gate.gateCalls.length === 1);
|
|
868
|
+
clock.at += 1_000;
|
|
869
|
+
await fireSessionStart(hooks, ctx);
|
|
870
|
+
await settleWindow();
|
|
871
|
+
assert.equal(gate.gateCalls.length, 1, 'inside the TTL the same checkout is reused');
|
|
872
|
+
|
|
873
|
+
await fireSessionShutdown(hooks, ctx);
|
|
874
|
+
await fireSessionStart(hooks, ctx);
|
|
875
|
+
await waitFor(() => gate.gateCalls.length === 2);
|
|
876
|
+
assert.equal(gate.gateCalls.length, 2, 'a new session never inherits the probe its predecessor paid for');
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
test('the cache holds a handful of checkouts, never every one ever seen', async () => {
|
|
880
|
+
const { hooks } = await loadExtension();
|
|
881
|
+
const gate = gateRunner();
|
|
882
|
+
ghIssues.setGhRunner(gate.runner);
|
|
883
|
+
const scopes = Array.from({ length: 10 }, (_, index) => scratchCheckout(`bound-${index}`));
|
|
884
|
+
for (const scope of scopes) await fireSessionStart(hooks, gateCtx(scope, []));
|
|
885
|
+
await waitFor(() => gate.gateCalls.length === scopes.length);
|
|
886
|
+
assert.equal(gate.gateCalls.length, scopes.length, 'every checkout probed once');
|
|
887
|
+
|
|
888
|
+
await fireSessionStart(hooks, gateCtx(scopes.at(-1), []));
|
|
889
|
+
await settleWindow();
|
|
890
|
+
assert.equal(gate.gateCalls.length, scopes.length, 'the newest checkout is still cached');
|
|
891
|
+
|
|
892
|
+
await fireSessionStart(hooks, gateCtx(scopes[0], []));
|
|
893
|
+
await waitFor(() => gate.gateCalls.length === scopes.length + 1);
|
|
894
|
+
assert.equal(gate.gateCalls.length, scopes.length + 1,
|
|
895
|
+
'the oldest checkout was evicted instead of the cache growing without bound');
|
|
896
|
+
});
|
|
897
|
+
});
|
|
898
|
+
|
|
468
899
|
describe('/issues overlay and arguments', () => {
|
|
469
|
-
test('opens full screen fed by the scoped searches and
|
|
900
|
+
test('opens full screen fed by the three scoped searches, and leaves All until it is asked for', async () => {
|
|
470
901
|
const root = makeRepo({ tag: 'issues-open' });
|
|
471
902
|
const { runner, calls } = makeIssuesRunner();
|
|
472
903
|
const { component, customs, notes } = await openIssues(root, { runner });
|
|
@@ -485,17 +916,112 @@ describe('/issues overlay and arguments', () => {
|
|
|
485
916
|
'assignee:@me sort:updated-desc',
|
|
486
917
|
'involves:@me -author:@me sort:updated-desc',
|
|
487
918
|
], 'every scoped tab is read once with its own exact query');
|
|
488
|
-
assert.equal(connectionReads(calls).length,
|
|
919
|
+
assert.equal(connectionReads(calls).length, 0,
|
|
920
|
+
'opening the panel reads no connection page: All is read when it is entered (S2)');
|
|
489
921
|
const body = clean(component.render(110).join('\n'));
|
|
490
922
|
assert.match(body, /My issues/);
|
|
491
923
|
assert.match(body, /Assigned/);
|
|
492
924
|
assert.match(body, /Involved/);
|
|
925
|
+
assert.doesNotMatch(clean(component.render(110)[2]), /\bAll\b/, 'All is no longer a tab (S1)');
|
|
493
926
|
assert.match(body, /76/, 'the listed issue number');
|
|
494
927
|
assert.match(body, /chore: update/, 'the listed issue title');
|
|
495
928
|
assert.match(body, /◈ Issues/, 'the header names the surface');
|
|
496
929
|
assert.ok(!body.includes(path.basename(root)), 'the header never repeats the checkout name');
|
|
497
930
|
});
|
|
498
931
|
|
|
932
|
+
test('All is read the first time the shortcut enters it, and re-entering reuses it (S1/S2)', async () => {
|
|
933
|
+
const root = makeRepo({ tag: 'issues-all-lazy' });
|
|
934
|
+
const { runner, calls } = makeIssuesRunner();
|
|
935
|
+
const { component } = await openIssues(root, { runner });
|
|
936
|
+
await tick();
|
|
937
|
+
assert.equal(connectionReads(calls).length, 0, 'the mount reads no connection page');
|
|
938
|
+
assert.equal(searchQueries(calls).length, 3, 'and exactly the three scoped searches');
|
|
939
|
+
component.handleInput('g');
|
|
940
|
+
await tick();
|
|
941
|
+
const reads = connectionReads(calls);
|
|
942
|
+
assert.equal(reads.length, 1, 'entering All issues one connection read');
|
|
943
|
+
const bar = clean(component.render(110)[2]);
|
|
944
|
+
assert.match(bar, /▸ All \(\d+\)/, `the bar reads only the All view: ${bar}`);
|
|
945
|
+
for (const label of ['My issues', 'Assigned', 'Involved']) {
|
|
946
|
+
assert.ok(!bar.includes(label), `the scoped tabs leave the bar in the All view: ${bar}`);
|
|
947
|
+
}
|
|
948
|
+
// The full legend only fits a wide frame; the label is what is under test.
|
|
949
|
+
assert.match(clean(component.render(200).at(-2)), /g related issues/,
|
|
950
|
+
'inside All the hint says the key goes back (D1)');
|
|
951
|
+
component.handleInput('g');
|
|
952
|
+
await tick();
|
|
953
|
+
assert.match(clean(component.render(200).at(-2)), /g all issues/,
|
|
954
|
+
'outside All the hint names what the key opens (D1)');
|
|
955
|
+
assert.equal(connectionReads(calls).length, 1, 'leaving All reads nothing');
|
|
956
|
+
component.handleInput('g');
|
|
957
|
+
await tick();
|
|
958
|
+
assert.equal(connectionReads(calls).length, 1, 're-entering All reuses the page it read (S2)');
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
test('a typed filter is read by the three scoped tabs, and the All view searches instead of connecting (S3/S4/S5)', async () => {
|
|
962
|
+
const root = makeRepo({ tag: 'issues-filter' });
|
|
963
|
+
const { runner, calls } = makeIssuesRunner();
|
|
964
|
+
const { component } = await openIssues(root, { runner });
|
|
965
|
+
await tick();
|
|
966
|
+
const mount = searchQueries(calls).length;
|
|
967
|
+
assert.equal(mount, 3, 'the mount read the three scoped buckets');
|
|
968
|
+
component.handleInput('t');
|
|
969
|
+
for (const ch of 'label:bug') component.handleInput(ch);
|
|
970
|
+
await waitFor(() => searchQueries(calls).length >= mount + 3);
|
|
971
|
+
await tick();
|
|
972
|
+
assert.deepEqual(searchQueries(calls).slice(mount), [
|
|
973
|
+
'author:@me sort:updated-desc label:bug',
|
|
974
|
+
'assignee:@me sort:updated-desc label:bug',
|
|
975
|
+
'involves:@me -author:@me sort:updated-desc label:bug',
|
|
976
|
+
], 'the settled filter re-reads all three scoped buckets, each with its own scope');
|
|
977
|
+
component.handleInput('enter');
|
|
978
|
+
await tick();
|
|
979
|
+
// Entering All while the filter is on is a SEARCH read: the connection takes
|
|
980
|
+
// no text, and the search count is capped, so the view never claims it exact.
|
|
981
|
+
const before = searchQueries(calls).length;
|
|
982
|
+
component.handleInput('g');
|
|
983
|
+
await waitFor(() => searchQueries(calls).length > before);
|
|
984
|
+
await tick();
|
|
985
|
+
assert.deepEqual(searchQueries(calls).slice(before), ['sort:updated-desc label:bug'],
|
|
986
|
+
'a filtered All goes through the search path, with the filter');
|
|
987
|
+
assert.equal(connectionReads(calls).length, 0, 'and never reads the unfiltered connection');
|
|
988
|
+
await waitFor(() => /▸ All \(\d+\+\)/.test(clean(component.render(110)[2])));
|
|
989
|
+
assert.match(clean(component.render(110)[2]), /▸ All \(\d+\+\)/,
|
|
990
|
+
'a filtered All marks its count inexact instead of claiming an exact total');
|
|
991
|
+
assert.match(clean(component.render(110)[3]), /via search/, 'the frame names the read on screen');
|
|
992
|
+
});
|
|
993
|
+
|
|
994
|
+
// S5: the route trims a whitespace-only query into "no filter" and takes the
|
|
995
|
+
// repository CONNECTION, so the note the view paints has to name that same
|
|
996
|
+
// read — the route and the note decide from one fact.
|
|
997
|
+
test('a whitespace-only filter takes the connection read, and the note names it (S5)', async () => {
|
|
998
|
+
const root = makeRepo({ tag: 'issues-blank-filter' });
|
|
999
|
+
const { runner, calls } = makeIssuesRunner();
|
|
1000
|
+
const { component } = await openIssues(root, { runner });
|
|
1001
|
+
await tick();
|
|
1002
|
+
const mount = searchQueries(calls).length;
|
|
1003
|
+
assert.equal(mount, 3, 'the mount read the three scoped buckets');
|
|
1004
|
+
component.handleInput('g');
|
|
1005
|
+
await waitFor(() => connectionReads(calls).length === 1);
|
|
1006
|
+
await tick();
|
|
1007
|
+
component.handleInput('t');
|
|
1008
|
+
component.handleInput(' ');
|
|
1009
|
+
await waitFor(() => connectionReads(calls).length === 2);
|
|
1010
|
+
await tick();
|
|
1011
|
+
assert.deepEqual(searchQueries(calls).slice(mount), [
|
|
1012
|
+
'author:@me sort:updated-desc',
|
|
1013
|
+
'assignee:@me sort:updated-desc',
|
|
1014
|
+
'involves:@me -author:@me sort:updated-desc',
|
|
1015
|
+
], 'the scoped tabs re-read their own searches with no stray text appended');
|
|
1016
|
+
assert.equal(connectionReads(calls).length, 2,
|
|
1017
|
+
'the All view reads the repository connection again, never a search');
|
|
1018
|
+
const note = clean(component.render(110)[3]);
|
|
1019
|
+
assert.match(note, /via connection \(exact total\)/, `the note names the read on screen: ${note}`);
|
|
1020
|
+
const bar = clean(component.render(110)[2]);
|
|
1021
|
+
assert.match(bar, /▸ All \(\d+\)/, `and the exact connection total wears no mark: ${bar}`);
|
|
1022
|
+
assert.ok(!/\(\d+\+\)/.test(bar), `no inexact total is claimed for an exact read: ${bar}`);
|
|
1023
|
+
});
|
|
1024
|
+
|
|
499
1025
|
test('an argument notifies and opens nothing', async () => {
|
|
500
1026
|
const root = makeRepo({ tag: 'issues-args' });
|
|
501
1027
|
const { commands, mod, hooks } = await loadExtension();
|
|
@@ -510,9 +1036,10 @@ describe('/issues overlay and arguments', () => {
|
|
|
510
1036
|
assert.deepEqual(notes[0], ['Unknown option "extra". Use /issues.', 'error']);
|
|
511
1037
|
});
|
|
512
1038
|
|
|
513
|
-
test('outside a Git checkout notifies the shared line at info and
|
|
1039
|
+
test('outside a Git checkout notifies the shared line at info and spawns no gh', async () => {
|
|
514
1040
|
const { commands, mod, hooks } = await loadExtension();
|
|
515
|
-
|
|
1041
|
+
const { runner, calls } = makeIssuesRunner();
|
|
1042
|
+
ghIssues.setGhRunner(runner);
|
|
516
1043
|
const scratch = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-gate-')));
|
|
517
1044
|
await fireSessionStart(hooks, gateCtx(scratch, []));
|
|
518
1045
|
mod.setIssuesTuiLoader(async () => stubTui);
|
|
@@ -522,22 +1049,23 @@ describe('/issues overlay and arguments', () => {
|
|
|
522
1049
|
assert.equal(customs.length, 0, 'no overlay outside a checkout');
|
|
523
1050
|
assert.equal(selects.length, 0, 'no fallback selector outside a checkout');
|
|
524
1051
|
assert.deepEqual(notes, [[`not a git repository: ${outside}; run 'git init' first`, 'info']]);
|
|
1052
|
+
assert.deepEqual(calls, [],
|
|
1053
|
+
'the refusal is the checkout’s own answer: it never asks gh, which could only report its own error');
|
|
525
1054
|
});
|
|
526
1055
|
});
|
|
527
1056
|
|
|
528
1057
|
describe('/issues is read-only about the worktree association', () => {
|
|
1058
|
+
// S3/S4: the association's document is gone. The property this case proves is the
|
|
1059
|
+
// one that survives it — /issues is handed no association option and every read and
|
|
1060
|
+
// keypress writes nothing at all.
|
|
529
1061
|
test('the mounted view is handed no association option and reading writes nothing', async () => {
|
|
530
1062
|
const root = makeRepo({ tag: 'issues-readonly' });
|
|
531
1063
|
const file = registryFile(root);
|
|
532
|
-
fs.
|
|
533
|
-
version: 1,
|
|
534
|
-
worktrees: [{ branch: git(root, ['branch', '--show-current']).trim(), path: root, thread: 't', issues: [76], odd: null }],
|
|
535
|
-
}, null, 2)}\n`);
|
|
536
|
-
const before = fs.readFileSync(file, 'utf8');
|
|
1064
|
+
assert.equal(fs.existsSync(file), false, 'the fixture starts with no worktree document');
|
|
537
1065
|
const { runner } = makeIssuesRunner();
|
|
538
1066
|
const capture = captureIssuesView();
|
|
539
1067
|
try {
|
|
540
|
-
await openIssues(root, { runner });
|
|
1068
|
+
await openIssues(root, { runner, prepare: (mod) => capture.attach(mod) });
|
|
541
1069
|
const options = capture.holder.options;
|
|
542
1070
|
for (const key of ['assigned', 'assignedOdd', 'saveAssignment', 'assignmentEnabled']) {
|
|
543
1071
|
assert.equal(key in options, false, `the view is handed no ${key}: ${JSON.stringify(Object.keys(options))}`);
|
|
@@ -545,15 +1073,14 @@ describe('/issues is read-only about the worktree association', () => {
|
|
|
545
1073
|
} finally {
|
|
546
1074
|
capture.restore();
|
|
547
1075
|
}
|
|
548
|
-
assert.equal(fs.
|
|
1076
|
+
assert.equal(fs.existsSync(file), false, 'reading writes no worktree document');
|
|
549
1077
|
|
|
550
1078
|
const { component } = await openIssues(root, { runner });
|
|
551
|
-
assert.match(clean(component.render(110).join('\n')), /76/, 'the stored issue still lists');
|
|
552
1079
|
component.handleInput('down');
|
|
553
1080
|
component.handleInput('space');
|
|
554
1081
|
component.handleInput('ctrl+s');
|
|
555
1082
|
await tick();
|
|
556
|
-
assert.equal(fs.
|
|
1083
|
+
assert.equal(fs.existsSync(file), false, 'the removed association keys write nothing');
|
|
557
1084
|
});
|
|
558
1085
|
});
|
|
559
1086
|
|
|
@@ -677,6 +1204,8 @@ describe('/issues actions (S3,S4)', () => {
|
|
|
677
1204
|
assert.ok(!gitCalls[0].argv.join(' ').includes('xdg-open'), 'never an invented opener');
|
|
678
1205
|
assert.deepEqual(run.host.lifecycle, ['stop', 'start', 'render'],
|
|
679
1206
|
'the TUI is suspended for the browser open and taken back afterwards');
|
|
1207
|
+
assert.deepEqual(run.host.stops, [{ preserveScreen: true }],
|
|
1208
|
+
'the suspend preserves the screen: a bare stop stamps the whole alt-screen frame into scrollback');
|
|
680
1209
|
assert.deepEqual(run.host.paints, [true], 'the terminal is forced to repaint on resume');
|
|
681
1210
|
});
|
|
682
1211
|
|
|
@@ -688,7 +1217,7 @@ describe('/issues actions (S3,S4)', () => {
|
|
|
688
1217
|
const primed = searchQueries(calls);
|
|
689
1218
|
assert.equal(primed.length, 3, 'the mount read every scoped bucket once');
|
|
690
1219
|
const connections = connectionReads(calls).length;
|
|
691
|
-
assert.equal(connections,
|
|
1220
|
+
assert.equal(connections, 0, 'and no page of the All connection (S2)');
|
|
692
1221
|
|
|
693
1222
|
const before = clean(component.render(110).join('\n'));
|
|
694
1223
|
component.handleInput('f');
|
|
@@ -724,23 +1253,16 @@ describe('/issues actions (S3,S4)', () => {
|
|
|
724
1253
|
describe('/issues page seam (S5,D1)', () => {
|
|
725
1254
|
async function mountCapturing(root, rows = 24) {
|
|
726
1255
|
const base = makeIssuesRunner();
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
1256
|
+
// The extension's OWN view and client, taken after the load: one load compiles
|
|
1257
|
+
// its own lib modules, so the fakes go on the instance the command mounts.
|
|
1258
|
+
let lib;
|
|
1259
|
+
let realCreate;
|
|
1260
|
+
let realPage;
|
|
730
1261
|
const order = [];
|
|
731
1262
|
const pages = [];
|
|
732
1263
|
const holder = { options: null };
|
|
733
|
-
ghIssues.getIssuePage = (params, opts) => {
|
|
734
|
-
order.push('page');
|
|
735
|
-
pages.push({ params, opts });
|
|
736
|
-
return realPage(params, opts);
|
|
737
|
-
};
|
|
738
|
-
lib.createIssuesView = (options) => {
|
|
739
|
-
holder.options = options;
|
|
740
|
-
order.push('view');
|
|
741
|
-
return realCreate(options);
|
|
742
|
-
};
|
|
743
1264
|
const restore = () => {
|
|
1265
|
+
if (!lib) return;
|
|
744
1266
|
lib.createIssuesView = realCreate;
|
|
745
1267
|
ghIssues.getIssuePage = realPage;
|
|
746
1268
|
};
|
|
@@ -748,6 +1270,19 @@ describe('/issues page seam (S5,D1)', () => {
|
|
|
748
1270
|
let loaded = null;
|
|
749
1271
|
try {
|
|
750
1272
|
loaded = await loadExtension();
|
|
1273
|
+
lib = loaded.mod.libModule('issues-view.js');
|
|
1274
|
+
realCreate = lib.createIssuesView;
|
|
1275
|
+
realPage = ghIssues.getIssuePage;
|
|
1276
|
+
ghIssues.getIssuePage = (params, opts) => {
|
|
1277
|
+
order.push('page');
|
|
1278
|
+
pages.push({ params, opts });
|
|
1279
|
+
return realPage(params, opts);
|
|
1280
|
+
};
|
|
1281
|
+
lib.createIssuesView = (options) => {
|
|
1282
|
+
holder.options = options;
|
|
1283
|
+
order.push('view');
|
|
1284
|
+
return realCreate(options);
|
|
1285
|
+
};
|
|
751
1286
|
ghIssues.setGhRunner(base.runner);
|
|
752
1287
|
const scratch = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-gate-')));
|
|
753
1288
|
await fireSessionStart(loaded.hooks, gateCtx(scratch, []));
|
|
@@ -781,6 +1316,8 @@ describe('/issues page seam (S5,D1)', () => {
|
|
|
781
1316
|
['involved', 'Involved', null],
|
|
782
1317
|
['all', 'All', null],
|
|
783
1318
|
], 'bucket metadata only: no accumulated rows are handed to the view');
|
|
1319
|
+
assert.deepEqual(options.pages.filter((page) => page.lazy === true).map((page) => page.id), ['all'],
|
|
1320
|
+
'the All bucket is marked lazy so the mount-time prefetch skips it (S2)');
|
|
784
1321
|
assert.equal(options.loadPages, undefined, 'no eager/lazy-list loader is passed beside the fresh seam');
|
|
785
1322
|
assert.equal(typeof options.loadIssuePage, 'function');
|
|
786
1323
|
const first = run.pages[0];
|
|
@@ -1077,7 +1614,7 @@ describe('/issues repository identity (S5)', () => {
|
|
|
1077
1614
|
const run = await capturedIssuesOptions(root, { runner: gh.runner, calls: gh.calls });
|
|
1078
1615
|
const gitCalls = [];
|
|
1079
1616
|
const original = worktreeGit.runArgvAsync;
|
|
1080
|
-
worktreeGit.runArgvAsync = async (
|
|
1617
|
+
worktreeGit.runArgvAsync = async (_bin, argv) => {
|
|
1081
1618
|
gitCalls.push({ argv: argv.slice() });
|
|
1082
1619
|
return { status: 0, stdout: '', stderr: '', error: null };
|
|
1083
1620
|
};
|
|
@@ -1093,7 +1630,15 @@ describe('/issues repository identity (S5)', () => {
|
|
|
1093
1630
|
assert.equal(opened.ok, false, 'the opener refuses instead of opening another repository');
|
|
1094
1631
|
assert.match(opened.error, /is a local path, not a GitHub repository/);
|
|
1095
1632
|
assert.deepEqual(gitCalls, [], 'the browser opener never ran');
|
|
1096
|
-
|
|
1633
|
+
// S1/S3 (T1, T2): the session gate is dispatched startup work now and no
|
|
1634
|
+
// longer warms a session-wide `ok` from a scratch cwd, so THIS command's own
|
|
1635
|
+
// on-demand health probe (`gh api user`, `gh repo view`) runs here. That probe
|
|
1636
|
+
// asks gh whether it is usable; it reads nothing of this repository. No READ
|
|
1637
|
+
// and no opener reaches gh from a checkout it cannot name.
|
|
1638
|
+
const reads = gh.calls.filter((call) => call.argv[0] === 'issue'
|
|
1639
|
+
|| call.argv[0] === 'label'
|
|
1640
|
+
|| (call.argv[0] === 'api' && call.argv[1] === 'graphql'));
|
|
1641
|
+
assert.deepEqual(reads, [], 'no repository read left this checkout');
|
|
1097
1642
|
} finally {
|
|
1098
1643
|
worktreeGit.runArgvAsync = original;
|
|
1099
1644
|
run.restore();
|
|
@@ -1106,7 +1651,7 @@ describe('/issues repository identity (S5)', () => {
|
|
|
1106
1651
|
const run = await capturedIssuesOptions(root, { runner: gh.runner, calls: gh.calls });
|
|
1107
1652
|
const gitCalls = [];
|
|
1108
1653
|
const original = worktreeGit.runArgvAsync;
|
|
1109
|
-
worktreeGit.runArgvAsync = async (
|
|
1654
|
+
worktreeGit.runArgvAsync = async (_bin, argv) => {
|
|
1110
1655
|
gitCalls.push({ argv: argv.slice() });
|
|
1111
1656
|
return { status: 0, stdout: '', stderr: '', error: null };
|
|
1112
1657
|
};
|
|
@@ -1215,3 +1760,908 @@ describe('/issues registration survives a reused module', () => {
|
|
|
1215
1760
|
assert.ok(reloaded.has('issues'), 'a rebuilt registry on the same API must also regain the command');
|
|
1216
1761
|
});
|
|
1217
1762
|
});
|
|
1763
|
+
|
|
1764
|
+
// S7 (issues-all-toggle): `/issues <number>` opens the same panel on `Assigned`
|
|
1765
|
+
// with that issue selected and its detail shown, exactly as if the reader had
|
|
1766
|
+
// moved to Assigned and arrowed down to it. Anything that is not a bare
|
|
1767
|
+
// positive integer (optionally `#`-prefixed) keeps the command's original
|
|
1768
|
+
// refusal. S8 (the sidebar's cache) is another task and is not exercised here.
|
|
1769
|
+
describe('/issues <number> opens the panel on one issue (S7)', () => {
|
|
1770
|
+
const assignedSearches = (calls) => searchQueries(calls).filter((query) => query.startsWith('assignee:@me'));
|
|
1771
|
+
|
|
1772
|
+
function syntheticRow(number, title = `assigned issue ${number}`) {
|
|
1773
|
+
return {
|
|
1774
|
+
number,
|
|
1775
|
+
title,
|
|
1776
|
+
state: 'OPEN',
|
|
1777
|
+
createdAt: '2026-02-01T00:00:00Z',
|
|
1778
|
+
updatedAt: '2026-02-01T00:00:00Z',
|
|
1779
|
+
url: `https://example.test/issues/${number}`,
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
// A runner that answers the scoped SEARCH reads from per-bucket row lists,
|
|
1784
|
+
// and everything else from the shared fixture runner, so the mounted view's
|
|
1785
|
+
// own cursor paging is exercised through the real client seam.
|
|
1786
|
+
function pagedSearchRunner(rowsByBucket) {
|
|
1787
|
+
const base = makeIssuesRunner();
|
|
1788
|
+
const calls = [];
|
|
1789
|
+
const runner = async (bin, argv, opts) => {
|
|
1790
|
+
calls.push({ bin, argv: argv.slice(), cwd: opts ? opts.cwd : undefined });
|
|
1791
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
1792
|
+
const query = graphqlField(argv, 'query', '-f') || '';
|
|
1793
|
+
if (query.includes('type: ISSUE')) {
|
|
1794
|
+
const search = graphqlField(argv, 'search') || '';
|
|
1795
|
+
const rows = search.includes('assignee:@me') ? rowsByBucket.assigned
|
|
1796
|
+
: search.includes('involves:@me') ? rowsByBucket.involved
|
|
1797
|
+
: rowsByBucket.mine;
|
|
1798
|
+
return { status: 0, stdout: graphqlSearchPage(argv, rows || []), stderr: '', error: null };
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
return base.runner(bin, argv, opts);
|
|
1802
|
+
};
|
|
1803
|
+
return { runner, calls };
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
test('a bare number opens on Assigned with that row selected and its detail shown', async () => {
|
|
1807
|
+
const root = makeRepo({ tag: 'issues-one-number' });
|
|
1808
|
+
const { runner, calls } = makeIssuesRunner();
|
|
1809
|
+
const { component } = await openIssues(root, { runner, args: '76' });
|
|
1810
|
+
await tick();
|
|
1811
|
+
const frame = clean(component.render(200).join('\n'));
|
|
1812
|
+
assert.match(frame, /▸ Assigned/, 'the panel opens on the Assigned tab');
|
|
1813
|
+
assert.match(frame, /▸ chore: update/, 'the matching row is the selected one');
|
|
1814
|
+
assert.ok(calls.some((call) => call.argv[0] === 'issue' && call.argv[1] === 'view'
|
|
1815
|
+
&& call.argv.includes('76') && call.argv.includes('--json')),
|
|
1816
|
+
'the requested issue detail was read through gh');
|
|
1817
|
+
assert.equal(searchQueries(calls).length, 3, 'opening still reads exactly the three scoped buckets');
|
|
1818
|
+
assert.equal(connectionReads(calls).length, 0, 'and never the All connection (S2)');
|
|
1819
|
+
});
|
|
1820
|
+
|
|
1821
|
+
test('the #-prefixed form opens the same panel on the same issue', async () => {
|
|
1822
|
+
const root = makeRepo({ tag: 'issues-one-hash' });
|
|
1823
|
+
const { runner } = makeIssuesRunner();
|
|
1824
|
+
const { component } = await openIssues(root, { runner, args: '#76' });
|
|
1825
|
+
await tick();
|
|
1826
|
+
const frame = clean(component.render(200).join('\n'));
|
|
1827
|
+
assert.match(frame, /▸ Assigned/);
|
|
1828
|
+
assert.match(frame, /▸ chore: update/);
|
|
1829
|
+
});
|
|
1830
|
+
|
|
1831
|
+
test('anything else keeps the exact old refusal and opens nothing', async () => {
|
|
1832
|
+
const root = makeRepo({ tag: 'issues-one-refused' });
|
|
1833
|
+
const { commands, mod, hooks } = await loadExtension();
|
|
1834
|
+
ghIssues.setGhRunner(makeIssuesRunner().runner);
|
|
1835
|
+
const scratch = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-gate-')));
|
|
1836
|
+
await fireSessionStart(hooks, gateCtx(scratch, []));
|
|
1837
|
+
mod.setIssuesTuiLoader(async () => stubTui);
|
|
1838
|
+
for (const arg of ['0', '-3', '12abc', 'all', '5 6', '#', '#0']) {
|
|
1839
|
+
const { ctx, customs, notes } = makeCtx({ cwd: root, customImpl: async () => null });
|
|
1840
|
+
await commands.get('issues').handler(arg, ctx);
|
|
1841
|
+
assert.equal(customs.length, 0, `${arg}: no overlay is opened`);
|
|
1842
|
+
assert.deepEqual(notes, [[`Unknown option "${arg}". Use /issues.`, 'error']], `${arg}: the old refusal is unchanged`);
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1845
|
+
|
|
1846
|
+
test('a number that is not in Assigned says so and keeps the first row', async () => {
|
|
1847
|
+
const root = makeRepo({ tag: 'issues-one-missing' });
|
|
1848
|
+
const { runner } = makeIssuesRunner();
|
|
1849
|
+
const { component } = await openIssues(root, { runner, args: '51' });
|
|
1850
|
+
assert.ok(await waitFor(() => clean(component.render(200).join('\n')).includes('#51 is not in Assigned')));
|
|
1851
|
+
const frame = clean(component.render(200).join('\n'));
|
|
1852
|
+
assert.match(frame, /#51 is not in Assigned/, 'the note row names the miss');
|
|
1853
|
+
assert.match(frame, /▸ chore: update/, 'the first row is still the selection');
|
|
1854
|
+
});
|
|
1855
|
+
|
|
1856
|
+
test('a number on a later Assigned page is found by paging and selected', async () => {
|
|
1857
|
+
const root = makeRepo({ tag: 'issues-one-page2' });
|
|
1858
|
+
const rows = Array.from({ length: 18 }, (_, at) => syntheticRow(at + 1));
|
|
1859
|
+
const { runner, calls } = pagedSearchRunner({ mine: [], assigned: [...rows, syntheticRow(51)], involved: [] });
|
|
1860
|
+
const { component } = await openIssues(root, { runner, args: '51' });
|
|
1861
|
+
await tick();
|
|
1862
|
+
const frame = clean(component.render(200).join('\n'));
|
|
1863
|
+
assert.match(frame, /▸ assigned issue 51/, 'the second-page match is selected');
|
|
1864
|
+
assert.equal(assignedSearches(calls).length, 2, 'exactly one more page was read to find it');
|
|
1865
|
+
});
|
|
1866
|
+
|
|
1867
|
+
test('paging for a missing number stops at five Assigned pages', async () => {
|
|
1868
|
+
const root = makeRepo({ tag: 'issues-one-bound' });
|
|
1869
|
+
const rows = Array.from({ length: 200 }, (_, at) => syntheticRow(at + 1));
|
|
1870
|
+
const { runner, calls } = pagedSearchRunner({ mine: [], assigned: rows, involved: [] });
|
|
1871
|
+
const { component } = await openIssues(root, { runner, args: '999' });
|
|
1872
|
+
assert.ok(await waitFor(() => assignedSearches(calls).length >= 5));
|
|
1873
|
+
await tick();
|
|
1874
|
+
assert.equal(assignedSearches(calls).length, 5, 'the bound is five Assigned pages in total');
|
|
1875
|
+
const frame = clean(component.render(200).join('\n'));
|
|
1876
|
+
assert.match(frame, /#999 is not in Assigned/, 'the panel discloses the miss');
|
|
1877
|
+
assert.match(frame, /▸ assigned issue 1/, 'the first row stays selected');
|
|
1878
|
+
});
|
|
1879
|
+
|
|
1880
|
+
test('plain /issues still opens on My issues and is handed no initial issue', async () => {
|
|
1881
|
+
const root = makeRepo({ tag: 'issues-one-plain' });
|
|
1882
|
+
const run = await capturedIssuesOptions(root);
|
|
1883
|
+
try {
|
|
1884
|
+
assert.equal('initialBucket' in run.options, false, 'a plain open passes no initial bucket');
|
|
1885
|
+
assert.equal('initialIssue' in run.options, false, 'and no initial issue');
|
|
1886
|
+
} finally {
|
|
1887
|
+
run.restore();
|
|
1888
|
+
}
|
|
1889
|
+
const { runner } = makeIssuesRunner();
|
|
1890
|
+
const { component } = await openIssues(root, { runner });
|
|
1891
|
+
const frame = clean(component.render(200).join('\n'));
|
|
1892
|
+
assert.match(frame, /▸ My issues/, 'a plain open still starts on My issues');
|
|
1893
|
+
assert.ok(!frame.includes('is not in'), 'and paints no initial-issue note');
|
|
1894
|
+
});
|
|
1895
|
+
});
|
|
1896
|
+
|
|
1897
|
+
// ---------------------------------------------------------------------------
|
|
1898
|
+
// S8 (the panel ODD's T4; the sidebar ODD's S9 consumer half): the rail's
|
|
1899
|
+
// process cache is what makes the first frame instant. The cache is filled by
|
|
1900
|
+
// the section's ONE combined read — through the published bridge — and the
|
|
1901
|
+
// panel READS it, keyed by the identity the panel itself just proved.
|
|
1902
|
+
//
|
|
1903
|
+
// The contract under test, through the public surface only:
|
|
1904
|
+
// - with an entry for the proved identity, the three scoped pages are seeded
|
|
1905
|
+
// from it, so the first frame paints rows instead of `loading…`;
|
|
1906
|
+
// - the seeded open STILL reads: the visible bucket's page read is issued at
|
|
1907
|
+
// mount and its answer replaces the seeded rows, and every other seeded tab
|
|
1908
|
+
// is read the first time it is activated — nothing is seeded forever;
|
|
1909
|
+
// - with NO entry the panel behaves exactly as before (the same notes, the same
|
|
1910
|
+
// three scoped reads and the same first frame);
|
|
1911
|
+
// - a bucket the cache reported TRUNCATED never renders an exact total (`N+`);
|
|
1912
|
+
// - the panel never writes the cache: a second open paints the same seeded rows.
|
|
1913
|
+
// ---------------------------------------------------------------------------
|
|
1914
|
+
|
|
1915
|
+
describe('/issues opens from the rail cache (S8/T4)', () => {
|
|
1916
|
+
const BRIDGE_SLOT = Symbol.for('gentle-shell-bridge/api/v1');
|
|
1917
|
+
// The identity both halves prove for the fixture checkout: one remote would
|
|
1918
|
+
// have no scope identity, and `makeRepo` has none at all, so gh's own answer
|
|
1919
|
+
// (`tools/fixtures/gh-repo-view.json`) is normalized host-qualified.
|
|
1920
|
+
const IDENTITY = 'github.com/jonasotoaguilar/herdr-gentle-shell';
|
|
1921
|
+
|
|
1922
|
+
function installBridge() {
|
|
1923
|
+
const registered = [];
|
|
1924
|
+
globalThis[BRIDGE_SLOT] = {
|
|
1925
|
+
schema: 'gentle-shell-bridge/api',
|
|
1926
|
+
version: 1,
|
|
1927
|
+
registerRows: () => {},
|
|
1928
|
+
registerSection: (section) => { registered.push(section); return () => {}; },
|
|
1929
|
+
createStore: () => ({}),
|
|
1930
|
+
requestRepaint: () => {},
|
|
1931
|
+
};
|
|
1932
|
+
return registered;
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
// One issue node in the shape the rail's combined read asks for.
|
|
1936
|
+
function relatedNode(row) {
|
|
1937
|
+
const stamp = row.updatedAt || '2026-02-01T00:00:00Z';
|
|
1938
|
+
return {
|
|
1939
|
+
number: row.number,
|
|
1940
|
+
title: row.title,
|
|
1941
|
+
state: 'OPEN',
|
|
1942
|
+
stateReason: '',
|
|
1943
|
+
url: `https://example.test/issues/${row.number}`,
|
|
1944
|
+
createdAt: stamp,
|
|
1945
|
+
updatedAt: stamp,
|
|
1946
|
+
author: { login: 'me' },
|
|
1947
|
+
labels: { nodes: [] },
|
|
1948
|
+
// T10 (S9): the assignees the panel's first frame can show without
|
|
1949
|
+
// waiting for the detail read.
|
|
1950
|
+
assignees: { nodes: Array.isArray(row.assignees) ? row.assignees.map((login) => ({ login })) : [] },
|
|
1951
|
+
comments: { totalCount: 0 },
|
|
1952
|
+
reactionGroups: [],
|
|
1953
|
+
timelineItems: { nodes: [] },
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
// The rail's ONE combined answer: three aliased buckets, each with its exact
|
|
1958
|
+
// `issueCount`. `counts` overrides a count, which is how a bucket past the
|
|
1959
|
+
// cache's cap becomes `truncated`.
|
|
1960
|
+
function relatedAnswer({ mine = [], assigned = [], involved = [], counts = {} } = {}) {
|
|
1961
|
+
const bucket = (key, rows) => ({
|
|
1962
|
+
issueCount: Number.isInteger(counts[key]) ? counts[key] : rows.length,
|
|
1963
|
+
nodes: rows.map(relatedNode),
|
|
1964
|
+
});
|
|
1965
|
+
return {
|
|
1966
|
+
data: {
|
|
1967
|
+
mine: bucket('mine', mine),
|
|
1968
|
+
assigned: bucket('assigned', assigned),
|
|
1969
|
+
involved: bucket('involved', involved),
|
|
1970
|
+
},
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
function issueRow(number, title) {
|
|
1975
|
+
return {
|
|
1976
|
+
number,
|
|
1977
|
+
title,
|
|
1978
|
+
state: 'OPEN',
|
|
1979
|
+
createdAt: '2026-02-01T00:00:00Z',
|
|
1980
|
+
updatedAt: '2026-02-01T00:00:00Z',
|
|
1981
|
+
url: `https://example.test/issues/${number}`,
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
// The detail `gh issue view` answers with when a test holds it and then
|
|
1986
|
+
// releases it: one row's whole issue, with a body.
|
|
1987
|
+
function defaultIssueDetail(row) {
|
|
1988
|
+
return {
|
|
1989
|
+
number: row.number,
|
|
1990
|
+
title: row.title,
|
|
1991
|
+
state: 'OPEN',
|
|
1992
|
+
body: `body of issue ${row.number}`,
|
|
1993
|
+
author: { login: 'me' },
|
|
1994
|
+
labels: [],
|
|
1995
|
+
assignees: [],
|
|
1996
|
+
createdAt: '2026-02-01T00:00:00Z',
|
|
1997
|
+
updatedAt: '2026-02-01T00:00:00Z',
|
|
1998
|
+
url: `https://example.test/issues/${row.number}`,
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
// A runner over the shared fixture runner: the rail's combined read answers
|
|
2003
|
+
// from `related`, and the panel's page reads can be HELD so the seeded first
|
|
2004
|
+
// frame is observable before any answer lands.
|
|
2005
|
+
function cacheRunner({ related, holdPages = false, holdDetail = false, fixtureIssue = defaultIssueDetail }) {
|
|
2006
|
+
const base = makeIssuesRunner();
|
|
2007
|
+
const calls = [];
|
|
2008
|
+
const held = [];
|
|
2009
|
+
const heldDetails = [];
|
|
2010
|
+
const runner = async (bin, argv, opts) => {
|
|
2011
|
+
calls.push({ bin, argv: argv.slice(), env: { ...((opts && opts.env) || {}) }, cwd: opts ? opts.cwd : undefined });
|
|
2012
|
+
if (holdDetail && argv[0] === 'issue' && argv[1] === 'view') {
|
|
2013
|
+
const entry = { argv: argv.slice(), release: null };
|
|
2014
|
+
entry.answer = new Promise((resolve) => {
|
|
2015
|
+
entry.release = (row) => resolve({
|
|
2016
|
+
status: 0, stdout: JSON.stringify(fixtureIssue(row)), stderr: '', error: null,
|
|
2017
|
+
});
|
|
2018
|
+
});
|
|
2019
|
+
heldDetails.push(entry);
|
|
2020
|
+
return entry.answer;
|
|
2021
|
+
}
|
|
2022
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
2023
|
+
const query = graphqlField(argv, 'query', '-f') || '';
|
|
2024
|
+
if (query.includes('mine: search(')) {
|
|
2025
|
+
return { status: 0, stdout: JSON.stringify(related), stderr: '', error: null };
|
|
2026
|
+
}
|
|
2027
|
+
if (holdPages && query.includes('type: ISSUE')) {
|
|
2028
|
+
const entry = { argv: argv.slice(), release: null };
|
|
2029
|
+
entry.answer = new Promise((resolve) => {
|
|
2030
|
+
entry.release = (rows) => resolve({
|
|
2031
|
+
status: 0, stdout: graphqlSearchPage(argv, rows), stderr: '', error: null,
|
|
2032
|
+
});
|
|
2033
|
+
});
|
|
2034
|
+
held.push(entry);
|
|
2035
|
+
return entry.answer;
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
return base.runner(bin, argv, opts);
|
|
2039
|
+
};
|
|
2040
|
+
return { runner, calls, held, heldDetails };
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
// Mount `/issues` over an already-loaded extension. The component is the real
|
|
2044
|
+
// view, against the real (injected) client.
|
|
2045
|
+
async function mountIssues(loaded, root, { args = '' } = {}) {
|
|
2046
|
+
loaded.mod.setIssuesTuiLoader(async () => stubTui);
|
|
2047
|
+
let factory = null;
|
|
2048
|
+
const { ctx, notes } = makeCtx({ cwd: root });
|
|
2049
|
+
ctx.ui.custom = async (captured) => { factory = captured; return null; };
|
|
2050
|
+
await loaded.commands.get('issues').handler(args, ctx);
|
|
2051
|
+
assert.ok(factory, 'the overlay opens');
|
|
2052
|
+
const { component } = openComponent(factory, makeHostTui(24));
|
|
2053
|
+
return { component, notes };
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
// The rail fills the cache exactly as it does in a live session: the bridge is
|
|
2057
|
+
// published BEFORE the extension loads (that is when the section is
|
|
2058
|
+
// registered), `session_start` binds the checkout, and ONE drawn frame starts
|
|
2059
|
+
// the section's read.
|
|
2060
|
+
async function warmRail(root, related, options = {}) {
|
|
2061
|
+
const registered = installBridge();
|
|
2062
|
+
const loaded = await loadExtension();
|
|
2063
|
+
const gh = cacheRunner({
|
|
2064
|
+
related,
|
|
2065
|
+
holdPages: true,
|
|
2066
|
+
holdDetail: options.holdDetail === true,
|
|
2067
|
+
fixtureIssue: options.fixtureIssue || defaultIssueDetail,
|
|
2068
|
+
});
|
|
2069
|
+
ghIssues.setGhRunner(gh.runner);
|
|
2070
|
+
await fireSessionStart(loaded.hooks, gateCtx(root, []));
|
|
2071
|
+
assert.equal(registered.length, 1, 'the rail section is registered through the bridge');
|
|
2072
|
+
const section = registered[0];
|
|
2073
|
+
const ctx = { cwd: root, ui: { notify: () => {} } };
|
|
2074
|
+
const deadline = Date.now() + 4000;
|
|
2075
|
+
while (Date.now() < deadline) {
|
|
2076
|
+
const rows = section.lines(ctx);
|
|
2077
|
+
if (!(rows.length === 1 && rows[0].label === 'loading…')) break;
|
|
2078
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
2079
|
+
}
|
|
2080
|
+
const labels = section.lines(ctx).map((row) => row.label);
|
|
2081
|
+
assert.ok(labels.length > 0 && labels[0] !== 'loading…',
|
|
2082
|
+
`the rail never filled the cache (saw ${JSON.stringify(labels)})`);
|
|
2083
|
+
return { loaded, gh, section, labels };
|
|
2084
|
+
}
|
|
2085
|
+
|
|
2086
|
+
test('a warmed cache paints the cached rows on the first frame and still reads', async () => {
|
|
2087
|
+
const root = makeRepo({ tag: 'issues-cache-warm' });
|
|
2088
|
+
const related = relatedAnswer({
|
|
2089
|
+
mine: [{ number: 12, title: 'Newer twelve', updatedAt: '2026-02-02T00:00:00Z' },
|
|
2090
|
+
{ number: 11, title: 'Older eleven', updatedAt: '2026-02-01T00:00:00Z' }],
|
|
2091
|
+
assigned: [{ number: 21, title: 'Assigned twenty-one', updatedAt: '2026-02-03T00:00:00Z' }],
|
|
2092
|
+
involved: [{ number: 31, title: 'Involved thirty-one', updatedAt: '2026-02-04T00:00:00Z' }],
|
|
2093
|
+
});
|
|
2094
|
+
const warmed = await warmRail(root, related);
|
|
2095
|
+
const { loaded, gh } = warmed;
|
|
2096
|
+
assert.deepEqual(warmed.labels,
|
|
2097
|
+
['#21 Assigned twenty-one', '#12 Newer twelve', '#11 Older eleven'],
|
|
2098
|
+
'the rail draws the merged mine+assigned list it caches (S7/T8)');
|
|
2099
|
+
const railRead = gh.calls.filter((call) => call.argv[0] === 'api' && call.argv[1] === 'graphql')[0];
|
|
2100
|
+
assert.equal(railRead.env.GH_REPO, IDENTITY,
|
|
2101
|
+
'the cache entry is keyed by the identity the rail proved for this checkout');
|
|
2102
|
+
|
|
2103
|
+
const { component } = await mountIssues(loaded, root);
|
|
2104
|
+
const first = clean(component.render(200).join('\n'));
|
|
2105
|
+
// The list row is the title alone (the number lives in the preview beside
|
|
2106
|
+
// it), and the seeded frames are what is on screen before any page read
|
|
2107
|
+
// answers — which is exactly what the cache is for.
|
|
2108
|
+
assert.match(first, /Newer twelve/, 'the cached row is painted before any page read answers');
|
|
2109
|
+
assert.match(first, /Older eleven/);
|
|
2110
|
+
assert.match(first, /▸ My issues \(2\)/, 'and the seeded bucket reports the rows it holds');
|
|
2111
|
+
assert.match(first, /Assigned \(1\)/);
|
|
2112
|
+
assert.match(first, /Involved \(1\)/);
|
|
2113
|
+
|
|
2114
|
+
// The seeded open STILL reads: the visible bucket (My issues) asks for its
|
|
2115
|
+
// own page at mount, so the seeded rows are replaced by a real answer.
|
|
2116
|
+
await waitFor(() => gh.held.length === 1, 'opening never started the visible bucket\'s own read');
|
|
2117
|
+
assert.deepEqual(searchQueries(gh.held), ['author:@me sort:updated-desc'],
|
|
2118
|
+
'the held read is the visible bucket\'s scoped search');
|
|
2119
|
+
|
|
2120
|
+
gh.held[0].release([issueRow(40, 'Fresh forty')]);
|
|
2121
|
+
await waitFor(() => clean(component.render(200).join('\n')).includes('Fresh forty'));
|
|
2122
|
+
const afterAnswer = clean(component.render(200).join('\n'));
|
|
2123
|
+
assert.ok(!afterAnswer.includes('Newer twelve'),
|
|
2124
|
+
'the real answer replaced the seeded row instead of sitting beside it');
|
|
2125
|
+
|
|
2126
|
+
// A seeded tab that mount did not read is read on its FIRST activation: the
|
|
2127
|
+
// seed is never the tab's only data.
|
|
2128
|
+
component.handleInput('tab');
|
|
2129
|
+
await waitFor(() => gh.held.length === 2, 'the activated seeded tab never read its own page');
|
|
2130
|
+
assert.deepEqual(searchQueries([gh.held[1]]), ['assignee:@me sort:updated-desc'],
|
|
2131
|
+
'the Assigned tab reads its own bucket the first time it is entered');
|
|
2132
|
+
|
|
2133
|
+
// The panel never writes the cache: a second open still paints the SAME
|
|
2134
|
+
// seeded rows, not the answer the first open read — and it backs them with
|
|
2135
|
+
// its own read again.
|
|
2136
|
+
const second = await mountIssues(loaded, root);
|
|
2137
|
+
const secondFrame = clean(second.component.render(200).join('\n'));
|
|
2138
|
+
assert.match(secondFrame, /Newer twelve/, 'the cache still holds the rail\'s rows');
|
|
2139
|
+
await waitFor(() => gh.held.length === 3, 'the second open never read its own page');
|
|
2140
|
+
assert.deepEqual(searchQueries([gh.held[2]]), ['author:@me sort:updated-desc'],
|
|
2141
|
+
'the second open reads the visible bucket again');
|
|
2142
|
+
});
|
|
2143
|
+
|
|
2144
|
+
// S7 (T8): an issue that is BOTH authored and assigned is one merged row, and
|
|
2145
|
+
// the assigned bucket wins the collision — so clicking it opens on Assigned,
|
|
2146
|
+
// exactly as the user asked ("assigned tiene prioridad").
|
|
2147
|
+
test('a number in both mine and assigned opens on Assigned', async () => {
|
|
2148
|
+
const root = makeRepo({ tag: 'issues-seed-both' });
|
|
2149
|
+
const related = relatedAnswer({
|
|
2150
|
+
mine: [{ number: 13, title: 'Both thirteen', updatedAt: '2026-02-03T00:00:00Z' }],
|
|
2151
|
+
assigned: [{ number: 13, title: 'Both thirteen', updatedAt: '2026-02-03T00:00:00Z' }],
|
|
2152
|
+
});
|
|
2153
|
+
const { loaded } = await warmRail(root, related);
|
|
2154
|
+
const { component } = await mountIssues(loaded, root, { args: '13' });
|
|
2155
|
+
const frame = clean(component.render(240).join('\n'));
|
|
2156
|
+
const bar = frame.split('\n').find((line) => line.includes('Assigned')) ?? '';
|
|
2157
|
+
assert.match(bar, /▸ Assigned/, 'the assigned bucket wins the collision');
|
|
2158
|
+
assert.ok(!frame.includes('is not in'), 'and the number is found, not reported missing');
|
|
2159
|
+
});
|
|
2160
|
+
|
|
2161
|
+
// S9 (T10) part 2: the rail's cached row is the panel's seed, so the FIRST
|
|
2162
|
+
// frame of a numbered open already carries the issue's identity — number,
|
|
2163
|
+
// title, labels, assignees, author — while the body is still on its way. The
|
|
2164
|
+
// defect was the opposite: a bare `loading…` pane for facts the rail knew.
|
|
2165
|
+
test('a numbered open paints the seeded facts on its first frame, with the body behind them', async () => {
|
|
2166
|
+
const root = makeRepo({ tag: 'issues-seed-detail' });
|
|
2167
|
+
const related = relatedAnswer({
|
|
2168
|
+
assigned: [{
|
|
2169
|
+
number: 22,
|
|
2170
|
+
title: 'Assigned twenty-two',
|
|
2171
|
+
updatedAt: '2026-02-02T00:00:00Z',
|
|
2172
|
+
assignees: ['ana'],
|
|
2173
|
+
}],
|
|
2174
|
+
});
|
|
2175
|
+
const { loaded, gh } = await warmRail(root, related, { holdDetail: true });
|
|
2176
|
+
const { component } = await mountIssues(loaded, root, { args: '22' });
|
|
2177
|
+
await waitFor(() => gh.heldDetails.length === 1, 'the detail read never started');
|
|
2178
|
+
|
|
2179
|
+
const first = clean(component.render(240).join('\n'));
|
|
2180
|
+
assert.match(first, /#22 Assigned twenty-two/, 'the number and title are on screen at once');
|
|
2181
|
+
assert.match(first, /\[open\]/, 'and the state the row already carried');
|
|
2182
|
+
assert.match(first, /assignees: ana/, 'so are the assignees the rail cached');
|
|
2183
|
+
assert.match(first, /\(no labels\)/, 'and the labels line, honest about a row that carried none');
|
|
2184
|
+
assert.match(first, /by me/, 'and the author');
|
|
2185
|
+
// S9: the frame opens ON the issue. The body marker still names the read,
|
|
2186
|
+
// but only under those facts — never a bare `loading…` pane.
|
|
2187
|
+
assert.match(first, /loading…/, 'the body read still names itself under the facts');
|
|
2188
|
+
assert.match(first, /#22 Assigned twenty-two[\s\S]*loading…/,
|
|
2189
|
+
'the facts come first and the read is named below them — never a bare loading pane');
|
|
2190
|
+
assert.ok(!first.includes('body of issue 22'),
|
|
2191
|
+
'the body is not invented from a row that never carried it');
|
|
2192
|
+
|
|
2193
|
+
// The body follows behind the facts, in the same pane.
|
|
2194
|
+
gh.heldDetails[0].release({ number: 22, title: 'Assigned twenty-two' });
|
|
2195
|
+
assert.ok(await waitFor(() => clean(component.render(240).join('\n')).includes('body of issue 22')),
|
|
2196
|
+
'the detail read replaced the pending frame');
|
|
2197
|
+
});
|
|
2198
|
+
|
|
2199
|
+
// S9 (T10) part 3: the command picks the bucket from the cache — `assigned`
|
|
2200
|
+
// when the number is there, `mine` when it is only there. A number that is
|
|
2201
|
+
// only authored therefore opens on My issues, selected and loaded.
|
|
2202
|
+
test('a number that is only in mine opens on My issues', async () => {
|
|
2203
|
+
const root = makeRepo({ tag: 'issues-seed-mine' });
|
|
2204
|
+
const related = relatedAnswer({
|
|
2205
|
+
mine: [{ number: 61, title: 'Mine sixty-one', updatedAt: '2026-02-03T00:00:00Z' }],
|
|
2206
|
+
assigned: [{ number: 21, title: 'Assigned twenty-one', updatedAt: '2026-02-02T00:00:00Z' }],
|
|
2207
|
+
});
|
|
2208
|
+
const { loaded, gh } = await warmRail(root, related);
|
|
2209
|
+
assert.deepEqual(gh.held.length, 0, 'the rail read answers no page');
|
|
2210
|
+
|
|
2211
|
+
const { component } = await mountIssues(loaded, root, { args: '61' });
|
|
2212
|
+
const frame = clean(component.render(240).join('\n'));
|
|
2213
|
+
const bar = frame.split('\n').find((line) => line.includes('My issues')) ?? '';
|
|
2214
|
+
assert.match(bar, /▸ My issues/, 'the reader lands on My issues, which holds the number');
|
|
2215
|
+
assert.match(frame, /Mine sixty-one/, 'and its row is on screen');
|
|
2216
|
+
assert.ok(!frame.includes('is not in'), 'no miss is reported for a number the rail had');
|
|
2217
|
+
assert.ok(await waitFor(() => gh.held.length >= 1), 'the visible bucket still reads its own page');
|
|
2218
|
+
assert.deepEqual(searchQueries([gh.held[0]]), ['author:@me sort:updated-desc'],
|
|
2219
|
+
'and the page it reads is My issues, the bucket the cache chose');
|
|
2220
|
+
});
|
|
2221
|
+
|
|
2222
|
+
test('with no cache the panel opens exactly as before', async () => {
|
|
2223
|
+
const root = makeRepo({ tag: 'issues-cache-empty' });
|
|
2224
|
+
const base = makeIssuesRunner();
|
|
2225
|
+
const calls = [];
|
|
2226
|
+
const held = [];
|
|
2227
|
+
// No bridge at all: no rail, no draw, so no entry for this identity.
|
|
2228
|
+
const loaded = await loadExtension();
|
|
2229
|
+
ghIssues.setGhRunner(async (bin, argv, opts) => {
|
|
2230
|
+
calls.push({ bin, argv: argv.slice(), cwd: opts ? opts.cwd : undefined });
|
|
2231
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
2232
|
+
const query = graphqlField(argv, 'query', '-f') || '';
|
|
2233
|
+
if (query.includes('type: ISSUE')) {
|
|
2234
|
+
const entry = { argv: argv.slice(), release: null };
|
|
2235
|
+
entry.answer = new Promise((resolve) => {
|
|
2236
|
+
entry.release = (rows) => resolve({
|
|
2237
|
+
status: 0, stdout: graphqlSearchPage(argv, rows), stderr: '', error: null,
|
|
2238
|
+
});
|
|
2239
|
+
});
|
|
2240
|
+
held.push(entry);
|
|
2241
|
+
return entry.answer;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
return base.runner(bin, argv, opts);
|
|
2245
|
+
});
|
|
2246
|
+
const scratch = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-gate-')));
|
|
2247
|
+
await fireSessionStart(loaded.hooks, gateCtx(scratch, []));
|
|
2248
|
+
|
|
2249
|
+
const { component, notes } = await mountIssues(loaded, root);
|
|
2250
|
+
await waitFor(() => held.length === 3, 'the open never read the three scoped buckets');
|
|
2251
|
+
assert.deepEqual(notes, [], 'an empty cache produces no note');
|
|
2252
|
+
assert.deepEqual(searchQueries(calls), [
|
|
2253
|
+
'author:@me sort:updated-desc',
|
|
2254
|
+
'assignee:@me sort:updated-desc',
|
|
2255
|
+
'involves:@me -author:@me sort:updated-desc',
|
|
2256
|
+
], 'the open reads the three scoped buckets exactly as before');
|
|
2257
|
+
assert.equal(connectionReads(calls).length, 0, 'and never the All connection');
|
|
2258
|
+
// `render(100)` produces the full-screen frame the host paints. Runs of box
|
|
2259
|
+
// drawing and padding are collapsed so the assertion states the frame's
|
|
2260
|
+
// CONTENT — the box, the search row, the loading line and the footer, with
|
|
2261
|
+
// today's blank body rows. A seeded frame would carry rows here instead.
|
|
2262
|
+
const frame = clean(component.render(100).join('\n'));
|
|
2263
|
+
const shape = frame.split('\n').map((line) => line
|
|
2264
|
+
.trimEnd()
|
|
2265
|
+
.replace(/─{2,}/g, '─…')
|
|
2266
|
+
.replace(/ {2,}/g, ' '));
|
|
2267
|
+
assert.deepEqual(shape, [
|
|
2268
|
+
'╭─ ◈ Issues ─…╮',
|
|
2269
|
+
'│ › Search │',
|
|
2270
|
+
'│ loading issues… │',
|
|
2271
|
+
...new Array(19).fill('│ │'),
|
|
2272
|
+
// S11: no issue is under the cursor on the first frame, so the five
|
|
2273
|
+
// tokens that act on one are absent; every other hint stays.
|
|
2274
|
+
'│ ↑↓ move · ctrl+j/k scroll · ←→ bucket · t search · g all issues · esc close │',
|
|
2275
|
+
'╰─…╯',
|
|
2276
|
+
], 'the first frame is today\'s loading frame, byte for byte');
|
|
2277
|
+
});
|
|
2278
|
+
|
|
2279
|
+
test('a truncated cached bucket never claims an exact total', async () => {
|
|
2280
|
+
const root = makeRepo({ tag: 'issues-cache-truncated' });
|
|
2281
|
+
const assigned = Array.from({ length: 105 }, (_, at) => ({
|
|
2282
|
+
number: 100 + at,
|
|
2283
|
+
title: `assigned ${100 + at}`,
|
|
2284
|
+
updatedAt: '2026-02-01T00:00:00Z',
|
|
2285
|
+
}));
|
|
2286
|
+
const related = relatedAnswer({
|
|
2287
|
+
mine: [{ number: 12, title: 'Mine twelve', updatedAt: '2026-02-02T00:00:00Z' }],
|
|
2288
|
+
assigned,
|
|
2289
|
+
counts: { assigned: 105 },
|
|
2290
|
+
});
|
|
2291
|
+
const { loaded } = await warmRail(root, related);
|
|
2292
|
+
|
|
2293
|
+
const { component } = await mountIssues(loaded, root);
|
|
2294
|
+
const first = clean(component.render(240).join('\n'));
|
|
2295
|
+
assert.match(first, /Assigned \(100\+\)/, 'a bucket the cache truncated is painted as inexact');
|
|
2296
|
+
assert.ok(!/Assigned \(100\)/.test(first), 'and never with an exact total it does not have');
|
|
2297
|
+
assert.ok(!/Assigned \(105\)/.test(first), 'nor with a count no surface read');
|
|
2298
|
+
});
|
|
2299
|
+
|
|
2300
|
+
// T17 (E17b): the rail refuses to trust an entry whose cached rows no longer
|
|
2301
|
+
// match the `issueCount` the response reported (its next sync is a full
|
|
2302
|
+
// re-read), so a total derived from those rows is exactly the number the rail
|
|
2303
|
+
// itself refuses to claim. The panel must paint it inexact too.
|
|
2304
|
+
// E18 (S4, verify round 5 blocker b): a seeded page is rows on screen before its
|
|
2305
|
+
// own read answers, and the verifier's exact scenario is `/issues 22` over a
|
|
2306
|
+
// seeded `Assigned` of `[21, 22]` with that page still in flight: the initial
|
|
2307
|
+
// selection landed on 21, and `c` then `ctrl+s` posted a comment on 21 while the
|
|
2308
|
+
// human asked for 22. A mutation on an issue nobody chose is the one thing the
|
|
2309
|
+
// identity work exists to prevent.
|
|
2310
|
+
//
|
|
2311
|
+
// The property: with `Assigned` seeded and `/issues <n>` where `n` is the second
|
|
2312
|
+
// seeded row, no mutation of any kind — comment, labels, assignees, close — can
|
|
2313
|
+
// reach any row other than `n`.
|
|
2314
|
+
test('a seeded Assigned page never lends a mutation to another issue (E18)', async () => {
|
|
2315
|
+
const root = makeRepo({ tag: 'issues-seed-mutation' });
|
|
2316
|
+
const related = relatedAnswer({
|
|
2317
|
+
assigned: [
|
|
2318
|
+
{ number: 21, title: 'Assigned twenty-one', updatedAt: '2026-02-03T00:00:00Z' },
|
|
2319
|
+
{ number: 22, title: 'Assigned twenty-two', updatedAt: '2026-02-02T00:00:00Z' },
|
|
2320
|
+
],
|
|
2321
|
+
});
|
|
2322
|
+
const warmed = await warmRail(root, related);
|
|
2323
|
+
const { loaded, gh } = warmed;
|
|
2324
|
+
const { component } = await mountIssues(loaded, root, { args: '22' });
|
|
2325
|
+
const frame = () => clean(component.render(240).join('\n'));
|
|
2326
|
+
const writes = () => gh.calls.filter((call) => call.argv[0] === 'issue'
|
|
2327
|
+
&& ['comment', 'edit', 'close'].includes(call.argv[1]));
|
|
2328
|
+
|
|
2329
|
+
assert.ok(await waitFor(() => gh.held.length >= 1), 'the numbered open issued its own Assigned read');
|
|
2330
|
+
assert.deepEqual(searchQueries([gh.held[0]]), ['assignee:@me sort:updated-desc'],
|
|
2331
|
+
'the held read is the bucket the panel was opened on');
|
|
2332
|
+
|
|
2333
|
+
// The verifier's exact scenario: `c`, then `ctrl+s`, in that window.
|
|
2334
|
+
component.handleInput('c');
|
|
2335
|
+
for (const ch of 'looks right') component.handleInput(ch);
|
|
2336
|
+
component.handleInput('ctrl+s');
|
|
2337
|
+
assert.ok(await waitFor(() => writes().length > 0), 'the comment reached gh');
|
|
2338
|
+
assert.deepEqual(writes().map((call) => call.argv.slice(0, 3)), [['issue', 'comment', '22']],
|
|
2339
|
+
'the comment names the issue the human asked for, never the seeded #21');
|
|
2340
|
+
|
|
2341
|
+
// The page's own answer lands. The correct issue is still the only one any
|
|
2342
|
+
// mutation can reach.
|
|
2343
|
+
gh.held[0].release([
|
|
2344
|
+
issueRow(21, 'Assigned twenty-one'),
|
|
2345
|
+
issueRow(22, 'Assigned twenty-two'),
|
|
2346
|
+
]);
|
|
2347
|
+
assert.ok(await waitFor(() => frame().includes('l labels')),
|
|
2348
|
+
'the answer is on screen and the detail confirmed the role');
|
|
2349
|
+
|
|
2350
|
+
component.handleInput('l');
|
|
2351
|
+
await tick();
|
|
2352
|
+
component.handleInput('down');
|
|
2353
|
+
component.handleInput('space');
|
|
2354
|
+
component.handleInput('ctrl+s');
|
|
2355
|
+
assert.ok(await waitFor(() => writes().some((call) => call.argv[1] === 'edit'
|
|
2356
|
+
&& call.argv.includes('--add-label'))), 'the label save reached gh');
|
|
2357
|
+
assert.ok(await waitFor(() => component.state.mode === 'list'), 'the label save closed the editor');
|
|
2358
|
+
// A successful write re-reads the detail, and the editor keys are only
|
|
2359
|
+
// offered once that answer confirms the repository role again.
|
|
2360
|
+
const roleBack = await waitFor(() => frame().includes('l labels'));
|
|
2361
|
+
if (!roleBack) console.log('DEBUG2>>>\n' + frame().split('\n').filter((line) => !line.trim().startsWith('│') || line.includes('Assigned twenty') || line.includes('·')).join('\n') + '\n<<<DEBUG2');
|
|
2362
|
+
assert.ok(roleBack, 'the refreshed detail confirms the role');
|
|
2363
|
+
|
|
2364
|
+
component.handleInput('a');
|
|
2365
|
+
// S10: the editor's title is its name alone; its keys are the footer row.
|
|
2366
|
+
assert.ok(await waitFor(() => frame().includes('Assignees') && frame().includes('space toggle')),
|
|
2367
|
+
'the assignee editor opened');
|
|
2368
|
+
assert.ok(await waitFor(() => !frame().includes('loading assignees')), 'the assignable users answered');
|
|
2369
|
+
component.handleInput('space');
|
|
2370
|
+
component.handleInput('ctrl+s');
|
|
2371
|
+
const assigneeWrite = (call) => call.argv[1] === 'edit'
|
|
2372
|
+
&& (call.argv.includes('--add-assignee') || call.argv.includes('--remove-assignee'));
|
|
2373
|
+
assert.ok(await waitFor(() => writes().some(assigneeWrite)), 'the assignee save reached gh');
|
|
2374
|
+
assert.ok(await waitFor(() => component.state.mode === 'list'), 'the assignee save closed the editor');
|
|
2375
|
+
assert.ok(await waitFor(() => frame().includes('x close')), 'the refreshed detail confirms the role again');
|
|
2376
|
+
|
|
2377
|
+
component.handleInput('x');
|
|
2378
|
+
component.handleInput('enter');
|
|
2379
|
+
assert.ok(await waitFor(() => writes().some((call) => call.argv[1] === 'close')), 'the close reached gh');
|
|
2380
|
+
|
|
2381
|
+
assert.deepEqual(writes().map((call) => call.argv[2]), ['22', '22', '22', '22'],
|
|
2382
|
+
'every mutation this panel ran named #22, the issue the human asked for');
|
|
2383
|
+
assert.equal(writes().some((call) => call.argv[2] === '21'), false,
|
|
2384
|
+
'and not one of them ever named the seeded #21');
|
|
2385
|
+
});
|
|
2386
|
+
|
|
2387
|
+
test('an inconsistent cached entry never claims an exact total', async () => {
|
|
2388
|
+
const root = makeRepo({ tag: 'issues-cache-inconsistent' });
|
|
2389
|
+
// ONE read whose assigned `issueCount` (2) outruns the nodes it returned
|
|
2390
|
+
// (1): the count invariant breaks on the very first apply, which is exactly
|
|
2391
|
+
// the state a departed issue leaves behind between two rail reads.
|
|
2392
|
+
const related = relatedAnswer({
|
|
2393
|
+
mine: [{ number: 12, title: 'Mine twelve', updatedAt: '2026-02-02T00:00:00Z' }],
|
|
2394
|
+
assigned: [{ number: 21, title: 'Assigned twenty-one', updatedAt: '2026-02-03T00:00:00Z' }],
|
|
2395
|
+
counts: { assigned: 2 },
|
|
2396
|
+
});
|
|
2397
|
+
const { loaded } = await warmRail(root, related);
|
|
2398
|
+
|
|
2399
|
+
const { component } = await mountIssues(loaded, root);
|
|
2400
|
+
const first = clean(component.render(240).join('\n'));
|
|
2401
|
+
assert.match(first, /Assigned \(1\+\)/, 'an entry the rail calls inconsistent is seeded inexact');
|
|
2402
|
+
assert.ok(!/Assigned \(1\)(?!\+)/.test(first), 'and never with the exact total it cannot prove');
|
|
2403
|
+
});
|
|
2404
|
+
});
|
|
2405
|
+
|
|
2406
|
+
// ---------------------------------------------------------------------------
|
|
2407
|
+
// S21 (T17), the human's own words: «me la asigne a mi o me quite la
|
|
2408
|
+
// asignacion … no se refresca altiro los tabs … actualmente eso demora o no
|
|
2409
|
+
// refrezca de hecho hasta que lo cierro y abro panel». This drives the REAL
|
|
2410
|
+
// panel over the injected `gh` client, and the REAL rail section over the
|
|
2411
|
+
// published bridge, so every assertion below is a read or a write that reached
|
|
2412
|
+
// `gh`:
|
|
2413
|
+
// - a save that changed the VIEWER's own assignment drops the rail's cached
|
|
2414
|
+
// entry for this repository, so the rail's next read is the FULL one (a delta
|
|
2415
|
+
// merges by issue number and can never express a removal) and it starts now,
|
|
2416
|
+
// not on the 20 s floor;
|
|
2417
|
+
// - the panel reads the `assigned` bucket again and its count and rows follow;
|
|
2418
|
+
// - a write that did not land invalidates nothing: no rail read, no page read,
|
|
2419
|
+
// the pre-write rows and count stay, and the draft stays open with the error.
|
|
2420
|
+
// ---------------------------------------------------------------------------
|
|
2421
|
+
describe('/issues reflects a self-assignment on the panel and the rail (S21/T17)', () => {
|
|
2422
|
+
const BRIDGE_SLOT = Symbol.for('gentle-shell-bridge/api/v1');
|
|
2423
|
+
const VIEWER = 'jonasotoaguilar';
|
|
2424
|
+
|
|
2425
|
+
// The one repository state both surfaces read. `assignees` is what makes an
|
|
2426
|
+
// issue `assigned` to the viewer; `mine` is authorship, which an assignment
|
|
2427
|
+
// never changes.
|
|
2428
|
+
function repoState() {
|
|
2429
|
+
return {
|
|
2430
|
+
issues: new Map([
|
|
2431
|
+
[12, { number: 12, title: 'Mine twelve', mine: true, assignees: [], updatedAt: '2026-02-02T00:00:00Z' }],
|
|
2432
|
+
[21, { number: 21, title: 'Assigned twenty-one', mine: false, assignees: [VIEWER], updatedAt: '2026-02-03T00:00:00Z' }],
|
|
2433
|
+
]),
|
|
2434
|
+
};
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
const authored = (state) => [...state.issues.values()].filter((row) => row.mine);
|
|
2438
|
+
const assignedToViewer = (state) => [...state.issues.values()].filter((row) => row.assignees.includes(VIEWER));
|
|
2439
|
+
|
|
2440
|
+
function searchRow(row) {
|
|
2441
|
+
return {
|
|
2442
|
+
number: row.number,
|
|
2443
|
+
title: row.title,
|
|
2444
|
+
state: 'OPEN',
|
|
2445
|
+
url: `https://example.test/issues/${row.number}`,
|
|
2446
|
+
createdAt: row.updatedAt,
|
|
2447
|
+
updatedAt: row.updatedAt,
|
|
2448
|
+
author: { login: row.mine ? VIEWER : 'octocat' },
|
|
2449
|
+
};
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
function relatedNode(row) {
|
|
2453
|
+
return {
|
|
2454
|
+
...searchRow(row),
|
|
2455
|
+
labels: { nodes: [] },
|
|
2456
|
+
assignees: { nodes: row.assignees.map((login) => ({ login })) },
|
|
2457
|
+
comments: { totalCount: 0 },
|
|
2458
|
+
reactionGroups: [],
|
|
2459
|
+
timelineItems: { nodes: [] },
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
function relatedAnswer(state) {
|
|
2464
|
+
const bucket = (rows) => ({ issueCount: rows.length, nodes: rows.map(relatedNode) });
|
|
2465
|
+
return { data: { mine: bucket(authored(state)), assigned: bucket(assignedToViewer(state)), involved: bucket([]) } };
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
function assignmentRunner(state, failure) {
|
|
2469
|
+
const calls = [];
|
|
2470
|
+
const ok = (stdout) => ({ status: 0, stdout, stderr: '', error: null });
|
|
2471
|
+
const runner = async (bin, argv, opts) => {
|
|
2472
|
+
calls.push({ bin, argv: argv.slice(), cwd: opts ? opts.cwd : undefined });
|
|
2473
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
2474
|
+
const query = graphqlField(argv, 'query', '-f') || '';
|
|
2475
|
+
const search = graphqlField(argv, 'search');
|
|
2476
|
+
if (query.includes('mine: search(')) return ok(JSON.stringify(relatedAnswer(state)));
|
|
2477
|
+
if (search !== null) {
|
|
2478
|
+
if (search.includes('assignee:@me')) return ok(graphqlSearchPage(argv, assignedToViewer(state).map(searchRow)));
|
|
2479
|
+
if (search.includes('involves:@me')) return ok(graphqlSearchPage(argv, []));
|
|
2480
|
+
return ok(graphqlSearchPage(argv, authored(state).map(searchRow)));
|
|
2481
|
+
}
|
|
2482
|
+
if (query.includes('assignableUsers')) {
|
|
2483
|
+
return ok(JSON.stringify({ data: { repository: { assignableUsers: {
|
|
2484
|
+
nodes: [{ login: VIEWER, name: 'Jonathan Soto' }, { login: 'octocat', name: 'Octo Cat' }],
|
|
2485
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
2486
|
+
} } } }));
|
|
2487
|
+
}
|
|
2488
|
+
// The assignee mutation's own permission read: it names the viewer too,
|
|
2489
|
+
// which is what makes the save's answer able to say "this one was mine".
|
|
2490
|
+
if (query.includes('viewer {')) {
|
|
2491
|
+
return ok(JSON.stringify({ data: { repository: { viewerPermission: 'WRITE' }, viewer: { login: VIEWER } } }));
|
|
2492
|
+
}
|
|
2493
|
+
if (query.includes('projectItems')) {
|
|
2494
|
+
return ok(JSON.stringify({ data: { repository: { issue: { projectItems: { nodes: [], pageInfo: { hasNextPage: false } } } } } }));
|
|
2495
|
+
}
|
|
2496
|
+
if (query.includes('viewerPermission')) {
|
|
2497
|
+
const number = Number(graphqlField(argv, 'number', '-F'));
|
|
2498
|
+
const row = state.issues.get(number);
|
|
2499
|
+
return ok(JSON.stringify({ data: { repository: {
|
|
2500
|
+
viewerPermission: 'WRITE',
|
|
2501
|
+
issue: {
|
|
2502
|
+
assignees: { nodes: (row ? row.assignees : []).map((login) => ({ login })), pageInfo: { hasNextPage: false } },
|
|
2503
|
+
closedByPullRequestsReferences: { nodes: [], pageInfo: { hasNextPage: false } },
|
|
2504
|
+
},
|
|
2505
|
+
} } }));
|
|
2506
|
+
}
|
|
2507
|
+
return ok(JSON.stringify({ data: {} }));
|
|
2508
|
+
}
|
|
2509
|
+
if (argv[0] === 'api') return ok(fixture('gh-api-user.json'));
|
|
2510
|
+
if (argv[0] === 'repo') return ok(fixture('gh-repo-view.json'));
|
|
2511
|
+
if (argv[0] === 'issue' && argv[1] === 'view' && argv.includes('--json')) {
|
|
2512
|
+
const number = Number(argv[2]);
|
|
2513
|
+
const row = state.issues.get(number);
|
|
2514
|
+
return ok(JSON.stringify({
|
|
2515
|
+
number,
|
|
2516
|
+
title: row.title,
|
|
2517
|
+
state: 'OPEN',
|
|
2518
|
+
body: `body of issue ${number}`,
|
|
2519
|
+
author: { login: row.mine ? VIEWER : 'octocat' },
|
|
2520
|
+
labels: [],
|
|
2521
|
+
createdAt: row.updatedAt,
|
|
2522
|
+
updatedAt: row.updatedAt,
|
|
2523
|
+
url: `https://example.test/issues/${number}`,
|
|
2524
|
+
comments: [],
|
|
2525
|
+
}));
|
|
2526
|
+
}
|
|
2527
|
+
if (argv[0] === 'issue' && argv[1] === 'edit') {
|
|
2528
|
+
if (failure && failure.on === true) return { status: 1, stdout: '', stderr: 'Forbidden', error: null };
|
|
2529
|
+
const row = state.issues.get(Number(argv[2]));
|
|
2530
|
+
for (let index = 3; index < argv.length; index += 1) {
|
|
2531
|
+
const flag = argv[index];
|
|
2532
|
+
const login = argv[index + 1];
|
|
2533
|
+
if (flag === '--add-assignee' && row) row.assignees = [...new Set([...row.assignees, login])];
|
|
2534
|
+
if (flag === '--remove-assignee' && row) row.assignees = row.assignees.filter((name) => name !== login);
|
|
2535
|
+
}
|
|
2536
|
+
return ok('');
|
|
2537
|
+
}
|
|
2538
|
+
if (argv[0] === 'label' && argv[1] === 'list') return ok(fixture('gh-label-list.json'));
|
|
2539
|
+
return ok('');
|
|
2540
|
+
};
|
|
2541
|
+
return { runner, calls };
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
// The rail fills its cache exactly as a live session does: the bridge is
|
|
2545
|
+
// published BEFORE the extension loads, `session_start` binds the checkout,
|
|
2546
|
+
// and ONE drawn frame starts the read.
|
|
2547
|
+
async function warmRail(root, state, options = {}) {
|
|
2548
|
+
const registered = [];
|
|
2549
|
+
globalThis[BRIDGE_SLOT] = {
|
|
2550
|
+
schema: 'gentle-shell-bridge/api',
|
|
2551
|
+
version: 1,
|
|
2552
|
+
registerRows: () => {},
|
|
2553
|
+
registerSection: (section) => { registered.push(section); return () => {}; },
|
|
2554
|
+
createStore: () => ({}),
|
|
2555
|
+
requestRepaint: () => {},
|
|
2556
|
+
};
|
|
2557
|
+
const loaded = await loadExtension();
|
|
2558
|
+
const gh = assignmentRunner(state, options.failure);
|
|
2559
|
+
ghIssues.setGhRunner(gh.runner);
|
|
2560
|
+
await fireSessionStart(loaded.hooks, gateCtx(root, []));
|
|
2561
|
+
assert.equal(registered.length, 1, 'the rail section is registered through the bridge');
|
|
2562
|
+
const section = registered[0];
|
|
2563
|
+
const ctx = { cwd: root, ui: { notify: () => {} } };
|
|
2564
|
+
const deadline = Date.now() + 4000;
|
|
2565
|
+
while (Date.now() < deadline) {
|
|
2566
|
+
const rows = section.lines(ctx);
|
|
2567
|
+
if (!(rows.length === 1 && rows[0].label === 'loading…')) break;
|
|
2568
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
2569
|
+
}
|
|
2570
|
+
return { loaded, gh, section, ctx };
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
async function mountPanel(loaded, root) {
|
|
2574
|
+
loaded.mod.setIssuesTuiLoader(async () => stubTui);
|
|
2575
|
+
let factory = null;
|
|
2576
|
+
const { ctx } = makeCtx({ cwd: root });
|
|
2577
|
+
ctx.ui.custom = async (captured) => { factory = captured; return null; };
|
|
2578
|
+
await loaded.commands.get('issues').handler('', ctx);
|
|
2579
|
+
assert.ok(factory, 'the overlay opens');
|
|
2580
|
+
const host = makeHostTui(24);
|
|
2581
|
+
const { component } = openComponent(factory, host.tui);
|
|
2582
|
+
return { component, host };
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
const isRailRead = (call) => call.argv[0] === 'api' && call.argv[1] === 'graphql'
|
|
2586
|
+
&& (graphqlField(call.argv, 'query', '-f') || '').includes('mine: search(');
|
|
2587
|
+
const railReads = (gh) => gh.calls.filter(isRailRead);
|
|
2588
|
+
const railQuery = (call) => graphqlField(call.argv, 'query', '-f');
|
|
2589
|
+
const assigneeWrites = (gh) => gh.calls.filter((call) => call.argv[0] === 'issue'
|
|
2590
|
+
&& call.argv[1] === 'edit'
|
|
2591
|
+
&& (call.argv.includes('--add-assignee') || call.argv.includes('--remove-assignee')));
|
|
2592
|
+
const frameOf = (component) => clean(component.render(240).join('\n'));
|
|
2593
|
+
|
|
2594
|
+
test('unassigning yourself repaints the tab, refetches the full rail entry and counts one less', async () => {
|
|
2595
|
+
const root = makeRepo({ tag: 'issues-self-assign' });
|
|
2596
|
+
const state = repoState();
|
|
2597
|
+
const { loaded, gh, section, ctx } = await warmRail(root, state);
|
|
2598
|
+
assert.equal(section.meta(ctx), '2 issues', 'the rail starts with both rows');
|
|
2599
|
+
|
|
2600
|
+
const { component } = await mountPanel(loaded, root);
|
|
2601
|
+
// `Assigned` is where the viewer's own row lives; the tab reads it on entry.
|
|
2602
|
+
component.handleInput('tab');
|
|
2603
|
+
assert.ok(await waitFor(() => frameOf(component).includes('Assigned twenty-one')),
|
|
2604
|
+
'the Assigned tab paints the viewer\'s row before the write');
|
|
2605
|
+
|
|
2606
|
+
// The editor key requires the repository role the DETAIL confirms, so the
|
|
2607
|
+
// press waits for that answer exactly like the panel's other editor tests.
|
|
2608
|
+
assert.ok(await waitFor(() => frameOf(component).includes('a assign')), 'the detail confirmed the role');
|
|
2609
|
+
component.handleInput('a');
|
|
2610
|
+
assert.ok(await waitFor(() => frameOf(component).includes('Assignees') && frameOf(component).includes('space toggle')),
|
|
2611
|
+
'the assignee editor opened');
|
|
2612
|
+
assert.ok(await waitFor(() => !frameOf(component).includes('loading assignees')),
|
|
2613
|
+
'the assignable users answered');
|
|
2614
|
+
component.handleInput('space');
|
|
2615
|
+
component.handleInput('ctrl+s');
|
|
2616
|
+
assert.ok(await waitFor(() => assigneeWrites(gh).length === 1), 'the assignee save reached gh');
|
|
2617
|
+
assert.deepEqual(assigneeWrites(gh)[0].argv,
|
|
2618
|
+
['issue', 'edit', '21', '--remove-assignee', VIEWER],
|
|
2619
|
+
'the write names the viewer exactly as the editor toggled it');
|
|
2620
|
+
|
|
2621
|
+
// The panel: the Assigned bucket was read again and its count follows.
|
|
2622
|
+
assert.ok(await waitFor(() => frameOf(component).includes('Assigned (0)')),
|
|
2623
|
+
'the Assigned tab count follows the removal without reopening the panel');
|
|
2624
|
+
assert.ok(!frameOf(component).includes('Assigned twenty-one'), 'and the row is gone');
|
|
2625
|
+
const assignedReads = gh.calls
|
|
2626
|
+
.filter((call) => call.argv[0] === 'api' && call.argv[1] === 'graphql')
|
|
2627
|
+
.map((call) => graphqlField(call.argv, 'search'))
|
|
2628
|
+
.filter((value) => value !== null && value.includes('assignee:@me'));
|
|
2629
|
+
assert.ok(assignedReads.length >= 2, 'the write invalidated the Assigned page, so it was read again');
|
|
2630
|
+
|
|
2631
|
+
// The rail: one read started by the write itself, and it is the FULL one —
|
|
2632
|
+
// a delta could only merge by issue number and could never drop the row.
|
|
2633
|
+
assert.ok(await waitFor(() => railReads(gh).length >= 2), 'the write started a rail read of its own');
|
|
2634
|
+
assert.match(railQuery(railReads(gh)[1]), /first: 100/,
|
|
2635
|
+
'the dropped entry makes the next rail read the full size, so a removal can land');
|
|
2636
|
+
assert.ok(await waitFor(() => section.meta(ctx) === '1 issues'), 'the rail count follows the removal');
|
|
2637
|
+
assert.deepEqual(section.lines(ctx).map((row) => row.label), ['#12 Mine twelve'],
|
|
2638
|
+
'and the merged rows are the ones the full read answered');
|
|
2639
|
+
});
|
|
2640
|
+
|
|
2641
|
+
test('a rejected assignee save repaints nothing and keeps the row and the count', async () => {
|
|
2642
|
+
const root = makeRepo({ tag: 'issues-self-assign-fail' });
|
|
2643
|
+
const state = repoState();
|
|
2644
|
+
// GitHub refuses the write: the answer is the only source of truth here, so
|
|
2645
|
+
// a rejection that reached the surface must leave every row and count alone.
|
|
2646
|
+
const failure = { on: false };
|
|
2647
|
+
const { loaded, gh, section, ctx } = await warmRail(root, state, { failure });
|
|
2648
|
+
const { component } = await mountPanel(loaded, root);
|
|
2649
|
+
component.handleInput('tab');
|
|
2650
|
+
assert.ok(await waitFor(() => frameOf(component).includes('Assigned twenty-one')), 'the row is on screen');
|
|
2651
|
+
assert.ok(await waitFor(() => frameOf(component).includes('a assign')), 'the detail confirmed the role');
|
|
2652
|
+
component.handleInput('a');
|
|
2653
|
+
assert.ok(await waitFor(() => !frameOf(component).includes('loading assignees')), 'the users answered');
|
|
2654
|
+
component.handleInput('space');
|
|
2655
|
+
const before = railReads(gh).length;
|
|
2656
|
+
failure.on = true;
|
|
2657
|
+
component.handleInput('ctrl+s');
|
|
2658
|
+
assert.ok(await waitFor(() => /Forbidden/.test(frameOf(component))), 'the rejection is visible');
|
|
2659
|
+
await tick();
|
|
2660
|
+
await tick();
|
|
2661
|
+
assert.equal(component.state.mode, 'assignees', 'the editor keeps the draft');
|
|
2662
|
+
assert.equal(railReads(gh).length, before, 'a failed write invalidates nothing, so no rail read starts');
|
|
2663
|
+
assert.equal(section.meta(ctx), '2 issues', 'the rail keeps the pre-write count');
|
|
2664
|
+
assert.match(frameOf(component), /Assigned \(1\)/, 'and the panel keeps the pre-write count');
|
|
2665
|
+
assert.ok(frameOf(component).includes('Assigned twenty-one'), 'the row never left');
|
|
2666
|
+
});
|
|
2667
|
+
});
|