fix: refresh pi dependency compatibility
Update Pi packages to 0.79.9 and align pi-ask with current TUI/RPC behavior. - guard custom ask/settings flows to TUI mode with a clear non-TUI fallback - reset config cache on extension reload so edited settings are picked up - clean up remote ask flow listeners on session shutdown - forward editor focus/invalidation and keep @ file autocomplete explicit - document the non-TUI contract and cover the compatibility fixes with tests
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { registerAnswerCommands } from "../src/answer-commands.ts";
|
||||
|
||||
function registerCommands() {
|
||||
const commands = new Map<
|
||||
string,
|
||||
{ handler: (args: string, ctx: any) => Promise<void> }
|
||||
>();
|
||||
registerAnswerCommands({
|
||||
registerCommand(
|
||||
name: string,
|
||||
command: { handler: (args: string, ctx: any) => Promise<void> }
|
||||
) {
|
||||
commands.set(name, command);
|
||||
},
|
||||
} as never);
|
||||
return commands;
|
||||
}
|
||||
|
||||
test("answer commands do not open custom UI outside TUI mode", async () => {
|
||||
const commands = registerCommands();
|
||||
const notifications: Array<{ message: string; type: string }> = [];
|
||||
let customOpened = false;
|
||||
const ctx = {
|
||||
mode: "rpc",
|
||||
ui: {
|
||||
custom() {
|
||||
customOpened = true;
|
||||
},
|
||||
notify(message: string, type: string) {
|
||||
notifications.push({ message, type });
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await commands.get("answer")?.handler("", ctx);
|
||||
await commands.get("answer:again")?.handler("", ctx);
|
||||
await commands.get("ask:replay")?.handler("", ctx);
|
||||
|
||||
assert.equal(customOpened, false);
|
||||
assert.deepEqual(notifications, [
|
||||
{ message: "/answer requires interactive TUI mode.", type: "error" },
|
||||
{ message: "Ask replay requires interactive TUI mode.", type: "error" },
|
||||
{ message: "Ask replay requires interactive TUI mode.", type: "error" },
|
||||
]);
|
||||
});
|
||||
@@ -37,6 +37,7 @@ test("registers /ask-settings and opens the shared settings overlay", async () =
|
||||
|
||||
const customCalls: Array<{ options: unknown; lines: string[] }> = [];
|
||||
await commands.get("ask-settings")?.handler("", {
|
||||
mode: "tui",
|
||||
ui: {
|
||||
custom(callback: any, options: unknown) {
|
||||
const done = () => {
|
||||
@@ -75,3 +76,40 @@ test("registers /ask-settings and opens the shared settings overlay", async () =
|
||||
delete process.env.PI_CODING_AGENT_DIR;
|
||||
await rm(agentDir, { force: true, recursive: true });
|
||||
});
|
||||
|
||||
test("/ask-settings notifies outside TUI instead of opening custom UI", async () => {
|
||||
const commands = new Map<
|
||||
string,
|
||||
{ handler: (args: string, ctx: any) => Promise<void> }
|
||||
>();
|
||||
registerAskSettingsCommand({
|
||||
registerCommand(
|
||||
name: string,
|
||||
command: { handler: (args: string, ctx: any) => Promise<void> }
|
||||
) {
|
||||
commands.set(name, command);
|
||||
},
|
||||
} as never);
|
||||
|
||||
const notifications: Array<{ message: string; type: string }> = [];
|
||||
let customOpened = false;
|
||||
await commands.get("ask-settings")?.handler("", {
|
||||
mode: "rpc",
|
||||
ui: {
|
||||
custom() {
|
||||
customOpened = true;
|
||||
},
|
||||
notify(message: string, type: string) {
|
||||
notifications.push({ message, type });
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(customOpened, false);
|
||||
assert.deepEqual(notifications, [
|
||||
{
|
||||
message: "/ask-settings requires interactive TUI mode.",
|
||||
type: "error",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
+22
-3
@@ -4,7 +4,7 @@ import { registerAskTool } from "../src/ask-tool.ts";
|
||||
import type { AskParams } from "../src/types.ts";
|
||||
|
||||
const NON_INTERACTIVE_MESSAGE_RE =
|
||||
/Needs user input: ask_user requires interactive UI\./;
|
||||
/Needs user input: ask_user requires interactive TUI mode\./;
|
||||
const FIRST_QUESTION_RE = /1\. Goal: What should I optimize for\?/;
|
||||
const SPEED_OPTION_RE = /- Speed \[speed\]/;
|
||||
const CUSTOM_OPTION_RE = /- Type your own \[custom\]/;
|
||||
@@ -47,8 +47,8 @@ function registerMockTool() {
|
||||
};
|
||||
}
|
||||
|
||||
function makeCtx(hasUi: boolean): unknown {
|
||||
return { [HAS_UI]: hasUi };
|
||||
function makeCtx(hasUi: boolean, mode = hasUi ? "tui" : "print"): unknown {
|
||||
return { [HAS_UI]: hasUi, mode };
|
||||
}
|
||||
|
||||
function sampleParams(): AskParams {
|
||||
@@ -113,6 +113,25 @@ test("ask tool returns pending questions in non-interactive mode", async () => {
|
||||
assert.match(result.content[0].text, CUSTOM_OPTION_RE);
|
||||
});
|
||||
|
||||
test("ask tool does not open custom UI outside TUI mode", async () => {
|
||||
const { tool } = registerMockTool();
|
||||
let customOpened = false;
|
||||
|
||||
const result = await tool.execute("call-1", sampleParams(), undefined, noop, {
|
||||
[HAS_UI]: true,
|
||||
mode: "rpc",
|
||||
ui: {
|
||||
custom() {
|
||||
customOpened = true;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(customOpened, false);
|
||||
assert.equal(result.details.cancelled, true);
|
||||
assert.match(result.content[0].text, NON_INTERACTIVE_MESSAGE_RE);
|
||||
});
|
||||
|
||||
test("ask tool includes custom answer fallback for preview questions", async () => {
|
||||
const { tool } = registerMockTool();
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { createAskAutocompleteProvider } from "../src/ui/autocomplete.ts";
|
||||
|
||||
test("ask autocomplete explicitly triggers on file mention marker", () => {
|
||||
const provider = createAskAutocompleteProvider(process.cwd());
|
||||
|
||||
assert.deepEqual(provider.triggerCharacters, ["@"]);
|
||||
});
|
||||
@@ -5,7 +5,11 @@ import { dirname, join } from "node:path";
|
||||
import test from "node:test";
|
||||
import { DEFAULT_ASK_CONFIG } from "../src/config/defaults.ts";
|
||||
import type { AskConfig } from "../src/config/schema.ts";
|
||||
import { AskConfigStore } from "../src/config/store.ts";
|
||||
import {
|
||||
AskConfigStore,
|
||||
getAskConfigStore,
|
||||
resetAskConfigStore,
|
||||
} from "../src/config/store.ts";
|
||||
|
||||
const DEFAULT_KEYMAPS_NOTICE_PATTERN =
|
||||
/Using default ask keymaps for this session/;
|
||||
@@ -31,6 +35,38 @@ async function makeTempPath(name: string): Promise<string> {
|
||||
return join(root, "eko24ive-pi-ask.json");
|
||||
}
|
||||
|
||||
test("resetAskConfigStore reloads the global store from disk", async () => {
|
||||
const root = await import("node:fs/promises").then(({ mkdtemp }) =>
|
||||
mkdtemp(join(tmpdir(), "pi-ask-config-reset-"))
|
||||
);
|
||||
const path = join(root, "extensions", "eko24ive-pi-ask.json");
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(
|
||||
path,
|
||||
JSON.stringify({
|
||||
...expectedConfigFile(),
|
||||
behaviour: {
|
||||
...DEFAULT_ASK_CONFIG.behaviour,
|
||||
autoSubmitWhenAnsweredWithoutNotes: true,
|
||||
},
|
||||
})
|
||||
);
|
||||
process.env.PI_CODING_AGENT_DIR = root;
|
||||
resetAskConfigStore();
|
||||
getAskConfigStore().setConfig(DEFAULT_ASK_CONFIG);
|
||||
|
||||
resetAskConfigStore();
|
||||
const result = await getAskConfigStore().ensureLoaded();
|
||||
|
||||
assert.equal(
|
||||
result.config.behaviour.autoSubmitWhenAnsweredWithoutNotes,
|
||||
true
|
||||
);
|
||||
delete process.env.PI_CODING_AGENT_DIR;
|
||||
resetAskConfigStore();
|
||||
await rm(root, { force: true, recursive: true });
|
||||
});
|
||||
|
||||
test("config store writes defaults when file is missing", async () => {
|
||||
const path = await makeTempPath("pi-ask-config-missing-");
|
||||
const store = new AskConfigStore(path);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { Editor } from "@earendil-works/pi-tui";
|
||||
import { DEFAULT_ASK_CONFIG } from "../src/config/defaults.ts";
|
||||
import { getAskConfigStore } from "../src/config/store.ts";
|
||||
import { createInitialState } from "../src/state/create.ts";
|
||||
@@ -279,6 +280,7 @@ test("custom editor submit key controls actual editor submission", async () => {
|
||||
const resultPromise = runAskFlow(
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
mode: "tui",
|
||||
ui: {
|
||||
custom(callback: (...args: unknown[]) => unknown) {
|
||||
return new Promise((resolve) => {
|
||||
@@ -331,6 +333,78 @@ function plainTheme() {
|
||||
};
|
||||
}
|
||||
|
||||
test("ask flow forwards focus and invalidation to its editor", async () => {
|
||||
getAskConfigStore().setConfig({
|
||||
...DEFAULT_ASK_CONFIG,
|
||||
notifications: {
|
||||
...DEFAULT_ASK_CONFIG.notifications,
|
||||
enabled: false,
|
||||
},
|
||||
});
|
||||
const originalInvalidate = Editor.prototype.invalidate;
|
||||
let invalidateCalls = 0;
|
||||
Editor.prototype.invalidate = function patchedInvalidate(this: Editor) {
|
||||
invalidateCalls += 1;
|
||||
return originalInvalidate.call(this);
|
||||
};
|
||||
let component:
|
||||
| {
|
||||
focused: boolean;
|
||||
handleInput(data: string): void;
|
||||
invalidate(): void;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
try {
|
||||
const resultPromise = runAskFlow(
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
mode: "tui",
|
||||
ui: {
|
||||
custom(callback: (...args: unknown[]) => unknown) {
|
||||
return new Promise((resolve) => {
|
||||
component = callback(
|
||||
{
|
||||
requestRender() {
|
||||
// Rendering is not needed for this controller test.
|
||||
},
|
||||
},
|
||||
plainTheme(),
|
||||
{},
|
||||
resolve
|
||||
) as typeof component;
|
||||
});
|
||||
},
|
||||
},
|
||||
} as never,
|
||||
{
|
||||
questions: [
|
||||
{
|
||||
id: "q1",
|
||||
prompt: "Question?",
|
||||
options: [{ value: "a", label: "A" }],
|
||||
},
|
||||
],
|
||||
}
|
||||
);
|
||||
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert(component);
|
||||
component.focused = true;
|
||||
assert.equal(component.focused, true);
|
||||
component.focused = false;
|
||||
assert.equal(component.focused, false);
|
||||
component.invalidate();
|
||||
assert.equal(invalidateCalls, 1);
|
||||
component.handleInput("\x1b");
|
||||
const result = await resultPromise;
|
||||
assert.equal(result.cancelled, true);
|
||||
} finally {
|
||||
Editor.prototype.invalidate = originalInvalidate;
|
||||
getAskConfigStore().setConfig(DEFAULT_ASK_CONFIG);
|
||||
}
|
||||
});
|
||||
|
||||
test("custom configured note shortcuts are used at runtime", () => {
|
||||
const navigation = createInitialState({
|
||||
questions: [
|
||||
|
||||
@@ -172,6 +172,45 @@ test("started event questions are cloned", async () => {
|
||||
assert.equal(questions[0].options[0].label, "Yes");
|
||||
});
|
||||
|
||||
test("remote runtime disposes active flows and submit listener", () => {
|
||||
const bus = new TestEventBus();
|
||||
const remoteAsk = createRemoteAskRuntime(bus as never);
|
||||
let submitCalls = 0;
|
||||
const flow = remoteAsk.startFlow({
|
||||
source: "tool",
|
||||
questions: createInitialState({
|
||||
questions: [
|
||||
{
|
||||
id: "decision",
|
||||
prompt: "Proceed?",
|
||||
options: [{ value: "yes", label: "Yes" }],
|
||||
},
|
||||
],
|
||||
}).questions,
|
||||
onSubmit: () => {
|
||||
submitCalls += 1;
|
||||
return { ok: true };
|
||||
},
|
||||
});
|
||||
remoteAsk.disposeAll();
|
||||
|
||||
bus.emit(PI_ASK_SUBMIT_EVENT, {
|
||||
version: 1,
|
||||
requestId: "request-1",
|
||||
flowId: flow.flowId,
|
||||
response: {
|
||||
kind: "answer",
|
||||
answers: { decision: { values: ["yes"] } },
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(submitCalls, 0);
|
||||
assert.equal(
|
||||
bus.events.some((event) => event.channel === PI_ASK_SUBMIT_RESULT_EVENT),
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
test("remote submit resolves an active ask flow and emits lifecycle events", async () => {
|
||||
getAskConfigStore().setConfig({
|
||||
...DEFAULT_ASK_CONFIG,
|
||||
@@ -197,6 +236,7 @@ test("remote submit resolves an active ask flow and emits lifecycle events", asy
|
||||
const result = await runAskFlow(
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
mode: "tui",
|
||||
ui: {
|
||||
custom(callback: (...args: unknown[]) => unknown) {
|
||||
return new Promise((resolve) => {
|
||||
|
||||
Reference in New Issue
Block a user