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,247 @@
1
+ /**
2
+ * The sidebar section surface, proven against the fake host in `test/fake-sidebar.ts`.
3
+ *
4
+ * T1 (S9, S4): the fake host models the host's process-global rail state, its `parts` map and the
5
+ * card frame the layout draws from a rail's `cardGroups`. T2 (S1, S2): the section registry on the
6
+ * same process-global bus as the providers — one ordered snapshot, `id` replacement, a disposer
7
+ * that removes exactly one section.
8
+ *
9
+ * The first two tests are the scaffold's own: the fake is not the host, so it must be shown to
10
+ * behave like it (state slot, later registration, framed output) before any section test leans on
11
+ * it.
12
+ */
13
+
14
+ import assert from "node:assert/strict";
15
+ import test from "node:test";
16
+
17
+ import {
18
+ registerRows,
19
+ registerSection,
20
+ resetBusForTests,
21
+ resetSectionsForTests,
22
+ snapshotProviders,
23
+ snapshotSections,
24
+ } from "../../lib/shell-api/bus.ts";
25
+ import type { RowProvider, SidebarSection } from "../../lib/shell-api/types.ts";
26
+ import {
27
+ SIDEBAR_STATE_KEY,
28
+ cardTitles,
29
+ fakeState,
30
+ registerNativeFooter,
31
+ renderSidebar,
32
+ resetSidebar,
33
+ } from "./fake-sidebar.ts";
34
+
35
+ const section = (id: string, extra: Partial<SidebarSection> = {}): SidebarSection => ({
36
+ id,
37
+ title: id.toUpperCase(),
38
+ lines: () => [`body ${id}`],
39
+ ...extra,
40
+ });
41
+
42
+ const provider = (id: string): RowProvider => ({ id, category: "Layout", rows: () => [] });
43
+
44
+ const ids = (): string[] => snapshotSections().map((entry) => entry.id);
45
+
46
+ test.beforeEach(() => {
47
+ resetBusForTests();
48
+ resetSectionsForTests();
49
+ resetSidebar();
50
+ });
51
+
52
+ test("the fake host carries the rail map on the host's process-global state symbol", () => {
53
+ assert.equal(SIDEBAR_STATE_KEY, Symbol.for("gentle-pi.experimental-sidebar.state"));
54
+ assert.equal(renderSidebar(40).join("\n"), "", "an empty host paints nothing");
55
+
56
+ registerNativeFooter();
57
+ const footer = fakeState().parts.get("footer");
58
+ assert.ok(footer !== undefined, "the native footer sits in the host's rail map");
59
+ assert.deepEqual(cardTitles(), ["FOOTER"], "the host draws the rail as one framed card");
60
+ });
61
+
62
+ test("the host can register its footer rail after the first frame was painted", () => {
63
+ assert.deepEqual(cardTitles(), []);
64
+ registerNativeFooter();
65
+ assert.deepEqual(cardTitles(), ["FOOTER"]);
66
+ });
67
+
68
+ test("registerSection returns a disposer that removes exactly that section", () => {
69
+ registerSection(section("a"));
70
+ const disposeB = registerSection(section("b"));
71
+ registerSection(section("c"));
72
+
73
+ assert.deepEqual(ids(), ["a", "b", "c"]);
74
+
75
+ disposeB();
76
+
77
+ assert.deepEqual(ids(), ["a", "c"], "the other sections keep their relative order");
78
+ });
79
+
80
+ test("registerSection stores the caller's object unchanged", () => {
81
+ const registered = section("a", {
82
+ title: "MUSIC",
83
+ meta: () => "1 playing",
84
+ lines: () => ["track -", "album -"],
85
+ defaultVisible: false,
86
+ order: 3,
87
+ });
88
+
89
+ registerSection(registered);
90
+
91
+ assert.equal(snapshotSections()[0], registered, "the snapshot hands back the registered object");
92
+ assert.equal(snapshotSections()[0].title, "MUSIC");
93
+ assert.equal(snapshotSections()[0].defaultVisible, false);
94
+ assert.equal(snapshotSections()[0].order, 3);
95
+ });
96
+
97
+ test("a second registration with the same id replaces in place, keeping its position", () => {
98
+ registerSection(section("a"));
99
+ registerSection(section("b"));
100
+ registerSection(section("c"));
101
+
102
+ const replacement = section("b", { title: "REPLACED" });
103
+ registerSection(replacement);
104
+
105
+ assert.deepEqual(ids(), ["a", "b", "c"], "one entry, original position");
106
+ assert.equal(snapshotSections().length, 3);
107
+ assert.equal(snapshotSections()[1], replacement, "the new registration is the live one");
108
+ assert.equal(snapshotSections()[1].title, "REPLACED");
109
+ });
110
+
111
+ test("the replaced section's disposer does not remove its replacement", () => {
112
+ const disposeFirst = registerSection(section("a"));
113
+ const replacement = section("a", { title: "REPLACED" });
114
+ registerSection(replacement);
115
+
116
+ disposeFirst();
117
+
118
+ assert.deepEqual(ids(), ["a"], "the stale disposer is a no-op, not a removal of the replacement");
119
+ assert.equal(snapshotSections()[0], replacement);
120
+ });
121
+
122
+ test("a disposer called twice is a no-op the second time", () => {
123
+ registerSection(section("a"));
124
+ const disposeB = registerSection(section("b"));
125
+ registerSection(section("c"));
126
+
127
+ disposeB();
128
+ disposeB();
129
+
130
+ assert.deepEqual(ids(), ["a", "c"]);
131
+ });
132
+
133
+ test("sections with an order come first, ascending and ties by id", () => {
134
+ registerSection(section("un-ordered-first"));
135
+ registerSection(section("ten", { order: 10 }));
136
+ registerSection(section("one", { order: 1 }));
137
+ registerSection(section("tie-a", { order: 5 }));
138
+ registerSection(section("tie-b", { order: 5 }));
139
+ registerSection(section("un-ordered-second"));
140
+
141
+ assert.deepEqual(
142
+ ids(),
143
+ ["one", "tie-a", "tie-b", "ten", "un-ordered-first", "un-ordered-second"],
144
+ "ordered sections sort ascending ahead of the unordered ones, which sort by id",
145
+ );
146
+ });
147
+
148
+ test("a replacement may move a section by changing its order", () => {
149
+ registerSection(section("a", { order: 2 }));
150
+ registerSection(section("b", { order: 1 }));
151
+
152
+ registerSection(section("a", { order: 0 }));
153
+
154
+ assert.deepEqual(ids(), ["a", "b"]);
155
+ });
156
+
157
+ test("only numbered orders sort; a section without one goes to the tail", () => {
158
+ registerSection(section("zero", { order: 0 }));
159
+ registerSection(section("unordered", { order: undefined }));
160
+ registerSection(section("negative", { order: -3 }));
161
+ registerSection(section("not-a-number", { order: Number.NaN }));
162
+
163
+ // The unordered half is ordered by `id`, not by registration order: the S2 tiebreak replaced the
164
+ // registration index so the same registrations always draw the same rail (section-placement S2).
165
+ assert.deepEqual(ids(), ["negative", "zero", "not-a-number", "unordered"]);
166
+ });
167
+
168
+ test("a section snapshot is a stable copy taken at call time", () => {
169
+ registerSection(section("a"));
170
+
171
+ const during = snapshotSections();
172
+ const seen: string[] = [];
173
+ for (const entry of during) {
174
+ seen.push(entry.id);
175
+ registerSection(section("late"));
176
+ }
177
+
178
+ assert.deepEqual(seen, ["a"]);
179
+ assert.deepEqual(during.map((entry) => entry.id), ["a"]);
180
+ assert.deepEqual(ids(), ["a", "late"]);
181
+ });
182
+
183
+ test("two independent module copies in one process share one section registry", async () => {
184
+ // A query string yields a second module instance with its own module scope — the closest local
185
+ // model of jiti's `moduleCache: false` loading two package copies.
186
+ const secondCopySpecifier = "../../lib/shell-api/bus.ts?copy=2";
187
+ const copyTwo: typeof import("../../lib/shell-api/bus.ts") = await import(secondCopySpecifier);
188
+
189
+ registerSection(section("from-copy-one"));
190
+ copyTwo.registerSection(section("from-copy-two"));
191
+
192
+ assert.deepEqual(ids(), ["from-copy-one", "from-copy-two"]);
193
+ assert.deepEqual(
194
+ copyTwo.snapshotSections().map((entry) => entry.id),
195
+ ["from-copy-one", "from-copy-two"],
196
+ );
197
+
198
+ const dispose = copyTwo.registerSection(section("shared"));
199
+ assert.deepEqual(ids(), ["from-copy-one", "from-copy-two", "shared"]);
200
+ dispose();
201
+ assert.deepEqual(ids(), ["from-copy-one", "from-copy-two"], "the global registry, not a local one");
202
+ });
203
+
204
+ test("the section list is reachable behind the same bus slot as the providers", () => {
205
+ registerSection(section("a"));
206
+ const slot = (globalThis as unknown as Record<symbol, unknown>)[
207
+ Symbol.for("gentle-shell-bridge.providers")
208
+ ];
209
+ assert.ok(slot !== undefined, "the bus is the provider bus, not a second registry");
210
+ });
211
+
212
+ test("a bus slot created before sections existed keeps its providers and grows a section list", () => {
213
+ // A copy of this package that predates sections writes `{ entries }` only. Reading that slot
214
+ // must not throw away the providers already registered in it.
215
+ const earlierProvider = provider("earlier");
216
+ const slot = globalThis as unknown as Record<symbol, unknown>;
217
+ slot[Symbol.for("gentle-shell-bridge.providers")] = { entries: [{ provider: earlierProvider }] };
218
+
219
+ registerSection(section("a"));
220
+
221
+ assert.deepEqual(ids(), ["a"], "the section list was added in place");
222
+ assert.deepEqual(
223
+ snapshotProviders().map((entry) => entry.id),
224
+ ["earlier"],
225
+ "the providers the earlier copy registered are still there",
226
+ );
227
+ });
228
+
229
+ test("resetSectionsForTests clears sections and leaves providers registered", () => {
230
+ registerRows(provider("p"));
231
+ registerSection(section("a"));
232
+
233
+ resetSectionsForTests();
234
+
235
+ assert.deepEqual(ids(), []);
236
+ assert.deepEqual(
237
+ snapshotProviders().map((entry) => entry.id),
238
+ ["p"],
239
+ "provider state is not the section state",
240
+ );
241
+ });
242
+
243
+ test("the internal section seams are not on the public entry", async () => {
244
+ const entry = await import("../../lib/shell-api/index.ts");
245
+ assert.equal("resetSectionsForTests" in entry, false);
246
+ assert.equal("snapshotSections" in entry, false);
247
+ });
@@ -0,0 +1,192 @@
1
+ import assert from "node:assert/strict";
2
+ import {
3
+ existsSync,
4
+ mkdirSync,
5
+ mkdtempSync,
6
+ readFileSync,
7
+ readdirSync,
8
+ rmSync,
9
+ writeFileSync,
10
+ } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import test from "node:test";
14
+
15
+ import {
16
+ createStore,
17
+ getStoreDiagnostics,
18
+ resetStoreStateForTests,
19
+ STORE_SCHEMA_VERSION,
20
+ } from "../../lib/shell-api/store.ts";
21
+
22
+ let configHome: string;
23
+ let previousConfigHome: string | undefined;
24
+
25
+ const bridgeDir = (): string => join(configHome, "gentle-shell-bridge");
26
+ const storePath = (pluginId: string): string => join(bridgeDir(), `${pluginId}.json`);
27
+
28
+ test.beforeEach(() => {
29
+ configHome = mkdtempSync(join(tmpdir(), "gsb-store-"));
30
+ previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
31
+ process.env.GENTLE_PI_CONFIG_HOME = configHome;
32
+ resetStoreStateForTests();
33
+ });
34
+
35
+ test.afterEach(() => {
36
+ if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
37
+ else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
38
+ rmSync(configHome, { recursive: true, force: true });
39
+ });
40
+
41
+ test("round-trips a value through a namespaced file", () => {
42
+ const store = createStore("loon");
43
+
44
+ assert.equal(store.get("bannerSource", "activity"), "activity");
45
+ assert.equal(store.path, storePath("loon"));
46
+
47
+ store.set("bannerSource", "output");
48
+
49
+ assert.equal(store.get("bannerSource", "activity"), "output");
50
+ const document = JSON.parse(readFileSync(storePath("loon"), "utf8"));
51
+ assert.equal(document.schemaVersion, STORE_SCHEMA_VERSION);
52
+ assert.equal(document.schemaVersion, 1);
53
+ assert.deepEqual(document.values, { bannerSource: "output" });
54
+ });
55
+
56
+ test("a second store instance reads what the first wrote", () => {
57
+ createStore("loon").set("bannerSource", "output");
58
+
59
+ assert.equal(createStore("loon").get("bannerSource", "activity"), "output");
60
+ });
61
+
62
+ test("a missing file reads the caller's default and creates nothing", () => {
63
+ const store = createStore("loon");
64
+
65
+ assert.equal(store.get("bannerSource", "activity"), "activity");
66
+ assert.deepEqual(getStoreDiagnostics(), [], "a missing file is not a problem to report");
67
+ assert.equal(existsSync(bridgeDir()), false, "reading must not create the bridge directory");
68
+ });
69
+
70
+ test("malformed JSON reads the default, is reported, and is left untouched", () => {
71
+ mkdirSync(bridgeDir(), { recursive: true });
72
+ writeFileSync(storePath("loon"), "{ not json", "utf8");
73
+
74
+ const store = createStore("loon");
75
+
76
+ assert.equal(store.get("bannerSource", "activity"), "activity");
77
+ const problems = getStoreDiagnostics();
78
+ assert.equal(problems.length, 1);
79
+ assert.equal(problems[0].pluginId, "loon");
80
+ assert.equal(problems[0].kind, "invalid-json");
81
+ assert.equal(problems[0].path, storePath("loon"));
82
+ assert.equal(
83
+ readFileSync(storePath("loon"), "utf8"),
84
+ "{ not json",
85
+ "the malformed file is neither repaired nor deleted",
86
+ );
87
+ });
88
+
89
+ test("a later set after a malformed file writes a valid document", () => {
90
+ mkdirSync(bridgeDir(), { recursive: true });
91
+ writeFileSync(storePath("loon"), "{ not json", "utf8");
92
+ const store = createStore("loon");
93
+
94
+ store.set("bannerSource", "output");
95
+
96
+ const document = JSON.parse(readFileSync(storePath("loon"), "utf8"));
97
+ assert.equal(document.schemaVersion, 1);
98
+ assert.deepEqual(document.values, { bannerSource: "output" });
99
+ assert.equal(store.get("bannerSource", "activity"), "output");
100
+ assert.deepEqual(getStoreDiagnostics(), [], "a valid write clears that plugin's problem");
101
+ });
102
+
103
+ test("a document that is not an object reads the default and is reported", () => {
104
+ mkdirSync(bridgeDir(), { recursive: true });
105
+ writeFileSync(storePath("loon"), "[1,2,3]", "utf8");
106
+
107
+ const store = createStore("loon");
108
+
109
+ assert.equal(store.get("bannerSource", "activity"), "activity");
110
+ assert.equal(getStoreDiagnostics()[0]?.kind, "not-an-object");
111
+ });
112
+
113
+ test("an unknown schemaVersion reads the default and is reported", () => {
114
+ mkdirSync(bridgeDir(), { recursive: true });
115
+ writeFileSync(
116
+ storePath("loon"),
117
+ JSON.stringify({ schemaVersion: 99, values: { keep: "me" }, extraTopLevel: true }),
118
+ "utf8",
119
+ );
120
+
121
+ const store = createStore("loon");
122
+
123
+ assert.equal(store.get("bannerSource", "activity"), "activity");
124
+ assert.equal(getStoreDiagnostics()[0]?.kind, "unsupported-schema-version");
125
+ });
126
+
127
+ test("a later set after an unknown schemaVersion writes only the caller's keys and reports the discarded payload", () => {
128
+ mkdirSync(bridgeDir(), { recursive: true });
129
+ writeFileSync(
130
+ storePath("loon"),
131
+ JSON.stringify({ schemaVersion: 99, values: { keep: "me" }, extraTopLevel: true }),
132
+ "utf8",
133
+ );
134
+ const store = createStore("loon");
135
+
136
+ store.set("added", 1);
137
+
138
+ const document = JSON.parse(readFileSync(storePath("loon"), "utf8"));
139
+ assert.equal(document.schemaVersion, 1);
140
+ assert.deepEqual(
141
+ document.values,
142
+ { added: 1 },
143
+ "a future schema's payload is never re-labelled as schema 1",
144
+ );
145
+ assert.equal(
146
+ "extraTopLevel" in document,
147
+ false,
148
+ "keys the bridge does not understand are not carried into the valid document",
149
+ );
150
+ const problem = getStoreDiagnostics()[0];
151
+ assert.equal(problem?.kind, "unsupported-schema-version");
152
+ assert.match(problem?.message ?? "", /discarded/);
153
+ });
154
+
155
+ test("writes are atomic: the temp file is gone and the target parses completely", () => {
156
+ const store = createStore("loon");
157
+
158
+ for (let index = 0; index < 5; index += 1) {
159
+ store.set("counter", index);
160
+ assert.deepEqual(readdirSync(bridgeDir()), ["loon.json"], `no temp file after write ${index}`);
161
+ assert.equal(JSON.parse(readFileSync(storePath("loon"), "utf8")).values.counter, index);
162
+ }
163
+ });
164
+
165
+ test("two plugin ids never touch each other's file", () => {
166
+ const loon = createStore("loon");
167
+ const card = createStore("cards");
168
+
169
+ loon.set("bannerSource", "output");
170
+ card.set("style", "rounded");
171
+
172
+ assert.deepEqual(readdirSync(bridgeDir()).sort(), ["cards.json", "loon.json"]);
173
+ assert.equal(loon.get("style", "none"), "none");
174
+ assert.equal(card.get("bannerSource", "none"), "none");
175
+ assert.equal(loon.get("bannerSource", "activity"), "output");
176
+ assert.equal(card.get("style", "plain"), "rounded");
177
+ });
178
+
179
+ test("invalid plugin ids are rejected before any filesystem access", () => {
180
+ const invalidIds = ["", ".", "..", "../escape", "a/b", "a\\b", "nested/../escape", "loon..v2"];
181
+
182
+ for (const pluginId of invalidIds) {
183
+ assert.throws(
184
+ () => createStore(pluginId),
185
+ /invalid plugin id/,
186
+ `plugin id ${JSON.stringify(pluginId)} must be rejected`,
187
+ );
188
+ }
189
+
190
+ assert.equal(existsSync(bridgeDir()), false, "rejection happens before the directory is created");
191
+ assert.equal(existsSync(join(configHome, "escape.json")), false, "nothing escaped the bridge dir");
192
+ });