pi-odd-worktree 3.15.1 → 3.16.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 +48 -25
- package/extensions/odd-worktree-tools.ts +64 -211
- package/lib/shell-api/api.ts +523 -0
- package/lib/shell-api/arm.ts +83 -0
- package/lib/shell-api/bus.ts +1389 -0
- package/lib/shell-api/capture.ts +1340 -0
- package/lib/shell-api/card-style-line.ts +112 -0
- package/lib/shell-api/card-style-rows.ts +390 -0
- package/lib/shell-api/card-style-transform.ts +862 -0
- package/lib/shell-api/card-style-wiring.ts +477 -0
- package/lib/shell-api/card-styles.ts +153 -0
- package/lib/shell-api/config.ts +71 -0
- package/lib/shell-api/extension.ts +247 -0
- package/lib/shell-api/hook.ts +322 -0
- package/lib/shell-api/index.ts +88 -0
- package/lib/shell-api/message-design-adoption.ts +549 -0
- package/lib/shell-api/message-design-rows.ts +313 -0
- package/lib/shell-api/message-design-wiring.ts +369 -0
- package/lib/shell-api/message-designs.ts +746 -0
- package/lib/shell-api/notices.ts +137 -0
- package/lib/shell-api/plugin-lines.ts +877 -0
- package/lib/shell-api/presence.ts +258 -0
- package/lib/shell-api/repaint.ts +351 -0
- package/lib/shell-api/row-labels.ts +146 -0
- package/lib/shell-api/row-names.ts +273 -0
- package/lib/shell-api/row-origin.ts +144 -0
- package/lib/shell-api/rows.ts +591 -0
- package/lib/shell-api/section-panel.ts +378 -0
- package/lib/shell-api/section-pointer.ts +164 -0
- package/lib/shell-api/sections-preview.ts +275 -0
- package/lib/shell-api/sections-rows.ts +133 -0
- package/lib/shell-api/sidebar-render.ts +705 -0
- package/lib/shell-api/sidebar.ts +1126 -0
- package/lib/shell-api/store.ts +279 -0
- package/lib/shell-api/tool-design-adoption.ts +263 -0
- package/lib/shell-api/tool-design-rows.ts +307 -0
- package/lib/shell-api/tool-design-wiring.ts +481 -0
- package/lib/shell-api/tool-designs.ts +1411 -0
- package/lib/shell-api/transform-pipeline.ts +351 -0
- package/lib/shell-api/types.ts +803 -0
- package/lib/shell-api/visibility.ts +154 -0
- package/package.json +3 -2
- package/tools/files-bridge.test.js +81 -66
- package/tools/fixtures/load-extension.js +40 -18
- package/tools/issues-command.test.js +4 -7
- package/tools/issues-section.test.js +71 -81
- package/tools/odd-rail-wiring.test.js +16 -10
- package/tools/package-surface.test.js +42 -13
- package/tools/prs-command.test.js +11 -6
- package/tools/shell-api/api.test.ts +484 -0
- package/tools/shell-api/apply-on-move.test.ts +529 -0
- package/tools/shell-api/arm.test.ts +220 -0
- package/tools/shell-api/bridge-ready.test.ts +309 -0
- package/tools/shell-api/bus.test.ts +194 -0
- package/tools/shell-api/button-rows.test.ts +435 -0
- package/tools/shell-api/capture.test.ts +583 -0
- package/tools/shell-api/card-style-rows.test.ts +493 -0
- package/tools/shell-api/card-style-transform.test.ts +379 -0
- package/tools/shell-api/card-style-wiring.test.ts +258 -0
- package/tools/shell-api/card-styles-e2e.test.ts +502 -0
- package/tools/shell-api/card-styles.test.ts +324 -0
- package/tools/shell-api/card-transcript-path.test.ts +178 -0
- package/tools/shell-api/compatibility-regression.test.mjs +64 -0
- package/tools/shell-api/config.test.ts +93 -0
- package/tools/shell-api/docs-coverage.test.ts +82 -0
- package/tools/shell-api/e2e.test.ts +562 -0
- package/tools/shell-api/example-bash-identity.test.ts +372 -0
- package/tools/shell-api/example-bash-matrix.test.ts +856 -0
- package/tools/shell-api/example-designs.test.ts +737 -0
- package/tools/shell-api/example-neon-transform.test.ts +283 -0
- package/tools/shell-api/example-plain-style.test.ts +1225 -0
- package/tools/shell-api/extension.test.ts +157 -0
- package/tools/shell-api/fake-events.ts +58 -0
- package/tools/shell-api/fake-host.ts +211 -0
- package/tools/shell-api/fake-sidebar.ts +516 -0
- package/tools/shell-api/fake-transcript.ts +486 -0
- package/tools/shell-api/frame-telemetry.test.ts +317 -0
- package/tools/shell-api/hook.test.ts +196 -0
- package/tools/shell-api/manifest.test.ts +47 -0
- package/tools/shell-api/message-design-adoption.test.ts +611 -0
- package/tools/shell-api/message-design-follows.test.ts +361 -0
- package/tools/shell-api/message-design-pi-release.test.mjs +157 -0
- package/tools/shell-api/message-design-regressions.test.mjs +162 -0
- package/tools/shell-api/message-design-rows.test.ts +266 -0
- package/tools/shell-api/message-design-wiring.test.ts +362 -0
- package/tools/shell-api/message-designs.test.ts +339 -0
- package/tools/shell-api/new-category.test.ts +1101 -0
- package/tools/shell-api/notices.test.ts +292 -0
- package/tools/shell-api/plugin-integration-lines.test.ts +827 -0
- package/tools/shell-api/presence.test.ts +396 -0
- package/tools/shell-api/rail-part-hits.test.ts +281 -0
- package/tools/shell-api/rail-surfaces.test.ts +402 -0
- package/tools/shell-api/rail-width.test.ts +406 -0
- package/tools/shell-api/regression.test.ts +434 -0
- package/tools/shell-api/repaint-api.test.ts +200 -0
- package/tools/shell-api/reserved-categories.test.ts +250 -0
- package/tools/shell-api/row-labels.test.ts +261 -0
- package/tools/shell-api/row-names.test.ts +407 -0
- package/tools/shell-api/row-origin.test.ts +395 -0
- package/tools/shell-api/row-placement-regression.test.ts +797 -0
- package/tools/shell-api/row-placement.test.ts +410 -0
- package/tools/shell-api/section-interaction.test.ts +364 -0
- package/tools/shell-api/section-panel.test.ts +430 -0
- package/tools/shell-api/section-placement-rail.test.ts +390 -0
- package/tools/shell-api/section-placement.test.ts +386 -0
- package/tools/shell-api/sections-preview.test.ts +312 -0
- package/tools/shell-api/sections-rows.test.ts +293 -0
- package/tools/shell-api/sidebar-backend.test.ts +477 -0
- package/tools/shell-api/sidebar-e2e.test.ts +317 -0
- package/tools/shell-api/sidebar-hover.test.ts +276 -0
- package/tools/shell-api/sidebar-independent.test.ts +291 -0
- package/tools/shell-api/sidebar-render.test.ts +281 -0
- package/tools/shell-api/sidebar-sections.test.ts +247 -0
- package/tools/shell-api/store.test.ts +192 -0
- package/tools/shell-api/surface-repaint-cost.test.ts +520 -0
- package/tools/shell-api/tool-design-card-style.test.ts +308 -0
- package/tools/shell-api/tool-design-chain.test.ts +471 -0
- package/tools/shell-api/tool-design-cost.test.ts +591 -0
- package/tools/shell-api/tool-design-rows.test.ts +627 -0
- package/tools/shell-api/tool-design-scopes-audit.test.ts +212 -0
- package/tools/shell-api/tool-designs.test.ts +2412 -0
- package/tools/shell-api/transform-pipeline.test.ts +376 -0
- package/tools/shell-api/transforms-bus.test.ts +233 -0
- package/tools/shell-api/verifier-width-regressions.test.ts +147 -0
- package/tools/shell-api-rpc.test.js +189 -0
- package/tools/user-prompt-card.test.js +8 -9
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T12/T13 — the RUNTIME presence gate for the required host package (S9).
|
|
3
|
+
*
|
|
4
|
+
* `gentle-pi` is the package that owns `/gentle:customize`, the surface this bridge feeds. Its
|
|
5
|
+
* presence is never read from disk: the sanctioned check is `pi.getCommands()` including the
|
|
6
|
+
* `gentle:customize` command, the same precedent gentle-shell itself uses
|
|
7
|
+
* (`extensions/gentle-design.ts:137`, `extensions/gentle-guide.ts:62`). All extensions are loaded
|
|
8
|
+
* before `session_start`, so that event is the moment the answer is real.
|
|
9
|
+
*
|
|
10
|
+
* What is asserted here is only what a user or a plugin can observe: whether a plugin's row reaches
|
|
11
|
+
* the host's menu, whether the ONE tool-design resolver was registered, whether the sidebar widget
|
|
12
|
+
* factory and the footer status surface were handed out, exactly which `ctx.ui.notify` messages
|
|
13
|
+
* appeared, and the the diagnostics record lines. No internal field is read.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import assert from "node:assert/strict";
|
|
17
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
18
|
+
import { tmpdir } from "node:os";
|
|
19
|
+
import { join } from "node:path";
|
|
20
|
+
import test from "node:test";
|
|
21
|
+
|
|
22
|
+
import { bridgeApi } from "../../lib/shell-api/api.ts";
|
|
23
|
+
import { registerRows, resetBusForTests } from "../../lib/shell-api/bus.ts";
|
|
24
|
+
import { resetCardStyleRowStateForTests } from "../../lib/shell-api/card-style-rows.ts";
|
|
25
|
+
import { resetCardStyleTransformForTests } from "../../lib/shell-api/card-style-transform.ts";
|
|
26
|
+
import { disableCardStyleTransform, resetCardStyleWiringForTests } from "../../lib/shell-api/card-style-wiring.ts";
|
|
27
|
+
import { getCaptureDiagnostics, resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
|
|
28
|
+
import gentleShellBridge, {
|
|
29
|
+
type BridgeCommandEntry,
|
|
30
|
+
type BridgeSessionHandler,
|
|
31
|
+
type BridgeExtensionApi,
|
|
32
|
+
} from "../../lib/shell-api/extension.ts";
|
|
33
|
+
import { resetHookStateForTests } from "../../lib/shell-api/hook.ts";
|
|
34
|
+
import { resetNoticesForTests } from "../../lib/shell-api/notices.ts";
|
|
35
|
+
import { getPluginLineReport, resetPluginLinesForTests } from "../../lib/shell-api/plugin-lines.ts";
|
|
36
|
+
import {
|
|
37
|
+
GENTLE_PI_COMMAND,
|
|
38
|
+
getGentlePiPresence,
|
|
39
|
+
hasGentlePi,
|
|
40
|
+
resetPresenceForTests,
|
|
41
|
+
} from "../../lib/shell-api/presence.ts";
|
|
42
|
+
import { resetRepaintForTests } from "../../lib/shell-api/repaint.ts";
|
|
43
|
+
import { resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
|
|
44
|
+
import { disableSidebarBackend, resetSidebarStateForTests } from "../../lib/shell-api/sidebar.ts";
|
|
45
|
+
import { resetSectionFailuresForTests } from "../../lib/shell-api/sidebar-render.ts";
|
|
46
|
+
import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
|
|
47
|
+
import { resetToolDesignRowStateForTests } from "../../lib/shell-api/tool-design-rows.ts";
|
|
48
|
+
import { registerToolDesign, resetToolDesignsForTests } from "../../lib/shell-api/tool-designs.ts";
|
|
49
|
+
import { resetToolDesignWiringForTests } from "../../lib/shell-api/tool-design-wiring.ts";
|
|
50
|
+
import { createFakeHost } from "./fake-host.ts";
|
|
51
|
+
|
|
52
|
+
let configHome: string;
|
|
53
|
+
let previousConfigHome: string | undefined;
|
|
54
|
+
|
|
55
|
+
test.before(() => {
|
|
56
|
+
configHome = mkdtempSync(join(tmpdir(), "gsb-presence-"));
|
|
57
|
+
previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
|
|
58
|
+
process.env.GENTLE_PI_CONFIG_HOME = configHome;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test.after(() => {
|
|
62
|
+
if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
63
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
|
|
64
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test.beforeEach(() => {
|
|
68
|
+
resetBusForTests();
|
|
69
|
+
resetCaptureStateForTests();
|
|
70
|
+
resetCardStyleRowStateForTests();
|
|
71
|
+
resetCardStyleTransformForTests();
|
|
72
|
+
resetCardStyleWiringForTests();
|
|
73
|
+
resetHookStateForTests();
|
|
74
|
+
resetNoticesForTests();
|
|
75
|
+
resetPluginLinesForTests();
|
|
76
|
+
resetRepaintForTests();
|
|
77
|
+
resetRowBuildStateForTests();
|
|
78
|
+
resetSectionFailuresForTests();
|
|
79
|
+
resetSidebarStateForTests();
|
|
80
|
+
resetStoreStateForTests();
|
|
81
|
+
resetToolDesignRowStateForTests();
|
|
82
|
+
resetToolDesignsForTests();
|
|
83
|
+
resetToolDesignWiringForTests();
|
|
84
|
+
resetPresenceForTests();
|
|
85
|
+
disableCardStyleTransform();
|
|
86
|
+
disableSidebarBackend();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// ---------------------------------------------------------------------------------------------
|
|
90
|
+
// The harness: the real entry, a fake Pi whose command list can change, and one recording `ctx.ui`
|
|
91
|
+
// ---------------------------------------------------------------------------------------------
|
|
92
|
+
|
|
93
|
+
interface RecordingWorld {
|
|
94
|
+
/** The API object the entry was loaded against; `getCommands` disappears for the absent case. */
|
|
95
|
+
pi: BridgeExtensionApi;
|
|
96
|
+
start: () => void;
|
|
97
|
+
warnings: string[];
|
|
98
|
+
widgets: number;
|
|
99
|
+
statuses: Array<{ key: string; text?: string }>;
|
|
100
|
+
resolvers: unknown[];
|
|
101
|
+
host: ReturnType<typeof createFakeHost>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Load the real entry against a fake Pi. `getCommands` is a live factory, so a test can model the
|
|
106
|
+
* host "showing up" later; passing `undefined` models a host that exposes no command surface at all.
|
|
107
|
+
*/
|
|
108
|
+
const createWorld = (getCommands: (() => unknown) | undefined, rowLabel?: string): RecordingWorld => {
|
|
109
|
+
const warnings: string[] = [];
|
|
110
|
+
const statuses: Array<{ key: string; text?: string }> = [];
|
|
111
|
+
const handlers: BridgeSessionHandler[] = [];
|
|
112
|
+
const resolvers: unknown[] = [];
|
|
113
|
+
let widgets = 0;
|
|
114
|
+
const host = createFakeHost();
|
|
115
|
+
const ui = host.ui as Record<string, unknown>;
|
|
116
|
+
ui.notify = (message: string) => warnings.push(message);
|
|
117
|
+
ui.setWidget = (_key: string, _factory: (tui: unknown, theme: unknown) => unknown) => {
|
|
118
|
+
widgets += 1;
|
|
119
|
+
};
|
|
120
|
+
ui.setStatus = (key: string, text?: string) => statuses.push({ key, text });
|
|
121
|
+
|
|
122
|
+
const pi: BridgeExtensionApi = {
|
|
123
|
+
on(event, handler) {
|
|
124
|
+
if (event === "session_start") handlers.push(handler);
|
|
125
|
+
},
|
|
126
|
+
registerCommand() {},
|
|
127
|
+
registerToolRenderer(resolver) {
|
|
128
|
+
resolvers.push(resolver);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
if (getCommands !== undefined) {
|
|
132
|
+
// The host is a TRUST BOUNDARY: the cast models a host whose answer violates Pi's own type
|
|
133
|
+
// (a non-array, an entry with no name, a throwing call), which is exactly what `./presence.ts`
|
|
134
|
+
// re-validates at runtime.
|
|
135
|
+
pi.getCommands = getCommands as () => readonly BridgeCommandEntry[];
|
|
136
|
+
}
|
|
137
|
+
gentleShellBridge(pi);
|
|
138
|
+
|
|
139
|
+
if (rowLabel !== undefined) {
|
|
140
|
+
registerRows({
|
|
141
|
+
id: "presence.probe",
|
|
142
|
+
category: "Banner",
|
|
143
|
+
rows: () => [{ label: rowLabel, action: () => {} }],
|
|
144
|
+
});
|
|
145
|
+
registerToolDesign({
|
|
146
|
+
tool: "bash",
|
|
147
|
+
id: "presence.probe",
|
|
148
|
+
label: "Probe",
|
|
149
|
+
apply: (lines) => [...lines],
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
pi,
|
|
155
|
+
host,
|
|
156
|
+
warnings,
|
|
157
|
+
resolvers,
|
|
158
|
+
get widgets() {
|
|
159
|
+
return widgets;
|
|
160
|
+
},
|
|
161
|
+
statuses,
|
|
162
|
+
start: () => {
|
|
163
|
+
for (const handler of handlers) handler({}, { hasUI: true, ui });
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The presence answer the entry recorded, read from the process-global record: what the user's
|
|
170
|
+
* warning and every later check agree on.
|
|
171
|
+
*/
|
|
172
|
+
const recordedPresence = () => {
|
|
173
|
+
const presence = getGentlePiPresence();
|
|
174
|
+
assert.ok(presence !== undefined, "a check has run, so the record answers");
|
|
175
|
+
return presence;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// ---------------------------------------------------------------------------------------------
|
|
179
|
+
// T13 — present: the bridge arms exactly as it does today
|
|
180
|
+
// ---------------------------------------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
test("present: session_start arms every surface exactly as today", () => {
|
|
183
|
+
const world = createWorld(() => [{ name: GENTLE_PI_COMMAND }], "Probe row");
|
|
184
|
+
|
|
185
|
+
world.start();
|
|
186
|
+
|
|
187
|
+
assert.equal(getCaptureDiagnostics().armedTargets, 1, "the row bridge is armed");
|
|
188
|
+
assert.equal(world.resolvers.length, 1, "the ONE tool-design resolver is registered");
|
|
189
|
+
assert.ok(world.widgets >= 1, "the sidebar widget factory is handed to the host");
|
|
190
|
+
assert.equal(
|
|
191
|
+
getPluginLineReport().availability,
|
|
192
|
+
"installed",
|
|
193
|
+
"the footer status surface is installed, so a plugin's INTEGRATIONS line is painted",
|
|
194
|
+
);
|
|
195
|
+
assert.deepEqual(world.warnings, [], "a present host needs no warning");
|
|
196
|
+
|
|
197
|
+
world.host.buildMenu();
|
|
198
|
+
assert.ok(world.host.rendered().includes("Probe row"), "a plugin's row reaches the host's menu");
|
|
199
|
+
|
|
200
|
+
assert.deepEqual(recordedPresence(), { present: true }, "the record answers present");
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test("present: a second session_start changes nothing (arming stays idempotent)", () => {
|
|
204
|
+
const world = createWorld(() => [{ name: GENTLE_PI_COMMAND }], "Probe row");
|
|
205
|
+
|
|
206
|
+
world.start();
|
|
207
|
+
world.start();
|
|
208
|
+
|
|
209
|
+
assert.equal(getCaptureDiagnostics().armedTargets, 1);
|
|
210
|
+
assert.equal(world.resolvers.length, 1, "one resolver, however many times the event fires");
|
|
211
|
+
assert.equal(
|
|
212
|
+
getPluginLineReport().availability,
|
|
213
|
+
"installed",
|
|
214
|
+
"a second event re-installs the same surface, it does not duplicate it",
|
|
215
|
+
);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// ---------------------------------------------------------------------------------------------
|
|
219
|
+
// T13 — absent: nothing armed, one warning, and one honest presence record
|
|
220
|
+
// ---------------------------------------------------------------------------------------------
|
|
221
|
+
|
|
222
|
+
test("absent: nothing is armed, one warning per absence, and the report says missing", () => {
|
|
223
|
+
const world = createWorld(undefined, "Probe row");
|
|
224
|
+
|
|
225
|
+
world.start();
|
|
226
|
+
world.start();
|
|
227
|
+
world.start();
|
|
228
|
+
|
|
229
|
+
assert.equal(world.warnings.length, 1, "exactly one warning for the same absence");
|
|
230
|
+
assert.match(world.warnings[0], /gentle-pi/u, "the warning names the missing package");
|
|
231
|
+
assert.match(world.warnings[0], /missing/u);
|
|
232
|
+
|
|
233
|
+
assert.equal(getCaptureDiagnostics().armedTargets, 0, "no wrapper is armed");
|
|
234
|
+
assert.equal(world.resolvers.length, 0, "no tool-design resolver is registered");
|
|
235
|
+
assert.equal(world.widgets, 0, "no sidebar widget factory is handed out");
|
|
236
|
+
assert.deepEqual(world.statuses, [], "no footer line: the bridge never claims readiness");
|
|
237
|
+
assert.equal(
|
|
238
|
+
getPluginLineReport().availability,
|
|
239
|
+
"not-armed",
|
|
240
|
+
"the INTEGRATIONS surface is never installed, so no plugin is told 'ready'",
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
world.host.buildMenu();
|
|
244
|
+
assert.equal(
|
|
245
|
+
world.host.rendered().filter((label) => label === "Probe row").length,
|
|
246
|
+
0,
|
|
247
|
+
"a plugin's row is recorded but never reaches the menu",
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
assert.deepEqual(
|
|
251
|
+
recordedPresence(),
|
|
252
|
+
{ present: false, reason: "the host has no getCommands()" },
|
|
253
|
+
"the record names the absence and why",
|
|
254
|
+
);
|
|
255
|
+
assert.equal(world.widgets, 0, "and nothing else was armed after the report");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("absent: a plugin's registrations still succeed and never throw", () => {
|
|
259
|
+
const world = createWorld(undefined);
|
|
260
|
+
|
|
261
|
+
assert.doesNotThrow(() =>
|
|
262
|
+
bridgeApi()?.registerRows({
|
|
263
|
+
id: "presence.offline",
|
|
264
|
+
category: "Banner",
|
|
265
|
+
rows: () => [{ label: "Offline", action: () => {} }],
|
|
266
|
+
}),
|
|
267
|
+
);
|
|
268
|
+
const api = bridgeApi();
|
|
269
|
+
assert.ok(api !== undefined, "the API object is still published while disabled");
|
|
270
|
+
assert.equal(typeof api.registerToolDesign, "function");
|
|
271
|
+
assert.doesNotThrow(() =>
|
|
272
|
+
api.registerToolDesign?.({
|
|
273
|
+
tool: "bash",
|
|
274
|
+
id: "presence.offline",
|
|
275
|
+
label: "Offline",
|
|
276
|
+
apply: (lines) => [...lines],
|
|
277
|
+
}),
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
world.start();
|
|
281
|
+
world.host.buildMenu();
|
|
282
|
+
|
|
283
|
+
assert.equal(getCaptureDiagnostics().armedTargets, 0);
|
|
284
|
+
assert.equal(world.resolvers.length, 0);
|
|
285
|
+
assert.equal(world.host.rendered().includes("Offline"), false);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// ---------------------------------------------------------------------------------------------
|
|
289
|
+
// T13 — the check is a guard, not a crash
|
|
290
|
+
// ---------------------------------------------------------------------------------------------
|
|
291
|
+
|
|
292
|
+
test("the predicate is true only for a command list that names gentle:customize", () => {
|
|
293
|
+
assert.equal(GENTLE_PI_COMMAND, "gentle:customize");
|
|
294
|
+
assert.equal(hasGentlePi({ getCommands: () => [{ name: GENTLE_PI_COMMAND }] }), true);
|
|
295
|
+
assert.equal(
|
|
296
|
+
hasGentlePi({ getCommands: () => [{ name: "other:command" }, { name: GENTLE_PI_COMMAND }] }),
|
|
297
|
+
true,
|
|
298
|
+
"the list is searched, not required to be a single entry",
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
for (const [what, host] of [
|
|
302
|
+
["no getCommands", {}],
|
|
303
|
+
["an undefined host", undefined],
|
|
304
|
+
["a null host", null],
|
|
305
|
+
["a non-object host", "gentle-pi"],
|
|
306
|
+
["a non-function getCommands", { getCommands: "gentle:customize" }],
|
|
307
|
+
["a throwing getCommands", { getCommands: () => { throw new Error("host exploded"); } }],
|
|
308
|
+
["a non-array command list", { getCommands: () => "gentle:customize" }],
|
|
309
|
+
["an entry without a name", { getCommands: () => [{ label: GENTLE_PI_COMMAND }] }],
|
|
310
|
+
["a non-object entry", { getCommands: () => ["gentle:customize"] }],
|
|
311
|
+
["a non-string name", { getCommands: () => [{ name: 42 }] }],
|
|
312
|
+
["a near-miss name", { getCommands: () => [{ name: "gentle:customize " }] }],
|
|
313
|
+
["an empty list", { getCommands: () => [] }],
|
|
314
|
+
] as const) {
|
|
315
|
+
assert.equal(hasGentlePi(host), false, `${what} means missing`);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test("a throwing getCommands on session_start is missing, warned and never armed", () => {
|
|
320
|
+
const world = createWorld(() => {
|
|
321
|
+
throw new Error("host exploded");
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
assert.doesNotThrow(() => world.start());
|
|
325
|
+
|
|
326
|
+
assert.equal(world.warnings.length, 1);
|
|
327
|
+
assert.equal(getCaptureDiagnostics().armedTargets, 0);
|
|
328
|
+
assert.equal(world.resolvers.length, 0);
|
|
329
|
+
assert.deepEqual(
|
|
330
|
+
recordedPresence(),
|
|
331
|
+
{ present: false, reason: "getCommands() threw: host exploded" },
|
|
332
|
+
"the record carries the host's own failure message",
|
|
333
|
+
);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// ---------------------------------------------------------------------------------------------
|
|
337
|
+
// T13 — a late host: missing, then present
|
|
338
|
+
// ---------------------------------------------------------------------------------------------
|
|
339
|
+
|
|
340
|
+
test("a late session_start after gentle-pi appears enables the bridge exactly once", () => {
|
|
341
|
+
let commands: unknown = [];
|
|
342
|
+
const world = createWorld(() => commands, "Probe row");
|
|
343
|
+
|
|
344
|
+
world.start();
|
|
345
|
+
world.start();
|
|
346
|
+
assert.equal(world.warnings.length, 1, "one warning for the one absence");
|
|
347
|
+
assert.equal(getCaptureDiagnostics().armedTargets, 0);
|
|
348
|
+
|
|
349
|
+
// gentle-pi shows up: the next session_start is the re-check.
|
|
350
|
+
commands = [{ name: GENTLE_PI_COMMAND }];
|
|
351
|
+
world.start();
|
|
352
|
+
|
|
353
|
+
assert.equal(getCaptureDiagnostics().armedTargets, 1, "the row bridge arms on the re-check");
|
|
354
|
+
assert.equal(world.resolvers.length, 1, "the resolver registers on the re-check");
|
|
355
|
+
assert.ok(world.widgets >= 1, "the sidebar widget factory is installed on the re-check");
|
|
356
|
+
assert.equal(getPluginLineReport().availability, "installed");
|
|
357
|
+
assert.equal(world.warnings.length, 1, "enabling does not repeat the warning");
|
|
358
|
+
world.host.buildMenu();
|
|
359
|
+
assert.ok(world.host.rendered().includes("Probe row"));
|
|
360
|
+
|
|
361
|
+
assert.deepEqual(recordedPresence(), { present: true }, "the re-check records present");
|
|
362
|
+
|
|
363
|
+
// Exactly once: arming is idempotent and is not re-run as a second resolver or a second wrapper.
|
|
364
|
+
world.start();
|
|
365
|
+
assert.equal(getCaptureDiagnostics().armedTargets, 1);
|
|
366
|
+
assert.equal(world.resolvers.length, 1);
|
|
367
|
+
assert.equal(world.warnings.length, 1);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test("present then missing again warns again for the new absence", () => {
|
|
371
|
+
let commands: unknown = [{ name: GENTLE_PI_COMMAND }];
|
|
372
|
+
const world = createWorld(() => commands, "Probe row");
|
|
373
|
+
|
|
374
|
+
world.start();
|
|
375
|
+
assert.deepEqual(world.warnings, []);
|
|
376
|
+
|
|
377
|
+
// The host vanishes: the next re-check must report it and warn again, exactly once.
|
|
378
|
+
commands = [{ name: "other:command" }];
|
|
379
|
+
world.start();
|
|
380
|
+
world.start();
|
|
381
|
+
|
|
382
|
+
assert.equal(world.warnings.length, 1, "one warning for the second absence");
|
|
383
|
+
assert.match(world.warnings[0], /gentle-pi/u);
|
|
384
|
+
|
|
385
|
+
assert.deepEqual(
|
|
386
|
+
recordedPresence(),
|
|
387
|
+
{ present: false, reason: "getCommands() lists no gentle:customize" },
|
|
388
|
+
"the record names the second absence and why",
|
|
389
|
+
);
|
|
390
|
+
assert.equal(world.widgets, 1, "the surfaces armed for the present host were not re-armed");
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// ---------------------------------------------------------------------------------------------
|
|
394
|
+
// The presence record: process-global, absent until the first check
|
|
395
|
+
// ---------------------------------------------------------------------------------------------
|
|
396
|
+
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contributed rail rows stay live under a PARTIAL pass (S1–S3, S5): the host's layout memo re-renders
|
|
3
|
+
* ONE part when that part's digest moves, so a live tick in `todo`, `jobs` or `agents` repaints that
|
|
4
|
+
* part alone. The pointer map a contributed row answers from must therefore be recorded PER PART:
|
|
5
|
+
* one part's re-render must never erase another part's rows.
|
|
6
|
+
*
|
|
7
|
+
* The bug this pins (0.13.0–0.16.1): the renderer kept ONE frame of row ranges for the whole rail and
|
|
8
|
+
* the first part of a new pass erased every part's blocks, so after any partial pass the footer's
|
|
9
|
+
* contributed rows were inert — no click, no hover. The events below are dispatched exactly the way
|
|
10
|
+
* the layout dispatches them (`lib/shell-sidebar-layout.ts:245-259`): `y` counts the PART's rows, so
|
|
11
|
+
* the native footer's three rows come first and the section's header is row 3.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import assert from "node:assert/strict";
|
|
15
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
16
|
+
import { tmpdir } from "node:os";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import test from "node:test";
|
|
19
|
+
|
|
20
|
+
import { registerSection, resetBusForTests, resetSectionsForTests } from "../../lib/shell-api/bus.ts";
|
|
21
|
+
import { resetRepaintForTests, setRepaintHost } from "../../lib/shell-api/repaint.ts";
|
|
22
|
+
import { resetSectionPanelForTests, setSectionTheme } from "../../lib/shell-api/section-panel.ts";
|
|
23
|
+
import { resetSectionPointerForTests } from "../../lib/shell-api/section-pointer.ts";
|
|
24
|
+
import {
|
|
25
|
+
disableSidebarBackend,
|
|
26
|
+
installSidebarBackend,
|
|
27
|
+
resetSidebarStateForTests,
|
|
28
|
+
} from "../../lib/shell-api/sidebar.ts";
|
|
29
|
+
import { installSectionRail, resetSectionFailuresForTests } from "../../lib/shell-api/sidebar-render.ts";
|
|
30
|
+
import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
|
|
31
|
+
import type { SidebarSection } from "../../lib/shell-api/types.ts";
|
|
32
|
+
import {
|
|
33
|
+
fakeState,
|
|
34
|
+
fakeTerminal,
|
|
35
|
+
fakeTui,
|
|
36
|
+
registerNativeFooter,
|
|
37
|
+
registerNativeRail,
|
|
38
|
+
renderSidebar,
|
|
39
|
+
resetSidebar,
|
|
40
|
+
} from "./fake-sidebar.ts";
|
|
41
|
+
|
|
42
|
+
let configHome: string;
|
|
43
|
+
let previousConfigHome: string | undefined;
|
|
44
|
+
|
|
45
|
+
test.before(() => {
|
|
46
|
+
configHome = mkdtempSync(join(tmpdir(), "gsb-rail-part-hits-"));
|
|
47
|
+
previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
|
|
48
|
+
process.env.GENTLE_PI_CONFIG_HOME = configHome;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test.after(() => {
|
|
52
|
+
if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
53
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
|
|
54
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test.beforeEach(() => {
|
|
58
|
+
rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
|
|
59
|
+
resetBusForTests();
|
|
60
|
+
resetSectionsForTests();
|
|
61
|
+
resetSidebar();
|
|
62
|
+
resetSidebarStateForTests();
|
|
63
|
+
resetSectionFailuresForTests();
|
|
64
|
+
resetSectionPanelForTests();
|
|
65
|
+
resetSectionPointerForTests();
|
|
66
|
+
resetRepaintForTests();
|
|
67
|
+
resetStoreStateForTests();
|
|
68
|
+
disableSidebarBackend();
|
|
69
|
+
renders = 0;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const section = (id: string, extra: Partial<SidebarSection> = {}): SidebarSection => ({
|
|
73
|
+
id,
|
|
74
|
+
title: id.toUpperCase(),
|
|
75
|
+
lines: () => [`body ${id}`],
|
|
76
|
+
...extra,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
let renders = 0;
|
|
80
|
+
|
|
81
|
+
/** Arm the rail with a `tui` whose `requestRender` a test can count. */
|
|
82
|
+
function arm(): void {
|
|
83
|
+
const tui = {
|
|
84
|
+
terminal: fakeTerminal(),
|
|
85
|
+
requestRender: () => {
|
|
86
|
+
renders += 1;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
setRepaintHost(tui);
|
|
90
|
+
// Every painted part the fake layout walks, so a "partial pass" is a real second render of one.
|
|
91
|
+
registerNativeRail("todo", nativePart("TODO"));
|
|
92
|
+
registerNativeRail("agents", nativePart("AGENTS"));
|
|
93
|
+
registerNativeFooter();
|
|
94
|
+
installSidebarBackend(() => fakeTui());
|
|
95
|
+
installSectionRail();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The host's own part shape: a `▾ TITLE` header and two body rows, declared as one card group. */
|
|
99
|
+
function nativePart(title: string): {
|
|
100
|
+
render(): string[];
|
|
101
|
+
cardGroups(): { groups: Array<{ start: number; end: number }> };
|
|
102
|
+
digest(): string;
|
|
103
|
+
} {
|
|
104
|
+
const lines = [`▾ ${title}`, "native row 1", "native row 2"];
|
|
105
|
+
return {
|
|
106
|
+
render: () => [...lines],
|
|
107
|
+
cardGroups: () => ({ groups: [{ start: 0, end: lines.length }] }),
|
|
108
|
+
digest: () => `${title.toLowerCase()}:native`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The native footer renders three rows, so the contribution's first row is 3. */
|
|
113
|
+
const NATIVE_ROWS = 3;
|
|
114
|
+
|
|
115
|
+
const part = (key: string) => fakeState().parts.get(key);
|
|
116
|
+
const footer = () => part("footer");
|
|
117
|
+
|
|
118
|
+
/** The footer's wrapped render: what the user reads, host rows first and our rows after them. */
|
|
119
|
+
const footerRows = (width = 40): string[] => footer()?.render(width) ?? [];
|
|
120
|
+
const rowOf = (text: string, width = 40): string | undefined =>
|
|
121
|
+
footerRows(width).find((row) => row.includes(text));
|
|
122
|
+
|
|
123
|
+
/** One part re-rendered on its own — exactly what the layout memo does when its digest moves. */
|
|
124
|
+
const reRenderPart = (key: string, width = 40): void => {
|
|
125
|
+
part(key)?.render(width);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const event = (type: "move" | "click", y: number, width = 40): unknown => ({
|
|
129
|
+
type,
|
|
130
|
+
button: type === "click" ? "left" : "none",
|
|
131
|
+
x: 4,
|
|
132
|
+
y,
|
|
133
|
+
width,
|
|
134
|
+
height: 40,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const move = (y: number, width = 40): unknown => footer()?.handleMouse?.(event("move", y, width));
|
|
138
|
+
const click = (y: number, width = 40): unknown => footer()?.handleMouse?.(event("click", y, width));
|
|
139
|
+
|
|
140
|
+
const ROLE_SGR: Record<string, number> = {
|
|
141
|
+
text: 37,
|
|
142
|
+
muted: 90,
|
|
143
|
+
dim: 2,
|
|
144
|
+
accent: 95,
|
|
145
|
+
success: 32,
|
|
146
|
+
error: 31,
|
|
147
|
+
warning: 33,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
function fakeTheme(): { fg(role: string, text: string): string; bold(text: string): string } {
|
|
151
|
+
return {
|
|
152
|
+
fg: (role, text) => `\u001b[${ROLE_SGR[role] ?? 0}m${text}\u001b[39m`,
|
|
153
|
+
bold: (text) => `\u001b[1m${text}\u001b[22m`,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The one section these tests contribute: the default placement puts it after the footer's rows. */
|
|
158
|
+
const registerMusic = (calls: string[] = []): void => {
|
|
159
|
+
registerSection(
|
|
160
|
+
section("music", {
|
|
161
|
+
title: "MUSIC",
|
|
162
|
+
lines: () => [
|
|
163
|
+
{ label: "play", onClick: () => calls.push("play") },
|
|
164
|
+
{ label: "inert" },
|
|
165
|
+
],
|
|
166
|
+
}),
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/** S1. A part repainted on its own must not take the footer's clickable row with it. */
|
|
171
|
+
test("S1: a one-part re-render keeps the footer's clickable row answering", () => {
|
|
172
|
+
const calls: string[] = [];
|
|
173
|
+
registerMusic(calls);
|
|
174
|
+
arm();
|
|
175
|
+
renderSidebar(40);
|
|
176
|
+
|
|
177
|
+
assert.deepEqual(click(4), { handled: true, render: true }, "the full pass recorded the row");
|
|
178
|
+
assert.deepEqual(calls, ["play"], "one click, one call");
|
|
179
|
+
|
|
180
|
+
// The layout memo re-renders ONE part when its digest moves: the earlier painted `todo` here.
|
|
181
|
+
reRenderPart("todo");
|
|
182
|
+
|
|
183
|
+
assert.deepEqual(click(4), { handled: true, render: true }, "the footer's row still answers");
|
|
184
|
+
assert.deepEqual(calls, ["play", "play"], "and runs its onClick exactly once");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
/** S2. The same partial pass must not cost the hover either. */
|
|
188
|
+
test("S2: hover survives a one-part re-render, and the same row is not a new hover", () => {
|
|
189
|
+
setSectionTheme(fakeTheme());
|
|
190
|
+
registerMusic();
|
|
191
|
+
arm();
|
|
192
|
+
renderSidebar(40);
|
|
193
|
+
|
|
194
|
+
reRenderPart("todo");
|
|
195
|
+
|
|
196
|
+
assert.deepEqual(move(4), { handled: true, render: true }, "the row claims the hover");
|
|
197
|
+
assert.equal(renders, 1, "and asks for exactly one frame");
|
|
198
|
+
assert.ok((rowOf("play") ?? "").includes("\u001b[33m"), "the hovered row takes the hover role");
|
|
199
|
+
|
|
200
|
+
assert.deepEqual(move(4), { handled: true }, "the same row again is not a new hover");
|
|
201
|
+
assert.equal(renders, 1, "so it asks for no frame");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
/** S3. Ranges answer only at the width they were recorded at, and are replaced by a re-render. */
|
|
205
|
+
test("S3: a part's ranges answer only the width they were recorded at", () => {
|
|
206
|
+
const calls: string[] = [];
|
|
207
|
+
registerMusic(calls);
|
|
208
|
+
arm();
|
|
209
|
+
renderSidebar(40);
|
|
210
|
+
assert.deepEqual(click(4), { handled: true, render: true }, "recorded at 40, answering at 40");
|
|
211
|
+
|
|
212
|
+
// The footer alone is re-rendered at a new width: its ranges are REPLACED at that width.
|
|
213
|
+
reRenderPart("footer", 50);
|
|
214
|
+
|
|
215
|
+
assert.equal(
|
|
216
|
+
click(4, 40),
|
|
217
|
+
undefined,
|
|
218
|
+
"an event mapped at 40 declines instead of guessing an offset",
|
|
219
|
+
);
|
|
220
|
+
assert.deepEqual(calls, ["play"], "and runs nothing");
|
|
221
|
+
assert.deepEqual(click(4, 50), { handled: true, render: true }, "the ranges recorded at 50 answer");
|
|
222
|
+
assert.deepEqual(calls, ["play", "play"], "one click, one call");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
/** S5 (first half). A part this contributor never rendered has no ranges to answer with. */
|
|
226
|
+
test("S5: a part the contributor never rendered declines the event", () => {
|
|
227
|
+
const calls: string[] = [];
|
|
228
|
+
registerMusic(calls);
|
|
229
|
+
arm();
|
|
230
|
+
renderSidebar(40);
|
|
231
|
+
|
|
232
|
+
// `agents` rendered its own rows, but no section landed there: a click inside its frame is not
|
|
233
|
+
// ours to answer, and nothing may run.
|
|
234
|
+
const agents = part("agents");
|
|
235
|
+
assert.ok(agents !== undefined, "the agents part is wrapped like every painted part");
|
|
236
|
+
assert.equal(agents?.handleMouse?.(event("click", 1)), undefined, "it has no ranges to answer");
|
|
237
|
+
assert.equal(agents?.handleMouse?.(event("move", 1)), undefined, "and no hover to claim");
|
|
238
|
+
assert.deepEqual(calls, [], "nothing ran");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
/** S5 (second half). The test seam drops the per-part ranges AND the hover, like it always did. */
|
|
242
|
+
test("S5: resetSectionFailuresForTests drops the ranges and the hover", () => {
|
|
243
|
+
setSectionTheme(fakeTheme());
|
|
244
|
+
const calls: string[] = [];
|
|
245
|
+
registerMusic(calls);
|
|
246
|
+
arm();
|
|
247
|
+
renderSidebar(40);
|
|
248
|
+
|
|
249
|
+
assert.deepEqual(move(4), { handled: true, render: true }, "the row claims the hover");
|
|
250
|
+
assert.ok((rowOf("play") ?? "").includes("\u001b[33m"), "and paints with the hover role");
|
|
251
|
+
|
|
252
|
+
resetSectionFailuresForTests();
|
|
253
|
+
// Only the footer re-renders, which is what records ranges for it again: the hover is NOT restored.
|
|
254
|
+
reRenderPart("footer");
|
|
255
|
+
assert.ok(
|
|
256
|
+
!(rowOf("play") ?? "").includes("\u001b[33m"),
|
|
257
|
+
"the hover was dropped by the reset, not by the frame",
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
// Ranges are back with that render, so the row answers again as a FRESH hover.
|
|
261
|
+
assert.deepEqual(move(4), { handled: true, render: true }, "a new hover, because the old one went");
|
|
262
|
+
|
|
263
|
+
resetSectionFailuresForTests();
|
|
264
|
+
assert.equal(click(4), undefined, "the recorded ranges are gone, so the click declines");
|
|
265
|
+
assert.deepEqual(calls, [], "and runs nothing");
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* PRESERVE. The host-first rule and the "only rows that act" rule are unchanged by per-part ranges: a
|
|
270
|
+
* host row still answers for the host, and a contributed row without `onClick` still declines.
|
|
271
|
+
*/
|
|
272
|
+
test("a host row still answers, and a contributed row without onClick still declines", () => {
|
|
273
|
+
const calls: string[] = [];
|
|
274
|
+
registerMusic(calls);
|
|
275
|
+
arm();
|
|
276
|
+
renderSidebar(40);
|
|
277
|
+
|
|
278
|
+
assert.deepEqual(click(0), { handled: true, render: true }, "the host's own header row answers");
|
|
279
|
+
assert.equal(click(5), undefined, "our inert body row declines the click");
|
|
280
|
+
assert.deepEqual(calls, [], "and runs nothing");
|
|
281
|
+
});
|