From 276803095d2dbe4db5e503153d731c5a9c4ddbea Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 17 Mar 2026 06:50:33 +0000 Subject: [PATCH] refactor(provider-tests): share discovery catalog helpers --- .../contracts/discovery.contract.test.ts | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/src/plugins/contracts/discovery.contract.test.ts b/src/plugins/contracts/discovery.contract.test.ts index 0a334a619a1..c2ec44496bb 100644 --- a/src/plugins/contracts/discovery.contract.test.ts +++ b/src/plugins/contracts/discovery.contract.test.ts @@ -75,6 +75,64 @@ function createModelConfig(id: string, name = id): ModelDefinitionConfig { maxTokens: 8_192, }; } + +function requireQwenPortalProvider() { + return requireProvider(registerProviders(qwenPortalPlugin), "qwen-portal"); +} + +function requireGithubCopilotProvider() { + return requireProvider(registerProviders(githubCopilotPlugin), "github-copilot"); +} + +function setQwenPortalOauthSnapshot() { + replaceRuntimeAuthProfileStoreSnapshots([ + { + store: { + version: 1, + profiles: { + "qwen-portal:default": { + type: "oauth", + provider: "qwen-portal", + access: "access-token", + refresh: "refresh-token", + expires: Date.now() + 60_000, + }, + }, + }, + }, + ]); +} + +function setGithubCopilotProfileSnapshot() { + replaceRuntimeAuthProfileStoreSnapshots([ + { + store: { + version: 1, + profiles: { + "github-copilot:github": { + type: "token", + provider: "github-copilot", + token: "profile-token", + }, + }, + }, + }, + ]); +} + +function runCatalog(params: { + provider: Awaited>; + env?: NodeJS.ProcessEnv; + resolveProviderApiKey?: () => { apiKey: string | undefined }; +}) { + return runProviderCatalog({ + provider: params.provider, + config: {}, + env: params.env ?? ({} as NodeJS.ProcessEnv), + resolveProviderApiKey: params.resolveProviderApiKey ?? (() => ({ apiKey: undefined })), + }); +} + describe("provider discovery contract", () => { afterEach(() => { resolveCopilotApiTokenMock.mockReset(); @@ -85,30 +143,12 @@ describe("provider discovery contract", () => { }); it("keeps qwen portal oauth marker fallback provider-owned", async () => { - const provider = requireProvider(registerProviders(qwenPortalPlugin), "qwen-portal"); - replaceRuntimeAuthProfileStoreSnapshots([ - { - store: { - version: 1, - profiles: { - "qwen-portal:default": { - type: "oauth", - provider: "qwen-portal", - access: "access-token", - refresh: "refresh-token", - expires: Date.now() + 60_000, - }, - }, - }, - }, - ]); + const provider = requireQwenPortalProvider(); + setQwenPortalOauthSnapshot(); await expect( - runProviderCatalog({ + runCatalog({ provider, - config: {}, - env: {} as NodeJS.ProcessEnv, - resolveProviderApiKey: () => ({ apiKey: undefined }), }), ).resolves.toEqual({ provider: { @@ -124,28 +164,12 @@ describe("provider discovery contract", () => { }); it("keeps qwen portal env api keys higher priority than oauth markers", async () => { - const provider = requireProvider(registerProviders(qwenPortalPlugin), "qwen-portal"); - replaceRuntimeAuthProfileStoreSnapshots([ - { - store: { - version: 1, - profiles: { - "qwen-portal:default": { - type: "oauth", - provider: "qwen-portal", - access: "access-token", - refresh: "refresh-token", - expires: Date.now() + 60_000, - }, - }, - }, - }, - ]); + const provider = requireQwenPortalProvider(); + setQwenPortalOauthSnapshot(); await expect( - runProviderCatalog({ + runCatalog({ provider, - config: {}, env: { QWEN_PORTAL_API_KEY: "env-key" } as NodeJS.ProcessEnv, resolveProviderApiKey: () => ({ apiKey: "env-key" }), }), @@ -157,41 +181,18 @@ describe("provider discovery contract", () => { }); it("keeps GitHub Copilot catalog disabled without env tokens or profiles", async () => { - const provider = requireProvider(registerProviders(githubCopilotPlugin), "github-copilot"); + const provider = requireGithubCopilotProvider(); - await expect( - runProviderCatalog({ - provider, - config: {}, - env: {} as NodeJS.ProcessEnv, - resolveProviderApiKey: () => ({ apiKey: undefined }), - }), - ).resolves.toBeNull(); + await expect(runCatalog({ provider })).resolves.toBeNull(); }); it("keeps GitHub Copilot profile-only catalog fallback provider-owned", async () => { - const provider = requireProvider(registerProviders(githubCopilotPlugin), "github-copilot"); - replaceRuntimeAuthProfileStoreSnapshots([ - { - store: { - version: 1, - profiles: { - "github-copilot:github": { - type: "token", - provider: "github-copilot", - token: "profile-token", - }, - }, - }, - }, - ]); + const provider = requireGithubCopilotProvider(); + setGithubCopilotProfileSnapshot(); await expect( - runProviderCatalog({ + runCatalog({ provider, - config: {}, - env: {} as NodeJS.ProcessEnv, - resolveProviderApiKey: () => ({ apiKey: undefined }), }), ).resolves.toEqual({ provider: { @@ -202,7 +203,7 @@ describe("provider discovery contract", () => { }); it("keeps GitHub Copilot env-token base URL resolution provider-owned", async () => { - const provider = requireProvider(registerProviders(githubCopilotPlugin), "github-copilot"); + const provider = requireGithubCopilotProvider(); resolveCopilotApiTokenMock.mockResolvedValueOnce({ token: "copilot-api-token", baseUrl: "https://copilot-proxy.example.com", @@ -210,9 +211,8 @@ describe("provider discovery contract", () => { }); await expect( - runProviderCatalog({ + runCatalog({ provider, - config: {}, env: { GITHUB_TOKEN: "github-env-token", } as NodeJS.ProcessEnv,