From 66a96a5fdbab099cbc3ba98ae3c5e4cb6f14ee64 Mon Sep 17 00:00:00 2001 From: Tawhidul Islam <276017696+FhDBro@users.noreply.github.com> Date: Sun, 1 Nov 2026 11:48:48 +0600 Subject: [PATCH] fix(pi): show ecc-doctor report immediately when run --- .pi/extensions/index.ts | 2 +- tests/pi/pi-extension-adapter.test.js | 60 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/.pi/extensions/index.ts b/.pi/extensions/index.ts index 241deabce..55a88892b 100644 --- a/.pi/extensions/index.ts +++ b/.pi/extensions/index.ts @@ -759,7 +759,7 @@ export default function (pi: ExtensionAPI): void { content: buildDoctorReport(ctx), display: true, }, - { deliverAs: "nextTurn" } + { triggerTurn: false } ) }, }) diff --git a/tests/pi/pi-extension-adapter.test.js b/tests/pi/pi-extension-adapter.test.js index b900fc7d6..deb74c4db 100644 --- a/tests/pi/pi-extension-adapter.test.js +++ b/tests/pi/pi-extension-adapter.test.js @@ -44,6 +44,8 @@ const assert = require("assert") const fs = require("fs") const os = require("os") const path = require("path") +const vm = require("vm") +const ts = require("typescript") const { spawnSync, execFile } = require("child_process") const { resolveHookRuntime } = require( path.join(__dirname, "..", "..", ".pi", "extensions", "hook-runtime.js") @@ -528,6 +530,64 @@ async function main() { ) }], + ["ecc-doctor emits report immediately without nextTurn delivery delay", async () => { + const commands = new Map() + const messages = [] + const mockPi = { + on: () => {}, + registerCommand: (name, def) => commands.set(name, def), + sendMessage: (msg, opts) => messages.push({ msg, opts }), + } + const compiled = ts.transpileModule(extensionSource, { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, + }).outputText + const mod = { exports: {} } + vm.runInNewContext(compiled, { + module: mod, + exports: mod.exports, + __dirname: path.resolve(repoRoot, ".pi", "extensions"), + process, + require: name => { + if (name === "./hook-runtime.js") { + return require(path.resolve(repoRoot, ".pi", "extensions", "hook-runtime.js")) + } + return require(name) + }, + }) + + mod.exports.default(mockPi) + + const doctorCmd = commands.get("ecc-doctor") + assert.ok( + doctorCmd && typeof doctorCmd.handler === "function", + "expected ecc-doctor command to register a handler" + ) + + const mockCtx = { + cwd: repoRoot, + ui: { notify: () => {} }, + } + + await doctorCmd.handler({}, mockCtx) + + assert.strictEqual(messages.length, 1, "expected ecc-doctor to send exactly one message") + assert.strictEqual(messages[0].msg?.customType, "ecc-doctor", "expected ecc-doctor customType") + assert.strictEqual(messages[0].msg?.display, true, "expected ecc-doctor report to be visible") + assert.ok( + typeof messages[0].msg?.content === "string" && messages[0].msg.content.trim().length > 0, + "expected ecc-doctor report content to be nonempty" + ) + assert.strictEqual( + messages[0].opts?.triggerTurn, + false, + "expected ecc-doctor to pass triggerTurn: false so running diagnostics does not invoke the LLM" + ) + assert.ok( + messages[0].opts?.deliverAs !== "nextTurn", + "expected ecc-doctor not to queue with deliverAs: nextTurn; in Pi, queued delivery stalls display until next turn" + ) + }], + ["bounds hook execution with a timeout and a maxBuffer", () => { assert.ok( extensionSource.includes("timeout"),