Add sticky round-robin for combos (#831)

Made-with: Cursor
This commit is contained in:
Abhishek Divekar
2026-05-01 15:06:36 +05:30
committed by GitHub
parent 0da61d8f7b
commit 3f17ee0e21
8 changed files with 160 additions and 24 deletions

View File

@@ -0,0 +1,58 @@
import { describe, it, expect, beforeEach } from "vitest";
import { getRotatedModels, resetComboRotation } from "../../open-sse/services/combo.js";
describe("combo round-robin routing", () => {
beforeEach(() => {
resetComboRotation();
});
it("keeps existing one-request round-robin behavior by default", () => {
const models = ["provider/model-a", "provider/model-b"];
const firstChoices = Array.from({ length: 4 }, () => (
getRotatedModels(models, "code-xhigh", "round-robin")[0]
));
expect(firstChoices).toEqual([
"provider/model-a",
"provider/model-b",
"provider/model-a",
"provider/model-b",
]);
});
it("sticks to each combo model for the configured number of requests", () => {
const models = ["provider/model-a", "provider/model-b"];
const firstChoices = Array.from({ length: 6 }, () => (
getRotatedModels(models, "code-xhigh", "round-robin", 2)[0]
));
expect(firstChoices).toEqual([
"provider/model-a",
"provider/model-a",
"provider/model-b",
"provider/model-b",
"provider/model-a",
"provider/model-a",
]);
});
it("tracks sticky rotation independently per combo", () => {
const models = ["provider/model-a", "provider/model-b"];
expect(getRotatedModels(models, "code-high", "round-robin", 2)[0]).toBe("provider/model-a");
expect(getRotatedModels(models, "code-xhigh", "round-robin", 2)[0]).toBe("provider/model-a");
expect(getRotatedModels(models, "code-high", "round-robin", 2)[0]).toBe("provider/model-a");
expect(getRotatedModels(models, "code-high", "round-robin", 2)[0]).toBe("provider/model-b");
expect(getRotatedModels(models, "code-xhigh", "round-robin", 2)[0]).toBe("provider/model-a");
});
it("does not rotate fallback combos", () => {
const models = ["provider/model-a", "provider/model-b"];
expect(getRotatedModels(models, "code-xhigh", "fallback", 2)).toEqual(models);
expect(getRotatedModels(models, "code-xhigh", "fallback", 2)).toEqual(models);
});
});