Files
OmniRoute/tests/unit/provider-header-profiles.test.ts
backryun 65e0aeda79 [Part 1/3]refactor(qwen): replace legacy Qwen Code and remove OAuth provider (#7866)
* refactor(cli): remove legacy Qwen Code integration

* refactor(qwen): remove deprecated Qwen OAuth provider

* feat(cli): rebuild Qwen Code integration for upstream V4

* fix(qwen): clear stale CLI auth on reset

* test(qwen): align retired provider coverage

* fix(db): renumber qwen-cleanup migration 129 -> 130

release/v3.8.49 tip took slot 129 via #7843 (usage_history_codex_strong_identity,
itself renumbered from 128 during the #7838/#7840 base-red cleanup) after this
branch forked; renumber remove_unregistered_qwen_data to 130.

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

---------

Co-authored-by: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com>
2026-07-20 17:53:04 -03:00

79 lines
3.7 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import {
GITHUB_COPILOT_API_VERSION,
GITHUB_COPILOT_CHAT_PLUGIN_VERSION,
GITHUB_COPILOT_CHAT_USER_AGENT,
GITHUB_COPILOT_EDITOR_VERSION,
GITHUB_COPILOT_REFRESH_PLUGIN_VERSION,
GITHUB_COPILOT_REFRESH_USER_AGENT,
KIRO_AMZ_USER_AGENT,
KIRO_SDK_USER_AGENT,
QWEN_CLI_VERSION,
getQwenCliUserAgent,
getGitHubCopilotChatHeaders,
getGitHubCopilotInternalUserHeaders,
getGitHubCopilotRefreshHeaders,
getKiroServiceHeaders,
getQoderDashscopeCompatHeaders,
} from "../../open-sse/config/providerHeaderProfiles.ts";
test("provider header profiles expose current GitHub chat and internal headers", () => {
const chatHeaders = getGitHubCopilotChatHeaders("text/event-stream", "agent");
assert.equal(chatHeaders["editor-version"], GITHUB_COPILOT_EDITOR_VERSION);
assert.equal(chatHeaders["editor-plugin-version"], GITHUB_COPILOT_CHAT_PLUGIN_VERSION);
assert.equal(chatHeaders["user-agent"], GITHUB_COPILOT_CHAT_USER_AGENT);
assert.equal(chatHeaders["x-github-api-version"], GITHUB_COPILOT_API_VERSION);
assert.equal(chatHeaders["X-Initiator"], "agent");
assert.equal(chatHeaders.Accept, "text/event-stream");
const internalHeaders = getGitHubCopilotInternalUserHeaders("token gh-access");
assert.equal(internalHeaders.Authorization, "token gh-access");
assert.equal(internalHeaders["User-Agent"], GITHUB_COPILOT_CHAT_USER_AGENT);
assert.equal(internalHeaders["Editor-Version"], GITHUB_COPILOT_EDITOR_VERSION);
assert.equal(internalHeaders["Editor-Plugin-Version"], GITHUB_COPILOT_CHAT_PLUGIN_VERSION);
assert.equal(internalHeaders["X-GitHub-Api-Version"], GITHUB_COPILOT_API_VERSION);
});
test("provider header profiles expose dedicated refresh, qoder and kiro variants", () => {
const refreshHeaders = getGitHubCopilotRefreshHeaders("token gh-access");
assert.equal(refreshHeaders.Authorization, "token gh-access");
assert.equal(refreshHeaders["User-Agent"], GITHUB_COPILOT_REFRESH_USER_AGENT);
assert.equal(refreshHeaders["Editor-Version"], GITHUB_COPILOT_EDITOR_VERSION);
assert.equal(refreshHeaders["Editor-Plugin-Version"], GITHUB_COPILOT_REFRESH_PLUGIN_VERSION);
const qoderHeaders = getQoderDashscopeCompatHeaders();
assert.equal(qoderHeaders["user-agent"], getQwenCliUserAgent());
assert.equal(qoderHeaders["x-dashscope-useragent"], getQwenCliUserAgent());
assert.equal(
qoderHeaders["user-agent"],
`QwenCode/${QWEN_CLI_VERSION} (${process.platform}; ${process.arch})`
);
const kiroHeaders = getKiroServiceHeaders("application/json");
assert.equal(kiroHeaders.Accept, "application/json");
assert.equal(kiroHeaders["User-Agent"], KIRO_SDK_USER_AGENT);
assert.equal(kiroHeaders["X-Amz-User-Agent"], KIRO_AMZ_USER_AGENT);
});
test("provider header profiles tolerate browser-like process shims", async () => {
const originalPlatform = process.platform;
const originalArch = process.arch;
const originalVersion = process.version;
Object.defineProperty(process, "platform", { value: undefined, configurable: true });
Object.defineProperty(process, "arch", { value: undefined, configurable: true });
Object.defineProperty(process, "version", { value: undefined, configurable: true });
try {
assert.equal(getQwenCliUserAgent(), `QwenCode/${QWEN_CLI_VERSION} (unknown; unknown)`);
const qoderHeaders = getQoderDashscopeCompatHeaders();
assert.equal(qoderHeaders["user-agent"], `QwenCode/${QWEN_CLI_VERSION} (unknown; unknown)`);
} finally {
Object.defineProperty(process, "platform", { value: originalPlatform, configurable: true });
Object.defineProperty(process, "arch", { value: originalArch, configurable: true });
Object.defineProperty(process, "version", { value: originalVersion, configurable: true });
}
});