Files
OmniRoute/tests/unit/codex-tools-strict-default.test.ts
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host.

Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean.

Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
2026-08-23 11:45:01 -03:00

164 lines
5.1 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { normalizeCodexTools } from "../../open-sse/executors/codex/tools.ts";
type JsonRecord = Record<string, unknown>;
function functionTool(name: string, definition: JsonRecord, extra: JsonRecord = {}): JsonRecord {
return {
type: "function",
name,
parameters: { type: "object" },
...extra,
...definition,
};
}
function nestedFunctionTool(name: string, definition: JsonRecord): JsonRecord {
return {
type: "function",
function: {
name,
parameters: { type: "object" },
...definition,
},
};
}
function strictOf(tool: JsonRecord): unknown {
return tool.strict;
}
test("default false applies to omitted nested and flat function strict", () => {
const flat = functionTool("flat_tool", {});
const nested = nestedFunctionTool("nested_tool", {});
normalizeCodexTools({ tools: [flat, nested] }, { defaultFunctionStrict: false });
assert.equal(strictOf(flat), false);
assert.equal(strictOf(nested), false);
});
test("omitted function strict stays omitted without a fallback", () => {
const flat = functionTool("flat_tool", {});
const nested = nestedFunctionTool("nested_tool", {});
normalizeCodexTools({ tools: [flat, nested] });
assert.equal(strictOf(flat), undefined);
assert.equal(strictOf(nested), undefined);
});
test("explicit top-level true and false are preserved", () => {
for (const value of [true, false]) {
const tool = functionTool("top_level_tool", { strict: value });
normalizeCodexTools({ tools: [tool] }, { defaultFunctionStrict: !value });
assert.equal(strictOf(tool), value);
}
});
test("explicit nested function true and false are preserved", () => {
for (const value of [true, false]) {
const tool = nestedFunctionTool("nested_tool", { strict: value });
normalizeCodexTools({ tools: [tool] }, { defaultFunctionStrict: !value });
assert.equal(strictOf(tool), value);
}
});
test("top-level boolean strict takes precedence over nested boolean strict", () => {
const topLevelTrue = nestedFunctionTool("top_true", { strict: false });
topLevelTrue.strict = true;
const topLevelFalse = nestedFunctionTool("top_false", { strict: true });
topLevelFalse.strict = false;
normalizeCodexTools({ tools: [topLevelTrue, topLevelFalse] }, { defaultFunctionStrict: true });
assert.equal(strictOf(topLevelTrue), true);
assert.equal(strictOf(topLevelFalse), false);
});
test("nonboolean explicit strict values fall back through the precedence chain", () => {
const topNonBoolean = nestedFunctionTool("nested_boolean", { strict: false });
topNonBoolean.strict = "true";
const bothNonBoolean = nestedFunctionTool("fallback", { strict: "false" });
bothNonBoolean.strict = 1;
normalizeCodexTools({ tools: [topNonBoolean, bothNonBoolean] }, { defaultFunctionStrict: true });
assert.equal(strictOf(topNonBoolean), false);
assert.equal(strictOf(bothNonBoolean), true);
});
test("hosted, namespace, and custom tools are unchanged by function strict defaults", () => {
const hosted = { type: "web_search", search_context_size: "high" };
const namespace = {
type: "namespace",
name: "mcp__example__",
tools: [{ type: "function", name: "search", parameters: { type: "object" } }],
};
const custom = {
type: "custom",
name: "apply_patch",
format: { type: "grammar", syntax: "lark", definition: "start: /.+/" },
};
const tools = [hosted, namespace, custom];
const before = structuredClone(tools);
normalizeCodexTools({ tools }, { defaultFunctionStrict: false, preserveCustomTools: true });
assert.deepEqual(tools, before);
});
// Since #9828 (16bf95fe33), normalizeCodexTools strips a `oneOf` that is fully
// redundant with a sibling `enum` (Codex private Responses 502 workaround); the
// rest of the production-like schema must still be preserved exactly.
test("production-like enum and oneOf schema keeps everything but the redundant oneOf", () => {
const parameters = {
type: "object",
description: "Dynamic action parameters",
properties: {
action: {
type: "string",
enum: ["read_file", "write_file", "list_files"],
oneOf: [
{
const: "write_file",
description: "Write a file",
title: "Write file",
$comment: "branch 1",
},
{
const: "read_file",
description: "Read a file",
title: "Read file",
$comment: "branch 2",
},
{
const: "list_files",
description: "List files",
title: "List files",
$comment: "branch 3",
},
],
},
},
required: ["action"],
};
const tool = {
type: "function",
function: { name: "dynamic_tool", parameters },
} as JsonRecord;
const expected = structuredClone(parameters);
// #9828: the const set exactly matches the sibling enum, so oneOf is dropped.
delete (expected.properties.action as { oneOf?: unknown }).oneOf;
normalizeCodexTools({ tools: [tool] });
assert.deepEqual(tool.parameters, expected);
});