mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
fix(tests+providers): env-dependent tests exposed by GH-hosted runners (#6634 selfref shallow checkout + yuanbao live-network 401) (#7174)
* fix(tests): #6634 selfref test tolerates shallow checkouts (fetch origin/main on demand, skip offline) * fix(providers): yuanbao cookie validation rejects foreign pairs locally (was a hidden live-network test dependency)
This commit is contained in:
committed by
GitHub
parent
5b8d63c094
commit
2e42b8efce
1
changelog.d/fixes/yuanbao-cookie-validation.md
Normal file
1
changelog.d/fixes/yuanbao-cookie-validation.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- **Providers**: yuanbao-web no longer forwards a foreign single cookie pair upstream — `buildYuanbaoCookie` only trusts `hy_user`/`hy_token` extractions the input explicitly names, so a missing session token now fails fast with the local 401 guidance instead of a live Tencent round-trip
|
||||||
1
changelog.d/maintenance/selfref-6634-shallow.md
Normal file
1
changelog.d/maintenance/selfref-6634-shallow.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- **Tests**: the #6634 self-reference test now fetches `origin/main` on demand and skips cleanly when the ref is unreachable — it failed as a false positive on shallow/single-ref checkouts (GitHub-hosted runners)
|
||||||
@@ -106,8 +106,13 @@ function buildPrompt(messages: Array<Record<string, unknown>>): string {
|
|||||||
/** Build the `hy_source=web; hy_user=...; hy_token=...` cookie from the pasted header. */
|
/** Build the `hy_source=web; hy_user=...; hy_token=...` cookie from the pasted header. */
|
||||||
function buildYuanbaoCookie(rawApiKey: string): { cookie: string; hasToken: boolean } {
|
function buildYuanbaoCookie(rawApiKey: string): { cookie: string; hasToken: boolean } {
|
||||||
const raw = stripCookieInputPrefix(rawApiKey || "");
|
const raw = stripCookieInputPrefix(rawApiKey || "");
|
||||||
const hyUser = extractCookieValue(raw, "hy_user");
|
// Guard the extractCookieValue bare-value fallback: for input that is a single
|
||||||
const hyToken = extractCookieValue(raw, "hy_token");
|
// FOREIGN pair (e.g. "some_other=abc") the helper returns the whole string, which
|
||||||
|
// used to fool this validation into forwarding garbage upstream (the request only
|
||||||
|
// failed when Tencent replied 401 — a live-network dependency). Yuanbao needs the
|
||||||
|
// two distinct cookies, so only trust an extraction the input explicitly names.
|
||||||
|
const hyUser = raw.includes("hy_user=") ? extractCookieValue(raw, "hy_user") : null;
|
||||||
|
const hyToken = raw.includes("hy_token=") ? extractCookieValue(raw, "hy_token") : null;
|
||||||
|
|
||||||
if (hyUser && hyToken) {
|
if (hyUser && hyToken) {
|
||||||
return { cookie: `hy_source=web; hy_user=${hyUser}; hy_token=${hyToken}`, hasToken: true };
|
return { cookie: `hy_source=web; hy_user=${hyUser}; hy_token=${hyToken}`, hasToken: true };
|
||||||
|
|||||||
@@ -33,10 +33,23 @@ function git(args: string[]): string {
|
|||||||
return execFileSync("git", args, { encoding: "utf8" });
|
return execFileSync("git", args, { encoding: "utf8" });
|
||||||
}
|
}
|
||||||
|
|
||||||
test("#6634: check-test-masking.test.ts's own tautology fixtures must not self-flag as weakening", () => {
|
test("#6634: check-test-masking.test.ts's own tautology fixtures must not self-flag as weakening", (t) => {
|
||||||
// origin/main predates the #6404 fixtures (countBareTautologies/scanBareTautologies
|
// origin/main predates the #6404 fixtures (countBareTautologies/scanBareTautologies
|
||||||
// tests) that legitimately embed tautology-pattern literals as string fixtures.
|
// tests) that legitimately embed tautology-pattern literals as string fixtures.
|
||||||
const baseSrc = git(["show", "origin/main:" + FILE]);
|
// Shallow/single-ref checkouts (GitHub-hosted runners) have no origin/main —
|
||||||
|
// fetch it on demand; skip (never fail) when the ref is unreachable offline.
|
||||||
|
let baseSrc: string;
|
||||||
|
try {
|
||||||
|
baseSrc = git(["show", "origin/main:" + FILE]);
|
||||||
|
} catch {
|
||||||
|
try {
|
||||||
|
git(["fetch", "--depth=1", "origin", "main"]);
|
||||||
|
baseSrc = git(["show", "origin/main:" + FILE]);
|
||||||
|
} catch {
|
||||||
|
t.skip("origin/main unavailable (shallow checkout, offline) — nothing to compare against");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
const headSrc = git(["show", "HEAD:" + FILE]);
|
const headSrc = git(["show", "HEAD:" + FILE]);
|
||||||
|
|
||||||
const perFile = [
|
const perFile = [
|
||||||
|
|||||||
@@ -71,6 +71,13 @@ async function readStreamText(res: Response): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test("missing hy_token cookie returns a 401 auth error", async () => {
|
test("missing hy_token cookie returns a 401 auth error", async () => {
|
||||||
|
// Hermetic: the 401 must come from the executor's own cookie validation, never
|
||||||
|
// from the real upstream — on GitHub-hosted runners the Tencent endpoint is
|
||||||
|
// unreachable and a live call turns this into a 71s 502 false-negative.
|
||||||
|
const original = globalThis.fetch;
|
||||||
|
globalThis.fetch = (async () => {
|
||||||
|
throw new Error("network disabled in this test — executor must reject before fetching");
|
||||||
|
}) as typeof fetch;
|
||||||
const exec = new YuanbaoWebExecutor();
|
const exec = new YuanbaoWebExecutor();
|
||||||
const { response } = await exec.execute({
|
const { response } = await exec.execute({
|
||||||
model: "deepseek-v3",
|
model: "deepseek-v3",
|
||||||
@@ -84,6 +91,7 @@ test("missing hy_token cookie returns a 401 auth error", async () => {
|
|||||||
assert.match(body.error.message, /hy_user|hy_token|session cookie/);
|
assert.match(body.error.message, /hy_user|hy_token|session cookie/);
|
||||||
// Never leak stack traces.
|
// Never leak stack traces.
|
||||||
assert.ok(!body.error.message.includes("at /"));
|
assert.ok(!body.error.message.includes("at /"));
|
||||||
|
globalThis.fetch = original;
|
||||||
});
|
});
|
||||||
|
|
||||||
test("streaming request translates think/text events into OpenAI chunks", async () => {
|
test("streaming request translates think/text events into OpenAI chunks", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user