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,361 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* S1 — a message design that FOLLOWS a tool design's switch (0.12.0).
|
|
3
|
+
*
|
|
4
|
+
* The consumer's case in one sentence: the user already picked `activity` on the `Card tags` line, and
|
|
5
|
+
* that same value must turn the two alert designs on — no second switch, no seed, no writing the other
|
|
6
|
+
* store. So a design may declare `follows: { line, id }`, its activation is answered LIVE from that
|
|
7
|
+
* tool line, and nothing about it costs anything while the follow answers something else.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import assert from "node:assert/strict";
|
|
11
|
+
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import test from "node:test";
|
|
15
|
+
|
|
16
|
+
import { adoptCustomMessages } from "../../lib/shell-api/message-design-adoption.ts";
|
|
17
|
+
import { resetBusForTests } from "../../lib/shell-api/bus.ts";
|
|
18
|
+
import {
|
|
19
|
+
getMessageDesignSelectionReads,
|
|
20
|
+
registerMessageDesign,
|
|
21
|
+
resetMessageDesignSelectionReads,
|
|
22
|
+
resetMessageDesignsForTests,
|
|
23
|
+
resolveMessageDesignFollow,
|
|
24
|
+
resolveMessageDesignSelection,
|
|
25
|
+
setMessageDesignSelection,
|
|
26
|
+
} from "../../lib/shell-api/message-designs.ts";
|
|
27
|
+
import {
|
|
28
|
+
installMessageDesignRows,
|
|
29
|
+
messageDesignLineNames,
|
|
30
|
+
messageDesignRows,
|
|
31
|
+
resetMessageDesignRowStateForTests,
|
|
32
|
+
} from "../../lib/shell-api/message-design-rows.ts";
|
|
33
|
+
import { resetNoticesForTests } from "../../lib/shell-api/notices.ts";
|
|
34
|
+
import { resetPluginLinesForTests } from "../../lib/shell-api/plugin-lines.ts";
|
|
35
|
+
import { resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
|
|
36
|
+
import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
|
|
37
|
+
import {
|
|
38
|
+
registerToolDesign,
|
|
39
|
+
resetToolDesignsForTests,
|
|
40
|
+
setToolDesignLineSelection,
|
|
41
|
+
} from "../../lib/shell-api/tool-designs.ts";
|
|
42
|
+
import type { CustomizeRow, MessageDesignRegistration } from "../../lib/shell-api/types.ts";
|
|
43
|
+
|
|
44
|
+
let configHome: string;
|
|
45
|
+
let previousConfigHome: string | undefined;
|
|
46
|
+
|
|
47
|
+
test.before(() => {
|
|
48
|
+
configHome = mkdtempSync(join(tmpdir(), "gsb-message-follows-"));
|
|
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
|
+
resetMessageDesignsForTests();
|
|
62
|
+
resetMessageDesignRowStateForTests();
|
|
63
|
+
resetToolDesignsForTests();
|
|
64
|
+
resetStoreStateForTests();
|
|
65
|
+
resetNoticesForTests();
|
|
66
|
+
resetPluginLinesForTests();
|
|
67
|
+
resetRowBuildStateForTests();
|
|
68
|
+
resetBusForTests();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const BUDGET = "gentle-pi.exploration-budget";
|
|
72
|
+
const REMINDER = "gentle-pi.verifier-settle-reminder";
|
|
73
|
+
|
|
74
|
+
/** The consumer's own tool line, and the value its user has to pick. */
|
|
75
|
+
const TOOL_LINE = "tags";
|
|
76
|
+
const TOOL_DESIGN_ID = "activity";
|
|
77
|
+
|
|
78
|
+
const toolLine = (): (() => void) =>
|
|
79
|
+
registerToolDesign({
|
|
80
|
+
line: TOOL_LINE,
|
|
81
|
+
tools: ["bash", "read"],
|
|
82
|
+
id: TOOL_DESIGN_ID,
|
|
83
|
+
label: "activity",
|
|
84
|
+
apply: (lines: readonly string[]) => [...lines],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const follows = (
|
|
88
|
+
extra: Partial<MessageDesignRegistration> = {},
|
|
89
|
+
): MessageDesignRegistration => ({
|
|
90
|
+
customType: BUDGET,
|
|
91
|
+
id: "loon.budget",
|
|
92
|
+
label: "budget",
|
|
93
|
+
follows: { line: TOOL_LINE, id: TOOL_DESIGN_ID },
|
|
94
|
+
apply: (lines: readonly string[]) => [...lines],
|
|
95
|
+
...extra,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const toolStorePath = (): string =>
|
|
99
|
+
join(configHome, "gentle-shell-bridge", "bridge-tool-designs.json");
|
|
100
|
+
|
|
101
|
+
// ---------------------------------------------------------------------------------------------
|
|
102
|
+
// The capability
|
|
103
|
+
// ---------------------------------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
test("S1: while the followed switch answers that design, the message design is the one selected", () => {
|
|
106
|
+
toolLine();
|
|
107
|
+
registerMessageDesign(follows());
|
|
108
|
+
setToolDesignLineSelection("line", TOOL_LINE, TOOL_DESIGN_ID);
|
|
109
|
+
|
|
110
|
+
assert.deepEqual(
|
|
111
|
+
resolveMessageDesignSelection(BUDGET).kind,
|
|
112
|
+
"design",
|
|
113
|
+
"the value the user already picked turns it on",
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test("S1: while it answers something else, the message stays the host's own — no second switch", () => {
|
|
118
|
+
toolLine();
|
|
119
|
+
registerMessageDesign(follows());
|
|
120
|
+
|
|
121
|
+
// Nothing picked on the tool line: `native` (the host's own output), not a second choice to make.
|
|
122
|
+
assert.deepEqual(resolveMessageDesignSelection(BUDGET), { kind: "native" });
|
|
123
|
+
|
|
124
|
+
setToolDesignLineSelection("line", TOOL_LINE, "native");
|
|
125
|
+
assert.deepEqual(resolveMessageDesignSelection(BUDGET), { kind: "native" });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("S1: the follow is answered LIVE, so flipping the switch flips the message with no re-registration", () => {
|
|
129
|
+
toolLine();
|
|
130
|
+
registerMessageDesign(follows());
|
|
131
|
+
|
|
132
|
+
setToolDesignLineSelection("line", TOOL_LINE, TOOL_DESIGN_ID);
|
|
133
|
+
assert.equal(resolveMessageDesignSelection(BUDGET).kind, "design");
|
|
134
|
+
setToolDesignLineSelection("line", TOOL_LINE, "native");
|
|
135
|
+
assert.equal(resolveMessageDesignSelection(BUDGET).kind, "native");
|
|
136
|
+
setToolDesignLineSelection("line", TOOL_LINE, TOOL_DESIGN_ID);
|
|
137
|
+
assert.equal(resolveMessageDesignSelection(BUDGET).kind, "design");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("S1: a follow naming no live tool line answers nothing, and says so", () => {
|
|
141
|
+
registerMessageDesign(follows({ follows: { line: "nobody-registered-this", id: TOOL_DESIGN_ID } }));
|
|
142
|
+
|
|
143
|
+
assert.deepEqual(resolveMessageDesignSelection(BUDGET), { kind: "native" });
|
|
144
|
+
assert.deepEqual(resolveMessageDesignFollow({ line: "nobody-registered-this", id: TOOL_DESIGN_ID }), {
|
|
145
|
+
line: "nobody-registered-this",
|
|
146
|
+
found: false,
|
|
147
|
+
answered: "none",
|
|
148
|
+
active: false,
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("S1: the follow is READ, never written: the tool document is byte-identical afterwards", () => {
|
|
153
|
+
toolLine();
|
|
154
|
+
setToolDesignLineSelection("line", TOOL_LINE, TOOL_DESIGN_ID);
|
|
155
|
+
registerMessageDesign(follows());
|
|
156
|
+
const before = readFileSync(toolStorePath(), "utf8");
|
|
157
|
+
|
|
158
|
+
resetMessageDesignSelectionReads();
|
|
159
|
+
resolveMessageDesignSelection(BUDGET);
|
|
160
|
+
resolveMessageDesignFollow({ line: TOOL_LINE, id: TOOL_DESIGN_ID });
|
|
161
|
+
|
|
162
|
+
assert.equal(readFileSync(toolStorePath(), "utf8"), before, "reading a switch never rewrites it");
|
|
163
|
+
assert.equal(
|
|
164
|
+
getMessageDesignSelectionReads(),
|
|
165
|
+
0,
|
|
166
|
+
"and the message document is never opened: the follow decides, so there is nothing to look up",
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("S1: the reader says which line answered what, for the diagnostics record", () => {
|
|
171
|
+
toolLine();
|
|
172
|
+
setToolDesignLineSelection("line", TOOL_LINE, "native");
|
|
173
|
+
assert.deepEqual(resolveMessageDesignFollow({ line: TOOL_LINE, id: TOOL_DESIGN_ID }), {
|
|
174
|
+
line: TOOL_LINE,
|
|
175
|
+
found: true,
|
|
176
|
+
answered: "native",
|
|
177
|
+
active: false,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
setToolDesignLineSelection("line", TOOL_LINE, TOOL_DESIGN_ID);
|
|
181
|
+
assert.deepEqual(resolveMessageDesignFollow({ line: TOOL_LINE, id: TOOL_DESIGN_ID }), {
|
|
182
|
+
line: TOOL_LINE,
|
|
183
|
+
found: true,
|
|
184
|
+
answered: TOOL_DESIGN_ID,
|
|
185
|
+
active: true,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// ---------------------------------------------------------------------------------------------
|
|
190
|
+
// No second switch, and nothing paid when the follow answers nothing
|
|
191
|
+
// ---------------------------------------------------------------------------------------------
|
|
192
|
+
|
|
193
|
+
test("S1: a following design offers NO value on the customize line", () => {
|
|
194
|
+
toolLine();
|
|
195
|
+
registerMessageDesign(follows());
|
|
196
|
+
installMessageDesignRows();
|
|
197
|
+
|
|
198
|
+
assert.deepEqual(messageDesignRows(), [], "no row: the tool switch is the only switch");
|
|
199
|
+
assert.deepEqual(messageDesignLineNames(), []);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("S1: a line of only following designs contributes no row, and a line with a real design keeps its own", () => {
|
|
203
|
+
toolLine();
|
|
204
|
+
registerMessageDesign([
|
|
205
|
+
follows(),
|
|
206
|
+
follows({ customType: REMINDER, id: "loon.reminder", follows: { line: TOOL_LINE, id: TOOL_DESIGN_ID } }),
|
|
207
|
+
]);
|
|
208
|
+
assert.deepEqual(messageDesignRows(), [], "two follows, still no switch of their own");
|
|
209
|
+
|
|
210
|
+
registerMessageDesign({
|
|
211
|
+
customType: "loon.some-other-message",
|
|
212
|
+
id: "loon.plain",
|
|
213
|
+
label: "plain",
|
|
214
|
+
apply: (lines: readonly string[]) => [...lines],
|
|
215
|
+
});
|
|
216
|
+
const values = messageDesignRows().map((row: CustomizeRow) => row.choice?.value);
|
|
217
|
+
assert.deepEqual(values, ["default", "plain"], "a design with its own switch keeps it");
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// ---------------------------------------------------------------------------------------------
|
|
221
|
+
// Backwards compatibility
|
|
222
|
+
// ---------------------------------------------------------------------------------------------
|
|
223
|
+
|
|
224
|
+
test("S1: a 0.11.0 registration without `follows` behaves exactly as it did", () => {
|
|
225
|
+
registerMessageDesign({
|
|
226
|
+
customType: BUDGET,
|
|
227
|
+
id: "loon.budget",
|
|
228
|
+
label: "budget",
|
|
229
|
+
apply: (lines: readonly string[]) => [...lines],
|
|
230
|
+
});
|
|
231
|
+
setMessageDesignSelection(BUDGET, "loon.budget");
|
|
232
|
+
|
|
233
|
+
assert.equal(resolveMessageDesignSelection(BUDGET).kind, "design");
|
|
234
|
+
assert.deepEqual(
|
|
235
|
+
messageDesignRows().map((row: CustomizeRow) => row.choice?.value),
|
|
236
|
+
["default", "budget"],
|
|
237
|
+
"its own switch, unchanged",
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("S1: a malformed follow is refused whole, and stores nothing", () => {
|
|
242
|
+
for (const bad of [
|
|
243
|
+
{ line: "", id: TOOL_DESIGN_ID },
|
|
244
|
+
{ line: TOOL_LINE, id: "" },
|
|
245
|
+
{ line: TOOL_LINE },
|
|
246
|
+
{ id: TOOL_DESIGN_ID },
|
|
247
|
+
]) {
|
|
248
|
+
assert.throws(
|
|
249
|
+
() => registerMessageDesign(follows({ follows: bad as never })),
|
|
250
|
+
/invalid message design/u,
|
|
251
|
+
JSON.stringify(bad),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
assert.deepEqual(messageDesignRows(), []);
|
|
255
|
+
assert.deepEqual(resolveMessageDesignSelection(BUDGET), { kind: "native" });
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// ---------------------------------------------------------------------------------------------
|
|
259
|
+
// The flip reaches a message already on screen
|
|
260
|
+
// ---------------------------------------------------------------------------------------------
|
|
261
|
+
|
|
262
|
+
test("S1: flipping the Card tags switch repaints a message already on screen", () => {
|
|
263
|
+
toolLine();
|
|
264
|
+
registerMessageDesign(follows({ apply: () => ["design row"] }));
|
|
265
|
+
|
|
266
|
+
// The smallest faithful Pi message: the renderer is resolved at rebuild, the frame renders it.
|
|
267
|
+
const child = {
|
|
268
|
+
message: { customType: BUDGET, content: "body" },
|
|
269
|
+
customRenderer: ((): unknown => ({ render: () => ["host frame"] })) as unknown,
|
|
270
|
+
component: undefined as unknown,
|
|
271
|
+
rebuild(this: { component: unknown; message: unknown; customRenderer: unknown }): void {
|
|
272
|
+
this.component =
|
|
273
|
+
typeof this.customRenderer === "function"
|
|
274
|
+
? (this.customRenderer as (m: unknown, o: unknown, t: unknown) => unknown)(
|
|
275
|
+
this.message,
|
|
276
|
+
{},
|
|
277
|
+
{},
|
|
278
|
+
)
|
|
279
|
+
: undefined;
|
|
280
|
+
},
|
|
281
|
+
invalidate(): void {
|
|
282
|
+
this.rebuild();
|
|
283
|
+
},
|
|
284
|
+
render(width: number): readonly string[] {
|
|
285
|
+
const component = this.component as { render(w: number): readonly string[] } | undefined;
|
|
286
|
+
return component === undefined ? ["pi box"] : component.render(width);
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
child.rebuild();
|
|
290
|
+
const chat = { children: [child] };
|
|
291
|
+
|
|
292
|
+
adoptCustomMessages(chat);
|
|
293
|
+
assert.deepEqual(child.render(40), ["host frame"], "nothing picked: the host's own frame");
|
|
294
|
+
|
|
295
|
+
setToolDesignLineSelection("line", TOOL_LINE, TOOL_DESIGN_ID);
|
|
296
|
+
adoptCustomMessages(chat);
|
|
297
|
+
assert.deepEqual(child.render(40), ["design row"], "the value the user already picked turns it on");
|
|
298
|
+
|
|
299
|
+
setToolDesignLineSelection("line", TOOL_LINE, "native");
|
|
300
|
+
adoptCustomMessages(chat);
|
|
301
|
+
assert.deepEqual(child.render(40), ["host frame"], "and off again, with the host's own frame");
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// ---------------------------------------------------------------------------------------------
|
|
305
|
+
// The report answers "why is my design not painting?"
|
|
306
|
+
// ---------------------------------------------------------------------------------------------
|
|
307
|
+
|
|
308
|
+
// ---------------------------------------------------------------------------------------------
|
|
309
|
+
// 0.12.1 — a stale message-side value cannot veto an active follow (the case 0.12.0 was built for)
|
|
310
|
+
// ---------------------------------------------------------------------------------------------
|
|
311
|
+
|
|
312
|
+
test("S1: a stale stored id in the message document cannot veto an active follow", () => {
|
|
313
|
+
toolLine();
|
|
314
|
+
registerMessageDesign(follows());
|
|
315
|
+
// What a disposed 0.11.0 design leaves behind: its id is still stored for this custom type.
|
|
316
|
+
setMessageDesignSelection(BUDGET, "stale.previous-design");
|
|
317
|
+
setToolDesignLineSelection("line", TOOL_LINE, TOOL_DESIGN_ID);
|
|
318
|
+
|
|
319
|
+
const resolved = resolveMessageDesignSelection(BUDGET);
|
|
320
|
+
assert.equal(resolved.kind, "design", "the follow decides, whatever the message document holds");
|
|
321
|
+
assert.equal(resolved.kind === "design" ? resolved.design.id : "", "loon.budget");
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test("S1: an active follow wins over a stale id even when the followed line has other designs", () => {
|
|
325
|
+
toolLine();
|
|
326
|
+
registerToolDesign({
|
|
327
|
+
line: TOOL_LINE,
|
|
328
|
+
tools: ["read"],
|
|
329
|
+
id: "plain",
|
|
330
|
+
label: "plain",
|
|
331
|
+
apply: (lines: readonly string[]) => [...lines],
|
|
332
|
+
});
|
|
333
|
+
registerMessageDesign(follows());
|
|
334
|
+
setMessageDesignSelection(BUDGET, "loon.removed-long-ago");
|
|
335
|
+
setToolDesignLineSelection("line", TOOL_LINE, TOOL_DESIGN_ID);
|
|
336
|
+
|
|
337
|
+
assert.equal(resolveMessageDesignSelection(BUDGET).kind, "design");
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test("S4: a claimed alert whose follow answers nothing reads NO store at all", () => {
|
|
341
|
+
toolLine();
|
|
342
|
+
registerMessageDesign(follows()); // claimed, and the tool line answers something else
|
|
343
|
+
resetMessageDesignSelectionReads();
|
|
344
|
+
|
|
345
|
+
assert.deepEqual(resolveMessageDesignSelection(BUDGET), { kind: "native" });
|
|
346
|
+
assert.equal(
|
|
347
|
+
getMessageDesignSelectionReads(),
|
|
348
|
+
0,
|
|
349
|
+
"no message-document read: the follow is the only thing that could select it",
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("S4: and it still reads nothing on the second pass", () => {
|
|
354
|
+
toolLine();
|
|
355
|
+
registerMessageDesign(follows());
|
|
356
|
+
resetMessageDesignSelectionReads();
|
|
357
|
+
resolveMessageDesignSelection(BUDGET);
|
|
358
|
+
const after = getMessageDesignSelectionReads();
|
|
359
|
+
resolveMessageDesignSelection(BUDGET);
|
|
360
|
+
assert.equal(getMessageDesignSelectionReads() - after, 0);
|
|
361
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { mkdtempSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { stripVTControlCharacters as strip } from 'node:util';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import test from 'node:test';
|
|
8
|
+
|
|
9
|
+
// Run with PI_NODE_MODULES pointing to the installed Pi 1.6.0 distribution's node_modules.
|
|
10
|
+
// BRIDGE_SOURCE is only for running the unmodified test beside an isolated source archive.
|
|
11
|
+
const pi = process.env.PI_NODE_MODULES;
|
|
12
|
+
const bridge = process.env.BRIDGE_SOURCE;
|
|
13
|
+
const src = file => import(bridge
|
|
14
|
+
? pathToFileURL(resolve(bridge, 'src', file))
|
|
15
|
+
: new URL(`../../lib/shell-api/${file}`, import.meta.url));
|
|
16
|
+
const piImport = file => import(pathToFileURL(resolve(pi, '@earendil-works', file)));
|
|
17
|
+
|
|
18
|
+
if (!pi) {
|
|
19
|
+
test('Pi message-design integration', { skip: 'set PI_NODE_MODULES to Pi 1.6.0' }, () => {});
|
|
20
|
+
} else {
|
|
21
|
+
const { CustomMessageComponent: Custom } = await piImport('pi-coding-agent/dist/modes/interactive/components/custom-message.js');
|
|
22
|
+
const { initTheme } = await piImport('pi-coding-agent/dist/modes/interactive/theme/theme.js');
|
|
23
|
+
const { Container } = await piImport('pi-tui/dist/tui.js');
|
|
24
|
+
const { adoptCustomMessages: adopt, resetMessageDesignAdoptionForTests } = await src('message-design-adoption.ts');
|
|
25
|
+
const { getMessageDesignSelectionReads, registerMessageDesign, resetMessageDesignsForTests, setMessageDesignSelection } = await src('message-designs.ts');
|
|
26
|
+
const { snapshotProviders, registerRows, resetBusForTests, registerTransform } = await src('bus.ts');
|
|
27
|
+
const { installMessageDesignRows, resetMessageDesignRowStateForTests } = await src('message-design-rows.ts');
|
|
28
|
+
const { applyTransforms } = await src('transform-pipeline.ts');
|
|
29
|
+
const { TuiMainScreen } = await piImport('pi-tui/dist/tui-main-screen.js');
|
|
30
|
+
const { TuiAltScreen } = await piImport('pi-tui/dist/tui-alt-screen.js');
|
|
31
|
+
initTheme('dark');
|
|
32
|
+
|
|
33
|
+
test.beforeEach(() => {
|
|
34
|
+
resetMessageDesignRowStateForTests();
|
|
35
|
+
resetMessageDesignAdoptionForTests();
|
|
36
|
+
resetMessageDesignsForTests();
|
|
37
|
+
resetBusForTests();
|
|
38
|
+
process.env.GENTLE_PI_CONFIG_HOME = mkdtempSync(join(tmpdir(), 'message-design-pi-'));
|
|
39
|
+
});
|
|
40
|
+
const message = (customType, content = 'keep the full body') => ({ role: 'custom', display: true, customType, content });
|
|
41
|
+
const select = (customType, apply) => {
|
|
42
|
+
const off = registerMessageDesign({ customType, id: 'probe.panel', label: 'panel', apply });
|
|
43
|
+
setMessageDesignSelection(customType, 'probe.panel');
|
|
44
|
+
return off;
|
|
45
|
+
};
|
|
46
|
+
const draw = (chat, width = 48) => { adopt(chat); return chat.render(width); };
|
|
47
|
+
const terminal = () => ({ columns: 24, rows: 54, start() {}, stop() {}, hideCursor() {}, showCursor() {}, write() {} });
|
|
48
|
+
|
|
49
|
+
test('S2/S3: failed design preserves Pi fallback when an expanded host renderer declines', () => {
|
|
50
|
+
const m = message('conditional');
|
|
51
|
+
const host = (_m, options) => options.expanded ? undefined : { render: () => ['host frame'] };
|
|
52
|
+
const chat = new Container();
|
|
53
|
+
const child = new Custom(m, host), control = new Custom(m, host);
|
|
54
|
+
chat.addChild(child);
|
|
55
|
+
select(m.customType, () => { throw Error('could not paint'); });
|
|
56
|
+
assert.deepEqual(draw(chat), control.render(48));
|
|
57
|
+
child.setExpanded(true);
|
|
58
|
+
control.setExpanded(true);
|
|
59
|
+
// The declined build left Pi's own box unpopulated, so the frame that fails can only show the
|
|
60
|
+
// message's plain body; the recovery is that the failed design is not retried, which lets Pi run
|
|
61
|
+
// its default path and populate the box the next frame renders.
|
|
62
|
+
const native = control.render(48);
|
|
63
|
+
const first = draw(chat);
|
|
64
|
+
if (JSON.stringify(first) !== JSON.stringify(native)) {
|
|
65
|
+
assert.deepEqual(first, ['[conditional]', '', 'keep the full body']);
|
|
66
|
+
}
|
|
67
|
+
assert.deepEqual(draw(chat), native, 'the next ordinary frame recovers without invalidate()');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('S2/L7: text parts reach a design that uses the supplied body', () => {
|
|
71
|
+
const m = message('structured', [{ type: 'text', text: 'first' }, { type: 'text', text: 'last' }]);
|
|
72
|
+
const chat = new Container();
|
|
73
|
+
chat.addChild(new Custom(m));
|
|
74
|
+
select(m.customType, lines => [...lines]);
|
|
75
|
+
assert.deepEqual(draw(chat).slice(1), ['[structured]', '', 'first', 'last']);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('S4: reconciliation of another conversation cannot strand an adopted message', () => {
|
|
79
|
+
const m = message('revisit');
|
|
80
|
+
const host = () => ({ render: () => ['native'] });
|
|
81
|
+
const first = new Container(), second = new Container();
|
|
82
|
+
const child = new Custom(m, host);
|
|
83
|
+
first.addChild(child);
|
|
84
|
+
const off = select(m.customType, () => ['design']);
|
|
85
|
+
draw(first);
|
|
86
|
+
draw(second);
|
|
87
|
+
off();
|
|
88
|
+
const reads = getMessageDesignSelectionReads();
|
|
89
|
+
assert.deepEqual(draw(first), ['', 'native']);
|
|
90
|
+
assert.equal(child.customRenderer, host);
|
|
91
|
+
assert.equal(getMessageDesignSelectionReads(), reads);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('reserved provider ids leave the bus untouched and the message switch available', () => {
|
|
95
|
+
const before = snapshotProviders();
|
|
96
|
+
for (const id of [
|
|
97
|
+
'bridge.sections', 'bridge.card-styles', 'bridge.tool-designs', 'bridge.message-designs',
|
|
98
|
+
]) {
|
|
99
|
+
assert.throws(
|
|
100
|
+
() => registerRows({ id, category: 'Cards', rows: () => [] }),
|
|
101
|
+
/belongs to the bridge's own line/,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
assert.deepEqual(snapshotProviders(), before, 'nothing stored, nothing replaced');
|
|
105
|
+
installMessageDesignRows();
|
|
106
|
+
assert.equal(
|
|
107
|
+
snapshotProviders().some(p => p.id === 'bridge.message-designs'),
|
|
108
|
+
false,
|
|
109
|
+
'no design yet: no provider at all',
|
|
110
|
+
);
|
|
111
|
+
select('late-menu', () => ['design']);
|
|
112
|
+
const line = snapshotProviders().find(p => p.id === 'bridge.message-designs').rows();
|
|
113
|
+
assert.deepEqual(
|
|
114
|
+
line.map(row => row.choice?.value),
|
|
115
|
+
['default', 'panel'],
|
|
116
|
+
'the first design installs the line: default first, then the design',
|
|
117
|
+
);
|
|
118
|
+
assert.ok(
|
|
119
|
+
snapshotProviders().flatMap(p => p.rows()).some(r => r.choice?.value === 'panel'),
|
|
120
|
+
'and the design switch is there',
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('L7: design keeps all rows; pipeline and fullscreen fit columns; regular diff renderer rejects overflow', () => {
|
|
125
|
+
const m = message('width');
|
|
126
|
+
const chat = new Container();
|
|
127
|
+
chat.addChild(new Custom(m));
|
|
128
|
+
const rows = Array.from({ length: 40 }, (_, i) => String(i).padStart(2, '0') + 'x'.repeat(188));
|
|
129
|
+
let output = rows;
|
|
130
|
+
select(m.customType, () => output);
|
|
131
|
+
assert.deepEqual(draw(chat, 24).slice(1), rows);
|
|
132
|
+
const off = registerTransform({ id: 'probe.copy', transform: lines => [...lines] });
|
|
133
|
+
assert.deepEqual(applyTransforms(draw(chat, 24), 24).slice(1), rows.map(row => row.slice(0, 24)));
|
|
134
|
+
off();
|
|
135
|
+
|
|
136
|
+
const alt = new TuiAltScreen(terminal(), false, process.env.GENTLE_PI_CONFIG_HOME);
|
|
137
|
+
alt.addChild(chat);
|
|
138
|
+
alt.start();
|
|
139
|
+
try {
|
|
140
|
+
alt.renderNow();
|
|
141
|
+
assert.deepEqual(alt.previousScreen.map(strip).filter(line => /^\d\dx/.test(line)), rows.map(row => row.slice(0, 24)));
|
|
142
|
+
} finally {
|
|
143
|
+
alt.stop({ preserveScreen: true });
|
|
144
|
+
}
|
|
145
|
+
const regular = new TuiMainScreen(terminal(), false, process.env.GENTLE_PI_CONFIG_HOME);
|
|
146
|
+
regular.addChild(chat);
|
|
147
|
+
output = rows.map(row => row.slice(0, 24));
|
|
148
|
+
regular.start();
|
|
149
|
+
try {
|
|
150
|
+
regular.renderNow();
|
|
151
|
+
output = rows;
|
|
152
|
+
assert.throws(() => regular.renderNow(), /^Error: Rendered line 1 exceeds terminal width \(190 > 24\)\./);
|
|
153
|
+
} finally {
|
|
154
|
+
regular.stop();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { mkdtempSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import { registerRows, snapshotProviders } from '../../lib/shell-api/bus.ts';
|
|
7
|
+
import { installCardStyleTransform } from '../../lib/shell-api/card-style-wiring.ts';
|
|
8
|
+
import { adoptCustomMessages as adopt } from '../../lib/shell-api/message-design-adoption.ts';
|
|
9
|
+
import { installMessageDesignRows } from '../../lib/shell-api/message-design-rows.ts';
|
|
10
|
+
import { messageDesignRenderer } from '../../lib/shell-api/message-design-wiring.ts';
|
|
11
|
+
import { getMessageDesignFailures, getMessageDesignSelectionReads, registerMessageDesign, setMessageDesignSelection } from '../../lib/shell-api/message-designs.ts';
|
|
12
|
+
|
|
13
|
+
// Pi stores the result from rebuild(), not a renderer invocation per render().
|
|
14
|
+
// Keep this stateful distinction so regressions also fail outside an installed Pi.
|
|
15
|
+
function message(customType, customRenderer) {
|
|
16
|
+
const child = {
|
|
17
|
+
message: { customType, content: 'Keep the full body.' }, customRenderer,
|
|
18
|
+
invalidations: 0, component: undefined,
|
|
19
|
+
rebuild() { this.component = this.customRenderer?.(this.message, { expanded: false, outputPad: 3 }, {}); },
|
|
20
|
+
invalidate() { this.invalidations++; this.rebuild(); },
|
|
21
|
+
render(width) { return this.component?.render(width) ?? ['Pi box: ' + this.message.content]; },
|
|
22
|
+
};
|
|
23
|
+
child.rebuild();
|
|
24
|
+
return child;
|
|
25
|
+
}
|
|
26
|
+
const frame = child => ({ children: [child] });
|
|
27
|
+
const register = (customType, apply) => registerMessageDesign({ customType, id: `regression.${customType}`, label: 'card', apply });
|
|
28
|
+
const select = customType => setMessageDesignSelection(customType, `regression.${customType}`);
|
|
29
|
+
const host = () => ({ render: () => ['host'] });
|
|
30
|
+
|
|
31
|
+
test.beforeEach(() => { process.env.GENTLE_PI_CONFIG_HOME = mkdtempSync(join(tmpdir(), 'gsb-message-regressions-')); });
|
|
32
|
+
|
|
33
|
+
test('S1/S4: the bridge owns its provider id, so no plugin can take the line off the menu', () => {
|
|
34
|
+
const provider = { id: 'bridge.message-designs', category: 'Cards', rows: () => [] };
|
|
35
|
+
const disarm = installMessageDesignRows();
|
|
36
|
+
try {
|
|
37
|
+
assert.throws(() => registerRows(provider), /belongs to the bridge's own line/);
|
|
38
|
+
assert.equal(snapshotProviders().includes(provider), false, 'nothing stored');
|
|
39
|
+
const drop = register('provider-collision', () => []);
|
|
40
|
+
try {
|
|
41
|
+
assert.ok(
|
|
42
|
+
snapshotProviders().some((candidate) => candidate.id === 'bridge.message-designs'),
|
|
43
|
+
"the bridge's own line is what answers that id",
|
|
44
|
+
);
|
|
45
|
+
} finally {
|
|
46
|
+
drop();
|
|
47
|
+
}
|
|
48
|
+
} finally {
|
|
49
|
+
disarm();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('S4: no live message design means the conversation adds no message inspection or store reads', () => {
|
|
54
|
+
let inspections = 0;
|
|
55
|
+
const child = message('unclaimed', host), original = child.message, renderer = child.customRenderer;
|
|
56
|
+
Object.defineProperty(child, 'message', { get() { inspections++; return original; } });
|
|
57
|
+
const chat = { children: [child], render: width => child.render(width) };
|
|
58
|
+
installCardStyleTransform({ children: [{ children: [null, null, chat] }] });
|
|
59
|
+
const reads = getMessageDesignSelectionReads();
|
|
60
|
+
assert.deepEqual(chat.render(24), ['host']);
|
|
61
|
+
assert.deepEqual(chat.render(24), ['host']);
|
|
62
|
+
assert.deepEqual([inspections, child.invalidations, getMessageDesignSelectionReads() - reads], [0, 0, 0]);
|
|
63
|
+
assert.equal(child.customRenderer, renderer);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('S2: an own-the-box design failure restores the full fallback body and records once', () => {
|
|
67
|
+
// Real Pi keeps the message's OWN default box on the component (`CustomMessageComponent.box`,
|
|
68
|
+
// built in its constructor), and that box is what a failed design falls back to: the same bytes
|
|
69
|
+
// the user would have seen without a design, at the same width, never a re-drawing of them. The
|
|
70
|
+
// stand-in below carries such a box; a component with no box at all falls back to the message's
|
|
71
|
+
// plain body (label + content), which is the last resort and never an empty frame.
|
|
72
|
+
const child = message('failed-panel');
|
|
73
|
+
// A row that fits: Pi's own box wraps its content, so the fallback never has to measure it.
|
|
74
|
+
child.box = { render: (width) => [`Pi box(${width})`] };
|
|
75
|
+
const before = child.box.render(24);
|
|
76
|
+
const drop = register('failed-panel', () => { throw Error('cannot draw panel'); });
|
|
77
|
+
try {
|
|
78
|
+
select('failed-panel'); adopt(frame(child));
|
|
79
|
+
// The frame that fails shows the box the message already had; the failed design is then not
|
|
80
|
+
// retried, so Pi takes its OWN default path and the box it populates is what every later frame
|
|
81
|
+
// shows. Nothing is drawn twice for the same failure.
|
|
82
|
+
assert.deepEqual(child.render(24), before);
|
|
83
|
+
assert.deepEqual(child.render(24), [`Pi box: ${child.message.content}`]);
|
|
84
|
+
assert.deepEqual(getMessageDesignFailures().filter(f => f.customType === 'failed-panel').map(f => f.message), ['cannot draw panel']);
|
|
85
|
+
} finally { drop(); }
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('S2: with no box to ask, a failed design still leaves the message body on screen', () => {
|
|
89
|
+
const child = message('no-box');
|
|
90
|
+
const drop = register('no-box', () => { throw Error('cannot draw panel'); });
|
|
91
|
+
try {
|
|
92
|
+
select('no-box'); adopt(frame(child));
|
|
93
|
+
const rows = child.render(24);
|
|
94
|
+
assert.ok(rows.length > 0, 'never an empty frame');
|
|
95
|
+
assert.ok(rows.some((row) => String(row).includes('no-box')), 'the type is still named');
|
|
96
|
+
assert.ok(rows.some((row) => String(row).includes('Keep the full body.')), 'and the body');
|
|
97
|
+
} finally { drop(); }
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('S4: disposing the only active design restores the original box and removes render-time store reads', () => {
|
|
101
|
+
const child = message('disposed-panel'), before = child.render(24);
|
|
102
|
+
const drop = register('disposed-panel', () => ['panel']);
|
|
103
|
+
try {
|
|
104
|
+
select('disposed-panel'); adopt(frame(child)); assert.deepEqual(child.render(24), ['panel']);
|
|
105
|
+
} finally { drop(); }
|
|
106
|
+
adopt(frame(child));
|
|
107
|
+
const reads = getMessageDesignSelectionReads(), after = child.render(24);
|
|
108
|
+
assert.deepEqual([after, getMessageDesignSelectionReads() - reads], [before, 0]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('S3: host renderer receiver and mouse handler survive wrapping', () => {
|
|
112
|
+
let clicked = 0;
|
|
113
|
+
const child = message('clickable', function () { return { render: () => [this.message.customType], handleMouse() { clicked++; } }; });
|
|
114
|
+
const before = child.render(24);
|
|
115
|
+
const drop = register('clickable', rows => [...rows, 'design']);
|
|
116
|
+
try {
|
|
117
|
+
adopt(frame(child)); assert.deepEqual(child.render(24), before);
|
|
118
|
+
select('clickable'); adopt(frame(child));
|
|
119
|
+
assert.deepEqual(child.render(24), [...before, 'design']);
|
|
120
|
+
child.component.handleMouse?.({}); assert.equal(clicked, 1);
|
|
121
|
+
} finally { drop(); }
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('S3: refusing an adoption marker does not replace or repeatedly wrap the renderer', () => {
|
|
125
|
+
const child = message('sealed', host), renderer = child.customRenderer;
|
|
126
|
+
Object.seal(child);
|
|
127
|
+
const drop = register('sealed', rows => [...rows, 'design']);
|
|
128
|
+
try {
|
|
129
|
+
assert.equal(adopt(frame(child)).failed, 1);
|
|
130
|
+
const first = child.customRenderer;
|
|
131
|
+
assert.equal(adopt(frame(child)).failed, 1);
|
|
132
|
+
assert.deepEqual([first === renderer, child.customRenderer === first, child.invalidations], [true, true, 0]);
|
|
133
|
+
} finally { drop(); }
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('S3: a still-component renderer does not rebuild on returning to default', () => {
|
|
137
|
+
const child = message('fixed-shape', host);
|
|
138
|
+
const drop = register('fixed-shape', rows => [...rows, 'design']);
|
|
139
|
+
try {
|
|
140
|
+
select('fixed-shape'); adopt(frame(child)); assert.deepEqual(child.render(24), ['host', 'design']);
|
|
141
|
+
setMessageDesignSelection('fixed-shape', 'native'); adopt(frame(child)); adopt(frame(child));
|
|
142
|
+
assert.deepEqual([child.render(24), child.invalidations], [['host'], 1]);
|
|
143
|
+
} finally { drop(); }
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('S3: sparse or malformed returned arrays fall back to the host rows rather than throw', () => {
|
|
147
|
+
let result;
|
|
148
|
+
const drop = register('bad-rows', () => result);
|
|
149
|
+
try {
|
|
150
|
+
select('bad-rows');
|
|
151
|
+
const component = messageDesignRenderer('bad-rows', host)({}, {});
|
|
152
|
+
for (const bad of [Array(1), ["x", , "y"], Object.assign(['x'], { every: undefined })]) {
|
|
153
|
+
result = bad;
|
|
154
|
+
assert.doesNotThrow(() => component.render(24), 'a plugin value never throws into the frame');
|
|
155
|
+
// A sparse array is refused: reading by index finds its holes. A dense array whose own `every`
|
|
156
|
+
// was replaced is accepted — its positions ARE rows, nothing calls that member, and only the
|
|
157
|
+
// positions are copied into the frame.
|
|
158
|
+
const sparse = bad.length !== Object.keys(bad).filter((key) => key !== 'every').length;
|
|
159
|
+
assert.deepEqual(component.render(24), sparse ? ['host'] : ['x']);
|
|
160
|
+
}
|
|
161
|
+
} finally { drop(); }
|
|
162
|
+
});
|