|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
2 | 2 |
|
3 | | -import { ProviderInstanceId, type ModelSelection, type ServerConfig } from "@t3tools/contracts"; |
| 3 | +import { |
| 4 | + DEFAULT_SERVER_SETTINGS, |
| 5 | + ProjectId, |
| 6 | + ProviderDriverKind, |
| 7 | + ProviderInstanceId, |
| 8 | + type ModelSelection, |
| 9 | + type ServerConfig, |
| 10 | + type ServerSettings, |
| 11 | +} from "@t3tools/contracts"; |
4 | 12 |
|
5 | 13 | import { |
6 | 14 | buildModelOptions, |
@@ -503,4 +511,68 @@ describe("mobile model options", () => { |
503 | 511 | }), |
504 | 512 | ).toBeNull(); |
505 | 513 | }); |
| 514 | + |
| 515 | + describe("project-aware enablement", () => { |
| 516 | + const projectId = ProjectId.make("project-a"); |
| 517 | + const instanceId = ProviderInstanceId.make("codex_work"); |
| 518 | + |
| 519 | + function configWith(settings: ServerSettings): ServerConfig { |
| 520 | + return { |
| 521 | + providers: [ |
| 522 | + { |
| 523 | + instanceId, |
| 524 | + driver: "codex", |
| 525 | + displayName: "Codex Work", |
| 526 | + enabled: true, |
| 527 | + installed: true, |
| 528 | + auth: { status: "authenticated" }, |
| 529 | + models: [{ slug: "model-a", name: "Model A", isCustom: false, capabilities: null }], |
| 530 | + }, |
| 531 | + ], |
| 532 | + settings, |
| 533 | + } as unknown as ServerConfig; |
| 534 | + } |
| 535 | + |
| 536 | + it("hides an instance the project disables even though the machine enables it", () => { |
| 537 | + const settings: ServerSettings = { |
| 538 | + ...DEFAULT_SERVER_SETTINGS, |
| 539 | + providerInstances: { |
| 540 | + [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true }, |
| 541 | + }, |
| 542 | + projectSettingsOverrides: { |
| 543 | + [projectId]: { providerInstanceEnablement: { [instanceId]: false } }, |
| 544 | + }, |
| 545 | + }; |
| 546 | + |
| 547 | + expect(buildModelOptions(configWith(settings), null, undefined, projectId)).toEqual([]); |
| 548 | + }); |
| 549 | + |
| 550 | + it("shows an instance the project enables even though the machine disables it", () => { |
| 551 | + const settings: ServerSettings = { |
| 552 | + ...DEFAULT_SERVER_SETTINGS, |
| 553 | + providerInstances: { |
| 554 | + [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: false }, |
| 555 | + }, |
| 556 | + projectSettingsOverrides: { |
| 557 | + [projectId]: { providerInstanceEnablement: { [instanceId]: true } }, |
| 558 | + }, |
| 559 | + }; |
| 560 | + |
| 561 | + expect(buildModelOptions(configWith(settings), null, undefined, projectId)).toHaveLength(1); |
| 562 | + }); |
| 563 | + |
| 564 | + it("falls back to the machine value with no project in scope", () => { |
| 565 | + const settings: ServerSettings = { |
| 566 | + ...DEFAULT_SERVER_SETTINGS, |
| 567 | + providerInstances: { |
| 568 | + [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true }, |
| 569 | + }, |
| 570 | + projectSettingsOverrides: { |
| 571 | + [projectId]: { providerInstanceEnablement: { [instanceId]: false } }, |
| 572 | + }, |
| 573 | + }; |
| 574 | + |
| 575 | + expect(buildModelOptions(configWith(settings), null, undefined, null)).toHaveLength(1); |
| 576 | + }); |
| 577 | + }); |
506 | 578 | }); |
0 commit comments