pi-odd-worktree 3.15.0 → 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/lib/user-prompt-card.js +48 -2
- 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 +80 -10
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T26 / S15: `Keymaps` is the host's own interaction and is closed to plugins.
|
|
3
|
+
*
|
|
4
|
+
* The host's `Keymaps` page is not a list of settings: its rows capture the next key press, write
|
|
5
|
+
* `keymaps.json` and carry a category footer that promises `Enter assign`
|
|
6
|
+
* (`lib/keymaps-customize.ts:49-68`, `lib/visual-customize-view.ts:40`). A plugin row there would be
|
|
7
|
+
* advertised as an assignable binding and could never honour it, so the category is reserved —
|
|
8
|
+
* compared trimmed and case-insensitively, because ` Keymaps ` is the same page as `Keymaps`.
|
|
9
|
+
*
|
|
10
|
+
* The refusal reuses the bridge's ONE rejection channel, at the two boundaries that can see a
|
|
11
|
+
* category:
|
|
12
|
+
*
|
|
13
|
+
* - registration (`./bus.ts`): the provider is refused BEFORE anything is stored, so the throw lands
|
|
14
|
+
* in `attributeRegistration` and the plugin's INTEGRATIONS line counts it and reads `degraded`
|
|
15
|
+
* (proved here with a real plugin module in its own temporary package, like every attribution
|
|
16
|
+
* test);
|
|
17
|
+
* - menu build (`./rows.ts`): a single row whose OWN category is reserved is dropped as it is
|
|
18
|
+
* staged and recorded for the diagnostics record, exactly like a row-name rejection. Its siblings still
|
|
19
|
+
* reach the menu — one bad row never costs the provider the rest.
|
|
20
|
+
*
|
|
21
|
+
* Nothing else changes: `Keymap`, `Key maps` and `Cards` are ordinary categories.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import assert from "node:assert/strict";
|
|
25
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
26
|
+
import { tmpdir } from "node:os";
|
|
27
|
+
import { join } from "node:path";
|
|
28
|
+
import test from "node:test";
|
|
29
|
+
import { pathToFileURL } from "node:url";
|
|
30
|
+
|
|
31
|
+
import { publishBridgeApi, resetBridgeApiForTests } from "../../lib/shell-api/api.ts";
|
|
32
|
+
import { armBridge } from "../../lib/shell-api/arm.ts";
|
|
33
|
+
import {
|
|
34
|
+
registerRows,
|
|
35
|
+
resetBusForTests,
|
|
36
|
+
resetCardStylesForTests,
|
|
37
|
+
resetSectionsForTests,
|
|
38
|
+
resetTransformsForTests,
|
|
39
|
+
snapshotProviders,
|
|
40
|
+
} from "../../lib/shell-api/bus.ts";
|
|
41
|
+
import { disableCaptureBackend, resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
|
|
42
|
+
import { resetHookStateForTests } from "../../lib/shell-api/hook.ts";
|
|
43
|
+
import { resetNoticesForTests } from "../../lib/shell-api/notices.ts";
|
|
44
|
+
import {
|
|
45
|
+
resetPluginLinesForTests,
|
|
46
|
+
} from "../../lib/shell-api/plugin-lines.ts";
|
|
47
|
+
import { getRowNameRejections, resetRowNameRejectionsForTests } from "../../lib/shell-api/row-names.ts";
|
|
48
|
+
import { getLastRowBuild, resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
|
|
49
|
+
import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
|
|
50
|
+
import type { CustomizeRow, RowLabel } from "../../lib/shell-api/types.ts";
|
|
51
|
+
import { createFakeHost, type FakeHost } from "./fake-host.ts";
|
|
52
|
+
|
|
53
|
+
/** The one sentence the refusal quotes, so the reason stands on its own in both places. */
|
|
54
|
+
const RULE =
|
|
55
|
+
"works differently in the host (its own key capture and footer); not open to plugins yet";
|
|
56
|
+
|
|
57
|
+
const labelText = (label: RowLabel | undefined): string => {
|
|
58
|
+
if (typeof label === "function") return label();
|
|
59
|
+
return label ?? "";
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const rowsOfLastBuild = (providerId: string): CustomizeRow[] =>
|
|
63
|
+
getLastRowBuild()?.find((record) => record.providerId === providerId)?.rows ?? [];
|
|
64
|
+
|
|
65
|
+
const loonLabels = (host: FakeHost): string[] =>
|
|
66
|
+
host
|
|
67
|
+
.liveRows()
|
|
68
|
+
.map((row) => labelText(row.label))
|
|
69
|
+
.filter((label) => label.startsWith("Loon"));
|
|
70
|
+
|
|
71
|
+
let configHome: string;
|
|
72
|
+
let previousConfigHome: string | undefined;
|
|
73
|
+
|
|
74
|
+
test.before(() => {
|
|
75
|
+
configHome = mkdtempSync(join(tmpdir(), "gsb-reserved-categories-"));
|
|
76
|
+
previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
|
|
77
|
+
process.env.GENTLE_PI_CONFIG_HOME = configHome;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test.after(() => {
|
|
81
|
+
if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
82
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
|
|
83
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
84
|
+
for (const dir of scratchDirs) rmSync(dir, { recursive: true, force: true });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test.beforeEach(() => {
|
|
88
|
+
rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
|
|
89
|
+
resetBridgeApiForTests();
|
|
90
|
+
resetBusForTests();
|
|
91
|
+
resetSectionsForTests();
|
|
92
|
+
resetCardStylesForTests();
|
|
93
|
+
resetTransformsForTests();
|
|
94
|
+
resetRowNameRejectionsForTests();
|
|
95
|
+
resetCaptureStateForTests();
|
|
96
|
+
resetHookStateForTests();
|
|
97
|
+
resetRowBuildStateForTests();
|
|
98
|
+
resetNoticesForTests();
|
|
99
|
+
resetStoreStateForTests();
|
|
100
|
+
resetPluginLinesForTests();
|
|
101
|
+
disableCaptureBackend();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const menuHost = (): FakeHost => {
|
|
105
|
+
const host = createFakeHost();
|
|
106
|
+
armBridge(host.ui);
|
|
107
|
+
return host;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const button = (category: string, label: string): CustomizeRow => ({
|
|
111
|
+
category,
|
|
112
|
+
label,
|
|
113
|
+
action: () => {},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// ---------------------------------------------------------------------------------------------
|
|
117
|
+
// Registration (the throw the plugin's own call sees, and how it is reported)
|
|
118
|
+
// ---------------------------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
const registrationError = (category: string, id = "loon.keymaps"): string =>
|
|
121
|
+
`gentle-shell-bridge: cannot register row provider ${JSON.stringify(id)}: its category ` +
|
|
122
|
+
`${JSON.stringify(category)} is the reserved category "Keymaps". Keymaps ${RULE}. ` +
|
|
123
|
+
`Place the rows in one of the host's other categories, e.g. "Cards".`;
|
|
124
|
+
|
|
125
|
+
test("a provider registered in Keymaps is refused, and nothing is stored", () => {
|
|
126
|
+
const api = publishBridgeApi();
|
|
127
|
+
|
|
128
|
+
assert.throws(
|
|
129
|
+
() => api.registerRows({ id: "loon.keymaps", category: "Keymaps", rows: () => [] }),
|
|
130
|
+
{ message: registrationError("Keymaps") },
|
|
131
|
+
"the error names the category and says why it is closed",
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
assert.deepEqual(snapshotProviders(), [], "a refused provider never reaches the bus");
|
|
135
|
+
const host = menuHost();
|
|
136
|
+
host.buildMenu();
|
|
137
|
+
assert.deepEqual(loonLabels(host), [], "and therefore never reaches the menu");
|
|
138
|
+
assert.deepEqual(getLastRowBuild(), [], "no build record exists for it");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("every spelling of the same category is refused: trimmed and case-insensitive", () => {
|
|
142
|
+
const api = publishBridgeApi();
|
|
143
|
+
const spellings = ["keymaps", " Keymaps ", "KEYMAPS", "\tKeyMaps\n"];
|
|
144
|
+
|
|
145
|
+
for (const [index, category] of spellings.entries()) {
|
|
146
|
+
const id = `loon.keymaps-${String(index)}`;
|
|
147
|
+
assert.throws(
|
|
148
|
+
() => api.registerRows({ id, category, rows: () => [] }),
|
|
149
|
+
{ message: registrationError(category, id) },
|
|
150
|
+
`${JSON.stringify(category)} is the same page as Keymaps`,
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
assert.deepEqual(snapshotProviders(), []);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("lookalikes are ordinary categories: Keymap, Key maps and Cards are still allowed", () => {
|
|
157
|
+
const api = publishBridgeApi();
|
|
158
|
+
const categories = ["Keymap", "Key maps", "Cards"];
|
|
159
|
+
|
|
160
|
+
for (const [index, category] of categories.entries()) {
|
|
161
|
+
api.registerRows({
|
|
162
|
+
id: `loon.lookalike-${String(index)}`,
|
|
163
|
+
category,
|
|
164
|
+
rows: () => [button(category, `Loon choice ${String(index)}`)],
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
assert.deepEqual(
|
|
169
|
+
snapshotProviders().map((provider) => provider.category),
|
|
170
|
+
categories,
|
|
171
|
+
"the comparison is exact after trimming: a near-miss is a different category",
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const host = menuHost();
|
|
175
|
+
host.buildMenu();
|
|
176
|
+
assert.deepEqual(loonLabels(host), [
|
|
177
|
+
"Loon choice 0",
|
|
178
|
+
"Loon choice 1",
|
|
179
|
+
"Loon choice 2",
|
|
180
|
+
]);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// ---------------------------------------------------------------------------------------------
|
|
184
|
+
// The reported rejection: the plugin's INTEGRATIONS line and the diagnostics record
|
|
185
|
+
// ---------------------------------------------------------------------------------------------
|
|
186
|
+
|
|
187
|
+
const scratchDirs: string[] = [];
|
|
188
|
+
let fixtureCount = 0;
|
|
189
|
+
|
|
190
|
+
/** A real plugin module in its own temporary package, so attribution runs as it does in Pi. */
|
|
191
|
+
const writePlugin = (packageName: string, body: string): string => {
|
|
192
|
+
fixtureCount += 1;
|
|
193
|
+
const root = mkdtempSync(join(tmpdir(), "gsb-reserved-plugin-"));
|
|
194
|
+
scratchDirs.push(root);
|
|
195
|
+
writeFileSync(join(root, "package.json"), JSON.stringify({ name: packageName, type: "module" }));
|
|
196
|
+
const dir = join(root, `plugin-${String(fixtureCount)}`);
|
|
197
|
+
mkdirSync(dir, { recursive: true });
|
|
198
|
+
const file = join(dir, `plugin-${String(fixtureCount)}.mjs`);
|
|
199
|
+
writeFileSync(
|
|
200
|
+
file,
|
|
201
|
+
`const api = globalThis[Symbol.for("gentle-shell-bridge/api/v1")];\n${body}\n`,
|
|
202
|
+
);
|
|
203
|
+
return file;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const loadPlugin = async (file: string): Promise<void> => {
|
|
207
|
+
await import(`${pathToFileURL(file).href}?load=${String(Date.now())}-${String(fixtureCount)}`);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// ---------------------------------------------------------------------------------------------
|
|
211
|
+
// A single row whose own category is reserved (the build boundary)
|
|
212
|
+
// ---------------------------------------------------------------------------------------------
|
|
213
|
+
|
|
214
|
+
const rowRejection = (value: string, id = "loon.mixed"): unknown => ({
|
|
215
|
+
surface: "rows",
|
|
216
|
+
id,
|
|
217
|
+
field: "category",
|
|
218
|
+
value,
|
|
219
|
+
rule: "reserved category",
|
|
220
|
+
reason: `it is the reserved category "Keymaps", which ${RULE}`,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("a rebuild keeps one record, and a corrected provider clears it", () => {
|
|
224
|
+
const dispose = registerRows({
|
|
225
|
+
id: "loon.mixed",
|
|
226
|
+
category: "Cards",
|
|
227
|
+
rows: () => [button("Cards", "Loon first"), { category: "Keymaps", label: "Loon keymap", action: () => {} }],
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
menuHost().buildMenu();
|
|
231
|
+
menuHost().buildMenu();
|
|
232
|
+
assert.equal(getRowNameRejections().length, 1, "a repeated build cannot grow the report");
|
|
233
|
+
|
|
234
|
+
dispose();
|
|
235
|
+
registerRows({
|
|
236
|
+
id: "loon.mixed",
|
|
237
|
+
category: "Cards",
|
|
238
|
+
rows: () => [button("Cards", "Loon first"), button("Cards", "Loon second")],
|
|
239
|
+
});
|
|
240
|
+
const host = menuHost();
|
|
241
|
+
host.buildMenu();
|
|
242
|
+
|
|
243
|
+
assert.deepEqual(
|
|
244
|
+
getRowNameRejections(),
|
|
245
|
+
[],
|
|
246
|
+
"the build that no longer contains the refused row clears the stale record",
|
|
247
|
+
);
|
|
248
|
+
assert.deepEqual(loonLabels(host), ["Loon first", "Loon second"]);
|
|
249
|
+
});
|
|
250
|
+
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row naming (N1–N3): a row is a LABEL, not an id.
|
|
3
|
+
*
|
|
4
|
+
* The host prints `choice.setting` as a toggle line's name
|
|
5
|
+
* (`lib/visual-customize-view.ts:583-595`), so a bridge-derived setting that contains an id puts
|
|
6
|
+
* that id in front of the user: `Section: bash-card.status`. These tests pin the replacement rule —
|
|
7
|
+
* lowercase words derived from the visible text, an explicit `rowLabel` winning, the id staying
|
|
8
|
+
* internal, and collisions between two equal labels being disambiguated deterministically and
|
|
9
|
+
* reported by the diagnostics record.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import assert from "node:assert/strict";
|
|
13
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
14
|
+
import { tmpdir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import test from "node:test";
|
|
17
|
+
|
|
18
|
+
import { armBridge } from "../../lib/shell-api/arm.ts";
|
|
19
|
+
import {
|
|
20
|
+
registerCardStyle,
|
|
21
|
+
registerSection,
|
|
22
|
+
resetBusForTests,
|
|
23
|
+
resetCardStylesForTests,
|
|
24
|
+
resetSectionsForTests,
|
|
25
|
+
} from "../../lib/shell-api/bus.ts";
|
|
26
|
+
import { installCardStyleRows, resetCardStyleRowStateForTests } from "../../lib/shell-api/card-style-rows.ts";
|
|
27
|
+
import { HOST_CARD_STYLE_SETTING } from "../../lib/shell-api/card-style-line.ts";
|
|
28
|
+
import {
|
|
29
|
+
disableCaptureBackend,
|
|
30
|
+
resetCaptureStateForTests,
|
|
31
|
+
} from "../../lib/shell-api/capture.ts";
|
|
32
|
+
import { resetHookStateForTests } from "../../lib/shell-api/hook.ts";
|
|
33
|
+
import { resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
|
|
34
|
+
import { installSectionRows } from "../../lib/shell-api/sections-rows.ts";
|
|
35
|
+
import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
|
|
36
|
+
import type {
|
|
37
|
+
CardFrame,
|
|
38
|
+
CardStyleRegistration,
|
|
39
|
+
CustomizeRow,
|
|
40
|
+
SidebarSection,
|
|
41
|
+
} from "../../lib/shell-api/types.ts";
|
|
42
|
+
import { createFakeHost, type FakeHost } from "./fake-host.ts";
|
|
43
|
+
|
|
44
|
+
let configHome: string;
|
|
45
|
+
let previousConfigHome: string | undefined;
|
|
46
|
+
|
|
47
|
+
test.before(() => {
|
|
48
|
+
configHome = mkdtempSync(join(tmpdir(), "gsb-row-labels-"));
|
|
49
|
+
previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
|
|
50
|
+
process.env.GENTLE_PI_CONFIG_HOME = configHome;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test.after(() => {
|
|
54
|
+
if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
55
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
|
|
56
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test.beforeEach(() => {
|
|
60
|
+
rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
|
|
61
|
+
resetBusForTests();
|
|
62
|
+
resetSectionsForTests();
|
|
63
|
+
resetCardStylesForTests();
|
|
64
|
+
resetCardStyleRowStateForTests();
|
|
65
|
+
resetCaptureStateForTests();
|
|
66
|
+
resetHookStateForTests();
|
|
67
|
+
resetRowBuildStateForTests();
|
|
68
|
+
resetStoreStateForTests();
|
|
69
|
+
disableCaptureBackend();
|
|
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
|
+
const frame = (): CardFrame => ({
|
|
80
|
+
top: (ctx) => "▛".repeat(ctx.width),
|
|
81
|
+
line: (ctx) => ctx.text,
|
|
82
|
+
bottom: (ctx) => "▙".repeat(ctx.width),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const style = (id: string, extra: Partial<CardStyleRegistration> = {}): CardStyleRegistration => ({
|
|
86
|
+
id,
|
|
87
|
+
label: id,
|
|
88
|
+
frame: frame(),
|
|
89
|
+
...extra,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const textOf = (row: CustomizeRow): string => {
|
|
93
|
+
const label = row.label;
|
|
94
|
+
return typeof label === "function" ? label() : (label ?? "");
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** The bridge's own `Sections` provider, then a menu host that captures it. */
|
|
98
|
+
const sectionsHost = (): FakeHost => {
|
|
99
|
+
installSectionRows();
|
|
100
|
+
const host = createFakeHost();
|
|
101
|
+
armBridge(host.ui);
|
|
102
|
+
return host;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** The host's own `Card style` row, shaped like `extensions/gentle-shell.ts:3405-3419`. */
|
|
106
|
+
const hostStyleRow = (value: "neon" | "float"): CustomizeRow => ({
|
|
107
|
+
category: "Cards",
|
|
108
|
+
label: () => `Card style: ${value}`,
|
|
109
|
+
choice: {
|
|
110
|
+
setting: HOST_CARD_STYLE_SETTING,
|
|
111
|
+
value,
|
|
112
|
+
current: () => value === "float",
|
|
113
|
+
},
|
|
114
|
+
action: async () => {},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/** A host menu long enough to be captured, with the host's own `Card style` line in `Cards`. */
|
|
118
|
+
const rowsWithHostLine = (): CustomizeRow[] => [
|
|
119
|
+
{ category: "Cards", label: "Card bash: builtin", action: () => {} },
|
|
120
|
+
{ category: "Cards", label: "Card output: builtin", action: () => {} },
|
|
121
|
+
hostStyleRow("neon"),
|
|
122
|
+
hostStyleRow("float"),
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
/** The capture backend, then the card-style surface, against a host that already has the line. */
|
|
126
|
+
const cardStyleHost = (): FakeHost => {
|
|
127
|
+
const host = createFakeHost({ rows: rowsWithHostLine() });
|
|
128
|
+
armBridge(host.ui);
|
|
129
|
+
installCardStyleRows();
|
|
130
|
+
return host;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** Every string the user could read in this menu: row labels, toggle lines and previews. */
|
|
134
|
+
const visibleText = (host: FakeHost): string[] => [
|
|
135
|
+
...host.rendered(),
|
|
136
|
+
...host.toggleLines(),
|
|
137
|
+
...host.liveRows().flatMap((row) => {
|
|
138
|
+
const preview = row.preview?.();
|
|
139
|
+
return preview === undefined ? [] : [preview.title, preview.sample];
|
|
140
|
+
}),
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
// ---------------------------------------------------------------------------------------------
|
|
144
|
+
// Sections (N1, N2)
|
|
145
|
+
// ---------------------------------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
test("a section's row reads its title as a label: no prefix, no id", () => {
|
|
148
|
+
registerSection(section("bash-card.status", { title: "BASH CARD" }));
|
|
149
|
+
const host = sectionsHost();
|
|
150
|
+
|
|
151
|
+
host.buildMenu();
|
|
152
|
+
|
|
153
|
+
assert.deepEqual(host.toggleLines(), ["bash card ● shown ○ hidden"]);
|
|
154
|
+
const injected = host.liveRows().filter((row) => row.category === "Sections");
|
|
155
|
+
assert.equal(injected.length, 2);
|
|
156
|
+
assert.deepEqual(
|
|
157
|
+
injected.map(textOf),
|
|
158
|
+
["bash card", "bash card"],
|
|
159
|
+
"the row label is the derived label, not the title as typed and not the id",
|
|
160
|
+
);
|
|
161
|
+
assert.equal(injected[0]?.choice?.setting, "bash card", "the line's name is the same label");
|
|
162
|
+
assert.equal(
|
|
163
|
+
visibleText(host).some((text) => text.includes("bash-card.status")),
|
|
164
|
+
false,
|
|
165
|
+
"the id never reaches a row",
|
|
166
|
+
);
|
|
167
|
+
assert.equal(
|
|
168
|
+
visibleText(host).some((text) => text.startsWith("Section:")),
|
|
169
|
+
false,
|
|
170
|
+
"no prefix anywhere",
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("the derivation lowercases and joins words, and drops dots and punctuation", () => {
|
|
175
|
+
registerSection(section("internal.one", { title: "usageCost" }));
|
|
176
|
+
registerSection(section("internal.two", { title: "bash-card.status" }));
|
|
177
|
+
registerSection(section("internal.three", { title: "MUSIC 2" }));
|
|
178
|
+
const host = sectionsHost();
|
|
179
|
+
|
|
180
|
+
host.buildMenu();
|
|
181
|
+
|
|
182
|
+
assert.deepEqual(host.toggleLines(), [
|
|
183
|
+
"usage cost ● shown ○ hidden",
|
|
184
|
+
// Sections sort by `id` inside one slot (section-placement S2), so the rows read in that order:
|
|
185
|
+
// `internal.one`, `internal.three`, `internal.two`.
|
|
186
|
+
"music 2 ● shown ○ hidden",
|
|
187
|
+
"bash card status ● shown ○ hidden",
|
|
188
|
+
]);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("an explicit rowLabel wins over the derived label", () => {
|
|
192
|
+
registerSection(
|
|
193
|
+
section("loon.music", { title: "MUSIC", rowLabel: "Music now playing" }),
|
|
194
|
+
);
|
|
195
|
+
const host = sectionsHost();
|
|
196
|
+
|
|
197
|
+
host.buildMenu();
|
|
198
|
+
|
|
199
|
+
assert.deepEqual(host.toggleLines(), ["Music now playing ● shown ○ hidden"]);
|
|
200
|
+
assert.deepEqual(
|
|
201
|
+
host.liveRows().filter((row) => row.category === "Sections").map(textOf),
|
|
202
|
+
["Music now playing", "Music now playing"],
|
|
203
|
+
"the author's label is used verbatim",
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("two sections with equal labels are disambiguated deterministically, never by id", () => {
|
|
208
|
+
registerSection(section("loon.one", { title: "MUSIC" }));
|
|
209
|
+
registerSection(section("loon.two", { title: "MUSIC" }));
|
|
210
|
+
const first = sectionsHost();
|
|
211
|
+
first.buildMenu();
|
|
212
|
+
|
|
213
|
+
assert.deepEqual(first.toggleLines(), [
|
|
214
|
+
"music ● shown ○ hidden",
|
|
215
|
+
"music 2 ● shown ○ hidden",
|
|
216
|
+
]);
|
|
217
|
+
assert.equal(
|
|
218
|
+
first.toggleLines().some((line) => line.includes("loon.one") || line.includes("loon.two")),
|
|
219
|
+
false,
|
|
220
|
+
"the disambiguation is a readable suffix, never the raw id",
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// Same registrations, a second menu build: the assignment cannot drift.
|
|
224
|
+
const second = sectionsHost();
|
|
225
|
+
second.buildMenu();
|
|
226
|
+
assert.deepEqual(second.toggleLines(), first.toggleLines());
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// ---------------------------------------------------------------------------------------------
|
|
230
|
+
// Card styles (N1, N3)
|
|
231
|
+
// ---------------------------------------------------------------------------------------------
|
|
232
|
+
|
|
233
|
+
test("a card-style row is a label derived from its label; the id stays internal", () => {
|
|
234
|
+
registerCardStyle(style("loon.cute", { label: "Cute Card" }));
|
|
235
|
+
const host = cardStyleHost();
|
|
236
|
+
|
|
237
|
+
host.buildMenu();
|
|
238
|
+
|
|
239
|
+
assert.deepEqual(host.toggleLines(), ["Card style ○ neon ● float ○ Cute Card"]);
|
|
240
|
+
const registered = host.liveRows().filter((row) => row.choice?.value === "Cute Card");
|
|
241
|
+
assert.equal(registered.length, 1);
|
|
242
|
+
assert.equal(textOf(registered[0] as CustomizeRow), "cute card", "the row reads as a label");
|
|
243
|
+
assert.equal(
|
|
244
|
+
visibleText(host).some((text) => text.includes("loon.cute")),
|
|
245
|
+
false,
|
|
246
|
+
"the id never reaches a row, a line or a preview",
|
|
247
|
+
);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("an explicit card-style rowLabel wins, and the value keeps the style's own label", () => {
|
|
251
|
+
registerCardStyle(style("loon.cute", { label: "Cute Card", rowLabel: "Plain card" }));
|
|
252
|
+
const host = cardStyleHost();
|
|
253
|
+
|
|
254
|
+
host.buildMenu();
|
|
255
|
+
|
|
256
|
+
const registered = host.liveRows().filter((row) => row.choice?.setting === HOST_CARD_STYLE_SETTING);
|
|
257
|
+
const bridgeRow = registered.find((row) => row.choice?.value === "Cute Card");
|
|
258
|
+
assert.ok(bridgeRow !== undefined);
|
|
259
|
+
assert.equal(textOf(bridgeRow), "Plain card", "the author's row label is used verbatim");
|
|
260
|
+
assert.equal(bridgeRow.choice?.value, "Cute Card", "the line's value is still the style's label");
|
|
261
|
+
});
|