pi-odd-worktree 3.15.1 → 3.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -25
- package/extensions/odd-worktree-tools.ts +70 -212
- 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/session-auto-name-wiring.test.js +39 -0
- 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,529 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Move the cursor, press Enter to apply (A1–A4, L4).
|
|
3
|
+
*
|
|
4
|
+
* The user's report: a line the bridge added changes its value the moment ←/→ touches it — the `›`
|
|
5
|
+
* cursor and "Enter applies" never appear — while the host's own `Stats` line moves the cursor and
|
|
6
|
+
* applies on Enter. The host's rule is PER ROW, not per line, so the fix is a row field:
|
|
7
|
+
*
|
|
8
|
+
* - `lib/visual-customize-view.ts:552-566` steps the cursor inside one setting line and runs
|
|
9
|
+
* `rows[next].action()` only while `rows[next].choice?.applyOnMove !== false`;
|
|
10
|
+
* - `:409-417` lands a line on its current value, which is the cursor the user sees first;
|
|
11
|
+
* - `:590-592` marks the focused non-current value with `›`, and `:35-38,751` prints
|
|
12
|
+
* `←/→ choose · Enter apply` for a focused line whose row defers.
|
|
13
|
+
*
|
|
14
|
+
* `KeyDriver` below is that rule, modelled once and driven over the REAL rows the bridge emits —
|
|
15
|
+
* the `Sections` toggle, the card-style values in both modes (mixed with the host's own), and a
|
|
16
|
+
* plugin provider's own rows (a fixture with the shape the worked example used to demonstrate).
|
|
17
|
+
* It counts the actions it runs, so "a move applies
|
|
18
|
+
* nothing" and "Enter applies exactly once" are observations, not assumptions.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import assert from "node:assert/strict";
|
|
22
|
+
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
23
|
+
import { tmpdir } from "node:os";
|
|
24
|
+
import { join } from "node:path";
|
|
25
|
+
import test from "node:test";
|
|
26
|
+
|
|
27
|
+
import { BRIDGE_API_KEY, publishBridgeApi, resetBridgeApiForTests } from "../../lib/shell-api/api.ts";
|
|
28
|
+
import { armBridge } from "../../lib/shell-api/arm.ts";
|
|
29
|
+
import {
|
|
30
|
+
registerCardStyle,
|
|
31
|
+
registerRows,
|
|
32
|
+
registerSection,
|
|
33
|
+
resetBusForTests,
|
|
34
|
+
resetCardStylesForTests,
|
|
35
|
+
resetSectionsForTests,
|
|
36
|
+
} from "../../lib/shell-api/bus.ts";
|
|
37
|
+
import { installCardStyleRows, resetCardStyleRowStateForTests } from "../../lib/shell-api/card-style-rows.ts";
|
|
38
|
+
import { HOST_CARD_STYLE_SETTING } from "../../lib/shell-api/card-style-line.ts";
|
|
39
|
+
import { getCardStyleSelection } from "../../lib/shell-api/card-styles.ts";
|
|
40
|
+
import { disableCaptureBackend, resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
|
|
41
|
+
import { resetHookStateForTests } from "../../lib/shell-api/hook.ts";
|
|
42
|
+
import { getRepaintDiagnostics, resetRepaintForTests } from "../../lib/shell-api/repaint.ts";
|
|
43
|
+
import { buildRows, resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
|
|
44
|
+
import { installSectionRows } from "../../lib/shell-api/sections-rows.ts";
|
|
45
|
+
import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
|
|
46
|
+
import type { CardStyleRegistration, CustomizeRow, InlineHelpers, RowContext, SidebarSection } from "../../lib/shell-api/types.ts";
|
|
47
|
+
import { createFakeHost, type FakeRow } from "./fake-host.ts";
|
|
48
|
+
|
|
49
|
+
const inlineHelpers: InlineHelpers = {
|
|
50
|
+
input: async () => undefined,
|
|
51
|
+
confirm: async () => true,
|
|
52
|
+
capture: async () => undefined,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const isVisible = (row: FakeRow): boolean => {
|
|
56
|
+
if (row.visible === undefined) return true;
|
|
57
|
+
try {
|
|
58
|
+
return row.visible();
|
|
59
|
+
} catch {
|
|
60
|
+
return false; // the renderer fails closed
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
interface KeyDriver {
|
|
65
|
+
/** Focus one setting line: the host lands on the value that is current (`:409-417`). */
|
|
66
|
+
focus: (setting: string) => { first: number; count: number; index: number };
|
|
67
|
+
/** ←/→ inside the focused line: move the cursor, then apply ONLY if the row allows it (`:565`). */
|
|
68
|
+
arrow: (direction: -1 | 1) => Promise<void>;
|
|
69
|
+
/** Enter on the focused value: always applies (`:575-577`). */
|
|
70
|
+
enter: () => Promise<void>;
|
|
71
|
+
/** How many row actions the host has run so far. */
|
|
72
|
+
actions: () => number;
|
|
73
|
+
/** The row the cursor sits on. */
|
|
74
|
+
focused: () => FakeRow;
|
|
75
|
+
/** The line the host would draw right now (`:583-595`): `●` current, `›` the cursor. */
|
|
76
|
+
line: () => string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The host's keyboard rule over whatever rows are live right now, taken row by row from
|
|
81
|
+
* `lib/visual-customize-view.ts` — including the per-row deferral the bridge rows now carry.
|
|
82
|
+
*/
|
|
83
|
+
function keyDriver(rowsNow: () => FakeRow[]): KeyDriver {
|
|
84
|
+
const rows = (): FakeRow[] => rowsNow().filter(isVisible);
|
|
85
|
+
let setting: string | undefined;
|
|
86
|
+
let index = 0;
|
|
87
|
+
let actions = 0;
|
|
88
|
+
|
|
89
|
+
const range = (name: string): { first: number; count: number } => {
|
|
90
|
+
const all = rows();
|
|
91
|
+
const first = all.findIndex((row) => row.choice?.setting === name);
|
|
92
|
+
if (first < 0) throw new Error(`keyDriver: no setting line ${JSON.stringify(name)}`);
|
|
93
|
+
let count = 1;
|
|
94
|
+
while (first + count < all.length && all[first + count]?.choice?.setting === name) count += 1;
|
|
95
|
+
return { first, count };
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const run = async (row: FakeRow): Promise<void> => {
|
|
99
|
+
actions += 1;
|
|
100
|
+
await row.action?.(inlineHelpers);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
focus(name) {
|
|
105
|
+
const { first, count } = range(name);
|
|
106
|
+
setting = name;
|
|
107
|
+
index = first;
|
|
108
|
+
const all = rows();
|
|
109
|
+
for (let i = first; i < first + count; i += 1) {
|
|
110
|
+
try {
|
|
111
|
+
if (all[i]!.choice?.current() === true) {
|
|
112
|
+
index = i;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
} catch {
|
|
116
|
+
// An unreadable value lands on the first choice, exactly as the host does.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { first, count, index };
|
|
120
|
+
},
|
|
121
|
+
async arrow(direction) {
|
|
122
|
+
if (setting === undefined) throw new Error("keyDriver: focus a line first");
|
|
123
|
+
const { first, count } = range(setting);
|
|
124
|
+
const next = index + direction;
|
|
125
|
+
// Stepping out of the value range does nothing; the host leaves the cursor where it is.
|
|
126
|
+
if (next < first || next >= first + count) return;
|
|
127
|
+
index = next;
|
|
128
|
+
const row = rows()[next]!;
|
|
129
|
+
// THE rule under test (`visual-customize-view.ts:565`): an explicit `false` defers to Enter.
|
|
130
|
+
if (row.choice?.applyOnMove !== false) await run(row);
|
|
131
|
+
},
|
|
132
|
+
async enter() {
|
|
133
|
+
if (setting === undefined) throw new Error("keyDriver: focus a line first");
|
|
134
|
+
await run(rows()[index]!);
|
|
135
|
+
},
|
|
136
|
+
actions: () => actions,
|
|
137
|
+
focused: () => rows()[index]!,
|
|
138
|
+
line() {
|
|
139
|
+
if (setting === undefined) throw new Error("keyDriver: focus a line first");
|
|
140
|
+
const { first, count } = range(setting);
|
|
141
|
+
const marks = rows()
|
|
142
|
+
.slice(first, first + count)
|
|
143
|
+
.map((row, offset) => {
|
|
144
|
+
const current = row.choice?.current() === true;
|
|
145
|
+
const cursor = !current && first + offset === index;
|
|
146
|
+
return `${current ? "●" : cursor ? "›" : "○"} ${row.choice?.value ?? ""}`;
|
|
147
|
+
});
|
|
148
|
+
return `${setting} ${marks.join(" ")}`;
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let configHome: string;
|
|
154
|
+
let previousConfigHome: string | undefined;
|
|
155
|
+
|
|
156
|
+
test.before(() => {
|
|
157
|
+
configHome = mkdtempSync(join(tmpdir(), "gsb-apply-on-move-"));
|
|
158
|
+
previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
|
|
159
|
+
process.env.GENTLE_PI_CONFIG_HOME = configHome;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test.after(() => {
|
|
163
|
+
if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
164
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
|
|
165
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test.beforeEach(() => {
|
|
169
|
+
rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
|
|
170
|
+
delete (globalThis as unknown as Record<symbol, unknown>)[BRIDGE_API_KEY];
|
|
171
|
+
resetBridgeApiForTests();
|
|
172
|
+
resetBusForTests();
|
|
173
|
+
resetSectionsForTests();
|
|
174
|
+
resetCardStylesForTests();
|
|
175
|
+
resetCardStyleRowStateForTests();
|
|
176
|
+
resetCaptureStateForTests();
|
|
177
|
+
resetHookStateForTests();
|
|
178
|
+
resetRowBuildStateForTests();
|
|
179
|
+
resetRepaintForTests();
|
|
180
|
+
resetStoreStateForTests();
|
|
181
|
+
disableCaptureBackend();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const ctx = (): RowContext => ({ theme: undefined, configHome });
|
|
185
|
+
|
|
186
|
+
const section = (id: string, extra: Partial<SidebarSection> = {}): SidebarSection => ({
|
|
187
|
+
id,
|
|
188
|
+
title: id.toUpperCase(),
|
|
189
|
+
lines: () => [`body ${id}`],
|
|
190
|
+
...extra,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const frame = () => ({
|
|
194
|
+
top: (given: { width: number }) => "▛".repeat(given.width),
|
|
195
|
+
line: (given: { text: string }) => given.text,
|
|
196
|
+
bottom: (given: { width: number }) => "▙".repeat(given.width),
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const style = (id: string, extra: Partial<CardStyleRegistration> = {}): CardStyleRegistration => ({
|
|
200
|
+
id,
|
|
201
|
+
label: id,
|
|
202
|
+
frame: frame(),
|
|
203
|
+
...extra,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
/** The host's own `Card style` row, shaped like `extensions/gentle-shell.ts:3405-3419`. */
|
|
207
|
+
const hostStyleRow = (value: "neon" | "float", actions: string[]): FakeRow => ({
|
|
208
|
+
category: "Cards",
|
|
209
|
+
label: () => `Card style: ${value}`,
|
|
210
|
+
preview: () => ({ title: `Cards · ${value}`, sample: `${value} chrome + prompt` }),
|
|
211
|
+
action: async () => {
|
|
212
|
+
actions.push(value);
|
|
213
|
+
},
|
|
214
|
+
choice: { setting: HOST_CARD_STYLE_SETTING, value, current: () => value === "float" },
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const rowsWithHostLine = (actions: string[]): FakeRow[] => [
|
|
218
|
+
{ category: "Cards", label: "Card bash: builtin", action: () => {} },
|
|
219
|
+
{ category: "Cards", label: "Card output: builtin", action: () => {} },
|
|
220
|
+
{ category: "Layout", label: "Layout: builtin", action: () => {} },
|
|
221
|
+
hostStyleRow("neon", actions),
|
|
222
|
+
hostStyleRow("float", actions),
|
|
223
|
+
];
|
|
224
|
+
|
|
225
|
+
const sectionStorePath = (): string => join(configHome, "gentle-shell-bridge", "bridge-sections.json");
|
|
226
|
+
|
|
227
|
+
const storedSections = (): unknown => {
|
|
228
|
+
try {
|
|
229
|
+
return JSON.parse(readFileSync(sectionStorePath(), "utf8"));
|
|
230
|
+
} catch {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// ---------------------------------------------------------------------------------------------
|
|
236
|
+
// The bridge's own `Sections` toggle
|
|
237
|
+
// ---------------------------------------------------------------------------------------------
|
|
238
|
+
|
|
239
|
+
test("the Sections toggle moves with ←/→ and applies only on Enter (A1, A4)", async () => {
|
|
240
|
+
registerSection(section("loon.music", { title: "MUSIC" }));
|
|
241
|
+
installSectionRows();
|
|
242
|
+
const host = createFakeHost();
|
|
243
|
+
armBridge(host.ui);
|
|
244
|
+
host.buildMenu();
|
|
245
|
+
|
|
246
|
+
const keys = keyDriver(host.liveRows);
|
|
247
|
+
keys.focus("music");
|
|
248
|
+
|
|
249
|
+
assert.equal(keys.focused().choice?.applyOnMove, false, "the toggle defers to Enter");
|
|
250
|
+
|
|
251
|
+
await keys.arrow(1);
|
|
252
|
+
|
|
253
|
+
assert.equal(keys.focused().choice?.value, "hidden", "the cursor moved to the other value");
|
|
254
|
+
assert.equal(keys.actions(), 0, "moving applied nothing");
|
|
255
|
+
assert.deepEqual(storedSections(), undefined, "and wrote no state");
|
|
256
|
+
assert.equal(getRepaintDiagnostics().lastTrigger, undefined, "nor asked for a frame");
|
|
257
|
+
assert.equal(keys.line(), "music ● shown › hidden", "the cursor is drawn on the value Enter would apply");
|
|
258
|
+
|
|
259
|
+
await keys.enter();
|
|
260
|
+
|
|
261
|
+
assert.equal(keys.actions(), 1, "Enter applied the choice exactly once");
|
|
262
|
+
assert.deepEqual(storedSections(), {
|
|
263
|
+
schemaVersion: 1,
|
|
264
|
+
values: { sections: { "loon.music": false } },
|
|
265
|
+
});
|
|
266
|
+
assert.equal(
|
|
267
|
+
getRepaintDiagnostics().lastTrigger?.cause,
|
|
268
|
+
'section "loon.music" → hidden',
|
|
269
|
+
"and the rail repaint still happens on the write, not on the move",
|
|
270
|
+
);
|
|
271
|
+
assert.equal(keys.line(), "music ○ shown ● hidden");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// ---------------------------------------------------------------------------------------------
|
|
275
|
+
// Card styles: the fallback line and the host's own line
|
|
276
|
+
// ---------------------------------------------------------------------------------------------
|
|
277
|
+
|
|
278
|
+
test("a registered card style defers to Enter on the fallback line (A1)", async () => {
|
|
279
|
+
const host = createFakeHost();
|
|
280
|
+
armBridge(host.ui);
|
|
281
|
+
installCardStyleRows();
|
|
282
|
+
registerCardStyle(style("loon.cute", { label: "cute" }));
|
|
283
|
+
host.buildMenu();
|
|
284
|
+
|
|
285
|
+
const keys = keyDriver(host.liveRows);
|
|
286
|
+
keys.focus("Bridge card style");
|
|
287
|
+
|
|
288
|
+
await keys.arrow(1);
|
|
289
|
+
|
|
290
|
+
assert.equal(keys.focused().choice?.value, "cute", "the cursor moved onto the registered style");
|
|
291
|
+
assert.equal(keys.actions(), 0, "moving applied nothing");
|
|
292
|
+
assert.equal(getCardStyleSelection(), "native", "the stored selection is untouched");
|
|
293
|
+
assert.equal(getRepaintDiagnostics().lastTrigger, undefined, "and no surface was repainted");
|
|
294
|
+
assert.equal(keys.line(), "Bridge card style ● native › cute");
|
|
295
|
+
|
|
296
|
+
await keys.enter();
|
|
297
|
+
|
|
298
|
+
assert.equal(keys.actions(), 1, "Enter applied exactly once");
|
|
299
|
+
assert.equal(getCardStyleSelection(), "loon.cute");
|
|
300
|
+
assert.equal(getRepaintDiagnostics().lastTrigger?.cause, "card style → loon.cute");
|
|
301
|
+
assert.deepEqual(getRepaintDiagnostics().lastTrigger?.surfaces, ["conversation", "rail"]);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test("the fallback line's native value defers too (A1)", async () => {
|
|
305
|
+
const host = createFakeHost();
|
|
306
|
+
armBridge(host.ui);
|
|
307
|
+
installCardStyleRows();
|
|
308
|
+
registerCardStyle(style("loon.cute", { label: "cute" }));
|
|
309
|
+
host.buildMenu();
|
|
310
|
+
|
|
311
|
+
const keys = keyDriver(host.liveRows);
|
|
312
|
+
keys.focus("Bridge card style");
|
|
313
|
+
await keys.arrow(1);
|
|
314
|
+
await keys.enter(); // select cute first, so native is no longer current
|
|
315
|
+
assert.equal(getCardStyleSelection(), "loon.cute");
|
|
316
|
+
const before = keys.actions();
|
|
317
|
+
|
|
318
|
+
keys.focus("Bridge card style");
|
|
319
|
+
await keys.arrow(-1);
|
|
320
|
+
|
|
321
|
+
assert.equal(keys.focused().choice?.value, "native", "the cursor moved back to native");
|
|
322
|
+
assert.equal(keys.actions(), before, "moving applied nothing");
|
|
323
|
+
assert.equal(getCardStyleSelection(), "loon.cute", "cute is still selected");
|
|
324
|
+
|
|
325
|
+
await keys.enter();
|
|
326
|
+
assert.equal(keys.actions(), before + 1, "Enter applied exactly once");
|
|
327
|
+
assert.equal(getCardStyleSelection(), "native");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
test("on the host's line the host's values keep their own field and the bridge's value defers (A3)", async () => {
|
|
331
|
+
const hostActions: string[] = [];
|
|
332
|
+
const host = createFakeHost({ rows: rowsWithHostLine(hostActions) });
|
|
333
|
+
armBridge(host.ui);
|
|
334
|
+
installCardStyleRows();
|
|
335
|
+
registerCardStyle(style("loon.cute", { label: "cute" }));
|
|
336
|
+
host.buildMenu();
|
|
337
|
+
|
|
338
|
+
const live = host.liveRows();
|
|
339
|
+
const hostRows = live.filter((row) => row.choice?.setting === HOST_CARD_STYLE_SETTING);
|
|
340
|
+
assert.equal(hostRows.length, 3, "neon, float and the spliced bridge value on ONE line");
|
|
341
|
+
assert.equal(hostRows[0]?.choice?.applyOnMove, undefined, "the host's neon row is the host's");
|
|
342
|
+
assert.equal(hostRows[1]?.choice?.applyOnMove, undefined, "and so is float");
|
|
343
|
+
assert.equal(hostRows[2]?.choice?.applyOnMove, false, "the bridge's value defers to Enter");
|
|
344
|
+
|
|
345
|
+
const keys = keyDriver(host.liveRows);
|
|
346
|
+
keys.focus(HOST_CARD_STYLE_SETTING);
|
|
347
|
+
|
|
348
|
+
// The host's own value applies on the move, exactly as before: the bridge did not rewrite it.
|
|
349
|
+
await keys.arrow(-1);
|
|
350
|
+
assert.deepEqual(hostActions, ["neon"], "the host's own action ran on the move");
|
|
351
|
+
keys.focus(HOST_CARD_STYLE_SETTING);
|
|
352
|
+
|
|
353
|
+
// The bridge's value on the SAME line only takes focus.
|
|
354
|
+
await keys.arrow(1);
|
|
355
|
+
await keys.arrow(1);
|
|
356
|
+
assert.equal(keys.focused().choice?.value, "cute", "the cursor reached the bridge value");
|
|
357
|
+
assert.equal(getCardStyleSelection(), "native", "moving onto it applied nothing");
|
|
358
|
+
assert.deepEqual(hostActions, ["neon"], "and ran no host action either");
|
|
359
|
+
|
|
360
|
+
await keys.enter();
|
|
361
|
+
assert.equal(getCardStyleSelection(), "loon.cute", "Enter applied the bridge value");
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// ---------------------------------------------------------------------------------------------
|
|
365
|
+
// A plugin's own provider rows (a fixture, not the worked example)
|
|
366
|
+
// ---------------------------------------------------------------------------------------------
|
|
367
|
+
//
|
|
368
|
+
// The example contributes a tool DESIGN now, and the bridge owns the design line: its rows are not a
|
|
369
|
+
// provider's, so the provider path is driven by a fixture with the same shape and the same rules.
|
|
370
|
+
// Nothing here is specific to bash; the values are just two choices on one line.
|
|
371
|
+
|
|
372
|
+
test("a plugin's provider rows move without applying and apply on Enter (A1, A2)", async () => {
|
|
373
|
+
publishBridgeApi();
|
|
374
|
+
let stored = "native";
|
|
375
|
+
const values = ["native", "bash heading"];
|
|
376
|
+
registerRows({
|
|
377
|
+
id: "loon.apply-on-move",
|
|
378
|
+
category: "Cards",
|
|
379
|
+
name: "Loon example",
|
|
380
|
+
rows: () =>
|
|
381
|
+
values.map((value) => ({
|
|
382
|
+
category: "Cards",
|
|
383
|
+
label: "Bash design",
|
|
384
|
+
choice: {
|
|
385
|
+
setting: "Bash design",
|
|
386
|
+
value,
|
|
387
|
+
current: (): boolean => stored === value,
|
|
388
|
+
},
|
|
389
|
+
action: async (): Promise<void> => {
|
|
390
|
+
stored = value;
|
|
391
|
+
},
|
|
392
|
+
})),
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
const rows = buildRows(ctx()).rows;
|
|
396
|
+
const design = rows.filter((row) => row.choice?.setting === "Bash design");
|
|
397
|
+
assert.deepEqual(
|
|
398
|
+
design.map((row) => row.choice?.value),
|
|
399
|
+
["native", "bash heading"],
|
|
400
|
+
"the provider's two values are on one line",
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
const keys = keyDriver(() => rows);
|
|
404
|
+
keys.focus("Bash design");
|
|
405
|
+
|
|
406
|
+
await keys.arrow(1);
|
|
407
|
+
|
|
408
|
+
assert.equal(keys.focused().choice?.value, "bash heading", "the cursor moved onto the other value");
|
|
409
|
+
assert.equal(keys.actions(), 0, "moving applied nothing");
|
|
410
|
+
assert.equal(design[0]?.choice?.current(), true, "the stored value is still the first one");
|
|
411
|
+
assert.equal(design[1]?.choice?.current(), false);
|
|
412
|
+
assert.equal(keys.line(), "Bash design ● native › bash heading");
|
|
413
|
+
|
|
414
|
+
await keys.enter();
|
|
415
|
+
|
|
416
|
+
assert.equal(keys.actions(), 1, "Enter applied exactly once");
|
|
417
|
+
assert.equal(design[0]?.choice?.current(), false, "and the stored value became the other one");
|
|
418
|
+
assert.equal(design[1]?.choice?.current(), true);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
// ---------------------------------------------------------------------------------------------
|
|
422
|
+
// The build boundary: every provider choice defers, and the provider's objects are untouched
|
|
423
|
+
// ---------------------------------------------------------------------------------------------
|
|
424
|
+
|
|
425
|
+
test("the build defers every provider choice on a copy, never mutating the provider's row (A2)", () => {
|
|
426
|
+
const authored: CustomizeRow = {
|
|
427
|
+
category: "Cards",
|
|
428
|
+
label: "Loon mode",
|
|
429
|
+
choice: { setting: "Loon mode", value: "first", current: () => true },
|
|
430
|
+
action: () => {},
|
|
431
|
+
};
|
|
432
|
+
const alreadyDeferring: CustomizeRow = {
|
|
433
|
+
category: "Cards",
|
|
434
|
+
label: "Loon other",
|
|
435
|
+
choice: { setting: "Loon other", value: "one", current: () => true, applyOnMove: false },
|
|
436
|
+
action: () => {},
|
|
437
|
+
};
|
|
438
|
+
const explicitImmediate: CustomizeRow = {
|
|
439
|
+
category: "Cards",
|
|
440
|
+
label: "Loon third",
|
|
441
|
+
choice: { setting: "Loon third", value: "one", current: () => true, applyOnMove: true },
|
|
442
|
+
action: () => {},
|
|
443
|
+
};
|
|
444
|
+
const plain: CustomizeRow = { category: "Cards", label: "Loon action", action: () => {} };
|
|
445
|
+
registerRows({
|
|
446
|
+
id: "test.apply-on-move",
|
|
447
|
+
category: "Cards",
|
|
448
|
+
rows: () => [authored, alreadyDeferring, explicitImmediate, plain],
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
const built = buildRows(ctx()).rows;
|
|
452
|
+
|
|
453
|
+
assert.equal(built.length, 4, "no row was dropped");
|
|
454
|
+
for (const row of built) {
|
|
455
|
+
if (row.choice !== undefined) {
|
|
456
|
+
assert.equal(row.choice.applyOnMove, false, `${String(row.choice.setting)} defers to Enter`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// The emitted copy is not the provider's row, and the provider's own objects are untouched.
|
|
461
|
+
assert.notEqual(built[0], authored, "the row reached the host as a copy");
|
|
462
|
+
assert.notEqual(built[0]?.choice, authored.choice, "and so did its choice");
|
|
463
|
+
assert.equal(authored.choice?.applyOnMove, undefined, "the provider's choice was not mutated");
|
|
464
|
+
assert.equal(built[0]?.label, authored.label, "every other field is carried as the same reference");
|
|
465
|
+
assert.equal(built[0]?.action, authored.action);
|
|
466
|
+
|
|
467
|
+
assert.equal(built[1], alreadyDeferring, "an authored false already conforms: no copy is needed");
|
|
468
|
+
assert.equal(explicitImmediate.choice?.applyOnMove, true, "an authored true is not mutated either");
|
|
469
|
+
assert.equal(built[2]?.choice?.applyOnMove, false, "but the emitted copy defers");
|
|
470
|
+
// A row without a choice is a BUTTON row (S16). The bridge hands the host a copy so it can contain
|
|
471
|
+
// a failing `action`; nothing else about it changes and the provider's object is never mutated.
|
|
472
|
+
assert.notEqual(built[3], plain, "a button row is a copy, so its action can be contained (S16)");
|
|
473
|
+
assert.equal(built[3]?.label, plain.label, "its label is carried as the same reference");
|
|
474
|
+
assert.notEqual(built[3]?.action, plain.action, "its action is the contained wrapper");
|
|
475
|
+
assert.equal(built[3]?.choice, undefined, "no choice is invented for a button");
|
|
476
|
+
assert.deepEqual(Object.keys(plain).sort(), ["action", "category", "label"], "the provider's row is not mutated");
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
test("a placed provider's rows defer to Enter, and the host's Card style pair is never split", async () => {
|
|
480
|
+
const hostActions: string[] = [];
|
|
481
|
+
const host = createFakeHost({ rows: rowsWithHostLine(hostActions) });
|
|
482
|
+
armBridge(host.ui);
|
|
483
|
+
installCardStyleRows();
|
|
484
|
+
registerCardStyle(style("loon.cute", { label: "cute" }));
|
|
485
|
+
registerRows({
|
|
486
|
+
id: "loon.top",
|
|
487
|
+
category: "Cards",
|
|
488
|
+
placement: "start",
|
|
489
|
+
rows: () => [
|
|
490
|
+
{
|
|
491
|
+
category: "Cards",
|
|
492
|
+
label: "Loon mode",
|
|
493
|
+
choice: { setting: "Loon mode", value: "on", current: () => true },
|
|
494
|
+
action: () => {},
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
category: "Cards",
|
|
498
|
+
label: "Loon mode",
|
|
499
|
+
choice: { setting: "Loon mode", value: "off", current: () => false },
|
|
500
|
+
action: () => {},
|
|
501
|
+
},
|
|
502
|
+
],
|
|
503
|
+
});
|
|
504
|
+
host.buildMenu();
|
|
505
|
+
|
|
506
|
+
const live = host.liveRows();
|
|
507
|
+
const styleRows = live.filter((row) => row.choice?.setting === HOST_CARD_STYLE_SETTING);
|
|
508
|
+
const styleIndices = live
|
|
509
|
+
.map((row, index) => (row.choice?.setting === HOST_CARD_STYLE_SETTING ? index : -1))
|
|
510
|
+
.filter((index) => index !== -1);
|
|
511
|
+
assert.equal(styleRows.length, 3, "the host's neon/float pair still holds the bridge's value");
|
|
512
|
+
assert.deepEqual(
|
|
513
|
+
styleIndices,
|
|
514
|
+
[styleIndices[0], (styleIndices[0] ?? 0) + 1, (styleIndices[0] ?? 0) + 2],
|
|
515
|
+
"the pair plus the bridge value stay one consecutive line",
|
|
516
|
+
);
|
|
517
|
+
assert.deepEqual(
|
|
518
|
+
styleRows.map((row) => row.choice?.value),
|
|
519
|
+
["neon", "float", "cute"],
|
|
520
|
+
"and the bridge's value still lands inside its pair",
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
const keys = keyDriver(host.liveRows);
|
|
524
|
+
keys.focus("Loon mode");
|
|
525
|
+
await keys.arrow(1);
|
|
526
|
+
assert.equal(keys.focused().choice?.value, "off", "the cursor moved inside the placed block");
|
|
527
|
+
assert.equal(keys.actions(), 0, "moving applied nothing");
|
|
528
|
+
assert.equal(keys.focused().choice?.applyOnMove, false, "a placed row still defers to Enter");
|
|
529
|
+
});
|