pi-odd-worktree 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -319
- package/extensions/odd-worktree-tools.ts +4145 -2529
- package/lib/bash-activity.js +1164 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1416 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +308 -14
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -712
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1419 -0
- package/tools/bash-design.test.js +1091 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +610 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1871 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +391 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1512 -66
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4195 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2565 -309
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +419 -199
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
|
@@ -0,0 +1,4195 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// T1/T2/T8/T9/T10/T11 (issues-sidebar S1-S7): the rail section and its wiring.
|
|
3
|
+
//
|
|
4
|
+
// Contract under test, through the public surface only:
|
|
5
|
+
// - the rows are the UNION of the checkout repository's OPEN issues the viewer
|
|
6
|
+
// authored and the ones they are assigned (S7/T8), merged and deduplicated by
|
|
7
|
+
// number, ordered `updatedAt` descending, each row keeping the bucket it came
|
|
8
|
+
// from so its click can ask for it — while the header reports the merged count
|
|
9
|
+
// alone (`8 issues`, never `8 assigned`, and `8 issues · stale` while stalled);
|
|
10
|
+
// the heading reads `GITHUB` and the count names its unit (S12/T10);
|
|
11
|
+
// - a row reads `#<number> <title>`, and the body paints at most SEVEN of them
|
|
12
|
+
// (S4); a read that produced more appends ONE eighth, dim, clickable
|
|
13
|
+
// `and N more issues` row (`N+` when the read hit its fetch bound) and a click
|
|
14
|
+
// on it dispatches `/issues`;
|
|
15
|
+
// - ONE combined GraphQL read (S9/T14) returns the rows AND their
|
|
16
|
+
// pull-request cross-reference facts (`author:@me`, `assignee:@me` and
|
|
17
|
+
// `involves:@me -author:@me` in one request), feeds a process cache and leaves
|
|
18
|
+
// every failure to the section's own read state; a row whose issue has a pull
|
|
19
|
+
// request wears that pull request's NUMBER behind the glyph the human asked
|
|
20
|
+
// for — `\ue726 #69` (S7/T5) — in the bridge's
|
|
21
|
+
// right-hand `meta` column — painted `muted` by the bridge itself, which is
|
|
22
|
+
// the gray the user asked for — and one without a pull request carries no
|
|
23
|
+
// `meta`;
|
|
24
|
+
// - a failed refresh over an on-screen list keeps every row and reports
|
|
25
|
+
// `<n> issues · stale` (T10), while a failed first read is still one error row —
|
|
26
|
+
// except a session cwd that is not a repository (S12/T11), whose one line is
|
|
27
|
+
// exactly `not a git repository` in the `dim` tone, never `error`;
|
|
28
|
+
// - a host with no bridge gets ONE warning per process naming
|
|
29
|
+
// `pi install npm:gentle-shell-bridge` (T11), primary sessions only, after
|
|
30
|
+
// the announcement window and never once the bridge announced;
|
|
31
|
+
// - `lines()`/`meta()` are synchronous frames over an in-process snapshot: a
|
|
32
|
+
// never-settled read still answers, two stale frames schedule ONE refresh,
|
|
33
|
+
// and `onRefreshed` fires once per landed refresh;
|
|
34
|
+
// - a row click defers `open(number, identity, bucket)` off the paint path,
|
|
35
|
+
// exactly once, and a failing opener lands in the snapshot instead of escaping
|
|
36
|
+
// the caller; the identity is the one the ROW was built from, so a row
|
|
37
|
+
// retained across a checkout change opens the repository it was read from;
|
|
38
|
+
// the click itself proves NOTHING (S9/T10): the panel proves its own identity
|
|
39
|
+
// when it opens, and a host that cannot dispatch says so visibly;
|
|
40
|
+
// - a read still in flight at `session_shutdown` repaints nothing and lands
|
|
41
|
+
// nowhere;
|
|
42
|
+
// - `refreshIfStale(maxAgeMs)` is the activity seam: one read for an absent or
|
|
43
|
+
// aged snapshot, nothing for a fresh one, one in flight, or a disposed one;
|
|
44
|
+
// - the three states are rows (`loading…`, `no open issues`, ONE error row),
|
|
45
|
+
// never a throw;
|
|
46
|
+
// - the extension reaches the rail ONLY through gentle-shell-bridge's
|
|
47
|
+
// published object (read from its Symbol slot, never imported): present it
|
|
48
|
+
// registers one section, absent it subscribes to the ready announcement
|
|
49
|
+
// once and registers nothing;
|
|
50
|
+
// - the drawn section reads the checkout's own repository ONCE:
|
|
51
|
+
// `checkoutRepoScope({cwd})` then ONE combined `gh api graphql` read of the
|
|
52
|
+
// three scoped buckets, and a failed resolution is the error row with NO `gh`
|
|
53
|
+
// call;
|
|
54
|
+
// - a hidden section costs nothing (T13): `session_start` reads nothing at all,
|
|
55
|
+
// `drawnWithin(window)` is false until `lines()`/`meta()` draws (and false
|
|
56
|
+
// again after `invalidate()`/`dispose()`), and the session's own activity
|
|
57
|
+
// (`before_agent_start`, `turn_end`) reads ONLY while it is true — behind the
|
|
58
|
+
// same 30 s floor, which is what recovers a `/reload` (no `session_start`
|
|
59
|
+
// fires) and what keeps an idle session free of calls;
|
|
60
|
+
// - `session_shutdown` drops the snapshot and forgets the session context.
|
|
61
|
+
//
|
|
62
|
+
// Every child process is injected: `gh` goes through lib/gh-issues.js
|
|
63
|
+
// `setGhRunner`, git through its `setGitRunner`, and the checkouts live under
|
|
64
|
+
// os.tmpdir() and are removed in `after()`. The bridge slot is process-wide, so
|
|
65
|
+
// it is always deleted again.
|
|
66
|
+
|
|
67
|
+
const { test, after, afterEach, beforeEach } = require('node:test');
|
|
68
|
+
const assert = require('node:assert/strict');
|
|
69
|
+
const fs = require('node:fs');
|
|
70
|
+
const os = require('node:os');
|
|
71
|
+
const path = require('node:path');
|
|
72
|
+
const { execFileSync } = require('node:child_process');
|
|
73
|
+
|
|
74
|
+
const { LIB_DIR, loadExtension, stubbedSource, installDefaultBridge } = require('./fixtures/load-extension.js');
|
|
75
|
+
const { pathToFileURL } = require('node:url');
|
|
76
|
+
const { createIssuesSection } = require('../lib/issues-section.js');
|
|
77
|
+
|
|
78
|
+
const BRIDGE_SLOT = Symbol.for('gentle-shell-bridge/api/v1');
|
|
79
|
+
// T11's "one warning per process" lives on a process-wide slot, so a test that
|
|
80
|
+
// expects the warning must not inherit another test's.
|
|
81
|
+
const WARNED_SLOT = Symbol.for('odd-worktree/issues-sidebar/install-warned');
|
|
82
|
+
const IDENTITY = 'github.com/myfork/project';
|
|
83
|
+
|
|
84
|
+
// The harness may ITSELF run inside an agent child (`GENTLE_PI_AGENTS_CHILD=1`),
|
|
85
|
+
// which is exactly the signal the missing-bridge warning respects, so these tests
|
|
86
|
+
// own it: cleared for the file, restored once at the end.
|
|
87
|
+
const savedChildEnv = process.env.GENTLE_PI_AGENTS_CHILD;
|
|
88
|
+
delete process.env.GENTLE_PI_AGENTS_CHILD;
|
|
89
|
+
after(() => {
|
|
90
|
+
if (savedChildEnv === undefined) delete process.env.GENTLE_PI_AGENTS_CHILD;
|
|
91
|
+
else process.env.GENTLE_PI_AGENTS_CHILD = savedChildEnv;
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// The lib instance the LAST extension load actually uses (its first libRequire
|
|
95
|
+
// purges this directory once and then reuses the cache), so patching it with
|
|
96
|
+
// `setGhRunner`/`setGitRunner` reaches the section's own reads.
|
|
97
|
+
let ghIssues = null;
|
|
98
|
+
|
|
99
|
+
const roots = [];
|
|
100
|
+
after(() => {
|
|
101
|
+
for (const dir of roots) {
|
|
102
|
+
try { fs.rmSync(dir, { recursive: true, force: true }); } catch {}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// T8 (S10): the drawn section now keeps a real, unref'd floor timer, and a test
|
|
107
|
+
// that ends while the section is still drawn would leave that timer to fire 20 s
|
|
108
|
+
// later — in a later test, with no runner of its own. The clock jumps ten minutes
|
|
109
|
+
// between tests, so every such timer finds the section OUTSIDE its drawn window
|
|
110
|
+
// and stops without reading (and without arming another one). Nothing else about
|
|
111
|
+
// the suite notices: every assertion measures a distance between two instants of
|
|
112
|
+
// the same test.
|
|
113
|
+
let suiteClockSkewMs = 0;
|
|
114
|
+
const realDateNow = Date.now;
|
|
115
|
+
Date.now = () => realDateNow() + suiteClockSkewMs;
|
|
116
|
+
|
|
117
|
+
afterEach(() => {
|
|
118
|
+
delete globalThis[BRIDGE_SLOT];
|
|
119
|
+
delete globalThis[WARNED_SLOT];
|
|
120
|
+
suiteClockSkewMs += 10 * 60 * 1000;
|
|
121
|
+
if (ghIssues) {
|
|
122
|
+
ghIssues.setGhRunner(null);
|
|
123
|
+
ghIssues.setGitRunner(null);
|
|
124
|
+
ghIssues.setGhWhich(null);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// S4 (T3): the read cache has a disk half, so every test starts from an EMPTY
|
|
129
|
+
// cache directory of its own: no test can inherit a warm identity from another
|
|
130
|
+
// (which would silently turn a full read into a delta), and nothing here ever
|
|
131
|
+
// touches a real `$XDG_CACHE_HOME` or home. A test that needs the directory to
|
|
132
|
+
// survive two loads names its own and restores this one.
|
|
133
|
+
beforeEach(() => {
|
|
134
|
+
process.env.XDG_CACHE_HOME = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-cache-home-')));
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
function track(dir) {
|
|
138
|
+
roots.push(dir);
|
|
139
|
+
return dir;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// A manual scheduler: the section's refresh and its click callbacks are queued
|
|
143
|
+
// and only run when a test says so, so "deferred" is observable.
|
|
144
|
+
function manualSchedule() {
|
|
145
|
+
const queue = [];
|
|
146
|
+
return {
|
|
147
|
+
schedule: (fn) => { queue.push(fn); },
|
|
148
|
+
pending: () => queue.length,
|
|
149
|
+
async flush() {
|
|
150
|
+
while (queue.length > 0) {
|
|
151
|
+
const fn = queue.shift();
|
|
152
|
+
await fn();
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function issue(number, title, updatedAt) {
|
|
159
|
+
return { number, title, updatedAt };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// `count` assigned issues, newest last in the array so a sorted paint is
|
|
163
|
+
// distinguishable from the read order.
|
|
164
|
+
function issueList(count) {
|
|
165
|
+
return Array.from({ length: count }, (_, index) => {
|
|
166
|
+
const day = String(index + 1).padStart(2, '0');
|
|
167
|
+
return issue(index + 1, `Issue ${index + 1}`, `2024-01-${day}T00:00:00Z`);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function readyLoad(issues, truncated = false) {
|
|
172
|
+
return async () => ({ ok: true, identity: IDENTITY, issues, truncated });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ---------------------------------------------------------------------------
|
|
176
|
+
// T1/T8: lib/issues-section.js, the pure module.
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
test('S1/S4: the assigned issues sort by updatedAt, read #<number> <title> and cap at seven', async () => {
|
|
180
|
+
const sched = manualSchedule();
|
|
181
|
+
const handle = createIssuesSection({
|
|
182
|
+
load: readyLoad([
|
|
183
|
+
issue(3, 'Older', '2024-01-01T00:00:00Z'),
|
|
184
|
+
issue(1, 'Newest', '2024-04-01T00:00:00Z'),
|
|
185
|
+
issue(2, 'Middle', '2024-03-01T00:00:00Z'),
|
|
186
|
+
]),
|
|
187
|
+
open: () => {},
|
|
188
|
+
openAll: () => {},
|
|
189
|
+
schedule: sched.schedule,
|
|
190
|
+
});
|
|
191
|
+
handle.section.lines({});
|
|
192
|
+
await sched.flush();
|
|
193
|
+
|
|
194
|
+
const rows = handle.section.lines({});
|
|
195
|
+
assert.deepEqual(rows.map((row) => row.label), ['#1 Newest', '#2 Middle', '#3 Older'],
|
|
196
|
+
'rows sort by updatedAt descending, never by the order they were read in');
|
|
197
|
+
assert.deepEqual(rows.map((row) => row.tone), ['text', 'text', 'text'],
|
|
198
|
+
'every issue row is the host\'s plain text tone');
|
|
199
|
+
assert.deepEqual(Object.keys(rows[0]).sort(), ['label', 'onClick', 'tone'],
|
|
200
|
+
'a row is its label, its tone and its click — nothing else');
|
|
201
|
+
|
|
202
|
+
const snap = handle.snapshot();
|
|
203
|
+
assert.deepEqual(Object.keys(snap).sort(),
|
|
204
|
+
['at', 'error', 'identity', 'issues', 'rows', 'status', 'truncated'],
|
|
205
|
+
'the snapshot reports exactly what a caller can observe, with no bucket fields left');
|
|
206
|
+
assert.equal(snap.status, 'ready');
|
|
207
|
+
assert.equal(snap.identity, IDENTITY);
|
|
208
|
+
assert.equal(snap.truncated, false);
|
|
209
|
+
assert.equal(snap.issues.length, 3);
|
|
210
|
+
assert.equal(snap.error, null);
|
|
211
|
+
assert.equal(handle.snapshot().mine, undefined, 'no `mine` bucket survives');
|
|
212
|
+
assert.equal(handle.snapshot().assigned, undefined, 'no `assigned` bucket survives');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('S4: seven or fewer issues paint no overflow row at all', async () => {
|
|
216
|
+
const seven = createIssuesSection({ load: readyLoad(issueList(7)), open: () => {}, openAll: () => {}, schedule: () => {} });
|
|
217
|
+
await seven.refresh();
|
|
218
|
+
const sevenRows = seven.section.lines({});
|
|
219
|
+
assert.equal(sevenRows.length, 7, 'exactly seven issues fill the body on their own');
|
|
220
|
+
assert.ok(sevenRows.every((row) => !/more issues$/.test(row.label)), 'no overflow row appears');
|
|
221
|
+
|
|
222
|
+
const fewer = createIssuesSection({ load: readyLoad(issueList(2)), open: () => {}, openAll: () => {}, schedule: () => {} });
|
|
223
|
+
await fewer.refresh();
|
|
224
|
+
assert.deepEqual(fewer.section.lines({}).map((row) => row.label), ['#2 Issue 2', '#1 Issue 1'],
|
|
225
|
+
'fewer than seven issues paint only their own rows');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('S4: no issue row carries a meta — the header reports the count instead', async () => {
|
|
229
|
+
const handle = createIssuesSection({
|
|
230
|
+
load: readyLoad(issueList(2)),
|
|
231
|
+
open: () => {},
|
|
232
|
+
openAll: () => {},
|
|
233
|
+
schedule: () => {},
|
|
234
|
+
});
|
|
235
|
+
await handle.refresh();
|
|
236
|
+
const rows = handle.section.lines({});
|
|
237
|
+
for (const row of rows) {
|
|
238
|
+
assert.equal('meta' in row, false, `no row carries a meta (saw ${JSON.stringify(row)})`);
|
|
239
|
+
}
|
|
240
|
+
assert.equal(handle.section.meta({}), '2 issues', 'the heading names the one relation and its count');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test('S4: more than seven issues paint seven rows plus one dim, clickable overflow row', async () => {
|
|
244
|
+
const opened = [];
|
|
245
|
+
const openedAll = [];
|
|
246
|
+
const sched = manualSchedule();
|
|
247
|
+
const handle = createIssuesSection({
|
|
248
|
+
load: readyLoad(issueList(9)),
|
|
249
|
+
open: (number) => { opened.push(number); },
|
|
250
|
+
openAll: () => { openedAll.push(1); },
|
|
251
|
+
schedule: sched.schedule,
|
|
252
|
+
});
|
|
253
|
+
await handle.refresh();
|
|
254
|
+
|
|
255
|
+
const rows = handle.section.lines({});
|
|
256
|
+
assert.equal(rows.length, 8, 'seven issue rows plus the one overflow row');
|
|
257
|
+
assert.deepEqual(rows.slice(0, 7).map((row) => row.label),
|
|
258
|
+
['#9 Issue 9', '#8 Issue 8', '#7 Issue 7', '#6 Issue 6', '#5 Issue 5', '#4 Issue 4', '#3 Issue 3'],
|
|
259
|
+
'the body keeps the seven most recently updated issues');
|
|
260
|
+
assert.equal(rows[7].label, 'and 2 more issues');
|
|
261
|
+
assert.equal(rows[7].tone, 'dim');
|
|
262
|
+
assert.equal('meta' in rows[7], false, 'the overflow row carries no meta either');
|
|
263
|
+
assert.equal(typeof rows[7].onClick, 'function');
|
|
264
|
+
assert.equal(handle.section.meta({}), '9 issues',
|
|
265
|
+
'the header counts every issue read, before any display cap');
|
|
266
|
+
|
|
267
|
+
rows[7].onClick();
|
|
268
|
+
assert.deepEqual(openedAll, [], 'the overflow click never runs on the paint path');
|
|
269
|
+
await sched.flush();
|
|
270
|
+
assert.deepEqual(openedAll, [1], 'the overflow row opens the /issues panel exactly once');
|
|
271
|
+
assert.deepEqual(opened, [], 'the overflow row opens the panel, never one issue');
|
|
272
|
+
|
|
273
|
+
// The overflow seam classifies its outcome exactly like an issue row's click:
|
|
274
|
+
// a resolved `{ ok: false }` is recorded, never thrown.
|
|
275
|
+
const failingSched = manualSchedule();
|
|
276
|
+
const failing = createIssuesSection({
|
|
277
|
+
load: readyLoad(issueList(9)),
|
|
278
|
+
open: () => {},
|
|
279
|
+
openAll: () => Promise.resolve({ ok: false, error: 'cannot open the issues panel' }),
|
|
280
|
+
schedule: failingSched.schedule,
|
|
281
|
+
});
|
|
282
|
+
await failing.refresh();
|
|
283
|
+
failing.section.lines({})[7].onClick();
|
|
284
|
+
await failingSched.flush();
|
|
285
|
+
assert.equal(failing.snapshot().error, 'cannot open the issues panel',
|
|
286
|
+
'a failed panel dispatch lands in the snapshot instead of escaping');
|
|
287
|
+
assert.equal(failing.section.lines({}).length, 8, 'a dispatch failure never turns the list into an error row');
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test('S4: a read that reached its fetch bound writes the overflow count with a +', async () => {
|
|
291
|
+
const handle = createIssuesSection({
|
|
292
|
+
load: readyLoad(issueList(20), true),
|
|
293
|
+
open: () => {},
|
|
294
|
+
openAll: () => {},
|
|
295
|
+
schedule: () => {},
|
|
296
|
+
});
|
|
297
|
+
await handle.refresh();
|
|
298
|
+
const rows = handle.section.lines({});
|
|
299
|
+
assert.equal(rows.length, 8);
|
|
300
|
+
assert.equal(rows[7].label, 'and 13+ more issues',
|
|
301
|
+
'the bound was reached, so the real total is larger than the rows counted here');
|
|
302
|
+
assert.equal(rows[7].tone, 'dim');
|
|
303
|
+
assert.equal(handle.section.meta({}), '20 issues', 'the header reports the count it read');
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// T9 amended (S8): the mark is the pull request's NUMBER, not a glyph, and the
|
|
307
|
+
// bridge paints the right-hand `meta` column in its own `muted` role — that is
|
|
308
|
+
// the gray the user asked for, segment by segment. The row's `tone` stays
|
|
309
|
+
// `text`, so nothing paints the whole row gray to gray one mark.
|
|
310
|
+
test('S8 (T9): an issue whose pull request is #69 carries `#69`, one without a number carries no meta', async () => {
|
|
311
|
+
const handle = createIssuesSection({
|
|
312
|
+
load: async () => ({
|
|
313
|
+
ok: true,
|
|
314
|
+
identity: IDENTITY,
|
|
315
|
+
issues: [
|
|
316
|
+
{ ...issue(4, 'Waits for a merge', '2024-02-01T00:00:00Z'), hasPullRequest: true, pullRequestNumber: 69 },
|
|
317
|
+
{ ...issue(3, 'Nobody opened a PR', '2024-01-01T00:00:00Z'), hasPullRequest: false, pullRequestNumber: null },
|
|
318
|
+
],
|
|
319
|
+
truncated: false,
|
|
320
|
+
}),
|
|
321
|
+
open: () => {},
|
|
322
|
+
openAll: () => {},
|
|
323
|
+
schedule: () => {},
|
|
324
|
+
});
|
|
325
|
+
await handle.refresh();
|
|
326
|
+
|
|
327
|
+
const rows = handle.section.lines({});
|
|
328
|
+
assert.deepEqual(rows.map((row) => row.label), ['#4 Waits for a merge', '#3 Nobody opened a PR']);
|
|
329
|
+
assert.equal(rows[0].meta, '\ue726 #69', 'the row whose issue has a pull request carries its number');
|
|
330
|
+
assert.equal('meta' in rows[1], false, 'the row without one carries no meta at all');
|
|
331
|
+
assert.deepEqual(rows.map((row) => row.tone), ['text', 'text'],
|
|
332
|
+
'the marker never turns the row gray: the bridge paints only the meta column muted');
|
|
333
|
+
assert.deepEqual(Object.keys(rows[0]).sort(), ['label', 'meta', 'onClick', 'tone'],
|
|
334
|
+
'the marker is the row\'s only extra field');
|
|
335
|
+
|
|
336
|
+
const snap = handle.snapshot();
|
|
337
|
+
assert.equal(snap.issues[0].hasPullRequest, true, 'the fact is observable on the snapshot');
|
|
338
|
+
assert.equal(snap.issues[0].pullRequestNumber, 69, 'so is the number the mark is drawn from');
|
|
339
|
+
assert.equal(snap.issues[1].hasPullRequest, false,
|
|
340
|
+
'an issue the decoration did not answer for reports the fact as false, never undefined');
|
|
341
|
+
assert.equal(snap.issues[1].pullRequestNumber, null,
|
|
342
|
+
'and no reference reports null instead of a number nobody opened');
|
|
343
|
+
assert.equal(handle.section.meta({}), '2 issues', 'the marker never changes the count');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test('S8 (T9): only a positive integer number marks a row — anything else marks nothing', async () => {
|
|
347
|
+
const handle = createIssuesSection({
|
|
348
|
+
load: async () => ({
|
|
349
|
+
ok: true,
|
|
350
|
+
identity: IDENTITY,
|
|
351
|
+
issues: [
|
|
352
|
+
{ ...issue(6, 'Unknown', '2024-03-01T00:00:00Z'), hasPullRequest: 'yes', pullRequestNumber: 'yes' },
|
|
353
|
+
{ ...issue(5, 'One PR', '2024-02-01T00:00:00Z'), hasPullRequest: true, pullRequestNumber: 70 },
|
|
354
|
+
{ ...issue(4, 'Zero', '2024-01-01T00:00:00Z'), hasPullRequest: true, pullRequestNumber: 0 },
|
|
355
|
+
],
|
|
356
|
+
truncated: false,
|
|
357
|
+
}),
|
|
358
|
+
open: () => {},
|
|
359
|
+
openAll: () => {},
|
|
360
|
+
schedule: () => {},
|
|
361
|
+
});
|
|
362
|
+
await handle.refresh();
|
|
363
|
+
const rows = handle.section.lines({});
|
|
364
|
+
assert.equal('meta' in rows[0], false, 'anything but a positive integer is no mark');
|
|
365
|
+
assert.equal(rows[1].meta, '\ue726 #70');
|
|
366
|
+
assert.equal('meta' in rows[2], false, 'a zero is not a pull request number');
|
|
367
|
+
assert.equal(handle.snapshot().issues[0].hasPullRequest, false);
|
|
368
|
+
assert.equal(handle.snapshot().issues[0].pullRequestNumber, null);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// S7 (T5, issues-startup-performance): the mark the human asked for is the
|
|
372
|
+
// nerd-font pull-request glyph, ONE space, then `#` and the number —
|
|
373
|
+
// `\ue726 #69`. It still comes from the timeline the ONE combined read already
|
|
374
|
+
// carries (no per-issue call), it still names the LAST associated pull request,
|
|
375
|
+
// and a row whose issue has none still carries no mark at all (S6).
|
|
376
|
+
test('S7 (T5): a marked row reads `\\ue726 #69` — the glyph, one space, `#` and the number', async () => {
|
|
377
|
+
const handle = createIssuesSection({
|
|
378
|
+
load: async () => ({
|
|
379
|
+
ok: true,
|
|
380
|
+
identity: IDENTITY,
|
|
381
|
+
issues: [
|
|
382
|
+
{ ...issue(4, 'Newest pull request', '2024-03-01T00:00:00Z'), hasPullRequest: true, pullRequestNumber: 71 },
|
|
383
|
+
{ ...issue(3, 'One pull request', '2024-02-01T00:00:00Z'), hasPullRequest: true, pullRequestNumber: 69 },
|
|
384
|
+
{ ...issue(2, 'No pull request', '2024-01-01T00:00:00Z'), hasPullRequest: false, pullRequestNumber: null },
|
|
385
|
+
],
|
|
386
|
+
truncated: false,
|
|
387
|
+
}),
|
|
388
|
+
open: () => {},
|
|
389
|
+
openAll: () => {},
|
|
390
|
+
schedule: () => {},
|
|
391
|
+
});
|
|
392
|
+
await handle.refresh();
|
|
393
|
+
|
|
394
|
+
const rows = handle.section.lines({});
|
|
395
|
+
assert.equal(rows[0].meta, '\ue726 #71',
|
|
396
|
+
'the glyph, one space, `#` and the number — the LAST associated pull request');
|
|
397
|
+
assert.equal(rows[1].meta, '\ue726 #69', 'a single pull request wears the same mark');
|
|
398
|
+
assert.equal('meta' in rows[2], false, 'a row whose issue has no pull request keeps no mark');
|
|
399
|
+
assert.equal(rows[0].meta.codePointAt(0), 0xe726,
|
|
400
|
+
'the glyph is U+E726, nf-dev-git_pull_request');
|
|
401
|
+
assert.equal(rows[0].meta.length, '\ue726 #71'.length, 'exactly one glyph, one space and the number');
|
|
402
|
+
assert.equal(rows[0].meta.slice(1), ' #71', 'the glyph is followed by ONE space, a `#` and the number');
|
|
403
|
+
assert.equal(handle.section.meta({}), '3 issues', 'the mark never changes the count');
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// T11 (S12): a checkout that is not a repository is its own state: ONE short
|
|
407
|
+
// line, in the gray tone the rail already has for secondary text, never the
|
|
408
|
+
// error red. The wording belongs to the rail alone; the command notices keep
|
|
409
|
+
// their own sentence.
|
|
410
|
+
test('S12 (T11): a checkout that is not a repository paints one dim line, never an error row', async () => {
|
|
411
|
+
const handle = createIssuesSection({
|
|
412
|
+
load: async () => ({ ok: false, error: 'not a git repository', errorTone: 'dim' }),
|
|
413
|
+
open: () => {},
|
|
414
|
+
openAll: () => {},
|
|
415
|
+
schedule: () => {},
|
|
416
|
+
});
|
|
417
|
+
await handle.refresh();
|
|
418
|
+
assert.deepEqual(handle.section.lines({}), [{ label: 'not a git repository', tone: 'dim' }],
|
|
419
|
+
'one short gray line, with no path and no git advice');
|
|
420
|
+
assert.equal(handle.section.meta({}), undefined, 'and no count to report');
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// S3 (T2): outside a repository there is nothing to check, so the state is not a
|
|
424
|
+
// failure to retry. The line stays until a session boundary supersedes it: a
|
|
425
|
+
// frame, the activity seam and the TTL re-read nothing, so a session that is not
|
|
426
|
+
// in a checkout costs no child process and no timer however long it lives.
|
|
427
|
+
test('S3 (T2): a non-repository line is a state, so no frame and no activity retries it', async () => {
|
|
428
|
+
let reads = 0;
|
|
429
|
+
const sched = manualSchedule();
|
|
430
|
+
const handle = createIssuesSection({
|
|
431
|
+
load: async () => {
|
|
432
|
+
reads += 1;
|
|
433
|
+
return { ok: false, error: 'not a git repository', errorTone: 'dim' };
|
|
434
|
+
},
|
|
435
|
+
open: () => {},
|
|
436
|
+
openAll: () => {},
|
|
437
|
+
schedule: sched.schedule,
|
|
438
|
+
// A clock far past every window: nothing here is excused by being fresh.
|
|
439
|
+
now: () => Date.now() + 3600000,
|
|
440
|
+
});
|
|
441
|
+
handle.section.lines({});
|
|
442
|
+
await sched.flush();
|
|
443
|
+
assert.deepEqual(handle.section.lines({}), [{ label: 'not a git repository', tone: 'dim' }]);
|
|
444
|
+
assert.equal(reads, 1, 'the first read is the one that stated it');
|
|
445
|
+
|
|
446
|
+
assert.equal(handle.refreshIfStale(0), false, 'the activity seam starts nothing');
|
|
447
|
+
handle.section.lines({});
|
|
448
|
+
handle.section.meta({});
|
|
449
|
+
await sched.flush();
|
|
450
|
+
assert.equal(reads, 1, 'no refresh: a non-repository session has nothing to check');
|
|
451
|
+
|
|
452
|
+
// An EXPLICIT refresh is still the caller's own decision, exactly as before.
|
|
453
|
+
await handle.refresh();
|
|
454
|
+
assert.equal(reads, 2);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
// S3/S13 (T2, T11): a `dim` state is a STATE, not a failure to retry — a cwd
|
|
458
|
+
// outside a repository is the one the section draws that way, and a `gh` that
|
|
459
|
+
// vanished after load reaches the same shape — so the floor timer a draw armed is
|
|
460
|
+
// dropped the moment the toned line lands, instead of surviving to its next fire
|
|
461
|
+
// only to find the state already settled. The line stays, and no later frame arms
|
|
462
|
+
// another one.
|
|
463
|
+
test('S3/S13 (T2, T11): a settled (dim) state owns no floor timer', async () => {
|
|
464
|
+
const timers = [];
|
|
465
|
+
let reads = 0;
|
|
466
|
+
const handle = createIssuesSection({
|
|
467
|
+
load: async () => {
|
|
468
|
+
reads += 1;
|
|
469
|
+
return { ok: false, error: 'nothing to read here', errorTone: 'dim' };
|
|
470
|
+
},
|
|
471
|
+
open: () => {},
|
|
472
|
+
openAll: () => {},
|
|
473
|
+
schedule: () => {},
|
|
474
|
+
refreshFloorMs: 20000,
|
|
475
|
+
setTimer: (fn, ms) => {
|
|
476
|
+
const timer = { fn, ms, cleared: false };
|
|
477
|
+
timers.push(timer);
|
|
478
|
+
return timer;
|
|
479
|
+
},
|
|
480
|
+
clearTimer: (timer) => { timer.cleared = true; },
|
|
481
|
+
});
|
|
482
|
+
handle.section.lines({});
|
|
483
|
+
assert.equal(timers.length, 1, 'the draw armed the one floor timer');
|
|
484
|
+
await handle.refresh();
|
|
485
|
+
assert.deepEqual(handle.section.lines({}), [{ label: 'nothing to read here', tone: 'dim' }]);
|
|
486
|
+
assert.equal(reads, 1, 'the read that stated it is the only read');
|
|
487
|
+
assert.equal(timers[0].cleared, true, 'the settled line cleared the timer the draw had armed');
|
|
488
|
+
handle.section.lines({});
|
|
489
|
+
handle.section.meta({});
|
|
490
|
+
assert.equal(timers.length, 1, 'and a settled state arms no second timer');
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
// S7 (T8): the rows are one merged list, but each row remembers the bucket it
|
|
494
|
+
// came from, so its click can ask the panel for that bucket. The module never
|
|
495
|
+
// merges — the extension owns the read — it only carries the tag the read set.
|
|
496
|
+
test('S7 (T8): a row keeps its bucket, and its click hands it to the opener', async () => {
|
|
497
|
+
const opened = [];
|
|
498
|
+
const sched = manualSchedule();
|
|
499
|
+
const handle = createIssuesSection({
|
|
500
|
+
load: async () => ({
|
|
501
|
+
ok: true,
|
|
502
|
+
identity: IDENTITY,
|
|
503
|
+
issues: [
|
|
504
|
+
{ ...issue(11, 'Mine eleven', '2024-02-01T00:00:00Z'), bucket: 'mine' },
|
|
505
|
+
{ ...issue(22, 'Assigned twenty-two', '2024-01-01T00:00:00Z'), bucket: 'assigned' },
|
|
506
|
+
],
|
|
507
|
+
truncated: false,
|
|
508
|
+
}),
|
|
509
|
+
open: (number, identity, bucket) => { opened.push({ number, identity, bucket }); },
|
|
510
|
+
openAll: () => {},
|
|
511
|
+
schedule: sched.schedule,
|
|
512
|
+
});
|
|
513
|
+
await handle.refresh();
|
|
514
|
+
const rows = handle.section.lines({});
|
|
515
|
+
assert.deepEqual(rows.map((row) => row.label), ['#11 Mine eleven', '#22 Assigned twenty-two']);
|
|
516
|
+
assert.deepEqual(handle.snapshot().issues.map((item) => item.bucket), ['mine', 'assigned'],
|
|
517
|
+
'the merged rows keep the bucket each one came from');
|
|
518
|
+
|
|
519
|
+
rows[0].onClick();
|
|
520
|
+
await sched.flush();
|
|
521
|
+
assert.deepEqual(opened, [{ number: 11, identity: IDENTITY, bucket: 'mine' }],
|
|
522
|
+
'the click asks for the bucket the row was read from');
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
// S2 (issues-sidebar-click T1, correction): the caller's read answers with the
|
|
526
|
+
// generation it was taken under, and that opaque token rides the row into the
|
|
527
|
+
// `open` seam. The section never reads it — it is how the opener tells a row read
|
|
528
|
+
// by the session that is still running from one the host retained across a
|
|
529
|
+
// session boundary. A load that carries no generation hands `null`, so nothing
|
|
530
|
+
// depends on the field existing.
|
|
531
|
+
test('S2 (correction): the open seam carries the generation the row was read under', async () => {
|
|
532
|
+
const sched = manualSchedule();
|
|
533
|
+
const opened = [];
|
|
534
|
+
const handle = createIssuesSection({
|
|
535
|
+
load: async () => ({
|
|
536
|
+
ok: true,
|
|
537
|
+
identity: IDENTITY,
|
|
538
|
+
issues: [issue(11, 'Mine eleven', '2024-02-01T00:00:00Z')],
|
|
539
|
+
truncated: false,
|
|
540
|
+
generation: 7,
|
|
541
|
+
}),
|
|
542
|
+
open: (number, identity, bucket, generation) => { opened.push({ number, identity, bucket, generation }); },
|
|
543
|
+
openAll: () => {},
|
|
544
|
+
schedule: sched.schedule,
|
|
545
|
+
});
|
|
546
|
+
await handle.refresh();
|
|
547
|
+
handle.section.lines({})[0].onClick();
|
|
548
|
+
await sched.flush();
|
|
549
|
+
assert.deepEqual(opened, [{ number: 11, identity: IDENTITY, bucket: undefined, generation: 7 }],
|
|
550
|
+
'the click hands the opener the read\'s own generation, unchanged');
|
|
551
|
+
|
|
552
|
+
const bare = [];
|
|
553
|
+
const schedBare = manualSchedule();
|
|
554
|
+
const noGeneration = createIssuesSection({
|
|
555
|
+
load: readyLoad([issue(12, 'Mine twelve', '2024-02-01T00:00:00Z')]),
|
|
556
|
+
// The two seams this case does not speak about are named `_` so a reader sees
|
|
557
|
+
// that the SHAPE is the contract: only a bare opener proves what `generation`
|
|
558
|
+
// is when the read carried none.
|
|
559
|
+
open: (number, _identity, _bucket, generation) => { bare.push({ number, generation }); },
|
|
560
|
+
openAll: () => {},
|
|
561
|
+
schedule: schedBare.schedule,
|
|
562
|
+
});
|
|
563
|
+
await noGeneration.refresh();
|
|
564
|
+
noGeneration.section.lines({})[0].onClick();
|
|
565
|
+
await schedBare.flush();
|
|
566
|
+
assert.deepEqual(bare, [{ number: 12, generation: null }],
|
|
567
|
+
'a read that carries no generation hands `null`, never `undefined` or a clock of its own');
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
test('S3: a frame never waits, two stale frames schedule one refresh, and onRefreshed fires once per landing', async () => {
|
|
571
|
+
// A read that never settles: the frame still answers immediately, twice, and
|
|
572
|
+
// schedules exactly one refresh.
|
|
573
|
+
const neverSched = manualSchedule();
|
|
574
|
+
const never = createIssuesSection({
|
|
575
|
+
load: () => new Promise(() => {}),
|
|
576
|
+
open: () => {},
|
|
577
|
+
openAll: () => {},
|
|
578
|
+
schedule: neverSched.schedule,
|
|
579
|
+
});
|
|
580
|
+
const first = never.section.lines({});
|
|
581
|
+
const second = never.section.meta({});
|
|
582
|
+
assert.deepEqual(first, [{ label: 'loading…', tone: 'dim' }]);
|
|
583
|
+
assert.equal(second, undefined);
|
|
584
|
+
assert.deepEqual(never.section.lines({}), [{ label: 'loading…', tone: 'dim' }]);
|
|
585
|
+
assert.equal(neverSched.pending(), 1, 'two stale frames schedule exactly one refresh');
|
|
586
|
+
|
|
587
|
+
// A ready snapshot goes stale on the TTL and schedules again; each landed
|
|
588
|
+
// refresh calls onRefreshed once.
|
|
589
|
+
let clock = 1000;
|
|
590
|
+
let landed = 0;
|
|
591
|
+
const sched = manualSchedule();
|
|
592
|
+
const handle = createIssuesSection({
|
|
593
|
+
load: readyLoad([]),
|
|
594
|
+
open: () => {},
|
|
595
|
+
openAll: () => {},
|
|
596
|
+
schedule: sched.schedule,
|
|
597
|
+
now: () => clock,
|
|
598
|
+
ttlMs: 100,
|
|
599
|
+
onRefreshed: () => { landed += 1; },
|
|
600
|
+
});
|
|
601
|
+
handle.section.lines({});
|
|
602
|
+
await sched.flush();
|
|
603
|
+
assert.equal(landed, 1);
|
|
604
|
+
assert.deepEqual(handle.section.lines({}), [{ label: 'no open issues', tone: 'dim' }]);
|
|
605
|
+
assert.equal(sched.pending(), 0, 'a fresh snapshot schedules nothing');
|
|
606
|
+
clock += 200;
|
|
607
|
+
handle.section.lines({});
|
|
608
|
+
handle.section.lines({});
|
|
609
|
+
assert.equal(sched.pending(), 1, 'the stale snapshot schedules one refresh');
|
|
610
|
+
await sched.flush();
|
|
611
|
+
assert.equal(landed, 2);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
test('S4: a click defers open, calls it once, and never lets a failure escape', async () => {
|
|
615
|
+
const opened = [];
|
|
616
|
+
const sched = manualSchedule();
|
|
617
|
+
let failure = null;
|
|
618
|
+
const handle = createIssuesSection({
|
|
619
|
+
load: readyLoad([issue(7, 'Click me', '2024-01-01T00:00:00Z')]),
|
|
620
|
+
open: (number) => {
|
|
621
|
+
opened.push(number);
|
|
622
|
+
if (failure) throw failure;
|
|
623
|
+
},
|
|
624
|
+
openAll: () => {},
|
|
625
|
+
schedule: sched.schedule,
|
|
626
|
+
});
|
|
627
|
+
handle.section.lines({});
|
|
628
|
+
await sched.flush();
|
|
629
|
+
|
|
630
|
+
handle.section.lines({})[0].onClick();
|
|
631
|
+
assert.deepEqual(opened, [], 'the opener never runs on the paint path');
|
|
632
|
+
await sched.flush();
|
|
633
|
+
assert.deepEqual(opened, [7], 'one click opens that issue exactly once');
|
|
634
|
+
|
|
635
|
+
failure = new Error('no browser here');
|
|
636
|
+
let escaped = null;
|
|
637
|
+
try {
|
|
638
|
+
handle.section.lines({})[0].onClick();
|
|
639
|
+
await sched.flush();
|
|
640
|
+
} catch (err) {
|
|
641
|
+
escaped = err;
|
|
642
|
+
}
|
|
643
|
+
assert.equal(escaped, null, 'the failure never escapes into the caller');
|
|
644
|
+
assert.deepEqual(opened, [7, 7]);
|
|
645
|
+
assert.equal(handle.snapshot().error, 'no browser here');
|
|
646
|
+
|
|
647
|
+
const asyncSched = manualSchedule();
|
|
648
|
+
const asyncHandle = createIssuesSection({
|
|
649
|
+
load: readyLoad([issue(8, 'Async click', '2024-01-01T00:00:00Z')]),
|
|
650
|
+
open: () => Promise.reject(new Error('async opener failed')),
|
|
651
|
+
openAll: () => {},
|
|
652
|
+
schedule: asyncSched.schedule,
|
|
653
|
+
});
|
|
654
|
+
await asyncHandle.refresh();
|
|
655
|
+
asyncHandle.section.lines({})[0].onClick();
|
|
656
|
+
await asyncSched.flush();
|
|
657
|
+
assert.equal(asyncHandle.snapshot().error, 'async opener failed',
|
|
658
|
+
'an async opener rejection lands in the snapshot, not in the host');
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
test('S4: an opener that RESOLVES { ok: false } records its error and keeps the ready rows', async () => {
|
|
662
|
+
const sched = manualSchedule();
|
|
663
|
+
const handle = createIssuesSection({
|
|
664
|
+
load: readyLoad([issue(9, 'Open fails', '2024-01-01T00:00:00Z')]),
|
|
665
|
+
// The extension's real opener catches and RESOLVES this shape; it never
|
|
666
|
+
// rejects.
|
|
667
|
+
open: () => Promise.resolve({ ok: false, error: 'cannot open the issue in the browser' }),
|
|
668
|
+
openAll: () => {},
|
|
669
|
+
schedule: sched.schedule,
|
|
670
|
+
});
|
|
671
|
+
await handle.refresh();
|
|
672
|
+
const rows = handle.section.lines({});
|
|
673
|
+
assert.deepEqual(rows.map((row) => row.label), ['#9 Open fails']);
|
|
674
|
+
|
|
675
|
+
rows[0].onClick();
|
|
676
|
+
await sched.flush();
|
|
677
|
+
|
|
678
|
+
assert.equal(handle.snapshot().error, 'cannot open the issue in the browser',
|
|
679
|
+
'a resolved { ok: false } failure lands in the snapshot like a throw');
|
|
680
|
+
assert.equal(handle.snapshot().status, 'ready');
|
|
681
|
+
assert.deepEqual(handle.section.lines({}).map((row) => row.label), ['#9 Open fails'],
|
|
682
|
+
'a click failure never turns a ready list into an error row');
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
test('S3: only lines() schedules the TTL refresh, a meta-only frame schedules nothing', async () => {
|
|
686
|
+
let clock = 1000;
|
|
687
|
+
let loads = 0;
|
|
688
|
+
const sched = manualSchedule();
|
|
689
|
+
const handle = createIssuesSection({
|
|
690
|
+
load: async () => {
|
|
691
|
+
loads += 1;
|
|
692
|
+
return { ok: true, identity: IDENTITY, issues: [], truncated: false };
|
|
693
|
+
},
|
|
694
|
+
open: () => {},
|
|
695
|
+
openAll: () => {},
|
|
696
|
+
schedule: sched.schedule,
|
|
697
|
+
now: () => clock,
|
|
698
|
+
ttlMs: 100,
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
// An absent snapshot: the collapsed header draws `meta()` alone.
|
|
702
|
+
assert.equal(handle.section.meta({}), undefined);
|
|
703
|
+
assert.equal(sched.pending(), 0, 'a meta-only frame over an absent snapshot schedules nothing');
|
|
704
|
+
handle.section.lines({});
|
|
705
|
+
assert.equal(sched.pending(), 1, 'the drawn body schedules exactly one refresh');
|
|
706
|
+
await sched.flush();
|
|
707
|
+
assert.equal(loads, 1);
|
|
708
|
+
assert.equal(handle.section.meta({}), '0 issues');
|
|
709
|
+
|
|
710
|
+
// A ready snapshot past its TTL: still only the drawn body schedules.
|
|
711
|
+
clock += 200;
|
|
712
|
+
handle.section.meta({});
|
|
713
|
+
assert.equal(sched.pending(), 0, 'a meta-only frame over a stale snapshot schedules nothing');
|
|
714
|
+
handle.section.lines({});
|
|
715
|
+
assert.equal(sched.pending(), 1, 'the drawn body schedules exactly one refresh');
|
|
716
|
+
await sched.flush();
|
|
717
|
+
assert.equal(loads, 2, 'the stale frame starts exactly one read');
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
test('S1/S6: an explicit refresh never coalesces, and an older answer never overwrites the latest', async () => {
|
|
721
|
+
const deferred = [];
|
|
722
|
+
const handle = createIssuesSection({
|
|
723
|
+
load: () => new Promise((resolve) => { deferred.push(resolve); }),
|
|
724
|
+
open: () => {},
|
|
725
|
+
openAll: () => {},
|
|
726
|
+
schedule: () => {},
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
// Repository A's read is in flight when a checkout switch fires the second
|
|
730
|
+
// explicit refresh for repository B.
|
|
731
|
+
const first = handle.refresh();
|
|
732
|
+
const second = handle.refresh();
|
|
733
|
+
assert.equal(deferred.length, 2, 'an explicit refresh starts its own read instead of joining the in-flight one');
|
|
734
|
+
|
|
735
|
+
deferred[1]({
|
|
736
|
+
ok: true,
|
|
737
|
+
identity: 'github.com/myfork/repo-b',
|
|
738
|
+
issues: [issue(20, 'B issue', '2024-02-01T00:00:00Z')],
|
|
739
|
+
truncated: false,
|
|
740
|
+
});
|
|
741
|
+
await second;
|
|
742
|
+
assert.equal(handle.snapshot().identity, 'github.com/myfork/repo-b');
|
|
743
|
+
assert.deepEqual(handle.section.lines({}).map((row) => row.label), ['#20 B issue']);
|
|
744
|
+
assert.equal(handle.section.meta({}), '1 issues');
|
|
745
|
+
|
|
746
|
+
// A settles later: its rows are dropped, never applied over B's.
|
|
747
|
+
deferred[0]({
|
|
748
|
+
ok: true,
|
|
749
|
+
identity: 'github.com/myfork/repo-a',
|
|
750
|
+
issues: [issue(10, 'A issue', '2024-01-01T00:00:00Z')],
|
|
751
|
+
truncated: false,
|
|
752
|
+
});
|
|
753
|
+
await first;
|
|
754
|
+
assert.equal(handle.snapshot().identity, 'github.com/myfork/repo-b');
|
|
755
|
+
assert.deepEqual(handle.section.lines({}).map((row) => row.label), ['#20 B issue'],
|
|
756
|
+
'the older answer never overwrites the newer one');
|
|
757
|
+
assert.equal(handle.section.meta({}), '1 issues',
|
|
758
|
+
'the metadata is the newer repository\'s too');
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
test('S6: invalidate drops the snapshot and an in-flight answer never lands', async () => {
|
|
762
|
+
// The supersede the session boundary performs: the current snapshot is gone
|
|
763
|
+
// (the rail shows its loading row), the queued TTL refresh no longer counts
|
|
764
|
+
// as scheduled, and nothing is read or repainted by the drop itself.
|
|
765
|
+
let clock = 1000;
|
|
766
|
+
let loads = 0;
|
|
767
|
+
let landed = 0;
|
|
768
|
+
const sched = manualSchedule();
|
|
769
|
+
const handle = createIssuesSection({
|
|
770
|
+
load: async () => {
|
|
771
|
+
loads += 1;
|
|
772
|
+
return {
|
|
773
|
+
ok: true,
|
|
774
|
+
identity: 'github.com/myfork/repo-a',
|
|
775
|
+
issues: [issue(10, 'A issue', '2024-01-01T00:00:00Z')],
|
|
776
|
+
truncated: false,
|
|
777
|
+
};
|
|
778
|
+
},
|
|
779
|
+
open: () => {},
|
|
780
|
+
openAll: () => {},
|
|
781
|
+
schedule: sched.schedule,
|
|
782
|
+
now: () => clock,
|
|
783
|
+
ttlMs: 100,
|
|
784
|
+
onRefreshed: () => { landed += 1; },
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
handle.section.lines({});
|
|
788
|
+
await sched.flush();
|
|
789
|
+
assert.deepEqual(handle.section.lines({}).map((row) => row.label), ['#10 A issue']);
|
|
790
|
+
assert.equal(landed, 1);
|
|
791
|
+
|
|
792
|
+
// A stale frame queues the one TTL refresh it is allowed to queue.
|
|
793
|
+
clock += 200;
|
|
794
|
+
handle.section.lines({});
|
|
795
|
+
assert.equal(sched.pending(), 1, 'a stale frame queues one refresh');
|
|
796
|
+
|
|
797
|
+
handle.invalidate();
|
|
798
|
+
|
|
799
|
+
assert.equal(handle.snapshot(), null, 'invalidate drops the snapshot');
|
|
800
|
+
assert.deepEqual(handle.section.lines({}), [{ label: 'loading…', tone: 'dim' }],
|
|
801
|
+
'the rail falls back to the loading row, never the previous repository\'s rows');
|
|
802
|
+
assert.equal(handle.section.meta({}), undefined, 'the heading counts nothing after a supersede');
|
|
803
|
+
assert.equal(sched.pending(), 2,
|
|
804
|
+
'invalidate clears the scheduled flag, so the next frame queues its own refresh');
|
|
805
|
+
assert.equal(loads, 1, 'invalidate starts no read of its own');
|
|
806
|
+
assert.equal(landed, 1, 'invalidate never repaints');
|
|
807
|
+
|
|
808
|
+
// The read that was in flight when the session switched settles afterwards:
|
|
809
|
+
// its answer is discarded by the bumped token instead of being applied.
|
|
810
|
+
const late = [];
|
|
811
|
+
let lateLoads = 0;
|
|
812
|
+
let lateLanded = 0;
|
|
813
|
+
const inflightHandle = createIssuesSection({
|
|
814
|
+
load: () => {
|
|
815
|
+
lateLoads += 1;
|
|
816
|
+
return new Promise((resolve) => { late.push(resolve); });
|
|
817
|
+
},
|
|
818
|
+
open: () => {},
|
|
819
|
+
openAll: () => {},
|
|
820
|
+
schedule: () => {},
|
|
821
|
+
onRefreshed: () => { lateLanded += 1; },
|
|
822
|
+
});
|
|
823
|
+
const ready = inflightHandle.refresh();
|
|
824
|
+
late[0]({
|
|
825
|
+
ok: true,
|
|
826
|
+
identity: 'github.com/myfork/repo-a',
|
|
827
|
+
issues: [issue(30, 'A thirty', '2024-01-01T00:00:00Z')],
|
|
828
|
+
truncated: false,
|
|
829
|
+
});
|
|
830
|
+
await ready;
|
|
831
|
+
assert.deepEqual(inflightHandle.section.lines({}).map((row) => row.label), ['#30 A thirty']);
|
|
832
|
+
assert.equal(lateLanded, 1);
|
|
833
|
+
|
|
834
|
+
const inFlight = inflightHandle.refresh();
|
|
835
|
+
inflightHandle.invalidate();
|
|
836
|
+
assert.deepEqual(inflightHandle.section.lines({}), [{ label: 'loading…', tone: 'dim' }]);
|
|
837
|
+
|
|
838
|
+
late[1]({
|
|
839
|
+
ok: true,
|
|
840
|
+
identity: 'github.com/myfork/repo-a',
|
|
841
|
+
issues: [issue(31, 'A thirty-one', '2024-01-01T00:00:00Z')],
|
|
842
|
+
truncated: false,
|
|
843
|
+
});
|
|
844
|
+
await inFlight;
|
|
845
|
+
assert.equal(inflightHandle.snapshot(), null, 'the in-flight answer never lands after invalidate');
|
|
846
|
+
assert.deepEqual(inflightHandle.section.lines({}), [{ label: 'loading…', tone: 'dim' }],
|
|
847
|
+
'the previous repository\'s late rows never paint');
|
|
848
|
+
assert.equal(lateLanded, 1, 'a discarded answer never repaints');
|
|
849
|
+
assert.equal(lateLoads, 2, 'invalidate itself read nothing');
|
|
850
|
+
|
|
851
|
+
// After `dispose()` the drop is a no-op: the disposed module keeps answering
|
|
852
|
+
// the snapshot it was left with, and nothing throws.
|
|
853
|
+
const disposedHandle = createIssuesSection({
|
|
854
|
+
load: readyLoad([issue(40, 'Ready', '2024-01-01T00:00:00Z')]),
|
|
855
|
+
open: () => {},
|
|
856
|
+
openAll: () => {},
|
|
857
|
+
schedule: () => {},
|
|
858
|
+
});
|
|
859
|
+
await disposedHandle.refresh();
|
|
860
|
+
disposedHandle.dispose();
|
|
861
|
+
assert.doesNotThrow(() => disposedHandle.invalidate(), 'invalidate never throws');
|
|
862
|
+
assert.deepEqual(disposedHandle.section.lines({}).map((row) => row.label), ['#40 Ready'],
|
|
863
|
+
'invalidate after dispose changes nothing');
|
|
864
|
+
});
|
|
865
|
+
|
|
866
|
+
// T7 (S3 amended): the activity floor. Because a frame only exists when the
|
|
867
|
+
// host has a reason to produce one, the TTL alone never fires on a session that
|
|
868
|
+
// is merely in use. The caller asks for a read on its own events; the module
|
|
869
|
+
// decides whether one is due.
|
|
870
|
+
test('S3: refreshIfStale reads an absent or aged snapshot and nothing else', async () => {
|
|
871
|
+
let clock = 1000;
|
|
872
|
+
let loads = 0;
|
|
873
|
+
const handle = createIssuesSection({
|
|
874
|
+
load: async () => {
|
|
875
|
+
loads += 1;
|
|
876
|
+
return {
|
|
877
|
+
ok: true,
|
|
878
|
+
identity: IDENTITY,
|
|
879
|
+
issues: [issue(5, 'Five', '2024-01-01T00:00:00Z')],
|
|
880
|
+
truncated: false,
|
|
881
|
+
};
|
|
882
|
+
},
|
|
883
|
+
open: () => {},
|
|
884
|
+
openAll: () => {},
|
|
885
|
+
schedule: () => {},
|
|
886
|
+
now: () => clock,
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
// An absent snapshot: the activity trigger starts ONE read.
|
|
890
|
+
assert.equal(handle.refreshIfStale(30000), true, 'an absent snapshot starts a read');
|
|
891
|
+
await waitFor(() => handle.snapshot() !== null, 'the activity read never landed');
|
|
892
|
+
assert.equal(loads, 1);
|
|
893
|
+
assert.deepEqual(handle.section.lines({}).map((row) => row.label), ['#5 Five']);
|
|
894
|
+
|
|
895
|
+
// Fresher than the floor, and just under it: nothing starts.
|
|
896
|
+
assert.equal(handle.refreshIfStale(30000), false, 'a snapshot fresher than the floor starts nothing');
|
|
897
|
+
clock += 29999;
|
|
898
|
+
assert.equal(handle.refreshIfStale(30000), false, 'an age below the floor starts nothing');
|
|
899
|
+
assert.equal(loads, 1);
|
|
900
|
+
|
|
901
|
+
// At the floor exactly: one more read.
|
|
902
|
+
clock += 1;
|
|
903
|
+
assert.equal(handle.refreshIfStale(30000), true, 'an age at the floor starts one read');
|
|
904
|
+
await waitFor(() => loads === 2 && handle.snapshot().at === clock, 'the second activity read never landed');
|
|
905
|
+
assert.equal(handle.refreshIfStale(30000), false, 'the landed snapshot is fresh again');
|
|
906
|
+
|
|
907
|
+
// A read already in flight is never doubled.
|
|
908
|
+
let inFlightLoads = 0;
|
|
909
|
+
const inFlight = createIssuesSection({
|
|
910
|
+
load: () => {
|
|
911
|
+
inFlightLoads += 1;
|
|
912
|
+
return new Promise(() => {});
|
|
913
|
+
},
|
|
914
|
+
open: () => {},
|
|
915
|
+
openAll: () => {},
|
|
916
|
+
schedule: () => {},
|
|
917
|
+
});
|
|
918
|
+
assert.equal(inFlight.refreshIfStale(30000), true, 'the first activity read starts');
|
|
919
|
+
assert.equal(inFlight.refreshIfStale(30000), false, 'a read already in flight is never doubled');
|
|
920
|
+
assert.equal(inFlightLoads, 1);
|
|
921
|
+
|
|
922
|
+
// After dispose() nothing starts, however stale the snapshot would be, and
|
|
923
|
+
// the seam never throws.
|
|
924
|
+
let disposedLoads = 0;
|
|
925
|
+
const disposedHandle = createIssuesSection({
|
|
926
|
+
load: async () => {
|
|
927
|
+
disposedLoads += 1;
|
|
928
|
+
return { ok: true, identity: IDENTITY, issues: [], truncated: false };
|
|
929
|
+
},
|
|
930
|
+
open: () => {},
|
|
931
|
+
openAll: () => {},
|
|
932
|
+
schedule: () => {},
|
|
933
|
+
now: () => clock,
|
|
934
|
+
});
|
|
935
|
+
await disposedHandle.refresh();
|
|
936
|
+
disposedHandle.dispose();
|
|
937
|
+
clock += 600000;
|
|
938
|
+
assert.doesNotThrow(() => disposedHandle.refreshIfStale(30000), 'refreshIfStale never throws');
|
|
939
|
+
assert.equal(disposedHandle.refreshIfStale(30000), false, 'a disposed section starts nothing');
|
|
940
|
+
assert.equal(disposedLoads, 1, 'dispose stops the read, not the staleness');
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
// T10 (S5 amended, L9): a failed refresh over a list that is already on screen
|
|
944
|
+
// is a transient stall (`gh` was killed by its 30 s bound, not an empty
|
|
945
|
+
// repository), so the rows stay exactly as they were and the failure is
|
|
946
|
+
// disclosed instead: `<n> assigned · stale`, `error` recording the reason and
|
|
947
|
+
// `status` a fourth value a caller can tell from `ready`.
|
|
948
|
+
test('S5 (T10): a failed refresh keeps every ready row and reports it stale', async () => {
|
|
949
|
+
let clock = 1000;
|
|
950
|
+
let answer = {
|
|
951
|
+
ok: true,
|
|
952
|
+
identity: IDENTITY,
|
|
953
|
+
issues: [
|
|
954
|
+
{ ...issue(2, 'Has a pull request', '2024-02-01T00:00:00Z'), hasPullRequest: true, pullRequestNumber: 69 },
|
|
955
|
+
issue(1, 'Plain', '2024-01-01T00:00:00Z'),
|
|
956
|
+
],
|
|
957
|
+
truncated: false,
|
|
958
|
+
};
|
|
959
|
+
const sched = manualSchedule();
|
|
960
|
+
const handle = createIssuesSection({
|
|
961
|
+
load: async () => answer,
|
|
962
|
+
open: () => {},
|
|
963
|
+
openAll: () => {},
|
|
964
|
+
schedule: sched.schedule,
|
|
965
|
+
now: () => clock,
|
|
966
|
+
ttlMs: 100,
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
await handle.refresh();
|
|
970
|
+
const ready = handle.section.lines({});
|
|
971
|
+
const successfulAt = handle.snapshot().at;
|
|
972
|
+
assert.equal(handle.section.meta({}), '2 issues');
|
|
973
|
+
assert.equal(ready[0].meta, '\ue726 #69', 'the marker is part of what is on screen');
|
|
974
|
+
|
|
975
|
+
clock += 200;
|
|
976
|
+
answer = { ok: false, error: 'gh timed out after 30000ms' };
|
|
977
|
+
await handle.refresh();
|
|
978
|
+
|
|
979
|
+
const stale = handle.snapshot();
|
|
980
|
+
assert.equal(stale.status, 'stale', 'a fourth status tells the caller it is a stale list');
|
|
981
|
+
assert.equal(stale.error, 'gh timed out after 30000ms', 'the reason is recorded for a caller');
|
|
982
|
+
assert.equal(stale.at, successfulAt,
|
|
983
|
+
'the age stays the last SUCCESSFUL read, which is what keeps the TTL retrying');
|
|
984
|
+
assert.deepEqual(handle.section.lines({}), ready,
|
|
985
|
+
'the rows stay exactly as they were: same rows, same order, same markers');
|
|
986
|
+
assert.equal(handle.section.meta({}), '2 issues · stale', 'the header discloses the stall');
|
|
987
|
+
|
|
988
|
+
// A second failure changes nothing about the rows, and a success replaces the
|
|
989
|
+
// stale list as it always did.
|
|
990
|
+
clock += 200;
|
|
991
|
+
await handle.refresh();
|
|
992
|
+
assert.equal(handle.snapshot().status, 'stale');
|
|
993
|
+
assert.deepEqual(handle.section.lines({}), ready, 'a repeated failure never drops a row');
|
|
994
|
+
|
|
995
|
+
clock += 200;
|
|
996
|
+
answer = {
|
|
997
|
+
ok: true,
|
|
998
|
+
identity: IDENTITY,
|
|
999
|
+
issues: [issue(3, 'Back again', '2024-04-01T00:00:00Z')],
|
|
1000
|
+
truncated: false,
|
|
1001
|
+
};
|
|
1002
|
+
await handle.refresh();
|
|
1003
|
+
assert.equal(handle.snapshot().status, 'ready', 'the next success clears the stale state');
|
|
1004
|
+
assert.equal(handle.snapshot().error, null);
|
|
1005
|
+
assert.equal(handle.snapshot().at, clock, 'a success moves the age again');
|
|
1006
|
+
assert.deepEqual(handle.section.lines({}).map((row) => row.label), ['#3 Back again']);
|
|
1007
|
+
assert.equal(handle.section.meta({}), '1 issues', 'the stale suffix is gone with the stall');
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
// S12 (T10, issues-startup-performance): the rail's heading names the source —
|
|
1011
|
+
// `GITHUB`, not `ISSUES` — and the right-hand count names its unit: `7 issues`,
|
|
1012
|
+
// and `7 issues · stale` while the list is stalled. The number is still the one
|
|
1013
|
+
// the last read produced, and no snapshot still means no count at all.
|
|
1014
|
+
test('S12 (T10): the heading reads GITHUB and the count reads `7 issues`', async () => {
|
|
1015
|
+
let answer = { ok: true, identity: IDENTITY, issues: issueList(7), truncated: false };
|
|
1016
|
+
const handle = createIssuesSection({
|
|
1017
|
+
load: async () => answer,
|
|
1018
|
+
open: () => {},
|
|
1019
|
+
openAll: () => {},
|
|
1020
|
+
schedule: () => {},
|
|
1021
|
+
});
|
|
1022
|
+
|
|
1023
|
+
assert.equal(handle.section.title, 'GITHUB', 'the heading names the source, not the subject');
|
|
1024
|
+
assert.equal(handle.section.meta({}), undefined, 'no snapshot still means no count at all');
|
|
1025
|
+
|
|
1026
|
+
await handle.refresh();
|
|
1027
|
+
assert.equal(handle.section.meta({}), '7 issues', 'the count says what it counts');
|
|
1028
|
+
|
|
1029
|
+
answer = { ok: false, error: 'gh timed out after 30000ms' };
|
|
1030
|
+
await handle.refresh();
|
|
1031
|
+
assert.equal(handle.snapshot().status, 'stale');
|
|
1032
|
+
assert.equal(handle.section.meta({}), '7 issues · stale', 'the stale suffix keeps its own wording');
|
|
1033
|
+
assert.equal(handle.section.lines({}).length, 7, 'and the seven rows stay on screen');
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
test('S5 (T10): a failed first read is still ONE error row, and a success clears a stale list', async () => {
|
|
1037
|
+
let answer = { ok: false, error: 'cannot resolve this checkout\'s own repository' };
|
|
1038
|
+
const handle = createIssuesSection({
|
|
1039
|
+
load: async () => answer,
|
|
1040
|
+
open: () => {},
|
|
1041
|
+
openAll: () => {},
|
|
1042
|
+
schedule: () => {},
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
await handle.refresh();
|
|
1046
|
+
assert.equal(handle.snapshot().status, 'error');
|
|
1047
|
+
assert.deepEqual(handle.section.lines({}), [{
|
|
1048
|
+
label: "cannot resolve this checkout's own repository",
|
|
1049
|
+
tone: 'error',
|
|
1050
|
+
}], 'nothing was ever on screen, so the failure is still the one error row');
|
|
1051
|
+
assert.equal(handle.section.meta({}), undefined, 'an error row has no count and no stale suffix');
|
|
1052
|
+
|
|
1053
|
+
answer = {
|
|
1054
|
+
ok: true,
|
|
1055
|
+
identity: IDENTITY,
|
|
1056
|
+
issues: [issue(8, 'Eight', '2024-05-01T00:00:00Z')],
|
|
1057
|
+
truncated: false,
|
|
1058
|
+
};
|
|
1059
|
+
await handle.refresh();
|
|
1060
|
+
assert.equal(handle.snapshot().status, 'ready');
|
|
1061
|
+
assert.deepEqual(handle.section.lines({}).map((row) => row.label), ['#8 Eight']);
|
|
1062
|
+
|
|
1063
|
+
answer = { ok: false, error: 'gh timed out after 30000ms' };
|
|
1064
|
+
await handle.refresh();
|
|
1065
|
+
assert.equal(handle.snapshot().status, 'stale');
|
|
1066
|
+
assert.deepEqual(handle.section.lines({}).map((row) => row.label), ['#8 Eight'],
|
|
1067
|
+
'the row survives the stall that used to erase it');
|
|
1068
|
+
|
|
1069
|
+
answer = { ok: true, identity: IDENTITY, issues: [], truncated: false };
|
|
1070
|
+
await handle.refresh();
|
|
1071
|
+
assert.equal(handle.snapshot().status, 'ready');
|
|
1072
|
+
assert.deepEqual(handle.section.lines({}), [{ label: 'no open issues', tone: 'dim' }],
|
|
1073
|
+
'a success after the stale list draws the empty state again');
|
|
1074
|
+
assert.equal(handle.section.meta({}), '0 issues');
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
test('S5: loading, empty and error are rows, never a throw', async () => {
|
|
1078
|
+
const loading = createIssuesSection({
|
|
1079
|
+
load: readyLoad([]),
|
|
1080
|
+
open: () => {},
|
|
1081
|
+
openAll: () => {},
|
|
1082
|
+
schedule: () => {},
|
|
1083
|
+
});
|
|
1084
|
+
assert.deepEqual(loading.section.lines({}), [{ label: 'loading…', tone: 'dim' }]);
|
|
1085
|
+
|
|
1086
|
+
const empty = createIssuesSection({
|
|
1087
|
+
load: readyLoad([]),
|
|
1088
|
+
open: () => {},
|
|
1089
|
+
openAll: () => {},
|
|
1090
|
+
schedule: () => {},
|
|
1091
|
+
});
|
|
1092
|
+
await empty.refresh();
|
|
1093
|
+
assert.deepEqual(empty.section.lines({}), [{ label: 'no open issues', tone: 'dim' }]);
|
|
1094
|
+
|
|
1095
|
+
const failed = createIssuesSection({
|
|
1096
|
+
load: async () => ({ ok: false, error: "cannot resolve this checkout's own repository" }),
|
|
1097
|
+
open: () => {},
|
|
1098
|
+
openAll: () => {},
|
|
1099
|
+
schedule: () => {},
|
|
1100
|
+
});
|
|
1101
|
+
await failed.refresh();
|
|
1102
|
+
assert.deepEqual(failed.section.lines({}), [{
|
|
1103
|
+
label: "cannot resolve this checkout's own repository",
|
|
1104
|
+
tone: 'error',
|
|
1105
|
+
}]);
|
|
1106
|
+
assert.equal(failed.section.meta({}), undefined);
|
|
1107
|
+
|
|
1108
|
+
const thrown = createIssuesSection({
|
|
1109
|
+
load: async () => { throw new Error('kaboom'); },
|
|
1110
|
+
open: () => {},
|
|
1111
|
+
openAll: () => {},
|
|
1112
|
+
schedule: () => {},
|
|
1113
|
+
});
|
|
1114
|
+
await thrown.refresh();
|
|
1115
|
+
assert.deepEqual(thrown.section.lines({}), [{ label: 'kaboom', tone: 'error' }],
|
|
1116
|
+
'a throwing read is ONE error row, not a throw');
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
// ---------------------------------------------------------------------------
|
|
1120
|
+
// T2: the bridge wiring in extensions/odd-worktree-tools.ts.
|
|
1121
|
+
// ---------------------------------------------------------------------------
|
|
1122
|
+
|
|
1123
|
+
function installBridge() {
|
|
1124
|
+
const registered = [];
|
|
1125
|
+
const repaints = [];
|
|
1126
|
+
// T18 (S11): every section registration's own disposer is observable, so a
|
|
1127
|
+
// replacement can be asserted to UNREGISTER the binding it replaces before the
|
|
1128
|
+
// new section is registered (the order the tear-down contract names).
|
|
1129
|
+
const released = [];
|
|
1130
|
+
globalThis[BRIDGE_SLOT] = {
|
|
1131
|
+
schema: 'gentle-shell-bridge/api',
|
|
1132
|
+
version: 1,
|
|
1133
|
+
registerRows: () => {},
|
|
1134
|
+
registerSection: (section) => {
|
|
1135
|
+
registered.push(section);
|
|
1136
|
+
return () => { released.push(section); };
|
|
1137
|
+
},
|
|
1138
|
+
createStore: () => ({}),
|
|
1139
|
+
requestRepaint: () => { repaints.push(1); },
|
|
1140
|
+
};
|
|
1141
|
+
return { registered, repaints, released };
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
function git(cwd, args) {
|
|
1145
|
+
return execFileSync('git', args, {
|
|
1146
|
+
cwd,
|
|
1147
|
+
encoding: 'utf8',
|
|
1148
|
+
env: { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_SYSTEM: '/dev/null' },
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// A checkout with the given remotes. The two-remote default is a fork (a
|
|
1153
|
+
// scope identity to pin); ONE remote is the case that has none, so the
|
|
1154
|
+
// identity has to come from gh's own resolution (T4).
|
|
1155
|
+
function makeCheckout(remotes = [
|
|
1156
|
+
['origin', 'git@github.com:myfork/project.git'],
|
|
1157
|
+
['upstream', 'git@github.com:original/project.git'],
|
|
1158
|
+
]) {
|
|
1159
|
+
const dir = track(fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-section-'))));
|
|
1160
|
+
git(dir, ['init']);
|
|
1161
|
+
git(dir, ['config', 'user.email', 'test@example.com']);
|
|
1162
|
+
git(dir, ['config', 'user.name', 'Test']);
|
|
1163
|
+
git(dir, ['commit', '--allow-empty', '-m', 'init']);
|
|
1164
|
+
for (const [name, url] of remotes) git(dir, ['remote', 'add', name, url]);
|
|
1165
|
+
return dir;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
function okJson(stdout) {
|
|
1169
|
+
return { status: 0, stdout, stderr: '', error: null };
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// The one query a `gh api graphql` call sends, without gh's `query=` prefix.
|
|
1173
|
+
function graphqlQueryOf(call) {
|
|
1174
|
+
const at = call.argv.indexOf('-f');
|
|
1175
|
+
if (at < 0 || at + 1 >= call.argv.length) return null;
|
|
1176
|
+
const raw = call.argv[at + 1];
|
|
1177
|
+
return raw.startsWith('query=') ? raw.slice('query='.length) : raw;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// A test row becomes the GraphQL node the combined read returns. A row may
|
|
1181
|
+
// carry the whole node shape already; the row-level fields are the ones these
|
|
1182
|
+
// tests speak in, and `hasPullRequest`/`pullRequestNumber` become the
|
|
1183
|
+
// cross-reference source the marker and its number are derived from.
|
|
1184
|
+
function graphqlNode(item) {
|
|
1185
|
+
const entry = item && typeof item === 'object' ? item : {};
|
|
1186
|
+
const source = (number) => ({ source: { __typename: 'PullRequest', ...(Number.isInteger(number) ? { number } : {}) } });
|
|
1187
|
+
const timeline = entry.timelineItems && Array.isArray(entry.timelineItems.nodes)
|
|
1188
|
+
? entry.timelineItems.nodes
|
|
1189
|
+
: (entry.hasPullRequest === true ? [source(entry.pullRequestNumber)] : []);
|
|
1190
|
+
const labels = entry.labels && typeof entry.labels === 'object' && Array.isArray(entry.labels.nodes)
|
|
1191
|
+
? entry.labels
|
|
1192
|
+
: { nodes: Array.isArray(entry.labels) ? entry.labels : [] };
|
|
1193
|
+
const comments = entry.comments && typeof entry.comments === 'object'
|
|
1194
|
+
? entry.comments
|
|
1195
|
+
: { totalCount: Number.isInteger(entry.commentsCount) ? entry.commentsCount : 0 };
|
|
1196
|
+
return {
|
|
1197
|
+
number: entry.number,
|
|
1198
|
+
title: typeof entry.title === 'string' ? entry.title : '',
|
|
1199
|
+
state: typeof entry.state === 'string' ? entry.state : 'OPEN',
|
|
1200
|
+
stateReason: entry.stateReason === undefined ? '' : entry.stateReason,
|
|
1201
|
+
url: typeof entry.url === 'string' ? entry.url : '',
|
|
1202
|
+
createdAt: typeof entry.createdAt === 'string' ? entry.createdAt : '',
|
|
1203
|
+
updatedAt: typeof entry.updatedAt === 'string' ? entry.updatedAt : '',
|
|
1204
|
+
author: entry.author && typeof entry.author === 'object'
|
|
1205
|
+
? entry.author
|
|
1206
|
+
: { login: typeof entry.author === 'string' ? entry.author : 'me' },
|
|
1207
|
+
labels,
|
|
1208
|
+
comments,
|
|
1209
|
+
reactionGroups: Array.isArray(entry.reactionGroups) ? entry.reactionGroups : [],
|
|
1210
|
+
timelineItems: { nodes: timeline },
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
// The combined read's answer (`listRelatedIssues`): three aliased buckets, each
|
|
1215
|
+
// with its exact issueCount and nodes. `counts` overrides a bucket's count to
|
|
1216
|
+
// model an issue that left the result between two reads.
|
|
1217
|
+
function relatedAnswer({ mine = [], assigned = [], involved = [], counts = {} } = {}) {
|
|
1218
|
+
const bucket = (key, rows) => ({
|
|
1219
|
+
issueCount: Number.isInteger(counts[key]) ? counts[key] : rows.length,
|
|
1220
|
+
nodes: rows.map(graphqlNode),
|
|
1221
|
+
});
|
|
1222
|
+
return {
|
|
1223
|
+
data: {
|
|
1224
|
+
mine: bucket('mine', mine),
|
|
1225
|
+
assigned: bucket('assigned', assigned),
|
|
1226
|
+
involved: bucket('involved', involved),
|
|
1227
|
+
},
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// gh's answers for the section: the identity probes plus the ONE combined
|
|
1232
|
+
// GraphQL read. `repoView` is what gh's OWN resolution answers for the checkout.
|
|
1233
|
+
function sectionGithub({ issues = [], mine = [], involved = [], counts = {}, repoView = 'original/project' } = {}) {
|
|
1234
|
+
const calls = [];
|
|
1235
|
+
const runner = async (bin, argv, runOpts) => {
|
|
1236
|
+
const env = (runOpts && runOpts.env) || {};
|
|
1237
|
+
calls.push({ bin, argv: argv.slice(), env: { ...env }, cwd: runOpts && runOpts.cwd });
|
|
1238
|
+
if (argv[0] === 'api' && argv[1] === 'user') return okJson('{"login":"me"}');
|
|
1239
|
+
if (argv[0] === 'repo' && argv[1] === 'view') return okJson(JSON.stringify({ nameWithOwner: repoView }));
|
|
1240
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
1241
|
+
return okJson(JSON.stringify(relatedAnswer({ mine, assigned: issues, involved, counts })));
|
|
1242
|
+
}
|
|
1243
|
+
return okJson('');
|
|
1244
|
+
};
|
|
1245
|
+
return { runner, calls };
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
function graphqlCalls(calls) {
|
|
1249
|
+
return calls.filter((call) => call.argv[0] === 'api' && call.argv[1] === 'graphql');
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
function sessionStartHandlers(hooks) {
|
|
1253
|
+
return hooks.filter(([event]) => event === 'session_start').map(([, handler]) => handler);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
function hooksFor(hooks, event) {
|
|
1257
|
+
return hooks.filter(([name]) => name === event).map(([, handler]) => handler);
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
// Fire one host event's handlers in registration order, awaiting the async ones.
|
|
1261
|
+
async function fireHook(hooks, event, ctx) {
|
|
1262
|
+
for (const handler of hooksFor(hooks, event)) {
|
|
1263
|
+
const out = handler({ toolResults: [] }, ctx);
|
|
1264
|
+
if (out && typeof out.then === 'function') await out;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
async function fireSessionStart(hooks, ctx) {
|
|
1269
|
+
for (const handler of sessionStartHandlers(hooks)) {
|
|
1270
|
+
const out = handler({}, ctx);
|
|
1271
|
+
if (out && typeof out.then === 'function') await out;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
// Fire one host event with a SPECIFIC payload: `fireHook` sends the
|
|
1276
|
+
// `turn_end`-shaped event, while a `tool_call`/`tool_result` handler must see the
|
|
1277
|
+
// tool it rides on.
|
|
1278
|
+
async function fireEvent(hooks, name, event, ctx) {
|
|
1279
|
+
for (const handler of hooksFor(hooks, name)) {
|
|
1280
|
+
const out = handler(event, ctx);
|
|
1281
|
+
if (out && typeof out.then === 'function') await out;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
async function waitFor(predicate, message) {
|
|
1286
|
+
const deadline = Date.now() + 8000;
|
|
1287
|
+
while (Date.now() < deadline) {
|
|
1288
|
+
if (predicate()) return;
|
|
1289
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1290
|
+
}
|
|
1291
|
+
throw new Error(message);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
// The section's synchronous frame is the only public read; poll it until the
|
|
1295
|
+
// `waitForRows` poll draws the section until its own TTL read has landed
|
|
1296
|
+
// (loading stops); only a drawn section reads, so the draw IS the trigger.
|
|
1297
|
+
async function waitForRows(section, ctx) {
|
|
1298
|
+
const deadline = Date.now() + 8000;
|
|
1299
|
+
while (Date.now() < deadline) {
|
|
1300
|
+
const rows = section.lines(ctx);
|
|
1301
|
+
if (!(rows.length === 1 && rows[0].label === 'loading…')) return rows;
|
|
1302
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1303
|
+
}
|
|
1304
|
+
throw new Error('the section never left loading');
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
// S1/S2 (issues-startup-performance T1): the `gh` gate is DISPATCHED startup work
|
|
1308
|
+
// now, not an awaited step of `session_start`, so it settles a moment after the
|
|
1309
|
+
// host's handlers return. A test that counts `gh` children waits for that work to
|
|
1310
|
+
// go quiet first, instead of racing it. `fireSessionStart` cannot wait for it here
|
|
1311
|
+
// (the extension module the fixture imports is private to the fixture), so the
|
|
1312
|
+
// observable — the injected runner's own call list — is what settles.
|
|
1313
|
+
async function settleStartup(calls) {
|
|
1314
|
+
let seen = -1;
|
|
1315
|
+
for (let attempt = 0; attempt < 100 && seen !== calls.length; attempt += 1) {
|
|
1316
|
+
seen = calls.length;
|
|
1317
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
// S1/S2 (issues-startup-performance T1) / S10 (T8): quiet is NOT a barrier. The
|
|
1322
|
+
// session gate is DISPATCHED startup work, so its two identity probes
|
|
1323
|
+
// (`gh api user`, then `gh repo view`) land whenever the host gets to the probe —
|
|
1324
|
+
// on a loaded CI runner that is long after `session_start` returned, and after any
|
|
1325
|
+
// short quiet window a test uses to guess that startup went quiet. A test that
|
|
1326
|
+
// counts `gh` children therefore counts the gate's probes as the rail's read: it
|
|
1327
|
+
// is the `expected 1, actual 3` PR #89 reported, and the two extra children are
|
|
1328
|
+
// the gate's, in the gate's own order (a destroyed rail read is not involved).
|
|
1329
|
+
//
|
|
1330
|
+
// The barrier is the gate's OWN coalescing seam. `probeIssuesGateStatus` asks the
|
|
1331
|
+
// client one cached question — `cachedGhStatus({ cwd: checkoutRoot, scope: null })`
|
|
1332
|
+
// — and the client holds one promise per repository while that question is in
|
|
1333
|
+
// flight, so asking it here is either the same promise or the same cached answer.
|
|
1334
|
+
// Once it answers, the gate's children have already landed (or never will: the
|
|
1335
|
+
// gate finds the answer cached), and everything the injected runner records
|
|
1336
|
+
// afterwards belongs to the surfaces the test itself drives.
|
|
1337
|
+
async function awaitIssuesGateSettled(cwd) {
|
|
1338
|
+
if (!ghIssues || typeof ghIssues.cachedGhStatus !== 'function') return;
|
|
1339
|
+
try {
|
|
1340
|
+
await ghIssues.cachedGhStatus({ cwd, scope: null });
|
|
1341
|
+
} catch {
|
|
1342
|
+
// A gate that refuses its own probe is still settled: nothing else spawns.
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
test('S2: a published bridge receives exactly one section with the decided identity', async () => {
|
|
1347
|
+
const { registered } = installBridge();
|
|
1348
|
+
const loaded = await loadExtension({});
|
|
1349
|
+
assert.equal(registered.length, 1, 'exactly one section is registered');
|
|
1350
|
+
const section = registered[0];
|
|
1351
|
+
assert.equal(section.id, 'odd-worktree.issues');
|
|
1352
|
+
assert.equal(section.title, 'GITHUB');
|
|
1353
|
+
assert.equal(section.rowLabel, 'issues');
|
|
1354
|
+
assert.equal(section.defaultVisible, true);
|
|
1355
|
+
assert.equal(typeof section.lines, 'function');
|
|
1356
|
+
assert.equal(typeof section.meta, 'function');
|
|
1357
|
+
assert.equal(loaded.commands.has('issues'), true, 'every other surface still registers');
|
|
1358
|
+
});
|
|
1359
|
+
|
|
1360
|
+
// RE-SCOPED (was "with no bridge and no events, nothing registers and nothing
|
|
1361
|
+
// throws", which asserted that `/issues` and both worktree tools still registered
|
|
1362
|
+
// without a bridge — the old policy, where only the bridge surfaces waited).
|
|
1363
|
+
// S18 (T14, the human's "Desactivar todo el plugin"): with no bridge NOTHING of
|
|
1364
|
+
// this package loads, not one command, tool, renderer, card or rail.
|
|
1365
|
+
test('S18 (T14): with no bridge and no events, NOTHING registers and nothing throws', async () => {
|
|
1366
|
+
delete globalThis[BRIDGE_SLOT];
|
|
1367
|
+
const loaded = await loadExtension({}, { bridge: false });
|
|
1368
|
+
assert.deepEqual([...loaded.commands.keys()], [], 'no command at all');
|
|
1369
|
+
assert.deepEqual([...loaded.tools.keys()], [], 'no tool at all');
|
|
1370
|
+
assert.deepEqual([...loaded.messageRenderers.keys()], [], 'no message renderer');
|
|
1371
|
+
assert.deepEqual([...loaded.entryRenderers.keys()], [], 'no entry renderer');
|
|
1372
|
+
assert.deepEqual(loaded.hooks.map(([event]) => event), ['session_start'],
|
|
1373
|
+
'only the observer the missing-plugin notice needs');
|
|
1374
|
+
});
|
|
1375
|
+
|
|
1376
|
+
// RE-SCOPED (was "with no bridge but events, the ready announcement is subscribed
|
|
1377
|
+
// once", which also asserted `/issues` was registered). The subscription is still
|
|
1378
|
+
// exactly one — it now carries the whole gate — and an announcement with no bridge
|
|
1379
|
+
// on the slot still registers nothing.
|
|
1380
|
+
test('S2/S18 (T14): with no bridge but events, the ready announcement is subscribed once and registers nothing yet', async () => {
|
|
1381
|
+
delete globalThis[BRIDGE_SLOT];
|
|
1382
|
+
const subscriptions = [];
|
|
1383
|
+
const loaded = await loadExtension({
|
|
1384
|
+
events: {
|
|
1385
|
+
on: (event, handler) => {
|
|
1386
|
+
subscriptions.push({ event, handler });
|
|
1387
|
+
return () => {};
|
|
1388
|
+
},
|
|
1389
|
+
},
|
|
1390
|
+
}, { bridge: false });
|
|
1391
|
+
assert.equal(subscriptions.length, 1);
|
|
1392
|
+
assert.equal(subscriptions[0].event, 'gentle-shell-bridge:ready');
|
|
1393
|
+
assert.deepEqual([...loaded.commands.keys()], [], 'still nothing registered');
|
|
1394
|
+
subscriptions[0].handler();
|
|
1395
|
+
assert.equal(subscriptions.length, 1, 'a ready announcement is never a second subscription');
|
|
1396
|
+
assert.deepEqual([...loaded.commands.keys()], [], 'an announcement with no published bridge registers nothing');
|
|
1397
|
+
|
|
1398
|
+
// The bridge publishes and the SAME subscription registers the surface, once.
|
|
1399
|
+
installBridge();
|
|
1400
|
+
subscriptions[0].handler();
|
|
1401
|
+
assert.equal(loaded.commands.has('issues'), true, 'the published bridge brings the command');
|
|
1402
|
+
assert.equal(loaded.tools.has('worktree_list'), true, 'and the tools');
|
|
1403
|
+
const counted = loaded.hooks.length;
|
|
1404
|
+
subscriptions[0].handler();
|
|
1405
|
+
assert.equal(loaded.hooks.length, counted, 'a second announcement registers nothing twice');
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
// S7 (T8): ONE combined read, and the rail draws the UNION of the two buckets the
|
|
1409
|
+
// user named — the issues they authored and the ones they are assigned — merged
|
|
1410
|
+
// by number, ordered by `updatedAt` descending, under the bare merged count.
|
|
1411
|
+
test("S6/S7 (T8): session_start reads the checkout's mine AND assigned issues, merged under a bare count", async () => {
|
|
1412
|
+
const checkout = makeCheckout();
|
|
1413
|
+
const { registered } = installBridge();
|
|
1414
|
+
const loaded = await loadExtension({});
|
|
1415
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1416
|
+
const gh = sectionGithub({
|
|
1417
|
+
issues: [
|
|
1418
|
+
{ number: 11, title: 'Assigned older', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' },
|
|
1419
|
+
{ number: 12, title: 'Assigned newer', state: 'OPEN', updatedAt: '2024-06-01T00:00:00Z' },
|
|
1420
|
+
// 13 is BOTH authored and assigned: it is one row, and it is the assigned
|
|
1421
|
+
// one (that is the bucket its click opens). 14 is only authored.
|
|
1422
|
+
{ number: 13, title: 'Both thirteen', state: 'OPEN', updatedAt: '2024-07-01T00:00:00Z' },
|
|
1423
|
+
],
|
|
1424
|
+
mine: [
|
|
1425
|
+
{ number: 13, title: 'Both thirteen', state: 'OPEN', updatedAt: '2024-07-01T00:00:00Z' },
|
|
1426
|
+
{ number: 14, title: 'Only mine fourteen', state: 'OPEN', updatedAt: '2024-04-01T00:00:00Z' },
|
|
1427
|
+
],
|
|
1428
|
+
});
|
|
1429
|
+
ghIssues.setGhRunner(gh.runner);
|
|
1430
|
+
|
|
1431
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
1432
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1433
|
+
assert.equal(registered.length, 1);
|
|
1434
|
+
const section = registered[0];
|
|
1435
|
+
const rows = await waitForRows(section, ctx);
|
|
1436
|
+
|
|
1437
|
+
assert.deepEqual(rows.map((row) => row.label),
|
|
1438
|
+
['#13 Both thirteen', '#12 Assigned newer', '#11 Assigned older', '#14 Only mine fourteen'],
|
|
1439
|
+
'one merged list, deduplicated by number, newest first');
|
|
1440
|
+
assert.equal(section.meta(ctx), '4 issues', 'the header is the merged count alone, never `4 assigned`');
|
|
1441
|
+
assert.ok(rows.every((row) => !('meta' in row)), 'no row reports a relation');
|
|
1442
|
+
const snap = section.lines(ctx);
|
|
1443
|
+
assert.equal(snap.length, 4);
|
|
1444
|
+
|
|
1445
|
+
const reads = graphqlCalls(gh.calls);
|
|
1446
|
+
assert.equal(reads.length, 1, 'exactly one gh call: the combined read, nothing else');
|
|
1447
|
+
assert.equal(reads[0].env.GH_REPO, 'github.com/myfork/project', 'the read carries the pinned identity');
|
|
1448
|
+
const query = graphqlQueryOf(reads[0]);
|
|
1449
|
+
for (const qualifier of ['author:@me', 'assignee:@me', 'involves:@me -author:@me']) {
|
|
1450
|
+
assert.ok(query.includes(`repo:myfork/project is:issue is:open ${qualifier} sort:updated-desc`),
|
|
1451
|
+
`the combined read carries ${qualifier}`);
|
|
1452
|
+
}
|
|
1453
|
+
assert.equal((query.match(/first: 100/g) || []).length, 3, 'the first sync reads 100 per bucket');
|
|
1454
|
+
});
|
|
1455
|
+
|
|
1456
|
+
// S7 (T8): `truncated` is true when EITHER contributing bucket hit the cache cap:
|
|
1457
|
+
// the overflow row's `N+` says the real total is larger than the merged rows.
|
|
1458
|
+
test('S7 (T8): a truncated mine bucket alone still writes the overflow count with a +', async () => {
|
|
1459
|
+
const checkout = makeCheckout();
|
|
1460
|
+
const { registered } = installBridge();
|
|
1461
|
+
const loaded = await loadExtension({});
|
|
1462
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1463
|
+
const gh = sectionGithub({
|
|
1464
|
+
issues: [
|
|
1465
|
+
{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' },
|
|
1466
|
+
],
|
|
1467
|
+
mine: issueList(9).map((item, index) => ({
|
|
1468
|
+
number: 100 + index,
|
|
1469
|
+
title: item.title,
|
|
1470
|
+
state: 'OPEN',
|
|
1471
|
+
updatedAt: item.updatedAt,
|
|
1472
|
+
})),
|
|
1473
|
+
// The mine bucket reported more issues than the cache could hold.
|
|
1474
|
+
counts: { mine: 150 },
|
|
1475
|
+
});
|
|
1476
|
+
ghIssues.setGhRunner(gh.runner);
|
|
1477
|
+
|
|
1478
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
1479
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1480
|
+
const section = registered[0];
|
|
1481
|
+
const rows = await waitForRows(section, ctx);
|
|
1482
|
+
assert.equal(rows.length, 8, 'seven merged rows plus the one overflow row');
|
|
1483
|
+
assert.equal(rows[7].label, 'and 3+ more issues',
|
|
1484
|
+
'either contributing bucket being truncated makes the count inexact');
|
|
1485
|
+
assert.equal(section.meta(ctx), '10 issues', 'the header counts the merged rows it has');
|
|
1486
|
+
});
|
|
1487
|
+
|
|
1488
|
+
test('S4: nine assigned issues paint seven rows plus an overflow row that dispatches /issues once', async () => {
|
|
1489
|
+
const checkout = makeCheckout();
|
|
1490
|
+
const { registered } = installBridge();
|
|
1491
|
+
const sent = [];
|
|
1492
|
+
const loaded = await loadExtension({
|
|
1493
|
+
sendUserMessage: (text, opts) => { sent.push({ text, opts }); },
|
|
1494
|
+
});
|
|
1495
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1496
|
+
const gh = sectionGithub({
|
|
1497
|
+
issues: issueList(9).map((item, index) => ({
|
|
1498
|
+
number: 100 + index,
|
|
1499
|
+
title: item.title,
|
|
1500
|
+
state: 'OPEN',
|
|
1501
|
+
updatedAt: item.updatedAt,
|
|
1502
|
+
})),
|
|
1503
|
+
});
|
|
1504
|
+
ghIssues.setGhRunner(gh.runner);
|
|
1505
|
+
|
|
1506
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
1507
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1508
|
+
assert.equal(registered.length, 1);
|
|
1509
|
+
const section = registered[0];
|
|
1510
|
+
await waitForRows(section, ctx);
|
|
1511
|
+
|
|
1512
|
+
const rows = section.lines(ctx);
|
|
1513
|
+
assert.equal(rows.length, 8, 'seven issue rows plus the one overflow row');
|
|
1514
|
+
assert.equal(rows[7].label, 'and 2 more issues');
|
|
1515
|
+
assert.equal(rows[7].tone, 'dim');
|
|
1516
|
+
assert.equal('meta' in rows[7], false, 'the overflow row carries no meta');
|
|
1517
|
+
assert.equal(section.meta(ctx), '9 issues', 'the header counts every issue read');
|
|
1518
|
+
assert.equal(graphqlCalls(gh.calls).length, 1, 'one read, never one per bucket');
|
|
1519
|
+
|
|
1520
|
+
rows[7].onClick();
|
|
1521
|
+
assert.deepEqual(sent, [], 'the dispatch is deferred off the paint path');
|
|
1522
|
+
await waitFor(() => sent.length > 0, 'the overflow click never dispatched /issues');
|
|
1523
|
+
assert.deepEqual(sent, [{ text: '/issues', opts: { expandPromptTemplates: true } }],
|
|
1524
|
+
'the overflow row dispatches the /issues command exactly once');
|
|
1525
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
1526
|
+
assert.equal(sent.length, 1, 'one click is one dispatch');
|
|
1527
|
+
});
|
|
1528
|
+
|
|
1529
|
+
test("S6: a failed scope resolution is one error row and reads no gh", async () => {
|
|
1530
|
+
const checkout = makeCheckout();
|
|
1531
|
+
const { registered } = installBridge();
|
|
1532
|
+
const loaded = await loadExtension({});
|
|
1533
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1534
|
+
const gh = sectionGithub();
|
|
1535
|
+
ghIssues.setGhRunner(gh.runner);
|
|
1536
|
+
// The checkout's own repository cannot be proven: the client fails closed.
|
|
1537
|
+
ghIssues.setGitRunner((argv) => {
|
|
1538
|
+
if (argv[0] === 'config') {
|
|
1539
|
+
return { status: null, stdout: '', stderr: '', error: 'spawn git ENOENT: git is not available' };
|
|
1540
|
+
}
|
|
1541
|
+
return { status: 0, stdout: '', stderr: '', error: null };
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1544
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
1545
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1546
|
+
assert.equal(registered.length, 1);
|
|
1547
|
+
const section = registered[0];
|
|
1548
|
+
const rows = await waitForRows(section, ctx);
|
|
1549
|
+
|
|
1550
|
+
assert.equal(rows.length, 1, 'one error row');
|
|
1551
|
+
assert.equal(rows[0].tone, 'error');
|
|
1552
|
+
assert.match(rows[0].label, /cannot read this checkout's git configuration/);
|
|
1553
|
+
assert.equal(section.meta(ctx), undefined);
|
|
1554
|
+
// S1/S3 (T1, T2): the session gate asks gh whether gh is USABLE (`gh api user`,
|
|
1555
|
+
// `gh repo view`) and passes `scope: null`, so it never resolves this checkout's
|
|
1556
|
+
// identity through gh — the local checkout check is what decides whether there is
|
|
1557
|
+
// anything to read. What must never happen is a READ without a proven identity.
|
|
1558
|
+
assert.deepEqual(graphqlCalls(gh.calls), [], 'no issue read runs without a proven identity');
|
|
1559
|
+
assert.ok(gh.calls.every((call) => (call.argv[0] === 'api' && call.argv[1] === 'user')
|
|
1560
|
+
|| (call.argv[0] === 'repo' && call.argv[1] === 'view')),
|
|
1561
|
+
`every child is the gate's own health probe (saw ${JSON.stringify(gh.calls.map((call) => call.argv))})`);
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
// S12 (T11): a cwd that is not a repository is not an ERROR — nothing is broken,
|
|
1565
|
+
// there is simply nothing to read. The rail says so with one short line in the
|
|
1566
|
+
// gray tone it already has for secondary text, and names no path: the human
|
|
1567
|
+
// knows where they are. The command notices keep their own, fuller sentence.
|
|
1568
|
+
test('S12 (T11): a session outside a repository paints one short dim line, and the command keeps its wording', async () => {
|
|
1569
|
+
const notGit = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-not-git-')));
|
|
1570
|
+
const { registered } = installBridge();
|
|
1571
|
+
const notices = [];
|
|
1572
|
+
const loaded = await loadExtension({});
|
|
1573
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1574
|
+
const gh = sectionGithub();
|
|
1575
|
+
ghIssues.setGhRunner(gh.runner);
|
|
1576
|
+
|
|
1577
|
+
const ctx = { cwd: notGit, ui: { notify: (text, level) => { notices.push({ text, level }); } } };
|
|
1578
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1579
|
+
assert.equal(registered.length, 1);
|
|
1580
|
+
const section = registered[0];
|
|
1581
|
+
const rows = await waitForRows(section, ctx);
|
|
1582
|
+
|
|
1583
|
+
assert.deepEqual(rows, [{ label: 'not a git repository', tone: 'dim' }],
|
|
1584
|
+
'one short line, no path, no git advice, and never the error tone');
|
|
1585
|
+
assert.equal(section.meta(ctx), undefined, 'and no count');
|
|
1586
|
+
assert.equal(graphqlCalls(gh.calls).length, 0, 'and no issue read runs at all');
|
|
1587
|
+
|
|
1588
|
+
// The command's own notices are untouched by this: `/issues` still says the
|
|
1589
|
+
// full sentence it always did.
|
|
1590
|
+
const notes = [];
|
|
1591
|
+
const commandCtx = { cwd: notGit, ui: { notify: (text, level) => { notes.push([text, level]); } } };
|
|
1592
|
+
await loaded.commands.get('issues').handler('', commandCtx);
|
|
1593
|
+
assert.equal(notes.length, 1);
|
|
1594
|
+
assert.equal(notes[0][0], `not a git repository: ${notGit}; run 'git init' first`,
|
|
1595
|
+
'the command notice keeps its own wording');
|
|
1596
|
+
});
|
|
1597
|
+
|
|
1598
|
+
// S13 (T11, corrected): without the `gh` CLI the rail section is NEVER ADDED —
|
|
1599
|
+
// "/issues nunca se carga ni nunca se agrega a sidebar github sidebar". The decision
|
|
1600
|
+
// is a LOCAL presence answer (a PATH walk; the module answers `ghCliPresent`, no
|
|
1601
|
+
// child), so the host pays no `gh` child, no git child and no read at all, and there
|
|
1602
|
+
// is no line, notice or refusal to draw: nothing appears, because nothing was
|
|
1603
|
+
// registered. Every other surface the package contributes is still there.
|
|
1604
|
+
test('S13 (T11): without the gh CLI the GITHUB section is never added to the rail', async () => {
|
|
1605
|
+
const checkout = makeCheckout();
|
|
1606
|
+
const { registered } = installBridge();
|
|
1607
|
+
// The decision is the real probe over PATH — no seam, because registration reads
|
|
1608
|
+
// it before any module instance a test could patch exists.
|
|
1609
|
+
const loaded = await loadExtension({}, { gh: false });
|
|
1610
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1611
|
+
const gh = sectionGithub();
|
|
1612
|
+
ghIssues.setGhRunner(gh.runner);
|
|
1613
|
+
|
|
1614
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
1615
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1616
|
+
|
|
1617
|
+
assert.deepEqual(registered, [], 'no section is added to the rail: there is nothing to draw');
|
|
1618
|
+
assert.equal(loaded.commands.has('issues'), false, '/issues never loads either');
|
|
1619
|
+
await settleStartup(gh.calls);
|
|
1620
|
+
assert.deepEqual(gh.calls, [], 'and no gh child runs — not even the session gate\'s health probe');
|
|
1621
|
+
// A missing `gh` is not a plugin-wide switch: the rest of the surface is here.
|
|
1622
|
+
assert.ok(loaded.commands.has('warp'), '/warp still registers');
|
|
1623
|
+
assert.ok(loaded.commands.has('odd'), '/odd still registers');
|
|
1624
|
+
});
|
|
1625
|
+
|
|
1626
|
+
// S6: the supersede is synchronous. A session that starts in ANOTHER checkout
|
|
1627
|
+
// drops the previous checkout's snapshot and stops trusting its in-flight read
|
|
1628
|
+
// BEFORE the handler awaits the `gh` gate, so an answer that settles during that
|
|
1629
|
+
// await is discarded instead of painting the previous repository's rows.
|
|
1630
|
+
test("S6: a session starting in another checkout drops the previous checkout's answer", async () => {
|
|
1631
|
+
const checkoutA = makeCheckout([
|
|
1632
|
+
['origin', 'git@github.com:myfork/project-a.git'],
|
|
1633
|
+
['upstream', 'git@github.com:original/project-a.git'],
|
|
1634
|
+
]);
|
|
1635
|
+
const checkoutB = makeCheckout([
|
|
1636
|
+
['origin', 'git@github.com:myfork/project-b.git'],
|
|
1637
|
+
['upstream', 'git@github.com:original/project-b.git'],
|
|
1638
|
+
]);
|
|
1639
|
+
const { registered } = installBridge();
|
|
1640
|
+
const loaded = await loadExtension({});
|
|
1641
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1642
|
+
|
|
1643
|
+
// Every combined read is HELD, so the test decides when each one answers; the
|
|
1644
|
+
// second checkout's gate probe (`gh api user`) is held too.
|
|
1645
|
+
const lists = [];
|
|
1646
|
+
const gates = [];
|
|
1647
|
+
ghIssues.setGhRunner((_bin, argv, runOpts = {}) => {
|
|
1648
|
+
const cwd = runOpts.cwd;
|
|
1649
|
+
const env = runOpts.env || {};
|
|
1650
|
+
if (argv[0] === 'api' && argv[1] === 'user') {
|
|
1651
|
+
if (cwd === checkoutB) return new Promise((resolve) => { gates.push(resolve); });
|
|
1652
|
+
return Promise.resolve(okJson('{"login":"me"}'));
|
|
1653
|
+
}
|
|
1654
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
1655
|
+
return Promise.resolve(okJson(JSON.stringify({ nameWithOwner: 'myfork/ignored' })));
|
|
1656
|
+
}
|
|
1657
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
1658
|
+
const entry = { cwd, repo: env.GH_REPO, query: graphqlQueryOf({ argv }), settle: null };
|
|
1659
|
+
entry.answer = new Promise((resolve) => {
|
|
1660
|
+
entry.settle = (payload) => resolve(okJson(JSON.stringify(payload)));
|
|
1661
|
+
});
|
|
1662
|
+
lists.push(entry);
|
|
1663
|
+
return entry.answer;
|
|
1664
|
+
}
|
|
1665
|
+
return Promise.resolve(okJson(''));
|
|
1666
|
+
});
|
|
1667
|
+
|
|
1668
|
+
const ctxA = { cwd: checkoutA, ui: { notify: () => {} } };
|
|
1669
|
+
const ctxB = { cwd: checkoutB, ui: { notify: () => {} } };
|
|
1670
|
+
await fireSessionStart(loaded.hooks, ctxA);
|
|
1671
|
+
assert.equal(registered.length, 1, 'exactly one section is registered');
|
|
1672
|
+
const section = registered[0];
|
|
1673
|
+
|
|
1674
|
+
// T13 (S3 amended): `session_start` reads nothing — a hidden section costs
|
|
1675
|
+
// nothing — so the checkout's first read starts when the rail DRAWS the
|
|
1676
|
+
// section. This test rewrote its old `waitFor(lists.length === 1)` here for
|
|
1677
|
+
// exactly that reason.
|
|
1678
|
+
section.lines(ctxA);
|
|
1679
|
+
|
|
1680
|
+
// The bridge's repaint is where the rail's next frame is observable, so what
|
|
1681
|
+
// it records is what the rail would have painted.
|
|
1682
|
+
const painted = [];
|
|
1683
|
+
globalThis[BRIDGE_SLOT].requestRepaint = () => {
|
|
1684
|
+
painted.push(section.lines(ctxB).map((row) => row.label));
|
|
1685
|
+
};
|
|
1686
|
+
|
|
1687
|
+
await waitFor(() => lists.length === 1, 'the first checkout never read its issues');
|
|
1688
|
+
assert.deepEqual(lists.map((entry) => entry.repo), ['github.com/myfork/project-a'],
|
|
1689
|
+
'the first session reads its own checkout');
|
|
1690
|
+
assert.ok(lists[0].query.includes('assignee:@me'),
|
|
1691
|
+
'the one read carries the assigned search');
|
|
1692
|
+
|
|
1693
|
+
// The session moves to the second checkout. Its handler is fired without
|
|
1694
|
+
// awaiting: it holds on the `gh` gate, which is the window the defect lived in.
|
|
1695
|
+
const bPending = [];
|
|
1696
|
+
for (const handler of sessionStartHandlers(loaded.hooks)) {
|
|
1697
|
+
try {
|
|
1698
|
+
bPending.push(Promise.resolve(handler({}, ctxB)));
|
|
1699
|
+
} catch (err) {
|
|
1700
|
+
bPending.push(Promise.reject(err));
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
await waitFor(() => gates.length === 1, 'the second session never reached its gh gate');
|
|
1704
|
+
|
|
1705
|
+
// The first checkout's answer settles NOW — before the second session's gate
|
|
1706
|
+
// has answered. It belongs to a superseded session and is dropped.
|
|
1707
|
+
lists[0].settle(relatedAnswer({ assigned: [{ number: 10, title: 'A ten', state: 'OPEN', updatedAt: '2024-01-01T00:00:00Z' }] }));
|
|
1708
|
+
await new Promise((resolve) => setTimeout(resolve, 30));
|
|
1709
|
+
|
|
1710
|
+
assert.equal(gates.length, 1, 'the second session is still waiting on its gh gate');
|
|
1711
|
+
assert.deepEqual(painted, [], 'nothing from the previous checkout ever repaints the rail');
|
|
1712
|
+
const during = section.lines(ctxB).map((row) => row.label);
|
|
1713
|
+
assert.ok(
|
|
1714
|
+
!during.some((label) => label.includes('A ten')),
|
|
1715
|
+
`the previous checkout's rows never paint (saw ${JSON.stringify(during)})`,
|
|
1716
|
+
);
|
|
1717
|
+
|
|
1718
|
+
// Only now does the gate answer, and the second session reads its own issues.
|
|
1719
|
+
gates[0](okJson('{"login":"me"}'));
|
|
1720
|
+
await Promise.all(bPending);
|
|
1721
|
+
const bList = () => lists.find((entry) => entry.cwd === checkoutB);
|
|
1722
|
+
await waitFor(() => bList() !== undefined, "the second checkout's own read never ran");
|
|
1723
|
+
assert.equal(bList().repo, 'github.com/myfork/project-b',
|
|
1724
|
+
"the second session's read carries its own pinned identity");
|
|
1725
|
+
|
|
1726
|
+
bList().settle(relatedAnswer({ assigned: [{ number: 21, title: 'B twenty-one', state: 'OPEN', updatedAt: '2024-03-01T00:00:00Z' }] }));
|
|
1727
|
+
await waitFor(
|
|
1728
|
+
() => section.lines(ctxB).some((row) => row.label === '#21 B twenty-one'),
|
|
1729
|
+
"the second checkout's rows never painted",
|
|
1730
|
+
);
|
|
1731
|
+
assert.ok(painted.some((labels) => labels.includes('#21 B twenty-one')), 'the landed read repaints the rail');
|
|
1732
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
1733
|
+
assert.equal(lists.length, 2, 'no extra read ran');
|
|
1734
|
+
assert.ok(
|
|
1735
|
+
!painted.some((labels) => labels.includes('#10 A ten')),
|
|
1736
|
+
"the previous checkout's rows never painted a frame",
|
|
1737
|
+
);
|
|
1738
|
+
});
|
|
1739
|
+
|
|
1740
|
+
test('S8 (T9): the ONE combined read supplies both the rows and the pull-request number each marker draws', async () => {
|
|
1741
|
+
const checkout = makeCheckout();
|
|
1742
|
+
const { registered } = installBridge();
|
|
1743
|
+
const loaded = await loadExtension({});
|
|
1744
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1745
|
+
const calls = [];
|
|
1746
|
+
ghIssues.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
1747
|
+
const env = runOpts.env || {};
|
|
1748
|
+
calls.push({ argv: argv.slice(), env: { ...env }, cwd: runOpts.cwd });
|
|
1749
|
+
if (argv[0] === 'api' && argv[1] === 'user') return okJson('{"login":"me"}');
|
|
1750
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
1751
|
+
return okJson(JSON.stringify({ nameWithOwner: 'original/project' }));
|
|
1752
|
+
}
|
|
1753
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
1754
|
+
return okJson(JSON.stringify(relatedAnswer({
|
|
1755
|
+
assigned: [
|
|
1756
|
+
{ number: 11, title: 'Has a PR', updatedAt: '2024-05-01T00:00:00Z', hasPullRequest: true, pullRequestNumber: 69 },
|
|
1757
|
+
{ number: 12, title: 'No PR', updatedAt: '2024-06-01T00:00:00Z' },
|
|
1758
|
+
{ number: 13, title: 'Two PRs', updatedAt: '2024-07-01T00:00:00Z', timelineItems: { nodes: [
|
|
1759
|
+
{ source: { __typename: 'Issue', number: 5 } },
|
|
1760
|
+
{ source: { __typename: 'PullRequest', number: 70 } },
|
|
1761
|
+
{ source: { __typename: 'PullRequest', number: 71 } },
|
|
1762
|
+
] } },
|
|
1763
|
+
],
|
|
1764
|
+
})));
|
|
1765
|
+
}
|
|
1766
|
+
return okJson('');
|
|
1767
|
+
});
|
|
1768
|
+
|
|
1769
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
1770
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1771
|
+
assert.equal(registered.length, 1);
|
|
1772
|
+
const section = registered[0];
|
|
1773
|
+
await waitForRows(section, ctx);
|
|
1774
|
+
|
|
1775
|
+
const rows = section.lines(ctx);
|
|
1776
|
+
assert.deepEqual(rows.map((row) => row.label), ['#13 Two PRs', '#12 No PR', '#11 Has a PR']);
|
|
1777
|
+
// S3 (issues-sidebar-click): the mark is the NEWEST pull request's number, so
|
|
1778
|
+
// the fixture's later event (#71) wins over the earlier one (#70).
|
|
1779
|
+
assert.equal(rows[0].meta, '\ue726 #71', 'an issue with several pull requests marks the NEWEST number');
|
|
1780
|
+
assert.equal('meta' in rows[1], false, 'an issue no pull request references carries no marker');
|
|
1781
|
+
assert.equal(rows[2].meta, '\ue726 #69');
|
|
1782
|
+
assert.deepEqual(rows.map((row) => row.tone), ['text', 'text', 'text'],
|
|
1783
|
+
'only the meta column is gray: the row keeps the plain text tone');
|
|
1784
|
+
assert.equal(section.meta(ctx), '3 issues', 'the marker never changes the count');
|
|
1785
|
+
|
|
1786
|
+
// T14: the marker read T9 introduced is gone — the same read that returns the
|
|
1787
|
+
// rows returns their cross-reference facts, so there is no second call.
|
|
1788
|
+
const graphql = graphqlCalls(calls);
|
|
1789
|
+
assert.equal(graphql.length, 1, 'exactly one GraphQL read serves every row and its marker');
|
|
1790
|
+
assert.equal(graphql[0].env.GH_REPO, 'github.com/myfork/project',
|
|
1791
|
+
'the read carries the identity the checkout already proved');
|
|
1792
|
+
assert.equal(calls.some((call) => call.argv[0] === 'issue' && call.argv[1] === 'list'), false,
|
|
1793
|
+
'no separate list read remains');
|
|
1794
|
+
const query = graphqlQueryOf(graphql[0]);
|
|
1795
|
+
assert.ok(query !== null, 'the read sends one query argument');
|
|
1796
|
+
assert.equal((query.match(/first: 100/g) || []).length, 3, 'the first sync reads 100 per bucket');
|
|
1797
|
+
for (const qualifier of ['author:@me', 'assignee:@me', 'involves:@me -author:@me']) {
|
|
1798
|
+
assert.ok(query.includes(`repo:myfork/project is:issue is:open ${qualifier} sort:updated-desc`),
|
|
1799
|
+
`the combined read carries ${qualifier}`);
|
|
1800
|
+
}
|
|
1801
|
+
assert.ok(query.includes('timelineItems(last: 10, itemTypes: [CROSS_REFERENCED_EVENT])'),
|
|
1802
|
+
'the marker selection rides each row and reads the newest events');
|
|
1803
|
+
assert.ok(query.includes('... on PullRequest { number }'),
|
|
1804
|
+
'and the selection asks for the number the mark prints (S8)');
|
|
1805
|
+
});
|
|
1806
|
+
|
|
1807
|
+
// T14 rewrote this test: its old premise — a separate marker read that fails
|
|
1808
|
+
// while the list read succeeds — no longer exists. The decoration is still best
|
|
1809
|
+
// effort in the only way it can be now: a row whose node carries no
|
|
1810
|
+
// cross-referenced pull request simply has no marker, and the section stays
|
|
1811
|
+
// ready. A failed combined read is the section's own read failure (S5/T10).
|
|
1812
|
+
test('S4 (T9): a row without a cross-referenced pull request carries no marker and the section stays ready', async () => {
|
|
1813
|
+
const checkout = makeCheckout();
|
|
1814
|
+
const { registered } = installBridge();
|
|
1815
|
+
const loaded = await loadExtension({});
|
|
1816
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1817
|
+
const gh = sectionGithub({
|
|
1818
|
+
issues: [
|
|
1819
|
+
{ number: 11, title: 'Has a PR', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z', hasPullRequest: true, pullRequestNumber: 69 },
|
|
1820
|
+
{ number: 12, title: 'No PR', state: 'OPEN', updatedAt: '2024-06-01T00:00:00Z' },
|
|
1821
|
+
],
|
|
1822
|
+
});
|
|
1823
|
+
ghIssues.setGhRunner(gh.runner);
|
|
1824
|
+
|
|
1825
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
1826
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1827
|
+
assert.equal(registered.length, 1);
|
|
1828
|
+
const section = registered[0];
|
|
1829
|
+
const rows = await waitForRows(section, ctx);
|
|
1830
|
+
|
|
1831
|
+
assert.deepEqual(rows.map((row) => row.label), ['#12 No PR', '#11 Has a PR'],
|
|
1832
|
+
'the rows are the combined read\'s own');
|
|
1833
|
+
assert.equal('meta' in rows[0], false, 'the decoration is simply absent');
|
|
1834
|
+
assert.equal(rows[1].meta, '\ue726 #69', 'the row with a pull request carries its number');
|
|
1835
|
+
const meta = section.meta(ctx);
|
|
1836
|
+
assert.equal(meta, '2 issues', 'the section stays ready, never stale');
|
|
1837
|
+
assert.ok(!String(meta).includes('stale'), 'a decoration never reports a stall');
|
|
1838
|
+
});
|
|
1839
|
+
|
|
1840
|
+
// ---------------------------------------------------------------------------
|
|
1841
|
+
// T11 (S2 amended, L10): a host without the bridge gets ONE warning per process,
|
|
1842
|
+
// primary sessions only, naming the install command. An empty slot at
|
|
1843
|
+
// `session_start` is "not yet" — the check waits the announcement window — while
|
|
1844
|
+
// a host with no bus can never announce and is warned at once.
|
|
1845
|
+
// ---------------------------------------------------------------------------
|
|
1846
|
+
|
|
1847
|
+
function warningTexts(notices) {
|
|
1848
|
+
return notices.filter((notice) => notice.level === 'warning').map((notice) => notice.text);
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
// The gate and the section's own read still have to answer: a T11 test fires a
|
|
1852
|
+
// real `session_start`, so no child may ever reach the real `gh`.
|
|
1853
|
+
async function bridgeWarnHarness({ events } = {}) {
|
|
1854
|
+
const checkout = makeCheckout();
|
|
1855
|
+
// S18 (T14): the shared fixture publishes a default bridge, and this harness is
|
|
1856
|
+
// about the ABSENT one, so it opts out: the slot is exactly what the test left.
|
|
1857
|
+
const loaded = await loadExtension(events ? { events } : {}, { bridge: false });
|
|
1858
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1859
|
+
const gh = sectionGithub({
|
|
1860
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
1861
|
+
});
|
|
1862
|
+
ghIssues.setGhRunner(gh.runner);
|
|
1863
|
+
const notices = [];
|
|
1864
|
+
const ctx = { cwd: checkout, ui: { notify: (text, level) => { notices.push({ text, level }); } } };
|
|
1865
|
+
return { loaded, checkout, notices, ctx };
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
test('S2 (T11): with no bridge and no bus, ONE warning names the install command', async () => {
|
|
1869
|
+
delete globalThis[BRIDGE_SLOT];
|
|
1870
|
+
const { loaded, notices, ctx } = await bridgeWarnHarness();
|
|
1871
|
+
|
|
1872
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1873
|
+
assert.deepEqual(warningTexts(notices), [
|
|
1874
|
+
'the issues rail needs the gentle-shell-bridge plugin: install it with pi install npm:gentle-shell-bridge',
|
|
1875
|
+
], 'a host that can never announce is told at once, with the command');
|
|
1876
|
+
|
|
1877
|
+
// One warning for the whole process: a second session start says nothing.
|
|
1878
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1879
|
+
assert.equal(warningTexts(notices).length, 1, 'a second session_start never repeats the warning');
|
|
1880
|
+
|
|
1881
|
+
// And neither does a `/reload`, which builds a new instance of the extension:
|
|
1882
|
+
// the human was already told, once, for this process.
|
|
1883
|
+
const reloaded = await bridgeWarnHarness();
|
|
1884
|
+
await fireSessionStart(reloaded.loaded.hooks, reloaded.ctx);
|
|
1885
|
+
assert.deepEqual(warningTexts(reloaded.notices), [], 'a reloaded extension stays silent');
|
|
1886
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1887
|
+
assert.equal(warningTexts(notices).length, 1);
|
|
1888
|
+
});
|
|
1889
|
+
|
|
1890
|
+
test('S2 (T11): with a bus, a silent window warns once, and a late bridge cancels it', async () => {
|
|
1891
|
+
// A host whose bus stays silent: the warning only lands after the window.
|
|
1892
|
+
delete globalThis[BRIDGE_SLOT];
|
|
1893
|
+
const silent = await bridgeWarnHarness({ events: { on: () => () => {} } });
|
|
1894
|
+
const startedAt = Date.now();
|
|
1895
|
+
await fireSessionStart(silent.loaded.hooks, silent.ctx);
|
|
1896
|
+
assert.deepEqual(warningTexts(silent.notices), [],
|
|
1897
|
+
'an empty slot at session_start is "not yet", never "not installed"');
|
|
1898
|
+
await waitFor(
|
|
1899
|
+
() => warningTexts(silent.notices).length === 1,
|
|
1900
|
+
'the deferred check never warned',
|
|
1901
|
+
);
|
|
1902
|
+
assert.ok(Date.now() - startedAt >= 1000, 'the warning waits for the announcement window');
|
|
1903
|
+
assert.match(warningTexts(silent.notices)[0], /pi install npm:gentle-shell-bridge/,
|
|
1904
|
+
'the warning names the install command verbatim');
|
|
1905
|
+
|
|
1906
|
+
// A bridge that announces inside the window cancels the warning entirely.
|
|
1907
|
+
delete globalThis[BRIDGE_SLOT];
|
|
1908
|
+
const subscriptions = [];
|
|
1909
|
+
const latched = await bridgeWarnHarness({
|
|
1910
|
+
events: { on: (event, handler) => { subscriptions.push({ event, handler }); return () => {}; } },
|
|
1911
|
+
});
|
|
1912
|
+
await fireSessionStart(latched.loaded.hooks, latched.ctx);
|
|
1913
|
+
assert.deepEqual(warningTexts(latched.notices), [], 'nothing is said before the window closes');
|
|
1914
|
+
assert.equal(subscriptions.length, 1, 'the section is subscribed to the ready announcement');
|
|
1915
|
+
subscriptions[0].handler();
|
|
1916
|
+
await new Promise((resolve) => setTimeout(resolve, 2300));
|
|
1917
|
+
assert.deepEqual(warningTexts(latched.notices), [],
|
|
1918
|
+
'a late announcement cancels the warning the window would have produced');
|
|
1919
|
+
});
|
|
1920
|
+
|
|
1921
|
+
test('S2 (T11): a published bridge and a child session are never warned about', async () => {
|
|
1922
|
+
// The bridge is installed: nothing is missing, so nothing is said, now or
|
|
1923
|
+
// after the window.
|
|
1924
|
+
const published = installBridge();
|
|
1925
|
+
const withBridge = await bridgeWarnHarness();
|
|
1926
|
+
await fireSessionStart(withBridge.loaded.hooks, withBridge.ctx);
|
|
1927
|
+
assert.equal(published.registered.length, 1, 'the section still registers');
|
|
1928
|
+
assert.deepEqual(warningTexts(withBridge.notices), [], 'an installed bridge is not a missing one');
|
|
1929
|
+
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
1930
|
+
assert.deepEqual(warningTexts(withBridge.notices), []);
|
|
1931
|
+
|
|
1932
|
+
// A child session never speaks for the human: the prompt block's own child
|
|
1933
|
+
// signal is the test, and the warning stays silent.
|
|
1934
|
+
delete globalThis[BRIDGE_SLOT];
|
|
1935
|
+
const child = await bridgeWarnHarness();
|
|
1936
|
+
const saved = process.env.GENTLE_PI_AGENTS_CHILD;
|
|
1937
|
+
process.env.GENTLE_PI_AGENTS_CHILD = '1';
|
|
1938
|
+
try {
|
|
1939
|
+
await fireSessionStart(child.loaded.hooks, child.ctx);
|
|
1940
|
+
} finally {
|
|
1941
|
+
if (saved === undefined) delete process.env.GENTLE_PI_AGENTS_CHILD;
|
|
1942
|
+
else process.env.GENTLE_PI_AGENTS_CHILD = saved;
|
|
1943
|
+
}
|
|
1944
|
+
assert.deepEqual(warningTexts(child.notices), [], 'a subagent never warns about a missing plugin');
|
|
1945
|
+
});
|
|
1946
|
+
|
|
1947
|
+
// ---------------------------------------------------------------------------
|
|
1948
|
+
// T4 (S4 amended): a single-remote checkout has NO scope identity to pin, so
|
|
1949
|
+
// the identity the row opens and the identity the read uses is the one gh
|
|
1950
|
+
// itself resolves, normalized host-qualified exactly as `/issues` does.
|
|
1951
|
+
// ---------------------------------------------------------------------------
|
|
1952
|
+
|
|
1953
|
+
// T12 rewrote this test: its old assertion was the browser argv the row click
|
|
1954
|
+
// used to reach (`issue view 11 --web -R github.com/myfork/project`). A row click
|
|
1955
|
+
// now dispatches `/issues 11` instead — the panel proves its own identity when it
|
|
1956
|
+
// opens — so the browser argv it pinned is impossible to keep. What is still this
|
|
1957
|
+
// test's subject is the READ: a single-remote checkout has no scope identity to
|
|
1958
|
+
// pin, so the read must carry the identity gh itself resolves.
|
|
1959
|
+
test('S4 (T4/T12): a single-remote checkout lists its issues, and a row click opens the panel on that issue', async () => {
|
|
1960
|
+
// ONE remote: `checkoutRepoScope()` answers `identity: null`, so the identity
|
|
1961
|
+
// the read (and, before T12, the opener) uses is the one gh itself resolves.
|
|
1962
|
+
const checkout = makeCheckout([['origin', 'git@github.com:myfork/project.git']]);
|
|
1963
|
+
const { registered } = installBridge();
|
|
1964
|
+
const sent = [];
|
|
1965
|
+
const loaded = await loadExtension({
|
|
1966
|
+
sendUserMessage: (text, opts) => { sent.push({ text, opts }); },
|
|
1967
|
+
});
|
|
1968
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
1969
|
+
const gh = sectionGithub({
|
|
1970
|
+
repoView: 'myfork/project',
|
|
1971
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
1972
|
+
});
|
|
1973
|
+
ghIssues.setGhRunner(gh.runner);
|
|
1974
|
+
const worktreeGit = require(path.join(LIB_DIR, 'worktree-git.js'));
|
|
1975
|
+
const opened = [];
|
|
1976
|
+
const original = worktreeGit.runArgvAsync;
|
|
1977
|
+
worktreeGit.runArgvAsync = async (bin, argv, opts) => {
|
|
1978
|
+
if (argv[0] === 'issue') {
|
|
1979
|
+
opened.push({ bin, argv: argv.slice(), cwd: opts && opts.cwd });
|
|
1980
|
+
return { status: 0, stdout: '', stderr: '', error: null };
|
|
1981
|
+
}
|
|
1982
|
+
return original(bin, argv, opts);
|
|
1983
|
+
};
|
|
1984
|
+
try {
|
|
1985
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
1986
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
1987
|
+
assert.equal(registered.length, 1);
|
|
1988
|
+
const section = registered[0];
|
|
1989
|
+
const rows = await waitForRows(section, ctx);
|
|
1990
|
+
assert.deepEqual(rows.map((row) => row.label), ['#11 Assigned one'],
|
|
1991
|
+
'the single-remote checkout still lists its issues');
|
|
1992
|
+
rows[0].onClick();
|
|
1993
|
+
await waitFor(() => sent.length > 0, 'the click never dispatched /issues');
|
|
1994
|
+
} finally {
|
|
1995
|
+
worktreeGit.runArgvAsync = original;
|
|
1996
|
+
}
|
|
1997
|
+
assert.deepEqual(sent, [{ text: '/issues 11', opts: { expandPromptTemplates: true } }],
|
|
1998
|
+
'the row click dispatches the panel command for that issue, exactly once');
|
|
1999
|
+
assert.deepEqual(opened, [], 'the click no longer opens a browser');
|
|
2000
|
+
const reads = graphqlCalls(gh.calls);
|
|
2001
|
+
assert.equal(reads[0].env.GH_REPO, 'github.com/myfork/project',
|
|
2002
|
+
'the read carries the identity gh resolved for this checkout, host-qualified');
|
|
2003
|
+
});
|
|
2004
|
+
|
|
2005
|
+
// T12: the deferred click contract is unchanged — off the paint path, a recorded
|
|
2006
|
+
// `{ ok, error }`, never a throw. T10 (S9) adds the one thing the old shape
|
|
2007
|
+
// lacked: a host that cannot dispatch is TOLD so visibly, never by a silent
|
|
2008
|
+
// snapshot field alone.
|
|
2009
|
+
test('S9 (T10): a host that cannot dispatch leaves a visible transcript entry, never silence', async () => {
|
|
2010
|
+
const checkout = makeCheckout();
|
|
2011
|
+
const { registered } = installBridge();
|
|
2012
|
+
const loaded = await loadExtension({});
|
|
2013
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2014
|
+
const gh = sectionGithub({
|
|
2015
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
2016
|
+
});
|
|
2017
|
+
ghIssues.setGhRunner(gh.runner);
|
|
2018
|
+
const worktreeGit = require(path.join(LIB_DIR, 'worktree-git.js'));
|
|
2019
|
+
const opened = [];
|
|
2020
|
+
const original = worktreeGit.runArgvAsync;
|
|
2021
|
+
worktreeGit.runArgvAsync = async (bin, argv, opts) => {
|
|
2022
|
+
if (argv[0] === 'issue') {
|
|
2023
|
+
opened.push({ bin, argv: argv.slice(), cwd: opts && opts.cwd });
|
|
2024
|
+
return { status: 0, stdout: '', stderr: '', error: null };
|
|
2025
|
+
}
|
|
2026
|
+
return original(bin, argv, opts);
|
|
2027
|
+
};
|
|
2028
|
+
try {
|
|
2029
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
2030
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
2031
|
+
const section = registered[0];
|
|
2032
|
+
const rows = await waitForRows(section, ctx);
|
|
2033
|
+
assert.equal(rows[0].label, '#11 Assigned one');
|
|
2034
|
+
// The click returns immediately and never throws; the refusal is both
|
|
2035
|
+
// recorded for a caller AND appended as one transcript entry.
|
|
2036
|
+
assert.equal(rows[0].onClick(), undefined, 'the deferred click never throws at the caller');
|
|
2037
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2038
|
+
assert.deepEqual(opened, [], 'no browser open runs when the host cannot dispatch');
|
|
2039
|
+
assert.equal(loaded.entries.length, 1, 'the refusal is one visible transcript entry');
|
|
2040
|
+
assert.match(String(loaded.entries[0].data && loaded.entries[0].data.line),
|
|
2041
|
+
/cannot dispatch the \/issues command/, 'the entry names the refusal');
|
|
2042
|
+
assert.deepEqual(section.lines(ctx).map((row) => row.label), ['#11 Assigned one'],
|
|
2043
|
+
'the recorded refusal never turns the ready list into an error row');
|
|
2044
|
+
assert.equal(section.meta(ctx), '1 issues', 'and the header still counts the list it has');
|
|
2045
|
+
} finally {
|
|
2046
|
+
worktreeGit.runArgvAsync = original;
|
|
2047
|
+
}
|
|
2048
|
+
});
|
|
2049
|
+
|
|
2050
|
+
test('S1/S6: a single-remote checkout reads only the assigned issues with the identity gh resolves', async () => {
|
|
2051
|
+
const checkout = makeCheckout([['origin', 'git@github.com:myfork/project.git']]);
|
|
2052
|
+
const { registered } = installBridge();
|
|
2053
|
+
const loaded = await loadExtension({});
|
|
2054
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2055
|
+
const gh = sectionGithub({
|
|
2056
|
+
repoView: 'myfork/project',
|
|
2057
|
+
issues: [
|
|
2058
|
+
{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' },
|
|
2059
|
+
{ number: 12, title: 'Assigned two', state: 'OPEN', updatedAt: '2024-06-01T00:00:00Z' },
|
|
2060
|
+
],
|
|
2061
|
+
});
|
|
2062
|
+
ghIssues.setGhRunner(gh.runner);
|
|
2063
|
+
|
|
2064
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
2065
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
2066
|
+
assert.equal(registered.length, 1);
|
|
2067
|
+
const section = registered[0];
|
|
2068
|
+
const rows = await waitForRows(section, ctx);
|
|
2069
|
+
assert.deepEqual(rows.map((row) => row.label), ['#12 Assigned two', '#11 Assigned one']);
|
|
2070
|
+
|
|
2071
|
+
const reads = graphqlCalls(gh.calls);
|
|
2072
|
+
assert.equal(reads.length, 1, 'exactly one read');
|
|
2073
|
+
assert.equal(reads[0].env.GH_REPO, 'github.com/myfork/project',
|
|
2074
|
+
'the read carries the identity gh resolved for this checkout, host-qualified, so the list and the click agree');
|
|
2075
|
+
const query = graphqlQueryOf(reads[0]);
|
|
2076
|
+
assert.ok(query.includes('repo:myfork/project is:issue is:open assignee:@me sort:updated-desc'));
|
|
2077
|
+
assert.equal((query.match(/first: 100/g) || []).length, 3, 'the first sync reads 100 per bucket');
|
|
2078
|
+
});
|
|
2079
|
+
|
|
2080
|
+
// ---------------------------------------------------------------------------
|
|
2081
|
+
// T7 (S3 amended): the activity floor in the extension. A frame only exists
|
|
2082
|
+
// when the host has a reason to produce one (the bridge ships no timer), so the
|
|
2083
|
+
// 60 s TTL on a drawn frame never fires in a session that is merely in use: a
|
|
2084
|
+
// live session showed `no open issues` for minutes while three issues existed,
|
|
2085
|
+
// and corrected itself only when the human sent a message. The session's own
|
|
2086
|
+
// events (`before_agent_start`, `turn_end`) ask for a read behind a 30 s floor.
|
|
2087
|
+
// ---------------------------------------------------------------------------
|
|
2088
|
+
|
|
2089
|
+
test("S3: the activity after a reload reads the session's own checkout", async () => {
|
|
2090
|
+
const checkout = makeCheckout();
|
|
2091
|
+
const { registered } = installBridge();
|
|
2092
|
+
const loaded = await loadExtension({});
|
|
2093
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2094
|
+
const gh = sectionGithub({
|
|
2095
|
+
issues: [
|
|
2096
|
+
{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' },
|
|
2097
|
+
{ number: 12, title: 'Assigned two', state: 'OPEN', updatedAt: '2024-06-01T00:00:00Z' },
|
|
2098
|
+
],
|
|
2099
|
+
});
|
|
2100
|
+
ghIssues.setGhRunner(gh.runner);
|
|
2101
|
+
|
|
2102
|
+
assert.equal(registered.length, 1);
|
|
2103
|
+
const section = registered[0];
|
|
2104
|
+
// The state `/reload` leaves: a section registered with no session context
|
|
2105
|
+
// and no snapshot, because a reload fires no `session_start`. `meta()` never
|
|
2106
|
+
// schedules, so asking it first does not create the very read under test.
|
|
2107
|
+
assert.equal(section.meta({}), undefined, 'a reload leaves the section with no snapshot');
|
|
2108
|
+
|
|
2109
|
+
// The next activity carries the session's own context and must adopt it
|
|
2110
|
+
// BEFORE it asks for a read.
|
|
2111
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
2112
|
+
await fireHook(loaded.hooks, 'before_agent_start', ctx);
|
|
2113
|
+
|
|
2114
|
+
const rows = await waitForRows(section, ctx);
|
|
2115
|
+
assert.deepEqual(rows.map((row) => row.label), ['#12 Assigned two', '#11 Assigned one'],
|
|
2116
|
+
'the section shows the reloaded session\'s rows');
|
|
2117
|
+
|
|
2118
|
+
const reads = graphqlCalls(gh.calls);
|
|
2119
|
+
assert.equal(reads.length, 1, 'exactly one read');
|
|
2120
|
+
assert.equal(reads[0].env.GH_REPO, 'github.com/myfork/project',
|
|
2121
|
+
"the read is bound to the session's own checkout, not the host process's cwd");
|
|
2122
|
+
assert.equal(reads[0].cwd, checkout, 'the read runs in the session\'s own checkout');
|
|
2123
|
+
const query = graphqlQueryOf(reads[0]);
|
|
2124
|
+
assert.ok(query.includes('repo:myfork/project is:issue is:open assignee:@me sort:updated-desc'),
|
|
2125
|
+
'the combined read carries the assigned search');
|
|
2126
|
+
assert.equal((query.match(/first: 100/g) || []).length, 3, 'the first sync reads 100 per bucket');
|
|
2127
|
+
});
|
|
2128
|
+
|
|
2129
|
+
test('S3: session_shutdown drops the ended rows and clears the session context', async () => {
|
|
2130
|
+
const checkout = makeCheckout();
|
|
2131
|
+
const { registered } = installBridge();
|
|
2132
|
+
const loaded = await loadExtension({});
|
|
2133
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2134
|
+
// Two different answers, so what a frame paints tells the test WHICH context
|
|
2135
|
+
// its read used: the ended checkout's identity, or the one of whatever cwd
|
|
2136
|
+
// the host process happens to have once the session context is gone.
|
|
2137
|
+
const calls = [];
|
|
2138
|
+
ghIssues.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
2139
|
+
const env = runOpts.env || {};
|
|
2140
|
+
calls.push({ argv: argv.slice(), env: { ...env }, cwd: runOpts.cwd });
|
|
2141
|
+
if (argv[0] === 'api' && argv[1] === 'user') return okJson('{"login":"me"}');
|
|
2142
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
2143
|
+
return okJson(JSON.stringify({ nameWithOwner: 'original/project' }));
|
|
2144
|
+
}
|
|
2145
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
2146
|
+
const assigned = env.GH_REPO === 'github.com/myfork/project'
|
|
2147
|
+
? { number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }
|
|
2148
|
+
: { number: 77, title: 'Host process repo', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' };
|
|
2149
|
+
return okJson(JSON.stringify(relatedAnswer({ assigned: [assigned] })));
|
|
2150
|
+
}
|
|
2151
|
+
return okJson('');
|
|
2152
|
+
});
|
|
2153
|
+
|
|
2154
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
2155
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
2156
|
+
// S10 (T8): this test reads the `gh` children themselves, so the dispatched gate
|
|
2157
|
+
// is settled through its own coalesced question before shutdown — a late probe
|
|
2158
|
+
// must not be mistaken for a read the dead session started.
|
|
2159
|
+
await awaitIssuesGateSettled(checkout);
|
|
2160
|
+
assert.equal(registered.length, 1);
|
|
2161
|
+
const section = registered[0];
|
|
2162
|
+
const rows = await waitForRows(section, ctx);
|
|
2163
|
+
assert.deepEqual(rows.map((row) => row.label), ['#11 Assigned one'], 'the session drew its own rows first');
|
|
2164
|
+
|
|
2165
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
2166
|
+
|
|
2167
|
+
assert.deepEqual(section.lines(ctx), [{ label: 'loading…', tone: 'dim' }],
|
|
2168
|
+
"the ended session's rows are gone, the rail falls back to the loading row");
|
|
2169
|
+
|
|
2170
|
+
// T18 (S11): the session that ended DISPOSED its section, so a frame the host
|
|
2171
|
+
// still paints reads nothing at all — no cwd of the dead session is ever used,
|
|
2172
|
+
// and no floor timer outlives the shutdown.
|
|
2173
|
+
const before = calls.length;
|
|
2174
|
+
assert.deepEqual(section.lines(ctx), [{ label: 'loading…', tone: 'dim' }],
|
|
2175
|
+
'a frame after shutdown still paints the loading row');
|
|
2176
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
2177
|
+
assert.equal(calls.length, before, 'a frame drawn after shutdown reads nothing');
|
|
2178
|
+
assert.deepEqual(section.lines(ctx), [{ label: 'loading…', tone: 'dim' }],
|
|
2179
|
+
"the ended session's rows never paint again");
|
|
2180
|
+
});
|
|
2181
|
+
|
|
2182
|
+
// ---------------------------------------------------------------------------
|
|
2183
|
+
// T7 (S4/S6, verify round 3): the two lifecycle findings. A row the host keeps
|
|
2184
|
+
// on screen outlives the checkout its snapshot belonged to, and a read that was
|
|
2185
|
+
// in flight when the session ended outlives the session.
|
|
2186
|
+
// ---------------------------------------------------------------------------
|
|
2187
|
+
|
|
2188
|
+
test('S4: a row retained across a checkout change opens the identity it was built from', async () => {
|
|
2189
|
+
const opened = [];
|
|
2190
|
+
const deferred = [];
|
|
2191
|
+
const sched = manualSchedule();
|
|
2192
|
+
const handle = createIssuesSection({
|
|
2193
|
+
load: () => new Promise((resolve) => { deferred.push(resolve); }),
|
|
2194
|
+
open: (number, identity) => { opened.push({ number, identity }); },
|
|
2195
|
+
openAll: () => {},
|
|
2196
|
+
schedule: sched.schedule,
|
|
2197
|
+
});
|
|
2198
|
+
|
|
2199
|
+
// Repository A's snapshot, and the row object the rail was handed for it.
|
|
2200
|
+
const aRead = handle.refresh();
|
|
2201
|
+
deferred[0]({
|
|
2202
|
+
ok: true,
|
|
2203
|
+
identity: 'github.com/original/repo-a',
|
|
2204
|
+
issues: [issue(11, 'A eleven', '2024-01-01T00:00:00Z')],
|
|
2205
|
+
truncated: false,
|
|
2206
|
+
});
|
|
2207
|
+
await aRead;
|
|
2208
|
+
const rowA = handle.section.lines({})[0];
|
|
2209
|
+
assert.equal(rowA.label, '#11 A eleven');
|
|
2210
|
+
|
|
2211
|
+
// The session moves: the snapshot is superseded and B's read lands.
|
|
2212
|
+
handle.invalidate();
|
|
2213
|
+
const bRead = handle.refresh();
|
|
2214
|
+
deferred[1]({
|
|
2215
|
+
ok: true,
|
|
2216
|
+
identity: 'github.com/original/repo-b',
|
|
2217
|
+
issues: [issue(11, 'B eleven', '2024-02-01T00:00:00Z')],
|
|
2218
|
+
truncated: false,
|
|
2219
|
+
});
|
|
2220
|
+
await bRead;
|
|
2221
|
+
assert.equal(handle.snapshot().identity, 'github.com/original/repo-b');
|
|
2222
|
+
assert.deepEqual(handle.section.lines({}).map((row) => row.label), ['#11 B eleven']);
|
|
2223
|
+
|
|
2224
|
+
// A retained frame is clicked AFTER B's rows replaced it on the rail.
|
|
2225
|
+
rowA.onClick();
|
|
2226
|
+
await sched.flush();
|
|
2227
|
+
assert.deepEqual(
|
|
2228
|
+
opened,
|
|
2229
|
+
[{ number: 11, identity: 'github.com/original/repo-a' }],
|
|
2230
|
+
"the retained row opens the repository it was read from, never the current snapshot's",
|
|
2231
|
+
);
|
|
2232
|
+
|
|
2233
|
+
// An absent identity is passed through as it is: the opener, not the module,
|
|
2234
|
+
// decides that nothing opens instead of guessing a repository.
|
|
2235
|
+
const noIdentity = createIssuesSection({
|
|
2236
|
+
load: async () => ({ ok: true, issues: [issue(12, 'No identity', '2024-01-01T00:00:00Z')], truncated: false }),
|
|
2237
|
+
open: (number, identity) => { opened.push({ number, identity }); },
|
|
2238
|
+
openAll: () => {},
|
|
2239
|
+
schedule: sched.schedule,
|
|
2240
|
+
});
|
|
2241
|
+
await noIdentity.refresh();
|
|
2242
|
+
noIdentity.section.lines({})[0].onClick();
|
|
2243
|
+
await sched.flush();
|
|
2244
|
+
assert.deepEqual(opened[opened.length - 1], { number: 12, identity: null },
|
|
2245
|
+
'an absent identity reaches the opener unchanged');
|
|
2246
|
+
});
|
|
2247
|
+
|
|
2248
|
+
// T12 wrote this test to assert that a row retained across a checkout change
|
|
2249
|
+
// dispatched `/issues 11` — the number alone, so the panel proved its own
|
|
2250
|
+
// repository. T17 (E17a) then compared the row's identity with this checkout's
|
|
2251
|
+
// before dispatching, and T10 (S9) removes that second proof again: the panel
|
|
2252
|
+
// pins and proves the identity itself when it opens (invariant 6), and the
|
|
2253
|
+
// pre-dispatch proof was exactly what left a click dead with no visible effect.
|
|
2254
|
+
// What is left — and what this test states — is the dispatch itself: the number
|
|
2255
|
+
// alone travels, and whatever repository the click came from, the panel decides.
|
|
2256
|
+
test('S9 (T10): a retained row dispatches its number, and the panel proves its own identity', async () => {
|
|
2257
|
+
const checkoutA = makeCheckout([
|
|
2258
|
+
['origin', 'git@github.com:myfork/project-a.git'],
|
|
2259
|
+
['upstream', 'git@github.com:original/project-a.git'],
|
|
2260
|
+
]);
|
|
2261
|
+
const checkoutB = makeCheckout([
|
|
2262
|
+
['origin', 'git@github.com:myfork/project-b.git'],
|
|
2263
|
+
['upstream', 'git@github.com:original/project-b.git'],
|
|
2264
|
+
]);
|
|
2265
|
+
const { registered } = installBridge();
|
|
2266
|
+
const sent = [];
|
|
2267
|
+
const loaded = await loadExtension({
|
|
2268
|
+
sendUserMessage: (text, opts) => { sent.push({ text, opts }); },
|
|
2269
|
+
});
|
|
2270
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2271
|
+
ghIssues.setGhRunner((_bin, argv, runOpts = {}) => {
|
|
2272
|
+
const env = runOpts.env || {};
|
|
2273
|
+
if (argv[0] === 'api' && argv[1] === 'user') return Promise.resolve(okJson('{"login":"me"}'));
|
|
2274
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
2275
|
+
return Promise.resolve(okJson(JSON.stringify({ nameWithOwner: 'myfork/project-a' })));
|
|
2276
|
+
}
|
|
2277
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
2278
|
+
const assigned = [{
|
|
2279
|
+
number: 11,
|
|
2280
|
+
title: env.GH_REPO === 'github.com/myfork/project-a' ? 'A eleven' : 'B eleven',
|
|
2281
|
+
state: 'OPEN',
|
|
2282
|
+
updatedAt: '2024-01-01T00:00:00Z',
|
|
2283
|
+
}];
|
|
2284
|
+
return Promise.resolve(okJson(JSON.stringify(relatedAnswer({ assigned }))));
|
|
2285
|
+
}
|
|
2286
|
+
return Promise.resolve(okJson(''));
|
|
2287
|
+
});
|
|
2288
|
+
|
|
2289
|
+
const worktreeGit = require(path.join(LIB_DIR, 'worktree-git.js'));
|
|
2290
|
+
const opened = [];
|
|
2291
|
+
const original = worktreeGit.runArgvAsync;
|
|
2292
|
+
worktreeGit.runArgvAsync = async (bin, argv, opts) => {
|
|
2293
|
+
if (argv[0] === 'issue') {
|
|
2294
|
+
opened.push({ bin, argv: argv.slice(), cwd: opts && opts.cwd });
|
|
2295
|
+
return { status: 0, stdout: '', stderr: '', error: null };
|
|
2296
|
+
}
|
|
2297
|
+
return original(bin, argv, opts);
|
|
2298
|
+
};
|
|
2299
|
+
|
|
2300
|
+
try {
|
|
2301
|
+
const ctxA = { cwd: checkoutA, ui: { notify: () => {} } };
|
|
2302
|
+
const ctxB = { cwd: checkoutB, ui: { notify: () => {} } };
|
|
2303
|
+
await fireSessionStart(loaded.hooks, ctxA);
|
|
2304
|
+
assert.equal(registered.length, 1);
|
|
2305
|
+
const section = registered[0];
|
|
2306
|
+
await waitForRows(section, ctxA);
|
|
2307
|
+
const rowA = section.lines(ctxA)[0];
|
|
2308
|
+
assert.equal(rowA.label, '#11 A eleven');
|
|
2309
|
+
|
|
2310
|
+
// The session moves to the second checkout, whose read lands after it.
|
|
2311
|
+
await fireSessionStart(loaded.hooks, ctxB);
|
|
2312
|
+
await waitFor(
|
|
2313
|
+
() => section.lines(ctxB).some((row) => row.label === '#11 B eleven'),
|
|
2314
|
+
"the second checkout's rows never painted",
|
|
2315
|
+
);
|
|
2316
|
+
|
|
2317
|
+
// The host still holds A's frame, so this click happens after B's snapshot
|
|
2318
|
+
// landed. The click dispatches the NUMBER alone — the panel is what proves
|
|
2319
|
+
// the repository it opens, exactly like a plain `/issues 11` typed by hand.
|
|
2320
|
+
rowA.onClick();
|
|
2321
|
+
await waitFor(() => sent.length > 0, 'the retained row never dispatched /issues');
|
|
2322
|
+
|
|
2323
|
+
assert.deepEqual(sent, [{ text: '/issues 11', opts: { expandPromptTemplates: true } }],
|
|
2324
|
+
'the click dispatches the number alone, with no repository on the command line');
|
|
2325
|
+
assert.deepEqual(opened, [], 'and opens no browser');
|
|
2326
|
+
assert.ok(section.lines(ctxB).some((row) => row.label === '#11 B eleven'),
|
|
2327
|
+
'the ready list is never disturbed by the click');
|
|
2328
|
+
assert.equal(section.meta(ctxB), '1 issues', 'and the header still counts it');
|
|
2329
|
+
} finally {
|
|
2330
|
+
worktreeGit.runArgvAsync = original;
|
|
2331
|
+
}
|
|
2332
|
+
});
|
|
2333
|
+
|
|
2334
|
+
// T10 (S9): the seam's answer. The seam is exported for exactly this contract
|
|
2335
|
+
// (like the other test seams in the extension): it is the function the row click
|
|
2336
|
+
// defers, and it is where the click's whole behaviour is observable without a
|
|
2337
|
+
// host. It loads the extension the way the host does, with a stub `pi`.
|
|
2338
|
+
async function loadSeam(pi = {}) {
|
|
2339
|
+
// S18 (T14): this file's own loader needs the bridge its host would have, or the
|
|
2340
|
+
// extension registers nothing and there is no session at all to reach a notice.
|
|
2341
|
+
installDefaultBridge();
|
|
2342
|
+
process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
|
|
2343
|
+
const dir = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-seam-')));
|
|
2344
|
+
const copy = path.join(dir, 'odd-worktree-tools.mjs');
|
|
2345
|
+
fs.writeFileSync(copy, stubbedSource());
|
|
2346
|
+
const hooks = [];
|
|
2347
|
+
const host = {
|
|
2348
|
+
registerCommand: () => {},
|
|
2349
|
+
registerTool: () => {},
|
|
2350
|
+
registerMessageRenderer: () => {},
|
|
2351
|
+
on: (event, handler) => { hooks.push([event, handler]); return () => {}; },
|
|
2352
|
+
...pi,
|
|
2353
|
+
};
|
|
2354
|
+
const mod = await import(pathToFileURL(copy).href);
|
|
2355
|
+
mod.default(host);
|
|
2356
|
+
return { mod, hooks };
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
// T10 (S9) part 1: the pre-dispatch proof is gone. A row click dispatches
|
|
2360
|
+
// `/issues <n>` synchronously — no awaited checkout probe, no generation check —
|
|
2361
|
+
// because the panel pins and proves the identity itself when it opens. The proof
|
|
2362
|
+
// was the thing that left a click dead with no visible effect: it awaited git
|
|
2363
|
+
// (and, on a single-remote checkout, `gh`) and its failures only reached a field
|
|
2364
|
+
// nothing draws.
|
|
2365
|
+
test('S9 (T10): a click dispatches `/issues <n>` synchronously, with no awaited identity read', async () => {
|
|
2366
|
+
const checkout = makeCheckout();
|
|
2367
|
+
const sent = [];
|
|
2368
|
+
const dispatch = { sendUserMessage: (text, opts) => { sent.push({ text, opts }); } };
|
|
2369
|
+
const { mod, hooks } = await loadSeam(dispatch);
|
|
2370
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2371
|
+
ghIssues.setGhRunner(sectionGithub({}).runner);
|
|
2372
|
+
const worktreeGit = require(path.join(LIB_DIR, 'worktree-git.js'));
|
|
2373
|
+
const reads = [];
|
|
2374
|
+
const original = worktreeGit.runArgvAsync;
|
|
2375
|
+
worktreeGit.runArgvAsync = async (bin, argv, opts) => {
|
|
2376
|
+
reads.push({ bin, argv: argv.slice() });
|
|
2377
|
+
return original(bin, argv, opts);
|
|
2378
|
+
};
|
|
2379
|
+
try {
|
|
2380
|
+
await fireSessionStart(hooks, { cwd: checkout, ui: { notify: () => {} } });
|
|
2381
|
+
const before = reads.length;
|
|
2382
|
+
// A row names a repository, and this one names another checkout: neither
|
|
2383
|
+
// fact is read on this path any more, and the dispatch happens before the
|
|
2384
|
+
// call returns — it is not a promise to await.
|
|
2385
|
+
const outcome = mod.dispatchIssuesPanel(dispatch, 11, 'github.com/other/project', 'mine');
|
|
2386
|
+
assert.deepEqual(outcome, { ok: true }, 'the click answers at once');
|
|
2387
|
+
assert.deepEqual(sent, [{ text: '/issues 11', opts: { expandPromptTemplates: true } }],
|
|
2388
|
+
'the number alone reaches the panel');
|
|
2389
|
+
assert.equal(reads.length, before, 'no checkout identity is read on the click path');
|
|
2390
|
+
} finally {
|
|
2391
|
+
worktreeGit.runArgvAsync = original;
|
|
2392
|
+
}
|
|
2393
|
+
});
|
|
2394
|
+
|
|
2395
|
+
// T10 (S9) part 1, second half: a host that truly cannot dispatch is told so,
|
|
2396
|
+
// visibly. The first surface is the host's own transcript entry seam; a host
|
|
2397
|
+
// without it gets the notice seam instead. The snapshot field keeps recording
|
|
2398
|
+
// the outcome, but it is never the only place the refusal lands.
|
|
2399
|
+
test('S9 (T10): a host with no sendUserMessage appends the refusal as a transcript entry', async () => {
|
|
2400
|
+
const entries = [];
|
|
2401
|
+
const host = { appendEntry: (customType, data) => { entries.push({ customType, data }); } };
|
|
2402
|
+
const { mod } = await loadSeam(host);
|
|
2403
|
+
const outcome = mod.dispatchIssuesPanel(host, 11);
|
|
2404
|
+
assert.equal(outcome.ok, false, 'the refusal is still reported to the caller');
|
|
2405
|
+
assert.match(outcome.error, /cannot dispatch the \/issues command/);
|
|
2406
|
+
assert.equal(entries.length, 1, 'exactly one visible entry, never silence');
|
|
2407
|
+
assert.match(String(entries[0].data && entries[0].data.line), /cannot dispatch the \/issues command/,
|
|
2408
|
+
'the entry carries the refusal the caller got');
|
|
2409
|
+
});
|
|
2410
|
+
|
|
2411
|
+
test('S9 (T10): with no entry seam, the refusal reaches the host notice seam', async () => {
|
|
2412
|
+
const notices = [];
|
|
2413
|
+
const host = { appendEntry: undefined };
|
|
2414
|
+
const { mod, hooks } = await loadSeam(host);
|
|
2415
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2416
|
+
ghIssues.setGhRunner(sectionGithub({}).runner);
|
|
2417
|
+
const checkout = makeCheckout();
|
|
2418
|
+
await fireSessionStart(hooks, {
|
|
2419
|
+
cwd: checkout,
|
|
2420
|
+
ui: { notify: (text, level) => { notices.push({ text, level }); } },
|
|
2421
|
+
});
|
|
2422
|
+
const outcome = mod.dispatchIssuesPanel(host, 11);
|
|
2423
|
+
assert.equal(outcome.ok, false);
|
|
2424
|
+
assert.ok(notices.some((notice) => /cannot dispatch the \/issues command/.test(notice.text)),
|
|
2425
|
+
'a host with only a notice seam is told there too');
|
|
2426
|
+
});
|
|
2427
|
+
|
|
2428
|
+
test('S6: a read in flight at session_shutdown never repaints the rail', async () => {
|
|
2429
|
+
const checkout = makeCheckout();
|
|
2430
|
+
const { registered, repaints } = installBridge();
|
|
2431
|
+
const loaded = await loadExtension({});
|
|
2432
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2433
|
+
|
|
2434
|
+
// The combined read is HELD, so the test decides when it settles.
|
|
2435
|
+
const lists = [];
|
|
2436
|
+
ghIssues.setGhRunner((_bin, argv) => {
|
|
2437
|
+
if (argv[0] === 'api' && argv[1] === 'user') return Promise.resolve(okJson('{"login":"me"}'));
|
|
2438
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
2439
|
+
return Promise.resolve(okJson(JSON.stringify({ nameWithOwner: 'myfork/project' })));
|
|
2440
|
+
}
|
|
2441
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
2442
|
+
const entry = { settle: null };
|
|
2443
|
+
entry.answer = new Promise((resolve) => {
|
|
2444
|
+
entry.settle = (payload) => resolve(okJson(JSON.stringify(payload)));
|
|
2445
|
+
});
|
|
2446
|
+
lists.push(entry);
|
|
2447
|
+
return entry.answer;
|
|
2448
|
+
}
|
|
2449
|
+
return Promise.resolve(okJson(''));
|
|
2450
|
+
});
|
|
2451
|
+
|
|
2452
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
2453
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
2454
|
+
assert.equal(registered.length, 1);
|
|
2455
|
+
const section = registered[0];
|
|
2456
|
+
// T13 (S3 amended): no read happens before a frame, so the section is DRAWN
|
|
2457
|
+
// here and its own TTL path is what reaches gh. This test rewrote its old
|
|
2458
|
+
// "the read never reached gh" wait, which assumed the removed eager read.
|
|
2459
|
+
section.lines(ctx);
|
|
2460
|
+
await waitFor(() => lists.length === 1, 'the drawn section never reached gh');
|
|
2461
|
+
|
|
2462
|
+
// The session ends while its read is still waiting on gh.
|
|
2463
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
2464
|
+
assert.deepEqual(section.lines(ctx), [{ label: 'loading…', tone: 'dim' }],
|
|
2465
|
+
'shutdown drops the rows the ended session had');
|
|
2466
|
+
|
|
2467
|
+
// The read that was in flight when the session ended settles now.
|
|
2468
|
+
for (const entry of lists) entry.settle(relatedAnswer({ assigned: [] }));
|
|
2469
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
2470
|
+
assert.deepEqual(repaints, [], 'a read that outlived the session never repaints the rail');
|
|
2471
|
+
assert.deepEqual(section.lines(ctx), [{ label: 'loading…', tone: 'dim' }],
|
|
2472
|
+
'its answer lands nowhere: the section holds no rows');
|
|
2473
|
+
});
|
|
2474
|
+
|
|
2475
|
+
// ---------------------------------------------------------------------------
|
|
2476
|
+
// T8 (S10, S11, L9): the rail re-reads on TIME, not on activity. While the
|
|
2477
|
+
// section is DRAWN it keeps ONE self-scheduled, unref'd timer at the floor L9
|
|
2478
|
+
// names (20 s): one read per floor, never a burst, never two reads in flight.
|
|
2479
|
+
// The timer keeps no clock of its own — it fires through the same injected
|
|
2480
|
+
// `setTimer`/`clearTimer` seams as everything else here — and it stops by itself
|
|
2481
|
+
// the moment the section is no longer drawn (the `drawnWithin` window), and it
|
|
2482
|
+
// is cleared by `invalidate()` and `dispose()`.
|
|
2483
|
+
// ---------------------------------------------------------------------------
|
|
2484
|
+
|
|
2485
|
+
// The injected clock plus one list of pending timers: a test fires exactly the
|
|
2486
|
+
// timer the section armed, at the instant that timer was armed for.
|
|
2487
|
+
function fakeTimerSeam(start = 100000) {
|
|
2488
|
+
const seam = {
|
|
2489
|
+
clock: start,
|
|
2490
|
+
armed: [],
|
|
2491
|
+
setTimer(fn, ms) {
|
|
2492
|
+
const timer = {
|
|
2493
|
+
at: seam.clock + ms,
|
|
2494
|
+
ms,
|
|
2495
|
+
fn,
|
|
2496
|
+
fired: false,
|
|
2497
|
+
cleared: false,
|
|
2498
|
+
unrefCalls: 0,
|
|
2499
|
+
unref() { this.unrefCalls += 1; },
|
|
2500
|
+
};
|
|
2501
|
+
seam.armed.push(timer);
|
|
2502
|
+
return timer;
|
|
2503
|
+
},
|
|
2504
|
+
clearTimer(timer) {
|
|
2505
|
+
if (!timer) return;
|
|
2506
|
+
timer.cleared = true;
|
|
2507
|
+
seam.armed = seam.armed.filter((pending) => pending !== timer);
|
|
2508
|
+
},
|
|
2509
|
+
take() {
|
|
2510
|
+
const timer = seam.armed.shift();
|
|
2511
|
+
if (!timer) throw new Error('the section armed no timer to fire');
|
|
2512
|
+
// A fire never rewinds the clock: a test that jumped the clock forward
|
|
2513
|
+
// (to model a section nobody drew for a while) keeps that instant.
|
|
2514
|
+
seam.clock = Math.max(seam.clock, timer.at);
|
|
2515
|
+
timer.fired = true;
|
|
2516
|
+
timer.fn();
|
|
2517
|
+
return timer;
|
|
2518
|
+
},
|
|
2519
|
+
};
|
|
2520
|
+
return seam;
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
// Let the section's own deferred read settle: its `schedule` runs inline, so
|
|
2524
|
+
// only the promise chain is left.
|
|
2525
|
+
async function settleFrames() {
|
|
2526
|
+
for (let i = 0; i < 4; i += 1) await new Promise((resolve) => setImmediate(resolve));
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
test('S10 (T8): a drawn section reads on its own timer at the floor, one read per floor', async () => {
|
|
2530
|
+
const timers = fakeTimerSeam();
|
|
2531
|
+
let loads = 0;
|
|
2532
|
+
const handle = createIssuesSection({
|
|
2533
|
+
load: async () => {
|
|
2534
|
+
loads += 1;
|
|
2535
|
+
return { ok: true, identity: IDENTITY, issues: [], truncated: false };
|
|
2536
|
+
},
|
|
2537
|
+
schedule: (fn) => { fn(); },
|
|
2538
|
+
now: () => timers.clock,
|
|
2539
|
+
setTimer: timers.setTimer,
|
|
2540
|
+
clearTimer: timers.clearTimer,
|
|
2541
|
+
refreshFloorMs: 20000,
|
|
2542
|
+
timerDrawnWindowMs: 120000,
|
|
2543
|
+
});
|
|
2544
|
+
|
|
2545
|
+
// A section nobody draws starts nothing: no read and no timer (S11).
|
|
2546
|
+
await settleFrames();
|
|
2547
|
+
assert.equal(loads, 0, 'an undrawn section reads nothing');
|
|
2548
|
+
assert.equal(timers.armed.length, 0, 'an undrawn section keeps no timer');
|
|
2549
|
+
|
|
2550
|
+
// The first frame arms the floor's timer, and it never keeps the process alive.
|
|
2551
|
+
handle.section.lines({});
|
|
2552
|
+
await settleFrames();
|
|
2553
|
+
assert.equal(loads, 1, 'the drawn frame made its own TTL read');
|
|
2554
|
+
assert.equal(timers.armed.length, 1, 'one timer, armed by the drawn frame');
|
|
2555
|
+
assert.equal(timers.armed[0].ms, 20000, 'the floor L9 names');
|
|
2556
|
+
assert.equal(timers.armed[0].unrefCalls, 1, 'the timer is unref\'d, so it never holds the process');
|
|
2557
|
+
|
|
2558
|
+
// More frames while it is armed never add a timer: one read per floor, never a burst.
|
|
2559
|
+
handle.section.lines({});
|
|
2560
|
+
handle.section.meta({});
|
|
2561
|
+
assert.equal(timers.armed.length, 1, 'a frame never stacks a second timer');
|
|
2562
|
+
|
|
2563
|
+
// The fire is the read, and it arms exactly the next floor.
|
|
2564
|
+
timers.take();
|
|
2565
|
+
await settleFrames();
|
|
2566
|
+
assert.equal(loads, 2, 'the timer fired exactly one read');
|
|
2567
|
+
assert.equal(timers.armed.length, 1, 'and armed the next floor, once');
|
|
2568
|
+
assert.equal(timers.armed[0].ms, 20000);
|
|
2569
|
+
|
|
2570
|
+
// The next fire reads again: the rail keeps itself current on an idle session.
|
|
2571
|
+
timers.take();
|
|
2572
|
+
await settleFrames();
|
|
2573
|
+
assert.equal(loads, 3, 'the second floor fired its own read');
|
|
2574
|
+
assert.equal(timers.armed.length, 1);
|
|
2575
|
+
});
|
|
2576
|
+
|
|
2577
|
+
test('S10/S11 (T8): the timer never overlaps a read, and it stops once the section is not drawn', async () => {
|
|
2578
|
+
const timers = fakeTimerSeam();
|
|
2579
|
+
const pending = [];
|
|
2580
|
+
let loads = 0;
|
|
2581
|
+
const handle = createIssuesSection({
|
|
2582
|
+
load: () => {
|
|
2583
|
+
loads += 1;
|
|
2584
|
+
return new Promise((resolve) => pending.push(resolve));
|
|
2585
|
+
},
|
|
2586
|
+
schedule: (fn) => { fn(); },
|
|
2587
|
+
now: () => timers.clock,
|
|
2588
|
+
setTimer: timers.setTimer,
|
|
2589
|
+
clearTimer: timers.clearTimer,
|
|
2590
|
+
refreshFloorMs: 20000,
|
|
2591
|
+
timerDrawnWindowMs: 120000,
|
|
2592
|
+
});
|
|
2593
|
+
|
|
2594
|
+
handle.section.lines({});
|
|
2595
|
+
await settleFrames();
|
|
2596
|
+
assert.equal(loads, 1, 'the drawn frame started its read');
|
|
2597
|
+
|
|
2598
|
+
// The timer fires while that read is still in flight: it starts nothing.
|
|
2599
|
+
timers.take();
|
|
2600
|
+
await settleFrames();
|
|
2601
|
+
assert.equal(loads, 1, 'never two reads in flight');
|
|
2602
|
+
assert.equal(timers.armed.length, 1, 'the timer still arms the next floor');
|
|
2603
|
+
|
|
2604
|
+
pending.shift()({ ok: true, identity: IDENTITY, issues: [], truncated: false });
|
|
2605
|
+
await settleFrames();
|
|
2606
|
+
assert.equal(handle.snapshot().status, 'ready');
|
|
2607
|
+
|
|
2608
|
+
// Nobody drew the section for longer than the drawn window: the fire starts
|
|
2609
|
+
// nothing and the timer keeps nothing.
|
|
2610
|
+
timers.clock += 121000;
|
|
2611
|
+
timers.take();
|
|
2612
|
+
await settleFrames();
|
|
2613
|
+
assert.equal(loads, 1, 'a section outside the drawn window reads nothing');
|
|
2614
|
+
assert.equal(timers.armed.length, 0, 'and it keeps no timer');
|
|
2615
|
+
});
|
|
2616
|
+
|
|
2617
|
+
test('S10/S11 (T8): invalidate and dispose clear the timer, and a queued callback is inert', async () => {
|
|
2618
|
+
const timers = fakeTimerSeam();
|
|
2619
|
+
let loads = 0;
|
|
2620
|
+
const handle = createIssuesSection({
|
|
2621
|
+
load: async () => {
|
|
2622
|
+
loads += 1;
|
|
2623
|
+
return { ok: true, identity: IDENTITY, issues: [], truncated: false };
|
|
2624
|
+
},
|
|
2625
|
+
schedule: (fn) => { fn(); },
|
|
2626
|
+
now: () => timers.clock,
|
|
2627
|
+
setTimer: timers.setTimer,
|
|
2628
|
+
clearTimer: timers.clearTimer,
|
|
2629
|
+
refreshFloorMs: 20000,
|
|
2630
|
+
timerDrawnWindowMs: 120000,
|
|
2631
|
+
});
|
|
2632
|
+
|
|
2633
|
+
handle.section.lines({});
|
|
2634
|
+
await settleFrames();
|
|
2635
|
+
assert.equal(loads, 1);
|
|
2636
|
+
const onInvalidate = timers.armed.shift();
|
|
2637
|
+
handle.invalidate();
|
|
2638
|
+
assert.equal(onInvalidate.cleared, true, 'invalidate clears the floor timer');
|
|
2639
|
+
// A host that already queued the callback still runs it: it must be inert.
|
|
2640
|
+
timers.clock = onInvalidate.at;
|
|
2641
|
+
onInvalidate.fn();
|
|
2642
|
+
await settleFrames();
|
|
2643
|
+
assert.equal(loads, 1, 'a cleared timer reads nothing');
|
|
2644
|
+
assert.equal(timers.armed.length, 0, 'and arms nothing');
|
|
2645
|
+
|
|
2646
|
+
handle.section.lines({});
|
|
2647
|
+
await settleFrames();
|
|
2648
|
+
assert.equal(loads, 2, 'the redrawn section reads again');
|
|
2649
|
+
const onDispose = timers.armed.shift();
|
|
2650
|
+
handle.dispose();
|
|
2651
|
+
assert.equal(onDispose.cleared, true, 'dispose clears the floor timer');
|
|
2652
|
+
timers.clock = onDispose.at;
|
|
2653
|
+
onDispose.fn();
|
|
2654
|
+
await settleFrames();
|
|
2655
|
+
assert.equal(loads, 2, 'a disposed section reads nothing');
|
|
2656
|
+
assert.equal(timers.armed.length, 0);
|
|
2657
|
+
});
|
|
2658
|
+
|
|
2659
|
+
test('S11 (T8): a caller that names no floor keeps the module timer-free', async () => {
|
|
2660
|
+
const timers = fakeTimerSeam();
|
|
2661
|
+
const handle = createIssuesSection({
|
|
2662
|
+
load: async () => ({ ok: true, identity: IDENTITY, issues: [], truncated: false }),
|
|
2663
|
+
schedule: (fn) => { fn(); },
|
|
2664
|
+
now: () => timers.clock,
|
|
2665
|
+
setTimer: timers.setTimer,
|
|
2666
|
+
clearTimer: timers.clearTimer,
|
|
2667
|
+
});
|
|
2668
|
+
|
|
2669
|
+
handle.section.lines({});
|
|
2670
|
+
await settleFrames();
|
|
2671
|
+
assert.equal(handle.snapshot().status, 'ready');
|
|
2672
|
+
assert.equal(timers.armed.length, 0, 'no floor, no timer: the module schedules nothing by itself');
|
|
2673
|
+
handle.dispose();
|
|
2674
|
+
});
|
|
2675
|
+
|
|
2676
|
+
// ---------------------------------------------------------------------------
|
|
2677
|
+
// T13 (S3 amended, L11): a hidden section costs nothing — no child process, no
|
|
2678
|
+
// network, no timer. The module records when it was last DRAWN (`lines()` and
|
|
2679
|
+
// `meta()` are the drawing calls), answers `drawnWithin(window)`, and the
|
|
2680
|
+
// extension reads on the session's own activity ONLY while that answer is true.
|
|
2681
|
+
// ---------------------------------------------------------------------------
|
|
2682
|
+
|
|
2683
|
+
test('S3 (T13): drawnWithin is false until a frame is drawn, and only inside the window', async () => {
|
|
2684
|
+
let clock = 5000;
|
|
2685
|
+
let loads = 0;
|
|
2686
|
+
const handle = createIssuesSection({
|
|
2687
|
+
load: async () => {
|
|
2688
|
+
loads += 1;
|
|
2689
|
+
return { ok: true, identity: IDENTITY, issues: [], truncated: false };
|
|
2690
|
+
},
|
|
2691
|
+
open: () => {},
|
|
2692
|
+
openAll: () => {},
|
|
2693
|
+
schedule: () => {},
|
|
2694
|
+
now: () => clock,
|
|
2695
|
+
});
|
|
2696
|
+
|
|
2697
|
+
assert.equal(typeof handle.drawnWithin, 'function',
|
|
2698
|
+
'the caller asks the section whether it was drawn instead of guessing');
|
|
2699
|
+
assert.equal(handle.drawnWithin(120000), false, 'a never-drawn section is not a drawn one');
|
|
2700
|
+
assert.equal(handle.drawnWithin(0), false, 'no window makes an undrawn section drawn');
|
|
2701
|
+
|
|
2702
|
+
// The unchanged seam: an explicit caller may still ask for a read, drawn or
|
|
2703
|
+
// not. A landed read is a read, never a draw — only a frame says the section
|
|
2704
|
+
// is on screen.
|
|
2705
|
+
assert.equal(handle.refreshIfStale(30000), true,
|
|
2706
|
+
'refreshIfStale still reads an absent snapshot whether or not a frame was drawn');
|
|
2707
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
2708
|
+
assert.equal(loads, 1, 'the explicit seam made its one read');
|
|
2709
|
+
assert.equal(handle.snapshot().status, 'ready');
|
|
2710
|
+
assert.equal(handle.drawnWithin(120000), false, 'a landed read is not a drawn frame');
|
|
2711
|
+
|
|
2712
|
+
// The collapsed header IS a drawing call: the host painted the section.
|
|
2713
|
+
handle.section.meta({});
|
|
2714
|
+
assert.equal(handle.drawnWithin(0), true, 'the collapsed header stamps the frame');
|
|
2715
|
+
|
|
2716
|
+
clock += 120000;
|
|
2717
|
+
assert.equal(handle.drawnWithin(120000), true, 'the window includes its own edge');
|
|
2718
|
+
clock += 1;
|
|
2719
|
+
assert.equal(handle.drawnWithin(120000), false, 'a draw older than the window is outside it');
|
|
2720
|
+
|
|
2721
|
+
handle.section.lines({});
|
|
2722
|
+
assert.equal(handle.drawnWithin(120000), true, 'the drawn body stamps it again');
|
|
2723
|
+
|
|
2724
|
+
handle.invalidate();
|
|
2725
|
+
assert.equal(handle.drawnWithin(120000), false, 'a superseded section is not a drawn one');
|
|
2726
|
+
|
|
2727
|
+
handle.section.lines({});
|
|
2728
|
+
assert.equal(handle.drawnWithin(120000), true, 'the next frame draws it again');
|
|
2729
|
+
|
|
2730
|
+
handle.dispose();
|
|
2731
|
+
assert.equal(handle.drawnWithin(120000), false, 'a disposed section is never drawn');
|
|
2732
|
+
});
|
|
2733
|
+
|
|
2734
|
+
test('S3 (T13): a hidden section makes no gh call, and the drawn window gates the activity hooks', async () => {
|
|
2735
|
+
// The extension builds the section with the module's default clock, so the
|
|
2736
|
+
// clock is offset BEFORE the extension loads (the default `now` captures the
|
|
2737
|
+
// `Date.now` it is handed) and the drawn window moves without adding, removing
|
|
2738
|
+
// or racing a real timer.
|
|
2739
|
+
const realNow = Date.now;
|
|
2740
|
+
let offset = 0;
|
|
2741
|
+
Date.now = () => realNow() + offset;
|
|
2742
|
+
try {
|
|
2743
|
+
const checkout = makeCheckout();
|
|
2744
|
+
const { registered } = installBridge();
|
|
2745
|
+
const loaded = await loadExtension({});
|
|
2746
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2747
|
+
const gh = sectionGithub({
|
|
2748
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
2749
|
+
});
|
|
2750
|
+
ghIssues.setGhRunner(gh.runner);
|
|
2751
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
2752
|
+
|
|
2753
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
2754
|
+
// S1/S2 (T1) / S10 (T8): the gate's two identity probes are DISPATCHED startup
|
|
2755
|
+
// work and land whenever the host gets to them — this test counts `gh`
|
|
2756
|
+
// children, so it settles them through the gate's own coalesced question
|
|
2757
|
+
// before taking a baseline, never through elapsed quiet.
|
|
2758
|
+
await awaitIssuesGateSettled(checkout);
|
|
2759
|
+
assert.equal(registered.length, 1);
|
|
2760
|
+
const section = registered[0];
|
|
2761
|
+
|
|
2762
|
+
// NO frame drawn: the session starts, an agent starts and a turn ends, and
|
|
2763
|
+
// the section reads nothing at all.
|
|
2764
|
+
await fireHook(loaded.hooks, 'before_agent_start', ctx);
|
|
2765
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
2766
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
2767
|
+
assert.equal(graphqlCalls(gh.calls).length, 0, 'a hidden section makes no gh read at all');
|
|
2768
|
+
assert.deepEqual(section.lines(ctx), [{ label: 'loading…', tone: 'dim' }],
|
|
2769
|
+
'a hidden section has no rows to show, because it was never read');
|
|
2770
|
+
|
|
2771
|
+
// The section becomes visible: one frame is what starts its own read.
|
|
2772
|
+
await waitFor(() => graphqlCalls(gh.calls).length === 1, 'the drawn section never read its issues');
|
|
2773
|
+
const drawnRows = await waitForRows(section, ctx);
|
|
2774
|
+
assert.deepEqual(drawnRows.map((row) => row.label), ['#11 Assigned one'],
|
|
2775
|
+
'the drawn frame paints the read it started');
|
|
2776
|
+
assert.equal(graphqlCalls(gh.calls).length, 1, 'the drawn frame started exactly one combined read');
|
|
2777
|
+
|
|
2778
|
+
// Drawn 31 s ago, inside the two-minute window: activity reads behind the
|
|
2779
|
+
// unchanged 30 s floor.
|
|
2780
|
+
offset = 31000;
|
|
2781
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
2782
|
+
await waitFor(() => graphqlCalls(gh.calls).length === 2,
|
|
2783
|
+
'a drawn section never read on the turn boundary');
|
|
2784
|
+
|
|
2785
|
+
// The drawn window has passed: the same hooks read nothing at all.
|
|
2786
|
+
offset = 161000;
|
|
2787
|
+
const quiet = gh.calls.length;
|
|
2788
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
2789
|
+
await fireHook(loaded.hooks, 'before_agent_start', ctx);
|
|
2790
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
2791
|
+
assert.equal(gh.calls.length, quiet, 'a section outside the drawn window makes no gh call');
|
|
2792
|
+
assert.equal(graphqlCalls(gh.calls).length, 2, 'and no combined read either');
|
|
2793
|
+
|
|
2794
|
+
// Drawn again, the section works again: the frame's own TTL starts the read.
|
|
2795
|
+
section.lines(ctx);
|
|
2796
|
+
await waitFor(() => graphqlCalls(gh.calls).length === 3, 'the redrawn section never read again');
|
|
2797
|
+
} finally {
|
|
2798
|
+
Date.now = realNow;
|
|
2799
|
+
}
|
|
2800
|
+
});
|
|
2801
|
+
|
|
2802
|
+
test('S3 (T13): a session that shut down reads nothing on a later activity', async () => {
|
|
2803
|
+
const checkout = makeCheckout();
|
|
2804
|
+
const { registered } = installBridge();
|
|
2805
|
+
const loaded = await loadExtension({});
|
|
2806
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2807
|
+
const gh = sectionGithub({
|
|
2808
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
2809
|
+
});
|
|
2810
|
+
ghIssues.setGhRunner(gh.runner);
|
|
2811
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
2812
|
+
|
|
2813
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
2814
|
+
// S10 (T8): the dispatched gate's probes are settled here for the same reason as
|
|
2815
|
+
// the drawn-window case above: this test measures a `gh` child count.
|
|
2816
|
+
await awaitIssuesGateSettled(checkout);
|
|
2817
|
+
assert.equal(registered.length, 1);
|
|
2818
|
+
const section = registered[0];
|
|
2819
|
+
// The section is on screen and drew its rows.
|
|
2820
|
+
section.lines(ctx);
|
|
2821
|
+
await waitFor(() => graphqlCalls(gh.calls).length === 1, 'the drawn section never read its issues');
|
|
2822
|
+
await waitForRows(section, ctx);
|
|
2823
|
+
|
|
2824
|
+
// Shutdown supersedes the drawn frame: the section is showing nothing, so the
|
|
2825
|
+
// next activity must not start a read.
|
|
2826
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
2827
|
+
const before = gh.calls.length;
|
|
2828
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
2829
|
+
await fireHook(loaded.hooks, 'before_agent_start', ctx);
|
|
2830
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
2831
|
+
assert.equal(gh.calls.length, before, 'a shut-down session reads nothing on a later activity');
|
|
2832
|
+
});
|
|
2833
|
+
|
|
2834
|
+
// ---------------------------------------------------------------------------
|
|
2835
|
+
// T8/T9 (S10, S11, L9): the rail refreshes on TIME and after a mutating `bash`.
|
|
2836
|
+
// The extension arms the section's own floor timer at 20 s (L9) while the
|
|
2837
|
+
// section is drawn, its activity hooks add no read on top of a fresh one, and a
|
|
2838
|
+
// `bash` result whose command mutates an issue or a pull request forces ONE read
|
|
2839
|
+
// behind the 5 s anti-storm cap. Nothing at all happens while the section is not
|
|
2840
|
+
// drawn (S11), and a result from a session that already ended forces nothing.
|
|
2841
|
+
// ---------------------------------------------------------------------------
|
|
2842
|
+
|
|
2843
|
+
test('S10 (T8): a drawn section reads on the extension\'s own 20 s timer, and activity adds nothing', async () => {
|
|
2844
|
+
const realSetTimeout = globalThis.setTimeout;
|
|
2845
|
+
const realClearTimeout = globalThis.clearTimeout;
|
|
2846
|
+
const realNow = Date.now;
|
|
2847
|
+
let offset = 0;
|
|
2848
|
+
Date.now = () => realNow() + offset;
|
|
2849
|
+
// The section's floor timer is the ONE timer this test owns: it is captured
|
|
2850
|
+
// instead of waited for, so the 20 s floor is exercised without 20 idle
|
|
2851
|
+
// seconds. Every other delay goes to the host's own `setTimeout`.
|
|
2852
|
+
const armed = [];
|
|
2853
|
+
globalThis.setTimeout = (fn, ms, ...rest) => {
|
|
2854
|
+
if (ms === 20000) {
|
|
2855
|
+
const timer = { fn, ms, fired: false, cleared: false, issuesFloorTimer: true, unref() {} };
|
|
2856
|
+
armed.push(timer);
|
|
2857
|
+
return timer;
|
|
2858
|
+
}
|
|
2859
|
+
return realSetTimeout(fn, ms, ...rest);
|
|
2860
|
+
};
|
|
2861
|
+
globalThis.clearTimeout = (handle) => {
|
|
2862
|
+
if (handle && handle.issuesFloorTimer === true) {
|
|
2863
|
+
handle.cleared = true;
|
|
2864
|
+
return;
|
|
2865
|
+
}
|
|
2866
|
+
return realClearTimeout(handle);
|
|
2867
|
+
};
|
|
2868
|
+
try {
|
|
2869
|
+
const checkout = makeCheckout();
|
|
2870
|
+
const { registered } = installBridge();
|
|
2871
|
+
const loaded = await loadExtension({});
|
|
2872
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2873
|
+
const gh = sectionGithub({
|
|
2874
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
2875
|
+
});
|
|
2876
|
+
ghIssues.setGhRunner(gh.runner);
|
|
2877
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} }, sessionManager: { getSessionId: () => 'session-one' } };
|
|
2878
|
+
|
|
2879
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
2880
|
+
assert.equal(registered.length, 1);
|
|
2881
|
+
const section = registered[0];
|
|
2882
|
+
|
|
2883
|
+
// A hidden section: no frame, no timer, no read (S11).
|
|
2884
|
+
await fireHook(loaded.hooks, 'before_agent_start', ctx);
|
|
2885
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
2886
|
+
await new Promise((resolve) => realSetTimeout(resolve, 120));
|
|
2887
|
+
assert.equal(armed.length, 0, 'a hidden section keeps no timer');
|
|
2888
|
+
assert.equal(graphqlCalls(gh.calls).length, 0, 'a hidden section reads nothing');
|
|
2889
|
+
|
|
2890
|
+
// The drawn frame arms ONE unref'd timer at the floor L9 names.
|
|
2891
|
+
await waitForRows(section, ctx);
|
|
2892
|
+
assert.equal(armed.length, 1, 'the drawn frame armed one timer');
|
|
2893
|
+
assert.equal(armed[0].ms, 20000, 'the floor is 20 s (L9)');
|
|
2894
|
+
const reads = graphqlCalls(gh.calls).length;
|
|
2895
|
+
assert.equal(reads, 1, 'the drawn frame made its own read');
|
|
2896
|
+
|
|
2897
|
+
// The timer fires at its floor: exactly one read, and the next floor armed.
|
|
2898
|
+
offset = 25000;
|
|
2899
|
+
armed[0].fired = true;
|
|
2900
|
+
armed[0].fn();
|
|
2901
|
+
await waitFor(() => graphqlCalls(gh.calls).length === reads + 1,
|
|
2902
|
+
'the drawn section\'s floor timer started no read');
|
|
2903
|
+
assert.equal(armed.length, 2, 'the fire armed the next floor');
|
|
2904
|
+
|
|
2905
|
+
// The session's own activity adds no read on top of the timer's own.
|
|
2906
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
2907
|
+
await fireHook(loaded.hooks, 'before_agent_start', ctx);
|
|
2908
|
+
await new Promise((resolve) => realSetTimeout(resolve, 150));
|
|
2909
|
+
assert.equal(graphqlCalls(gh.calls).length, reads + 1, 'activity added no read inside the floor');
|
|
2910
|
+
|
|
2911
|
+
// The session boundary clears the timer, and a callback already queued by
|
|
2912
|
+
// the host reads nothing.
|
|
2913
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
2914
|
+
assert.equal(armed[1].cleared, true, 'session_shutdown cleared the floor timer');
|
|
2915
|
+
offset = 50000;
|
|
2916
|
+
armed[1].fired = true;
|
|
2917
|
+
armed[1].fn();
|
|
2918
|
+
await new Promise((resolve) => realSetTimeout(resolve, 150));
|
|
2919
|
+
assert.equal(graphqlCalls(gh.calls).length, reads + 1, 'a cleared timer reads nothing');
|
|
2920
|
+
} finally {
|
|
2921
|
+
Date.now = realNow;
|
|
2922
|
+
globalThis.setTimeout = realSetTimeout;
|
|
2923
|
+
globalThis.clearTimeout = realClearTimeout;
|
|
2924
|
+
}
|
|
2925
|
+
});
|
|
2926
|
+
|
|
2927
|
+
// T18 (S11, PR #89 review): the extension stored the bridge's unregister and the
|
|
2928
|
+
// section's handle but ran neither, so a section that was REPLACED — a republished
|
|
2929
|
+
// bridge, a second mount — kept its 20 s floor timer alive for the rest of its
|
|
2930
|
+
// drawn window. A replaced section must be torn down before the replacement is
|
|
2931
|
+
// registered, and must read nothing afterwards: that duplicate `gh` traffic is
|
|
2932
|
+
// exactly what this feature exists to remove.
|
|
2933
|
+
test('S11 (T18): a re-mount tears the replaced section down, so it reads nothing', async () => {
|
|
2934
|
+
const floor = captureFloorTimers();
|
|
2935
|
+
const realNow = Date.now;
|
|
2936
|
+
let offset = 0;
|
|
2937
|
+
Date.now = () => realNow() + offset;
|
|
2938
|
+
try {
|
|
2939
|
+
const checkout = makeCheckout();
|
|
2940
|
+
const firstBridge = installBridge();
|
|
2941
|
+
const loaded = await loadExtension({});
|
|
2942
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2943
|
+
const gh = sectionGithub({
|
|
2944
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
2945
|
+
});
|
|
2946
|
+
ghIssues.setGhRunner(gh.runner);
|
|
2947
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} }, sessionManager: { getSessionId: () => 'session-one' } };
|
|
2948
|
+
|
|
2949
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
2950
|
+
await awaitIssuesGateSettled(checkout);
|
|
2951
|
+
assert.equal(firstBridge.registered.length, 1, 'the first bridge holds the first section');
|
|
2952
|
+
const replaced = firstBridge.registered[0];
|
|
2953
|
+
await waitForRows(replaced, ctx);
|
|
2954
|
+
assert.equal(graphqlCalls(gh.calls).length, 1, 'the first section read once');
|
|
2955
|
+
assert.equal(floor.armed.length, 1, 'and armed its own floor timer');
|
|
2956
|
+
|
|
2957
|
+
// A republished bridge is a NEW published object, so the rail binds again on
|
|
2958
|
+
// the next session boundary — while the replaced section is still live.
|
|
2959
|
+
const republished = installBridge();
|
|
2960
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
2961
|
+
await awaitIssuesGateSettled(checkout);
|
|
2962
|
+
|
|
2963
|
+
// The replaced section must be inert: a frame the host still paints (and the
|
|
2964
|
+
// clock moving past the floor with it) starts no read at all.
|
|
2965
|
+
const reads = graphqlCalls(gh.calls).length;
|
|
2966
|
+
replaced.lines(ctx);
|
|
2967
|
+
offset = 25000;
|
|
2968
|
+
for (const timer of floor.armed.slice(1)) timer.fn();
|
|
2969
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
2970
|
+
assert.equal(graphqlCalls(gh.calls).length, reads,
|
|
2971
|
+
'the replaced section kept reading after the re-mount');
|
|
2972
|
+
assert.equal(floor.armed.length, 1, 'and the replaced section armed no floor timer');
|
|
2973
|
+
|
|
2974
|
+
// The replacement was registered, and the binding it replaced was unregistered
|
|
2975
|
+
// FIRST — the tear-down order the contract names.
|
|
2976
|
+
assert.equal(republished.registered.length, 1, 'the new bridge holds the replacement section');
|
|
2977
|
+
assert.deepEqual(firstBridge.released, [replaced], 'the replaced binding was unregistered first');
|
|
2978
|
+
} finally {
|
|
2979
|
+
Date.now = realNow;
|
|
2980
|
+
floor.restore();
|
|
2981
|
+
}
|
|
2982
|
+
});
|
|
2983
|
+
|
|
2984
|
+
// T18 (S11): a session that ends takes its timer with it. `invalidate()` dropped
|
|
2985
|
+
// the snapshot but left the section alive, so one frame the host painted after
|
|
2986
|
+
// shutdown re-armed the floor and kept reading for the rest of the drawn window.
|
|
2987
|
+
test('S11 (T18): a shut-down session leaves no floor timer behind', async () => {
|
|
2988
|
+
const floor = captureFloorTimers();
|
|
2989
|
+
const realNow = Date.now;
|
|
2990
|
+
let offset = 0;
|
|
2991
|
+
Date.now = () => realNow() + offset;
|
|
2992
|
+
try {
|
|
2993
|
+
const checkout = makeCheckout();
|
|
2994
|
+
const { registered } = installBridge();
|
|
2995
|
+
const loaded = await loadExtension({});
|
|
2996
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
2997
|
+
const gh = sectionGithub({
|
|
2998
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
2999
|
+
});
|
|
3000
|
+
ghIssues.setGhRunner(gh.runner);
|
|
3001
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} }, sessionManager: { getSessionId: () => 'session-one' } };
|
|
3002
|
+
|
|
3003
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3004
|
+
await awaitIssuesGateSettled(checkout);
|
|
3005
|
+
const section = registered[0];
|
|
3006
|
+
await waitForRows(section, ctx);
|
|
3007
|
+
assert.equal(graphqlCalls(gh.calls).length, 1, 'the drawn section made its own read');
|
|
3008
|
+
assert.equal(floor.armed.length, 1, 'and armed the floor');
|
|
3009
|
+
|
|
3010
|
+
// One floor fires, so a second floor is armed when the session ends.
|
|
3011
|
+
offset = 25000;
|
|
3012
|
+
floor.armed[0].fn();
|
|
3013
|
+
await waitFor(() => graphqlCalls(gh.calls).length === 2, 'the floor timer started no read');
|
|
3014
|
+
// Let that read settle, so the only read the post-shutdown frame could start
|
|
3015
|
+
// is its own (a read still in flight would mask it behind `running`).
|
|
3016
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3017
|
+
assert.equal(floor.armed.length, 2, 'the fire armed the next floor');
|
|
3018
|
+
|
|
3019
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
3020
|
+
assert.equal(floor.armed[1].cleared, true, 'shutdown cleared the armed floor');
|
|
3021
|
+
|
|
3022
|
+
// The host can still paint the frame it held when the session ended, and that
|
|
3023
|
+
// draw would re-open the drawn window. A shut-down section must arm nothing and
|
|
3024
|
+
// start no read, however many floors pass inside that window.
|
|
3025
|
+
section.lines(ctx);
|
|
3026
|
+
offset = 25000 + 60000;
|
|
3027
|
+
for (const timer of floor.armed.slice(2)) timer.fn();
|
|
3028
|
+
await new Promise((resolve) => setTimeout(resolve, 400));
|
|
3029
|
+
assert.equal(floor.armed.length, 2, 'a shut-down section armed no floor timer');
|
|
3030
|
+
// A read attempt settles an ended-session error row; the disposed section keeps
|
|
3031
|
+
// the loading row, so this is what "nothing reads" looks like from outside.
|
|
3032
|
+
assert.deepEqual(section.lines(ctx), [{ label: 'loading…', tone: 'dim' }],
|
|
3033
|
+
'a shut-down section started a read after its session ended');
|
|
3034
|
+
} finally {
|
|
3035
|
+
Date.now = realNow;
|
|
3036
|
+
floor.restore();
|
|
3037
|
+
}
|
|
3038
|
+
});
|
|
3039
|
+
|
|
3040
|
+
// The rail's floor is a REAL 20 s timer (the extension's own constant) and no test
|
|
3041
|
+
// waits 20 s for it: a test that needs the floor fires the captured callback
|
|
3042
|
+
// itself, exactly like the host would. Every other delay still goes to the host.
|
|
3043
|
+
function captureFloorTimers() {
|
|
3044
|
+
const armed = [];
|
|
3045
|
+
const hostSetTimeout = globalThis.setTimeout;
|
|
3046
|
+
const hostClearTimeout = globalThis.clearTimeout;
|
|
3047
|
+
globalThis.setTimeout = (fn, ms, ...rest) => {
|
|
3048
|
+
if (ms === 20000) {
|
|
3049
|
+
const timer = { fn, ms, cleared: false, issuesFloorTimer: true, unref() {} };
|
|
3050
|
+
armed.push(timer);
|
|
3051
|
+
return timer;
|
|
3052
|
+
}
|
|
3053
|
+
return hostSetTimeout(fn, ms, ...rest);
|
|
3054
|
+
};
|
|
3055
|
+
globalThis.clearTimeout = (handle) => {
|
|
3056
|
+
if (handle && handle.issuesFloorTimer === true) {
|
|
3057
|
+
handle.cleared = true;
|
|
3058
|
+
return;
|
|
3059
|
+
}
|
|
3060
|
+
return hostClearTimeout(handle);
|
|
3061
|
+
};
|
|
3062
|
+
return {
|
|
3063
|
+
armed,
|
|
3064
|
+
restore() {
|
|
3065
|
+
globalThis.setTimeout = hostSetTimeout;
|
|
3066
|
+
globalThis.clearTimeout = hostClearTimeout;
|
|
3067
|
+
},
|
|
3068
|
+
};
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
// S10 (T8) L9: ONE floor window is ONE read. The floor is the only thing that
|
|
3072
|
+
// buys a read — a drawn frame, a session event and a timer callback all ask the
|
|
3073
|
+
// section, and none of them may add a second read inside the same window: that
|
|
3074
|
+
// is the duplicate `gh` traffic this feature exists to remove. And a read that
|
|
3075
|
+
// LANDS starts the next window, so an answer arriving does not immediately start
|
|
3076
|
+
// another read (requirement 2): its own settling instant is the floor's zero.
|
|
3077
|
+
test('S10 (T8): one floor window is ONE read, however many frames, activity events and timer fires land in it', async () => {
|
|
3078
|
+
const floor = captureFloorTimers();
|
|
3079
|
+
const realNow = Date.now;
|
|
3080
|
+
let offset = 0;
|
|
3081
|
+
Date.now = () => realNow() + offset;
|
|
3082
|
+
try {
|
|
3083
|
+
const checkout = makeCheckout();
|
|
3084
|
+
const { registered } = installBridge();
|
|
3085
|
+
const loaded = await loadExtension({});
|
|
3086
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3087
|
+
const gh = sectionGithub({
|
|
3088
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
3089
|
+
});
|
|
3090
|
+
ghIssues.setGhRunner(gh.runner);
|
|
3091
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} }, sessionManager: { getSessionId: () => 'session-one' } };
|
|
3092
|
+
|
|
3093
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3094
|
+
assert.equal(registered.length, 1);
|
|
3095
|
+
const section = registered[0];
|
|
3096
|
+
const reads = () => graphqlCalls(gh.calls).length;
|
|
3097
|
+
|
|
3098
|
+
// The drawn frame's own read, and the one floor it armed.
|
|
3099
|
+
await waitForRows(section, ctx);
|
|
3100
|
+
assert.equal(reads(), 1, 'the drawn frame made its own read');
|
|
3101
|
+
assert.equal(floor.armed.length, 1, 'and armed ONE floor timer');
|
|
3102
|
+
|
|
3103
|
+
// Twenty more frames and ten session events, all inside that floor: not one
|
|
3104
|
+
// read. The TTL has not expired and the activity floor is untouched.
|
|
3105
|
+
for (let index = 0; index < 20; index += 1) section.lines(ctx);
|
|
3106
|
+
section.meta(ctx);
|
|
3107
|
+
for (let index = 0; index < 5; index += 1) {
|
|
3108
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
3109
|
+
await fireHook(loaded.hooks, 'before_agent_start', ctx);
|
|
3110
|
+
}
|
|
3111
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
3112
|
+
assert.equal(reads(), 1, 'a floor window is ONE read, whatever lands inside it');
|
|
3113
|
+
|
|
3114
|
+
// The floor timer firing to its floor is the window's one read.
|
|
3115
|
+
offset = 25000;
|
|
3116
|
+
floor.armed[0].fn();
|
|
3117
|
+
await waitFor(() => reads() === 2, 'the floor timer started no read');
|
|
3118
|
+
assert.equal(floor.armed.length, 2, 'and it armed the next floor');
|
|
3119
|
+
|
|
3120
|
+
// The same callback a second time (a host that had already queued it) is
|
|
3121
|
+
// inert: the section moved its token on when it armed the next floor.
|
|
3122
|
+
floor.armed[0].fn();
|
|
3123
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
3124
|
+
assert.equal(reads(), 2, 'a repeated callback adds no read');
|
|
3125
|
+
|
|
3126
|
+
// The read has landed: its settling instant is the floor's zero, so neither
|
|
3127
|
+
// frames nor activity nor a stale callback start a read on top of it.
|
|
3128
|
+
for (let index = 0; index < 10; index += 1) section.lines(ctx);
|
|
3129
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
3130
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
3131
|
+
assert.equal(reads(), 2, 'an answer that landed started no further read');
|
|
3132
|
+
} finally {
|
|
3133
|
+
Date.now = realNow;
|
|
3134
|
+
floor.restore();
|
|
3135
|
+
}
|
|
3136
|
+
});
|
|
3137
|
+
|
|
3138
|
+
test('S10 (T9): a mutating bash result forces one read, capped to one per 5 s', async () => {
|
|
3139
|
+
const realNow = Date.now;
|
|
3140
|
+
let offset = 0;
|
|
3141
|
+
Date.now = () => realNow() + offset;
|
|
3142
|
+
try {
|
|
3143
|
+
const checkout = makeCheckout();
|
|
3144
|
+
const { registered } = installBridge();
|
|
3145
|
+
const loaded = await loadExtension({});
|
|
3146
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3147
|
+
const gh = sectionGithub({
|
|
3148
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
3149
|
+
});
|
|
3150
|
+
ghIssues.setGhRunner(gh.runner);
|
|
3151
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} }, sessionManager: { getSessionId: () => 'session-one' } };
|
|
3152
|
+
|
|
3153
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3154
|
+
assert.equal(registered.length, 1);
|
|
3155
|
+
const section = registered[0];
|
|
3156
|
+
await waitForRows(section, ctx);
|
|
3157
|
+
const reads = graphqlCalls(gh.calls).length;
|
|
3158
|
+
assert.equal(reads, 1);
|
|
3159
|
+
|
|
3160
|
+
const bashResult = (command) => ({ toolName: 'bash', input: { command }, toolResults: [] });
|
|
3161
|
+
|
|
3162
|
+
// The mutating result forces exactly one read, right after it.
|
|
3163
|
+
await fireEvent(loaded.hooks, 'tool_result', bashResult('gh issue close 11'), ctx);
|
|
3164
|
+
await waitFor(() => graphqlCalls(gh.calls).length === reads + 1,
|
|
3165
|
+
'a mutating bash result forced no read');
|
|
3166
|
+
|
|
3167
|
+
// A second write inside the 5 s cap forces nothing (L9).
|
|
3168
|
+
await fireEvent(loaded.hooks, 'tool_result', bashResult('gh pr merge 3'), ctx);
|
|
3169
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
3170
|
+
assert.equal(graphqlCalls(gh.calls).length, reads + 1, 'the anti-storm cap held');
|
|
3171
|
+
|
|
3172
|
+
// A read-only command and a non-bash tool force nothing either.
|
|
3173
|
+
await fireEvent(loaded.hooks, 'tool_result', bashResult('gh issue list --limit 5'), ctx);
|
|
3174
|
+
await fireEvent(loaded.hooks, 'tool_result', { toolName: 'write', input: { command: 'gh issue close 12' }, toolResults: [] }, ctx);
|
|
3175
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
3176
|
+
assert.equal(graphqlCalls(gh.calls).length, reads + 1, 'only a mutating bash forces a read');
|
|
3177
|
+
|
|
3178
|
+
// Past the cap the next mutation forces its own read.
|
|
3179
|
+
offset = 6000;
|
|
3180
|
+
await fireEvent(loaded.hooks, 'tool_result', bashResult('gh issue reopen 11'), ctx);
|
|
3181
|
+
await waitFor(() => graphqlCalls(gh.calls).length === reads + 2,
|
|
3182
|
+
'a mutation past the cap forced no read');
|
|
3183
|
+
|
|
3184
|
+
// A result from a session that already ended forces nothing.
|
|
3185
|
+
await fireEvent(loaded.hooks, 'tool_result', bashResult('gh issue close 11'), {
|
|
3186
|
+
...ctx,
|
|
3187
|
+
sessionManager: { getSessionId: () => 'session-that-ended' },
|
|
3188
|
+
});
|
|
3189
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
3190
|
+
assert.equal(graphqlCalls(gh.calls).length, reads + 2, 'an ended session\'s result forces nothing');
|
|
3191
|
+
} finally {
|
|
3192
|
+
Date.now = realNow;
|
|
3193
|
+
}
|
|
3194
|
+
});
|
|
3195
|
+
|
|
3196
|
+
// S10 (T9): the host does not have to spell a tool event the way our other
|
|
3197
|
+
// handlers read it first. `oddToolNameOf` accepts `toolName`, `tool` and `name`,
|
|
3198
|
+
// and `oddArgsOf` accepts `args`, `input`, `params` and `arguments`, so the one
|
|
3199
|
+
// handler that forces a read has to read the event through the same pair — a
|
|
3200
|
+
// `tool`/`args` result is the same bash call and must force the same read.
|
|
3201
|
+
test('S10 (T9): a mutating bash named under `tool`/`args` forces the same read', async () => {
|
|
3202
|
+
const realNow = Date.now;
|
|
3203
|
+
Date.now = () => realNow();
|
|
3204
|
+
try {
|
|
3205
|
+
const checkout = makeCheckout();
|
|
3206
|
+
const { registered } = installBridge();
|
|
3207
|
+
const loaded = await loadExtension({});
|
|
3208
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3209
|
+
const gh = sectionGithub({
|
|
3210
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
3211
|
+
});
|
|
3212
|
+
ghIssues.setGhRunner(gh.runner);
|
|
3213
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} }, sessionManager: { getSessionId: () => 'session-one' } };
|
|
3214
|
+
|
|
3215
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3216
|
+
const section = registered[0];
|
|
3217
|
+
await waitForRows(section, ctx);
|
|
3218
|
+
const reads = graphqlCalls(gh.calls).length;
|
|
3219
|
+
|
|
3220
|
+
await fireEvent(loaded.hooks, 'tool_result', { tool: 'bash', args: { command: 'gh issue close 11' }, toolResults: [] }, ctx);
|
|
3221
|
+
await waitFor(() => graphqlCalls(gh.calls).length === reads + 1,
|
|
3222
|
+
'a mutating bash carried under `tool`/`args` forced no read');
|
|
3223
|
+
} finally {
|
|
3224
|
+
Date.now = realNow;
|
|
3225
|
+
}
|
|
3226
|
+
});
|
|
3227
|
+
|
|
3228
|
+
test('S11 (T9): a hidden section forces no read, and a mutating result after shutdown does nothing', async () => {
|
|
3229
|
+
const realNow = Date.now;
|
|
3230
|
+
let offset = 0;
|
|
3231
|
+
Date.now = () => realNow() + offset;
|
|
3232
|
+
try {
|
|
3233
|
+
const checkout = makeCheckout();
|
|
3234
|
+
const { registered } = installBridge();
|
|
3235
|
+
const loaded = await loadExtension({});
|
|
3236
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3237
|
+
const gh = sectionGithub({
|
|
3238
|
+
issues: [{ number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' }],
|
|
3239
|
+
});
|
|
3240
|
+
ghIssues.setGhRunner(gh.runner);
|
|
3241
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} }, sessionManager: { getSessionId: () => 'session-one' } };
|
|
3242
|
+
|
|
3243
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3244
|
+
assert.equal(registered.length, 1);
|
|
3245
|
+
|
|
3246
|
+
// Nothing was ever drawn, so nothing is forced (S11).
|
|
3247
|
+
await fireEvent(loaded.hooks, 'tool_result', { toolName: 'bash', input: { command: 'gh issue close 11' }, toolResults: [] }, ctx);
|
|
3248
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
3249
|
+
assert.equal(graphqlCalls(gh.calls).length, 0, 'a hidden section forces no read at all');
|
|
3250
|
+
|
|
3251
|
+
// Drawn, then shut down: the section is showing nothing again.
|
|
3252
|
+
const section = registered[0];
|
|
3253
|
+
await waitForRows(section, ctx);
|
|
3254
|
+
const reads = graphqlCalls(gh.calls).length;
|
|
3255
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
3256
|
+
offset = 6000;
|
|
3257
|
+
await fireEvent(loaded.hooks, 'tool_result', { toolName: 'bash', input: { command: 'gh issue close 11' }, toolResults: [] }, ctx);
|
|
3258
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
3259
|
+
assert.equal(graphqlCalls(gh.calls).length, reads, 'a result after shutdown forces nothing');
|
|
3260
|
+
} finally {
|
|
3261
|
+
Date.now = realNow;
|
|
3262
|
+
}
|
|
3263
|
+
});
|
|
3264
|
+
|
|
3265
|
+
// ---------------------------------------------------------------------------
|
|
3266
|
+
// T14 (S9): ONE combined read feeds a process-local cache of all three scoped
|
|
3267
|
+
// views, and the rail keeps drawing only the assigned bucket. The wiring asks
|
|
3268
|
+
// the cache for a plan BEFORE the read — 100 per bucket with no entry, the
|
|
3269
|
+
// newest 20 afterwards — makes exactly ONE `gh` child per refresh, applies the
|
|
3270
|
+
// answer and returns the cached assigned rows. A count mismatch (an issue closed
|
|
3271
|
+
// or unassigned) makes the next refresh full; a failed read touches nothing, so
|
|
3272
|
+
// the T10 stale list survives; a shutdown clears the cache.
|
|
3273
|
+
// ---------------------------------------------------------------------------
|
|
3274
|
+
|
|
3275
|
+
test('S9 (T14): the first refresh reads 100 per bucket, the next reads 20 and merges them', async () => {
|
|
3276
|
+
const realNow = Date.now;
|
|
3277
|
+
let offset = 0;
|
|
3278
|
+
Date.now = () => realNow() + offset;
|
|
3279
|
+
try {
|
|
3280
|
+
const checkout = makeCheckout();
|
|
3281
|
+
const { registered } = installBridge();
|
|
3282
|
+
const loaded = await loadExtension({});
|
|
3283
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3284
|
+
const calls = [];
|
|
3285
|
+
const answers = [
|
|
3286
|
+
relatedAnswer({
|
|
3287
|
+
assigned: [
|
|
3288
|
+
{ number: 11, title: 'Eleven', updatedAt: '2024-01-01T00:00:00Z' },
|
|
3289
|
+
{ number: 12, title: 'Twelve', updatedAt: '2024-02-01T00:00:00Z' },
|
|
3290
|
+
],
|
|
3291
|
+
}),
|
|
3292
|
+
relatedAnswer({
|
|
3293
|
+
assigned: [
|
|
3294
|
+
{ number: 12, title: 'Twelve (updated)', updatedAt: '2024-03-01T00:00:00Z' },
|
|
3295
|
+
{ number: 13, title: 'Thirteen', updatedAt: '2024-04-01T00:00:00Z' },
|
|
3296
|
+
],
|
|
3297
|
+
counts: { assigned: 3 },
|
|
3298
|
+
}),
|
|
3299
|
+
];
|
|
3300
|
+
ghIssues.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
3301
|
+
calls.push({ argv: argv.slice(), env: { ...(runOpts.env || {}) }, cwd: runOpts && runOpts.cwd });
|
|
3302
|
+
if (argv[0] === 'api' && argv[1] === 'user') return okJson('{"login":"me"}');
|
|
3303
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
3304
|
+
return okJson(JSON.stringify({ nameWithOwner: 'myfork/project' }));
|
|
3305
|
+
}
|
|
3306
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
3307
|
+
return okJson(JSON.stringify(answers.shift()));
|
|
3308
|
+
}
|
|
3309
|
+
return okJson('');
|
|
3310
|
+
});
|
|
3311
|
+
|
|
3312
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
3313
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3314
|
+
assert.equal(registered.length, 1);
|
|
3315
|
+
const section = registered[0];
|
|
3316
|
+
// S1 (issues-startup-performance T1) / S5 (T8): the session gate is dispatched
|
|
3317
|
+
// startup work now, so its own identity probes are counted once they have
|
|
3318
|
+
// landed — which is what makes the baseline below count the refreshes and
|
|
3319
|
+
// nothing else. The barrier is the gate's own coalescing seam, never elapsed
|
|
3320
|
+
// quiet: a quiet window is exactly what a loaded runner breaks.
|
|
3321
|
+
await awaitIssuesGateSettled(checkout);
|
|
3322
|
+
await settleStartup(calls);
|
|
3323
|
+
const baseline = calls.length; // the session gate's own identity probes
|
|
3324
|
+
|
|
3325
|
+
const firstRows = await waitForRows(section, ctx);
|
|
3326
|
+
assert.deepEqual(firstRows.map((row) => row.label), ['#12 Twelve', '#11 Eleven']);
|
|
3327
|
+
|
|
3328
|
+
let reads = graphqlCalls(calls);
|
|
3329
|
+
assert.equal(reads.length, 1, 'one combined read serves the first refresh');
|
|
3330
|
+
assert.equal(calls.length, baseline + 1, 'exactly ONE gh child per refresh');
|
|
3331
|
+
let query = graphqlQueryOf(reads[0]);
|
|
3332
|
+
assert.equal((query.match(/first: 100/g) || []).length, 3, 'the first sync reads 100 per bucket');
|
|
3333
|
+
assert.equal(reads[0].env.GH_REPO, IDENTITY, 'the read carries the pinned identity');
|
|
3334
|
+
|
|
3335
|
+
// The section's 60 s TTL starts the next frame's refresh; the cache is well
|
|
3336
|
+
// inside its ten-minute full-read window, so the read is the newest 20.
|
|
3337
|
+
offset = 61000;
|
|
3338
|
+
section.lines(ctx);
|
|
3339
|
+
await waitFor(() => graphqlCalls(calls).length === 2, 'the delta refresh never ran');
|
|
3340
|
+
await waitFor(
|
|
3341
|
+
() => section.lines(ctx).some((row) => row.label === '#13 Thirteen'),
|
|
3342
|
+
'the delta rows never merged with the cached ones',
|
|
3343
|
+
);
|
|
3344
|
+
|
|
3345
|
+
reads = graphqlCalls(calls);
|
|
3346
|
+
assert.equal(calls.length, baseline + 2, 'one gh child per refresh, never more');
|
|
3347
|
+
query = graphqlQueryOf(reads[1]);
|
|
3348
|
+
assert.equal((query.match(/first: 20/g) || []).length, 3, 'later syncs read the newest 20 per bucket');
|
|
3349
|
+
assert.deepEqual(section.lines(ctx).map((row) => row.label),
|
|
3350
|
+
['#13 Thirteen', '#12 Twelve (updated)', '#11 Eleven'],
|
|
3351
|
+
'the delta merged by number and kept the rows it did not mention');
|
|
3352
|
+
} finally {
|
|
3353
|
+
Date.now = realNow;
|
|
3354
|
+
}
|
|
3355
|
+
});
|
|
3356
|
+
|
|
3357
|
+
// S10 (T8) / PR #89: the child count a refresh is measured by must be the
|
|
3358
|
+
// refresh's OWN children. The session gate is dispatched startup work, so its two
|
|
3359
|
+
// identity probes land whenever the host gets to them — and on the loaded CI
|
|
3360
|
+
// runner that produced `expected 1, actual 3` they landed inside the measured
|
|
3361
|
+
// window, after a quiet call list had been taken as "startup is over". The gate's
|
|
3362
|
+
// answers are slowed here exactly where a loaded runner slows them (its first
|
|
3363
|
+
// child), which makes the window deterministic instead of machine-dependent: no
|
|
3364
|
+
// quiet window can fall between `gh api user` and `gh repo view`, so an
|
|
3365
|
+
// unguarded baseline always miscounts. The rail itself reads ONCE.
|
|
3366
|
+
test('S10 (T8): the dispatched session gate never inflates the rail read\'s child count (PR #89)', async () => {
|
|
3367
|
+
const realNow = Date.now;
|
|
3368
|
+
let offset = 0;
|
|
3369
|
+
Date.now = () => realNow() + offset;
|
|
3370
|
+
try {
|
|
3371
|
+
const checkout = makeCheckout();
|
|
3372
|
+
const { registered } = installBridge();
|
|
3373
|
+
const loaded = await loadExtension({});
|
|
3374
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3375
|
+
const calls = [];
|
|
3376
|
+
ghIssues.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
3377
|
+
calls.push({ argv: argv.slice(), env: { ...(runOpts.env || {}) }, cwd: runOpts && runOpts.cwd });
|
|
3378
|
+
if (argv[0] === 'api' && argv[1] === 'user') {
|
|
3379
|
+
// The gate's first child straddles the quiet window a barrier-free baseline
|
|
3380
|
+
// uses, so its SECOND child (`gh repo view`, spawned only once this one
|
|
3381
|
+
// answers) lands after that baseline — exactly what a loaded CI runner did
|
|
3382
|
+
// to this count.
|
|
3383
|
+
await new Promise((resolve) => setTimeout(resolve, 40));
|
|
3384
|
+
return okJson('{"login":"me"}');
|
|
3385
|
+
}
|
|
3386
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
3387
|
+
return okJson(JSON.stringify({ nameWithOwner: 'original/project' }));
|
|
3388
|
+
}
|
|
3389
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
3390
|
+
// The rail's own read answers last, so the frame below cannot be drawn
|
|
3391
|
+
// before the gate's second child has reached the runner.
|
|
3392
|
+
await new Promise((resolve) => setTimeout(resolve, 80));
|
|
3393
|
+
return okJson(JSON.stringify(relatedAnswer({
|
|
3394
|
+
assigned: [
|
|
3395
|
+
{ number: 11, title: 'Eleven', updatedAt: '2024-01-01T00:00:00Z' },
|
|
3396
|
+
{ number: 12, title: 'Twelve', updatedAt: '2024-02-01T00:00:00Z' },
|
|
3397
|
+
],
|
|
3398
|
+
})));
|
|
3399
|
+
}
|
|
3400
|
+
return okJson('');
|
|
3401
|
+
});
|
|
3402
|
+
|
|
3403
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
3404
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3405
|
+
assert.equal(registered.length, 1);
|
|
3406
|
+
const section = registered[0];
|
|
3407
|
+
|
|
3408
|
+
// The barrier the counting test uses: the gate's own coalesced question, asked
|
|
3409
|
+
// from here, so its children have landed before the baseline is taken.
|
|
3410
|
+
await awaitIssuesGateSettled(checkout);
|
|
3411
|
+
await settleStartup(calls);
|
|
3412
|
+
const baseline = calls.length;
|
|
3413
|
+
|
|
3414
|
+
const rows = await waitForRows(section, ctx);
|
|
3415
|
+
assert.deepEqual(rows.map((row) => row.label), ['#12 Twelve', '#11 Eleven']);
|
|
3416
|
+
assert.equal(calls.length - baseline, 1, 'the refresh spawns exactly ONE gh child');
|
|
3417
|
+
assert.equal(graphqlCalls(calls).length, 1, 'and that child is the ONE combined read');
|
|
3418
|
+
assert.equal(graphqlCalls(calls).length, calls.length - baseline,
|
|
3419
|
+
'so nothing the session gate dispatches is counted as the rail\'s read');
|
|
3420
|
+
} finally {
|
|
3421
|
+
Date.now = realNow;
|
|
3422
|
+
}
|
|
3423
|
+
});
|
|
3424
|
+
|
|
3425
|
+
test('S9 (T14): an issue that left the assigned set makes the next refresh a full read', async () => {
|
|
3426
|
+
const realNow = Date.now;
|
|
3427
|
+
let offset = 0;
|
|
3428
|
+
Date.now = () => realNow() + offset;
|
|
3429
|
+
try {
|
|
3430
|
+
const checkout = makeCheckout();
|
|
3431
|
+
const { registered } = installBridge();
|
|
3432
|
+
const loaded = await loadExtension({});
|
|
3433
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3434
|
+
const calls = [];
|
|
3435
|
+
const answers = [
|
|
3436
|
+
relatedAnswer({
|
|
3437
|
+
assigned: [
|
|
3438
|
+
{ number: 11, title: 'Eleven', updatedAt: '2024-01-01T00:00:00Z' },
|
|
3439
|
+
{ number: 12, title: 'Twelve', updatedAt: '2024-02-01T00:00:00Z' },
|
|
3440
|
+
],
|
|
3441
|
+
}),
|
|
3442
|
+
// Issue 11 was closed: the delta (the newest rows) cannot see it, so the
|
|
3443
|
+
// cached two rows no longer match the reported one.
|
|
3444
|
+
relatedAnswer({
|
|
3445
|
+
assigned: [{ number: 12, title: 'Twelve', updatedAt: '2024-03-01T00:00:00Z' }],
|
|
3446
|
+
counts: { assigned: 1 },
|
|
3447
|
+
}),
|
|
3448
|
+
// The next plan is a full read, which replaces the bucket.
|
|
3449
|
+
relatedAnswer({
|
|
3450
|
+
assigned: [{ number: 12, title: 'Twelve', updatedAt: '2024-03-01T00:00:00Z' }],
|
|
3451
|
+
counts: { assigned: 1 },
|
|
3452
|
+
}),
|
|
3453
|
+
];
|
|
3454
|
+
ghIssues.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
3455
|
+
calls.push({ argv: argv.slice(), env: { ...(runOpts.env || {}) }, cwd: runOpts && runOpts.cwd });
|
|
3456
|
+
if (argv[0] === 'api' && argv[1] === 'user') return okJson('{"login":"me"}');
|
|
3457
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
3458
|
+
return okJson(JSON.stringify({ nameWithOwner: 'myfork/project' }));
|
|
3459
|
+
}
|
|
3460
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
3461
|
+
return okJson(JSON.stringify(answers.shift()));
|
|
3462
|
+
}
|
|
3463
|
+
return okJson('');
|
|
3464
|
+
});
|
|
3465
|
+
|
|
3466
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
3467
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3468
|
+
const section = registered[0];
|
|
3469
|
+
const firstRows = await waitForRows(section, ctx);
|
|
3470
|
+
assert.deepEqual(firstRows.map((row) => row.label), ['#12 Twelve', '#11 Eleven']);
|
|
3471
|
+
|
|
3472
|
+
offset = 61000;
|
|
3473
|
+
section.lines(ctx);
|
|
3474
|
+
await waitFor(() => graphqlCalls(calls).length === 2, 'the delta refresh never ran');
|
|
3475
|
+
let query = graphqlQueryOf(graphqlCalls(calls)[1]);
|
|
3476
|
+
assert.equal((query.match(/first: 20/g) || []).length, 3, 'the mismatch-causing read is a delta');
|
|
3477
|
+
assert.deepEqual(section.lines(ctx).map((row) => row.label), ['#12 Twelve', '#11 Eleven'],
|
|
3478
|
+
'the merge cannot remove a row it did not see');
|
|
3479
|
+
|
|
3480
|
+
offset = 122000;
|
|
3481
|
+
section.lines(ctx);
|
|
3482
|
+
await waitFor(() => graphqlCalls(calls).length === 3, 'the repair refresh never ran');
|
|
3483
|
+
query = graphqlQueryOf(graphqlCalls(calls)[2]);
|
|
3484
|
+
assert.equal((query.match(/first: 100/g) || []).length, 3,
|
|
3485
|
+
'the count mismatch made the NEXT plan a full read');
|
|
3486
|
+
await waitFor(
|
|
3487
|
+
() => section.lines(ctx).map((row) => row.label).join('|') === '#12 Twelve',
|
|
3488
|
+
'the full read never replaced the bucket',
|
|
3489
|
+
);
|
|
3490
|
+
assert.equal(section.meta(ctx), '1 issues');
|
|
3491
|
+
} finally {
|
|
3492
|
+
Date.now = realNow;
|
|
3493
|
+
}
|
|
3494
|
+
});
|
|
3495
|
+
|
|
3496
|
+
test('S9 (T14): a failed read keeps the cache and the section stale, so the next read is incremental', async () => {
|
|
3497
|
+
const realNow = Date.now;
|
|
3498
|
+
let offset = 0;
|
|
3499
|
+
Date.now = () => realNow() + offset;
|
|
3500
|
+
try {
|
|
3501
|
+
const checkout = makeCheckout();
|
|
3502
|
+
const { registered } = installBridge();
|
|
3503
|
+
const loaded = await loadExtension({});
|
|
3504
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3505
|
+
const calls = [];
|
|
3506
|
+
const answers = [
|
|
3507
|
+
relatedAnswer({
|
|
3508
|
+
assigned: [
|
|
3509
|
+
{ number: 11, title: 'Eleven', updatedAt: '2024-01-01T00:00:00Z' },
|
|
3510
|
+
{ number: 12, title: 'Twelve', updatedAt: '2024-02-01T00:00:00Z' },
|
|
3511
|
+
],
|
|
3512
|
+
}),
|
|
3513
|
+
null, // the stalled read
|
|
3514
|
+
relatedAnswer({
|
|
3515
|
+
assigned: [
|
|
3516
|
+
{ number: 12, title: 'Twelve (updated)', updatedAt: '2024-03-01T00:00:00Z' },
|
|
3517
|
+
{ number: 13, title: 'Thirteen', updatedAt: '2024-04-01T00:00:00Z' },
|
|
3518
|
+
],
|
|
3519
|
+
counts: { assigned: 3 },
|
|
3520
|
+
}),
|
|
3521
|
+
];
|
|
3522
|
+
ghIssues.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
3523
|
+
calls.push({ argv: argv.slice(), env: { ...(runOpts.env || {}) }, cwd: runOpts && runOpts.cwd });
|
|
3524
|
+
if (argv[0] === 'api' && argv[1] === 'user') return okJson('{"login":"me"}');
|
|
3525
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
3526
|
+
return okJson(JSON.stringify({ nameWithOwner: 'myfork/project' }));
|
|
3527
|
+
}
|
|
3528
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
3529
|
+
const answer = answers.shift();
|
|
3530
|
+
if (answer === null) return { status: 1, stdout: '', stderr: 'HTTP 502: bad gateway', error: null };
|
|
3531
|
+
return okJson(JSON.stringify(answer));
|
|
3532
|
+
}
|
|
3533
|
+
return okJson('');
|
|
3534
|
+
});
|
|
3535
|
+
|
|
3536
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
3537
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3538
|
+
const section = registered[0];
|
|
3539
|
+
await waitForRows(section, ctx);
|
|
3540
|
+
assert.equal(section.meta(ctx), '2 issues');
|
|
3541
|
+
|
|
3542
|
+
offset = 61000;
|
|
3543
|
+
section.lines(ctx);
|
|
3544
|
+
await waitFor(() => graphqlCalls(calls).length === 2, 'the failing refresh never ran');
|
|
3545
|
+
await waitFor(() => String(section.meta(ctx)).includes('· stale'), 'the failure never reported stale');
|
|
3546
|
+
assert.deepEqual(section.lines(ctx).map((row) => row.label), ['#12 Twelve', '#11 Eleven'],
|
|
3547
|
+
'a failed read never erases the rows already on screen');
|
|
3548
|
+
|
|
3549
|
+
// The cache's last SUCCESSFUL apply was two minutes ago, well inside the
|
|
3550
|
+
// ten-minute full-read window, so the recovery read is the newest 20 — the
|
|
3551
|
+
// failed read did not clear or invalidate the entry.
|
|
3552
|
+
offset = 122000;
|
|
3553
|
+
section.lines(ctx);
|
|
3554
|
+
await waitFor(() => graphqlCalls(calls).length === 3, 'the recovery refresh never ran');
|
|
3555
|
+
const query = graphqlQueryOf(graphqlCalls(calls)[2]);
|
|
3556
|
+
assert.equal((query.match(/first: 20/g) || []).length, 3,
|
|
3557
|
+
'a failed read leaves the cache intact, so the recovery stays incremental');
|
|
3558
|
+
await waitFor(
|
|
3559
|
+
() => section.lines(ctx).some((row) => row.label === '#13 Thirteen'),
|
|
3560
|
+
'the recovery read never merged',
|
|
3561
|
+
);
|
|
3562
|
+
assert.deepEqual(section.lines(ctx).map((row) => row.label),
|
|
3563
|
+
['#13 Thirteen', '#12 Twelve (updated)', '#11 Eleven']);
|
|
3564
|
+
} finally {
|
|
3565
|
+
Date.now = realNow;
|
|
3566
|
+
}
|
|
3567
|
+
});
|
|
3568
|
+
|
|
3569
|
+
// S4 (issues-startup-performance T3, L7): a session boundary is NOT a cache
|
|
3570
|
+
// boundary. `session_shutdown` still drops the section's snapshot (no frame drawn
|
|
3571
|
+
// afterwards shows the ended session's rows) and still advances the cache
|
|
3572
|
+
// generation (an answer the ended session is holding lands nowhere) — but the
|
|
3573
|
+
// ENTRIES stay, so the next session's first read is a delta instead of a full
|
|
3574
|
+
// re-read. Before T3 the shutdown cleared them and this test asserted a full read.
|
|
3575
|
+
test('S4 (T3): the cache survives a session_shutdown/start pair, so the next read is a delta', async () => {
|
|
3576
|
+
const checkout = makeCheckout();
|
|
3577
|
+
const { registered } = installBridge();
|
|
3578
|
+
const loaded = await loadExtension({});
|
|
3579
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3580
|
+
const calls = [];
|
|
3581
|
+
const answers = [
|
|
3582
|
+
relatedAnswer({
|
|
3583
|
+
assigned: [{ number: 11, title: 'Eleven', updatedAt: '2024-01-01T00:00:00Z' }],
|
|
3584
|
+
}),
|
|
3585
|
+
relatedAnswer({
|
|
3586
|
+
assigned: [{ number: 11, title: 'Eleven', updatedAt: '2024-01-01T00:00:00Z' }],
|
|
3587
|
+
}),
|
|
3588
|
+
];
|
|
3589
|
+
ghIssues.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
3590
|
+
calls.push({ argv: argv.slice(), env: { ...(runOpts.env || {}) }, cwd: runOpts && runOpts.cwd });
|
|
3591
|
+
if (argv[0] === 'api' && argv[1] === 'user') return okJson('{"login":"me"}');
|
|
3592
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
3593
|
+
return okJson(JSON.stringify({ nameWithOwner: 'myfork/project' }));
|
|
3594
|
+
}
|
|
3595
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
3596
|
+
return okJson(JSON.stringify(answers.shift()));
|
|
3597
|
+
}
|
|
3598
|
+
return okJson('');
|
|
3599
|
+
});
|
|
3600
|
+
|
|
3601
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
3602
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3603
|
+
const section = registered[0];
|
|
3604
|
+
await waitForRows(section, ctx);
|
|
3605
|
+
assert.equal((graphqlQueryOf(graphqlCalls(calls)[0]).match(/first: 100/g) || []).length, 3,
|
|
3606
|
+
'the first read of a cold cache is the full one');
|
|
3607
|
+
|
|
3608
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
3609
|
+
assert.equal(section.meta(ctx), undefined,
|
|
3610
|
+
'the snapshot is still dropped: no frame drawn afterwards shows the ended rows');
|
|
3611
|
+
|
|
3612
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3613
|
+
// T18 (S11): the shutdown disposed the ended section, so the new session's
|
|
3614
|
+
// boundary binds the rail again; its fresh section is the one that reads.
|
|
3615
|
+
const resumed = registered[registered.length - 1];
|
|
3616
|
+
assert.notEqual(resumed, section, 'the new session binds the rail again');
|
|
3617
|
+
resumed.lines(ctx);
|
|
3618
|
+
await waitFor(() => graphqlCalls(calls).length === 2, 'the new session never read its issues');
|
|
3619
|
+
const query = graphqlQueryOf(graphqlCalls(calls)[1]);
|
|
3620
|
+
assert.equal((query.match(/first: 20/g) || []).length, 3,
|
|
3621
|
+
'the surviving entry answers a delta plan, so the new session asks only for the newest rows');
|
|
3622
|
+
});
|
|
3623
|
+
|
|
3624
|
+
// ---------------------------------------------------------------------------
|
|
3625
|
+
// T15 (S3, S6, S9; verify round 3): the deferred refresh and the cache that
|
|
3626
|
+
// feeds it are now held to the same latest-wins discipline the snapshot already
|
|
3627
|
+
// had. One RED test per reproduced defect, through the public surface only.
|
|
3628
|
+
// ---------------------------------------------------------------------------
|
|
3629
|
+
|
|
3630
|
+
test('S3 (T15): a failed refresh starts the activity floor, so the same instant starts nothing', async () => {
|
|
3631
|
+
const realNow = Date.now;
|
|
3632
|
+
let offset = 0;
|
|
3633
|
+
Date.now = () => realNow() + offset;
|
|
3634
|
+
try {
|
|
3635
|
+
const checkout = makeCheckout();
|
|
3636
|
+
const { registered } = installBridge();
|
|
3637
|
+
const loaded = await loadExtension({});
|
|
3638
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3639
|
+
const calls = [];
|
|
3640
|
+
let fail = false;
|
|
3641
|
+
ghIssues.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
3642
|
+
calls.push({ argv: argv.slice(), env: { ...(runOpts.env || {}) }, cwd: runOpts && runOpts.cwd });
|
|
3643
|
+
if (argv[0] === 'api' && argv[1] === 'user') return okJson('{"login":"me"}');
|
|
3644
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
3645
|
+
return okJson(JSON.stringify({ nameWithOwner: 'myfork/project' }));
|
|
3646
|
+
}
|
|
3647
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
3648
|
+
if (fail) return { status: 1, stdout: '', stderr: 'HTTP 502: bad gateway', error: null };
|
|
3649
|
+
return okJson(JSON.stringify(relatedAnswer({
|
|
3650
|
+
assigned: [{ number: 11, title: 'Eleven', updatedAt: '2024-01-01T00:00:00Z' }],
|
|
3651
|
+
})));
|
|
3652
|
+
}
|
|
3653
|
+
return okJson('');
|
|
3654
|
+
});
|
|
3655
|
+
|
|
3656
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
3657
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3658
|
+
const section = registered[0];
|
|
3659
|
+
await waitForRows(section, ctx);
|
|
3660
|
+
assert.equal(graphqlCalls(calls).length, 1, 'the drawn frame made its one read');
|
|
3661
|
+
|
|
3662
|
+
// 30 s after that success the floor allows the activity refresh, and THIS
|
|
3663
|
+
// attempt fails.
|
|
3664
|
+
fail = true;
|
|
3665
|
+
offset = 30000;
|
|
3666
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
3667
|
+
await waitFor(() => graphqlCalls(calls).length === 2, 'the failing activity refresh never ran');
|
|
3668
|
+
await waitFor(() => String(section.meta(ctx)).includes('· stale'), 'the failure never reported stale');
|
|
3669
|
+
|
|
3670
|
+
// The failed ATTEMPT is what starts the floor: at this same instant nothing
|
|
3671
|
+
// may start another read.
|
|
3672
|
+
const before = graphqlCalls(calls).length;
|
|
3673
|
+
await fireHook(loaded.hooks, 'turn_end', ctx);
|
|
3674
|
+
await fireHook(loaded.hooks, 'before_agent_start', ctx);
|
|
3675
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
3676
|
+
assert.equal(graphqlCalls(calls).length, before,
|
|
3677
|
+
'a failed attempt starts the floor, so no activity retries the same instant');
|
|
3678
|
+
} finally {
|
|
3679
|
+
Date.now = realNow;
|
|
3680
|
+
}
|
|
3681
|
+
});
|
|
3682
|
+
|
|
3683
|
+
test('S3 (T15): after a failed refresh the frame TTL is measured from the attempt, not the last success', async () => {
|
|
3684
|
+
const realNow = Date.now;
|
|
3685
|
+
let offset = 0;
|
|
3686
|
+
Date.now = () => realNow() + offset;
|
|
3687
|
+
try {
|
|
3688
|
+
const checkout = makeCheckout();
|
|
3689
|
+
const { registered } = installBridge();
|
|
3690
|
+
const loaded = await loadExtension({});
|
|
3691
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3692
|
+
const calls = [];
|
|
3693
|
+
let fail = false;
|
|
3694
|
+
ghIssues.setGhRunner(async (_bin, argv, runOpts = {}) => {
|
|
3695
|
+
calls.push({ argv: argv.slice(), env: { ...(runOpts.env || {}) }, cwd: runOpts && runOpts.cwd });
|
|
3696
|
+
if (argv[0] === 'api' && argv[1] === 'user') return okJson('{"login":"me"}');
|
|
3697
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
3698
|
+
return okJson(JSON.stringify({ nameWithOwner: 'myfork/project' }));
|
|
3699
|
+
}
|
|
3700
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
3701
|
+
if (fail) return { status: 1, stdout: '', stderr: 'HTTP 502: bad gateway', error: null };
|
|
3702
|
+
return okJson(JSON.stringify(relatedAnswer({
|
|
3703
|
+
assigned: [{ number: 11, title: 'Eleven', updatedAt: '2024-01-01T00:00:00Z' }],
|
|
3704
|
+
})));
|
|
3705
|
+
}
|
|
3706
|
+
return okJson('');
|
|
3707
|
+
});
|
|
3708
|
+
|
|
3709
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
3710
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3711
|
+
const section = registered[0];
|
|
3712
|
+
await waitForRows(section, ctx);
|
|
3713
|
+
assert.equal(graphqlCalls(calls).length, 1, 'the first read succeeded');
|
|
3714
|
+
|
|
3715
|
+
// One minute after the success the frame TTL starts a refresh that fails.
|
|
3716
|
+
fail = true;
|
|
3717
|
+
offset = 61000;
|
|
3718
|
+
section.lines(ctx);
|
|
3719
|
+
await waitFor(() => graphqlCalls(calls).length === 2, 'the failed TTL refresh never ran');
|
|
3720
|
+
await waitFor(() => String(section.meta(ctx)).includes('· stale'), 'the failure never reported stale');
|
|
3721
|
+
|
|
3722
|
+
// A frame at that same instant must not queue a retry: the TTL runs from the
|
|
3723
|
+
// failed attempt, not from the success that preceded it.
|
|
3724
|
+
const before = graphqlCalls(calls).length;
|
|
3725
|
+
section.lines(ctx);
|
|
3726
|
+
section.lines(ctx);
|
|
3727
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
3728
|
+
assert.equal(graphqlCalls(calls).length, before,
|
|
3729
|
+
'the frame TTL waits for the ten-minute-style window from the attempt, never a tight retry');
|
|
3730
|
+
} finally {
|
|
3731
|
+
Date.now = realNow;
|
|
3732
|
+
}
|
|
3733
|
+
});
|
|
3734
|
+
|
|
3735
|
+
test('S3 (T15): a refresh queued before invalidate() or dispose() never reads', async () => {
|
|
3736
|
+
let loads = 0;
|
|
3737
|
+
const sched = manualSchedule();
|
|
3738
|
+
const handle = createIssuesSection({
|
|
3739
|
+
load: async () => {
|
|
3740
|
+
loads += 1;
|
|
3741
|
+
return { ok: true, identity: IDENTITY, issues: [], truncated: false };
|
|
3742
|
+
},
|
|
3743
|
+
open: () => {},
|
|
3744
|
+
openAll: () => {},
|
|
3745
|
+
schedule: sched.schedule,
|
|
3746
|
+
});
|
|
3747
|
+
|
|
3748
|
+
// The drawn frame queues the section's own refresh on the injected scheduler.
|
|
3749
|
+
handle.section.lines({});
|
|
3750
|
+
assert.equal(sched.pending(), 1, 'the stale frame queued one refresh');
|
|
3751
|
+
handle.invalidate();
|
|
3752
|
+
await sched.flush();
|
|
3753
|
+
assert.equal(loads, 0, 'a callback queued before invalidate() started no read');
|
|
3754
|
+
|
|
3755
|
+
// The same holds for a callback queued before dispose().
|
|
3756
|
+
handle.section.lines({});
|
|
3757
|
+
assert.equal(sched.pending(), 1, 'the new frame queued its own refresh');
|
|
3758
|
+
handle.dispose();
|
|
3759
|
+
await sched.flush();
|
|
3760
|
+
assert.equal(loads, 0, 'a callback queued before dispose() started no read');
|
|
3761
|
+
});
|
|
3762
|
+
|
|
3763
|
+
test('S3 (T15): a refresh queued before session_shutdown reads nothing and repaints nothing', async () => {
|
|
3764
|
+
const checkout = makeCheckout();
|
|
3765
|
+
const { registered, repaints } = installBridge();
|
|
3766
|
+
const loaded = await loadExtension({});
|
|
3767
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3768
|
+
const gh = sectionGithub({
|
|
3769
|
+
issues: [{ number: 11, title: 'Eleven', state: 'OPEN', updatedAt: '2024-01-01T00:00:00Z' }],
|
|
3770
|
+
});
|
|
3771
|
+
ghIssues.setGhRunner(gh.runner);
|
|
3772
|
+
|
|
3773
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
3774
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3775
|
+
const section = registered[0];
|
|
3776
|
+
|
|
3777
|
+
// The frame queues its refresh on the host's macrotask scheduler; the session
|
|
3778
|
+
// ends synchronously, before that callback can run.
|
|
3779
|
+
section.lines(ctx);
|
|
3780
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
3781
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3782
|
+
|
|
3783
|
+
assert.equal(graphqlCalls(gh.calls).length, 0, 'the queued callback never starts a read');
|
|
3784
|
+
assert.deepEqual(repaints, [], 'and it never repaints a torn-down host');
|
|
3785
|
+
});
|
|
3786
|
+
|
|
3787
|
+
test('S9 (T15): a read in flight at session_shutdown never repopulates the cache', async () => {
|
|
3788
|
+
const checkout = makeCheckout();
|
|
3789
|
+
const { registered } = installBridge();
|
|
3790
|
+
const loaded = await loadExtension({});
|
|
3791
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3792
|
+
|
|
3793
|
+
// Every combined read is HELD, so the test decides when each one answers.
|
|
3794
|
+
const lists = [];
|
|
3795
|
+
ghIssues.setGhRunner((_bin, argv, runOpts = {}) => {
|
|
3796
|
+
const env = runOpts.env || {};
|
|
3797
|
+
if (argv[0] === 'api' && argv[1] === 'user') return Promise.resolve(okJson('{"login":"me"}'));
|
|
3798
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
3799
|
+
return Promise.resolve(okJson(JSON.stringify({ nameWithOwner: 'original/project' })));
|
|
3800
|
+
}
|
|
3801
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
3802
|
+
const entry = { repo: env.GH_REPO, query: graphqlQueryOf({ argv }), settle: null };
|
|
3803
|
+
entry.answer = new Promise((resolve) => {
|
|
3804
|
+
entry.settle = (payload) => resolve(okJson(JSON.stringify(payload)));
|
|
3805
|
+
});
|
|
3806
|
+
lists.push(entry);
|
|
3807
|
+
return entry.answer;
|
|
3808
|
+
}
|
|
3809
|
+
return Promise.resolve(okJson(''));
|
|
3810
|
+
});
|
|
3811
|
+
|
|
3812
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
3813
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3814
|
+
const section = registered[0];
|
|
3815
|
+
section.lines(ctx);
|
|
3816
|
+
await waitFor(() => lists.length === 1, 'the drawn section never read its issues');
|
|
3817
|
+
|
|
3818
|
+
// The session ends while its read is still in flight.
|
|
3819
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
3820
|
+
|
|
3821
|
+
// The read that outlived the session answers NOW: it must not write the cache
|
|
3822
|
+
// shutdown just cleared.
|
|
3823
|
+
lists[0].settle(relatedAnswer({
|
|
3824
|
+
assigned: [{ number: 11, title: 'Gone eleven', updatedAt: '2024-01-01T00:00:00Z' }],
|
|
3825
|
+
}));
|
|
3826
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
3827
|
+
|
|
3828
|
+
// A new session on the same checkout draws: an emptied cache means its first
|
|
3829
|
+
// read is the full one. T18 (S11): shutdown disposed the previous section, so
|
|
3830
|
+
// the new session's boundary binds a fresh one; that is the section it draws.
|
|
3831
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3832
|
+
const resumed = registered[registered.length - 1];
|
|
3833
|
+
assert.notEqual(resumed, section, 'the new session binds the rail again');
|
|
3834
|
+
resumed.lines(ctx);
|
|
3835
|
+
await waitFor(() => lists.length === 2, 'the new session never read its issues');
|
|
3836
|
+
assert.equal((lists[1].query.match(/first: 100/g) || []).length, 3,
|
|
3837
|
+
'the shut-down read never repopulated the cache, so the next refresh is a full read');
|
|
3838
|
+
|
|
3839
|
+
lists[1].settle(relatedAnswer({
|
|
3840
|
+
assigned: [{ number: 22, title: 'New twenty-two', updatedAt: '2024-02-01T00:00:00Z' }],
|
|
3841
|
+
}));
|
|
3842
|
+
await waitFor(
|
|
3843
|
+
() => resumed.lines(ctx).some((row) => row.label === '#22 New twenty-two'),
|
|
3844
|
+
'the new session never painted its own rows',
|
|
3845
|
+
);
|
|
3846
|
+
assert.ok(!resumed.lines(ctx).some((row) => row.label === '#11 Gone eleven'),
|
|
3847
|
+
"the ended session's answer never became cached rows");
|
|
3848
|
+
});
|
|
3849
|
+
|
|
3850
|
+
test('S6/S9 (T16): a checkout switch cuts the previous read out of the cache', async () => {
|
|
3851
|
+
// Two checkouts of the SAME repository: the identity keys the cache, so this is
|
|
3852
|
+
// the case where a stale answer can seed the repository the session moved to.
|
|
3853
|
+
const firstCheckout = makeCheckout();
|
|
3854
|
+
const secondCheckout = makeCheckout();
|
|
3855
|
+
const { registered } = installBridge();
|
|
3856
|
+
const loaded = await loadExtension({});
|
|
3857
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3858
|
+
|
|
3859
|
+
const lists = [];
|
|
3860
|
+
ghIssues.setGhRunner((_bin, argv, runOpts = {}) => {
|
|
3861
|
+
const env = runOpts.env || {};
|
|
3862
|
+
if (argv[0] === 'api' && argv[1] === 'user') return Promise.resolve(okJson('{"login":"me"}'));
|
|
3863
|
+
if (argv[0] === 'repo' && argv[1] === 'view') {
|
|
3864
|
+
return Promise.resolve(okJson(JSON.stringify({ nameWithOwner: 'original/project' })));
|
|
3865
|
+
}
|
|
3866
|
+
if (argv[0] === 'api' && argv[1] === 'graphql') {
|
|
3867
|
+
const entry = { repo: env.GH_REPO, query: graphqlQueryOf({ argv }), settle: null };
|
|
3868
|
+
entry.answer = new Promise((resolve) => {
|
|
3869
|
+
entry.settle = (payload) => resolve(okJson(JSON.stringify(payload)));
|
|
3870
|
+
});
|
|
3871
|
+
lists.push(entry);
|
|
3872
|
+
return entry.answer;
|
|
3873
|
+
}
|
|
3874
|
+
return Promise.resolve(okJson(''));
|
|
3875
|
+
});
|
|
3876
|
+
|
|
3877
|
+
const ctxA = { cwd: firstCheckout, ui: { notify: () => {} } };
|
|
3878
|
+
await fireSessionStart(loaded.hooks, ctxA);
|
|
3879
|
+
const section = registered[0];
|
|
3880
|
+
section.lines(ctxA);
|
|
3881
|
+
await waitFor(() => lists.length === 1, 'the drawn section never read its issues');
|
|
3882
|
+
|
|
3883
|
+
// The session moves to another checkout of the same repository while A's read
|
|
3884
|
+
// is still in flight.
|
|
3885
|
+
const ctxB = { cwd: secondCheckout, ui: { notify: () => {} } };
|
|
3886
|
+
await fireSessionStart(loaded.hooks, ctxB);
|
|
3887
|
+
|
|
3888
|
+
// A's answer lands after the move: the section discarded it, so the cache must
|
|
3889
|
+
// not adopt it either.
|
|
3890
|
+
lists[0].settle(relatedAnswer({
|
|
3891
|
+
assigned: [{ number: 11, title: 'Left behind', updatedAt: '2024-01-01T00:00:00Z' }],
|
|
3892
|
+
}));
|
|
3893
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
3894
|
+
|
|
3895
|
+
section.lines(ctxB);
|
|
3896
|
+
await waitFor(() => lists.length === 2, 'the moved session never read its issues');
|
|
3897
|
+
assert.equal((lists[1].query.match(/first: 100/g) || []).length, 3,
|
|
3898
|
+
"the abandoned checkout's answer never seeded the cache, so the moved session starts with a full read");
|
|
3899
|
+
|
|
3900
|
+
lists[1].settle(relatedAnswer({
|
|
3901
|
+
assigned: [{ number: 22, title: 'Fresh twenty-two', updatedAt: '2024-02-01T00:00:00Z' }],
|
|
3902
|
+
}));
|
|
3903
|
+
await waitFor(
|
|
3904
|
+
() => section.lines(ctxB).some((row) => row.label === '#22 Fresh twenty-two'),
|
|
3905
|
+
'the moved session never painted its own rows',
|
|
3906
|
+
);
|
|
3907
|
+
assert.ok(!section.lines(ctxB).some((row) => row.label === '#11 Left behind'),
|
|
3908
|
+
"the previous checkout's rows never survive the move");
|
|
3909
|
+
assert.match(section.meta(ctxB), /^1 issues$/, 'the header counts only the moved session rows');
|
|
3910
|
+
});
|
|
3911
|
+
|
|
3912
|
+
// T10 (S9): the pre-dispatch proof E18 described is gone, so there is no window
|
|
3913
|
+
// in which a proof can outlive its session. The click is synchronous: it answers
|
|
3914
|
+
// before any session boundary can move, and the number alone travels — the panel
|
|
3915
|
+
// is the one surface that pins and proves the repository it opens. This states
|
|
3916
|
+
// the removal, so a proof creeping back onto the click path fails here.
|
|
3917
|
+
test('S9 (T10): the click path holds no proof a session move could outlive', async () => {
|
|
3918
|
+
const checkoutA = makeCheckout([['origin', 'git@github.com:myfork/project.git']]);
|
|
3919
|
+
const checkoutB = makeCheckout([['origin', 'git@github.com:myfork/project.git']]);
|
|
3920
|
+
const sent = [];
|
|
3921
|
+
const dispatch = { sendUserMessage: (text, opts) => { sent.push({ text, opts }); } };
|
|
3922
|
+
const { mod, hooks } = await loadSeam(dispatch);
|
|
3923
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3924
|
+
ghIssues.setGhRunner(sectionGithub({ repoView: 'myfork/project' }).runner);
|
|
3925
|
+
await fireSessionStart(hooks, { cwd: checkoutA, ui: { notify: () => {} } });
|
|
3926
|
+
|
|
3927
|
+
const worktreeGit = require(path.join(LIB_DIR, 'worktree-git.js'));
|
|
3928
|
+
const original = worktreeGit.runArgvAsync;
|
|
3929
|
+
const held = [];
|
|
3930
|
+
worktreeGit.runArgvAsync = async (bin, argv, opts) => {
|
|
3931
|
+
if (bin === 'git' && argv[0] === 'rev-parse' && argv[1] === '--show-toplevel') {
|
|
3932
|
+
held.push({ bin, argv: argv.slice() });
|
|
3933
|
+
}
|
|
3934
|
+
return original(bin, argv, opts);
|
|
3935
|
+
};
|
|
3936
|
+
try {
|
|
3937
|
+
// The click answers BEFORE the session moves, and it proves nothing: no
|
|
3938
|
+
// checkout probe runs on the click path at all.
|
|
3939
|
+
const outcome = mod.dispatchIssuesPanel(dispatch, 11, 'github.com/myfork/project');
|
|
3940
|
+
assert.deepEqual(outcome, { ok: true });
|
|
3941
|
+
assert.deepEqual(sent, [{ text: '/issues 11', opts: { expandPromptTemplates: true } }],
|
|
3942
|
+
'the click dispatched its issue');
|
|
3943
|
+
assert.deepEqual(held, [], 'no checkout proof ran on the click path');
|
|
3944
|
+
// The session then moves. Its own startup work may well read the checkout —
|
|
3945
|
+
// that is the session's start, not the click — and the dispatch is untouched:
|
|
3946
|
+
// nothing re-sends it and nothing drops it.
|
|
3947
|
+
await fireSessionStart(hooks, { cwd: checkoutB, ui: { notify: () => {} } });
|
|
3948
|
+
assert.equal(sent.length, 1, 'a later session move never re-dispatches or drops it');
|
|
3949
|
+
} finally {
|
|
3950
|
+
worktreeGit.runArgvAsync = original;
|
|
3951
|
+
}
|
|
3952
|
+
});
|
|
3953
|
+
|
|
3954
|
+
// ---------------------------------------------------------------------------
|
|
3955
|
+
// T2 (S3) and T3 (S4): what a session costs outside a repository, and how long
|
|
3956
|
+
// the read cache lives.
|
|
3957
|
+
// ---------------------------------------------------------------------------
|
|
3958
|
+
|
|
3959
|
+
// S3 (T2): a cwd outside a repository is stated, not probed. The rail's own read
|
|
3960
|
+
// already answers the short dim line without a `gh` child; the session gate used
|
|
3961
|
+
// to probe `gh` there anyway (two children per session start), which is exactly
|
|
3962
|
+
// the "no frequent checks" the user asked to stop.
|
|
3963
|
+
test('S3 (T2): a session outside a repository paints the dim row and spawns no gh child', async () => {
|
|
3964
|
+
const outside = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-outside-')));
|
|
3965
|
+
const { registered } = installBridge();
|
|
3966
|
+
const loaded = await loadExtension({});
|
|
3967
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
3968
|
+
const gh = sectionGithub();
|
|
3969
|
+
ghIssues.setGhRunner(gh.runner);
|
|
3970
|
+
|
|
3971
|
+
const ctx = { cwd: outside, ui: { notify: () => {} } };
|
|
3972
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
3973
|
+
const rows = await waitForRows(registered[0], ctx);
|
|
3974
|
+
assert.deepEqual(rows, [{ label: 'not a git repository', tone: 'dim' }],
|
|
3975
|
+
'one dim row, never the error tone');
|
|
3976
|
+
assert.equal(registered[0].meta(ctx), undefined, 'and no count');
|
|
3977
|
+
|
|
3978
|
+
// The session gate runs off the awaited startup path now, so it gets its own
|
|
3979
|
+
// window before "spawned nothing" is asserted.
|
|
3980
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
3981
|
+
assert.deepEqual(gh.calls, [],
|
|
3982
|
+
'no gh child and no network call at all: the checkout answers this, and the gate never asks gh either');
|
|
3983
|
+
});
|
|
3984
|
+
|
|
3985
|
+
// S4 (T3): the entries also outlive the PROCESS. A new load is a new in-process
|
|
3986
|
+
// cache, so the identity is hydrated from the disk half under
|
|
3987
|
+
// `$XDG_CACHE_HOME/odd-worktree/` before `plan`, and the first read is a delta.
|
|
3988
|
+
test('S4 (T3): a warm identity survives a process restart, so its first read is a delta', async () => {
|
|
3989
|
+
const cacheHome = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-warm-home-')));
|
|
3990
|
+
const savedCacheHome = process.env.XDG_CACHE_HOME;
|
|
3991
|
+
process.env.XDG_CACHE_HOME = cacheHome;
|
|
3992
|
+
try {
|
|
3993
|
+
const checkout = makeCheckout();
|
|
3994
|
+
const row = { number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' };
|
|
3995
|
+
|
|
3996
|
+
// One process: load the extension, draw the rail, shut the session down.
|
|
3997
|
+
const runProcess = async () => {
|
|
3998
|
+
const { registered } = installBridge();
|
|
3999
|
+
const loaded = await loadExtension({});
|
|
4000
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
4001
|
+
const gh = sectionGithub({ issues: [row] });
|
|
4002
|
+
ghIssues.setGhRunner(gh.runner);
|
|
4003
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
4004
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
4005
|
+
await waitForRows(registered[0], ctx);
|
|
4006
|
+
// S4 (T3 correction): the write is fired, never awaited by the read, so the
|
|
4007
|
+
// test waits for the document it produces — the one observable the next
|
|
4008
|
+
// process reads.
|
|
4009
|
+
await waitFor(
|
|
4010
|
+
() => fs.existsSync(path.join(cacheHome, 'odd-worktree', 'issues-cache.json')),
|
|
4011
|
+
'the disk half never wrote its document',
|
|
4012
|
+
);
|
|
4013
|
+
await fireHook(loaded.hooks, 'session_shutdown', ctx);
|
|
4014
|
+
return graphqlCalls(gh.calls);
|
|
4015
|
+
};
|
|
4016
|
+
|
|
4017
|
+
const firstReads = await runProcess();
|
|
4018
|
+
assert.equal(firstReads.length, 1);
|
|
4019
|
+
assert.ok(graphqlQueryOf(firstReads[0]).includes('first: 100'), 'a cold process reads everything');
|
|
4020
|
+
|
|
4021
|
+
const secondReads = await runProcess();
|
|
4022
|
+
assert.equal(secondReads.length, 1);
|
|
4023
|
+
assert.ok(graphqlQueryOf(secondReads[0]).includes('first: 20'),
|
|
4024
|
+
'the restarted process hydrates the identity from disk before `plan`, so it only asks for the delta');
|
|
4025
|
+
} finally {
|
|
4026
|
+
if (savedCacheHome === undefined) delete process.env.XDG_CACHE_HOME;
|
|
4027
|
+
else process.env.XDG_CACHE_HOME = savedCacheHome;
|
|
4028
|
+
}
|
|
4029
|
+
});
|
|
4030
|
+
|
|
4031
|
+
// S4 (T3): persistence never defeats the correctness rules the in-memory cache
|
|
4032
|
+
// already enforces. An entry that is `inconsistent` (its rows no longer match the
|
|
4033
|
+
// count the response reported) or older than the full-read TTL is NOT hydrated,
|
|
4034
|
+
// so `plan` still answers the full read it always did.
|
|
4035
|
+
test('S4 (T3): a stored entry past its full TTL, or inconsistent, is still read whole', async () => {
|
|
4036
|
+
const cacheHome = track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-issues-stale-home-')));
|
|
4037
|
+
const savedCacheHome = process.env.XDG_CACHE_HOME;
|
|
4038
|
+
process.env.XDG_CACHE_HOME = cacheHome;
|
|
4039
|
+
try {
|
|
4040
|
+
const checkout = makeCheckout();
|
|
4041
|
+
const row = { number: 11, title: 'Assigned one', state: 'OPEN', updatedAt: '2024-05-01T00:00:00Z' };
|
|
4042
|
+
const { createIssuesCacheStore } = require('../lib/issues-cache-store.js');
|
|
4043
|
+
const seeded = createIssuesCacheStore({ dir: path.join(cacheHome, 'odd-worktree') });
|
|
4044
|
+
const seed = (overrides) => seeded.save(IDENTITY, {
|
|
4045
|
+
buckets: { mine: [], assigned: [row], involved: [] },
|
|
4046
|
+
counts: { mine: 0, assigned: 1, involved: 0 },
|
|
4047
|
+
truncated: { mine: false, assigned: false, involved: false },
|
|
4048
|
+
inconsistent: false,
|
|
4049
|
+
full: true,
|
|
4050
|
+
syncedAt: Date.now(),
|
|
4051
|
+
lastApplied: 1,
|
|
4052
|
+
...overrides,
|
|
4053
|
+
});
|
|
4054
|
+
|
|
4055
|
+
const readQuery = async () => {
|
|
4056
|
+
const { registered } = installBridge();
|
|
4057
|
+
const loaded = await loadExtension({});
|
|
4058
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
4059
|
+
const gh = sectionGithub({ issues: [row] });
|
|
4060
|
+
ghIssues.setGhRunner(gh.runner);
|
|
4061
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
4062
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
4063
|
+
await waitForRows(registered[0], ctx);
|
|
4064
|
+
return graphqlQueryOf(graphqlCalls(gh.calls)[0]);
|
|
4065
|
+
};
|
|
4066
|
+
|
|
4067
|
+
await seed({ syncedAt: Date.now() - 3600000 });
|
|
4068
|
+
assert.ok((await readQuery()).includes('first: 100'),
|
|
4069
|
+
'an entry older than the full-read TTL is re-read whole, exactly like the in-memory cache plans it');
|
|
4070
|
+
|
|
4071
|
+
await seed({ inconsistent: true });
|
|
4072
|
+
assert.ok((await readQuery()).includes('first: 100'),
|
|
4073
|
+
'an inconsistent entry is never trusted for a total either');
|
|
4074
|
+
} finally {
|
|
4075
|
+
if (savedCacheHome === undefined) delete process.env.XDG_CACHE_HOME;
|
|
4076
|
+
else process.env.XDG_CACHE_HOME = savedCacheHome;
|
|
4077
|
+
}
|
|
4078
|
+
});
|
|
4079
|
+
|
|
4080
|
+
// S4 (T3, correction): the disk half is FIRE AND FORGET. The read has already
|
|
4081
|
+
// answered — `apply` made it visible in memory — so waiting for a file write puts
|
|
4082
|
+
// the filesystem back on the rail's path: the section's own `running` gate refuses
|
|
4083
|
+
// to schedule while a read is in flight, so one slow or stalled write postpones
|
|
4084
|
+
// every later read and the rail paints late. The two tests below hold the write
|
|
4085
|
+
// and watch what the rail does while it never settles.
|
|
4086
|
+
test('S4 (T3): a held save defers no read, and the newest entry waits behind it instead of interleaving', async () => {
|
|
4087
|
+
const realNow = Date.now;
|
|
4088
|
+
let offset = 0;
|
|
4089
|
+
Date.now = () => realNow() + offset;
|
|
4090
|
+
const checkout = makeCheckout();
|
|
4091
|
+
const { registered } = installBridge();
|
|
4092
|
+
const loaded = await loadExtension({});
|
|
4093
|
+
// The extension's OWN disk half, held: nothing is written until the test says so.
|
|
4094
|
+
// The module instance is required AFTER the load (the load purges the lib cache
|
|
4095
|
+
// once), so this is the very object the extension's `libRequire` gets.
|
|
4096
|
+
const store = require(path.join(LIB_DIR, 'issues-cache-store.js'));
|
|
4097
|
+
const originalFactory = store.createIssuesCacheStore;
|
|
4098
|
+
const saves = [];
|
|
4099
|
+
const held = [];
|
|
4100
|
+
store.createIssuesCacheStore = () => ({
|
|
4101
|
+
load: async () => null,
|
|
4102
|
+
directory: () => null,
|
|
4103
|
+
save: (identity, snapshot) => {
|
|
4104
|
+
saves.push({ identity, snapshot });
|
|
4105
|
+
return new Promise((resolve) => { held.push(resolve); });
|
|
4106
|
+
},
|
|
4107
|
+
});
|
|
4108
|
+
try {
|
|
4109
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
4110
|
+
const gh = sectionGithub({
|
|
4111
|
+
issues: [
|
|
4112
|
+
{ number: 11, title: 'Eleven', state: 'OPEN', updatedAt: '2024-01-01T00:00:00Z' },
|
|
4113
|
+
{ number: 12, title: 'Twelve', state: 'OPEN', updatedAt: '2024-02-01T00:00:00Z' },
|
|
4114
|
+
],
|
|
4115
|
+
});
|
|
4116
|
+
ghIssues.setGhRunner(gh.runner);
|
|
4117
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
4118
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
4119
|
+
const section = registered[0];
|
|
4120
|
+
|
|
4121
|
+
// 1) The first answer paints although its write has not settled: the read path
|
|
4122
|
+
// never waits for the disk.
|
|
4123
|
+
const rows = await waitForRows(section, ctx);
|
|
4124
|
+
assert.deepEqual(rows.map((row) => row.label), ['#12 Twelve', '#11 Eleven'],
|
|
4125
|
+
'the read settles and the rail paints while the disk half is still pending');
|
|
4126
|
+
assert.equal(saves.length, 1, 'the answer was still offered to the disk half');
|
|
4127
|
+
assert.equal(saves[0].identity, IDENTITY, 'for the identity the read was proven against');
|
|
4128
|
+
assert.equal(held.length, 1, 'and that one write is the one in flight');
|
|
4129
|
+
|
|
4130
|
+
// 2) A held write is not a running READ: the next stale frame starts its own
|
|
4131
|
+
// read on time instead of queueing behind the filesystem.
|
|
4132
|
+
offset = 61000;
|
|
4133
|
+
section.lines(ctx);
|
|
4134
|
+
await waitFor(() => graphqlCalls(gh.calls).length === 2,
|
|
4135
|
+
'a held save blocked the next read');
|
|
4136
|
+
assert.deepEqual(section.lines(ctx).map((row) => row.label), ['#12 Twelve', '#11 Eleven'],
|
|
4137
|
+
'and the rail keeps painting the rows the cache holds');
|
|
4138
|
+
assert.equal(saves.length, 1,
|
|
4139
|
+
'the second answer is COALESCED behind the write in flight — never a second interleaved save');
|
|
4140
|
+
|
|
4141
|
+
// 3) When the held write settles, the newest entry is the very next thing
|
|
4142
|
+
// written, so the stalled save cost the file nothing.
|
|
4143
|
+
held[0](true);
|
|
4144
|
+
await waitFor(() => saves.length === 2, 'the coalesced entry never followed the held one');
|
|
4145
|
+
assert.equal(saves[1].snapshot.lastApplied, 2, 'the write that follows carries the LATEST read');
|
|
4146
|
+
assert.equal(held.length, 2, 'exactly one write is in flight again — never two');
|
|
4147
|
+
|
|
4148
|
+
// 4) And a save that NEVER settles defers nothing either: the third stale frame
|
|
4149
|
+
// still reads, and the stalled write keeps the only in-flight slot.
|
|
4150
|
+
offset = 122000;
|
|
4151
|
+
section.lines(ctx);
|
|
4152
|
+
await waitFor(() => graphqlCalls(gh.calls).length === 3,
|
|
4153
|
+
'a save that never settles blocked a later read');
|
|
4154
|
+
assert.equal(saves.length, 2, 'a stalled write accumulates no second save');
|
|
4155
|
+
} finally {
|
|
4156
|
+
store.createIssuesCacheStore = originalFactory;
|
|
4157
|
+
Date.now = realNow;
|
|
4158
|
+
}
|
|
4159
|
+
});
|
|
4160
|
+
|
|
4161
|
+
test('S4 (T3): a save that REJECTS never escapes as an unhandled rejection and never blocks the rail', async () => {
|
|
4162
|
+
const checkout = makeCheckout();
|
|
4163
|
+
const { registered } = installBridge();
|
|
4164
|
+
const loaded = await loadExtension({});
|
|
4165
|
+
// The extension's OWN disk half, refusing every write.
|
|
4166
|
+
const store = require(path.join(LIB_DIR, 'issues-cache-store.js'));
|
|
4167
|
+
const originalFactory = store.createIssuesCacheStore;
|
|
4168
|
+
store.createIssuesCacheStore = () => ({
|
|
4169
|
+
load: async () => null,
|
|
4170
|
+
directory: () => null,
|
|
4171
|
+
save: async () => { throw new Error('EACCES: the cache directory is not writable'); },
|
|
4172
|
+
});
|
|
4173
|
+
const unhandled = [];
|
|
4174
|
+
const onUnhandled = (reason) => { unhandled.push(reason); };
|
|
4175
|
+
process.on('unhandledRejection', onUnhandled);
|
|
4176
|
+
try {
|
|
4177
|
+
ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
|
|
4178
|
+
const gh = sectionGithub({
|
|
4179
|
+
issues: [{ number: 11, title: 'Eleven', state: 'OPEN', updatedAt: '2024-01-01T00:00:00Z' }],
|
|
4180
|
+
});
|
|
4181
|
+
ghIssues.setGhRunner(gh.runner);
|
|
4182
|
+
const ctx = { cwd: checkout, ui: { notify: () => {} } };
|
|
4183
|
+
await fireSessionStart(loaded.hooks, ctx);
|
|
4184
|
+
const rows = await waitForRows(registered[0], ctx);
|
|
4185
|
+
assert.deepEqual(rows.map((row) => row.label), ['#11 Eleven'],
|
|
4186
|
+
'a write that cannot be committed costs the entry, never the read');
|
|
4187
|
+
// Two turns of the loop is enough for a rejected save to surface if it were
|
|
4188
|
+
// going to: it never does.
|
|
4189
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
4190
|
+
assert.deepEqual(unhandled, [], 'a refused save is silence, not an unhandled rejection');
|
|
4191
|
+
} finally {
|
|
4192
|
+
process.removeListener('unhandledRejection', onUnhandled);
|
|
4193
|
+
store.createIssuesCacheStore = originalFactory;
|
|
4194
|
+
}
|
|
4195
|
+
});
|