mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-12 18:22:48 +03:00
* feat(alibaba): add free-tier routing with console quota and builtin allowlist Classify DashScope free vs paid models via console quota API, a hardcoded operator allowlist fallback, and per-connection drained tracking. Wire wildcard combo expansion, model refresh, combo exhaustion, and audit redaction for Alibaba console credentials. * fix(routing): reset forced connection pin and persist Alibaba free-tier drain Drop session affinity pins when a forced connection is excluded after 429, and record Alibaba free-tier exhaustion on upstream 403 so per-key drained lists stay accurate without blocking sibling keys. * fix(alibaba): prefer live quota sync over static free-tier allowlist Stop unioning the builtin text allowlist when a console quota snapshot exists, treat expired quotaValidityPeriod as not_capable, and add a dated JSON pack plus sync-alibaba-allowlist script for operator refresh without code edits. * docs(alibaba): document free-tier console path + allowlist env overrides Adds the 4 ALIBABA_FREE_TIER_*_FE_PATH / ALIBABA_FREE_TIER_ALLOWLIST_PATH env vars (referenced by alibabaFreeTierQuotaFetcher.ts and alibabaFreeTierAllowlist.ts) to .env.example and docs/reference/ENVIRONMENT.md so the env/docs contract check passes. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * refactor(open-sse): split alibabaFreeTierQuotaFetcher.ts under file-size cap Extract pure parsing/classification/eligibility-filtering logic into alibabaFreeTierQuotaClassify.ts and shared types/primitives into alibabaFreeTierQuotaTypes.ts, leaving the HTTP/console-fetch flow in the original file. Public API is unchanged (re-exported), behavior is identical. Co-authored-by: AndrianBalanescu <AndrianBalanescu@users.noreply.github.com> * fix: resolve typecheck errors in alibaba-free-tier routing --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com> Co-authored-by: AndrianBalanescu <AndrianBalanescu@users.noreply.github.com> Co-authored-by: AndrianBalanescu <andrian@balanescu.dev>
87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { resolveForcedConnectionForCredentialPool } from "../../src/sse/services/sessionAffinityPin.ts";
|
|
|
|
const conn = (id: string, rateLimitedUntil: string | null = null) => ({
|
|
id,
|
|
rateLimitedUntil,
|
|
});
|
|
|
|
test("resolveForcedConnectionForCredentialPool drops forced id when excluded after 429 fallback", () => {
|
|
const excluded = new Set(["dead-account"]);
|
|
assert.equal(
|
|
resolveForcedConnectionForCredentialPool({
|
|
forcedConnectionId: "dead-account",
|
|
excludedConnectionIds: excluded,
|
|
connections: [conn("dead-account"), conn("healthy-account")],
|
|
allowRateLimitedConnections: false,
|
|
bypassQuotaPolicy: false,
|
|
isQuotaExhausted: () => false,
|
|
isQuotaPolicyBlocked: () => false,
|
|
}),
|
|
null
|
|
);
|
|
});
|
|
|
|
test("resolveForcedConnectionForCredentialPool keeps forced id when eligible", () => {
|
|
assert.equal(
|
|
resolveForcedConnectionForCredentialPool({
|
|
forcedConnectionId: "healthy-account",
|
|
excludedConnectionIds: new Set(),
|
|
connections: [conn("healthy-account"), conn("other-account")],
|
|
allowRateLimitedConnections: false,
|
|
bypassQuotaPolicy: false,
|
|
isQuotaExhausted: () => false,
|
|
isQuotaPolicyBlocked: () => false,
|
|
}),
|
|
"healthy-account"
|
|
);
|
|
});
|
|
|
|
test("resolveForcedConnectionForCredentialPool drops forced id on cooldown", () => {
|
|
const future = new Date(Date.now() + 60_000).toISOString();
|
|
assert.equal(
|
|
resolveForcedConnectionForCredentialPool({
|
|
forcedConnectionId: "cooling-account",
|
|
excludedConnectionIds: new Set(),
|
|
connections: [conn("cooling-account", future)],
|
|
allowRateLimitedConnections: false,
|
|
bypassQuotaPolicy: false,
|
|
isQuotaExhausted: () => false,
|
|
isQuotaPolicyBlocked: () => false,
|
|
}),
|
|
null
|
|
);
|
|
});
|
|
|
|
test("resolveForcedConnectionForCredentialPool drops forced id when quota exhausted", () => {
|
|
assert.equal(
|
|
resolveForcedConnectionForCredentialPool({
|
|
forcedConnectionId: "exhausted-account",
|
|
excludedConnectionIds: new Set(),
|
|
connections: [conn("exhausted-account")],
|
|
allowRateLimitedConnections: false,
|
|
bypassQuotaPolicy: false,
|
|
isQuotaExhausted: (id) => id === "exhausted-account",
|
|
isQuotaPolicyBlocked: () => false,
|
|
}),
|
|
null
|
|
);
|
|
});
|
|
|
|
test("resolveForcedConnectionForCredentialPool with empty connections only checks exclusion", () => {
|
|
assert.equal(
|
|
resolveForcedConnectionForCredentialPool({
|
|
forcedConnectionId: "pinned-account",
|
|
excludedConnectionIds: new Set(),
|
|
connections: [],
|
|
allowRateLimitedConnections: false,
|
|
bypassQuotaPolicy: false,
|
|
isQuotaExhausted: () => true,
|
|
isQuotaPolicyBlocked: () => true,
|
|
}),
|
|
"pinned-account"
|
|
);
|
|
});
|