pi-odd-worktree 3.15.1 → 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 (126) 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/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/shell-api/api.test.ts +484 -0
  51. package/tools/shell-api/apply-on-move.test.ts +529 -0
  52. package/tools/shell-api/arm.test.ts +220 -0
  53. package/tools/shell-api/bridge-ready.test.ts +309 -0
  54. package/tools/shell-api/bus.test.ts +194 -0
  55. package/tools/shell-api/button-rows.test.ts +435 -0
  56. package/tools/shell-api/capture.test.ts +583 -0
  57. package/tools/shell-api/card-style-rows.test.ts +493 -0
  58. package/tools/shell-api/card-style-transform.test.ts +379 -0
  59. package/tools/shell-api/card-style-wiring.test.ts +258 -0
  60. package/tools/shell-api/card-styles-e2e.test.ts +502 -0
  61. package/tools/shell-api/card-styles.test.ts +324 -0
  62. package/tools/shell-api/card-transcript-path.test.ts +178 -0
  63. package/tools/shell-api/compatibility-regression.test.mjs +64 -0
  64. package/tools/shell-api/config.test.ts +93 -0
  65. package/tools/shell-api/docs-coverage.test.ts +82 -0
  66. package/tools/shell-api/e2e.test.ts +562 -0
  67. package/tools/shell-api/example-bash-identity.test.ts +372 -0
  68. package/tools/shell-api/example-bash-matrix.test.ts +856 -0
  69. package/tools/shell-api/example-designs.test.ts +737 -0
  70. package/tools/shell-api/example-neon-transform.test.ts +283 -0
  71. package/tools/shell-api/example-plain-style.test.ts +1225 -0
  72. package/tools/shell-api/extension.test.ts +157 -0
  73. package/tools/shell-api/fake-events.ts +58 -0
  74. package/tools/shell-api/fake-host.ts +211 -0
  75. package/tools/shell-api/fake-sidebar.ts +516 -0
  76. package/tools/shell-api/fake-transcript.ts +486 -0
  77. package/tools/shell-api/frame-telemetry.test.ts +317 -0
  78. package/tools/shell-api/hook.test.ts +196 -0
  79. package/tools/shell-api/manifest.test.ts +47 -0
  80. package/tools/shell-api/message-design-adoption.test.ts +611 -0
  81. package/tools/shell-api/message-design-follows.test.ts +361 -0
  82. package/tools/shell-api/message-design-pi-release.test.mjs +157 -0
  83. package/tools/shell-api/message-design-regressions.test.mjs +162 -0
  84. package/tools/shell-api/message-design-rows.test.ts +266 -0
  85. package/tools/shell-api/message-design-wiring.test.ts +362 -0
  86. package/tools/shell-api/message-designs.test.ts +339 -0
  87. package/tools/shell-api/new-category.test.ts +1101 -0
  88. package/tools/shell-api/notices.test.ts +292 -0
  89. package/tools/shell-api/plugin-integration-lines.test.ts +827 -0
  90. package/tools/shell-api/presence.test.ts +396 -0
  91. package/tools/shell-api/rail-part-hits.test.ts +281 -0
  92. package/tools/shell-api/rail-surfaces.test.ts +402 -0
  93. package/tools/shell-api/rail-width.test.ts +406 -0
  94. package/tools/shell-api/regression.test.ts +434 -0
  95. package/tools/shell-api/repaint-api.test.ts +200 -0
  96. package/tools/shell-api/reserved-categories.test.ts +250 -0
  97. package/tools/shell-api/row-labels.test.ts +261 -0
  98. package/tools/shell-api/row-names.test.ts +407 -0
  99. package/tools/shell-api/row-origin.test.ts +395 -0
  100. package/tools/shell-api/row-placement-regression.test.ts +797 -0
  101. package/tools/shell-api/row-placement.test.ts +410 -0
  102. package/tools/shell-api/section-interaction.test.ts +364 -0
  103. package/tools/shell-api/section-panel.test.ts +430 -0
  104. package/tools/shell-api/section-placement-rail.test.ts +390 -0
  105. package/tools/shell-api/section-placement.test.ts +386 -0
  106. package/tools/shell-api/sections-preview.test.ts +312 -0
  107. package/tools/shell-api/sections-rows.test.ts +293 -0
  108. package/tools/shell-api/sidebar-backend.test.ts +477 -0
  109. package/tools/shell-api/sidebar-e2e.test.ts +317 -0
  110. package/tools/shell-api/sidebar-hover.test.ts +276 -0
  111. package/tools/shell-api/sidebar-independent.test.ts +291 -0
  112. package/tools/shell-api/sidebar-render.test.ts +281 -0
  113. package/tools/shell-api/sidebar-sections.test.ts +247 -0
  114. package/tools/shell-api/store.test.ts +192 -0
  115. package/tools/shell-api/surface-repaint-cost.test.ts +520 -0
  116. package/tools/shell-api/tool-design-card-style.test.ts +308 -0
  117. package/tools/shell-api/tool-design-chain.test.ts +471 -0
  118. package/tools/shell-api/tool-design-cost.test.ts +591 -0
  119. package/tools/shell-api/tool-design-rows.test.ts +627 -0
  120. package/tools/shell-api/tool-design-scopes-audit.test.ts +212 -0
  121. package/tools/shell-api/tool-designs.test.ts +2412 -0
  122. package/tools/shell-api/transform-pipeline.test.ts +376 -0
  123. package/tools/shell-api/transforms-bus.test.ts +233 -0
  124. package/tools/shell-api/verifier-width-regressions.test.ts +147 -0
  125. package/tools/shell-api-rpc.test.js +189 -0
  126. package/tools/user-prompt-card.test.js +8 -9
@@ -0,0 +1,82 @@
1
+ import assert from "node:assert/strict";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { dirname, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import test from "node:test";
6
+
7
+ // The shell API is odd-worktree's own code, so its docs live in this repository's `docs/shell-api/`
8
+ // (T5 flattened `lib/bridge/docs/` into it). The package root stays the one this suite runs in.
9
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
10
+
11
+ /** The markdown a plugin author is expected to read before their first registration. */
12
+ const DOC_FILES = [
13
+ "docs/shell-api/README.md",
14
+ "docs/shell-api/contract.md",
15
+ "docs/shell-api/architecture.md",
16
+ "docs/shell-api/state.md",
17
+ ];
18
+
19
+ /** Every `[text](target)` target in one markdown file, excluding anchors and absolute URLs. */
20
+ const localTargets = (file: string): { target: string; line: number }[] => {
21
+ const text = readFileSync(resolve(packageRoot, file), "utf8");
22
+ const targets: { target: string; line: number }[] = [];
23
+ text.split("\n").forEach((line, index) => {
24
+ const pattern = /\[[^\]]*\]\(([^)\s]+)\)/g;
25
+ for (const match of line.matchAll(pattern)) {
26
+ const target = match[1];
27
+ if (target.startsWith("http://") || target.startsWith("https://") || target.startsWith("#")) {
28
+ continue;
29
+ }
30
+ targets.push({ target: target.split("#")[0], line: index + 1 });
31
+ }
32
+ });
33
+ return targets;
34
+ };
35
+
36
+ test("the shell API's documented files exist in the repository", () => {
37
+ for (const file of DOC_FILES) {
38
+ assert.ok(existsSync(resolve(packageRoot, file)), `documented file is missing: ${file}`);
39
+ }
40
+ });
41
+
42
+ test("every local link in the shell API's docs resolves", () => {
43
+ for (const file of DOC_FILES) {
44
+ for (const { target, line } of localTargets(file)) {
45
+ const resolved = resolve(packageRoot, dirname(file), target);
46
+ assert.ok(
47
+ existsSync(resolved),
48
+ `${file}:${line} links a path that does not exist: ${target}`,
49
+ );
50
+ }
51
+ }
52
+ });
53
+
54
+ test("every fenced block in the shell API's docs is closed by a bare fence", () => {
55
+ // CommonMark: a closing fence may be followed only by spaces. `​```text` opens a block instead of
56
+ // closing one, so a doc that closes every block that way renders as one code block from the first
57
+ // fence onward — which is what the contract did before this test existed.
58
+ for (const file of DOC_FILES) {
59
+ const lines = readFileSync(resolve(packageRoot, file), "utf8").split("\n");
60
+ let openAt: number | undefined;
61
+ lines.forEach((line, index) => {
62
+ if (!line.startsWith("```")) return;
63
+ if (openAt === undefined) {
64
+ openAt = index + 1;
65
+ return;
66
+ }
67
+ if (line.trim() === "```") {
68
+ openAt = undefined;
69
+ return;
70
+ }
71
+ assert.fail(
72
+ `${file}:${index + 1} opens a nested block instead of closing the one opened at ${openAt}: ` +
73
+ `a closing fence carries no info string`,
74
+ );
75
+ });
76
+ assert.equal(
77
+ openAt,
78
+ undefined,
79
+ `${file}:${String(openAt)} opens a code block the file never closes`,
80
+ );
81
+ }
82
+ });
@@ -0,0 +1,562 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+
7
+ // The public surface, exactly as a plugin reaches it.
8
+ import * as publicApi from "../../lib/shell-api/index.ts";
9
+ import {
10
+ createStore,
11
+ registerRows,
12
+ STORE_SCHEMA_VERSION,
13
+ VERSION,
14
+ type CardFrame,
15
+ type CardFrameBottomContext,
16
+ type CardFrameLineContext,
17
+ type CardFrameTopContext,
18
+ type CardStyleRegistration,
19
+ type CustomizeRow,
20
+ type InlineHelpers,
21
+ type MessageDesignContext,
22
+ type MessageDesignRegistration,
23
+ type MessageDesignRender,
24
+ type RowChoice,
25
+ type RowContext,
26
+ type RowLabel,
27
+ type RowPreview,
28
+ type RowProvider,
29
+ type SectionContext,
30
+ type SidebarSection,
31
+ type Store,
32
+ type StoreProblem,
33
+ type StoreProblemKind,
34
+ type TransformContext,
35
+ type TranscriptTransform,
36
+ } from "../../lib/shell-api/index.ts";
37
+ // The real Pi entry: armed and commanded exactly as Pi loads it.
38
+ import gentleShellBridge, {
39
+ type BridgeExtensionApi,
40
+ type BridgeSessionHandler,
41
+ } from "../../lib/shell-api/extension.ts";
42
+
43
+ /** One recorded command registration: the host's own shape, used to prove none is added. */
44
+ type RecordedCommandHandler = (args: string, ctx: unknown) => unknown;
45
+ // Teardown-only seams; the API-surface test proves they are not public.
46
+ import {
47
+ observedHostCategories,
48
+ resetBusForTests,
49
+ resolveRowPlacements,
50
+ rowPlacementLandingText,
51
+ snapshotProviders,
52
+ } from "../../lib/shell-api/bus.ts";
53
+ import { getCaptureDiagnostics, resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
54
+ import { getHookDiagnostics, resetHookStateForTests } from "../../lib/shell-api/hook.ts";
55
+ import { resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
56
+ import { getStoreDiagnostics, resetStoreStateForTests } from "../../lib/shell-api/store.ts";
57
+ import { createFakeHost, type FakeHost } from "./fake-host.ts";
58
+
59
+ const HOOK_KEY = Symbol.for("gentle-pi.customize-row-providers");
60
+ const hookSlot = (): Record<symbol, unknown> => globalThis as unknown as Record<symbol, unknown>;
61
+
62
+ let configHome: string;
63
+ let previousConfigHome: string | undefined;
64
+ let pristineMap: typeof Array.prototype.map;
65
+
66
+ test.before(() => {
67
+ pristineMap = Array.prototype.map;
68
+ configHome = mkdtempSync(join(tmpdir(), "gsb-e2e-"));
69
+ previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
70
+ process.env.GENTLE_PI_CONFIG_HOME = configHome;
71
+ });
72
+
73
+ test.after(() => {
74
+ if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
75
+ else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
76
+ Array.prototype.map = pristineMap;
77
+ rmSync(configHome, { recursive: true, force: true });
78
+ });
79
+
80
+ test.beforeEach(() => {
81
+ resetBusForTests();
82
+ resetCaptureStateForTests();
83
+ resetRowBuildStateForTests();
84
+ resetHookStateForTests();
85
+ resetStoreStateForTests();
86
+ delete hookSlot()[HOOK_KEY];
87
+ });
88
+
89
+ test.afterEach(() => {
90
+ Array.prototype.map = pristineMap;
91
+ delete hookSlot()[HOOK_KEY];
92
+ });
93
+
94
+ interface Entry {
95
+ sessionHandlers: BridgeSessionHandler[];
96
+ commands: Array<{ name: string; description?: string; handler: RecordedCommandHandler }>;
97
+ }
98
+
99
+ /** Load the real extension entry against a recording API, as Pi would. */
100
+ const loadEntry = (): Entry => {
101
+ const sessionHandlers: BridgeSessionHandler[] = [];
102
+ const commands: Entry["commands"] = [];
103
+ const pi: BridgeExtensionApi = {
104
+ // `gentle-pi` is loaded, so the runtime gate is open (S9/T12).
105
+ getCommands: () => [{ name: "gentle:customize" }],
106
+ on(_event, handler) {
107
+ sessionHandlers.push(handler);
108
+ },
109
+ registerCommand(name, command) {
110
+ commands.push({ name, description: command.description, handler: command.handler });
111
+ },
112
+ };
113
+ gentleShellBridge(pi);
114
+ return { sessionHandlers, commands };
115
+ };
116
+
117
+ /** Pi fires `session_start`; the entry arms the bridge. */
118
+ const armThroughEntry = (ui: unknown): Entry => {
119
+ const entry = loadEntry();
120
+ entry.sessionHandlers[0]({}, { hasUI: true, ui });
121
+ return entry;
122
+ };
123
+
124
+ const labels = (id: string, category: string, values: string[]): RowProvider => ({
125
+ id,
126
+ category,
127
+ rows: () => values.map((label) => ({ label, action: () => {} })),
128
+ });
129
+
130
+ const armAndBuild = (host: FakeHost): Entry => {
131
+ const entry = armThroughEntry(host.ui);
132
+ host.buildMenu();
133
+ return entry;
134
+ };
135
+
136
+ test("two providers reach one menu build through registerRows, in subscription order", () => {
137
+ registerRows(labels("first", "Cards", ["First a"]));
138
+ registerRows(labels("second", "Banner", ["Second b"]));
139
+ const host = createFakeHost();
140
+
141
+ armAndBuild(host);
142
+
143
+ assert.deepEqual(host.rendered().slice(4), ["First a", "Second b"]);
144
+ assert.deepEqual(
145
+ host.liveRows().slice(4).map((row) => row.category),
146
+ ["Cards", "Banner"],
147
+ );
148
+ });
149
+
150
+ test("a throwing provider loses only its rows, the menu still renders, and the failure is recorded", () => {
151
+ registerRows(labels("before", "Cards", ["Before ok"]));
152
+ registerRows({
153
+ id: "boom",
154
+ category: "Banner",
155
+ rows: () => {
156
+ throw new Error("e2e provider exploded");
157
+ },
158
+ });
159
+ registerRows(labels("after", "Layout", ["After ok"]));
160
+ const host = createFakeHost();
161
+
162
+ armAndBuild(host);
163
+
164
+ assert.deepEqual(host.rendered().slice(4), ["Before ok", "After ok"]);
165
+ const failures = getCaptureDiagnostics().lastFailures;
166
+ assert.equal(failures.length, 1, "the frame records the one failure");
167
+ assert.equal(failures[0].providerId, "boom");
168
+ assert.equal(failures[0].message, "e2e provider exploded");
169
+ assert.equal(failures[0].rowsDropped, true);
170
+ });
171
+
172
+ test("Array.prototype.map identity survives success, a throwing factory and a non-row array", () => {
173
+ registerRows(labels("p1", "Cards", ["Row"]));
174
+
175
+ const okHost = createFakeHost();
176
+ armThroughEntry(okHost.ui);
177
+ const beforeSuccess = Array.prototype.map;
178
+ okHost.buildMenu();
179
+ assert.equal(Array.prototype.map, beforeSuccess);
180
+
181
+ const throwingHost = createFakeHost({ throwInsideFactory: true });
182
+ armThroughEntry(throwingHost.ui);
183
+ const beforeThrow = Array.prototype.map;
184
+ assert.throws(() => throwingHost.buildMenu(), /factory exploded/);
185
+ assert.equal(Array.prototype.map, beforeThrow);
186
+
187
+ const nonRowHost = createFakeHost({ mapOnlyNonRows: true });
188
+ armThroughEntry(nonRowHost.ui);
189
+ const beforeNonRows = Array.prototype.map;
190
+ nonRowHost.buildMenu();
191
+ assert.equal(Array.prototype.map, beforeNonRows);
192
+ assert.deepEqual(
193
+ nonRowHost.rendered().filter((label) => label === "Row"),
194
+ [],
195
+ "a plain array of numbers is never injected into",
196
+ );
197
+ });
198
+
199
+ test("two session_start events through the entry arm once: one injection, one invalidate", () => {
200
+ registerRows(labels("p1", "Cards", ["Once"]));
201
+ const host = createFakeHost();
202
+ const entry = loadEntry();
203
+ const context = { hasUI: true, ui: host.ui };
204
+
205
+ entry.sessionHandlers[0]({}, context);
206
+ entry.sessionHandlers[0]({}, context);
207
+
208
+ host.buildMenu();
209
+ assert.deepEqual(
210
+ host.rendered().filter((label) => label === "Once"),
211
+ ["Once"],
212
+ "the rows are injected once, not twice",
213
+ );
214
+ assert.equal(host.invalidateCount(), 1, "one invalidate per menu build");
215
+ assert.equal(host.factoryCallCount(), 1, "the host factory ran once");
216
+ assert.equal(getCaptureDiagnostics().armedTargets, 1, "the capture backend is the one armed");
217
+ });
218
+
219
+ test("the hook registry is preferred through the entry: nothing wrapped, rows via the registry", () => {
220
+ const registry: Array<{ id: string; rows: (ctx?: unknown) => CustomizeRow[] }> = [];
221
+ hookSlot()[HOOK_KEY] = registry;
222
+ registerRows(labels("hooked", "Cards", ["Hooked row"]));
223
+ const host = createFakeHost();
224
+ const customBefore = host.ui.custom;
225
+
226
+ const entry = armThroughEntry(host.ui);
227
+
228
+ assert.equal(host.ui.custom, customBefore, "capture patches nothing when the hook exists");
229
+ assert.equal(registry.length, 1, "one fan-out provider in the registry");
230
+ assert.deepEqual(
231
+ registry[0].rows({}).map((row) => row.label),
232
+ ["Hooked row"],
233
+ "rows land through the registry's own call path",
234
+ );
235
+ const hook = getHookDiagnostics();
236
+ assert.equal(hook.installed, true, "the hook backend is the one in use");
237
+ assert.equal(hook.lastOutcome, "hooked");
238
+ });
239
+
240
+ test("createStore writes atomically under the real config-home override", () => {
241
+ const store = createStore("e2e");
242
+ const bridgeDir = join(configHome, "gentle-shell-bridge");
243
+
244
+ store.set("bannerSource", "output");
245
+
246
+ assert.ok(store.path.startsWith(bridgeDir), "the store path follows GENTLE_PI_CONFIG_HOME");
247
+ assert.equal(store.path, join(bridgeDir, "e2e.json"));
248
+ assert.equal(store.get("bannerSource", "activity"), "output");
249
+ const entries = readdirSync(bridgeDir);
250
+ assert.ok(entries.includes("e2e.json"));
251
+ assert.deepEqual(entries.filter((name) => name.endsWith(".tmp")), [], "no temp file remains");
252
+ const document = JSON.parse(readFileSync(store.path, "utf8"));
253
+ assert.equal(document.schemaVersion, STORE_SCHEMA_VERSION);
254
+ assert.deepEqual(document.values, { bannerSource: "output" });
255
+ });
256
+
257
+ test("a malformed store file falls back, is recorded as a problem, and is fixed by a later set", () => {
258
+ const bridgeDir = join(configHome, "gentle-shell-bridge");
259
+ mkdirSync(bridgeDir, { recursive: true });
260
+ const path = join(bridgeDir, "broken.json");
261
+ writeFileSync(path, "{ not json", "utf8");
262
+ const store = createStore("broken");
263
+
264
+ assert.equal(store.get("bannerSource", "activity"), "activity");
265
+ const problems = getStoreDiagnostics();
266
+ assert.equal(problems.length, 1, "the unusable file is recorded once");
267
+ assert.equal(problems[0].pluginId, "broken");
268
+ assert.equal(problems[0].kind, "invalid-json");
269
+ assert.equal(problems[0].path, path);
270
+ assert.equal(readFileSync(path, "utf8"), "{ not json", "reads never repair the file");
271
+
272
+ store.set("bannerSource", "output");
273
+
274
+ const document = JSON.parse(readFileSync(path, "utf8"));
275
+ assert.equal(document.schemaVersion, 1);
276
+ assert.deepEqual(document.values, { bannerSource: "output" });
277
+ assert.deepEqual(getStoreDiagnostics(), [], "a later set repairs the record");
278
+ });
279
+
280
+ test("S8 end to end: action persists first and the repaint shows the new bullet", async () => {
281
+ const store = createStore("e2e-toggle");
282
+ const toggle = (value: string): CustomizeRow => ({
283
+ category: "Banner",
284
+ label: () => "Loon banner source",
285
+ choice: {
286
+ setting: "Loon banner source",
287
+ value,
288
+ current: () => store.get("bannerSource", "activity") === value,
289
+ },
290
+ action: () => {
291
+ store.set("bannerSource", value); // persist first
292
+ }, // the view repaints second
293
+ });
294
+ registerRows({
295
+ id: "loon.banner-source",
296
+ category: "Banner",
297
+ rows: () => [toggle("activity"), toggle("output")],
298
+ });
299
+ const host = createFakeHost();
300
+ armThroughEntry(host.ui);
301
+ host.buildMenu();
302
+
303
+ assert.deepEqual(host.toggleLines(), ["Loon banner source ● activity ○ output"]);
304
+
305
+ await host.pressRow((row) => row.choice?.value === "output");
306
+
307
+ assert.equal(store.get("bannerSource", "activity"), "output", "action persisted before repaint");
308
+ assert.deepEqual(
309
+ host.toggleLines(),
310
+ // Row order is fixed by the menu; only the rendered bullet moves onto the new value.
311
+ ["Loon banner source ○ activity ● output"],
312
+ "the same menu repaints onto the new value, with no second build",
313
+ );
314
+ assert.equal(host.factoryCallCount(), 1, "no second menu build was needed");
315
+ });
316
+
317
+ test("the public entry exports exactly the contract surface and no test seams", () => {
318
+ assert.deepEqual(Object.keys(publicApi).sort(), [
319
+ "BRIDGE_READY_EVENT",
320
+ "STORE_SCHEMA_VERSION",
321
+ "VERSION",
322
+ "bridgeApi",
323
+ "createStore",
324
+ "isBridgeApi",
325
+ "onBridgeApi",
326
+ "registerCardStyle",
327
+ "registerMessageDesign",
328
+ "registerRows",
329
+ "registerSection",
330
+ "registerToolDesign",
331
+ "registerTransform",
332
+ "resolveCardStyleSelection",
333
+ "resolveMessageDesignFollow",
334
+ "resolveMessageDesignSelection",
335
+ "resolveToolDesignSelection",
336
+ ]);
337
+ for (const seam of [
338
+ "installCardStyleTransform",
339
+ "disableCardStyleTransform",
340
+ "getCardStyleWiringDiagnostics",
341
+ "resetCardStyleWiringForTests",
342
+ "transformCardLines",
343
+ "getCardStyleTransformFailures",
344
+ "getCardStyleLastOutcome",
345
+ "resetCardStyleTransformForTests",
346
+ "installCardStyleRows",
347
+ "cardStyleRowMode",
348
+ "extendCardStyleLine",
349
+ "setCardStyleSelection",
350
+ "getCardStyleSelection",
351
+ "snapshotCardStyles",
352
+ "resetCardStylesForTests",
353
+ "CARD_STYLE_NATIVE",
354
+ "HOST_CARD_STYLE_SETTING",
355
+ "resetBusForTests",
356
+ "resetCaptureStateForTests",
357
+ "resetHookStateForTests",
358
+ "resetStoreStateForTests",
359
+ "snapshotSections",
360
+ "resetSectionsForTests",
361
+ "snapshotProviders",
362
+ "installSectionRail",
363
+ "installSectionRows",
364
+ "setRailContributor",
365
+ "getSectionFailures",
366
+ "getSidebarDiagnostics",
367
+ "resetBridgeApiForTests",
368
+ "publishBridgeApi",
369
+ "BRIDGE_API_KEY",
370
+ "snapshotTransforms",
371
+ "resetTransformsForTests",
372
+ "applyTransforms",
373
+ "getTransformFrameOutcomes",
374
+ "resetTransformPipelineForTests",
375
+ "getToolDesignLineSelection",
376
+ "setToolDesignLineSelection",
377
+ "getToolDesignSelectionReads",
378
+ "resetToolDesignSelectionReads",
379
+ "messageDesignLines",
380
+ "messageDesignRows",
381
+ "messageDesignLineNames",
382
+ "getMessageDesignSelection",
383
+ "getMessageDesignLineSelection",
384
+ "setMessageDesignSelection",
385
+ "setMessageDesignLineSelection",
386
+ "applyMessageDesign",
387
+ "getMessageDesignConflicts",
388
+ "getMessageDesignFailures",
389
+ "getMessageDesignSelectionReads",
390
+ "isMessageTypeClaimed",
391
+ "adoptCustomMessages",
392
+ "messageDesignRenderer",
393
+ "installMessageDesignRows",
394
+ "resetMessageDesignsForTests",
395
+ "resetMessageDesignAdoptionForTests",
396
+ "resetMessageDesignRowStateForTests",
397
+ ]) {
398
+ assert.equal(seam in publicApi, false, `${seam} must not be public`);
399
+ }
400
+ });
401
+
402
+ test("the documented values and types are reachable from the public entry", () => {
403
+ const provider: RowProvider = { id: "api", category: "Cards", rows: (): CustomizeRow[] => [] };
404
+ // The card-style surface: one registration, three functions, the contexts they receive.
405
+ const cardStyle: CardStyleRegistration = {
406
+ id: "api.cute",
407
+ label: "cute",
408
+ order: 1,
409
+ frame: {
410
+ top: (frameCtx: CardFrameTopContext) => `${frameCtx.title ?? ""}${frameCtx.hint ?? ""}`,
411
+ line: (frameCtx: CardFrameLineContext) => `${frameCtx.text}${frameCtx.first}`,
412
+ bottom: (frameCtx: CardFrameBottomContext) => String(frameCtx.width),
413
+ },
414
+ preview: (): RowPreview => ({ title: "Cute", sample: "sample" }),
415
+ };
416
+ const context: RowContext = { theme: undefined, configHome: configHome };
417
+ const choice: RowChoice = { setting: "s", value: "v", current: () => true };
418
+ const label: RowLabel = "text";
419
+ const preview: RowPreview = { title: "t", sample: "s" };
420
+ const helpers: InlineHelpers = {
421
+ input: async () => undefined,
422
+ confirm: async () => true,
423
+ capture: async () => undefined,
424
+ };
425
+ const store: Store = createStore("api-surface");
426
+ const kind: StoreProblemKind = "invalid-json";
427
+ const problem: StoreProblem = { pluginId: "api", path: "/tmp/x", kind, message: "m" };
428
+ // The section surface is public too: a section is written by a plugin and registered with one call.
429
+ const frame: CardFrame = cardStyle.frame;
430
+ assert.equal(typeof frame.bottom, "function");
431
+ const section: SidebarSection = {
432
+ id: "api.section",
433
+ title: "API",
434
+ meta: (sectionCtx: SectionContext) => sectionCtx.configHome,
435
+ lines: (sectionCtx: SectionContext) => [sectionCtx.configHome],
436
+ defaultVisible: true,
437
+ order: 1,
438
+ };
439
+ // The transform surface: one function over the rows, plus the context it receives.
440
+ const transform: TranscriptTransform = {
441
+ id: "api.transform",
442
+ order: 2,
443
+ transform: (lines: readonly string[], transformCtx: TransformContext) => [
444
+ ...lines,
445
+ String(transformCtx.width),
446
+ ],
447
+ };
448
+
449
+ assert.equal(provider.rows(context).length, 0);
450
+ assert.equal(typeof publicApi.registerCardStyle, "function", "the entry exports the registration");
451
+ // The message-design surface: one registration and the context its `apply` receives.
452
+ const render: MessageDesignRender = { expanded: false, outputPad: 1, message: { customType: "x" } };
453
+ const messageContext: MessageDesignContext = { width: 5, customType: "x", render };
454
+ const messageDesign: MessageDesignRegistration = {
455
+ customType: "x",
456
+ id: "api.budget",
457
+ label: "budget",
458
+ apply: (lines: readonly string[], designCtx: MessageDesignContext) => [
459
+ ...lines,
460
+ `${designCtx.customType}@${designCtx.width}`,
461
+ ],
462
+ };
463
+ assert.equal(
464
+ typeof publicApi.registerMessageDesign,
465
+ "function",
466
+ "the entry exports the message-design registration",
467
+ );
468
+ assert.equal(typeof publicApi.resolveMessageDesignSelection, "function");
469
+ assert.equal(
470
+ typeof publicApi.resolveMessageDesignFollow,
471
+ "function",
472
+ "a design that follows a tool switch can be asked what it answers right now",
473
+ );
474
+ assert.deepEqual(messageDesign.apply(["row"], messageContext), ["row", "x@5"]);
475
+ assert.equal(render.expanded, false);
476
+ assert.equal(
477
+ typeof publicApi.registerTransform,
478
+ "function",
479
+ "and the transcript-transform registration",
480
+ );
481
+ assert.equal(cardStyle.frame.top({ width: 1, title: "t" }), "t");
482
+ assert.equal(cardStyle.frame.line({ text: "x", width: 1, first: true }), "xtrue");
483
+ assert.equal(cardStyle.frame.bottom({ width: 7 }), "7");
484
+ assert.deepEqual(cardStyle.preview?.(), { title: "Cute", sample: "sample" });
485
+ assert.equal(choice.value, "v");
486
+ assert.equal(label, "text");
487
+ assert.deepEqual(preview, { title: "t", sample: "s" });
488
+ assert.equal(typeof helpers.confirm, "function");
489
+ assert.equal(store.pluginId, "api-surface");
490
+ assert.equal(problem.kind, "invalid-json");
491
+ assert.equal(STORE_SCHEMA_VERSION, 1);
492
+ assert.equal(section.title, "API");
493
+ assert.equal(section.lines(context).length, 1);
494
+ assert.deepEqual(transform.transform(["a"], { width: 3 }), ["a", "3"]);
495
+ assert.equal(VERSION, "0.16.2");
496
+ });
497
+
498
+ // ---------------------------------------------------------------------------------------------
499
+ // Row placement (S4, S5, S6) through the real entry and the two backends
500
+ // ---------------------------------------------------------------------------------------------
501
+
502
+ test("row placement survives the real entry: start and after land inside the category", () => {
503
+ registerRows({
504
+ id: "loon.top",
505
+ category: "Cards",
506
+ placement: "start",
507
+ rows: () => [{ label: "Loon top", action: () => {} }],
508
+ });
509
+ registerRows({
510
+ id: "loon.next",
511
+ category: "Cards",
512
+ placement: { after: "loon.top" },
513
+ rows: () => [{ label: "Loon next", action: () => {} }],
514
+ });
515
+ const host = createFakeHost();
516
+
517
+ armAndBuild(host);
518
+
519
+ assert.deepEqual(host.rendered(), [
520
+ "Loon top",
521
+ "Loon next",
522
+ "Card bash: builtin",
523
+ "Card output: builtin",
524
+ "Banner: builtin",
525
+ "Layout: builtin",
526
+ ]);
527
+ });
528
+
529
+ test("the hook backend orders by S2 and reports that start/after could not be honoured", () => {
530
+ const registry: Array<{ id: string; rows: (ctx?: unknown) => CustomizeRow[] }> = [];
531
+ hookSlot()[HOOK_KEY] = registry;
532
+ registerRows({
533
+ id: "loon.start",
534
+ category: "Cards",
535
+ placement: "start",
536
+ rows: () => [{ label: "Loon start", action: () => {} }],
537
+ });
538
+ registerRows({
539
+ id: "loon.first",
540
+ category: "Cards",
541
+ order: 1,
542
+ rows: () => [{ label: "Loon first", action: () => {} }],
543
+ });
544
+ const entry = armThroughEntry(createFakeHost().ui);
545
+
546
+ const rows = registry[0].rows({});
547
+
548
+ assert.deepEqual(
549
+ rows.map((row) => row.label),
550
+ ["Loon first", "Loon start"],
551
+ "the finite order comes first; the start request falls back to the end here",
552
+ );
553
+ assert.equal(getHookDiagnostics().installed, true, "the hook backend is the one in use");
554
+ // The hook path builds no menu, so no landing is recorded: the resolver's own plan is what the
555
+ // session would have drawn, and it says the same thing the report used to.
556
+ const plan = resolveRowPlacements(snapshotProviders(), observedHostCategories());
557
+ const start = plan.find((resolution) => resolution.provider.id === "loon.start");
558
+ assert.ok(start !== undefined, "the requested placement is planned");
559
+ assert.equal(start.requested, "start");
560
+ assert.equal(rowPlacementLandingText(start), "end");
561
+ assert.match(start.reason ?? "", /the host did not build the category "Cards"/u);
562
+ });