mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-08-28 08:35:57 +00:00
feat: add search API key configuration
This commit is contained in:
+33
-7
@@ -2,10 +2,10 @@ import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import test from "node:test";
|
||||
|
||||
import { EXA_TOOLS, MCP_CONFIG } from "../extensions/mcp-config.ts";
|
||||
import { createMcpConfig, EXA_TOOLS } from "../extensions/mcp-config.ts";
|
||||
|
||||
test("one MCP adapter config contains both Exa and CodeGraph", () => {
|
||||
assert.deepEqual(MCP_CONFIG, {
|
||||
assert.deepEqual(createMcpConfig({}), {
|
||||
settings: {
|
||||
disableProxyTool: true,
|
||||
scriptMode: false,
|
||||
@@ -35,13 +35,39 @@ test("one MCP adapter config contains both Exa and CodeGraph", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("the package loads only the shared MCP extension entry", async () => {
|
||||
test("Exa API key is resolved from the environment into a header and never placed in the URL", () => {
|
||||
const config = createMcpConfig({ EXA_API_KEY: "exa-test-key" });
|
||||
assert.deepEqual(config.mcpServers.exa.headers, { "x-api-key": "$env:EXA_API_KEY" });
|
||||
assert.equal(config.mcpServers.exa.url?.includes("exa-test-key"), false);
|
||||
assert.equal(JSON.stringify(config).includes("exa-test-key"), false);
|
||||
});
|
||||
|
||||
test("the package has exactly one local MCP adapter owner", async () => {
|
||||
const packageJson = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8")) as {
|
||||
pi: { extensions: string[] };
|
||||
};
|
||||
const localMcpEntries = packageJson.pi.extensions.filter((entry) =>
|
||||
entry === "./extensions/mcp.ts" || entry === "./extensions/exa.ts" || entry === "./extensions/codegraph.ts"
|
||||
);
|
||||
const localEntries = packageJson.pi.extensions.filter((entry) => entry.startsWith("./extensions/"));
|
||||
const adapterOwners: string[] = [];
|
||||
for (const entry of localEntries) {
|
||||
const source = await readFile(new URL(`../${entry.slice(2)}`, import.meta.url), "utf8");
|
||||
if (source.includes("createMcpAdapter") || source.includes('from "pi-mcp-adapter"')) {
|
||||
adapterOwners.push(entry);
|
||||
}
|
||||
}
|
||||
assert.deepEqual(adapterOwners, ["./extensions/mcp.ts"]);
|
||||
});
|
||||
|
||||
assert.deepEqual(localMcpEntries, ["./extensions/mcp.ts"]);
|
||||
test("search credentials load before all search providers", async () => {
|
||||
const packageJson = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8")) as {
|
||||
pi: { extensions: string[] };
|
||||
};
|
||||
const entries = packageJson.pi.extensions;
|
||||
const loaderIndex = entries.indexOf("./extensions/search-config.ts");
|
||||
for (const provider of [
|
||||
"./extensions/tavily-override.ts",
|
||||
"./node_modules/@keenable/pi-search/src/index.ts",
|
||||
"./extensions/mcp.ts",
|
||||
]) {
|
||||
assert.ok(loaderIndex >= 0 && loaderIndex < entries.indexOf(provider), `${provider} must load after search config`);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user