pi-archimedes 2.10.3 → 2.11.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.
- package/README.md +22 -6
- package/package.json +17 -17
- package/src/factory-lifecycle.test.ts +147 -9
- package/src/index.ts +57 -11
- package/src/onboarding/index.test.ts +2 -0
- package/src/onboarding/index.ts +3 -1
- package/src/overlay-width-audit.test.ts +262 -0
- package/src/pi-support-notice.test.ts +246 -0
- package/src/plugin-manager.ts +3 -3
- package/src/plugins.test.ts +6 -2
- package/src/readme-agreement.test.ts +227 -0
- package/src/settings-manager.test.ts +1085 -0
- package/src/settings-manager.ts +481 -269
- package/src/settings-panel-height.test.ts +525 -0
- package/src/settings.test.ts +219 -0
- package/src/settings.ts +26 -2
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame-width audit for the `/archimedes` settings overlay, the `/plugins`
|
|
3
|
+
* overlay (same manager, different items) and the onboarding overlay.
|
|
4
|
+
*
|
|
5
|
+
* Automated stand-in for a `PI_TUI_WRITE_LOG` capture: render each surface
|
|
6
|
+
* through its real entry point at several frame widths, measure **every produced
|
|
7
|
+
* line** with pi-tui's own `visibleWidth` (what the terminal draws), and require
|
|
8
|
+
* it to land on the frame. These are the surfaces `OVERLAY_CHROME` feeds, and
|
|
9
|
+
* the cursor marker they emit is the shape the old `.length`-based width maths
|
|
10
|
+
* measured far too wide — see Task 4 of the pi 1.x alignment plan.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, it, expect, vi } from "vitest";
|
|
14
|
+
import {
|
|
15
|
+
CURSOR_MARKER,
|
|
16
|
+
stripTerminalSequences,
|
|
17
|
+
visibleWidth as tuiVisibleWidth,
|
|
18
|
+
} from "@earendil-works/pi-tui";
|
|
19
|
+
import type { SettingItem } from "@earendil-works/pi-tui";
|
|
20
|
+
import { createSettingsManager, type PromptDescriptor } from "./settings-manager.js";
|
|
21
|
+
import { createOnboardingOverlay } from "./onboarding/overlay.js";
|
|
22
|
+
import type { OverlayTheme } from "@pi-archimedes/core/overlay";
|
|
23
|
+
|
|
24
|
+
// The onboarding overlay's live spinner previews come from @pi-archimedes/ui;
|
|
25
|
+
// the audit only needs a deterministic 4-cell string per (style, tick).
|
|
26
|
+
vi.mock("@pi-archimedes/ui/editor", () => ({
|
|
27
|
+
spinFrame: vi.fn((style: string, tick: number) => {
|
|
28
|
+
const c = 0x2800 + ((tick % 8) + (style.length % 4));
|
|
29
|
+
return String.fromCharCode(c) + "⣷⣾⣽";
|
|
30
|
+
}),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
// One entry per failure mode of the deleted width maths.
|
|
34
|
+
const URL = `https://example.com/${"segment/".repeat(12)}`;
|
|
35
|
+
|
|
36
|
+
/** A theme that actually colourises, so SGR sequences are in the measured lines. */
|
|
37
|
+
const theme = {
|
|
38
|
+
fg: (token: string, text: string) =>
|
|
39
|
+
token === "accent"
|
|
40
|
+
? `\x1b[38;2;80;120;255m${text}\x1b[0m`
|
|
41
|
+
: token === "error"
|
|
42
|
+
? `\x1b[38;2;255;90;90m${text}\x1b[0m`
|
|
43
|
+
: `\x1b[38;2;120;160;200m${text}\x1b[0m`,
|
|
44
|
+
bold: (text: string) => `\x1b[1m${text}\x1b[0m`,
|
|
45
|
+
muted: (text: string) => `\x1b[38;2;100;100;100m${text}\x1b[0m`,
|
|
46
|
+
strikethrough: (text: string) => `\x1b[9m${text}\x1b[0m`,
|
|
47
|
+
} as unknown as OverlayTheme & Record<string, (...args: never[]) => unknown>;
|
|
48
|
+
|
|
49
|
+
const plainTheme: OverlayTheme = { fg: (token: string, text: string) => String(theme.fg(token, text)) };
|
|
50
|
+
|
|
51
|
+
const ITEMS: SettingItem[] = [
|
|
52
|
+
{
|
|
53
|
+
id: "wide",
|
|
54
|
+
label: "界面表示の幅",
|
|
55
|
+
currentValue: "既定",
|
|
56
|
+
description: "この設定はオーバーレイの幅を検証するための日本語の説明です。".repeat(3),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: "linked",
|
|
60
|
+
label: `docs\x1b]8;;${URL}\x07link\x1b]8;;\x07`,
|
|
61
|
+
currentValue: `see \x1b]8;;${URL}\x07this\x1b]8;;\x07`,
|
|
62
|
+
description: `reference: \x1b]8;;${URL}\x07manual\x1b]8;;\x07`,
|
|
63
|
+
},
|
|
64
|
+
{ id: "coloured", label: "\x1b[33mtinted\x1b[0m label", currentValue: "\x1b[32mon\x1b[0m", values: ["on", "off"] },
|
|
65
|
+
{
|
|
66
|
+
id: "model",
|
|
67
|
+
label: "モデル スコープ モデル",
|
|
68
|
+
currentValue: "anthropic/claude-opus-4.5",
|
|
69
|
+
description: `${"説明文".repeat(60)}`,
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
const PROMPTS: Record<string, PromptDescriptor> = {
|
|
74
|
+
model: { kind: "text", label: "モデル スコープ モデル" },
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
interface Violation {
|
|
78
|
+
surface: string;
|
|
79
|
+
frameWidth: number;
|
|
80
|
+
row: number;
|
|
81
|
+
measured: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Every produced line of a bordered overlay must land on the frame exactly. */
|
|
85
|
+
function audit(surface: string, frameWidth: number, lines: string[]): Violation[] {
|
|
86
|
+
const bad: Violation[] = [];
|
|
87
|
+
lines.forEach((line, row) => {
|
|
88
|
+
const measured = tuiVisibleWidth(line);
|
|
89
|
+
if (measured !== frameWidth) bad.push({ surface, frameWidth, row, measured });
|
|
90
|
+
});
|
|
91
|
+
return bad;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ── Capture content checks ───────────────────────────────────────────────────
|
|
95
|
+
//
|
|
96
|
+
// A width audit only proves something if the captured frame is the frame it means
|
|
97
|
+
// to measure. List search accepts printable ASCII only (`isAsciiPrintable` in
|
|
98
|
+
// settings-manager.ts: `data.length === 1 && data >= " " && data <= "~"`), while
|
|
99
|
+
// the free-text prompt field is pi-tui's `Input`, which takes any non-control
|
|
100
|
+
// input including wide characters — so a wide-character prompt is real content
|
|
101
|
+
// and a wide-character search query is not reachable at all. Each capture
|
|
102
|
+
// therefore declares the content it expects and is checked before the frame is
|
|
103
|
+
// measured.
|
|
104
|
+
|
|
105
|
+
/** Drawn text of the search row, border and padding removed, or undefined. */
|
|
106
|
+
function searchRow(raw: string[]): string | undefined {
|
|
107
|
+
return raw
|
|
108
|
+
.map((l) => stripTerminalSequences(l).replace(/[│┌└┐┘─]/g, "").trim())
|
|
109
|
+
.find((l) => l.includes("Search:"));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function drawnIncludes(raw: string[], needle: string): boolean {
|
|
113
|
+
return raw.some((l) => stripTerminalSequences(l).includes(needle));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function makeManager() {
|
|
117
|
+
return createSettingsManager({
|
|
118
|
+
items: ITEMS.map((i) => ({ ...i })),
|
|
119
|
+
prompts: PROMPTS,
|
|
120
|
+
theme: theme as never,
|
|
121
|
+
onChange: () => {},
|
|
122
|
+
onSave: () => {},
|
|
123
|
+
onClose: () => {},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function makeOnboarding() {
|
|
128
|
+
return createOnboardingOverlay({
|
|
129
|
+
theme: plainTheme,
|
|
130
|
+
thinkingDefault: "Full",
|
|
131
|
+
toolDefault: "Minimal",
|
|
132
|
+
plugins: [
|
|
133
|
+
{ id: "ui", label: "界面表示", description: "TUI 拡張機能".repeat(6), selected: true },
|
|
134
|
+
{ id: "linked", label: `plugin\x1b]8;;${URL}\x07link\x1b]8;;\x07`, description: `see \x1b]8;;${URL}\x07docs\x1b]8;;\x07`, selected: false },
|
|
135
|
+
{ id: "diff", label: "\x1b[35mdiff\x1b[0m", description: "Shiki diff rendering", selected: true },
|
|
136
|
+
],
|
|
137
|
+
spinners: ["typing", "pulse", "rain"],
|
|
138
|
+
spinnerDefault: "pulse",
|
|
139
|
+
onDone: () => {},
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
describe("overlay surfaces frame-width audit", () => {
|
|
144
|
+
const FRAME_WIDTHS = [40, 60, 84, 100];
|
|
145
|
+
|
|
146
|
+
it("keeps every produced line on the frame, on every surface and mode", () => {
|
|
147
|
+
const violations: Violation[] = [];
|
|
148
|
+
const over: Violation[] = [];
|
|
149
|
+
|
|
150
|
+
for (const frameWidth of FRAME_WIDTHS) {
|
|
151
|
+
const capture = (
|
|
152
|
+
surface: string,
|
|
153
|
+
lines: string[],
|
|
154
|
+
expectContent?: (raw: string[]) => string | null,
|
|
155
|
+
) => {
|
|
156
|
+
// Check the capture is what the audit thinks it is *before* measuring it.
|
|
157
|
+
const problem = expectContent?.(lines);
|
|
158
|
+
expect(problem ?? null, `${surface}@${frameWidth} is not the capture this audit measures`).toBeNull();
|
|
159
|
+
const bad = audit(surface, frameWidth, lines);
|
|
160
|
+
violations.push(...bad);
|
|
161
|
+
over.push(...bad.filter((v) => v.measured > frameWidth));
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// /archimedes settings — list, search (emits CURSOR_MARKER), prompt mode
|
|
165
|
+
capture("settings:list", makeManager().render(frameWidth), (raw) =>
|
|
166
|
+
drawnIncludes(raw, "界面表示の幅") ? null : "list rows not rendered",
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
// The search row with an empty query — the shape that carries the cursor
|
|
170
|
+
// marker. The wide keystrokes after `/` are dropped by the ASCII gate.
|
|
171
|
+
const searchingEmpty = makeManager();
|
|
172
|
+
searchingEmpty.handleInput("/");
|
|
173
|
+
for (const ch of "界面") searchingEmpty.handleInput(ch);
|
|
174
|
+
capture("settings:search-empty", searchingEmpty.render(frameWidth), (raw) => {
|
|
175
|
+
// Tripwire for that gate: if search ever accepts wide input, this capture
|
|
176
|
+
// has to feed the wide query — otherwise a CJK search row goes unmeasured
|
|
177
|
+
// and the frame-width claim quietly goes stale.
|
|
178
|
+
if (!raw.some((l) => l.includes(CURSOR_MARKER))) return "cursor marker not rendered";
|
|
179
|
+
const row = searchRow(raw);
|
|
180
|
+
if (row?.trim() !== "Search:")
|
|
181
|
+
return `search row is not the empty query: ${JSON.stringify(row?.trim())}`;
|
|
182
|
+
return null;
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// A populated search row: `link` is accepted by the ASCII gate and matches
|
|
186
|
+
// exactly one fixture, so the filter result is checked, not assumed.
|
|
187
|
+
const searching = makeManager();
|
|
188
|
+
searching.handleInput("/");
|
|
189
|
+
for (const ch of "link") searching.handleInput(ch);
|
|
190
|
+
capture("settings:search", searching.render(frameWidth), (raw) => {
|
|
191
|
+
const row = searchRow(raw);
|
|
192
|
+
if (row?.trim() !== "Search: link")
|
|
193
|
+
return `search row does not show the query: ${JSON.stringify(row?.trim())}`;
|
|
194
|
+
if (!raw.some((l) => l.includes(CURSOR_MARKER))) return "cursor marker missing from the search row";
|
|
195
|
+
if (!drawnIncludes(raw, "docs")) return "filtered list lost the OSC 8 fixture row";
|
|
196
|
+
if (drawnIncludes(raw, "tinted")) return "search did not narrow the list";
|
|
197
|
+
return null;
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Prompt mode takes wide input (its field is pi-tui's `Input`), so the
|
|
201
|
+
// value the audit types really does land in the drawn frame. On the
|
|
202
|
+
// narrowest frame the value fills the row, so its tail — and the zero-width
|
|
203
|
+
// cursor behind it — are cut onto the frame instead of overflowing it.
|
|
204
|
+
const prompting = makeManager();
|
|
205
|
+
prompting.handleInput("\x1b[B"); // down to the free-text "model" row
|
|
206
|
+
prompting.handleInput("\x1b[B");
|
|
207
|
+
prompting.handleInput("\x1b[B");
|
|
208
|
+
prompting.handleInput("\r");
|
|
209
|
+
for (const ch of "検証モデル名") prompting.handleInput(ch);
|
|
210
|
+
capture("settings:prompt", prompting.render(frameWidth), (raw) => {
|
|
211
|
+
if (!drawnIncludes(raw, "検証")) return "prompt field does not show the typed wide value";
|
|
212
|
+
return null;
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// An empty filter result exercises the "no matching settings" row too.
|
|
216
|
+
const noMatches = makeManager();
|
|
217
|
+
noMatches.handleInput("/");
|
|
218
|
+
for (const ch of "zzzz") noMatches.handleInput(ch);
|
|
219
|
+
capture("settings:no-matches", noMatches.render(frameWidth), (raw) => {
|
|
220
|
+
if (searchRow(raw)?.trim() !== "Search: zzzz") return "search row does not show the query";
|
|
221
|
+
if (!drawnIncludes(raw, "No matching settings")) return "empty-filter row not rendered";
|
|
222
|
+
return null;
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Onboarding — four steps, each with its own row shapes.
|
|
226
|
+
const intro = makeOnboarding();
|
|
227
|
+
capture("onboarding:thinking", intro.render(frameWidth), (raw) =>
|
|
228
|
+
drawnIncludes(raw, "Thinking style") ? null : "thinking step not rendered",
|
|
229
|
+
);
|
|
230
|
+
intro.handleInput("\r");
|
|
231
|
+
capture("onboarding:tool", intro.render(frameWidth), (raw) =>
|
|
232
|
+
drawnIncludes(raw, "Tool output style") ? null : "tool step not rendered",
|
|
233
|
+
);
|
|
234
|
+
intro.handleInput("\r");
|
|
235
|
+
capture("onboarding:plugins", intro.render(frameWidth), (raw) =>
|
|
236
|
+
drawnIncludes(raw, "Which plugins")
|
|
237
|
+
? drawnIncludes(raw, "pluginlink")
|
|
238
|
+
? null
|
|
239
|
+
: "plugin row carrying the OSC 8 label not rendered"
|
|
240
|
+
: "plugin step not rendered",
|
|
241
|
+
);
|
|
242
|
+
intro.handleInput("\r");
|
|
243
|
+
capture("onboarding:spinner", intro.render(frameWidth), (raw) =>
|
|
244
|
+
drawnIncludes(raw, "Which spinner") ? null : "spinner step not rendered",
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Guard the fixtures: the marker is the shape that used to measure far too
|
|
249
|
+
// wide, so a green audit that never emitted one would prove nothing.
|
|
250
|
+
const probe = makeManager();
|
|
251
|
+
probe.handleInput("/");
|
|
252
|
+
expect(probe.render(84).some((line) => line.includes(CURSOR_MARKER))).toBe(true);
|
|
253
|
+
|
|
254
|
+
const summary = (list: Violation[]) =>
|
|
255
|
+
list.slice(0, 6).map((v) => `${v.surface}@${v.frameWidth}:row${v.row}=${v.measured}`).join(", ");
|
|
256
|
+
expect(
|
|
257
|
+
over,
|
|
258
|
+
`${over.length}/${violations.length} off-frame line(s) [wider than the frame]: ${summary(over)}`,
|
|
259
|
+
).toEqual([]);
|
|
260
|
+
expect(violations, `${violations.length} off-frame line(s) total: ${summary(violations)}`).toEqual([]);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
// ── The aggregated host-version notice (ADR 0026, Task 7) ──────────────────
|
|
4
|
+
//
|
|
5
|
+
// Packages report a below-floor host during their own `register()`; `meta` is
|
|
6
|
+
// the only place the suite shows it, as ONE message. This file pins the three
|
|
7
|
+
// things a user would notice if they broke:
|
|
8
|
+
//
|
|
9
|
+
// * one message, not one per package;
|
|
10
|
+
// * everything still registers on a below-floor host — refusing to load would
|
|
11
|
+
// make /plugins report an enabled package that did nothing;
|
|
12
|
+
// * the notice is not repeated on the next session_start, nor after a
|
|
13
|
+
// `/reload` (which re-evaluates these modules but keeps the process, and
|
|
14
|
+
// therefore the pi version, the same).
|
|
15
|
+
//
|
|
16
|
+
// The guard is driven through the real `core/pi-support` by reporting an
|
|
17
|
+
// impossible floor (`99.0.0`) — the same code path a genuinely old host takes,
|
|
18
|
+
// without monkey-patching the host's exported VERSION.
|
|
19
|
+
|
|
20
|
+
// ── settings-io: in-memory store (mirrors factory-lifecycle.test.ts) ────────
|
|
21
|
+
|
|
22
|
+
vi.mock("@pi-archimedes/core/settings-io", () => {
|
|
23
|
+
const store: Record<string, unknown> = {};
|
|
24
|
+
return {
|
|
25
|
+
loadConfig: vi.fn(
|
|
26
|
+
(ns: string, defaults: object) =>
|
|
27
|
+
({ ...defaults, ...((store[ns] as object) ?? {}) }),
|
|
28
|
+
),
|
|
29
|
+
saveConfig: vi.fn((ns: string, config: object) => {
|
|
30
|
+
store[ns] = config;
|
|
31
|
+
}),
|
|
32
|
+
removeConfig: vi.fn((ns: string) => {
|
|
33
|
+
delete store[ns];
|
|
34
|
+
}),
|
|
35
|
+
isConfigEnabled: vi.fn((ns: string) => {
|
|
36
|
+
const cfg = (store[ns] ?? {}) as Record<string, unknown>;
|
|
37
|
+
return cfg.enabled !== false;
|
|
38
|
+
}),
|
|
39
|
+
setConfigEnabled: vi.fn(),
|
|
40
|
+
__store: store,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const settingsIo = await import("@pi-archimedes/core/settings-io");
|
|
45
|
+
const mockStore = (settingsIo as unknown as { __store: Record<string, unknown> }).__store;
|
|
46
|
+
|
|
47
|
+
// ── Every package the factory touches, so this stays a unit test ────────────
|
|
48
|
+
|
|
49
|
+
vi.mock("@pi-archimedes/core/profiler", () => ({
|
|
50
|
+
time: vi.fn(),
|
|
51
|
+
print: vi.fn(),
|
|
52
|
+
reset: vi.fn(),
|
|
53
|
+
}));
|
|
54
|
+
vi.mock("@pi-archimedes/core/log", async (importOriginal) => {
|
|
55
|
+
const real = await importOriginal<typeof import("@pi-archimedes/core/log")>();
|
|
56
|
+
return { ...real, diag: vi.fn() };
|
|
57
|
+
});
|
|
58
|
+
import { diag } from "@pi-archimedes/core/log";
|
|
59
|
+
// NOTE: `@pi-archimedes/core/pi-support` is deliberately NOT mocked — the
|
|
60
|
+
// registry and the spend-once semantics under test are its own.
|
|
61
|
+
vi.mock("@pi-archimedes/core", () => ({ registerCore: vi.fn() }));
|
|
62
|
+
vi.mock("@pi-archimedes/ui", () => ({ registerUI: vi.fn() }));
|
|
63
|
+
vi.mock("@pi-archimedes/footer", () => ({ registerFooter: vi.fn() }));
|
|
64
|
+
vi.mock("@pi-archimedes/todo", () => ({ registerTodo: vi.fn() }));
|
|
65
|
+
vi.mock("@pi-archimedes/ask", () => ({ registerAsk: vi.fn() }));
|
|
66
|
+
vi.mock("@pi-archimedes/notify", () => ({ registerNotify: vi.fn() }));
|
|
67
|
+
vi.mock("@pi-archimedes/session-name", () => ({ registerSessionName: vi.fn() }));
|
|
68
|
+
vi.mock("@pi-archimedes/sudo", () => ({ registerSudo: vi.fn() }));
|
|
69
|
+
vi.mock("@pi-archimedes/diff", () => ({ registerDiffTools: vi.fn() }));
|
|
70
|
+
vi.mock("@pi-archimedes/image-paste", () => ({
|
|
71
|
+
registerImagePaste: vi.fn(),
|
|
72
|
+
shutdownImagePaste: vi.fn(),
|
|
73
|
+
initImagePasteSession: vi.fn(),
|
|
74
|
+
}));
|
|
75
|
+
vi.mock("@pi-archimedes/image-paste/keybinding-offer", () => ({
|
|
76
|
+
offerKeybindingFix: vi.fn(async () => false),
|
|
77
|
+
}));
|
|
78
|
+
vi.mock("@pi-archimedes/subagent", () => ({
|
|
79
|
+
registerSubagent: vi.fn(),
|
|
80
|
+
registerAgentsCommand: vi.fn(),
|
|
81
|
+
}));
|
|
82
|
+
vi.mock("@pi-archimedes/web", () => ({ registerWeb: vi.fn() }));
|
|
83
|
+
|
|
84
|
+
vi.mock("./config.js", () => ({ loadDiffConfig: vi.fn(() => ({})) }));
|
|
85
|
+
vi.mock("./settings.js", () => ({ openSettings: vi.fn() }));
|
|
86
|
+
vi.mock("./plugin-manager.js", () => ({ registerPluginsCommand: vi.fn() }));
|
|
87
|
+
vi.mock("./onboarding/index.js", () => ({ runOnboarding: vi.fn(async () => {}) }));
|
|
88
|
+
|
|
89
|
+
const { default: metaFactory } = await import("./index.js");
|
|
90
|
+
const { reportPiSupport, piSupportWarnings } = await import("@pi-archimedes/core/pi-support");
|
|
91
|
+
const registrations = await import("@pi-archimedes/ui");
|
|
92
|
+
const subagentReg = await import("@pi-archimedes/subagent");
|
|
93
|
+
const diffReg = await import("@pi-archimedes/diff");
|
|
94
|
+
const webReg = await import("@pi-archimedes/web");
|
|
95
|
+
|
|
96
|
+
// ── Harness ─────────────────────────────────────────────────────────────────
|
|
97
|
+
|
|
98
|
+
const WARNINGS_KEY = Symbol.for("archimedes:piSupportWarnings");
|
|
99
|
+
const NOTICED_KEY = Symbol.for("archimedes:piSupportNoticed");
|
|
100
|
+
const globals = globalThis as Record<symbol, unknown>;
|
|
101
|
+
|
|
102
|
+
interface Harness {
|
|
103
|
+
startSession: (ctx: unknown) => Promise<unknown>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function freshFactory(): Harness {
|
|
107
|
+
const handlers: Record<string, Array<(...args: unknown[]) => unknown>> = {};
|
|
108
|
+
const pi = {
|
|
109
|
+
on(event: string, handler: (...args: unknown[]) => unknown) {
|
|
110
|
+
(handlers[event] ??= []).push(handler);
|
|
111
|
+
},
|
|
112
|
+
registerCommand: () => {},
|
|
113
|
+
registerTool: () => {},
|
|
114
|
+
};
|
|
115
|
+
metaFactory(pi as never);
|
|
116
|
+
const startRcs = handlers["session_start"] ?? [];
|
|
117
|
+
expect(startRcs.length).toBeGreaterThan(0);
|
|
118
|
+
// The LAST session_start handler is the lazy-load one — the same handler meta
|
|
119
|
+
// prints the notice from, after every package has had its chance to report.
|
|
120
|
+
const lazy = startRcs[startRcs.length - 1] as (...args: unknown[]) => unknown;
|
|
121
|
+
return { startSession: (ctx: unknown) => lazy(undefined, ctx) as Promise<unknown> };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** A ctx with a UI surface, i.e. what an interactive session hands us. */
|
|
125
|
+
function uiCtx() {
|
|
126
|
+
return { hasUI: true, ui: { theme: {}, notify: vi.fn() }, cwd: "/tmp" };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
beforeEach(() => {
|
|
130
|
+
for (const key of Object.keys(mockStore)) delete mockStore[key];
|
|
131
|
+
delete globals[WARNINGS_KEY];
|
|
132
|
+
delete globals[NOTICED_KEY];
|
|
133
|
+
vi.clearAllMocks();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
afterEach(() => {
|
|
137
|
+
delete globals[WARNINGS_KEY];
|
|
138
|
+
delete globals[NOTICED_KEY];
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// ── Tests ───────────────────────────────────────────────────────────────────
|
|
142
|
+
|
|
143
|
+
describe("aggregated pi-support notice", () => {
|
|
144
|
+
it("stays silent on a supported host (nothing reported, nothing shown)", async () => {
|
|
145
|
+
const { startSession } = freshFactory();
|
|
146
|
+
const ctx = uiCtx();
|
|
147
|
+
await startSession(ctx);
|
|
148
|
+
|
|
149
|
+
expect(piSupportWarnings()).toEqual([]);
|
|
150
|
+
expect(ctx.ui.notify).not.toHaveBeenCalled();
|
|
151
|
+
// …and every package still registered, which is the baseline the next tests
|
|
152
|
+
// compare against.
|
|
153
|
+
expect(vi.mocked(registrations.registerUI)).toHaveBeenCalledTimes(1);
|
|
154
|
+
expect(vi.mocked(subagentReg.registerSubagent)).toHaveBeenCalledTimes(1);
|
|
155
|
+
expect(vi.mocked(diffReg.registerDiffTools)).toHaveBeenCalledTimes(1);
|
|
156
|
+
expect(vi.mocked(webReg.registerWeb)).toHaveBeenCalledTimes(1);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("shows ONE message naming every reporting package on a below-floor host, and still registers everything", async () => {
|
|
160
|
+
// What the packages recorded during registration on an old host.
|
|
161
|
+
reportPiSupport("ui", "99.0.0");
|
|
162
|
+
reportPiSupport("diff", "99.0.0");
|
|
163
|
+
reportPiSupport("subagent", "99.0.0");
|
|
164
|
+
|
|
165
|
+
const { startSession } = freshFactory();
|
|
166
|
+
const ctx = uiCtx();
|
|
167
|
+
await startSession(ctx);
|
|
168
|
+
|
|
169
|
+
expect(ctx.ui.notify).toHaveBeenCalledTimes(1);
|
|
170
|
+
const [message, level] = ctx.ui.notify.mock.calls[0] as [string, string | undefined];
|
|
171
|
+
expect(message).toContain("ui");
|
|
172
|
+
expect(message).toContain("diff");
|
|
173
|
+
expect(message).toContain("subagent");
|
|
174
|
+
expect(message).toContain("99.0.0");
|
|
175
|
+
expect(level).toBe("warning");
|
|
176
|
+
|
|
177
|
+
// Warn and STILL register — the guard changes nothing about loading.
|
|
178
|
+
expect(vi.mocked(registrations.registerUI)).toHaveBeenCalledTimes(1);
|
|
179
|
+
expect(vi.mocked(subagentReg.registerSubagent)).toHaveBeenCalledTimes(1);
|
|
180
|
+
expect(vi.mocked(subagentReg.registerAgentsCommand)).toHaveBeenCalledTimes(1);
|
|
181
|
+
expect(vi.mocked(diffReg.registerDiffTools)).toHaveBeenCalledTimes(1);
|
|
182
|
+
expect(vi.mocked(webReg.registerWeb)).toHaveBeenCalledTimes(1);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("does not repeat the notice on a later session_start (/new, /fork, /resume)", async () => {
|
|
186
|
+
reportPiSupport("ui", "99.0.0");
|
|
187
|
+
const { startSession } = freshFactory();
|
|
188
|
+
|
|
189
|
+
const first = uiCtx();
|
|
190
|
+
await startSession(first);
|
|
191
|
+
expect(first.ui.notify).toHaveBeenCalledTimes(1);
|
|
192
|
+
|
|
193
|
+
const second = uiCtx();
|
|
194
|
+
await startSession(second);
|
|
195
|
+
expect(second.ui.notify).not.toHaveBeenCalled();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("survives a /reload: re-evaluated modules must not print the notice again", async () => {
|
|
199
|
+
reportPiSupport("ui", "99.0.0");
|
|
200
|
+
const first = uiCtx();
|
|
201
|
+
await (await freshFactory()).startSession(first);
|
|
202
|
+
expect(first.ui.notify).toHaveBeenCalledTimes(1);
|
|
203
|
+
|
|
204
|
+
// Pi builds a fresh jiti/module registry when an extension is reloaded: same
|
|
205
|
+
// process, same globalThis, brand-new module bindings — and every register()
|
|
206
|
+
// runs again, so the packages report again. That is exactly the case a
|
|
207
|
+
// module-level `let warned = false` would get wrong.
|
|
208
|
+
vi.resetModules();
|
|
209
|
+
const reloadedGuard = (await import("@pi-archimedes/core/pi-support")) as typeof import("@pi-archimedes/core/pi-support");
|
|
210
|
+
const reloadedFactory = (await import("./index.js")).default as typeof metaFactory;
|
|
211
|
+
// Non-vacuity: this really is a fresh module instance, i.e. the same shape
|
|
212
|
+
// of event `/reload` produces.
|
|
213
|
+
expect(reloadedGuard.reportPiSupport).not.toBe(reportPiSupport);
|
|
214
|
+
|
|
215
|
+
const handlers: Record<string, Array<(...args: unknown[]) => unknown>> = {};
|
|
216
|
+
reloadedFactory({
|
|
217
|
+
on: (event: string, handler: (...args: unknown[]) => unknown) => {
|
|
218
|
+
(handlers[event] ??= []).push(handler);
|
|
219
|
+
},
|
|
220
|
+
registerCommand: () => {},
|
|
221
|
+
registerTool: () => {},
|
|
222
|
+
} as never);
|
|
223
|
+
// The packages re-report through the *reloaded* guard module.
|
|
224
|
+
reloadedGuard.reportPiSupport("ui", "99.0.0");
|
|
225
|
+
|
|
226
|
+
const second = uiCtx();
|
|
227
|
+
const lazy = (handlers["session_start"] ?? []).at(-1) as (...args: unknown[]) => unknown;
|
|
228
|
+
await lazy(undefined, second);
|
|
229
|
+
|
|
230
|
+
// The registry still holds the one entry, and the notice stays spent.
|
|
231
|
+
expect(reloadedGuard.piSupportWarnings()).toHaveLength(1);
|
|
232
|
+
expect(reloadedGuard.takePiSupportNotice()).toBeUndefined();
|
|
233
|
+
expect(second.ui.notify).not.toHaveBeenCalled();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("still records the notice to the log sink when there is no UI to show it", async () => {
|
|
237
|
+
reportPiSupport("ui", "99.0.0");
|
|
238
|
+
const { startSession } = freshFactory();
|
|
239
|
+
|
|
240
|
+
// A ctx without a UI surface (headless / print mode).
|
|
241
|
+
await startSession({ hasUI: false, cwd: "/tmp" });
|
|
242
|
+
|
|
243
|
+
const lines = vi.mocked(diag).mock.calls.map(([scope, message]) => `${scope} ${message}`);
|
|
244
|
+
expect(lines.some((l) => l.startsWith("meta") && l.includes("99.0.0"))).toBe(true);
|
|
245
|
+
});
|
|
246
|
+
});
|
package/src/plugin-manager.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
// chrome for a minimal per-plugin list: each row has `values: ["On", "Off"]`
|
|
6
6
|
// cycled with ←/→, and every change persists immediately to the
|
|
7
7
|
// package's own archimedes.* namespace (its `enabled` key). There are
|
|
8
|
-
// deliberately NO prompt descriptors
|
|
9
|
-
// Space
|
|
10
|
-
// text
|
|
8
|
+
// deliberately NO prompt descriptors, so no row carries a `submenu`: Enter and
|
|
9
|
+
// Space fall through to `SettingsList`'s own cycling and toggle the row, rather
|
|
10
|
+
// than opening a text field.
|
|
11
11
|
|
|
12
12
|
import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
13
13
|
import type { SettingItem } from "@earendil-works/pi-tui";
|
package/src/plugins.test.ts
CHANGED
|
@@ -58,7 +58,6 @@ vi.mock("@pi-archimedes/ui", () => ({
|
|
|
58
58
|
loadUIConfig: vi.fn(() => ({})),
|
|
59
59
|
saveUIConfig: vi.fn(),
|
|
60
60
|
registerUI: vi.fn(),
|
|
61
|
-
unpatchConsoleLog: vi.fn(),
|
|
62
61
|
}));
|
|
63
62
|
|
|
64
63
|
vi.mock("@pi-archimedes/footer/config", () => ({
|
|
@@ -236,7 +235,12 @@ describe("PLUGINS manifest integrity", () => {
|
|
|
236
235
|
}
|
|
237
236
|
});
|
|
238
237
|
|
|
239
|
-
|
|
238
|
+
// The one place the manifest is really imported, so this is a cold module-graph
|
|
239
|
+
// walk of the published `footer` package: 485 ms idle, 4389 ms in a loaded
|
|
240
|
+
// full-suite run (the repo's type-check looped over it) — inside the band that
|
|
241
|
+
// made #131 fail. Same class of shield as the other loaded-run cases; the
|
|
242
|
+
// assertion is unchanged.
|
|
243
|
+
it("load() resolves for a real installed package (footer probe)", { timeout: 10_000 }, async () => {
|
|
240
244
|
const footer = PLUGINS.find((p): p is PluginDef => p.id === "footer");
|
|
241
245
|
expect(footer).toBeDefined();
|
|
242
246
|
const mod = await footer!.load();
|