mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +03:00
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host. Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean. Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
110 lines
3.6 KiB
TypeScript
110 lines
3.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { resolveCursorAgentUrl } from "../../open-sse/executors/cursor/agentEndpoint.ts";
|
|
import { encodeMessage, encodeString } from "../../open-sse/utils/cursorAgentProtobuf/wire.ts";
|
|
|
|
function serverConfig(agentUrl: string, agentnUrl: string): Buffer {
|
|
return encodeMessage(27, [encodeString(1, agentUrl), encodeString(2, agentnUrl)]);
|
|
}
|
|
|
|
test("Cursor Agent uses each connection's server-assigned endpoint", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
const requestedTokens: string[] = [];
|
|
globalThis.fetch = async (input, init) => {
|
|
assert.equal(
|
|
String(input),
|
|
"https://api2.cursor.sh/aiserver.v1.ServerConfigService/GetServerConfig"
|
|
);
|
|
const token = new Headers(init?.headers).get("authorization") ?? "";
|
|
requestedTokens.push(token);
|
|
const region = token === "Bearer token-us" ? "us" : "eu";
|
|
return new Response(
|
|
serverConfig(
|
|
`https://agent.${region}.api5.cursor.sh`,
|
|
`https://agentn.${region}.api5.cursor.sh`
|
|
),
|
|
{ status: 200, headers: { "Content-Type": "application/proto" } }
|
|
);
|
|
};
|
|
|
|
try {
|
|
const usCredentials = {
|
|
accessToken: "token-us",
|
|
connectionId: "connection-us",
|
|
providerSpecificData: { ghostMode: false },
|
|
};
|
|
assert.equal(
|
|
await resolveCursorAgentUrl(usCredentials),
|
|
"https://agentn.us.api5.cursor.sh/agent.v1.AgentService/Run"
|
|
);
|
|
assert.equal(
|
|
await resolveCursorAgentUrl(usCredentials),
|
|
await resolveCursorAgentUrl(usCredentials)
|
|
);
|
|
assert.equal(
|
|
await resolveCursorAgentUrl({
|
|
accessToken: "token-eu",
|
|
connectionId: "connection-eu",
|
|
providerSpecificData: { ghostMode: true },
|
|
}),
|
|
"https://agent.eu.api5.cursor.sh/agent.v1.AgentService/Run"
|
|
);
|
|
assert.deepEqual(requestedTokens, ["Bearer token-us", "Bearer token-eu"]);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|
|
|
|
test("Cursor Agent uses the token with the connection cache key", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
const requestedTokens: string[] = [];
|
|
globalThis.fetch = async (_input, init) => {
|
|
const token = new Headers(init?.headers).get("authorization") ?? "";
|
|
requestedTokens.push(token);
|
|
const region = token.endsWith("new") ? "new" : "old";
|
|
return new Response(
|
|
serverConfig(
|
|
`https://agent.${region}.api5.cursor.sh`,
|
|
`https://agentn.${region}.api5.cursor.sh`
|
|
),
|
|
{ status: 200, headers: { "Content-Type": "application/proto" } }
|
|
);
|
|
};
|
|
|
|
try {
|
|
assert.equal(
|
|
await resolveCursorAgentUrl({ accessToken: "token-old", connectionId: "connection-rotate" }),
|
|
"https://agent.old.api5.cursor.sh/agent.v1.AgentService/Run"
|
|
);
|
|
assert.equal(
|
|
await resolveCursorAgentUrl({ accessToken: "token-new", connectionId: "connection-rotate" }),
|
|
"https://agent.new.api5.cursor.sh/agent.v1.AgentService/Run"
|
|
);
|
|
assert.deepEqual(requestedTokens, ["Bearer token-old", "Bearer token-new"]);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|
|
|
|
test("Cursor Agent rejects an endpoint outside Cursor's API domain", async () => {
|
|
const originalFetch = globalThis.fetch;
|
|
globalThis.fetch = async () =>
|
|
new Response(
|
|
serverConfig("https://attacker.example/agent", "https://attacker.example/agentn"),
|
|
{ status: 200, headers: { "Content-Type": "application/proto" } }
|
|
);
|
|
|
|
try {
|
|
await assert.rejects(
|
|
resolveCursorAgentUrl({
|
|
accessToken: "token-invalid-host",
|
|
connectionId: "connection-invalid-host",
|
|
}),
|
|
/invalid Agent URL/
|
|
);
|
|
} finally {
|
|
globalThis.fetch = originalFetch;
|
|
}
|
|
});
|