pi-odd-worktree 3.15.1 → 3.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -25
- package/extensions/odd-worktree-tools.ts +70 -212
- package/lib/shell-api/api.ts +523 -0
- package/lib/shell-api/arm.ts +83 -0
- package/lib/shell-api/bus.ts +1389 -0
- package/lib/shell-api/capture.ts +1340 -0
- package/lib/shell-api/card-style-line.ts +112 -0
- package/lib/shell-api/card-style-rows.ts +390 -0
- package/lib/shell-api/card-style-transform.ts +862 -0
- package/lib/shell-api/card-style-wiring.ts +477 -0
- package/lib/shell-api/card-styles.ts +153 -0
- package/lib/shell-api/config.ts +71 -0
- package/lib/shell-api/extension.ts +247 -0
- package/lib/shell-api/hook.ts +322 -0
- package/lib/shell-api/index.ts +88 -0
- package/lib/shell-api/message-design-adoption.ts +549 -0
- package/lib/shell-api/message-design-rows.ts +313 -0
- package/lib/shell-api/message-design-wiring.ts +369 -0
- package/lib/shell-api/message-designs.ts +746 -0
- package/lib/shell-api/notices.ts +137 -0
- package/lib/shell-api/plugin-lines.ts +877 -0
- package/lib/shell-api/presence.ts +258 -0
- package/lib/shell-api/repaint.ts +351 -0
- package/lib/shell-api/row-labels.ts +146 -0
- package/lib/shell-api/row-names.ts +273 -0
- package/lib/shell-api/row-origin.ts +144 -0
- package/lib/shell-api/rows.ts +591 -0
- package/lib/shell-api/section-panel.ts +378 -0
- package/lib/shell-api/section-pointer.ts +164 -0
- package/lib/shell-api/sections-preview.ts +275 -0
- package/lib/shell-api/sections-rows.ts +133 -0
- package/lib/shell-api/sidebar-render.ts +705 -0
- package/lib/shell-api/sidebar.ts +1126 -0
- package/lib/shell-api/store.ts +279 -0
- package/lib/shell-api/tool-design-adoption.ts +263 -0
- package/lib/shell-api/tool-design-rows.ts +307 -0
- package/lib/shell-api/tool-design-wiring.ts +481 -0
- package/lib/shell-api/tool-designs.ts +1411 -0
- package/lib/shell-api/transform-pipeline.ts +351 -0
- package/lib/shell-api/types.ts +803 -0
- package/lib/shell-api/visibility.ts +154 -0
- package/package.json +3 -2
- package/tools/files-bridge.test.js +81 -66
- package/tools/fixtures/load-extension.js +40 -18
- package/tools/issues-command.test.js +4 -7
- package/tools/issues-section.test.js +71 -81
- package/tools/odd-rail-wiring.test.js +16 -10
- package/tools/package-surface.test.js +42 -13
- package/tools/prs-command.test.js +11 -6
- package/tools/session-auto-name-wiring.test.js +39 -0
- package/tools/shell-api/api.test.ts +484 -0
- package/tools/shell-api/apply-on-move.test.ts +529 -0
- package/tools/shell-api/arm.test.ts +220 -0
- package/tools/shell-api/bridge-ready.test.ts +309 -0
- package/tools/shell-api/bus.test.ts +194 -0
- package/tools/shell-api/button-rows.test.ts +435 -0
- package/tools/shell-api/capture.test.ts +583 -0
- package/tools/shell-api/card-style-rows.test.ts +493 -0
- package/tools/shell-api/card-style-transform.test.ts +379 -0
- package/tools/shell-api/card-style-wiring.test.ts +258 -0
- package/tools/shell-api/card-styles-e2e.test.ts +502 -0
- package/tools/shell-api/card-styles.test.ts +324 -0
- package/tools/shell-api/card-transcript-path.test.ts +178 -0
- package/tools/shell-api/compatibility-regression.test.mjs +64 -0
- package/tools/shell-api/config.test.ts +93 -0
- package/tools/shell-api/docs-coverage.test.ts +82 -0
- package/tools/shell-api/e2e.test.ts +562 -0
- package/tools/shell-api/example-bash-identity.test.ts +372 -0
- package/tools/shell-api/example-bash-matrix.test.ts +856 -0
- package/tools/shell-api/example-designs.test.ts +737 -0
- package/tools/shell-api/example-neon-transform.test.ts +283 -0
- package/tools/shell-api/example-plain-style.test.ts +1225 -0
- package/tools/shell-api/extension.test.ts +157 -0
- package/tools/shell-api/fake-events.ts +58 -0
- package/tools/shell-api/fake-host.ts +211 -0
- package/tools/shell-api/fake-sidebar.ts +516 -0
- package/tools/shell-api/fake-transcript.ts +486 -0
- package/tools/shell-api/frame-telemetry.test.ts +317 -0
- package/tools/shell-api/hook.test.ts +196 -0
- package/tools/shell-api/manifest.test.ts +47 -0
- package/tools/shell-api/message-design-adoption.test.ts +611 -0
- package/tools/shell-api/message-design-follows.test.ts +361 -0
- package/tools/shell-api/message-design-pi-release.test.mjs +157 -0
- package/tools/shell-api/message-design-regressions.test.mjs +162 -0
- package/tools/shell-api/message-design-rows.test.ts +266 -0
- package/tools/shell-api/message-design-wiring.test.ts +362 -0
- package/tools/shell-api/message-designs.test.ts +339 -0
- package/tools/shell-api/new-category.test.ts +1101 -0
- package/tools/shell-api/notices.test.ts +292 -0
- package/tools/shell-api/plugin-integration-lines.test.ts +827 -0
- package/tools/shell-api/presence.test.ts +396 -0
- package/tools/shell-api/rail-part-hits.test.ts +281 -0
- package/tools/shell-api/rail-surfaces.test.ts +402 -0
- package/tools/shell-api/rail-width.test.ts +406 -0
- package/tools/shell-api/regression.test.ts +434 -0
- package/tools/shell-api/repaint-api.test.ts +200 -0
- package/tools/shell-api/reserved-categories.test.ts +250 -0
- package/tools/shell-api/row-labels.test.ts +261 -0
- package/tools/shell-api/row-names.test.ts +407 -0
- package/tools/shell-api/row-origin.test.ts +395 -0
- package/tools/shell-api/row-placement-regression.test.ts +797 -0
- package/tools/shell-api/row-placement.test.ts +410 -0
- package/tools/shell-api/section-interaction.test.ts +364 -0
- package/tools/shell-api/section-panel.test.ts +430 -0
- package/tools/shell-api/section-placement-rail.test.ts +390 -0
- package/tools/shell-api/section-placement.test.ts +386 -0
- package/tools/shell-api/sections-preview.test.ts +312 -0
- package/tools/shell-api/sections-rows.test.ts +293 -0
- package/tools/shell-api/sidebar-backend.test.ts +477 -0
- package/tools/shell-api/sidebar-e2e.test.ts +317 -0
- package/tools/shell-api/sidebar-hover.test.ts +276 -0
- package/tools/shell-api/sidebar-independent.test.ts +291 -0
- package/tools/shell-api/sidebar-render.test.ts +281 -0
- package/tools/shell-api/sidebar-sections.test.ts +247 -0
- package/tools/shell-api/store.test.ts +192 -0
- package/tools/shell-api/surface-repaint-cost.test.ts +520 -0
- package/tools/shell-api/tool-design-card-style.test.ts +308 -0
- package/tools/shell-api/tool-design-chain.test.ts +471 -0
- package/tools/shell-api/tool-design-cost.test.ts +591 -0
- package/tools/shell-api/tool-design-rows.test.ts +627 -0
- package/tools/shell-api/tool-design-scopes-audit.test.ts +212 -0
- package/tools/shell-api/tool-designs.test.ts +2412 -0
- package/tools/shell-api/transform-pipeline.test.ts +376 -0
- package/tools/shell-api/transforms-bus.test.ts +233 -0
- package/tools/shell-api/verifier-width-regressions.test.ts +147 -0
- package/tools/shell-api-rpc.test.js +189 -0
- package/tools/user-prompt-card.test.js +8 -9
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame telemetry (F1–F4): every frame records, per transform, whether it ran, how many lines it
|
|
3
|
+
* received, how many candidate cards it examined, how many it recognised and how many it rewrote —
|
|
4
|
+
* as COUNTS, and never any of the frame's own content.
|
|
5
|
+
*
|
|
6
|
+
* This is the instrument the bash-card defect (a real TUI where switching the example's toggle
|
|
7
|
+
* changed nothing visible) needs before any fix is invented: it answers "did the pipeline reach the
|
|
8
|
+
* conversation, and did the example's grammar recognise a real bash card there?" from the same
|
|
9
|
+
* report the author already reads.
|
|
10
|
+
*
|
|
11
|
+
* What these tests hold the record to:
|
|
12
|
+
*
|
|
13
|
+
* - counts for a frame with zero candidates, with candidates and no match, and with matches;
|
|
14
|
+
* - the counters are the frame's own: they reset per frame and never accumulate;
|
|
15
|
+
* - a transform that throws reports `failed` with the counts it reached;
|
|
16
|
+
* - a transform that reports nonsense, or nothing at all, loses only its counts — never the frame;
|
|
17
|
+
* - a session with no transform records nothing at all;
|
|
18
|
+
* - no line of the frame is stored, not even smuggled in as a "shape name".
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import assert from "node:assert/strict";
|
|
22
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
23
|
+
import { tmpdir } from "node:os";
|
|
24
|
+
import { join } from "node:path";
|
|
25
|
+
import test from "node:test";
|
|
26
|
+
|
|
27
|
+
import { registerTransform, resetTransformsForTests } from "../../lib/shell-api/bus.ts";
|
|
28
|
+
import { resetCardStyleTransformForTests } from "../../lib/shell-api/card-style-transform.ts";
|
|
29
|
+
import { disableCardStyleTransform, resetCardStyleWiringForTests } from "../../lib/shell-api/card-style-wiring.ts";
|
|
30
|
+
import { setCardStyleSelection } from "../../lib/shell-api/card-styles.ts";
|
|
31
|
+
import { disableCaptureBackend, resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
|
|
32
|
+
import { resetHookStateForTests } from "../../lib/shell-api/hook.ts";
|
|
33
|
+
import { resetNoticesForTests } from "../../lib/shell-api/notices.ts";
|
|
34
|
+
import { resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
|
|
35
|
+
import { disableSidebarBackend, resetSidebarStateForTests } from "../../lib/shell-api/sidebar.ts";
|
|
36
|
+
import { resetSectionFailuresForTests } from "../../lib/shell-api/sidebar-render.ts";
|
|
37
|
+
import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
|
|
38
|
+
import {
|
|
39
|
+
applyTransforms,
|
|
40
|
+
getTransformFrameOutcomes,
|
|
41
|
+
resetTransformPipelineForTests,
|
|
42
|
+
} from "../../lib/shell-api/transform-pipeline.ts";
|
|
43
|
+
import type { TransformContext } from "../../lib/shell-api/types.ts";
|
|
44
|
+
|
|
45
|
+
let configHome: string;
|
|
46
|
+
let previousConfigHome: string | undefined;
|
|
47
|
+
|
|
48
|
+
test.before(() => {
|
|
49
|
+
configHome = mkdtempSync(join(tmpdir(), "gsb-telemetry-"));
|
|
50
|
+
previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
|
|
51
|
+
process.env.GENTLE_PI_CONFIG_HOME = configHome;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test.after(() => {
|
|
55
|
+
if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
56
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
|
|
57
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test.beforeEach(() => {
|
|
61
|
+
rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
|
|
62
|
+
resetTransformsForTests();
|
|
63
|
+
resetTransformPipelineForTests();
|
|
64
|
+
resetCardStyleTransformForTests();
|
|
65
|
+
resetCardStyleWiringForTests();
|
|
66
|
+
resetCaptureStateForTests();
|
|
67
|
+
resetHookStateForTests();
|
|
68
|
+
resetRowBuildStateForTests();
|
|
69
|
+
resetSidebarStateForTests();
|
|
70
|
+
resetSectionFailuresForTests();
|
|
71
|
+
resetNoticesForTests();
|
|
72
|
+
resetStoreStateForTests();
|
|
73
|
+
disableCaptureBackend();
|
|
74
|
+
disableSidebarBackend();
|
|
75
|
+
disableCardStyleTransform();
|
|
76
|
+
setCardStyleSelection("native");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The counts a transform records for itself. `report` is how a transform tells the bridge what its
|
|
81
|
+
* own grammar saw; the bridge adds the line count and the outcome, so the two can never disagree
|
|
82
|
+
* about what the frame did.
|
|
83
|
+
*/
|
|
84
|
+
const counts = (
|
|
85
|
+
candidates: number,
|
|
86
|
+
recognised: number,
|
|
87
|
+
rewritten: number,
|
|
88
|
+
shapes?: Record<string, number>,
|
|
89
|
+
): { candidates: number; recognised: number; rewritten: number; shapes?: Record<string, number> } => ({
|
|
90
|
+
candidates,
|
|
91
|
+
recognised,
|
|
92
|
+
rewritten,
|
|
93
|
+
...(shapes === undefined ? {} : { shapes }),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// ---------------------------------------------------------------------------------------------
|
|
97
|
+
// F1 — the counts a frame records
|
|
98
|
+
// ---------------------------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
test("a frame with zero candidates records the lines it received and zeroed counts", () => {
|
|
101
|
+
registerTransform({
|
|
102
|
+
id: "probe",
|
|
103
|
+
transform: (lines, ctx: TransformContext) => {
|
|
104
|
+
ctx.report?.(counts(0, 0, 0));
|
|
105
|
+
return lines;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
applyTransforms(["one", "two", "three"], 40);
|
|
110
|
+
|
|
111
|
+
assert.deepEqual(getTransformFrameOutcomes(), [
|
|
112
|
+
{
|
|
113
|
+
id: "probe",
|
|
114
|
+
status: "skipped",
|
|
115
|
+
counts: { lines: 3, candidates: 0, recognised: 0, rewritten: 0, shapes: [] },
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("a frame with candidates and no match records the candidates and no recognition", () => {
|
|
121
|
+
registerTransform({
|
|
122
|
+
id: "probe",
|
|
123
|
+
transform: (lines, ctx: TransformContext) => {
|
|
124
|
+
ctx.report?.(counts(2, 0, 0, {}));
|
|
125
|
+
return lines;
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
applyTransforms(["a", "b"], 40);
|
|
130
|
+
|
|
131
|
+
assert.deepEqual(getTransformFrameOutcomes(), [
|
|
132
|
+
{
|
|
133
|
+
id: "probe",
|
|
134
|
+
status: "skipped",
|
|
135
|
+
counts: { lines: 2, candidates: 2, recognised: 0, rewritten: 0, shapes: [] },
|
|
136
|
+
},
|
|
137
|
+
]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("a frame with matches records recognition, rewrites and the shape that matched", () => {
|
|
141
|
+
registerTransform({
|
|
142
|
+
id: "probe",
|
|
143
|
+
transform: (lines, ctx: TransformContext) => {
|
|
144
|
+
ctx.report?.(counts(3, 1, 1, { float: 1 }));
|
|
145
|
+
return lines.map((line) => `>${line}`);
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
assert.deepEqual(applyTransforms(["a"], 40), [">a"]);
|
|
150
|
+
assert.deepEqual(getTransformFrameOutcomes(), [
|
|
151
|
+
{
|
|
152
|
+
id: "probe",
|
|
153
|
+
status: "applied",
|
|
154
|
+
counts: {
|
|
155
|
+
lines: 1,
|
|
156
|
+
candidates: 3,
|
|
157
|
+
recognised: 1,
|
|
158
|
+
rewritten: 1,
|
|
159
|
+
shapes: [{ name: "float", count: 1 }],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
]);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("the counts belong to the frame that produced them: they reset, never accumulate", () => {
|
|
166
|
+
let frame = 0;
|
|
167
|
+
registerTransform({
|
|
168
|
+
id: "probe",
|
|
169
|
+
transform: (lines, ctx: TransformContext) => {
|
|
170
|
+
frame += 1;
|
|
171
|
+
ctx.report?.(frame === 1 ? counts(2, 1, 1, { float: 1 }) : counts(1, 0, 0, {}));
|
|
172
|
+
return lines;
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
applyTransforms(["a", "b", "c"], 40);
|
|
177
|
+
const first = getTransformFrameOutcomes()[0]?.counts;
|
|
178
|
+
applyTransforms(["x"], 40);
|
|
179
|
+
const second = getTransformFrameOutcomes()[0]?.counts;
|
|
180
|
+
|
|
181
|
+
assert.deepEqual(first, {
|
|
182
|
+
lines: 3,
|
|
183
|
+
candidates: 2,
|
|
184
|
+
recognised: 1,
|
|
185
|
+
rewritten: 1,
|
|
186
|
+
shapes: [{ name: "float", count: 1 }],
|
|
187
|
+
});
|
|
188
|
+
assert.deepEqual(
|
|
189
|
+
second,
|
|
190
|
+
{ lines: 1, candidates: 1, recognised: 0, rewritten: 0, shapes: [] },
|
|
191
|
+
"the second frame's record replaces the first one instead of adding to it",
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("a transform that never reports still records the lines and zeroed counts", () => {
|
|
196
|
+
registerTransform({ id: "silent", transform: (lines) => lines });
|
|
197
|
+
|
|
198
|
+
applyTransforms(["a", "b"], 40);
|
|
199
|
+
|
|
200
|
+
assert.deepEqual(getTransformFrameOutcomes(), [
|
|
201
|
+
{
|
|
202
|
+
id: "silent",
|
|
203
|
+
status: "skipped",
|
|
204
|
+
counts: { lines: 2, candidates: 0, recognised: 0, rewritten: 0, shapes: [] },
|
|
205
|
+
},
|
|
206
|
+
]);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// ---------------------------------------------------------------------------------------------
|
|
210
|
+
// F1/F4 — a failed transform keeps the counts it reached
|
|
211
|
+
// ---------------------------------------------------------------------------------------------
|
|
212
|
+
|
|
213
|
+
test("a transform that throws is failed with the counts it reached and the lines it received", () => {
|
|
214
|
+
registerTransform({
|
|
215
|
+
id: "boom",
|
|
216
|
+
transform: (lines, ctx: TransformContext) => {
|
|
217
|
+
ctx.report?.(counts(4, 2, 0, { float: 2 }));
|
|
218
|
+
throw new Error("boom after two cards");
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
assert.deepEqual(applyTransforms(["a", "b", "c", "d", "e"], 40), ["a", "b", "c", "d", "e"]);
|
|
223
|
+
assert.deepEqual(getTransformFrameOutcomes(), [
|
|
224
|
+
{
|
|
225
|
+
id: "boom",
|
|
226
|
+
status: "failed",
|
|
227
|
+
message: "boom after two cards",
|
|
228
|
+
counts: {
|
|
229
|
+
lines: 5,
|
|
230
|
+
candidates: 4,
|
|
231
|
+
recognised: 2,
|
|
232
|
+
rewritten: 0,
|
|
233
|
+
shapes: [{ name: "float", count: 2 }],
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
// ---------------------------------------------------------------------------------------------
|
|
240
|
+
// F1/F4 — junk in, nothing out: the record is counts only, and recording never throws
|
|
241
|
+
// ---------------------------------------------------------------------------------------------
|
|
242
|
+
|
|
243
|
+
test("nonsense counts are clamped to zero and never thrown into the frame", () => {
|
|
244
|
+
registerTransform({
|
|
245
|
+
id: "liar",
|
|
246
|
+
transform: (lines, ctx: TransformContext) => {
|
|
247
|
+
assert.doesNotThrow(() => {
|
|
248
|
+
ctx.report?.({
|
|
249
|
+
candidates: -3,
|
|
250
|
+
recognised: Number.NaN,
|
|
251
|
+
rewritten: Number.POSITIVE_INFINITY,
|
|
252
|
+
} as unknown as Parameters<NonNullable<TransformContext["report"]>>[0]);
|
|
253
|
+
ctx.report?.("not counts" as unknown as Parameters<NonNullable<TransformContext["report"]>>[0]);
|
|
254
|
+
});
|
|
255
|
+
return lines.map((line) => `${line}!`);
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
assert.deepEqual(applyTransforms(["a"], 40), ["a!"]);
|
|
260
|
+
assert.deepEqual(getTransformFrameOutcomes(), [
|
|
261
|
+
{
|
|
262
|
+
id: "liar",
|
|
263
|
+
status: "applied",
|
|
264
|
+
counts: { lines: 1, candidates: 0, recognised: 0, rewritten: 0, shapes: [] },
|
|
265
|
+
},
|
|
266
|
+
]);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("a shape name is a name: anything with a space, an escape or a long tail is dropped", () => {
|
|
270
|
+
registerTransform({
|
|
271
|
+
id: "probe",
|
|
272
|
+
transform: (lines, ctx: TransformContext) => {
|
|
273
|
+
ctx.report?.(
|
|
274
|
+
counts(4, 2, 0, {
|
|
275
|
+
"ls -1 /home": 1,
|
|
276
|
+
"\u001b[31mred\u001b[39m": 1,
|
|
277
|
+
THIS_IS_A_NAME_THAT_IS_WAY_TOO_LONG_TO_BE_ONE: 1,
|
|
278
|
+
"Bash Card": 1,
|
|
279
|
+
float: 2,
|
|
280
|
+
}),
|
|
281
|
+
);
|
|
282
|
+
return lines;
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
applyTransforms(["a"], 40);
|
|
287
|
+
|
|
288
|
+
assert.deepEqual(getTransformFrameOutcomes()[0]?.counts.shapes, [{ name: "float", count: 2 }]);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test("no line of the frame is recorded, displayed or smuggled in as a shape name", () => {
|
|
292
|
+
const secret = "SECRET-OUTPUT-THAT-MUST-NOT-BE-STORED";
|
|
293
|
+
registerTransform({
|
|
294
|
+
id: "probe",
|
|
295
|
+
transform: (lines, ctx: TransformContext) => {
|
|
296
|
+
ctx.report?.(
|
|
297
|
+
counts(1, 1, 1, { [secret]: 1, [secret.toLowerCase()]: 1, float: 1 }),
|
|
298
|
+
);
|
|
299
|
+
return lines;
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
applyTransforms([secret, `a line with ${secret} in it`], 40);
|
|
304
|
+
|
|
305
|
+
const stored = JSON.stringify(getTransformFrameOutcomes());
|
|
306
|
+
assert.equal(stored.includes(secret), false, "the frame's content never leaves the frame");
|
|
307
|
+
assert.equal(
|
|
308
|
+
stored.includes(secret.toLowerCase()),
|
|
309
|
+
false,
|
|
310
|
+
"and a shape name cannot carry it either",
|
|
311
|
+
);
|
|
312
|
+
assert.equal(
|
|
313
|
+
stored.includes("\u001b"),
|
|
314
|
+
false,
|
|
315
|
+
"and no paint from the frame is kept: counts and ids only",
|
|
316
|
+
);
|
|
317
|
+
});
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { registerRows, resetBusForTests } from "../../lib/shell-api/bus.ts";
|
|
5
|
+
import {
|
|
6
|
+
getHookDiagnostics,
|
|
7
|
+
installHookBackend,
|
|
8
|
+
resetHookStateForTests,
|
|
9
|
+
} from "../../lib/shell-api/hook.ts";
|
|
10
|
+
import type { CustomizeRow, RowProvider } from "../../lib/shell-api/types.ts";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The host registry key (S4). No host has been observed emitting it, so the tests define the
|
|
14
|
+
* accepted shapes; the module documents that the branch is unverified.
|
|
15
|
+
*/
|
|
16
|
+
const HOOK_KEY = Symbol.for("gentle-pi.customize-row-providers");
|
|
17
|
+
|
|
18
|
+
/** The only writes these tests make to globalThis, cleaned up in afterEach. */
|
|
19
|
+
const hookSlot = (): Record<symbol, unknown> => globalThis as unknown as Record<symbol, unknown>;
|
|
20
|
+
const setHook = (value: unknown): void => {
|
|
21
|
+
hookSlot()[HOOK_KEY] = value;
|
|
22
|
+
};
|
|
23
|
+
const clearHook = (): void => {
|
|
24
|
+
delete hookSlot()[HOOK_KEY];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
test.beforeEach(() => {
|
|
28
|
+
resetBusForTests();
|
|
29
|
+
resetHookStateForTests();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test.afterEach(() => {
|
|
33
|
+
clearHook();
|
|
34
|
+
resetHookStateForTests();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const labelsProvider = (id: string, category: string, labels: string[]): RowProvider => ({
|
|
38
|
+
id,
|
|
39
|
+
category,
|
|
40
|
+
rows: () => labels.map((label) => ({ label, action: () => {} })),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
interface PushedProvider {
|
|
44
|
+
id: string;
|
|
45
|
+
rows: (ctx?: unknown) => CustomizeRow[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
test("no registry at all is reported as no-hook", () => {
|
|
49
|
+
const result = installHookBackend();
|
|
50
|
+
|
|
51
|
+
assert.equal(result.installed, false);
|
|
52
|
+
assert.equal(result.outcome, "no-hook");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("an array registry receives exactly one fan-out provider", () => {
|
|
56
|
+
const registry: PushedProvider[] = [];
|
|
57
|
+
setHook(registry);
|
|
58
|
+
registerRows(labelsProvider("p1", "Cards", ["Row one"]));
|
|
59
|
+
|
|
60
|
+
const first = installHookBackend();
|
|
61
|
+
const second = installHookBackend();
|
|
62
|
+
|
|
63
|
+
assert.equal(first.installed, true);
|
|
64
|
+
assert.equal(first.outcome, "hooked");
|
|
65
|
+
assert.equal(first.shape, "array");
|
|
66
|
+
assert.equal(second.installed, true, "a second arm is a no-op, not a second provider");
|
|
67
|
+
assert.equal(registry.length, 1, "exactly one fan-out provider is pushed");
|
|
68
|
+
assert.equal(typeof registry[0].rows, "function");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("the pushed provider builds rows from the shared snapshot, in subscription order", () => {
|
|
72
|
+
const registry: PushedProvider[] = [];
|
|
73
|
+
setHook(registry);
|
|
74
|
+
registerRows(labelsProvider("first", "Cards", ["First a"]));
|
|
75
|
+
registerRows(labelsProvider("second", "Banner", ["Second b"]));
|
|
76
|
+
installHookBackend();
|
|
77
|
+
|
|
78
|
+
const rows = registry[0].rows({ theme: "host-theme", configHome: "/host/home" });
|
|
79
|
+
|
|
80
|
+
assert.deepEqual(
|
|
81
|
+
rows.map((row) => [row.category, row.label]),
|
|
82
|
+
[
|
|
83
|
+
["Cards", "First a"],
|
|
84
|
+
["Banner", "Second b"],
|
|
85
|
+
],
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("the pushed provider isolates a throwing provider and records the failure", () => {
|
|
90
|
+
const registry: PushedProvider[] = [];
|
|
91
|
+
setHook(registry);
|
|
92
|
+
registerRows(labelsProvider("before", "Cards", ["Before ok"]));
|
|
93
|
+
registerRows({
|
|
94
|
+
id: "boom",
|
|
95
|
+
category: "Banner",
|
|
96
|
+
rows: () => {
|
|
97
|
+
throw new Error("hook provider exploded");
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
registerRows(labelsProvider("after", "Layout", ["After ok"]));
|
|
101
|
+
installHookBackend();
|
|
102
|
+
|
|
103
|
+
const rows = registry[0].rows({});
|
|
104
|
+
|
|
105
|
+
assert.deepEqual(
|
|
106
|
+
rows.map((row) => row.label),
|
|
107
|
+
["Before ok", "After ok"],
|
|
108
|
+
);
|
|
109
|
+
assert.deepEqual(getHookDiagnostics().lastFailures, [
|
|
110
|
+
{ providerId: "boom", message: "hook provider exploded", rowsDropped: true },
|
|
111
|
+
]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("a host context is reused when it carries a theme and a config home", () => {
|
|
115
|
+
const registry: PushedProvider[] = [];
|
|
116
|
+
setHook(registry);
|
|
117
|
+
let received: unknown;
|
|
118
|
+
registerRows({
|
|
119
|
+
id: "ctx",
|
|
120
|
+
category: "Cards",
|
|
121
|
+
rows: (ctx) => {
|
|
122
|
+
received = ctx;
|
|
123
|
+
return [];
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
installHookBackend();
|
|
127
|
+
|
|
128
|
+
registry[0].rows({ theme: { name: "host-theme" }, configHome: "/host/home" });
|
|
129
|
+
|
|
130
|
+
assert.deepEqual(received, { theme: { name: "host-theme" }, configHome: "/host/home" });
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("an object with a callable register is a usable registry", () => {
|
|
134
|
+
const pushed: PushedProvider[] = [];
|
|
135
|
+
setHook({
|
|
136
|
+
register(provider: PushedProvider) {
|
|
137
|
+
pushed.push(provider);
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
registerRows(labelsProvider("p1", "Cards", ["Via register"]));
|
|
141
|
+
|
|
142
|
+
const result = installHookBackend();
|
|
143
|
+
|
|
144
|
+
assert.equal(result.outcome, "hooked");
|
|
145
|
+
assert.equal(result.shape, "register");
|
|
146
|
+
assert.equal(pushed.length, 1);
|
|
147
|
+
assert.deepEqual(
|
|
148
|
+
pushed[0].rows({}).map((row) => row.label),
|
|
149
|
+
["Via register"],
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("unusable registry shapes are reported and never mistaken for a hook", () => {
|
|
154
|
+
const unusable: unknown[] = [
|
|
155
|
+
42,
|
|
156
|
+
"providers",
|
|
157
|
+
true,
|
|
158
|
+
{},
|
|
159
|
+
{ register: 5 },
|
|
160
|
+
{ register: null },
|
|
161
|
+
() => {},
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
for (const value of unusable) {
|
|
165
|
+
resetHookStateForTests();
|
|
166
|
+
setHook(value);
|
|
167
|
+
|
|
168
|
+
const result = installHookBackend();
|
|
169
|
+
|
|
170
|
+
assert.equal(result.installed, false, `value ${String(value)} must not install a hook`);
|
|
171
|
+
assert.equal(result.outcome, "unusable-hook", `value ${String(value)} is unusable`);
|
|
172
|
+
assert.equal(
|
|
173
|
+
getHookDiagnostics().shape,
|
|
174
|
+
"unusable",
|
|
175
|
+
"the unusable shape is recorded for diagnostics",
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("the registry is marked so a second package copy does not push a second provider", () => {
|
|
181
|
+
const registry: PushedProvider[] = [];
|
|
182
|
+
setHook(registry);
|
|
183
|
+
installHookBackend();
|
|
184
|
+
|
|
185
|
+
const armed = Symbol.for("gentle-shell-bridge.hook.armed.v1");
|
|
186
|
+
assert.equal(Object.hasOwn(registry, armed), true, "the registry carries the armed marker");
|
|
187
|
+
assert.equal(
|
|
188
|
+
Object.prototype.propertyIsEnumerable.call(registry, armed),
|
|
189
|
+
false,
|
|
190
|
+
"the marker is non-enumerable, so the host never iterates it",
|
|
191
|
+
);
|
|
192
|
+
// A second copy of this module has its own module scope but the same globalThis slot and the
|
|
193
|
+
// same registry, which carries the marker.
|
|
194
|
+
assert.equal(installHookBackend().installed, true);
|
|
195
|
+
assert.equal(registry.length, 1, "still exactly one fan-out provider");
|
|
196
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { dirname, isAbsolute, relative, 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: there is no nested package manifest any more (T5), so
|
|
8
|
+
// what is left to hold here is the ONE manifest Pi reads — this package's root `package.json`.
|
|
9
|
+
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
|
10
|
+
const manifest = JSON.parse(readFileSync(resolve(packageRoot, "package.json"), "utf8"));
|
|
11
|
+
|
|
12
|
+
test("keywords contains pi-package", () => {
|
|
13
|
+
assert.ok(Array.isArray(manifest.keywords), "keywords must be an array");
|
|
14
|
+
assert.ok(
|
|
15
|
+
manifest.keywords.includes("pi-package"),
|
|
16
|
+
`keywords must contain "pi-package", got ${JSON.stringify(manifest.keywords)}`,
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("pi.extensions is a non-empty array of package-root-relative paths", () => {
|
|
21
|
+
const extensions = manifest.pi?.extensions;
|
|
22
|
+
assert.ok(Array.isArray(extensions), "pi.extensions must be an array");
|
|
23
|
+
assert.ok(extensions.length > 0, "pi.extensions must not be empty");
|
|
24
|
+
for (const entry of extensions) {
|
|
25
|
+
assert.equal(typeof entry, "string", `pi.extensions entry must be a string: ${entry}`);
|
|
26
|
+
assert.ok(entry.length > 0, "pi.extensions entry must not be empty");
|
|
27
|
+
assert.ok(!isAbsolute(entry), `pi.extensions entry must be package-root relative: ${entry}`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("every declared extension path resolves to an existing file inside the package", () => {
|
|
32
|
+
for (const entry of manifest.pi.extensions) {
|
|
33
|
+
const resolved = resolve(packageRoot, entry);
|
|
34
|
+
const relativeToRoot = relative(packageRoot, resolved);
|
|
35
|
+
assert.ok(
|
|
36
|
+
relativeToRoot.length > 0 &&
|
|
37
|
+
!relativeToRoot.startsWith("..") &&
|
|
38
|
+
!isAbsolute(relativeToRoot),
|
|
39
|
+
`extension path escapes the package root: ${entry}`,
|
|
40
|
+
);
|
|
41
|
+
assert.ok(existsSync(resolved), `extension path does not exist: ${entry} -> ${resolved}`);
|
|
42
|
+
assert.ok(
|
|
43
|
+
statSync(resolved).isFile(),
|
|
44
|
+
`extension path is not a file: ${entry} -> ${resolved}`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
});
|