|
1 | 1 | import { afterEach, describe, expect, test } from "bun:test"; |
2 | 2 | import { |
3 | 3 | clearGatherRoutedModelsInflight, |
| 4 | + filterCatalogVisibleModels, |
4 | 5 | gatherRoutedModels as gatherRoutedModelsDirect, |
5 | 6 | resetCatalogRuntimeStateForTests, |
6 | 7 | type ComboCatalogOmission, |
@@ -241,4 +242,100 @@ describe("gatherRoutedModels single-flight", () => { |
241 | 242 | expect(a.find(m => m.id === "m1")?.contextWindow).toBe(100_000); |
242 | 243 | expect(b.find(m => m.id === "m1")?.contextWindow).toBe(200_000); |
243 | 244 | }); |
| 245 | + |
| 246 | + test("selectedModels-only config changes do not share a flight", async () => { |
| 247 | + let fetchCount = 0; |
| 248 | + let release!: () => void; |
| 249 | + const gate = new Promise<void>(resolve => { |
| 250 | + release = resolve; |
| 251 | + }); |
| 252 | + |
| 253 | + globalThis.fetch = (async () => { |
| 254 | + fetchCount += 1; |
| 255 | + await gate; |
| 256 | + return new Response( |
| 257 | + JSON.stringify({ data: [{ id: "keep-me" }, { id: "drop-me" }] }), |
| 258 | + { status: 200, headers: { "content-type": "application/json" } }, |
| 259 | + ); |
| 260 | + }) as typeof fetch; |
| 261 | + |
| 262 | + const base: OcxConfig = { |
| 263 | + port: 10100, |
| 264 | + defaultProvider: "p", |
| 265 | + providers: { |
| 266 | + p: { |
| 267 | + adapter: "openai-chat", |
| 268 | + baseUrl: "https://sel.example.test/v1", |
| 269 | + models: [], |
| 270 | + }, |
| 271 | + }, |
| 272 | + }; |
| 273 | + const withSel: OcxConfig = { |
| 274 | + ...base, |
| 275 | + providers: { |
| 276 | + p: { |
| 277 | + ...base.providers.p, |
| 278 | + selectedModels: ["keep-me"], |
| 279 | + }, |
| 280 | + }, |
| 281 | + }; |
| 282 | + |
| 283 | + const first = gatherRoutedModels(base); |
| 284 | + const second = gatherRoutedModels(withSel); |
| 285 | + await Promise.resolve(); |
| 286 | + // Distinct flight keys => two live discoveries (cannot reuse unfiltered result). |
| 287 | + expect(fetchCount).toBe(2); |
| 288 | + release(); |
| 289 | + const [all, withSelModels] = await Promise.all([first, second]); |
| 290 | + // gather itself is unfiltered; visibility is applied by callers. |
| 291 | + expect(all.map(m => m.id).sort()).toEqual(["drop-me", "keep-me"]); |
| 292 | + expect(withSelModels.map(m => m.id).sort()).toEqual(["drop-me", "keep-me"]); |
| 293 | + expect(filterCatalogVisibleModels(all, base).map(m => m.id).sort()).toEqual(["drop-me", "keep-me"]); |
| 294 | + expect(filterCatalogVisibleModels(withSelModels, withSel).map(m => m.id)).toEqual(["keep-me"]); |
| 295 | + }); |
| 296 | + |
| 297 | + test("disabledModels-only config changes do not share a flight", async () => { |
| 298 | + let fetchCount = 0; |
| 299 | + let release!: () => void; |
| 300 | + const gate = new Promise<void>(resolve => { |
| 301 | + release = resolve; |
| 302 | + }); |
| 303 | + |
| 304 | + globalThis.fetch = (async () => { |
| 305 | + fetchCount += 1; |
| 306 | + await gate; |
| 307 | + return new Response( |
| 308 | + JSON.stringify({ data: [{ id: "keep-me" }, { id: "drop-me" }] }), |
| 309 | + { status: 200, headers: { "content-type": "application/json" } }, |
| 310 | + ); |
| 311 | + }) as typeof fetch; |
| 312 | + |
| 313 | + const base: OcxConfig = { |
| 314 | + port: 10100, |
| 315 | + defaultProvider: "p", |
| 316 | + providers: { |
| 317 | + p: { |
| 318 | + adapter: "openai-chat", |
| 319 | + baseUrl: "https://dis.example.test/v1", |
| 320 | + models: [], |
| 321 | + }, |
| 322 | + }, |
| 323 | + }; |
| 324 | + const withDisabled: OcxConfig = { |
| 325 | + ...base, |
| 326 | + disabledModels: ["p/drop-me"], |
| 327 | + }; |
| 328 | + |
| 329 | + const first = gatherRoutedModels(base); |
| 330 | + const second = gatherRoutedModels(withDisabled); |
| 331 | + await Promise.resolve(); |
| 332 | + expect(fetchCount).toBe(2); |
| 333 | + release(); |
| 334 | + const [all, withDisabledModels] = await Promise.all([first, second]); |
| 335 | + expect(all.map(m => m.id).sort()).toEqual(["drop-me", "keep-me"]); |
| 336 | + expect(withDisabledModels.map(m => m.id).sort()).toEqual(["drop-me", "keep-me"]); |
| 337 | + expect(filterCatalogVisibleModels(all, base).map(m => m.id).sort()).toEqual(["drop-me", "keep-me"]); |
| 338 | + expect(filterCatalogVisibleModels(withDisabledModels, withDisabled).map(m => m.id)).toEqual(["keep-me"]); |
| 339 | + }); |
| 340 | + |
244 | 341 | }); |
0 commit comments