Files
OmniRoute/tests/unit/base-executor-sanitize-effort.test.ts
Diego Rodrigues de Sa e Souza 191009dd23 Release v3.8.7 (#2919)
* 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>
2026-05-29 19:54:00 -03:00

239 lines
8.7 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
const { sanitizeReasoningEffortForProvider } = await import("../../open-sse/executors/base.ts");
function makeLog() {
const messages: Array<[string, string]> = [];
return {
info: (tag: string, msg: string) => messages.push([tag, msg]),
messages,
};
}
test("sanitizeReasoningEffortForProvider: xiaomi-mimo downgrades xhigh → high", () => {
const log = makeLog();
const body = {
model: "mimo-v2.5-pro",
reasoning_effort: "xhigh",
messages: [{ role: "user", content: "hi" }],
};
const result = sanitizeReasoningEffortForProvider(body, "xiaomi-mimo", "mimo-v2.5-pro", log);
assert.notEqual(result, body, "must return a new object when mutating");
assert.equal((result as any).reasoning_effort, "high");
assert.equal((result as any).model, "mimo-v2.5-pro", "other fields preserved");
assert.ok(
log.messages.some(([tag, m]) => tag === "REASONING_SANITIZE" && /xhigh → high/.test(m)),
"logs the downgrade"
);
});
test("sanitizeReasoningEffortForProvider: xiaomi-mimo downgrades max → high", () => {
const log = makeLog();
const body = {
model: "mimo-v2.5-pro",
reasoning_effort: "max",
messages: [{ role: "user", content: "hi" }],
};
const result = sanitizeReasoningEffortForProvider(body, "xiaomi-mimo", "mimo-v2.5-pro", log);
assert.equal((result as any).reasoning_effort, "high");
assert.ok(
log.messages.some(([tag, m]) => tag === "REASONING_SANITIZE" && /max → high/.test(m)),
"logs the downgrade"
);
});
test("sanitizeReasoningEffortForProvider: OpenAI-compatible Gemini normalizes max → xhigh", () => {
const log = makeLog();
const body = {
model: "gemini-3.1-pro-preview",
reasoning_effort: "max",
messages: [{ role: "user", content: "hi" }],
};
const result = sanitizeReasoningEffortForProvider(
body,
"openai-compatible-free1",
"gemini-3.1-pro-preview",
log
);
assert.notEqual(result, body, "must return a new object when mutating");
assert.equal((result as any).reasoning_effort, "xhigh");
assert.ok(
log.messages.some(([tag, m]) => tag === "REASONING_SANITIZE" && /max → xhigh/.test(m)),
"logs the normalization"
);
});
test("sanitizeReasoningEffortForProvider: nested OpenAI reasoning max normalizes to xhigh", () => {
const body = {
model: "gemini-3.1-pro-preview",
reasoning: { effort: "max", summary: "auto" },
input: [],
};
const result = sanitizeReasoningEffortForProvider(
body,
"openai-compatible-free1",
"gemini-3.1-pro-preview",
null
);
assert.equal((result as any).reasoning.effort, "xhigh");
assert.equal((result as any).reasoning.summary, "auto", "other reasoning fields preserved");
assert.equal((result as any).reasoning_effort, undefined);
});
test("sanitizeReasoningEffortForProvider: claude preserves max for Opus/Sonnet and downgrades Haiku", () => {
const sonnetBody = {
model: "claude-sonnet-4-6",
reasoning_effort: "max",
messages: [{ role: "user", content: "hi" }],
};
const sonnetResult = sanitizeReasoningEffortForProvider(
sonnetBody,
"claude",
"claude-sonnet-4-6",
null
);
assert.equal(sonnetResult, sonnetBody);
assert.equal((sonnetResult as any).reasoning_effort, "max");
const opusBody = {
model: "claude-opus-4-6",
reasoning: { effort: "max", summary: "auto" },
input: [],
};
const opusResult = sanitizeReasoningEffortForProvider(
opusBody,
"anthropic-compatible-cc-test",
"claude-opus-4-6",
null
);
assert.equal(opusResult, opusBody);
assert.equal((opusResult as any).reasoning.effort, "max");
const haikuBody = {
model: "claude-haiku-4-5-20251001",
reasoning_effort: "max",
messages: [{ role: "user", content: "hi" }],
};
const haikuResult = sanitizeReasoningEffortForProvider(
haikuBody,
"claude",
"claude-haiku-4-5-20251001",
null
);
assert.notEqual(haikuResult, haikuBody);
assert.equal((haikuResult as any).reasoning_effort, "high");
});
test("sanitizeReasoningEffortForProvider: xiaomi-mimo downgrades xhigh in nested reasoning.effort", () => {
const body = {
model: "mimo-v2.5-pro",
reasoning: { effort: "xhigh", summary: "auto" },
messages: [],
};
const result = sanitizeReasoningEffortForProvider(body, "xiaomi-mimo", "mimo-v2.5-pro", null);
assert.equal((result as any).reasoning.effort, "high");
assert.equal((result as any).reasoning.summary, "auto", "other reasoning fields preserved");
});
test("sanitizeReasoningEffortForProvider: nested reasoning downgrade preserves Responses shape", () => {
const body = {
model: "responses-only-model",
reasoning: { effort: "xhigh", summary: "auto" },
input: [],
};
const result = sanitizeReasoningEffortForProvider(
body,
"xiaomi-mimo",
"responses-only-model",
null
);
assert.equal((result as any).reasoning.effort, "high");
assert.equal((result as any).reasoning_effort, undefined);
});
test("sanitizeReasoningEffortForProvider: mistral/devstral strips reasoning_effort entirely", () => {
const log = makeLog();
const body = {
model: "devstral-2512",
reasoning_effort: "medium",
messages: [],
};
const result = sanitizeReasoningEffortForProvider(body, "mistral", "devstral-2512", log);
assert.equal((result as any).reasoning_effort, undefined, "reasoning_effort must be stripped");
assert.ok(
log.messages.some(([tag, m]) => tag === "REASONING_SANITIZE" && /removed/.test(m)),
"logs the removal"
);
});
test("sanitizeReasoningEffortForProvider: github/claude-opus strips reasoning_effort entirely", () => {
const body = {
model: "claude-opus-4-6",
reasoning_effort: "high",
messages: [],
};
const result = sanitizeReasoningEffortForProvider(body, "github", "claude-opus-4-6", null);
assert.equal((result as any).reasoning_effort, undefined);
});
test("sanitizeReasoningEffortForProvider: mistral/devstral strips reasoning object when only effort present", () => {
const body = {
model: "devstral-2512",
reasoning: { effort: "medium" },
messages: [],
};
const result = sanitizeReasoningEffortForProvider(body, "mistral", "devstral-2512", null);
assert.equal((result as any).reasoning, undefined, "reasoning object dropped when emptied");
});
test("sanitizeReasoningEffortForProvider: mistral/devstral preserves reasoning when other fields remain", () => {
const body = {
model: "devstral-2512",
reasoning: { effort: "medium", summary: "auto" },
messages: [],
};
const result = sanitizeReasoningEffortForProvider(body, "mistral", "devstral-2512", null);
assert.deepEqual((result as any).reasoning, { summary: "auto" });
});
test("sanitizeReasoningEffortForProvider: codex with xhigh passes through unchanged when model supports it", () => {
// codex/gpt-5.5-xhigh is flagged supportsXHighEffort:true in providerRegistry.
// Claude Opus 4.7+ models default to xhigh support unless explicitly opted out.
const body = {
model: "gpt-5.5-xhigh",
reasoning_effort: "xhigh",
messages: [],
};
const result = sanitizeReasoningEffortForProvider(body, "codex", "gpt-5.5-xhigh", null);
// Either passes through unchanged (supportsXHighEffort=true)
// or the registry doesn't flag it — in which case downgrade is acceptable.
// We assert no error and that some reasoning_effort is present.
assert.ok(
(result as any).reasoning_effort === "xhigh" || (result as any).reasoning_effort === "high",
"either preserved (xhigh) or downgraded (high)"
);
});
test("sanitizeReasoningEffortForProvider: no-op when reasoning_effort absent", () => {
const body = { model: "mimo-v2.5-pro", messages: [] };
const result = sanitizeReasoningEffortForProvider(body, "xiaomi-mimo", "mimo-v2.5-pro", null);
assert.equal(result, body, "returns original body unchanged");
});
test("sanitizeReasoningEffortForProvider: handles unknown providers as pass-through", () => {
const body = { model: "some-model", reasoning_effort: "xhigh", messages: [] };
const result = sanitizeReasoningEffortForProvider(body, "unknown-provider", "some-model", null);
// unknown provider + xhigh + model not in registry → supportsXHighEffort returns false → downgrade
// OR unknown provider isn't in the strip list → returns xhigh
// Both are acceptable behavior; we just assert no exception thrown.
assert.ok(result !== undefined);
});
test("sanitizeReasoningEffortForProvider: non-object body returns unchanged", () => {
assert.equal(sanitizeReasoningEffortForProvider(null, "xiaomi-mimo", "x", null), null);
assert.equal(sanitizeReasoningEffortForProvider("string", "xiaomi-mimo", "x", null), "string");
const arr: unknown[] = [];
assert.equal(sanitizeReasoningEffortForProvider(arr, "xiaomi-mimo", "x", null), arr);
});