OmniRoute/tests/unit/grok-cli-proxy-selection.test.ts
QuangBlue 2d838a9ec7
fix(grok-cli): convert Responses custom tools and Codex additional_tools Grok Build rejects (#14738)
Maintainer rework: split the new grokCliCustomTools.ts SSE rewriter and incremental input decoder into small helpers (no behavior change) so complexity / cognitive-complexity / max-lines-per-function pass in new-code mode, and reconciled with the release tip. Red->green: with the tip's grok-cli.ts executor 19/39 of the six grok-cli suites fail; with the PR all grok-cli suites pass 183/183 (exits without force-exit). typecheck:core + open-sse typecheck clean, file-size OK. Title already names the additional_tools hoist. Thank you @QuangBlue!
2026-09-29 00:03:37 -03:00

28 lines
1.3 KiB
TypeScript

// Regression test for #7244: Grok Build inference used to bypass the configured
// proxy because the legacy executor overrode execute() with raw https.request().
// The official-client implementation must stay on BaseExecutor's shared fetch
// transport, which is patched by proxyFetch and receives the active proxy context.
import test from "node:test";
import assert from "node:assert/strict";
import { BaseExecutor } from "../../open-sse/executors/base.ts";
import { GrokCliExecutor } from "../../open-sse/executors/grok-cli.ts";
test("grok-cli inherits the shared proxy-aware BaseExecutor transport", async () => {
// execute() may only pre/post-process the request tools (namespace and custom
// tools); the transport itself must stay BaseExecutor.prototype.execute.
const executor = new GrokCliExecutor();
const originalExecute = BaseExecutor.prototype.execute;
const sentinel = { response: new Response("ok") };
let calls = 0;
BaseExecutor.prototype.execute = async function () {
calls++;
return sentinel;
};
try {
const input = { model: "grok-4.6", body: { input: "hi" }, stream: true, credentials: {} };
assert.equal(await executor.execute(input), sentinel);
} finally {
BaseExecutor.prototype.execute = originalExecute;
}
assert.equal(calls, 1);
});