66 lines
2.6 KiB
JavaScript
66 lines
2.6 KiB
JavaScript
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const test = require("node:test");
|
|
const vm = require("node:vm");
|
|
|
|
const extensionRoot = path.join(__dirname, "..", "apps", "browser-extension");
|
|
|
|
function loadAdapters() {
|
|
const context = { console, setTimeout, clearTimeout, URL };
|
|
context.globalThis = context;
|
|
vm.createContext(context);
|
|
vm.runInContext(fs.readFileSync(path.join(extensionRoot, "shared/provider-catalog.js"), "utf8"), context, {
|
|
filename: "shared/provider-catalog.js"
|
|
});
|
|
for (const file of [
|
|
"content/providers/core.js",
|
|
"content/providers/chatgpt.js",
|
|
"content/providers/deepseek.js",
|
|
"content/providers/qwen.js",
|
|
"content/providers/kimi.js",
|
|
"content/providers/zhipu.js",
|
|
"content/providers/claude.js",
|
|
"content/providers/gemini.js",
|
|
"content/providers/grok.js"
|
|
]) {
|
|
vm.runInContext(fs.readFileSync(path.join(extensionRoot, file), "utf8"), context, { filename: file });
|
|
}
|
|
return {
|
|
adapters: context.AIParallelProviderAdapters,
|
|
catalog: context.AIParallelProviderCatalog
|
|
};
|
|
}
|
|
|
|
test("all supported providers expose the adapter contract", () => {
|
|
const { adapters } = loadAdapters();
|
|
const ids = ["chatgpt", "deepseek", "qwen", "kimi", "zhipu", "claude", "gemini", "grok"];
|
|
assert.deepEqual(Object.keys(adapters).sort(), ids.slice().sort());
|
|
for (const id of ids) {
|
|
assert.equal(adapters[id].id, id);
|
|
assert.ok(adapters[id].hosts.length);
|
|
assert.ok(adapters[id].editorSelectors.length);
|
|
assert.ok(adapters[id].sendSelectors.length);
|
|
assert.equal(typeof adapters[id].sendPrompt, "function");
|
|
assert.equal(typeof adapters[id].collectResponse, "function");
|
|
assert.equal(typeof adapters[id].newChat, "function");
|
|
assert.equal(typeof adapters[id].healthCheck, "function");
|
|
}
|
|
});
|
|
|
|
test("provider adapters use the shared provider host catalog", () => {
|
|
const { adapters, catalog } = loadAdapters();
|
|
for (const provider of catalog) {
|
|
assert.deepEqual(adapters[provider.id].hosts, provider.hosts, provider.id);
|
|
}
|
|
});
|
|
|
|
test("Grok recognizes iframe-only authentication routes", () => {
|
|
const grok = loadAdapters().adapters.grok;
|
|
assert.equal(grok.isExternalAuthUrl("https://accounts.x.ai/check-login?redirect=grok-com"), true);
|
|
assert.equal(grok.isExternalAuthUrl("https://grok.com/sign-in?return_to=%2F"), true);
|
|
assert.equal(grok.isExternalAuthUrl("/login"), true);
|
|
assert.equal(grok.isExternalAuthUrl("https://grok.com/"), false);
|
|
assert.equal(grok.isExternalAuthUrl("https://example.com/sign-in"), false);
|
|
});
|