Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions apps/api/src/routes/keys-provider.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import { db, tables } from "@llmgateway/db";
import { providers } from "@llmgateway/models";
import {
models,
type ProviderModelMapping,
providers,
} from "@llmgateway/models";
import "dotenv/config";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import {
afterEach,
beforeEach,
describe,
expect,
test,
type TestOptions,
} from "vitest";

import { app } from "..";
import { getProviderEnvVar } from "../../../gateway/src/test-utils/test-helpers";
import { createTestUser, deleteAll } from "../testing";

function getTestOptions() {
return process.env.CI ? { retry: 3 } : {};
function getTestOptions(): TestOptions {
const hasTestOnly = models.some((model) =>
model.providers.some(
(provider: ProviderModelMapping) => provider.test === "only",
),
);
return process.env.CI
? { retry: 3 }
: { skip: hasTestOnly || !!process.env.TEST_MODELS };
}

describe("e2e tests for provider keys", getTestOptions(), () => {
Expand Down
27 changes: 12 additions & 15 deletions apps/gateway/src/api.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ const filteredModels = models
// Filter out deactivated models
.filter((model) => !model.deactivatedAt || new Date() <= model.deactivatedAt)
// Filter out free models if not in full mode
.filter((model) => fullMode || !(model as ModelDefinition).free);
.filter((model) => fullMode || !(model as ModelDefinition).free)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Parse FULL_MODE as a real boolean to avoid accidental truthiness

process.env.FULL_MODE is a string; "false"/"0" are truthy and will include free models unintentionally. Normalize once at definition.

Outside this hunk, update the declaration:

// before
const fullMode = process.env.FULL_MODE;

// after
const fullMode = /^1|true|yes$/i.test(process.env.FULL_MODE ?? "");
🤖 Prompt for AI Agents
In apps/gateway/src/api.e2e.ts around line 63, process.env.FULL_MODE is being
treated as a truthy string which causes values like "false" or "0" to be
considered true; change the environment parsing at its declaration to convert
FULL_MODE into a real boolean (e.g., test the env value against /^1|true|yes$/i
and default to false), then keep the existing .filter(...) but rely on the new
boolean fullMode so free models are excluded as intended.

// Filter by TEST_MODELS if specified
.filter((model) => {
if (!specifiedModels) {
return true;
}
// Check if any provider/model combination from this model matches TEST_MODELS
return model.providers.some((provider: ProviderModelMapping) => {
const providerModelId = `${provider.providerId}/${model.id}`;
return specifiedModels.includes(providerModelId);
});
});

const testModels = filteredModels
// If any model has test: "only", only include those models
Expand Down Expand Up @@ -105,13 +116,6 @@ const testModels = filteredModels
}

return testCases;
})
.filter((testCase) => {
// Filter by TEST_MODELS if specified
if (!specifiedModels) {
return true;
}
return specifiedModels.includes(testCase.model);
});

const providerModels = filteredModels
Expand Down Expand Up @@ -146,13 +150,6 @@ const providerModels = filteredModels
}

return testCases;
})
.filter((testCase) => {
// Filter by TEST_MODELS if specified
if (!specifiedModels) {
return true;
}
return specifiedModels.includes(testCase.model);
});

// Log the number of test models after filtering
Expand Down
Loading