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,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row placement (S1, S2, S3, S5): where a provider's block of customize rows lands inside its
|
|
3
|
+
* category, and what the order inside one slot is made of.
|
|
4
|
+
*
|
|
5
|
+
* Placement is REGISTRATION data, like `order`: nothing here is persisted, and nothing here depends
|
|
6
|
+
* on the order the plugins happened to load in. The capture backend only consumes the per-category
|
|
7
|
+
* blocks this resolver returns; the fallbacks are decided once, here, so the diagnostics record and the
|
|
8
|
+
* menu cannot disagree about where a block went.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import assert from "node:assert/strict";
|
|
12
|
+
import test from "node:test";
|
|
13
|
+
|
|
14
|
+
import * as bus from "../../lib/shell-api/bus.ts";
|
|
15
|
+
import { installCaptureBackend } from "../../lib/shell-api/capture.ts";
|
|
16
|
+
import type { CustomizeRow, RowProvider } from "../../lib/shell-api/types.ts";
|
|
17
|
+
import { createFakeHost } from "./fake-host.ts";
|
|
18
|
+
|
|
19
|
+
const HOST = ["Layout", "Banner", "Cards", "Settings"] as const;
|
|
20
|
+
|
|
21
|
+
const provider = (id: string, extra: Partial<RowProvider> = {}): RowProvider => ({
|
|
22
|
+
id,
|
|
23
|
+
category: "Layout",
|
|
24
|
+
rows: () => [],
|
|
25
|
+
...extra,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** `category/id@landing` for every block, in resolution order: the whole answer in one string. */
|
|
29
|
+
const places = (
|
|
30
|
+
providers: readonly RowProvider[],
|
|
31
|
+
hostCategories: readonly string[] = HOST,
|
|
32
|
+
): string[] =>
|
|
33
|
+
bus.resolveRowPlacements(providers, hostCategories).map(
|
|
34
|
+
(entry) => `${entry.category}/${entry.provider.id}@${bus.rowPlacementLandingText(entry)}`,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const resolutionOf = (
|
|
38
|
+
id: string,
|
|
39
|
+
providers: readonly RowProvider[],
|
|
40
|
+
hostCategories: readonly string[] = HOST,
|
|
41
|
+
) =>
|
|
42
|
+
bus.resolveRowPlacements(providers, hostCategories).find(
|
|
43
|
+
(entry) => entry.provider.id === id,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
test.beforeEach(() => {
|
|
47
|
+
bus.resetBusForTests();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/** S2. Registration order decides nothing: the same providers in any load order draw the same rows. */
|
|
51
|
+
test("the same registrations in any load order draw the same rows", () => {
|
|
52
|
+
const registrations = [
|
|
53
|
+
provider("start-b", { placement: "start" }),
|
|
54
|
+
provider("start-a", { placement: "start" }),
|
|
55
|
+
provider("after-a", { placement: { after: "start-a" } }),
|
|
56
|
+
provider("plain-b"),
|
|
57
|
+
provider("plain-a"),
|
|
58
|
+
provider("numbered", { order: 1 }),
|
|
59
|
+
provider("early", { order: -2, placement: { after: "start-a" } }),
|
|
60
|
+
];
|
|
61
|
+
const permutations = [
|
|
62
|
+
registrations,
|
|
63
|
+
[...registrations].reverse(),
|
|
64
|
+
[
|
|
65
|
+
registrations[3],
|
|
66
|
+
registrations[0],
|
|
67
|
+
registrations[6],
|
|
68
|
+
registrations[2],
|
|
69
|
+
registrations[5],
|
|
70
|
+
registrations[1],
|
|
71
|
+
registrations[4],
|
|
72
|
+
],
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
const answers = permutations.map((permutation) => {
|
|
76
|
+
bus.resetBusForTests();
|
|
77
|
+
for (const entry of permutation) bus.registerRows(entry);
|
|
78
|
+
return places(bus.snapshotProviders());
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
assert.deepEqual(answers[1], answers[0], "reverse load order, the same rows");
|
|
82
|
+
assert.deepEqual(answers[2], answers[0], "one more order, the same rows");
|
|
83
|
+
assert.deepEqual(answers[0], [
|
|
84
|
+
"Layout/start-a@start",
|
|
85
|
+
'Layout/early@after "start-a"',
|
|
86
|
+
'Layout/after-a@after "start-a"',
|
|
87
|
+
"Layout/start-b@start",
|
|
88
|
+
"Layout/numbered@end",
|
|
89
|
+
"Layout/plain-a@end",
|
|
90
|
+
"Layout/plain-b@end",
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/** S2. Finite `order` first, ascending, then the rest; ties by id. */
|
|
95
|
+
test("a finite order comes first ascending, then the rest by id", () => {
|
|
96
|
+
const providers = [
|
|
97
|
+
provider("b", { order: 5 }),
|
|
98
|
+
provider("a", { order: 5 }),
|
|
99
|
+
provider("z"),
|
|
100
|
+
provider("m", { order: -1 }),
|
|
101
|
+
provider("nan", { order: Number.NaN }),
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
assert.deepEqual(places(providers), [
|
|
105
|
+
"Layout/m@end",
|
|
106
|
+
"Layout/a@end",
|
|
107
|
+
"Layout/b@end",
|
|
108
|
+
"Layout/nan@end",
|
|
109
|
+
"Layout/z@end",
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("the id tiebreak is UTF-16 code units, not a locale collation", () => {
|
|
114
|
+
// In a locale-aware comparison `ä` sorts near `a`; by code unit it sorts after `z`.
|
|
115
|
+
assert.deepEqual(places([provider("ä"), provider("a"), provider("Z")]), [
|
|
116
|
+
"Layout/Z@end",
|
|
117
|
+
"Layout/a@end",
|
|
118
|
+
"Layout/ä@end",
|
|
119
|
+
]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/** S3. Several providers after the same anchor are one block, ordered by the S2 rule. */
|
|
123
|
+
test("several providers after one anchor sit as a block right after it, ordered by id", () => {
|
|
124
|
+
const providers = [
|
|
125
|
+
provider("anchor", { placement: "start" }),
|
|
126
|
+
provider("second", { placement: { after: "anchor" } }),
|
|
127
|
+
provider("first", { placement: { after: "anchor" } }),
|
|
128
|
+
provider("tail", { placement: "end" }),
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
assert.deepEqual(places(providers), [
|
|
132
|
+
"Layout/anchor@start",
|
|
133
|
+
'Layout/first@after "anchor"',
|
|
134
|
+
'Layout/second@after "anchor"',
|
|
135
|
+
"Layout/tail@end",
|
|
136
|
+
]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("a block after a provider keeps a finite order ahead of the plain ids", () => {
|
|
140
|
+
const providers = [
|
|
141
|
+
provider("anchor", { placement: "start" }),
|
|
142
|
+
provider("plain-b", { placement: { after: "anchor" } }),
|
|
143
|
+
provider("plain-a", { placement: { after: "anchor" } }),
|
|
144
|
+
provider("numbered", { placement: { after: "anchor" }, order: 3 }),
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
assert.deepEqual(places(providers), [
|
|
148
|
+
"Layout/anchor@start",
|
|
149
|
+
'Layout/numbered@after "anchor"',
|
|
150
|
+
'Layout/plain-a@after "anchor"',
|
|
151
|
+
'Layout/plain-b@after "anchor"',
|
|
152
|
+
]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
/** S3. Chains resolve transitively: A after B after C. */
|
|
156
|
+
test("an after-anchor chain is resolved transitively", () => {
|
|
157
|
+
const providers = [
|
|
158
|
+
provider("a", { placement: "start" }),
|
|
159
|
+
provider("b", { placement: { after: "a" } }),
|
|
160
|
+
provider("c", { placement: { after: "b" } }),
|
|
161
|
+
];
|
|
162
|
+
|
|
163
|
+
assert.deepEqual(places(providers), [
|
|
164
|
+
"Layout/a@start",
|
|
165
|
+
'Layout/b@after "a"',
|
|
166
|
+
'Layout/c@after "b"',
|
|
167
|
+
]);
|
|
168
|
+
assert.equal(resolutionOf("c", providers)?.anchor, '"b"');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
/** S5. A cycle, or a provider after itself, falls back to the end with a reason. */
|
|
172
|
+
test("two providers that would sit after each other both fall back to the end", () => {
|
|
173
|
+
const providers = [
|
|
174
|
+
provider("a", { placement: { after: "b" } }),
|
|
175
|
+
provider("b", { placement: { after: "a" } }),
|
|
176
|
+
provider("c", { placement: { after: "a" } }),
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
assert.deepEqual(places(providers), [
|
|
180
|
+
"Layout/a@end",
|
|
181
|
+
'Layout/c@after "a"',
|
|
182
|
+
"Layout/b@end",
|
|
183
|
+
]);
|
|
184
|
+
assert.match(resolutionOf("a", providers)?.reason ?? "", /cycle/);
|
|
185
|
+
assert.match(resolutionOf("b", providers)?.reason ?? "", /cycle/);
|
|
186
|
+
assert.equal(
|
|
187
|
+
resolutionOf("c", providers)?.reason,
|
|
188
|
+
undefined,
|
|
189
|
+
"a provider leading into a broken cycle still draws after its anchor",
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test("a provider that asks to sit after itself falls back to the end", () => {
|
|
194
|
+
const providers = [provider("loop", { placement: { after: "loop" } })];
|
|
195
|
+
|
|
196
|
+
assert.deepEqual(places(providers), ["Layout/loop@end"]);
|
|
197
|
+
assert.match(resolutionOf("loop", providers)?.reason ?? "", /cycle/);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
/** S5. An anchor nobody registered falls back to the end, and says so. */
|
|
201
|
+
test("after an id that is not a registered provider falls back to the end", () => {
|
|
202
|
+
const providers = [provider("lost", { placement: { after: "nobody" } })];
|
|
203
|
+
const resolved = resolutionOf("lost", providers);
|
|
204
|
+
|
|
205
|
+
assert.deepEqual(places(providers), ["Layout/lost@end"]);
|
|
206
|
+
assert.equal(resolved?.requested, 'after "nobody"');
|
|
207
|
+
assert.match(resolved?.reason ?? "", /not a registered row provider id/);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
/** S5. An anchor that exists in another category cannot be honoured in this one. */
|
|
211
|
+
test("after a provider in another category falls back to the end", () => {
|
|
212
|
+
const providers = [
|
|
213
|
+
provider("other", { category: "Banner" }),
|
|
214
|
+
provider("follower", { category: "Layout", placement: { after: "other" } }),
|
|
215
|
+
];
|
|
216
|
+
const resolved = resolutionOf("follower", providers);
|
|
217
|
+
|
|
218
|
+
assert.deepEqual(places(providers), ["Banner/other@end", "Layout/follower@end"]);
|
|
219
|
+
assert.match(resolved?.reason ?? "", /is in the category "Banner"/);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
/** S1. `"start"` sits before the first host row of the provider's category. */
|
|
223
|
+
test("start lands before the category's first row", () => {
|
|
224
|
+
const providers = [
|
|
225
|
+
provider("plain"),
|
|
226
|
+
provider("top", { placement: "start" }),
|
|
227
|
+
];
|
|
228
|
+
|
|
229
|
+
assert.deepEqual(places(providers), ["Layout/top@start", "Layout/plain@end"]);
|
|
230
|
+
const resolved = resolutionOf("top", providers);
|
|
231
|
+
assert.equal(resolved?.requested, "start");
|
|
232
|
+
assert.equal(resolved?.reason, undefined, "the request was honoured, so there is nothing to report");
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
/** S5. A category the host did not build has no row to sit before or after. */
|
|
236
|
+
test("start and after on a plugin-created category fall back to the end with a reason", () => {
|
|
237
|
+
const providers = [
|
|
238
|
+
provider("created", { category: "Plugins", placement: "start" }),
|
|
239
|
+
provider("after-created", { category: "Plugins", placement: { after: "created" } }),
|
|
240
|
+
provider("plain", { category: "Plugins" }),
|
|
241
|
+
];
|
|
242
|
+
|
|
243
|
+
assert.deepEqual(places(providers, ["Layout"]), [
|
|
244
|
+
"Plugins/after-created@end",
|
|
245
|
+
"Plugins/created@end",
|
|
246
|
+
"Plugins/plain@end",
|
|
247
|
+
]);
|
|
248
|
+
assert.match(resolutionOf("created", providers, ["Layout"])?.reason ?? "", /did not build/);
|
|
249
|
+
assert.match(
|
|
250
|
+
resolutionOf("after-created", providers, ["Layout"])?.reason ?? "",
|
|
251
|
+
/did not build/,
|
|
252
|
+
);
|
|
253
|
+
assert.equal(
|
|
254
|
+
resolutionOf("plain", providers, ["Layout"])?.reason,
|
|
255
|
+
undefined,
|
|
256
|
+
"the default `end` needs no host row, so it is still honoured",
|
|
257
|
+
);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
/** The host-category input is a set: how a caller collected it cannot change the answer. */
|
|
261
|
+
test("the host-category collection order never changes the answer", () => {
|
|
262
|
+
const providers = [
|
|
263
|
+
provider("top", { placement: "start" }),
|
|
264
|
+
provider("after-top", { placement: { after: "top" } }),
|
|
265
|
+
provider("plain"),
|
|
266
|
+
];
|
|
267
|
+
|
|
268
|
+
assert.deepEqual(places(providers, ["Banner", "Layout", "Layout"]), places(providers, [
|
|
269
|
+
"Layout",
|
|
270
|
+
"Banner",
|
|
271
|
+
]));
|
|
272
|
+
assert.deepEqual(
|
|
273
|
+
bus.resolveRowPlacements(providers, ["Layout", "Banner"]),
|
|
274
|
+
bus.resolveRowPlacements(providers, ["Banner", "Layout", "Layout"]),
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
/** S5. A malformed placement is rejected at registration, reported, and still registers as end. */
|
|
279
|
+
test("a malformed placement is rejected and the provider still registers as end", () => {
|
|
280
|
+
const malformed = { after: "" } as unknown as RowProvider["placement"];
|
|
281
|
+
const registered = provider("broken", { placement: malformed });
|
|
282
|
+
|
|
283
|
+
const dispose = bus.registerRows(registered);
|
|
284
|
+
|
|
285
|
+
assert.deepEqual(bus.snapshotProviders(), [registered], "the bus is unchanged apart from the record");
|
|
286
|
+
assert.deepEqual(bus.snapshotProviders()[0], registered);
|
|
287
|
+
const rejections = bus.getRowPlacementRejections();
|
|
288
|
+
assert.equal(rejections.length, 1);
|
|
289
|
+
assert.equal(rejections[0].providerId, "broken");
|
|
290
|
+
assert.equal(rejections[0].value, '{"after":""}', "the value is reported verbatim");
|
|
291
|
+
assert.match(rejections[0].reason, /non-empty string/);
|
|
292
|
+
assert.deepEqual(places(bus.snapshotProviders()), ["Layout/broken@end"]);
|
|
293
|
+
assert.match(resolutionOf("broken", bus.snapshotProviders())?.reason ?? "", /malformed/);
|
|
294
|
+
|
|
295
|
+
dispose();
|
|
296
|
+
assert.deepEqual(bus.snapshotProviders(), []);
|
|
297
|
+
assert.deepEqual(bus.getRowPlacementRejections(), [], "the disposer removes its record too");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("a placement shape the type does not allow is rejected and reported", () => {
|
|
301
|
+
const cases: unknown[] = [
|
|
302
|
+
7,
|
|
303
|
+
null,
|
|
304
|
+
[],
|
|
305
|
+
{},
|
|
306
|
+
{ after: "" },
|
|
307
|
+
{ after: 5 },
|
|
308
|
+
{ after: "anchor", extra: true },
|
|
309
|
+
];
|
|
310
|
+
|
|
311
|
+
for (const [index, value] of cases.entries()) {
|
|
312
|
+
bus.resetBusForTests();
|
|
313
|
+
const id = `bad-${index}`;
|
|
314
|
+
// SAFETY: the point of the case is a value the type forbids.
|
|
315
|
+
bus.registerRows(provider(id, { placement: value as RowProvider["placement"] }));
|
|
316
|
+
|
|
317
|
+
assert.deepEqual(
|
|
318
|
+
bus.snapshotProviders().map((entry) => entry.id),
|
|
319
|
+
[id],
|
|
320
|
+
`${JSON.stringify(value)}: the provider still registers`,
|
|
321
|
+
);
|
|
322
|
+
assert.deepEqual(places(bus.snapshotProviders()), [`Layout/${id}@end`], "and lands at the end");
|
|
323
|
+
const rejection = bus.getRowPlacementRejections().find((entry) => entry.providerId === id);
|
|
324
|
+
assert.ok(rejection !== undefined, `${JSON.stringify(value)}: the bad placement is reported`);
|
|
325
|
+
assert.equal(rejection.value, JSON.stringify(value), "the value is reported verbatim");
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test("a conforming re-registration clears the placement rejection", () => {
|
|
330
|
+
const malformed = { after: "" } as unknown as RowProvider["placement"];
|
|
331
|
+
bus.registerRows(provider("anchor", { placement: "start" }));
|
|
332
|
+
bus.registerRows(provider("broken", { placement: malformed, order: 1 }));
|
|
333
|
+
assert.equal(bus.getRowPlacementRejections().length, 1);
|
|
334
|
+
|
|
335
|
+
bus.registerRows(provider("broken", { placement: { after: "anchor" } }));
|
|
336
|
+
|
|
337
|
+
assert.deepEqual(bus.getRowPlacementRejections(), []);
|
|
338
|
+
assert.deepEqual(places(bus.snapshotProviders()), [
|
|
339
|
+
"Layout/anchor@start",
|
|
340
|
+
'Layout/broken@after "anchor"',
|
|
341
|
+
]);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test("a valid placement is stored on the provider exactly as written", () => {
|
|
345
|
+
const registered = provider("music", { placement: { after: "loon.news" } });
|
|
346
|
+
bus.registerRows(registered);
|
|
347
|
+
|
|
348
|
+
assert.equal(bus.snapshotProviders()[0], registered);
|
|
349
|
+
assert.deepEqual(bus.snapshotProviders()[0].placement, { after: "loon.news" });
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
test("the resolver never throws on a malformed stored placement", () => {
|
|
353
|
+
const broken = {
|
|
354
|
+
id: "broken",
|
|
355
|
+
category: "Layout",
|
|
356
|
+
rows: () => [],
|
|
357
|
+
placement: { after: "" },
|
|
358
|
+
} as unknown as RowProvider;
|
|
359
|
+
|
|
360
|
+
assert.doesNotThrow(() => bus.resolveRowPlacements([broken], HOST));
|
|
361
|
+
assert.deepEqual(places([broken]), ["Layout/broken@end"]);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// ---------------------------------------------------------------------------------------------
|
|
365
|
+
// The same rules through the capture splices (S4, S5, S6)
|
|
366
|
+
// ---------------------------------------------------------------------------------------------
|
|
367
|
+
|
|
368
|
+
const rowLabels = (rows: readonly CustomizeRow[]): string[] =>
|
|
369
|
+
rows.map((row) => (typeof row.label === "function" ? row.label() : (row.label ?? "")));
|
|
370
|
+
|
|
371
|
+
const captureHostRows = (): CustomizeRow[] => [
|
|
372
|
+
{ category: "Cards", label: "Card bash: builtin", action: () => {} },
|
|
373
|
+
{ category: "Cards", label: "Card output: builtin", action: () => {} },
|
|
374
|
+
{ category: "Banner", label: "Banner: builtin", action: () => {} },
|
|
375
|
+
{ category: "Layout", label: "Layout: builtin", action: () => {} },
|
|
376
|
+
];
|
|
377
|
+
|
|
378
|
+
test("the capture backend keeps a start block and its after follower inside the page", () => {
|
|
379
|
+
const rows = captureHostRows();
|
|
380
|
+
const host = createFakeHost({ rows });
|
|
381
|
+
bus.registerRows({
|
|
382
|
+
id: "loon.top",
|
|
383
|
+
category: "Layout",
|
|
384
|
+
placement: "start",
|
|
385
|
+
rows: () => [{ label: "Loon top", action: () => {} }],
|
|
386
|
+
});
|
|
387
|
+
bus.registerRows({
|
|
388
|
+
id: "loon.next",
|
|
389
|
+
category: "Layout",
|
|
390
|
+
placement: { after: "loon.top" },
|
|
391
|
+
rows: () => [{ label: "Loon next", action: () => {} }],
|
|
392
|
+
});
|
|
393
|
+
installCaptureBackend(host.ui);
|
|
394
|
+
|
|
395
|
+
host.buildMenu();
|
|
396
|
+
|
|
397
|
+
assert.deepEqual(rowLabels(rows), [
|
|
398
|
+
"Card bash: builtin",
|
|
399
|
+
"Card output: builtin",
|
|
400
|
+
"Banner: builtin",
|
|
401
|
+
"Loon top",
|
|
402
|
+
"Loon next",
|
|
403
|
+
"Layout: builtin",
|
|
404
|
+
]);
|
|
405
|
+
assert.deepEqual(
|
|
406
|
+
[...new Set(host.categories())],
|
|
407
|
+
["Cards", "Banner", "Layout"],
|
|
408
|
+
"the host's page list is unchanged: the provisional insert cannot hide an existing page",
|
|
409
|
+
);
|
|
410
|
+
});
|