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.
Files changed (127) hide show
  1. package/README.md +48 -25
  2. package/extensions/odd-worktree-tools.ts +70 -212
  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/package.json +3 -2
  43. package/tools/files-bridge.test.js +81 -66
  44. package/tools/fixtures/load-extension.js +40 -18
  45. package/tools/issues-command.test.js +4 -7
  46. package/tools/issues-section.test.js +71 -81
  47. package/tools/odd-rail-wiring.test.js +16 -10
  48. package/tools/package-surface.test.js +42 -13
  49. package/tools/prs-command.test.js +11 -6
  50. package/tools/session-auto-name-wiring.test.js +39 -0
  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 +8 -9
@@ -0,0 +1,194 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+
4
+ import type { RowProvider } from "../../lib/shell-api/types.ts";
5
+
6
+ const withId = (id: string, category = "Layout"): RowProvider => ({
7
+ id,
8
+ category,
9
+ rows: () => [],
10
+ });
11
+
12
+ // One shared bus for the whole file; every test resets it through the internal seam.
13
+ // `src/index.ts` deliberately does not re-export the seam (asserted below).
14
+ const bus = await import("../../lib/shell-api/bus.ts");
15
+ const { getRowPlacementRejections, registerRows, snapshotProviders, resetBusForTests } = bus;
16
+
17
+ const ids = () => snapshotProviders().map((provider: RowProvider) => provider.id);
18
+
19
+ test.beforeEach(() => {
20
+ resetBusForTests();
21
+ });
22
+
23
+ test("providers are returned in registration order", () => {
24
+ registerRows(withId("a"));
25
+ registerRows(withId("b"));
26
+ registerRows(withId("c"));
27
+ assert.deepEqual(ids(), ["a", "b", "c"]);
28
+ });
29
+
30
+ test("an empty bus returns an empty snapshot", () => {
31
+ assert.deepEqual(snapshotProviders(), []);
32
+ });
33
+
34
+ test("the disposer removes only its own provider", () => {
35
+ registerRows(withId("a"));
36
+ const disposeB = registerRows(withId("b"));
37
+ registerRows(withId("c"));
38
+
39
+ disposeB();
40
+
41
+ assert.deepEqual(ids(), ["a", "c"]);
42
+ });
43
+
44
+ test("the disposer keeps the remaining providers' relative order", () => {
45
+ const disposeA = registerRows(withId("a"));
46
+ registerRows(withId("b"));
47
+ registerRows(withId("c"));
48
+
49
+ disposeA();
50
+
51
+ assert.deepEqual(ids(), ["b", "c"]);
52
+ });
53
+
54
+ test("registering an existing id replaces in place and keeps its position", () => {
55
+ registerRows(withId("a", "Layout"));
56
+ registerRows(withId("b", "Banner"));
57
+ registerRows(withId("c", "Cards"));
58
+
59
+ const replacement = withId("b", "Layout");
60
+ registerRows(replacement);
61
+
62
+ assert.deepEqual(ids(), ["a", "b", "c"], "one entry, original position");
63
+ assert.equal(snapshotProviders().length, 3);
64
+ assert.equal(snapshotProviders()[1], replacement, "the new provider object is the live one");
65
+ assert.equal(snapshotProviders()[1].category, "Layout");
66
+ });
67
+
68
+ test("the replaced provider's disposer does not remove its replacement", () => {
69
+ const disposeFirst = registerRows(withId("a"));
70
+ const replacement = withId("a", "Banner");
71
+ registerRows(replacement);
72
+
73
+ disposeFirst();
74
+
75
+ assert.deepEqual(ids(), ["a"], "the stale disposer is a no-op, not a removal of the replacement");
76
+ assert.equal(snapshotProviders()[0], replacement);
77
+ });
78
+
79
+ test("a disposer called twice is a no-op the second time", () => {
80
+ registerRows(withId("a"));
81
+ const disposeB = registerRows(withId("b"));
82
+ registerRows(withId("c"));
83
+
84
+ disposeB();
85
+ disposeB();
86
+
87
+ assert.deepEqual(ids(), ["a", "c"]);
88
+ });
89
+
90
+ test("a disposer after a reset cannot remove a later provider", () => {
91
+ const disposeA = registerRows(withId("a"));
92
+ resetBusForTests();
93
+ registerRows(withId("a"));
94
+
95
+ disposeA();
96
+
97
+ assert.deepEqual(ids(), ["a"], "the pre-reset disposer must not touch the new registration");
98
+ });
99
+
100
+ test("a snapshot is a stable copy: registering during iteration does not change it", () => {
101
+ registerRows(withId("a"));
102
+
103
+ const during = snapshotProviders();
104
+ const seen: string[] = [];
105
+ for (const provider of during) {
106
+ seen.push(provider.id);
107
+ registerRows(withId("late"));
108
+ }
109
+
110
+ assert.deepEqual(seen, ["a"]);
111
+ assert.deepEqual(during.map((provider: RowProvider) => provider.id), ["a"]);
112
+ assert.deepEqual(ids(), ["a", "late"]);
113
+ });
114
+
115
+ test("two independent module copies in one process share one bus", async () => {
116
+ // Node's ESM loader keys modules by resolved URL, so a query string yields a second instance
117
+ // of the same source with its own module scope — the closest local model of jiti's
118
+ // `moduleCache: false` loading of two package copies. The specifier is computed so `tsc`
119
+ // types it as a dynamic import instead of trying to resolve a URL query on disk.
120
+ const secondCopySpecifier = "../../lib/shell-api/bus.ts?copy=2";
121
+ const copyTwo: typeof bus = await import(secondCopySpecifier);
122
+ assert.notEqual(copyTwo, bus, "the second import must be a distinct module instance");
123
+
124
+ resetBusForTests();
125
+ registerRows(withId("from-copy-one"));
126
+ copyTwo.registerRows(withId("from-copy-two"));
127
+
128
+ assert.deepEqual(ids(), ["from-copy-one", "from-copy-two"]);
129
+ assert.deepEqual(copyTwo.snapshotProviders().map((p: RowProvider) => p.id), [
130
+ "from-copy-one",
131
+ "from-copy-two",
132
+ ]);
133
+ });
134
+
135
+ test("a disposer from another module copy removes its provider", async () => {
136
+ const secondCopySpecifier = "../../lib/shell-api/bus.ts?copy=2";
137
+ const copyTwo: typeof bus = await import(secondCopySpecifier);
138
+
139
+ const dispose = copyTwo.registerRows(withId("shared"));
140
+ registerRows(withId("local"));
141
+ assert.deepEqual(ids(), ["shared", "local"]);
142
+
143
+ dispose();
144
+
145
+ assert.deepEqual(ids(), ["local"], "the visible registry is the process-global one");
146
+ });
147
+
148
+ test("the bus lives on globalThis behind a stable Symbol.for key", () => {
149
+ registerRows(withId("a"));
150
+ const slot = (globalThis as unknown as Record<symbol, unknown>)[
151
+ Symbol.for("gentle-shell-bridge.providers")
152
+ ];
153
+ assert.ok(slot !== undefined, "the registration state must sit on globalThis");
154
+ assert.notEqual(
155
+ Symbol.for("gentle-shell-bridge.providers"),
156
+ Symbol.for("gentle-pi.customize-row-providers"),
157
+ "the bridge bus must not reuse the hook registry key",
158
+ );
159
+ });
160
+
161
+ test("the public entry does not expose the test-only reset seam", async () => {
162
+ const entry = await import("../../lib/shell-api/index.ts");
163
+ assert.equal("resetBusForTests" in entry, false);
164
+ assert.equal("registerRows" in entry, true);
165
+ });
166
+
167
+ test("a placement rejection never changes registration order or replacement in place", () => {
168
+ const malformed = { after: "" } as unknown as RowProvider["placement"];
169
+ registerRows(withId("a", "Layout"));
170
+ // SAFETY: a plugin can pass anything at runtime; the bus must still store exactly one entry.
171
+ registerRows({ ...withId("b", "Layout"), placement: malformed });
172
+ registerRows(withId("c", "Layout"));
173
+
174
+ assert.deepEqual(ids(), ["a", "b", "c"], "the provider is still registered, in its position");
175
+ assert.equal(getRowPlacementRejections().length, 1);
176
+
177
+ const replacement = withId("b", "Layout");
178
+ registerRows(replacement);
179
+
180
+ assert.deepEqual(ids(), ["a", "b", "c"], "replacement happens in place");
181
+ assert.equal(snapshotProviders()[1], replacement, "the new provider object is the live one");
182
+ assert.deepEqual(getRowPlacementRejections(), [], "a conforming replacement clears the record");
183
+ });
184
+
185
+ test("a disposer removes the placement rejection it created", () => {
186
+ const malformed = { after: "" } as unknown as RowProvider["placement"];
187
+ const dispose = registerRows({ ...withId("a", "Layout"), placement: malformed });
188
+
189
+ assert.equal(getRowPlacementRejections().length, 1);
190
+ dispose();
191
+
192
+ assert.deepEqual(snapshotProviders(), []);
193
+ assert.deepEqual(getRowPlacementRejections(), []);
194
+ });
@@ -0,0 +1,435 @@
1
+ /**
2
+ * T27 / S16: a BUTTON row is a first-class kind, not an accident of a missing field.
3
+ *
4
+ * The host's row type (`lib/visual-customize-view.ts:107-130`) makes `choice` optional and
5
+ * `action(inline)` required, and Enter/Space runs `action` (`:575-577`) exactly as it does for the
6
+ * host's own `Profiles` and `Reset` rows (`extensions/gentle-shell.ts:3541,3550`). So a row with
7
+ * `category`, `label`, `action` and NO `choice` is the second supported kind, and this suite pins
8
+ * everything about it through the real entry (`publishBridgeApi().registerRows`) and the real
9
+ * capture path:
10
+ *
11
+ * - it is accepted, reaches the host's array with its category untouched, and renders as its own
12
+ * row — never a value of another row's setting;
13
+ * - `preview`, `keyhint`, `visible` and a function-valued `label` are reference-identical, so the
14
+ * bridge passes them through instead of re-deriving them;
15
+ * - its label is the WHOLE visible text of the row, so the bridge's plain-word row-name rule applies
16
+ * to it exactly as it applies to a toggle's label: a mark, or more than three words, is refused
17
+ * and reported verbatim, and the row is absent rather than rewritten;
18
+ * - `confirmOnEnter` never touches it: no `choice` appears, no `applyOnMove` is injected, and the
19
+ * provider's own object is not mutated;
20
+ * - a throwing (or rejecting) `action` is contained by the bridge and reported ONCE through the
21
+ * notice channel that the diagnostics record lists, so the menu and every other row stay usable;
22
+ * - a provider may mix toggles and buttons in one category, and the order it gave is kept.
23
+ */
24
+
25
+ import assert from "node:assert/strict";
26
+ import { mkdtempSync, rmSync } from "node:fs";
27
+ import { tmpdir } from "node:os";
28
+ import { join } from "node:path";
29
+ import test from "node:test";
30
+
31
+ import { publishBridgeApi, resetBridgeApiForTests } from "../../lib/shell-api/api.ts";
32
+ import { armBridge } from "../../lib/shell-api/arm.ts";
33
+ import {
34
+ registerRows,
35
+ resetBusForTests,
36
+ resetCardStylesForTests,
37
+ resetSectionsForTests,
38
+ resetTransformsForTests,
39
+ } from "../../lib/shell-api/bus.ts";
40
+ import { disableCaptureBackend, resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
41
+ import { resetHookStateForTests } from "../../lib/shell-api/hook.ts";
42
+ import { resetNoticesForTests, snapshotNotices } from "../../lib/shell-api/notices.ts";
43
+ import { getRowNameRejections, resetRowNameRejectionsForTests } from "../../lib/shell-api/row-names.ts";
44
+ import { getLastRowBuild, resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
45
+ import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
46
+ import type { CustomizeRow, RowLabel } from "../../lib/shell-api/types.ts";
47
+ import { createFakeHost, type FakeHost } from "./fake-host.ts";
48
+
49
+ const MARK_RULE =
50
+ "a row name is one to three plain words with no arrow, colon, dot, pipe, slash or bracket";
51
+ const WORD_RULE = "a row name is one to three plain words";
52
+
53
+ const labelText = (label: RowLabel | undefined): string => {
54
+ if (typeof label === "function") return label();
55
+ return label ?? "";
56
+ };
57
+
58
+ const loonLabels = (host: FakeHost): string[] =>
59
+ host
60
+ .liveRows()
61
+ .map((row) => labelText(row.label))
62
+ .filter((label) => label.startsWith("Loon"));
63
+
64
+ const rowsOfLastBuild = (providerId: string): CustomizeRow[] =>
65
+ getLastRowBuild()?.find((record) => record.providerId === providerId)?.rows ?? [];
66
+
67
+ /** The one visible row a provider contributed, as the host holds it right now. */
68
+ const liveRow = (host: FakeHost, label: string): CustomizeRow => {
69
+ const row = host.liveRows().find((candidate) => labelText(candidate.label) === label);
70
+ assert.ok(row !== undefined, `the host holds no row labelled ${JSON.stringify(label)}`);
71
+ return row;
72
+ };
73
+
74
+ let configHome: string;
75
+ let previousConfigHome: string | undefined;
76
+
77
+ test.before(() => {
78
+ configHome = mkdtempSync(join(tmpdir(), "gsb-button-rows-"));
79
+ previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
80
+ process.env.GENTLE_PI_CONFIG_HOME = configHome;
81
+ });
82
+
83
+ test.after(() => {
84
+ if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
85
+ else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
86
+ rmSync(configHome, { recursive: true, force: true });
87
+ });
88
+
89
+ test.beforeEach(() => {
90
+ rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
91
+ resetBridgeApiForTests();
92
+ resetBusForTests();
93
+ resetSectionsForTests();
94
+ resetCardStylesForTests();
95
+ resetTransformsForTests();
96
+ resetRowNameRejectionsForTests();
97
+ resetCaptureStateForTests();
98
+ resetHookStateForTests();
99
+ resetRowBuildStateForTests();
100
+ resetNoticesForTests();
101
+ resetStoreStateForTests();
102
+ disableCaptureBackend();
103
+ });
104
+
105
+ const menuHost = (): FakeHost => {
106
+ const host = createFakeHost();
107
+ armBridge(host.ui);
108
+ return host;
109
+ };
110
+
111
+ /** A toggle line: consecutive rows sharing one `choice.setting`, the existing kind. */
112
+ const toggles = (setting: string, label: string, values: [string, string]): CustomizeRow[] =>
113
+ values.map((value) => ({
114
+ category: "Cards",
115
+ label,
116
+ choice: { setting, value, current: () => value === values[0] },
117
+ action: () => {},
118
+ }));
119
+
120
+ // ---------------------------------------------------------------------------------------------
121
+ // Accepted, rendered, and never a value of somebody else's setting
122
+ // ---------------------------------------------------------------------------------------------
123
+
124
+ test("a button row is accepted in an existing category and Enter runs its action once", async () => {
125
+ const calls: string[] = [];
126
+ publishBridgeApi().registerRows({
127
+ id: "loon.buttons",
128
+ category: "Cards",
129
+ rows: () => [
130
+ ...toggles("Bash rendering", "Bash rendering", ["default", "tool"]),
131
+ { category: "Cards", label: "Loon refresh", action: () => void calls.push("refresh") },
132
+ ],
133
+ });
134
+
135
+ const host = menuHost();
136
+ host.buildMenu();
137
+
138
+ assert.ok(host.categories().includes("Cards"), "an existing category is reused");
139
+ assert.deepEqual(loonLabels(host), ["Loon refresh"], "the row is drawn as its own line");
140
+ assert.deepEqual(
141
+ host.toggleLines(),
142
+ ["Bash rendering ● default ○ tool"],
143
+ "and it is not a value of the toggle line it sits after",
144
+ );
145
+
146
+ const row = liveRow(host, "Loon refresh");
147
+ assert.equal(row.choice, undefined, "a button carries no choice");
148
+ assert.equal("choice" in row, false, "and no choice is invented for it");
149
+
150
+ await host.press("Loon refresh");
151
+ assert.deepEqual(calls, ["refresh"], "Enter (or Space) runs the action exactly once");
152
+ });
153
+
154
+ test("a button row in a new category keeps that category untouched", () => {
155
+ publishBridgeApi().registerRows({
156
+ id: "loon.buttons",
157
+ category: "Loon",
158
+ rows: () => [{ label: "Loon refresh", action: () => {} }],
159
+ });
160
+
161
+ const host = menuHost();
162
+ host.buildMenu();
163
+
164
+ const row = liveRow(host, "Loon refresh");
165
+ assert.equal(row.category, "Loon", "the provider's own category name is not rewritten");
166
+ assert.ok(
167
+ host.liveRows().some((candidate) => candidate.category === "Loon"),
168
+ "the row is in the array the host derives its categories from (visual-customize-view.ts:387)",
169
+ );
170
+ // Fixed by S18: the bridge appends the providers' rows BEFORE the view's constructor runs
171
+ // `options.rows.map(...)` (`visual-customize-view.ts:387`), so the page the row names exists to be
172
+ // selected. A late push — after the factory returned — could only join a page the list already
173
+ // held, which is why a brand-new category was invisible before (E8).
174
+ assert.equal(
175
+ host.categories().includes("Loon"),
176
+ true,
177
+ "the new page is in the category list the view computed",
178
+ );
179
+ });
180
+
181
+ // ---------------------------------------------------------------------------------------------
182
+ // Pass-through: nothing is re-derived
183
+ // ---------------------------------------------------------------------------------------------
184
+
185
+ test("preview, keyhint, visible and a function label pass through untouched", () => {
186
+ const preview = () => ({ title: "Loon · refresh", sample: "redraws the rail" });
187
+ const visible = () => true;
188
+ const label = () => "Loon refresh";
189
+ const action = () => {};
190
+ publishBridgeApi().registerRows({
191
+ id: "loon.buttons",
192
+ category: "Cards",
193
+ rows: () => [{ category: "Cards", label, preview, keyhint: "Enter refresh · Esc close", visible, action }],
194
+ });
195
+
196
+ const host = menuHost();
197
+ host.buildMenu();
198
+ const row = liveRow(host, "Loon refresh");
199
+
200
+ assert.equal(row.label, label, "a function label is handed over as the same function");
201
+ assert.equal(row.preview, preview, "preview is the provider's function");
202
+ assert.equal(row.keyhint, "Enter refresh · Esc close", "keyhint is verbatim");
203
+ assert.equal(row.visible, visible, "visible is the provider's function");
204
+ assert.deepEqual(row.preview?.(), { title: "Loon · refresh", sample: "redraws the rail" });
205
+ assert.equal(row.visible?.(), true);
206
+ assert.notEqual(row.action, action, "the action is the ONE thing the bridge wraps (see below)");
207
+ assert.deepEqual(
208
+ Object.keys(row).sort(),
209
+ ["action", "category", "keyhint", "label", "preview", "visible"],
210
+ "no field is added, dropped or renamed on the way through",
211
+ );
212
+ });
213
+
214
+ // ---------------------------------------------------------------------------------------------
215
+ // The label is the row's whole visible text, so the row-name rule applies to it unchanged
216
+ // ---------------------------------------------------------------------------------------------
217
+
218
+ test("a button label with a structural mark is refused and reported, and its siblings stay", () => {
219
+ publishBridgeApi().registerRows({
220
+ id: "loon.buttons",
221
+ category: "Cards",
222
+ rows: () => [
223
+ { category: "Cards", label: "Loon: refresh", action: () => {} },
224
+ { category: "Cards", label: "Loon refresh the rail now", action: () => {} },
225
+ { category: "Cards", label: () => "Loon: functional label", action: () => {} },
226
+ { category: "Cards", label: "Loon refresh", action: () => {} },
227
+ ],
228
+ });
229
+
230
+ const host = menuHost();
231
+ host.buildMenu();
232
+
233
+ assert.deepEqual(loonLabels(host), ["Loon refresh"], "only the conforming row reaches the menu");
234
+ assert.deepEqual(
235
+ getRowNameRejections(),
236
+ [
237
+ {
238
+ surface: "rows",
239
+ id: "loon.buttons",
240
+ field: "row label",
241
+ value: "Loon: refresh",
242
+ rule: "mark",
243
+ reason: `it contains ":"; ${MARK_RULE}`,
244
+ },
245
+ {
246
+ surface: "rows",
247
+ id: "loon.buttons",
248
+ field: "row label",
249
+ value: "Loon refresh the rail now",
250
+ rule: "words",
251
+ reason: `it has 5 words; ${WORD_RULE}`,
252
+ },
253
+ {
254
+ surface: "rows",
255
+ id: "loon.buttons",
256
+ field: "row label",
257
+ value: "Loon: functional label",
258
+ rule: "mark",
259
+ reason: `it contains ":"; ${MARK_RULE}`,
260
+ },
261
+ ],
262
+ "the same rule as a toggle's label, and a function label is evaluated to check it",
263
+ );
264
+ assert.deepEqual(
265
+ rowsOfLastBuild("loon.buttons").map((row) => labelText(row.label)),
266
+ ["Loon refresh"],
267
+ "the refused rows are absent from the effective set, not merely hidden",
268
+ );
269
+ });
270
+
271
+ // ---------------------------------------------------------------------------------------------
272
+ // confirmOnEnter leaves a button row alone
273
+ // ---------------------------------------------------------------------------------------------
274
+
275
+ test("a button row keeps no choice and no applyOnMove, and the provider's object is not mutated", () => {
276
+ const providerRow: CustomizeRow = { category: "Cards", label: "Loon refresh", action: () => {} };
277
+ const toggleRow: CustomizeRow = {
278
+ category: "Cards",
279
+ label: "Loon rendering",
280
+ choice: { setting: "Loon rendering", value: "on", current: () => true },
281
+ action: () => {},
282
+ };
283
+ publishBridgeApi().registerRows({
284
+ id: "loon.buttons",
285
+ category: "Cards",
286
+ rows: () => [providerRow, toggleRow],
287
+ });
288
+
289
+ const host = menuHost();
290
+ host.buildMenu();
291
+
292
+ assert.deepEqual(
293
+ Object.keys(providerRow).sort(),
294
+ ["action", "category", "label"],
295
+ "the bridge never writes to the row the provider keeps",
296
+ );
297
+ const row = liveRow(host, "Loon refresh");
298
+ assert.equal("choice" in row, false);
299
+ assert.equal("applyOnMove" in row, false);
300
+
301
+ // PRESERVE: the existing kind is unchanged — a choice row still defers its value to Enter.
302
+ const toggle = liveRow(host, "Loon rendering");
303
+ assert.equal(toggle.choice?.applyOnMove, false);
304
+ assert.equal(toggle.action, toggleRow.action, "and its action is handed over untouched");
305
+ });
306
+
307
+ // ---------------------------------------------------------------------------------------------
308
+ // A failing action is contained and reported once
309
+ // ---------------------------------------------------------------------------------------------
310
+
311
+ const failureNotice = (label: string, message: string): string =>
312
+ `gentle-shell-bridge: the button row ${JSON.stringify(label)} from "loon.buttons" failed: ` +
313
+ `${message}. The menu stays open; fix the row's action.`;
314
+
315
+ test("a synchronously throwing action is contained and reported once", async () => {
316
+ const ran: string[] = [];
317
+ publishBridgeApi().registerRows({
318
+ id: "loon.buttons",
319
+ category: "Cards",
320
+ rows: () => [
321
+ {
322
+ category: "Cards",
323
+ label: "Loon explode",
324
+ action: () => {
325
+ ran.push("explode");
326
+ throw new Error("row action exploded");
327
+ },
328
+ },
329
+ { category: "Cards", label: "Loon refresh", action: () => void ran.push("refresh") },
330
+ ],
331
+ });
332
+
333
+ const host = menuHost();
334
+ host.buildMenu();
335
+ assert.deepEqual(loonLabels(host), ["Loon explode", "Loon refresh"]);
336
+
337
+ await host.press("Loon explode");
338
+ await host.press("Loon explode");
339
+
340
+ assert.deepEqual(ran, ["explode", "explode"], "the row ran; the throw did not escape the bridge");
341
+ assert.deepEqual(
342
+ snapshotNotices().entries.map((entry) => `${entry.level}: ${entry.message}`),
343
+ [`error: ${failureNotice("Loon explode", "row action exploded")}`],
344
+ "one report for one repeated failure, not one per press",
345
+ );
346
+
347
+ // The menu is still usable: the other row renders and its action still runs.
348
+ assert.deepEqual(loonLabels(host), ["Loon explode", "Loon refresh"]);
349
+ await host.press("Loon refresh");
350
+ assert.deepEqual(ran, ["explode", "explode", "refresh"]);
351
+ });
352
+
353
+ test("a rejecting action is contained and reported once", async () => {
354
+ publishBridgeApi().registerRows({
355
+ id: "loon.buttons",
356
+ category: "Cards",
357
+ rows: () => [
358
+ {
359
+ category: "Cards",
360
+ label: "Loon explode",
361
+ action: async () => {
362
+ throw new Error("row action rejected");
363
+ },
364
+ },
365
+ ],
366
+ });
367
+
368
+ const host = menuHost();
369
+ host.buildMenu();
370
+
371
+ await host.press("Loon explode");
372
+ await host.press("Loon explode");
373
+
374
+ assert.deepEqual(
375
+ snapshotNotices().entries.map((entry) => entry.message),
376
+ [failureNotice("Loon explode", "row action rejected")],
377
+ "a rejected promise is a failure too, and it is reported once",
378
+ );
379
+ });
380
+
381
+ // ---------------------------------------------------------------------------------------------
382
+ // One provider, both kinds, in its own order
383
+ // ---------------------------------------------------------------------------------------------
384
+
385
+ test("toggles and buttons in one category keep the provider's order", () => {
386
+ publishBridgeApi().registerRows({
387
+ id: "loon.buttons",
388
+ category: "Cards",
389
+ rows: () => [
390
+ ...toggles("Loon alpha", "Loon alpha", ["on", "off"]),
391
+ { category: "Cards", label: "Loon refresh", action: () => {} },
392
+ ...toggles("Loon beta", "Loon beta", ["low", "high"]),
393
+ ],
394
+ });
395
+
396
+ const host = menuHost();
397
+ host.buildMenu();
398
+
399
+ assert.deepEqual(
400
+ rowsOfLastBuild("loon.buttons").map((row) => labelText(row.label)),
401
+ ["Loon alpha", "Loon alpha", "Loon refresh", "Loon beta", "Loon beta"],
402
+ "the build keeps the provider's order across both kinds",
403
+ );
404
+ assert.deepEqual(
405
+ host.toggleLines(),
406
+ ["Loon alpha ● on ○ off", "Loon beta ● low ○ high"],
407
+ "each toggle line is still one line; the button is its own row between them",
408
+ );
409
+ });
410
+
411
+ test("a placed block keeps its toggle pair and its button together, before the host rows", () => {
412
+ publishBridgeApi().registerRows({
413
+ id: "loon.block",
414
+ category: "Cards",
415
+ placement: "start",
416
+ rows: () => [
417
+ ...toggles("Loon alpha", "Loon alpha", ["on", "off"]),
418
+ { category: "Cards", label: "Loon refresh", action: () => {} },
419
+ ],
420
+ });
421
+
422
+ const host = menuHost();
423
+ host.buildMenu();
424
+
425
+ assert.deepEqual(
426
+ host.liveRows().filter((row) => row.category === "Cards").map((row) => labelText(row.label)),
427
+ ["Loon alpha", "Loon alpha", "Loon refresh", "Card bash: builtin", "Card output: builtin"],
428
+ "one block, before the host's own Card rows",
429
+ );
430
+ assert.deepEqual(
431
+ host.toggleLines(),
432
+ ["Loon alpha ● on ○ off"],
433
+ "and its two values are still one line",
434
+ );
435
+ });