Files
OmniRoute/tests/unit/cline-workos-auth-token-shape.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

141 lines
5.7 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import {
applyClineProtocolHeaders,
buildClineHeaders,
buildClinepassHeaders,
getClineAccessToken,
getClineAuthorizationHeader,
resolveClineTaskId,
} from "../../src/shared/utils/clineAuth.ts";
import { buildProviderHeaders } from "../../open-sse/services/provider.ts";
import { DefaultExecutor } from "../../open-sse/executors/default.ts";
test("getClineAccessToken prefixes the token with workos:", () => {
assert.equal(getClineAccessToken("abc123"), "workos:abc123");
});
test("getClineAccessToken is idempotent when already prefixed", () => {
assert.equal(getClineAccessToken("workos:abc123"), "workos:abc123");
});
test("getClineAccessToken trims and rejects empty / non-string input", () => {
assert.equal(getClineAccessToken(" abc123 "), "workos:abc123");
assert.equal(getClineAccessToken(" "), "");
assert.equal(getClineAccessToken(""), "");
assert.equal(getClineAccessToken(undefined), "");
assert.equal(getClineAccessToken(null), "");
assert.equal(getClineAccessToken(42), "");
});
test("getClineAuthorizationHeader builds a workos-prefixed bearer header", () => {
assert.equal(getClineAuthorizationHeader("abc123"), "Bearer workos:abc123");
assert.equal(getClineAuthorizationHeader(""), "");
});
test("buildClineHeaders emits the full cline client header set", () => {
const headers = buildClineHeaders("abc123", {}, { taskId: "task-123" });
assert.equal(headers.Authorization, "Bearer workos:abc123");
assert.equal(headers["HTTP-Referer"], "https://cline.bot");
assert.equal(headers["X-Title"], "Cline");
assert.equal(headers["X-CLIENT-TYPE"], "omniroute");
assert.equal(headers["X-Task-ID"], "task-123");
assert.equal(headers["X-IS-MULTIROOT"], "false");
assert.ok(/^Cline\//.test(headers["User-Agent"]));
assert.ok(!/9router/i.test(JSON.stringify(headers)));
});
test("buildClineHeaders merges extra headers and omits Authorization with no token", () => {
const headers = buildClineHeaders("", {
Accept: "application/json",
"x-task-id": "configured-task-must-not-leak",
});
assert.equal(headers.Accept, "application/json");
assert.ok(!("Authorization" in headers));
assert.ok(!("X-Task-ID" in headers));
assert.ok(!("x-task-id" in headers));
// Client-identification headers are still present even without a token.
assert.equal(headers["X-CLIENT-TYPE"], "omniroute");
});
test("resolveClineTaskId forwards client task identity but does not invent one", () => {
assert.equal(resolveClineTaskId({ "x-task-id": "client-task-123" }), "client-task-123");
assert.equal(resolveClineTaskId({}), undefined);
assert.equal(resolveClineTaskId(null), undefined);
});
test("required Cline protocol headers override conflicting configured casing", () => {
const headers = applyClineProtocolHeaders(
{
"user-agent": "other-client/1",
"x-client-type": "other-client",
"x-task-id": "stored-task",
},
{ clientVersion: "3.8.49", taskId: "request-task" }
);
assert.equal(headers["User-Agent"], "Cline/3.8.49");
assert.equal(headers["X-CLIENT-TYPE"], "omniroute");
assert.equal(headers["X-Task-ID"], "request-task");
assert.ok(!("user-agent" in headers));
assert.ok(!("x-client-type" in headers));
assert.ok(!("x-task-id" in headers));
});
test("ClinePass BYOK and OAuth auth modes both carry the full protocol headers", () => {
const byok = buildClinepassHeaders({ apiKey: "sk-pass" }, undefined, {
taskId: "task-byok",
});
assert.equal(byok.Authorization, "Bearer sk-pass");
assert.equal(byok["X-Task-ID"], "task-byok");
assert.equal(byok["X-CLIENT-TYPE"], "omniroute");
const oauth = buildClinepassHeaders({ accessToken: "oauth-token" }, undefined, {
taskId: "task-oauth",
});
assert.equal(oauth.Authorization, "Bearer workos:oauth-token");
assert.equal(oauth["X-Task-ID"], "task-oauth");
assert.equal(oauth["X-CLIENT-TYPE"], "omniroute");
});
test("buildProviderHeaders uses the cline workos auth token shape", () => {
const headers = buildProviderHeaders("cline", { apiKey: "tok-abc" }, true);
assert.equal(headers.Authorization, "Bearer workos:tok-abc");
assert.equal(headers["HTTP-Referer"], "https://cline.bot");
assert.equal(headers["X-CLIENT-TYPE"], "omniroute");
});
test("buildProviderHeaders honors an accessToken for cline", () => {
const headers = buildProviderHeaders("cline", { accessToken: "acc-xyz" }, false);
assert.equal(headers.Authorization, "Bearer workos:acc-xyz");
});
test("DefaultExecutor.buildHeaders uses the cline workos auth token shape", () => {
const executor = new DefaultExecutor("cline");
const headers = executor.buildHeaders({ apiKey: "tok-abc" }, true, {
"X-Task-ID": "task-from-client",
});
assert.equal(headers.Authorization, "Bearer workos:tok-abc");
assert.equal(headers["HTTP-Referer"], "https://cline.bot");
assert.equal(headers["X-CLIENT-TYPE"], "omniroute");
assert.equal(headers["X-Title"], "Cline");
assert.equal(headers["X-Task-ID"], "task-from-client");
const withoutTaskId = executor.buildHeaders({ apiKey: "tok-abc" }, true, {});
assert.ok(!("X-Task-ID" in withoutTaskId));
});
test("DefaultExecutor labels internal health checks separately from user traffic", () => {
const executor = new DefaultExecutor("cline");
const headers = executor.buildHeaders({ apiKey: "tok-abc" }, true, {
"X-Internal-Test": "combo-health-check",
});
assert.equal(headers["X-CLIENT-TYPE"], "omniroute-internal-health-check");
// BaseExecutor reapplies the required protocol headers immediately before dispatch.
applyClineProtocolHeaders(headers, { taskId: headers["X-Task-ID"] });
assert.equal(headers["X-CLIENT-TYPE"], "omniroute-internal-health-check");
});