mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-16 17:09:09 +00:00
Correções já validadas no board. Este squash entra com o crédito de @mdc2122 (fix(cursor): live-discover cursor-api models and stop reporting unknown models as missing). O board único passou changelog, typecheck:core, complexity e cognitive. Os 5 testes de guide-settings que falham com HTTP 422 também falham no tip: o guard de escrita recusa o alvo fora de um mount quando `/.dockerenv` existe. Não é regressão deste PR. O rebaseline de file-size dos arquivos que cresceram fica num follow-up, depois destes squashes. ⚠️ base-red inherited: #15306 Obrigado, @mdc2122.
87 lines
3.5 KiB
TypeScript
87 lines
3.5 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
classifyCursorError,
|
|
classifyCursorErrorKind,
|
|
isCursorBenignCancelError,
|
|
isCursorRequestTooLargeDetail,
|
|
resolveCursorEmptyTurnError,
|
|
CURSOR_EMPTY_TURN_MESSAGE,
|
|
} from "../../open-sse/executors/cursor/cursorErrors.ts";
|
|
|
|
test("classifyCursorErrorKind: resource_exhausted without size cue is rate_limit", () => {
|
|
assert.equal(classifyCursorErrorKind("resource_exhausted: quota exhausted"), "rate_limit");
|
|
assert.equal(classifyCursorErrorKind("You're out of usage. Increase limits"), "rate_limit");
|
|
});
|
|
|
|
test("classifyCursorErrorKind: resource_exhausted + size cue is invalid", () => {
|
|
assert.equal(classifyCursorErrorKind("resource_exhausted: tool catalog too large"), "invalid");
|
|
assert.equal(isCursorRequestTooLargeDetail("tool catalog too large"), true);
|
|
assert.equal(
|
|
isCursorRequestTooLargeDetail("resource_exhausted while loading tool catalog: quota exhausted"),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("classifyCursorErrorKind: auth cues", () => {
|
|
assert.equal(classifyCursorErrorKind("Authentication error"), "auth");
|
|
assert.equal(classifyCursorErrorKind("unauthenticated"), "auth");
|
|
});
|
|
|
|
test("classifyCursorErrorKind: AI Model Not Found is rate_limit only with a reset hint", () => {
|
|
assert.equal(
|
|
classifyCursorErrorKind("not_found: AI Model Not Found (reset after 109h 9s)"),
|
|
"rate_limit"
|
|
);
|
|
assert.equal(classifyCursorErrorKind("not_found: AI Model Not Found"), "not_found");
|
|
assert.equal(classifyCursorErrorKind("model not found"), "not_found");
|
|
});
|
|
|
|
test("classifyCursorError: an unknown Cursor model is a 404 invalid request, not a rate limit", () => {
|
|
const out = classifyCursorError("not_found: AI Model Not Found");
|
|
assert.equal(out.status, 404);
|
|
assert.equal(out.type, "invalid_request_error");
|
|
assert.match(out.message, /^Cursor model not found: /);
|
|
assert.doesNotMatch(out.message, /rate limit/i);
|
|
});
|
|
|
|
test("classifyCursorError redacts credentials and paths", () => {
|
|
const out = classifyCursorError(
|
|
"Authentication failed authorization=secret-token path=/Users/alice/code/file"
|
|
);
|
|
assert.equal(out.kind, "auth");
|
|
assert.equal(out.status, 401);
|
|
assert.match(out.message, /\[REDACTED\]/);
|
|
assert.match(out.message, /\[REDACTED_PATH\]/);
|
|
assert.doesNotMatch(out.message, /secret-token/);
|
|
assert.doesNotMatch(out.message, /\/Users\/alice/);
|
|
});
|
|
|
|
test("isCursorBenignCancelError recognizes NGHTTP2_CANCEL / suspend", () => {
|
|
assert.equal(isCursorBenignCancelError({ code: "NGHTTP2_CANCEL" }), true);
|
|
assert.equal(isCursorBenignCancelError(new Error("nghttp2_cancel")), true);
|
|
assert.equal(isCursorBenignCancelError(new Error("Cursor stream suspended")), true);
|
|
assert.equal(isCursorBenignCancelError(new Error("resource_exhausted")), false);
|
|
});
|
|
|
|
test("resolveCursorEmptyTurnError: no upstream → actionable 502", () => {
|
|
const out = resolveCursorEmptyTurnError({});
|
|
assert.equal(out.status, 502);
|
|
assert.equal(out.message, CURSOR_EMPTY_TURN_MESSAGE);
|
|
});
|
|
|
|
test("resolveCursorEmptyTurnError: quotaExhaustedHint → 429", () => {
|
|
const out = resolveCursorEmptyTurnError({ quotaExhaustedHint: true });
|
|
assert.equal(out.status, 429);
|
|
assert.equal(out.type, "rate_limit_error");
|
|
assert.equal(out.message, CURSOR_EMPTY_TURN_MESSAGE);
|
|
});
|
|
|
|
test("resolveCursorEmptyTurnError: classifies upstream quota message as 429", () => {
|
|
const out = resolveCursorEmptyTurnError({
|
|
upstreamMessage: "resource_exhausted: too many requests",
|
|
});
|
|
assert.equal(out.status, 429);
|
|
assert.equal(out.kind, "rate_limit");
|
|
});
|