mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 08:35:57 +00:00
Merge branch 'main' of bitbucket.org:siakitem/my-pi
# Conflicts: # AGENTS.md # README.md # package-lock.json # package.json # pi-tool-search/CHANGELOG.md # pi-tool-search/README.md # pi-tool-search/docs/dynamic-tool-loading.md # pi-tool-search/extensions/bundle-groups.ts # pi-tool-search/test/bundle-groups.test.ts
This commit is contained in:
@@ -49,6 +49,10 @@ test("all package extensions load together without global registration conflicts
|
||||
files: string[];
|
||||
pi: { extensions: string[] };
|
||||
};
|
||||
assert.ok(
|
||||
packageJson.pi.extensions.includes("./extensions/plugin-init.ts"),
|
||||
"the bundle must expose the project plugin initializer command",
|
||||
);
|
||||
assert.ok(
|
||||
packageJson.pi.extensions.includes("./hippo-memory-pi/index.ts"),
|
||||
"the bundle must load the vendored official Hippo Memory extension",
|
||||
@@ -61,6 +65,36 @@ test("all package extensions load together without global registration conflicts
|
||||
packageJson.pi.extensions.includes("./pi-extension-codex-fast-mode/index.ts"),
|
||||
"the bundle must load the locally maintained Codex Fast mode extension",
|
||||
);
|
||||
assert.ok(packageJson.pi.extensions.includes("./pi-ssh/index.ts"), "the bundle must load the locally maintained SSH extension");
|
||||
assert.equal(packageJson.dependencies["pi-ssh"], "file:./pi-ssh");
|
||||
assert.equal(packageJson.dependencies.ssh2, "1.17.0", "the packed bundle must install pi-ssh's runtime transport");
|
||||
assert.equal(packageJson.dependencies.jiti, "2.7.0", "the packed helper must load local TypeScript outside Pi");
|
||||
assert.ok(packageJson.files.includes("pi-ssh"), "the packed bundle must include the locally maintained SSH source");
|
||||
assert.ok(packageJson.files.includes("ssh_config.sh"), "the packed bundle must include the SSH host import helper");
|
||||
assert.ok(packageJson.pi.extensions.includes("./pi-ask-user/index.ts"), "the bundle must load pi-ask-user");
|
||||
assert.equal(packageJson.dependencies["pi-ask-user"], "file:./pi-ask-user");
|
||||
assert.ok(packageJson.files.includes("pi-ask-user"), "the packed bundle must include pi-ask-user source");
|
||||
const permissionConfig = JSON.parse(
|
||||
await readFile(join(repositoryRoot, "config", "pi-permission-system.json"), "utf8"),
|
||||
) as { authorizerChain: string[]; permission: Record<string, unknown> };
|
||||
assert.equal(permissionConfig.permission.ssh_connect, "ask", "SSH connection must enter the permission gate");
|
||||
assert.equal(permissionConfig.permission.ssh_cd, "ask", "remote workspace changes must enter the permission gate");
|
||||
assert.deepEqual(permissionConfig.authorizerChain, ["auto-review"], "SSH connection asks must reach AutoReview");
|
||||
assert.ok(
|
||||
packageJson.pi.extensions.indexOf("./extensions/permission-system.ts") <
|
||||
packageJson.pi.extensions.indexOf("./pi-ssh/index.ts"),
|
||||
"the permission service must load before pi-ssh registers its permission bridge",
|
||||
);
|
||||
assert.ok(
|
||||
packageJson.pi.extensions.indexOf("./pi-ssh/index.ts") <
|
||||
packageJson.pi.extensions.indexOf("./pi-tool-search/extensions/index.ts"),
|
||||
"pi-ssh tools must register before Tool Search builds its catalog",
|
||||
);
|
||||
assert.ok(
|
||||
packageJson.pi.extensions.indexOf("./pi-ask-user/index.ts") <
|
||||
packageJson.pi.extensions.indexOf("./pi-tool-search/extensions/index.ts"),
|
||||
"ask_user_question must register before Tool Search builds its catalog",
|
||||
);
|
||||
assert.equal(
|
||||
packageJson.dependencies["@firstpick/pi-extension-codex-fast-mode"],
|
||||
"file:./pi-extension-codex-fast-mode",
|
||||
@@ -69,6 +103,15 @@ test("all package extensions load together without global registration conflicts
|
||||
packageJson.files.includes("pi-extension-codex-fast-mode"),
|
||||
"the packed bundle must include the locally maintained Codex Fast mode source",
|
||||
);
|
||||
assert.ok(
|
||||
packageJson.pi.extensions.includes("./pi-notify/src/index.ts"),
|
||||
"the bundle must load the locally maintained Kitty notification extension",
|
||||
);
|
||||
assert.equal(packageJson.dependencies["@smoose/pi-notify"], "file:./pi-notify");
|
||||
assert.ok(
|
||||
packageJson.files.includes("pi-notify"),
|
||||
"the packed bundle must include the locally maintained notification source",
|
||||
);
|
||||
assert.equal(packageJson.dependencies["@ogulcancelik/pi-minimal-footer"], "file:./pi-minimal-footer");
|
||||
assert.equal(packageJson.dependencies["@tintinweb/pi-subagents"], "file:./pi-subagents");
|
||||
assert.ok(packageJson.pi.extensions.includes("./extensions/subagents.ts"));
|
||||
@@ -108,4 +151,8 @@ test("all package extensions load together without global registration conflicts
|
||||
|
||||
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
|
||||
assert.doesNotMatch(`${result.stdout}\n${result.stderr}`, /Failed to load extension|conflicts with/u);
|
||||
const deployedPermissionConfig = JSON.parse(
|
||||
await readFile(join(home, ".pi-agent", "extensions", "pi-permission-system", "config.json"), "utf8"),
|
||||
);
|
||||
assert.deepEqual(deployedPermissionConfig, permissionConfig, "the deployed permission config must match the bundle source");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { homedir, tmpdir } from "node:os";
|
||||
import { join, parse } from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import pluginInitExtension, {
|
||||
findMissingPluginInitializers,
|
||||
initializeMissingPlugins,
|
||||
validatePluginInitCwd,
|
||||
} from "../extensions/plugin-init.ts";
|
||||
|
||||
test("initializes missing CodeGraph and Hippo state after preflighting both CLIs", async () => {
|
||||
const cwd = await mkdtemp(join(tmpdir(), "my-pi-plugin-init-"));
|
||||
const calls: Array<{ command: string; args: string[]; cwd: string }> = [];
|
||||
try {
|
||||
const targets = await findMissingPluginInitializers(cwd);
|
||||
assert.deepEqual(targets.map(({ name }) => name), ["CodeGraph", "Hippo"]);
|
||||
|
||||
await initializeMissingPlugins(cwd, targets, async (command, args, options) => {
|
||||
calls.push({ command, args, cwd: options.cwd });
|
||||
return { code: 0, stdout: "ok", stderr: "" };
|
||||
});
|
||||
|
||||
assert.deepEqual(calls, [
|
||||
{ command: "codegraph", args: ["--version"], cwd },
|
||||
{ command: "hippo", args: ["--version"], cwd },
|
||||
{ command: "codegraph", args: ["init", cwd], cwd },
|
||||
{ command: "hippo", args: ["init"], cwd },
|
||||
]);
|
||||
} finally {
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("uses the CLIs' database files as authoritative initialization markers", async () => {
|
||||
const cwd = await mkdtemp(join(tmpdir(), "my-pi-plugin-init-"));
|
||||
const calls: string[] = [];
|
||||
try {
|
||||
await mkdir(join(cwd, ".codegraph"));
|
||||
await mkdir(join(cwd, ".hippo"));
|
||||
assert.deepEqual(
|
||||
(await findMissingPluginInitializers(cwd)).map(({ name }) => name),
|
||||
["CodeGraph", "Hippo"],
|
||||
"bare state directories must not count as initialized",
|
||||
);
|
||||
|
||||
await writeFile(join(cwd, ".codegraph", "codegraph.db"), "");
|
||||
assert.deepEqual((await findMissingPluginInitializers(cwd)).map(({ name }) => name), ["Hippo"]);
|
||||
await writeFile(join(cwd, ".hippo", "hippo.db"), "");
|
||||
const targets = await findMissingPluginInitializers(cwd);
|
||||
assert.deepEqual(targets, []);
|
||||
|
||||
await initializeMissingPlugins(cwd, targets, async (command, args) => {
|
||||
calls.push(`${command} ${args.join(" ")}`);
|
||||
return { code: 0, stdout: "ok", stderr: "" };
|
||||
});
|
||||
assert.deepEqual(calls, ["codegraph --version", "hippo --version"]);
|
||||
} finally {
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("rejects unsafe project roots", () => {
|
||||
assert.throws(() => validatePluginInitCwd(parse(homedir()).root), /文件系统根目录/);
|
||||
assert.throws(() => validatePluginInitCwd(homedir()), /用户主目录/);
|
||||
});
|
||||
|
||||
test("preflights both CLIs before creating project state", async () => {
|
||||
const cwd = await mkdtemp(join(tmpdir(), "my-pi-plugin-init-"));
|
||||
const calls: string[] = [];
|
||||
try {
|
||||
const targets = await findMissingPluginInitializers(cwd);
|
||||
await assert.rejects(
|
||||
initializeMissingPlugins(cwd, targets, async (command, args) => {
|
||||
calls.push(`${command} ${args.join(" ")}`);
|
||||
return command === "hippo"
|
||||
? { code: 1, stdout: "", stderr: "not installed" }
|
||||
: { code: 0, stdout: "ok", stderr: "" };
|
||||
}),
|
||||
/Hippo 检测失败:not installed/,
|
||||
);
|
||||
assert.deepEqual(calls, ["codegraph --version", "hippo --version"]);
|
||||
} finally {
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("plugin_init confirms the target and hot-reloads after initialization", async () => {
|
||||
let command: { handler: (args: string, ctx: any) => Promise<void> } | undefined;
|
||||
const calls: string[] = [];
|
||||
const pi = {
|
||||
registerCommand(name: string, definition: typeof command) {
|
||||
assert.equal(name, "plugin_init");
|
||||
command = definition;
|
||||
},
|
||||
exec: async (program: string, args: string[]) => {
|
||||
calls.push(`${program} ${args.join(" ")}`);
|
||||
return { code: 0, stdout: "ok", stderr: "" };
|
||||
},
|
||||
} as unknown as ExtensionAPI;
|
||||
pluginInitExtension(pi);
|
||||
assert.ok(command);
|
||||
const registeredCommand = command!;
|
||||
|
||||
const cwd = await mkdtemp(join(tmpdir(), "my-pi-plugin-init-"));
|
||||
let reloaded = false;
|
||||
let confirmation = "";
|
||||
try {
|
||||
await registeredCommand.handler("", {
|
||||
cwd,
|
||||
hasUI: true,
|
||||
ui: {
|
||||
confirm: async (_title: string, message: string) => {
|
||||
confirmation = message;
|
||||
return true;
|
||||
},
|
||||
notify() {},
|
||||
},
|
||||
reload: async () => {
|
||||
reloaded = true;
|
||||
},
|
||||
});
|
||||
assert.match(confirmation, new RegExp(cwd.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
|
||||
assert.deepEqual(calls, [
|
||||
"codegraph --version",
|
||||
"hippo --version",
|
||||
`codegraph init ${cwd}`,
|
||||
"hippo init",
|
||||
]);
|
||||
assert.equal(reloaded, true);
|
||||
} finally {
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("plugin_init reports retained partial state and does not reload when a later initializer fails", async () => {
|
||||
let command: { handler: (args: string, ctx: any) => Promise<void> } | undefined;
|
||||
const pi = {
|
||||
registerCommand(_name: string, definition: typeof command) {
|
||||
command = definition;
|
||||
},
|
||||
exec: async (program: string, args: string[]) => ({
|
||||
code: program === "hippo" && args[0] === "init" ? 1 : 0,
|
||||
stdout: "",
|
||||
stderr: "mock failure",
|
||||
}),
|
||||
} as unknown as ExtensionAPI;
|
||||
pluginInitExtension(pi);
|
||||
assert.ok(command);
|
||||
const registeredCommand = command!;
|
||||
|
||||
const cwd = await mkdtemp(join(tmpdir(), "my-pi-plugin-init-"));
|
||||
let reloaded = false;
|
||||
let error = "";
|
||||
try {
|
||||
await registeredCommand.handler("", {
|
||||
cwd,
|
||||
hasUI: true,
|
||||
ui: {
|
||||
confirm: async () => true,
|
||||
notify(message: string, level: string) {
|
||||
if (level === "error") error = message;
|
||||
},
|
||||
},
|
||||
reload: async () => {
|
||||
reloaded = true;
|
||||
},
|
||||
});
|
||||
assert.match(error, /Hippo 初始化失败:mock failure/);
|
||||
assert.match(error, /已完成的 CodeGraph 初始化会保留,不会自动回滚/);
|
||||
assert.equal(reloaded, false);
|
||||
} finally {
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("plugin_init stops without executing or reloading when confirmation is cancelled", async () => {
|
||||
let command: { handler: (args: string, ctx: any) => Promise<void> } | undefined;
|
||||
let executed = false;
|
||||
const pi = {
|
||||
registerCommand(_name: string, definition: typeof command) {
|
||||
command = definition;
|
||||
},
|
||||
exec: async () => {
|
||||
executed = true;
|
||||
return { code: 0, stdout: "", stderr: "" };
|
||||
},
|
||||
} as unknown as ExtensionAPI;
|
||||
pluginInitExtension(pi);
|
||||
const registeredCommand = command!;
|
||||
|
||||
const cwd = await mkdtemp(join(tmpdir(), "my-pi-plugin-init-"));
|
||||
let reloaded = false;
|
||||
try {
|
||||
await registeredCommand.handler("", {
|
||||
cwd,
|
||||
hasUI: true,
|
||||
ui: { confirm: async () => false, notify() {} },
|
||||
reload: async () => {
|
||||
reloaded = true;
|
||||
},
|
||||
});
|
||||
assert.equal(executed, false);
|
||||
assert.equal(reloaded, false);
|
||||
} finally {
|
||||
await rm(cwd, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -21,6 +21,27 @@ test("search routing narrows files before requesting matching line numbers", ()
|
||||
assert.match(section, /Use read with offset\/limit only for the exact matching region/);
|
||||
});
|
||||
|
||||
test("SSH connection routing requires an explicit named host and concrete task", () => {
|
||||
const section = buildToolRoutingSection(["ssh_connect"]);
|
||||
assert.match(section, /only when the user explicitly names an imported host/);
|
||||
assert.match(section, /separate step and wait for success before calling other ssh_\* tools/);
|
||||
assert.match(section, /never infer or substitute a different host/);
|
||||
});
|
||||
|
||||
test("remote cwd routing separates persistent workspace changes from shell commands", () => {
|
||||
const section = buildToolRoutingSection(["ssh_cd", "ssh_bash"]);
|
||||
assert.match(section, /call it as a separate step and wait for success/);
|
||||
assert.match(section, /relative ssh_read\/ssh_write\/ssh_edit\/ssh_find\/ssh_grep/);
|
||||
assert.match(section, /intentionally temporary, command-local directory change/);
|
||||
});
|
||||
|
||||
test("remote search routing uses structured bounded SSH tools", () => {
|
||||
const section = buildToolRoutingSection(["ssh_find", "ssh_grep"]);
|
||||
assert.match(section, /use ssh_find to narrow remote file paths before ssh_grep/);
|
||||
assert.match(section, /Do not run find, fd, grep, or rg through ssh_bash/);
|
||||
assert.match(section, /when a result says truncated, narrow the path or pattern/);
|
||||
});
|
||||
|
||||
test("context routing analyzes large files without a full read", () => {
|
||||
const section = buildToolRoutingSection(["ctx_execute", "ctx_execute_file"]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user