Files
OmniRoute/tests/unit/base-executor-buildheaders-extra-keys-8493.test.ts
Prudhvi Vuda 5bffb57b44 fix(providers): honor Extra API Keys rotation in OpencodeExecutor (#8493)
* fix(providers): honor Extra API Keys rotation in OpencodeExecutor

OpencodeExecutor.buildHeaders bypassed resolveEffectiveKey, so extraApiKeys
never rotated and an empty primary with populated extras sent no auth header.

Closes #8467

* fix(executors): gate the Authorization header write on the resolved effective key

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
2026-07-26 03:53:18 -03:00

39 lines
1.4 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { BaseExecutor } from "../../open-sse/executors/base.ts";
/**
* Generic BaseExecutor consumer — no buildHeaders() override — representing
* every provider (xai, cliproxyapi, chipotle, mimocode, ninerouter, theoldllm,
* gitlab, ...) that relies on BaseExecutor.buildHeaders() as-is.
*
* Regression guard for #8467/#8493: resolveEffectiveKey() already rotates to
* an extra key when the primary apiKey is empty, but the header-write gate in
* buildHeaders() tested the raw `credentials.apiKey` instead of the resolved
* `effectiveKey` — so with an empty primary + populated extras, no
* Authorization header was ever written, even though a valid key existed.
*/
class GenericExecutor extends BaseExecutor {
constructor() {
super("generic-provider", {
baseUrls: ["https://default.example/v1/chat/completions"],
});
}
async transformRequest(model: string, body: unknown, stream: boolean) {
return body;
}
}
test("buildHeaders: writes Authorization from the rotated extra key when primary apiKey is empty (#8467/#8493)", () => {
const executor = new GenericExecutor();
const headers = executor.buildHeaders({
apiKey: "",
connectionId: "generic-empty-primary",
providerSpecificData: { extraApiKeys: ["sk-extra-only"] },
});
assert.equal(headers["Authorization"], "Bearer sk-extra-only");
});