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.
Files changed (127) hide show
  1. package/README.md +48 -25
  2. package/extensions/odd-worktree-tools.ts +64 -211
  3. package/lib/shell-api/api.ts +523 -0
  4. package/lib/shell-api/arm.ts +83 -0
  5. package/lib/shell-api/bus.ts +1389 -0
  6. package/lib/shell-api/capture.ts +1340 -0
  7. package/lib/shell-api/card-style-line.ts +112 -0
  8. package/lib/shell-api/card-style-rows.ts +390 -0
  9. package/lib/shell-api/card-style-transform.ts +862 -0
  10. package/lib/shell-api/card-style-wiring.ts +477 -0
  11. package/lib/shell-api/card-styles.ts +153 -0
  12. package/lib/shell-api/config.ts +71 -0
  13. package/lib/shell-api/extension.ts +247 -0
  14. package/lib/shell-api/hook.ts +322 -0
  15. package/lib/shell-api/index.ts +88 -0
  16. package/lib/shell-api/message-design-adoption.ts +549 -0
  17. package/lib/shell-api/message-design-rows.ts +313 -0
  18. package/lib/shell-api/message-design-wiring.ts +369 -0
  19. package/lib/shell-api/message-designs.ts +746 -0
  20. package/lib/shell-api/notices.ts +137 -0
  21. package/lib/shell-api/plugin-lines.ts +877 -0
  22. package/lib/shell-api/presence.ts +258 -0
  23. package/lib/shell-api/repaint.ts +351 -0
  24. package/lib/shell-api/row-labels.ts +146 -0
  25. package/lib/shell-api/row-names.ts +273 -0
  26. package/lib/shell-api/row-origin.ts +144 -0
  27. package/lib/shell-api/rows.ts +591 -0
  28. package/lib/shell-api/section-panel.ts +378 -0
  29. package/lib/shell-api/section-pointer.ts +164 -0
  30. package/lib/shell-api/sections-preview.ts +275 -0
  31. package/lib/shell-api/sections-rows.ts +133 -0
  32. package/lib/shell-api/sidebar-render.ts +705 -0
  33. package/lib/shell-api/sidebar.ts +1126 -0
  34. package/lib/shell-api/store.ts +279 -0
  35. package/lib/shell-api/tool-design-adoption.ts +263 -0
  36. package/lib/shell-api/tool-design-rows.ts +307 -0
  37. package/lib/shell-api/tool-design-wiring.ts +481 -0
  38. package/lib/shell-api/tool-designs.ts +1411 -0
  39. package/lib/shell-api/transform-pipeline.ts +351 -0
  40. package/lib/shell-api/types.ts +803 -0
  41. package/lib/shell-api/visibility.ts +154 -0
  42. package/lib/user-prompt-card.js +48 -2
  43. package/package.json +3 -2
  44. package/tools/files-bridge.test.js +81 -66
  45. package/tools/fixtures/load-extension.js +40 -18
  46. package/tools/issues-command.test.js +4 -7
  47. package/tools/issues-section.test.js +71 -81
  48. package/tools/odd-rail-wiring.test.js +16 -10
  49. package/tools/package-surface.test.js +42 -13
  50. package/tools/prs-command.test.js +11 -6
  51. package/tools/shell-api/api.test.ts +484 -0
  52. package/tools/shell-api/apply-on-move.test.ts +529 -0
  53. package/tools/shell-api/arm.test.ts +220 -0
  54. package/tools/shell-api/bridge-ready.test.ts +309 -0
  55. package/tools/shell-api/bus.test.ts +194 -0
  56. package/tools/shell-api/button-rows.test.ts +435 -0
  57. package/tools/shell-api/capture.test.ts +583 -0
  58. package/tools/shell-api/card-style-rows.test.ts +493 -0
  59. package/tools/shell-api/card-style-transform.test.ts +379 -0
  60. package/tools/shell-api/card-style-wiring.test.ts +258 -0
  61. package/tools/shell-api/card-styles-e2e.test.ts +502 -0
  62. package/tools/shell-api/card-styles.test.ts +324 -0
  63. package/tools/shell-api/card-transcript-path.test.ts +178 -0
  64. package/tools/shell-api/compatibility-regression.test.mjs +64 -0
  65. package/tools/shell-api/config.test.ts +93 -0
  66. package/tools/shell-api/docs-coverage.test.ts +82 -0
  67. package/tools/shell-api/e2e.test.ts +562 -0
  68. package/tools/shell-api/example-bash-identity.test.ts +372 -0
  69. package/tools/shell-api/example-bash-matrix.test.ts +856 -0
  70. package/tools/shell-api/example-designs.test.ts +737 -0
  71. package/tools/shell-api/example-neon-transform.test.ts +283 -0
  72. package/tools/shell-api/example-plain-style.test.ts +1225 -0
  73. package/tools/shell-api/extension.test.ts +157 -0
  74. package/tools/shell-api/fake-events.ts +58 -0
  75. package/tools/shell-api/fake-host.ts +211 -0
  76. package/tools/shell-api/fake-sidebar.ts +516 -0
  77. package/tools/shell-api/fake-transcript.ts +486 -0
  78. package/tools/shell-api/frame-telemetry.test.ts +317 -0
  79. package/tools/shell-api/hook.test.ts +196 -0
  80. package/tools/shell-api/manifest.test.ts +47 -0
  81. package/tools/shell-api/message-design-adoption.test.ts +611 -0
  82. package/tools/shell-api/message-design-follows.test.ts +361 -0
  83. package/tools/shell-api/message-design-pi-release.test.mjs +157 -0
  84. package/tools/shell-api/message-design-regressions.test.mjs +162 -0
  85. package/tools/shell-api/message-design-rows.test.ts +266 -0
  86. package/tools/shell-api/message-design-wiring.test.ts +362 -0
  87. package/tools/shell-api/message-designs.test.ts +339 -0
  88. package/tools/shell-api/new-category.test.ts +1101 -0
  89. package/tools/shell-api/notices.test.ts +292 -0
  90. package/tools/shell-api/plugin-integration-lines.test.ts +827 -0
  91. package/tools/shell-api/presence.test.ts +396 -0
  92. package/tools/shell-api/rail-part-hits.test.ts +281 -0
  93. package/tools/shell-api/rail-surfaces.test.ts +402 -0
  94. package/tools/shell-api/rail-width.test.ts +406 -0
  95. package/tools/shell-api/regression.test.ts +434 -0
  96. package/tools/shell-api/repaint-api.test.ts +200 -0
  97. package/tools/shell-api/reserved-categories.test.ts +250 -0
  98. package/tools/shell-api/row-labels.test.ts +261 -0
  99. package/tools/shell-api/row-names.test.ts +407 -0
  100. package/tools/shell-api/row-origin.test.ts +395 -0
  101. package/tools/shell-api/row-placement-regression.test.ts +797 -0
  102. package/tools/shell-api/row-placement.test.ts +410 -0
  103. package/tools/shell-api/section-interaction.test.ts +364 -0
  104. package/tools/shell-api/section-panel.test.ts +430 -0
  105. package/tools/shell-api/section-placement-rail.test.ts +390 -0
  106. package/tools/shell-api/section-placement.test.ts +386 -0
  107. package/tools/shell-api/sections-preview.test.ts +312 -0
  108. package/tools/shell-api/sections-rows.test.ts +293 -0
  109. package/tools/shell-api/sidebar-backend.test.ts +477 -0
  110. package/tools/shell-api/sidebar-e2e.test.ts +317 -0
  111. package/tools/shell-api/sidebar-hover.test.ts +276 -0
  112. package/tools/shell-api/sidebar-independent.test.ts +291 -0
  113. package/tools/shell-api/sidebar-render.test.ts +281 -0
  114. package/tools/shell-api/sidebar-sections.test.ts +247 -0
  115. package/tools/shell-api/store.test.ts +192 -0
  116. package/tools/shell-api/surface-repaint-cost.test.ts +520 -0
  117. package/tools/shell-api/tool-design-card-style.test.ts +308 -0
  118. package/tools/shell-api/tool-design-chain.test.ts +471 -0
  119. package/tools/shell-api/tool-design-cost.test.ts +591 -0
  120. package/tools/shell-api/tool-design-rows.test.ts +627 -0
  121. package/tools/shell-api/tool-design-scopes-audit.test.ts +212 -0
  122. package/tools/shell-api/tool-designs.test.ts +2412 -0
  123. package/tools/shell-api/transform-pipeline.test.ts +376 -0
  124. package/tools/shell-api/transforms-bus.test.ts +233 -0
  125. package/tools/shell-api/verifier-width-regressions.test.ts +147 -0
  126. package/tools/shell-api-rpc.test.js +189 -0
  127. package/tools/user-prompt-card.test.js +80 -10
@@ -0,0 +1,797 @@
1
+ /**
2
+ * T4 regression cases from independent verification (S4–S6).
3
+ *
4
+ * Each case below is a defect the verifier reproduced against the T1–T3 slices: a provider's
5
+ * DECLARED category used as the block boundary, an unplaced provider moved because another one opted
6
+ * in, rollback by identity deleting a host row, a partially applied splice over a read-only index,
7
+ * and the diagnostics record printing the plan instead of the landing a frozen array produced.
8
+ */
9
+
10
+ import assert from "node:assert/strict";
11
+ import test from "node:test";
12
+
13
+ import { getRowPlacementLandings, registerRows, resetBusForTests } from "../../lib/shell-api/bus.ts";
14
+ import { getCaptureDiagnostics, installCaptureBackend, resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
15
+ import { resetNoticesForTests, snapshotNotices } from "../../lib/shell-api/notices.ts";
16
+ import type { CustomizeRow } from "../../lib/shell-api/types.ts";
17
+ import { createFakeHost } from "./fake-host.ts";
18
+
19
+ const labelText = (row: CustomizeRow): string =>
20
+ typeof row.label === "function" ? row.label() : (row.label ?? "");
21
+
22
+ const labels = (rows: readonly CustomizeRow[]): string[] => rows.map(labelText);
23
+
24
+ const page = (rows: readonly CustomizeRow[], category: string): string[] =>
25
+ rows
26
+ .filter((row) => (row.category ?? "Settings") === category)
27
+ .map(labelText);
28
+
29
+ const hostRows = (): CustomizeRow[] => [
30
+ { category: "Cards", label: "Card bash: builtin", action: () => {} },
31
+ { category: "Cards", label: "Card output: builtin", action: () => {} },
32
+ { category: "Banner", label: "Banner: builtin", action: () => {} },
33
+ { category: "Layout", label: "Layout: builtin", action: () => {} },
34
+ ];
35
+
36
+ /** A throwing early host: the build appends first, then `afterAppend` mutates, then it throws. */
37
+ const throwingHostAfter = (
38
+ providerRows: CustomizeRow[],
39
+ afterAppend: (rows: CustomizeRow[]) => void = () => {},
40
+ ) => {
41
+ const rows = hostRows();
42
+ const originalError = new Error("factory exploded");
43
+ const ui = {
44
+ custom: (factory: (ui: unknown, theme: unknown, ...rest: unknown[]) => unknown): unknown =>
45
+ factory(ui, undefined),
46
+ };
47
+ const host = {
48
+ ui,
49
+ build: (): unknown =>
50
+ ui.custom(() => {
51
+ rows.map((row) => row.category ?? "Settings");
52
+ afterAppend(rows);
53
+ throw originalError;
54
+ }),
55
+ };
56
+ registerRows({ id: "loon.injected", category: "Layout", rows: () => providerRows });
57
+ installCaptureBackend(host.ui);
58
+ return { rows, host, originalError };
59
+ };
60
+ /** A host that maps its rows to labels but never derives categories: the late path injects. */
61
+ const lateOnlyHost = (rows: CustomizeRow[]) => {
62
+ const ui = {
63
+ custom: (factory: (ui: unknown, theme: unknown, ...rest: unknown[]) => unknown): unknown =>
64
+ factory(ui, undefined),
65
+ };
66
+ return {
67
+ rows,
68
+ ui,
69
+ build: (): unknown =>
70
+ ui.custom(() => {
71
+ rows.map((row) => row.label);
72
+ return { invalidate: () => {} };
73
+ }),
74
+ };
75
+ };
76
+
77
+ test.beforeEach(() => {
78
+ resetBusForTests();
79
+ resetCaptureStateForTests();
80
+ resetNoticesForTests();
81
+ });
82
+
83
+ test("a row's own category is its block boundary, not the provider's declared category", () => {
84
+ const pair = (label: string, value: string): CustomizeRow => ({
85
+ category: "Cards",
86
+ label,
87
+ action: () => {},
88
+ choice: { setting: "Pair", value, current: () => value === "first", applyOnMove: false },
89
+ });
90
+ // Cards rows are not contiguous in the host array: the renderer still shows one Cards page.
91
+ const rows: CustomizeRow[] = [
92
+ pair("First value", "first"),
93
+ { category: "Banner", label: "Host banner", action: () => {} },
94
+ pair("Second value", "second"),
95
+ { category: "Layout", label: "Host layout", action: () => {} },
96
+ ];
97
+ const host = lateOnlyHost(rows);
98
+ registerRows({
99
+ id: "loon.plain",
100
+ // The provider declares Banner, but the row it contributes belongs to Cards.
101
+ category: "Banner",
102
+ placement: "start",
103
+ rows: () => [{ category: "Cards", label: "Plain row", action: () => {} }],
104
+ });
105
+ installCaptureBackend(host.ui);
106
+
107
+ host.build();
108
+
109
+ const cards = page(rows, "Cards");
110
+ assert.deepEqual(cards, ["Plain row", "First value", "Second value"]);
111
+ const pairIndices = cards
112
+ .map((label, index) => (label === "First value" || label === "Second value" ? index : -1))
113
+ .filter((index) => index !== -1);
114
+ assert.equal(pairIndices[1], (pairIndices[0] ?? 0) + 1, "the rendered Cards pair is never split");
115
+ });
116
+
117
+ test("a provider that opts into nothing keeps the pre-feature tail append", () => {
118
+ const rows = hostRows();
119
+ const host = lateOnlyHost(rows);
120
+ registerRows({
121
+ id: "loon.top",
122
+ category: "Cards",
123
+ placement: "start",
124
+ rows: () => [{ label: "Start row", action: () => {} }],
125
+ });
126
+ registerRows({
127
+ id: "loon.plain",
128
+ category: "Cards",
129
+ rows: () => [{ label: "Plain row", action: () => {} }],
130
+ });
131
+ installCaptureBackend(host.ui);
132
+
133
+ host.build();
134
+
135
+ assert.deepEqual(labels(rows), [
136
+ "Start row",
137
+ "Card bash: builtin",
138
+ "Card output: builtin",
139
+ "Banner: builtin",
140
+ "Layout: builtin",
141
+ "Plain row",
142
+ ]);
143
+ assert.deepEqual(page(rows, "Cards"), ["Start row", "Card bash: builtin", "Card output: builtin", "Plain row"]);
144
+ });
145
+
146
+ test("unplaced pages keep their subscription order when another provider opts in", () => {
147
+ const rows = hostRows();
148
+ const host = createFakeHost({ rows });
149
+ registerRows({
150
+ id: "loon.top",
151
+ category: "Cards",
152
+ placement: "start",
153
+ rows: () => [{ label: "Top row", action: () => {} }],
154
+ });
155
+ registerRows({
156
+ id: "loon.zeta",
157
+ category: "Zeta page",
158
+ rows: () => [{ label: "Zeta row", action: () => {} }],
159
+ });
160
+ registerRows({
161
+ id: "loon.alpha",
162
+ category: "Alpha page",
163
+ rows: () => [{ label: "Alpha row", action: () => {} }],
164
+ });
165
+ installCaptureBackend(host.ui);
166
+
167
+ host.buildMenu();
168
+
169
+ assert.deepEqual([...new Set(host.categories())], [
170
+ "Cards",
171
+ "Banner",
172
+ "Layout",
173
+ "Zeta page",
174
+ "Alpha page",
175
+ ]);
176
+ });
177
+
178
+ test("with no provider opting in, pages keep the pre-feature tail order", () => {
179
+ const rows = hostRows();
180
+ const host = createFakeHost({ rows });
181
+ registerRows({
182
+ id: "loon.zeta",
183
+ category: "Zeta page",
184
+ rows: () => [{ label: "Zeta row", action: () => {} }],
185
+ });
186
+ registerRows({
187
+ id: "loon.alpha",
188
+ category: "Alpha page",
189
+ rows: () => [{ label: "Alpha row", action: () => {} }],
190
+ });
191
+ installCaptureBackend(host.ui);
192
+
193
+ host.buildMenu();
194
+
195
+ assert.deepEqual([...new Set(host.categories())], [
196
+ "Cards",
197
+ "Banner",
198
+ "Layout",
199
+ "Zeta page",
200
+ "Alpha page",
201
+ ]);
202
+ });
203
+
204
+ test("rollback restores a host row object that a provider handed back", async () => {
205
+ const shared: CustomizeRow = {
206
+ category: "Cards",
207
+ label: "Shared row",
208
+ action: () => {},
209
+ choice: { setting: "Shared setting", value: "on", current: () => true, applyOnMove: false },
210
+ };
211
+ const rows: CustomizeRow[] = [
212
+ shared,
213
+ { category: "Cards", label: "Card tail", action: () => {} },
214
+ { category: "Banner", label: "Banner: builtin", action: () => {} },
215
+ { category: "Layout", label: "Layout: builtin", action: () => {} },
216
+ ];
217
+ const host = createFakeHost({ rows, factoryResult: "promise" });
218
+ registerRows({
219
+ id: "loon.shared",
220
+ category: "Cards",
221
+ rows: () => [shared],
222
+ });
223
+ installCaptureBackend(host.ui);
224
+ const before = [...rows];
225
+
226
+ await host.buildMenu();
227
+
228
+ assert.equal(rows.length, before.length, "same length");
229
+ assert.ok(
230
+ rows.every((row, index) => row === before[index]),
231
+ "the host's own row objects come back in the host's own order",
232
+ );
233
+ });
234
+
235
+ test("a read-only index skips the move instead of half-applying it", () => {
236
+ const rows = hostRows();
237
+ Object.defineProperty(rows, "1", {
238
+ value: rows[1],
239
+ writable: false,
240
+ enumerable: true,
241
+ configurable: true,
242
+ });
243
+ const host = lateOnlyHost(rows);
244
+ registerRows({
245
+ id: "loon.top",
246
+ category: "Cards",
247
+ placement: "start",
248
+ rows: () => [{ label: "Placed row", action: () => {} }],
249
+ });
250
+ installCaptureBackend(host.ui);
251
+
252
+ assert.doesNotThrow(() => host.build());
253
+
254
+ assert.deepEqual(labels(rows), [
255
+ "Card bash: builtin",
256
+ "Card output: builtin",
257
+ "Banner: builtin",
258
+ "Layout: builtin",
259
+ "Placed row",
260
+ ]);
261
+ assert.deepEqual(getCaptureDiagnostics().lastOutcome, { kind: "injected", injectedRows: 1 });
262
+
263
+ // The landing record is what the removed status module read for its `placement start → end` line:
264
+ // the block did not move, and the recorded reason says why instead of repeating the plan.
265
+ const landing = getRowPlacementLandings().find((entry) => entry.providerId === "loon.top");
266
+ assert.equal(landing?.requested, "start");
267
+ assert.equal(landing?.landed, "end");
268
+ assert.match(landing?.reason ?? "", /read-only|would not accept|planned write/);
269
+ });
270
+
271
+ test("a frozen array after the provisional injection reports the landing it really got", () => {
272
+ const rows = hostRows();
273
+ const ui = {
274
+ custom: (factory: (ui: unknown, theme: unknown, ...rest: unknown[]) => unknown): unknown =>
275
+ factory(ui, undefined),
276
+ };
277
+ const host = {
278
+ ui,
279
+ build: (): unknown =>
280
+ ui.custom(() => {
281
+ rows.map((row) => row.category ?? "Settings");
282
+ Object.freeze(rows);
283
+ return { invalidate: () => {} };
284
+ }),
285
+ };
286
+ registerRows({
287
+ id: "loon.top",
288
+ category: "Layout",
289
+ placement: "start",
290
+ rows: () => [{ label: "Top row", action: () => {} }],
291
+ });
292
+ installCaptureBackend(host.ui);
293
+
294
+ host.build();
295
+
296
+ assert.deepEqual(labels(rows), [
297
+ "Card bash: builtin",
298
+ "Card output: builtin",
299
+ "Banner: builtin",
300
+ "Layout: builtin",
301
+ "Top row",
302
+ ]);
303
+ const landing = getRowPlacementLandings().find((entry) => entry.providerId === "loon.top");
304
+ assert.equal(landing?.requested, "start");
305
+ assert.equal(landing?.landed, "end");
306
+ assert.match(landing?.reason ?? "", /frozen|read-only|would not accept|planned write/);
307
+ });
308
+
309
+ test("a recorded landing keeps the resolver's exact fallback reason", () => {
310
+ const rows = hostRows();
311
+ const host = lateOnlyHost(rows);
312
+ registerRows({
313
+ id: "loon.lost",
314
+ category: "Layout",
315
+ placement: { after: "loon.nope" },
316
+ rows: () => [{ label: "Lost row", action: () => {} }],
317
+ });
318
+ installCaptureBackend(host.ui);
319
+
320
+ host.build();
321
+
322
+ const landing = getRowPlacementLandings().find((entry) => entry.providerId === "loon.lost");
323
+ assert.equal(landing?.requested, 'after "loon.nope"');
324
+ assert.equal(landing?.landed, "end");
325
+ assert.equal(
326
+ landing?.reason,
327
+ 'after "loon.nope" is not a registered row provider id',
328
+ "the verifier-pinned reason survives the landing report",
329
+ );
330
+ });
331
+
332
+ test("an after anchor naming an unopted provider lands after that provider's tail block", () => {
333
+ const rows = hostRows();
334
+ const host = lateOnlyHost(rows);
335
+ registerRows({
336
+ id: "loon.anchor",
337
+ // No placement and no order: this provider keeps the pre-feature tail append.
338
+ category: "Layout",
339
+ rows: () => [{ label: "Anchor row", action: () => {} }],
340
+ });
341
+ registerRows({
342
+ id: "loon.after",
343
+ category: "Layout",
344
+ placement: { after: "loon.anchor" },
345
+ rows: () => [{ label: "After row", action: () => {} }],
346
+ });
347
+ installCaptureBackend(host.ui);
348
+
349
+ host.build();
350
+
351
+ assert.deepEqual(page(rows, "Layout"), ["Layout: builtin", "Anchor row", "After row"]);
352
+ const landing = getRowPlacementLandings().find((entry) => entry.providerId === "loon.after");
353
+ assert.equal(landing?.requested, 'after "loon.anchor"');
354
+ assert.equal(landing?.landed, 'after "loon.anchor"');
355
+ assert.equal(landing?.reason, undefined);
356
+ });
357
+
358
+ test("two after followers of one unopted anchor keep the resolver's order inside its tail block", () => {
359
+ const rows = hostRows();
360
+ const host = lateOnlyHost(rows);
361
+ registerRows({
362
+ id: "loon.anchor",
363
+ category: "Layout",
364
+ rows: () => [{ label: "Anchor row", action: () => {} }],
365
+ });
366
+ registerRows({
367
+ id: "loon.second",
368
+ category: "Layout",
369
+ placement: { after: "loon.anchor" },
370
+ rows: () => [{ label: "Second row", action: () => {} }],
371
+ });
372
+ registerRows({
373
+ id: "loon.first",
374
+ category: "Layout",
375
+ placement: { after: "loon.anchor" },
376
+ rows: () => [{ label: "First row", action: () => {} }],
377
+ });
378
+ installCaptureBackend(host.ui);
379
+
380
+ host.build();
381
+
382
+ // Both followers hang off the ONE tail segment the unopted anchor owns, so they stay a block after
383
+ // that anchor, in the resolver's own order (id, since neither names one), and never drift into the
384
+ // category's `after` slot.
385
+ assert.deepEqual(page(rows, "Layout"), [
386
+ "Layout: builtin",
387
+ "Anchor row",
388
+ "First row",
389
+ "Second row",
390
+ ]);
391
+ assert.deepEqual(
392
+ getRowPlacementLandings()
393
+ .filter((entry) => entry.providerId !== "loon.anchor")
394
+ .map((entry) => [entry.providerId, entry.requested, entry.landed]),
395
+ [
396
+ ["loon.first", 'after "loon.anchor"', 'after "loon.anchor"'],
397
+ ["loon.second", 'after "loon.anchor"', 'after "loon.anchor"'],
398
+ ],
399
+ );
400
+ });
401
+
402
+ test("a throwing rollback removes only its tail append and never writes a retained read-only index", () => {
403
+ const rows = hostRows();
404
+ Object.defineProperty(rows, "1", {
405
+ value: rows[1],
406
+ writable: false,
407
+ enumerable: true,
408
+ configurable: true,
409
+ });
410
+ const before = [...rows];
411
+ const host = createFakeHost({ rows, throwInsideFactory: true });
412
+ registerRows({
413
+ id: "loon.injected",
414
+ category: "Layout",
415
+ rows: () => [{ label: "Injected row", action: () => {} }],
416
+ });
417
+ installCaptureBackend(host.ui);
418
+
419
+ assert.throws(() => host.buildMenu(), /factory exploded/u);
420
+
421
+ assert.equal(rows.length, before.length, "the baseline length comes back exactly");
422
+ assert.ok(
423
+ rows.every((row, index) => row === before[index]),
424
+ "every retained host row keeps its exact element and index",
425
+ );
426
+ assert.equal(Object.hasOwn(rows, String(before.length)), false, "no phantom tail index");
427
+ for (let index = 0; index < before.length; index += 1) {
428
+ assert.equal(Object.hasOwn(rows, String(index)), true, `index ${index} is not a hole`);
429
+ }
430
+ });
431
+
432
+ test("a pop'd appended row makes the rollback report what it found and could not remove", () => {
433
+ const rows = hostRows();
434
+ const originalError = new Error("factory exploded");
435
+ const ui = {
436
+ custom: (factory: (ui: unknown, theme: unknown, ...rest: unknown[]) => unknown): unknown =>
437
+ factory(ui, undefined),
438
+ };
439
+ const host = {
440
+ ui,
441
+ build: (): unknown =>
442
+ ui.custom(() => {
443
+ rows.map((row) => row.category ?? "Settings");
444
+ rows.pop(); // the host removes one row this build appended, before it throws
445
+ throw originalError;
446
+ }),
447
+ };
448
+ registerRows({
449
+ id: "loon.injected",
450
+ category: "Layout",
451
+ rows: () => [{ label: "Injected row", action: () => {} }],
452
+ });
453
+ installCaptureBackend(host.ui);
454
+
455
+ assert.throws(() => host.build(), (error) => error === originalError);
456
+
457
+ assert.deepEqual(
458
+ snapshotNotices().entries.map((entry) => entry.message),
459
+ [
460
+ "gentle-shell-bridge: could not fully roll back the provisional rows: appended 1 row; " +
461
+ "1 already removed by the host; 0 removed by the bridge; 0 could not be removed. " +
462
+ "The host menu was left as consistent as the array allowed.",
463
+ ],
464
+ );
465
+ });
466
+
467
+ test("a throwing length descriptor trap never replaces the factory's own error", () => {
468
+ const rows = hostRows();
469
+ const initialLength = rows.length;
470
+ let lengthDescriptorReads = 0;
471
+ const proxyRows = new Proxy(rows, {
472
+ getOwnPropertyDescriptor(target, property) {
473
+ if (property === "length" && target.length > initialLength) {
474
+ // `push` consults the descriptor once while it grows the array; the rollback's next read
475
+ // is the one that traps, exactly the "after the provisional append" shape.
476
+ lengthDescriptorReads += 1;
477
+ if (lengthDescriptorReads > 1) throw new Error("length descriptor exploded");
478
+ }
479
+ return Reflect.getOwnPropertyDescriptor(target, property);
480
+ },
481
+ });
482
+ const originalError = new Error("factory exploded");
483
+ const ui = {
484
+ custom: (factory: (ui: unknown, theme: unknown, ...rest: unknown[]) => unknown): unknown =>
485
+ factory(ui, undefined),
486
+ };
487
+ const host = {
488
+ ui,
489
+ build: (): unknown =>
490
+ ui.custom(() => {
491
+ proxyRows.map((row) => row.category ?? "Settings");
492
+ throw originalError;
493
+ }),
494
+ };
495
+ registerRows({
496
+ id: "loon.injected",
497
+ category: "Layout",
498
+ rows: () => [{ label: "Injected row", action: () => {} }],
499
+ });
500
+ installCaptureBackend(host.ui);
501
+
502
+ assert.throws(() => host.build(), (error) => error === originalError);
503
+ assert.ok(
504
+ snapshotNotices().entries.some(
505
+ (entry) =>
506
+ entry.message.includes("could not be inspected or changed (an object)") &&
507
+ !entry.message.includes("length descriptor exploded"),
508
+ ),
509
+ "the guarded rollback describes the refusing value without reading it",
510
+ );
511
+ });
512
+
513
+ test("a clean rollback of every appended row emits no notice", () => {
514
+ const scenario = throwingHostAfter([
515
+ { label: "Injected one", action: () => {} },
516
+ { label: "Injected two", action: () => {} },
517
+ { label: "Injected three", action: () => {} },
518
+ ]);
519
+
520
+ assert.throws(() => scenario.host.build(), (error) => error === scenario.originalError);
521
+ assert.deepEqual(snapshotNotices().entries, []);
522
+ assert.deepEqual(labels(scenario.rows), labels(hostRows()));
523
+ });
524
+
525
+ test("a host pop of one of three appended rows reports host and bridge removals truthfully", () => {
526
+ const scenario = throwingHostAfter(
527
+ [
528
+ { label: "Injected one", action: () => {} },
529
+ { label: "Injected two", action: () => {} },
530
+ { label: "Injected three", action: () => {} },
531
+ ],
532
+ (rows) => rows.pop(),
533
+ );
534
+
535
+ assert.throws(() => scenario.host.build(), (error) => error === scenario.originalError);
536
+ assert.deepEqual(labels(scenario.rows), labels(hostRows()));
537
+ assert.deepEqual(snapshotNotices().entries.map((entry) => entry.message), [
538
+ "gentle-shell-bridge: could not fully roll back the provisional rows: appended 3 rows; " +
539
+ "1 already removed by the host; 2 removed by the bridge; 0 could not be removed. " +
540
+ "The host menu was left as consistent as the array allowed.",
541
+ ]);
542
+ });
543
+
544
+ test("a non-configurable appended index makes the rollback remove nothing", () => {
545
+ let injected: CustomizeRow[] = [];
546
+ const scenario = throwingHostAfter(
547
+ [
548
+ { label: "Injected one", action: () => {} },
549
+ { label: "Injected two", action: () => {} },
550
+ { label: "Injected three", action: () => {} },
551
+ ],
552
+ (rows) => {
553
+ injected = rows.slice(rows.length - 3);
554
+ Object.defineProperty(rows, String(rows.length - 3), { configurable: false });
555
+ },
556
+ );
557
+
558
+ assert.throws(() => scenario.host.build(), (error) => error === scenario.originalError);
559
+ assert.equal(scenario.rows.length, 7);
560
+ assert.deepEqual(labels(scenario.rows), [
561
+ ...labels(hostRows()),
562
+ "Injected one",
563
+ "Injected two",
564
+ "Injected three",
565
+ ]);
566
+ injected.forEach((row, index) => {
567
+ assert.equal(scenario.rows[4 + index], row, `appended row ${index} keeps its identity`);
568
+ });
569
+ for (let index = 0; index < 7; index += 1) {
570
+ assert.equal(Object.hasOwn(scenario.rows, String(index)), true, `index ${index} is not a hole`);
571
+ }
572
+ assert.deepEqual(snapshotNotices().entries.map((entry) => entry.message), [
573
+ "gentle-shell-bridge: could not fully roll back the provisional rows: index 4 is " +
574
+ "non-configurable; appended 3 rows; 0 already removed by the host; 0 removed by the " +
575
+ "bridge; 3 could not be removed. The host menu was left as consistent as the array allowed.",
576
+ ]);
577
+ });
578
+
579
+ test("a throwing message getter on the rollback error is never inspected", () => {
580
+ const rows = hostRows();
581
+ const initialLength = rows.length;
582
+ const hostile = new Error("descriptor exploded");
583
+ Object.defineProperty(hostile, "message", {
584
+ get() {
585
+ throw new Error("message getter exploded");
586
+ },
587
+ });
588
+ let lengthDescriptorReads = 0;
589
+ const proxyRows = new Proxy(rows, {
590
+ getOwnPropertyDescriptor(target, property) {
591
+ if (property === "length" && target.length > initialLength) {
592
+ lengthDescriptorReads += 1;
593
+ if (lengthDescriptorReads > 1) throw hostile;
594
+ }
595
+ return Reflect.getOwnPropertyDescriptor(target, property);
596
+ },
597
+ });
598
+ const originalError = new Error("factory exploded");
599
+ const ui = {
600
+ custom: (factory: (ui: unknown, theme: unknown, ...rest: unknown[]) => unknown): unknown =>
601
+ factory(ui, undefined),
602
+ };
603
+ const host = {
604
+ ui,
605
+ build: (): unknown =>
606
+ ui.custom(() => {
607
+ proxyRows.map((row) => row.category ?? "Settings");
608
+ throw originalError;
609
+ }),
610
+ };
611
+ registerRows({
612
+ id: "loon.injected",
613
+ category: "Layout",
614
+ rows: () => [{ label: "Injected row", action: () => {} }],
615
+ });
616
+ installCaptureBackend(host.ui);
617
+
618
+ assert.throws(() => host.build(), (error) => error === originalError);
619
+ assert.ok(
620
+ snapshotNotices().entries.some(
621
+ (entry) =>
622
+ entry.message.includes("could not be inspected or changed (an object)") &&
623
+ !entry.message.includes("message getter exploded"),
624
+ ),
625
+ "the rollback describes the hostile error without reading its message",
626
+ );
627
+ });
628
+
629
+ test("swapping the last two appended rows removes all three and accounts for them", () => {
630
+ const scenario = throwingHostAfter(
631
+ [
632
+ { label: "Injected one", action: () => {} },
633
+ { label: "Injected two", action: () => {} },
634
+ { label: "Injected three", action: () => {} },
635
+ ],
636
+ (rows) => {
637
+ const first = rows.length - 3;
638
+ const last = rows[first + 2] as CustomizeRow;
639
+ rows[first + 2] = rows[first + 1] as CustomizeRow;
640
+ rows[first + 1] = last;
641
+ },
642
+ );
643
+ const hostBefore = [...scenario.rows];
644
+
645
+ assert.throws(() => scenario.host.build(), (error) => error === scenario.originalError);
646
+ assert.equal(scenario.rows.length, 4);
647
+ assert.deepEqual(labels(scenario.rows), labels(hostRows()));
648
+ scenario.rows.forEach((row, index) => {
649
+ assert.equal(row, hostBefore[index], `host row ${index} keeps its identity`);
650
+ });
651
+ for (let index = 0; index < 4; index += 1) {
652
+ assert.equal(Object.hasOwn(scenario.rows, String(index)), true, `index ${index} is not a hole`);
653
+ }
654
+ assert.deepEqual(snapshotNotices().entries.map((entry) => entry.message), [
655
+ "gentle-shell-bridge: could not fully roll back the provisional rows: the host changed the " +
656
+ "appended rows before the rollback; appended 3 rows; 0 already removed by the host; " +
657
+ "3 removed by the bridge; 0 could not be removed. The host menu was left as consistent as " +
658
+ "the array allowed.",
659
+ ]);
660
+ });
661
+
662
+ test("a locked host row after the append leaves the build array byte-for-byte intact", () => {
663
+ let buildLeft: CustomizeRow[] = [];
664
+ const scenario = throwingHostAfter(
665
+ [
666
+ { label: "Injected one", action: () => {} },
667
+ { label: "Injected two", action: () => {} },
668
+ { label: "Injected three", action: () => {} },
669
+ ],
670
+ (rows) => {
671
+ rows.push(
672
+ { label: "Host extra one", action: () => {} },
673
+ { label: "Host extra two", action: () => {} },
674
+ );
675
+ Object.defineProperty(rows, String(rows.length - 2), {
676
+ configurable: false,
677
+ writable: false,
678
+ });
679
+ buildLeft = [...rows];
680
+ },
681
+ );
682
+
683
+ assert.throws(() => scenario.host.build(), (error) => error === scenario.originalError);
684
+ assert.equal(scenario.rows.length, 9);
685
+ assert.equal(scenario.rows.length, buildLeft.length);
686
+ scenario.rows.forEach((row, index) => {
687
+ assert.equal(row, buildLeft[index], `index ${index} keeps its build-left identity`);
688
+ });
689
+ for (let index = 0; index < 9; index += 1) {
690
+ assert.equal(Object.hasOwn(scenario.rows, String(index)), true, `index ${index} is not a hole`);
691
+ }
692
+ assert.deepEqual(snapshotNotices().entries.map((entry) => entry.message), [
693
+ "gentle-shell-bridge: could not fully roll back the provisional rows: index 7 is " +
694
+ "non-configurable; appended 3 rows; 0 already removed by the host; 0 removed by the " +
695
+ "bridge; 3 could not be removed. The host menu was left as consistent as the array allowed.",
696
+ ]);
697
+ });
698
+
699
+ test("a getter-only earlier splice target makes the rollback write nothing", () => {
700
+ let buildLeft: CustomizeRow[] = [];
701
+ let getterIndex = -1;
702
+ const scenario = throwingHostAfter(
703
+ [
704
+ { label: "Injected one", action: () => {} },
705
+ { label: "Injected two", action: () => {} },
706
+ { label: "Injected three", action: () => {} },
707
+ ],
708
+ (rows) => {
709
+ rows.push(
710
+ { label: "Host extra one", action: () => {} },
711
+ { label: "Host extra two", action: () => {} },
712
+ );
713
+ // The splice writes the host's two later rows into the first two positions it removes.
714
+ // A configurable getter-only accessor at the second target has no `writable` field, so it must
715
+ // be rejected before the first target is written.
716
+ getterIndex = rows.length - 4;
717
+ const value = rows[getterIndex] as CustomizeRow;
718
+ Object.defineProperty(rows, String(getterIndex), {
719
+ configurable: true,
720
+ enumerable: true,
721
+ get() {
722
+ return value;
723
+ },
724
+ });
725
+ buildLeft = [...rows];
726
+ },
727
+ );
728
+
729
+ assert.throws(() => scenario.host.build(), (error) => error === scenario.originalError);
730
+ assert.equal(getterIndex, 5);
731
+ assert.equal(scenario.rows.length, 9);
732
+ scenario.rows.forEach((row, index) => {
733
+ assert.equal(row, buildLeft[index], `index ${index} keeps its build-left identity and value`);
734
+ });
735
+ assert.equal(scenario.rows[4], buildLeft[4], "the earlier splice target was not written");
736
+ assert.notEqual(scenario.rows[4], buildLeft[7], "the first host-added row was not duplicated");
737
+ assert.equal(new Set(scenario.rows).size, scenario.rows.length, "no row identity is duplicated");
738
+ for (let index = 0; index < 9; index += 1) {
739
+ assert.equal(Object.hasOwn(scenario.rows, String(index)), true, `index ${index} is not a hole`);
740
+ }
741
+ assert.deepEqual(snapshotNotices().entries.map((entry) => entry.message), [
742
+ "gentle-shell-bridge: could not fully roll back the provisional rows: index 5 is " +
743
+ "read-only; appended 3 rows; 0 already removed by the host; 0 removed by the bridge; " +
744
+ "3 could not be removed. The host menu was left as consistent as the array allowed.",
745
+ ]);
746
+ });
747
+
748
+ test("a setter-bearing accessor is refused before any write", () => {
749
+ let buildLeft: CustomizeRow[] = [];
750
+ let getterIndex = -1;
751
+ let setterCalls = 0;
752
+ const scenario = throwingHostAfter(
753
+ [
754
+ { label: "Injected one", action: () => {} },
755
+ { label: "Injected two", action: () => {} },
756
+ { label: "Injected three", action: () => {} },
757
+ ],
758
+ (rows) => {
759
+ rows.push(
760
+ { label: "Host extra one", action: () => {} },
761
+ { label: "Host extra two", action: () => {} },
762
+ );
763
+ // A setter is code, not a verifiable write: this one accepts the assignment syntactically and
764
+ // throws the value away. It must never be reached.
765
+ getterIndex = rows.length - 4;
766
+ const value = rows[getterIndex] as CustomizeRow;
767
+ Object.defineProperty(rows, String(getterIndex), {
768
+ configurable: true,
769
+ enumerable: true,
770
+ get() {
771
+ return value;
772
+ },
773
+ set() {
774
+ setterCalls += 1;
775
+ },
776
+ });
777
+ buildLeft = [...rows];
778
+ },
779
+ );
780
+
781
+ assert.throws(() => scenario.host.build(), (error) => error === scenario.originalError);
782
+ assert.equal(getterIndex, 5);
783
+ assert.equal(setterCalls, 0, "the rollback never invokes the host setter");
784
+ assert.equal(scenario.rows.length, 9);
785
+ scenario.rows.forEach((row, index) => {
786
+ assert.equal(row, buildLeft[index], `index ${index} keeps its build-left identity and value`);
787
+ });
788
+ assert.equal(new Set(scenario.rows).size, scenario.rows.length, "no row identity is duplicated");
789
+ for (let index = 0; index < 9; index += 1) {
790
+ assert.equal(Object.hasOwn(scenario.rows, String(index)), true, `index ${index} is not a hole`);
791
+ }
792
+ assert.deepEqual(snapshotNotices().entries.map((entry) => entry.message), [
793
+ "gentle-shell-bridge: could not fully roll back the provisional rows: index 5 is " +
794
+ "read-only; appended 3 rows; 0 already removed by the host; 0 removed by the bridge; " +
795
+ "3 could not be removed. The host menu was left as consistent as the array allowed.",
796
+ ]);
797
+ });