mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-16 20:02:45 +03:00
Behind the new `OPENCODE_USER_BLOCKED_ROTATION` flag (default off), a 403 or 451 carrying `user_blocked` on a proxied opencode account rotates at most once to the next account instead of being returned as-is.
Maintainer rework before merge (kept the idea, no default behavior change):
- 403 and 451 are handled by one predicate (the original returned 451 without rotation), the refused account gets a cooldown and joins the tried-set, and the response body of the attempt rotated away from is cancelled.
Validated first on the combined board of all 38 PRs of this batch (10 merged as-is, 28 after the maintainer rework) on top of release/v3.8.51 c0f92ec: typecheck:core, check:open-sse-typecheck and check:dashboard-typecheck clean; ESLint clean on every changed file; file-size (rebaselined for the combined growth), complexity, cognitive-complexity, changelog-integrity, docs-counts, docs-sync, migration-numbering and i18n new-key gates green; 735 focused node:test cases with the only batch-caused failure (a flag-count assertion) fixed. Then re-validated alone on the fresh release tip right before this merge: ESLint on the changed files, typecheck:core, check:open-sse-typecheck, the file-size/complexity/changelog gates and this PR's own tests.
Thanks @maxmad64bis!
68 lines
2.8 KiB
TypeScript
68 lines
2.8 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert";
|
|
import { isOpencodeUserBlocked } from "../../open-sse/executors/opencodeGeoBlock.ts";
|
|
|
|
const BLOCKED_BODY = JSON.stringify({
|
|
error: {
|
|
type: "server_error",
|
|
message:
|
|
"Error from provider (Console): Upstream request failed: [user_blocked] egress refused.",
|
|
},
|
|
});
|
|
const AUTH_BODY = JSON.stringify({ error: { message: "invalid api key", type: "auth_error" } });
|
|
|
|
describe("isOpencodeUserBlocked", () => {
|
|
it("matches 403 + user_blocked signal", () => {
|
|
assert.strictEqual(isOpencodeUserBlocked(403, BLOCKED_BODY), true);
|
|
});
|
|
it("matches regardless of case", () => {
|
|
assert.strictEqual(isOpencodeUserBlocked(403, "[USER_BLOCKED] restricted"), true);
|
|
});
|
|
it("classifies 451 exactly like 403 (one predicate, no status special case)", () => {
|
|
assert.strictEqual(isOpencodeUserBlocked(451, BLOCKED_BODY), true);
|
|
assert.strictEqual(isOpencodeUserBlocked(451, AUTH_BODY), false);
|
|
});
|
|
it("leaves a geo-blocked body to the geo predicate even with the token present", () => {
|
|
const geo = JSON.stringify({
|
|
error: { type: "RegionError", message: "not available in your country [user_blocked]" },
|
|
});
|
|
assert.strictEqual(isOpencodeUserBlocked(403, geo), false);
|
|
assert.strictEqual(isOpencodeUserBlocked(451, geo), false);
|
|
});
|
|
it("rejects fingerprint 1010 even with the signal present", () => {
|
|
assert.strictEqual(
|
|
isOpencodeUserBlocked(403, `{"error_code":1010,"message":"[user_blocked] restricted"}`),
|
|
false,
|
|
"keyed 1010 = fingerprint, never rotation"
|
|
);
|
|
assert.strictEqual(
|
|
isOpencodeUserBlocked(403, "retry after 1010 seconds, [user_blocked] restricted"),
|
|
true,
|
|
"bare 1010 is not a fingerprint token; signal still matches"
|
|
);
|
|
});
|
|
it("rejects fingerprint tokens even with the signal present", () => {
|
|
assert.strictEqual(
|
|
isOpencodeUserBlocked(403, "[user_blocked] browser_signature_banned"),
|
|
false
|
|
);
|
|
assert.strictEqual(isOpencodeUserBlocked(403, "[user_blocked] fingerprint_rejection"), false);
|
|
});
|
|
it("rejects 403 without the signal", () => {
|
|
assert.strictEqual(isOpencodeUserBlocked(403, AUTH_BODY), false);
|
|
});
|
|
it("rejects non-403 statuses at the rotation predicate", () => {
|
|
for (const status of [200, 400, 401, 429, 500]) {
|
|
assert.strictEqual(isOpencodeUserBlocked(status, BLOCKED_BODY), false);
|
|
}
|
|
});
|
|
it("rejects separator variants without the exact token", () => {
|
|
assert.strictEqual(isOpencodeUserBlocked(403, "user-blocked restricted"), false);
|
|
assert.strictEqual(isOpencodeUserBlocked(403, "user blocked restricted"), false);
|
|
});
|
|
it("rejects empty and null bodies", () => {
|
|
assert.strictEqual(isOpencodeUserBlocked(403, ""), false);
|
|
assert.strictEqual(isOpencodeUserBlocked(403, null), false);
|
|
});
|
|
});
|