mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 08:35:57 +00:00
feat: vendor permission system source
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import {
|
||||
formatMissingToolNameReason,
|
||||
formatUnknownToolReason,
|
||||
} from "#src/permission-prompts";
|
||||
|
||||
describe("formatMissingToolNameReason", () => {
|
||||
test("mentions missing tool name and pi.getAllTools()", () => {
|
||||
const result = formatMissingToolNameReason();
|
||||
expect(result).toContain("no tool name");
|
||||
expect(result).toContain("pi.getAllTools()");
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatUnknownToolReason", () => {
|
||||
test("mentions the unknown tool name and lists available tools", () => {
|
||||
const result = formatUnknownToolReason("phantom", ["read", "write"]);
|
||||
expect(result).toContain("phantom");
|
||||
expect(result).toContain("read");
|
||||
expect(result).toContain("write");
|
||||
});
|
||||
|
||||
test("includes MCP hint for non-mcp tool names", () => {
|
||||
const result = formatUnknownToolReason("my-server:tool", ["mcp"]);
|
||||
expect(result).toContain("mcp");
|
||||
});
|
||||
|
||||
test("omits MCP hint when tool name is 'mcp'", () => {
|
||||
const result = formatUnknownToolReason("mcp", []);
|
||||
expect(result).not.toContain("call the registered 'mcp' tool");
|
||||
});
|
||||
|
||||
test("shows 'none' when no tools are registered", () => {
|
||||
const result = formatUnknownToolReason("ghost", []);
|
||||
expect(result).toContain("none");
|
||||
});
|
||||
|
||||
test("caps preview at 10 tools and appends ellipsis for longer lists", () => {
|
||||
const tools = Array.from({ length: 15 }, (_, i) => `tool${i}`);
|
||||
const result = formatUnknownToolReason("ghost", tools);
|
||||
expect(result).toContain("...");
|
||||
});
|
||||
});
|
||||
|
||||
// Skill denial text is now a render over the prompt payload.
|
||||
// Its behavior is tested in presentation/agent-renderer.test.ts.
|
||||
Reference in New Issue
Block a user