mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 09:02:11 +03:00
⭐5 — Provider x-search de primeira classe (SuperGrok/xAI x_search) em POST /v1/search e MCP omniroute_x_search. Fallback de credenciais xai-oauth→xao→xai; distinto de web search e do X Developer MCP. Reconciliado com o release tip (que já incluía #10981 "skip catalog-default SearXNG" deste mesmo lote): merge trouxe 5 conflitos reais de contagem gerada (llm.txt/README.md/AGENTS.md/PROVIDER_REFERENCE.md/SVGs/46 mirrors i18n, todos verificados como bump puro 347→348, sem perda de conteúdo do HEAD) + 1 conflito real de mergeable=CONFLICTING. Durante a validação, os 3 testes novos de SearXNG expuseram um bug real de interação com #10981: `isUnconfiguredLoopbackSearchProvider()` checava o baseUrl ESTÁTICO do catálogo em vez do baseUrl efetivo (após override de `provider_options.baseUrl` ou `providerSpecificData.baseUrl` da conexão), então QUALQUER request a searxng-search — mesmo com override customizado — era rejeitado como se fosse o default não-configurado. Corrigido em `open-sse/handlers/search.ts` (resolve o baseUrl efetivo via `resolveSearchBaseUrl()` antes do skip-check, tanto para o provider primário quanto o alternate). Um teste do próprio #10988 que assumia o comportamento pré-#10981 (default localhost:8888 sempre atendido) foi atualizado para refletir o comportamento já mesclado e intencional (503 quando não configurado). Validação completa: typecheck limpo, 70/70 testes unit (search-route/search-registry/x-search-provider/searxng-loopback-default), 24/24 vitest MCP, 14/14 integration (search-providers-catalog), lint limpo nos arquivos tocados, docs-counts-sync OK (2 drifts soft pré-existentes, não relacionados), gates estáticos (file-size/complexity/cognitive/dead-code/changelog) todos OK.
146 lines
5.8 KiB
TypeScript
146 lines
5.8 KiB
TypeScript
/**
|
|
* `modalityBridgeVisionMaxChars` — configurable teto for the vision-bridge
|
|
* describe-path output. 0 (default) means "no cap" (existing behavior
|
|
* unchanged); a positive value truncates the description with a `…` suffix
|
|
* before it is spliced back as `[Image N]: <description>`.
|
|
*
|
|
* Follows the DI harness pattern from `vision-bridge-cc-no-reroute.test.ts` /
|
|
* `vision-bridge-mode.test.ts` (settings + vision call injected, no real DB
|
|
* dependency for the describe path itself).
|
|
*/
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { VisionBridgeGuardrail } = await import("../../src/lib/guardrails/visionBridge.ts");
|
|
const { resolveVisionBridgeRuntimeSettings } =
|
|
await import("../../src/shared/constants/modalityBridgeDefaults.ts");
|
|
const { updateSettingsSchema } = await import("../../src/shared/validation/settingsSchemas.ts");
|
|
import type { GuardrailContext } from "../../src/lib/guardrails/base.ts";
|
|
import type { VisionModelConfig } from "../../src/lib/guardrails/visionBridgeHelpers.ts";
|
|
|
|
const TEXT_ONLY_MODEL = "some/text-only-model";
|
|
const LONG_DESCRIPTION = "x".repeat(500);
|
|
|
|
function imageBody(uniqueRef: string): Record<string, unknown> {
|
|
return {
|
|
model: TEXT_ONLY_MODEL,
|
|
messages: [
|
|
{
|
|
role: "user",
|
|
content: [
|
|
{ type: "text", text: "what is in the image?" },
|
|
{
|
|
type: "image_url",
|
|
image_url: {
|
|
url: `data:image/png;base64,${Buffer.from(uniqueRef).toString("base64")}`,
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
function findImageDescriptionText(modifiedPayload: unknown): string | undefined {
|
|
const body = modifiedPayload as { messages?: Array<{ content?: unknown }> } | undefined;
|
|
const messages = body?.messages ?? [];
|
|
for (const message of messages) {
|
|
const parts = message.content;
|
|
if (!Array.isArray(parts)) continue;
|
|
for (const part of parts) {
|
|
const p = part as { type?: string; text?: string };
|
|
if (p?.type === "text" && typeof p.text === "string" && p.text.startsWith("[Image 1]:")) {
|
|
return p.text;
|
|
}
|
|
}
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
test("modalityBridgeVisionMaxChars=120 caps the description with a … suffix", async () => {
|
|
const guardrail = new VisionBridgeGuardrail({
|
|
deps: {
|
|
getSettings: async () => ({
|
|
visionBridgeEnabled: true,
|
|
modalityBridgeVisionMode: "describe",
|
|
modalityBridgeVisionMaxChars: 120,
|
|
}),
|
|
callVisionModel: async (_imageDataUri: string, _config: VisionModelConfig) =>
|
|
LONG_DESCRIPTION,
|
|
},
|
|
});
|
|
|
|
const body = imageBody("maxchars-cap-test");
|
|
const context: GuardrailContext = { model: TEXT_ONLY_MODEL, log: console };
|
|
const result = await guardrail.preCall(body, context);
|
|
|
|
const text = findImageDescriptionText(result.modifiedPayload);
|
|
assert.ok(text, "expected a [Image 1]: text part in the modified payload");
|
|
const description = text!.slice("[Image 1]: ".length);
|
|
assert.ok(
|
|
description.length <= 121,
|
|
`capped description should be <= 121 chars (120 + ellipsis), got ${description.length}`
|
|
);
|
|
assert.ok(description.endsWith("…"), "capped description must end with an ellipsis suffix");
|
|
});
|
|
|
|
test("no modalityBridgeVisionMaxChars key: description is passed through in full", async () => {
|
|
const guardrail = new VisionBridgeGuardrail({
|
|
deps: {
|
|
getSettings: async () => ({
|
|
visionBridgeEnabled: true,
|
|
modalityBridgeVisionMode: "describe",
|
|
}),
|
|
callVisionModel: async (_imageDataUri: string, _config: VisionModelConfig) =>
|
|
LONG_DESCRIPTION,
|
|
},
|
|
});
|
|
|
|
const body = imageBody("maxchars-nokey-test");
|
|
const context: GuardrailContext = { model: TEXT_ONLY_MODEL, log: console };
|
|
const result = await guardrail.preCall(body, context);
|
|
|
|
const text = findImageDescriptionText(result.modifiedPayload);
|
|
assert.ok(text, "expected a [Image 1]: text part in the modified payload");
|
|
const description = text!.slice("[Image 1]: ".length);
|
|
assert.equal(description, LONG_DESCRIPTION, "without a cap the description must be untouched");
|
|
assert.ok(!description.endsWith("…"), "unconfigured cap must never add an ellipsis");
|
|
});
|
|
|
|
test("resolveVisionBridgeRuntimeSettings({}) defaults maxChars to 0 (no cap)", () => {
|
|
const runtime = resolveVisionBridgeRuntimeSettings({});
|
|
assert.equal(runtime.maxChars, 0);
|
|
});
|
|
|
|
test("updateSettingsSchema accepts an explicit modalityBridgeVisionMaxChars: 0 to disable the cap", async () => {
|
|
const parsed = updateSettingsSchema.safeParse({ modalityBridgeVisionMaxChars: 0 });
|
|
assert.equal(parsed.success, true, "explicit 0 must validate (disables the cap)");
|
|
|
|
const guardrail = new VisionBridgeGuardrail({
|
|
deps: {
|
|
getSettings: async () => ({
|
|
visionBridgeEnabled: true,
|
|
modalityBridgeVisionMode: "describe",
|
|
modalityBridgeVisionMaxChars: 0,
|
|
}),
|
|
callVisionModel: async (_imageDataUri: string, _config: VisionModelConfig) =>
|
|
LONG_DESCRIPTION,
|
|
},
|
|
});
|
|
|
|
const body = imageBody("maxchars-explicit-zero-test");
|
|
const context: GuardrailContext = { model: TEXT_ONLY_MODEL, log: console };
|
|
const result = await guardrail.preCall(body, context);
|
|
|
|
const text = findImageDescriptionText(result.modifiedPayload);
|
|
assert.ok(text, "expected a [Image 1]: text part in the modified payload");
|
|
const description = text!.slice("[Image 1]: ".length);
|
|
assert.equal(description, LONG_DESCRIPTION, "explicit 0 must disable truncation entirely");
|
|
assert.ok(!description.endsWith("…"), "explicit 0 must never add an ellipsis");
|
|
});
|
|
|
|
test("updateSettingsSchema rejects a value below the 100 floor that is not the explicit-0 sentinel", () => {
|
|
const parsed = updateSettingsSchema.safeParse({ modalityBridgeVisionMaxChars: 50 });
|
|
assert.equal(parsed.success, false, "50 is neither the 0 sentinel nor >= 100");
|
|
});
|