mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
AutoReview: - 审查器回到 Codex Guardian 风格的对话式审查,默认跟随会话当前主模型 (每次审查实时读取 ctx.model);provider/model 必须同时设置才固定审查 模型,只设其一视为配置错误并转人工。 - 结论只通过 approve / reject 两个工具给出,参数仅 reason;不强制 toolChoice,正文文本(即使是合法 JSON)一律忽略。 - approve 自动放行;reject 转人工并在弹窗显示理由(标注模型生成)。 超时、Provider 错误、截断、未调用工具、多次调用、参数无效等异常同样 转人工,并附固定的系统说明;用户按 Esc 中止时直接拒绝。 - 模型调用改为 modelRegistry.streamSimple(...).result():Pi 1.3.0 面向 扩展的 ModelRegistry 没有 completeSimple,原写法在真实环境中每次都会 转人工。 - 对话记录保留可信度标注;工具结果在有更短的 pi-compaction 摘要时替换 为摘要;token 估算改为非 ASCII 字符按 1 token 计;预算可配置。 - 同一条用户消息内完全相同的请求只缓存 approve 结论。 - 默认 reasoning low、总超时 30 秒、最多 2 次尝试、maxOutputTokens 4000。 删除: - 未发布过的 TypeSafe Jev 分类器实现、DenialCircuitBreaker。 - 整个 annotator 机制(model-explanation、注册表、registerAnnotator、 provider-timeout);annotators 配置键保留为已弃用并忽略,避免旧配置 被拒绝。 测试: - 新增 reviewer / transcript / 弹窗说明 / 默认配置测试;清理重复、恒真 或只测实现细节的旧测试。 - 使用 deepseek-v4.1-flash 实测 5 个场景各 5 次,25 次结论全部符合预期。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
224 lines
7.3 KiB
TypeScript
224 lines
7.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
createMcpPermissionTargets,
|
|
McpTargetList,
|
|
parseQualifiedMcpToolName,
|
|
} from "#src/access-intent/mcp-targets";
|
|
|
|
describe("parseQualifiedMcpToolName", () => {
|
|
it("returns server and tool for a valid qualified name", () => {
|
|
expect(parseQualifiedMcpToolName("exa:search")).toEqual({
|
|
server: "exa",
|
|
tool: "search",
|
|
});
|
|
});
|
|
|
|
it("returns server and tool with surrounding whitespace trimmed", () => {
|
|
expect(parseQualifiedMcpToolName(" exa : search ")).toEqual({
|
|
server: "exa",
|
|
tool: "search",
|
|
});
|
|
});
|
|
|
|
it("returns null for empty or whitespace-only string", () => {
|
|
expect(parseQualifiedMcpToolName("")).toBeNull();
|
|
expect(parseQualifiedMcpToolName(" ")).toBeNull();
|
|
});
|
|
|
|
it("returns null when colon is the first character", () => {
|
|
expect(parseQualifiedMcpToolName(":search")).toBeNull();
|
|
});
|
|
|
|
it("returns null when colon is the last character", () => {
|
|
expect(parseQualifiedMcpToolName("exa:")).toBeNull();
|
|
});
|
|
|
|
it("returns null for a plain tool name with no colon", () => {
|
|
expect(parseQualifiedMcpToolName("exa_search")).toBeNull();
|
|
});
|
|
|
|
it("returns null when either part is empty after trimming", () => {
|
|
expect(parseQualifiedMcpToolName(" :search")).toBeNull();
|
|
expect(parseQualifiedMcpToolName("exa: ")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("createMcpPermissionTargets", () => {
|
|
describe("tool call (input.tool)", () => {
|
|
it("produces targets for a bare tool name with no configured servers", () => {
|
|
const targets = createMcpPermissionTargets({ tool: "exa_search" }, []);
|
|
expect(targets).toContain("exa_search");
|
|
expect(targets).toContain("mcp_call");
|
|
});
|
|
|
|
it("produces targets for a qualified tool name (server:tool)", () => {
|
|
const targets = createMcpPermissionTargets({ tool: "exa:search" }, []);
|
|
expect(targets).toContain("exa_search");
|
|
expect(targets).toContain("exa:search");
|
|
expect(targets).toContain("exa");
|
|
expect(targets).toContain("mcp_call");
|
|
});
|
|
|
|
it("produces targets for a tool call with explicit server field", () => {
|
|
const targets = createMcpPermissionTargets(
|
|
{ tool: "search", server: "exa" },
|
|
[],
|
|
);
|
|
expect(targets).toContain("exa_search");
|
|
expect(targets).toContain("exa:search");
|
|
expect(targets).toContain("exa");
|
|
expect(targets).toContain("mcp_call");
|
|
});
|
|
|
|
it("derives server targets from configured server names when tool name ends with _<server>", () => {
|
|
const targets = createMcpPermissionTargets({ tool: "search_exa" }, [
|
|
"exa",
|
|
]);
|
|
expect(targets).toContain("exa_search_exa");
|
|
expect(targets).toContain("exa:search_exa");
|
|
expect(targets).toContain("exa");
|
|
});
|
|
|
|
it("does not derive server targets for names not ending in _<server>", () => {
|
|
const targets = createMcpPermissionTargets({ tool: "exa_search" }, [
|
|
"exa",
|
|
]);
|
|
expect(targets).toContain("exa_search");
|
|
expect(targets).not.toContain("exa");
|
|
expect(targets).not.toContain("exa:exa_search");
|
|
});
|
|
});
|
|
|
|
describe("connect call (input.connect)", () => {
|
|
it("produces targets for a connect operation", () => {
|
|
const targets = createMcpPermissionTargets({ connect: "exa" }, []);
|
|
expect(targets).toContain("mcp_connect_exa");
|
|
expect(targets).toContain("exa");
|
|
expect(targets).toContain("mcp_connect");
|
|
});
|
|
|
|
it("does not include mcp_call for connect operations", () => {
|
|
const targets = createMcpPermissionTargets({ connect: "exa" }, []);
|
|
expect(targets).not.toContain("mcp_call");
|
|
});
|
|
});
|
|
|
|
describe("describe operation (input.describe)", () => {
|
|
it("produces targets for a describe operation on a qualified tool", () => {
|
|
const targets = createMcpPermissionTargets(
|
|
{ describe: "exa:search" },
|
|
[],
|
|
);
|
|
expect(targets).toContain("exa_search");
|
|
expect(targets).toContain("exa:search");
|
|
expect(targets).toContain("exa");
|
|
expect(targets).toContain("mcp_describe");
|
|
});
|
|
});
|
|
|
|
describe("search operation (input.search)", () => {
|
|
it("produces mcp_search and the search string as targets", () => {
|
|
const targets = createMcpPermissionTargets({ search: "weather" }, []);
|
|
expect(targets).toContain("weather");
|
|
expect(targets).toContain("mcp_search");
|
|
});
|
|
|
|
it("includes server targets when server is provided alongside search", () => {
|
|
const targets = createMcpPermissionTargets(
|
|
{ search: "weather", server: "exa" },
|
|
[],
|
|
);
|
|
expect(targets).toContain("mcp_server_exa");
|
|
expect(targets).toContain("exa");
|
|
expect(targets).toContain("mcp_search");
|
|
});
|
|
});
|
|
|
|
describe("server listing (input.server only)", () => {
|
|
it("produces mcp_list and server-specific targets", () => {
|
|
const targets = createMcpPermissionTargets({ server: "exa" }, []);
|
|
expect(targets).toContain("mcp_server_exa");
|
|
expect(targets).toContain("exa");
|
|
expect(targets).toContain("mcp_list");
|
|
});
|
|
});
|
|
|
|
describe("status (no meaningful input)", () => {
|
|
it("produces mcp_status for empty input", () => {
|
|
const targets = createMcpPermissionTargets({}, []);
|
|
expect(targets).toContain("mcp_status");
|
|
});
|
|
|
|
it("produces mcp_status for null or unrecognized input", () => {
|
|
expect(createMcpPermissionTargets(null, [])).toContain("mcp_status");
|
|
expect(
|
|
createMcpPermissionTargets({ unrelated: "value" }, ["exa"]),
|
|
).toContain("mcp_status");
|
|
});
|
|
});
|
|
|
|
describe("priority ordering", () => {
|
|
it("tool targets appear before mcp_call", () => {
|
|
const targets = createMcpPermissionTargets({ tool: "exa:search" }, []);
|
|
const mcpCallIdx = targets.indexOf("mcp_call");
|
|
const exaSearchIdx = targets.indexOf("exa_search");
|
|
expect(exaSearchIdx).toBeGreaterThanOrEqual(0);
|
|
expect(mcpCallIdx).toBeGreaterThan(exaSearchIdx);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("McpTargetList", () => {
|
|
describe("add", () => {
|
|
it("ignores null", () => {
|
|
const list = new McpTargetList();
|
|
list.add(null);
|
|
expect(list.toArray()).toEqual([]);
|
|
});
|
|
|
|
it("ignores empty string", () => {
|
|
const list = new McpTargetList();
|
|
list.add("");
|
|
expect(list.toArray()).toEqual([]);
|
|
});
|
|
|
|
it("appends a new value", () => {
|
|
const list = new McpTargetList();
|
|
list.add("exa");
|
|
expect(list.toArray()).toEqual(["exa"]);
|
|
});
|
|
|
|
it("dedups repeated values", () => {
|
|
const list = new McpTargetList();
|
|
list.add("exa");
|
|
list.add("exa");
|
|
expect(list.toArray()).toEqual(["exa"]);
|
|
});
|
|
|
|
it("preserves first-insertion order across a mix of values", () => {
|
|
const list = new McpTargetList();
|
|
list.add("exa_search");
|
|
list.add("exa:search");
|
|
list.add("exa");
|
|
list.add("exa_search"); // duplicate — must not change order
|
|
list.add("mcp_call");
|
|
expect(list.toArray()).toEqual([
|
|
"exa_search",
|
|
"exa:search",
|
|
"exa",
|
|
"mcp_call",
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("toArray", () => {
|
|
it("returns an independent copy that does not mutate the list", () => {
|
|
const list = new McpTargetList();
|
|
list.add("exa");
|
|
const first = list.toArray();
|
|
first.push("mutated");
|
|
expect(list.toArray()).toEqual(["exa"]);
|
|
});
|
|
});
|
|
});
|