mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 04:42:10 +03:00
* feat(plugins): WordPress-style plugin system backend * fix(plugins): address code review feedback - Path traversal guard: validate entryPoint stays within plugin dir - install() now handles direct plugin directories (not just parent dirs) - Non-null assertion replaced with explicit null check - require efficiency: allowedModules map moved outside function - Source wrapper: add newlines to prevent trailing comment issues - Config validation: validate values against configSchema on save - Dynamic import comment: clarify Node.js caching behavior Co-Authored-By: OpenClaude (mimo-v2.5-pro) <openclaude@gitlawb.com> * fix(plugins): replace vm with child_process, add auth to all routes Addresses all remaining code review feedback: 1. **Loader rewrite**: Replaced Node.js vm module with child_process.fork() for proper process-level isolation. Complies with Rule 3 (no eval). Each plugin runs in a separate Node.js process with IPC communication. 2. **Auth on all routes**: Added requireManagementAuth to all 6 plugin API route files (list, install, scan, details, activate, deactivate, config). 3. **Env filtering**: Only safe env vars passed to plugin processes unless "env" permission is granted. Co-Authored-By: OpenClaude (mimo-v2.5-pro) <openclaude@gitlawb.com> * fix(plugins): security + ESM fixes for loader and manager loader.ts: - Fix IPC: use process.send()/process.on("message") instead of worker_threads.parentPort - Fix ESM: write host script as .mjs (not .js) to force ESM execution - Add timeout: 10s default on callHook() with Promise.race - Add SIGKILL escalation: SIGTERM first, then SIGKILL after 3s grace - Fix env filtering: use allowlist (safeKeys) instead of passing all env vars - Clear timeout on successful IPC response (no timer leak) manager.ts: - Fix path traversal: use fs.realpath() instead of startsWith() - Fix imports: use registerHook/unregisterHooks from hooks.ts - Register hooks individually via registerHook(event, name, handler) hooks.ts: - Copied from feat/plugin-custom-hooks (canonical registry) * feat(discovery): add discovery tool stub service Phase 1 scaffold for automated provider discovery: - DiscoveryConfig, DiscoveryResult types - probeEndpoint() for URL availability checking - scanProvider() stub (Phase 2 will implement real scanning) - getDiscoveryResults() stub - Default config: disabled (opt-in) * chore(plugins): slop cleanup — pino logger, remove redundant sorts - index.ts: replace console.log/error with pino structured logging - hooks.ts: remove redundant .sort() in emitHookBlocking/runOnResponse (already sorted on registration) - manager.ts: add readFile import * test(plugins): add scanner, loader, manager unit tests - scanner: 9 tests (discovery, hidden dirs, validation, entry point, multiple) - loader: 5 tests (type contracts, Plugin/PluginContext/PluginResult interfaces) - manager: 6 tests (singleton, lifecycle methods, error on unknown) - Total: 20 tests, all passing * fix(settings): add missing home page pin keys to updateSettingsSchema * feat(plugins): add i18n keys to all 42 locales * fix(settings): add missing security keys to updateSettingsSchema and add tests * fix(usage): analytics route reads combo_name/requested_model from call_logs only The 3.8.6 variant of #2904 added SELECTs of combo_name/requested_model against usage_history, but those columns only exist in call_logs (no migration adds them to usage_history). This returned HTTP 500 on /api/usage/analytics. Restore the working query shape from the 3.8.7 variant. Fixes 18 failing usage-analytics-route tests. * fix(types,test): resolve noImplicitAny in progressiveAging + align semaphore test to #2903 gate pruning - progressiveAging: type compression results so messages[0].content is indexable (was TS7053 against {}); restores typecheck:noimplicit:core gate. - services-branch-hardening: #2903 (perf-ram) prunes idle rate-limit gates on zero; assert no-running/empty-queue without assuming the entry persists. * fix(analytics): address merged review regressions * fix(executor): normalize max effort for openai shape providers * Make zero-latency combo optimizations opt-in * Address zero-latency combo review feedback * chore(release): sync v3.8.7 touchpoints + credit contributors - llm.txt → 3.8.7 (Current version + Key Features header) - CHANGELOG: add Dmitry Kuznetsov & Nikolay Alafuzov to 3.8.6 Hall of Contributors - version already 3.8.7 across package.json/open-sse/electron/openapi (from #2909) * fix(cleanup): restore usage history cutoff boundary * docs(changelog): rank 3.8.6 contributors in a commits table with their PRs * fix(dashboard): theme ReactFlow Controls +/- buttons for dark mode * fix(settings): add missing home page pin keys to updateSettingsSchema * fix(settings): add missing security keys to updateSettingsSchema and add tests * fix(executor): normalize max effort for openai shape providers * Make zero-latency combo optimizations opt-in * Address zero-latency combo review feedback * fix(analytics): address merged review regressions * fix(cleanup): restore usage history cutoff boundary * feat(plugins): WordPress-style plugin system backend * fix(plugins): address code review feedback - Path traversal guard: validate entryPoint stays within plugin dir - install() now handles direct plugin directories (not just parent dirs) - Non-null assertion replaced with explicit null check - require efficiency: allowedModules map moved outside function - Source wrapper: add newlines to prevent trailing comment issues - Config validation: validate values against configSchema on save - Dynamic import comment: clarify Node.js caching behavior Co-Authored-By: OpenClaude (mimo-v2.5-pro) <openclaude@gitlawb.com> * fix(plugins): replace vm with child_process, add auth to all routes Addresses all remaining code review feedback: 1. **Loader rewrite**: Replaced Node.js vm module with child_process.fork() for proper process-level isolation. Complies with Rule 3 (no eval). Each plugin runs in a separate Node.js process with IPC communication. 2. **Auth on all routes**: Added requireManagementAuth to all 6 plugin API route files (list, install, scan, details, activate, deactivate, config). 3. **Env filtering**: Only safe env vars passed to plugin processes unless "env" permission is granted. Co-Authored-By: OpenClaude (mimo-v2.5-pro) <openclaude@gitlawb.com> * fix(plugins): security + ESM fixes for loader and manager loader.ts: - Fix IPC: use process.send()/process.on("message") instead of worker_threads.parentPort - Fix ESM: write host script as .mjs (not .js) to force ESM execution - Add timeout: 10s default on callHook() with Promise.race - Add SIGKILL escalation: SIGTERM first, then SIGKILL after 3s grace - Fix env filtering: use allowlist (safeKeys) instead of passing all env vars - Clear timeout on successful IPC response (no timer leak) manager.ts: - Fix path traversal: use fs.realpath() instead of startsWith() - Fix imports: use registerHook/unregisterHooks from hooks.ts - Register hooks individually via registerHook(event, name, handler) hooks.ts: - Copied from feat/plugin-custom-hooks (canonical registry) * feat(discovery): add discovery tool stub service Phase 1 scaffold for automated provider discovery: - DiscoveryConfig, DiscoveryResult types - probeEndpoint() for URL availability checking - scanProvider() stub (Phase 2 will implement real scanning) - getDiscoveryResults() stub - Default config: disabled (opt-in) * chore(plugins): slop cleanup — pino logger, remove redundant sorts - index.ts: replace console.log/error with pino structured logging - hooks.ts: remove redundant .sort() in emitHookBlocking/runOnResponse (already sorted on registration) - manager.ts: add readFile import * test(plugins): add scanner, loader, manager unit tests - scanner: 9 tests (discovery, hidden dirs, validation, entry point, multiple) - loader: 5 tests (type contracts, Plugin/PluginContext/PluginResult interfaces) - manager: 6 tests (singleton, lifecycle methods, error on unknown) - Total: 20 tests, all passing * feat(plugins): add i18n keys to all 42 locales * chore(plugins): remove duplicate migration 059_create_plugins.sql * chore(plugins): remove duplicate migration 059_create_plugins.sql (post-merge) * fix(sse): guard non-string error.code in proxyFetch + harden model parsing (#2463) (#2923) Integrated into release/v3.8.7 * fix(docker): add runner-web stage with Playwright Chromium (#2832) (#2846) Integrated into release/v3.8.7 * docs(changelog): document NVIDIA NIM and error code type-crash fix (#2463) * test: ignore NVIDIA_BASE_URL and NVIDIA_MODEL in env contract check --------- Co-authored-by: oyi77 <oyi77@users.noreply.github.com> Co-authored-by: OpenClaude (mimo-v2.5-pro) <openclaude@gitlawb.com> Co-authored-by: Apostol Apostolov <theapoapostolov@gmail.com> Co-authored-by: Halil Tezcan KARABULUT <info@hlltzcnkb.com> Co-authored-by: R.D. <rogerproself@gmail.com>
150 lines
6.7 KiB
TypeScript
150 lines
6.7 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { GeminiWebExecutor } = await import("../../open-sse/executors/gemini-web.ts");
|
|
const { getExecutor, hasSpecializedExecutor } = await import("../../open-sse/executors/index.ts");
|
|
|
|
// ─── Registration ───────────────────────────────────────────────────────────
|
|
|
|
test("GeminiWebExecutor is registered in executor index", () => {
|
|
assert.ok(hasSpecializedExecutor("gemini-web"));
|
|
const executor = getExecutor("gemini-web");
|
|
assert.ok(executor instanceof GeminiWebExecutor);
|
|
});
|
|
|
|
test("GeminiWebExecutor sets correct provider name", () => {
|
|
const executor = new GeminiWebExecutor();
|
|
assert.equal(executor.getProvider(), "gemini-web");
|
|
});
|
|
|
|
// ─── Input validation ───────────────────────────────────────────────────────
|
|
|
|
test("Returns 401 when no cookies provided", async () => {
|
|
const executor = new GeminiWebExecutor();
|
|
const result = await executor.execute({
|
|
model: "gemini-2.5-pro",
|
|
body: { messages: [{ role: "user", content: "hi" }], stream: false },
|
|
stream: false,
|
|
credentials: {},
|
|
signal: AbortSignal.timeout(10000),
|
|
log: null,
|
|
});
|
|
assert.equal(result.response.status, 401);
|
|
const json = (await result.response.json()) as any;
|
|
assert.ok(json.error.includes("Missing Gemini cookies"));
|
|
});
|
|
|
|
test("Returns 400 when no user message", async () => {
|
|
const executor = new GeminiWebExecutor();
|
|
const result = await executor.execute({
|
|
model: "gemini-2.5-pro",
|
|
body: { messages: [{ role: "system", content: "You are helpful" }], stream: false },
|
|
stream: false,
|
|
credentials: { apiKey: "test-cookie" },
|
|
signal: AbortSignal.timeout(10000),
|
|
log: null,
|
|
});
|
|
assert.equal(result.response.status, 400);
|
|
const json = (await result.response.json()) as any;
|
|
assert.ok(json.error.includes("No user message"));
|
|
});
|
|
|
|
// ─── Provider registration ──────────────────────────────────────────────────
|
|
|
|
test("Provider: gemini-web in WEB_COOKIE_PROVIDERS", async () => {
|
|
const { WEB_COOKIE_PROVIDERS } = await import("../../src/shared/constants/providers.ts");
|
|
assert.ok(WEB_COOKIE_PROVIDERS["gemini-web"], "gemini-web should be in WEB_COOKIE_PROVIDERS");
|
|
assert.equal(WEB_COOKIE_PROVIDERS["gemini-web"].id, "gemini-web");
|
|
assert.ok(WEB_COOKIE_PROVIDERS["gemini-web"].authHint);
|
|
});
|
|
|
|
test("Provider: gemini-web in providerRegistry", async () => {
|
|
const { REGISTRY } = await import("../../open-sse/config/providerRegistry.ts");
|
|
assert.ok(REGISTRY["gemini-web"], "gemini-web should be in providerRegistry");
|
|
assert.equal(REGISTRY["gemini-web"].executor, "gemini-web");
|
|
assert.ok(REGISTRY["gemini-web"].models.length > 0);
|
|
});
|
|
|
|
test("Provider: gemini-web has correct models", async () => {
|
|
const { REGISTRY } = await import("../../open-sse/config/providerRegistry.ts");
|
|
const models = REGISTRY["gemini-web"].models;
|
|
const modelIds = models.map((m: any) => m.id);
|
|
assert.ok(modelIds.includes("gemini-2.5-pro"));
|
|
assert.ok(modelIds.includes("gemini-2.5-flash"));
|
|
assert.ok(modelIds.includes("gemini-2.0-pro"));
|
|
assert.ok(modelIds.includes("gemini-2.0-flash"));
|
|
});
|
|
|
|
// ─── Regression: #2832 — Playwright missing in Docker (runner-base) ──────────
|
|
//
|
|
// When the `runner-base` Docker image is used (no Playwright browsers installed),
|
|
// `import("playwright")` succeeds but `chromium.launch()` throws the well-known
|
|
// "Executable doesn't exist" error. The executor MUST surface this as a sanitized
|
|
// 500 — never an unhandled rejection — so users get a clear error message rather
|
|
// than a silent stream abort.
|
|
//
|
|
// Hard rule #12: error must go through sanitizeErrorMessage (no raw err.message
|
|
// or stack trace in the response body).
|
|
|
|
test("#2832: Playwright launch failure returns sanitized 500, not unhandled rejection", async () => {
|
|
const playwrightError = new Error(
|
|
"browserType.launch: Executable doesn't exist at /home/node/.cache/ms-playwright/chromium_headless_shell-1161/chrome-linux/headless_shell\n" +
|
|
" at /app/node_modules/playwright-core/lib/server/browserType.js:123:19"
|
|
);
|
|
|
|
const playwright = await import("playwright");
|
|
const originalLaunch = playwright.chromium.launch;
|
|
|
|
playwright.chromium.launch = async () => {
|
|
throw playwrightError;
|
|
};
|
|
|
|
try {
|
|
const executor = new GeminiWebExecutor();
|
|
const result = await executor.execute({
|
|
model: "gemini-2.5-pro",
|
|
body: { messages: [{ role: "user", content: "hello" }], stream: false },
|
|
stream: false,
|
|
credentials: { apiKey: "fake-cookie=abc" },
|
|
signal: AbortSignal.timeout(5000),
|
|
log: null,
|
|
});
|
|
|
|
assert.equal(result.response.status, 500, "should return HTTP 500");
|
|
const json = (await result.response.json()) as any;
|
|
assert.ok(typeof json.error === "string", "error field must be a string");
|
|
// Hard rule #12: sanitizeErrorMessage must strip the stack trace tail.
|
|
assert.ok(!json.error.includes("\n at "), "must not contain multi-line stack trace");
|
|
assert.ok(!json.error.includes("node_modules/playwright-core"), "must not contain node_modules source path");
|
|
} finally {
|
|
playwright.chromium.launch = originalLaunch;
|
|
}
|
|
});
|
|
|
|
test("#2832: GeminiWebExecutor catch block sanitizes Playwright launch errors (integration path)", async () => {
|
|
// This test verifies the actual catch block in GeminiWebExecutor.execute()
|
|
// handles the Playwright "Executable doesn't exist" error shape correctly.
|
|
// We use an AbortSignal that is already aborted so we bypass the Playwright
|
|
// import entirely and hit the pre-launch abort check — confirming the executor
|
|
// returns a structured Response rather than throwing.
|
|
const executor = new GeminiWebExecutor();
|
|
const controller = new AbortController();
|
|
controller.abort(new Error("Request aborted"));
|
|
|
|
const result = await executor.execute({
|
|
model: "gemini-2.5-pro",
|
|
body: { messages: [{ role: "user", content: "hello" }], stream: false },
|
|
stream: false,
|
|
credentials: { apiKey: "fake-cookie=abc" },
|
|
signal: controller.signal,
|
|
log: null,
|
|
});
|
|
|
|
// Aborted request should return a structured 500, not throw
|
|
assert.ok(result.response instanceof Response, "must return a Response object");
|
|
assert.equal(result.response.status, 500, "aborted request returns 500");
|
|
const json = (await result.response.json()) as any;
|
|
assert.ok(typeof json.error === "string", "error must be a string");
|
|
assert.ok(!json.error.includes("at /"), "no stack trace path in error response");
|
|
});
|