mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-27 11:20:42 +01:00
Add plugin and MCP hardening regression tests
This commit is contained in:
1 parent
518fc71cec
commit
30a13285c5
2 files changed
+56
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { normalizeApiUrl, readConfigFromEnv } from "./config.js";
|
||||
|
||||
describe("paperclip MCP config", () => {
|
||||
it("normalizes API URLs onto the /api base path", () => {
|
||||
expect(normalizeApiUrl("http://localhost:3100")).toBe("http://localhost:3100/api");
|
||||
expect(normalizeApiUrl("http://localhost:3100/")).toBe("http://localhost:3100/api");
|
||||
expect(normalizeApiUrl("http://localhost:3100/api")).toBe("http://localhost:3100/api");
|
||||
});
|
||||
|
||||
it("fails closed when PAPERCLIP_API_URL is missing or blank", () => {
|
||||
expect(() =>
|
||||
readConfigFromEnv({
|
||||
PAPERCLIP_API_KEY: "token-123",
|
||||
PAPERCLIP_API_URL: " ",
|
||||
}),
|
||||
).toThrow("Missing PAPERCLIP_API_URL");
|
||||
});
|
||||
|
||||
it("fails closed when PAPERCLIP_API_KEY is missing or blank", () => {
|
||||
expect(() =>
|
||||
readConfigFromEnv({
|
||||
PAPERCLIP_API_URL: "http://localhost:3100",
|
||||
PAPERCLIP_API_KEY: " ",
|
||||
}),
|
||||
).toThrow("Missing PAPERCLIP_API_KEY");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const pluginLoaderPath = path.resolve(import.meta.dirname, "../adapters/plugin-loader.ts");
|
||||
|
||||
describe("external adapter plugin loader", () => {
|
||||
it("keeps adapter loading dynamic instead of hardcoding external adapter imports", () => {
|
||||
const source = fs.readFileSync(pluginLoaderPath, "utf8");
|
||||
const importSpecifiers = Array.from(
|
||||
source.matchAll(/^\s*import(?:[\s\S]*?\sfrom\s+)?["']([^"']+)["'];?$/gm),
|
||||
(match) => match[1],
|
||||
);
|
||||
|
||||
expect(importSpecifiers).toEqual([
|
||||
"node:fs",
|
||||
"node:path",
|
||||
"./types.js",
|
||||
"../middleware/logger.js",
|
||||
"../services/adapter-plugin-store.js",
|
||||
"../services/adapter-plugin-store.js",
|
||||
]);
|
||||
expect(source).toContain("await import(modulePath)");
|
||||
expect(importSpecifiers.filter((specifier) => specifier.startsWith("../adapters/"))).toEqual([]);
|
||||
expect(importSpecifiers.filter((specifier) => specifier.startsWith("@paperclipai/"))).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user