Files
OmniRoute/tests/unit/cline-workos-auth-token-shape.test.ts
backryun 2d1801985c feat(cline): align ClinePass catalog and request protocol (#7914)
* feat(cline): align catalogs and official protocol

* fix(models): clean imports after final connection removal

* fix(quality): extract Cline/ClinePass auth-header wiring to shrink default.ts

open-sse/executors/default.ts grew to 894 lines against the frozen
890-line cap after adding the ClinePass official-protocol import plus
two Object.assign header-merge blocks. Extract the merge logic into a
new applyClineAuthHeaders() helper in src/shared/utils/clineAuth.ts so
the executor's case "clinepass" / case "cline" branches shrink to a
single call each, dropping default.ts back to 875 lines.

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

---------

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
2026-07-21 12:19:01 -03:00

113 lines
4.5 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import {
applyClineProtocolHeaders,
buildClineHeaders,
buildClinepassHeaders,
getClineAccessToken,
getClineAuthorizationHeader,
} 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" });
assert.equal(headers.Accept, "application/json");
assert.ok(!("Authorization" in headers));
// Client-identification headers are still present even without a token.
assert.equal(headers["X-CLIENT-TYPE"], "omniroute");
});
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");
});