@zhushanwen/pi-ask-user 7.0.12 → 7.0.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-ask-user",
3
- "version": "7.0.12",
3
+ "version": "7.0.14",
4
4
  "description": "Inline adaptive ask_user tool for Pi — single/multi-question structured input with split-pane preview, inline editor and optional comments.",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -29,7 +29,8 @@
29
29
  "ARCHITECTURE.md"
30
30
  ],
31
31
  "dependencies": {
32
- "@xyz-agent/extension-protocol": "0.5.1"
32
+ "@xyz-agent/extension-protocol": "0.6.0",
33
+ "@zhushanwen/pi-extension-logger": "0.3.0"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@earendil-works/pi-tui": "^0.84.2",
@@ -11,6 +11,16 @@
11
11
  // - version !== 1 → warn + 重建为新 slot,旧 pending 丢弃
12
12
  //
13
13
  // 隔离:每个用例前 Reflect.deleteProperty(globalThis, CHANNEL_HANDSHAKE_KEY)。
14
+ // Mock 共享 logger,让 logger.warn 可被 spy(源码已从 console.warn 改为 logger.warn)
15
+ const { loggerMock } = vi.hoisted(() => ({
16
+ loggerMock: { debug: vi.fn(), warn: vi.fn(), error: vi.fn() },
17
+ }));
18
+ vi.mock("@zhushanwen/pi-extension-logger", () => ({
19
+ getLogger: () => loggerMock,
20
+ createLogger: () => loggerMock,
21
+ setPiHandle: vi.fn(),
22
+ }));
23
+
14
24
  import { beforeEach,describe, expect, it, vi } from "vitest";
15
25
 
16
26
  import type { ChannelHandler } from "../channel-handler";
@@ -135,7 +145,7 @@ describe("registerAskUserChannelHandler", () => {
135
145
 
136
146
  it("version !== 1 → warn + 重建为新 slot,旧 pending 丢弃", () => {
137
147
  // 塞一个 version=2 的旧 slot(模拟未来协议升级 / 脏数据)
138
- const spyWarn = vi.spyOn(console, "warn").mockImplementation(() => undefined);
148
+ loggerMock.warn.mockClear();
139
149
  const legacyPending = [{ channel: "stale", handler: noopHandler }];
140
150
  const legacySlot = {
141
151
  version: 2 as const,
@@ -152,10 +162,8 @@ describe("registerAskUserChannelHandler", () => {
152
162
  expect(slot!.version).toBe(1);
153
163
  expect(slot!.pending).toEqual([{ channel: "ask_user", handler: noopHandler }]);
154
164
  // warn 被调用(包含 version mismatch 提示)
155
- expect(spyWarn).toHaveBeenCalledTimes(1);
156
- expect(spyWarn.mock.calls[0]![0]).toContain("version mismatch");
157
-
158
- spyWarn.mockRestore();
165
+ expect(loggerMock.warn).toHaveBeenCalledTimes(1);
166
+ expect(loggerMock.warn.mock.calls[0]![0]).toContain("version mismatch");
159
167
  });
160
168
 
161
169
  it("registry 就绪但 slot 已预置 pending → 仍走 register 路径(pending 不被本函数消费)", () => {
@@ -14,6 +14,9 @@
14
14
  // registry 实例——仅往 slot 写 pending 或调 slot.registry.register。
15
15
 
16
16
  import type { ChannelHandler } from "./channel-handler";
17
+ import { getLogger } from "@zhushanwen/pi-extension-logger";
18
+
19
+ const logger = getLogger("ask-user");
17
20
 
18
21
  /**
19
22
  * 进程级 channel registry 握手的 globalThis key(Symbol.for 跨模块共享)。
@@ -69,9 +72,10 @@ function readSlot(): ChannelRegistryHandshake | undefined {
69
72
  | undefined;
70
73
  if (slot === undefined) return undefined;
71
74
  if (slot.version !== HANDSHAKE_VERSION) {
72
- console.warn(
73
- `[ask-user] channel handshake slot version mismatch: expected ${HANDSHAKE_VERSION}, got ${slot.version}; discarding and rebuilding slot`,
74
- );
75
+ logger.warn('channel handshake slot version mismatch, discarding and rebuilding', {
76
+ expected: HANDSHAKE_VERSION,
77
+ got: slot.version,
78
+ });
75
79
  return undefined;
76
80
  }
77
81
  return slot;