mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 20:32:20 +03:00
Both device-code providers failed at the upstream request (surfacing in the
companion extension as 'ошибка сервера OmniRoute'). Diagnosed by calling the
upstream endpoints directly:
- qwen: QWEN_CONFIG used the bare host qwen.ai, whose /api/v1/oauth2/device/code
and /token paths return 404 Not Found. The working qwen-code device flow lives
at chat.qwen.ai (verified: 200 + a valid device_code/user_code). Point both
URLs at chat.qwen.ai.
- codebuddy-cn: the Tencent state endpoint reads 'platform' from the QUERY
string, not the JSON body. Sending it only in the body returned
400 {"code":10001,"msg":"platform is empty"}. Passing ?platform=CLI
returned 200 with {code:0, data:{state, authUrl}}. Build the stateUrl with the
platform query param (body kept as-is).
Validation: live upstream calls returned 200 for both corrected requests (device
flow can't be hit from CI). Regression guard: tests/unit/oauth-device-code-endpoints.test.ts.
33 lines
2.0 KiB
TypeScript
33 lines
2.0 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { fileURLToPath } from "node:url";
|
|
import { dirname, resolve } from "node:path";
|
|
|
|
// Regression guards for the two device-code providers that returned "ошибка сервера OmniRoute":
|
|
//
|
|
// qwen — QWEN_CONFIG pointed at the bare host qwen.ai, whose device/token paths 404.
|
|
// The working qwen-code device flow lives at chat.qwen.ai (verified live: 200 +
|
|
// a valid device_code). Guard: the config uses chat.qwen.ai, never bare qwen.ai.
|
|
// codebuddy-cn— the Tencent state endpoint reads `platform` from the QUERY string, not the JSON
|
|
// body; body-only returned 400 "platform is empty" (verified live). The fix passes
|
|
// it as a query param. Guard: requestDeviceCode builds the URL with ?platform=.
|
|
//
|
|
// Source-level: the real validation is the live upstream 200 (can't be hit from CI); these pin
|
|
// the exact change so a revert to the broken host / body-only platform fails here.
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const read = (p: string) => readFileSync(resolve(here, "../..", p), "utf8");
|
|
|
|
test("qwen device-code config uses chat.qwen.ai (not the 404ing bare qwen.ai)", () => {
|
|
const oauth = read("src/lib/oauth/constants/oauth.ts");
|
|
const qwenBlock = oauth.slice(oauth.indexOf("QWEN_CONFIG"), oauth.indexOf("QWEN_CONFIG") + 700);
|
|
assert.match(qwenBlock, /chat\.qwen\.ai\/api\/v1\/oauth2\/device\/code/, "deviceCodeUrl host");
|
|
assert.match(qwenBlock, /chat\.qwen\.ai\/api\/v1\/oauth2\/token/, "tokenUrl host");
|
|
assert.doesNotMatch(qwenBlock, /"https:\/\/qwen\.ai\//, "must not use the bare qwen.ai host");
|
|
});
|
|
|
|
test("codebuddy-cn device-code sends platform as a query param (not body-only)", () => {
|
|
const cb = read("src/lib/oauth/providers/codebuddy-cn.ts");
|
|
assert.match(cb, /\?platform=\$\{encodeURIComponent\(config\.platform\)\}/, "platform query param");
|
|
});
|