test: trim import-heavy startup paths

This commit is contained in:
Peter Steinberger
2026-03-22 05:02:09 +00:00
parent 8727338372
commit e1854dfbf6
9 changed files with 697 additions and 448 deletions

View File

@@ -5,8 +5,7 @@ import {
resolveProviderPluginChoice,
resolveProviderWizardOptions,
} from "../provider-wizard.js";
import type { ProviderPlugin } from "../types.js";
import { providerContractPluginIds, uniqueProviderContractProviders } from "./registry.js";
import type { ProviderAuthMethod, ProviderPlugin } from "../types.js";
const resolvePluginProvidersMock = vi.fn();
@@ -14,6 +13,94 @@ vi.mock("../providers.js", () => ({
resolvePluginProviders: (...args: unknown[]) => resolvePluginProvidersMock(...args),
}));
function createAuthMethod(
params: Pick<ProviderAuthMethod, "id" | "label"> &
Partial<Pick<ProviderAuthMethod, "hint" | "wizard">>,
): ProviderAuthMethod {
return {
id: params.id,
label: params.label,
...(params.hint ? { hint: params.hint } : {}),
...(params.wizard ? { wizard: params.wizard } : {}),
kind: "api_key",
run: async () => ({ profiles: [] }),
};
}
const TEST_PROVIDERS: ProviderPlugin[] = [
{
id: "alpha",
label: "Alpha",
auth: [
createAuthMethod({
id: "api-key",
label: "API key",
wizard: {
choiceLabel: "Alpha key",
choiceHint: "Use an API key",
groupId: "alpha",
groupLabel: "Alpha",
onboardingScopes: ["text-inference"],
},
}),
createAuthMethod({
id: "oauth",
label: "OAuth",
wizard: {
choiceId: "alpha-oauth",
choiceLabel: "Alpha OAuth",
groupId: "alpha",
groupLabel: "Alpha",
groupHint: "Recommended",
},
}),
],
wizard: {
modelPicker: {
label: "Alpha custom",
hint: "Pick Alpha models",
methodId: "oauth",
},
},
},
{
id: "beta",
label: "Beta",
auth: [createAuthMethod({ id: "token", label: "Token" })],
wizard: {
setup: {
choiceLabel: "Beta setup",
groupId: "beta",
groupLabel: "Beta",
},
modelPicker: {
label: "Beta custom",
},
},
},
{
id: "gamma",
label: "Gamma",
auth: [
createAuthMethod({ id: "default", label: "Default auth" }),
createAuthMethod({ id: "alt", label: "Alt auth" }),
],
wizard: {
setup: {
methodId: "alt",
choiceId: "gamma-alt",
choiceLabel: "Gamma alt",
groupId: "gamma",
groupLabel: "Gamma",
},
},
},
];
const TEST_PROVIDER_IDS = TEST_PROVIDERS.map((provider) => provider.id).toSorted((left, right) =>
left.localeCompare(right),
);
function resolveExpectedWizardChoiceValues(providers: ProviderPlugin[]) {
const values: string[] = [];
@@ -43,6 +130,11 @@ function resolveExpectedWizardChoiceValues(providers: ProviderPlugin[]) {
continue;
}
if (provider.auth.length === 1) {
values.push(setup.choiceId?.trim() || provider.id);
continue;
}
values.push(
...provider.auth.map((method) => buildProviderPluginMethodChoice(provider.id, method.id)),
);
@@ -73,15 +165,15 @@ function resolveExpectedModelPickerValues(providers: ProviderPlugin[]) {
describe("provider wizard contract", () => {
beforeEach(() => {
resolvePluginProvidersMock.mockReset();
resolvePluginProvidersMock.mockReturnValue(uniqueProviderContractProviders);
resolvePluginProvidersMock.mockReturnValue(TEST_PROVIDERS);
});
it("exposes every registered provider setup choice through the shared wizard layer", () => {
it("exposes every wizard setup choice through the shared wizard layer", () => {
const options = resolveProviderWizardOptions({
config: {
plugins: {
enabled: true,
allow: providerContractPluginIds,
allow: TEST_PROVIDER_IDS,
slots: {
memory: "none",
},
@@ -92,7 +184,7 @@ describe("provider wizard contract", () => {
expect(
options.map((option) => option.value).toSorted((left, right) => left.localeCompare(right)),
).toEqual(resolveExpectedWizardChoiceValues(uniqueProviderContractProviders));
).toEqual(resolveExpectedWizardChoiceValues(TEST_PROVIDERS));
expect(options.map((option) => option.value)).toEqual([
...new Set(options.map((option) => option.value)),
]);
@@ -101,7 +193,7 @@ describe("provider wizard contract", () => {
it("round-trips every shared wizard choice back to its provider and auth method", () => {
for (const option of resolveProviderWizardOptions({ config: {}, env: process.env })) {
const resolved = resolveProviderPluginChoice({
providers: uniqueProviderContractProviders,
providers: TEST_PROVIDERS,
choice: option.value,
});
expect(resolved).not.toBeNull();
@@ -110,15 +202,15 @@ describe("provider wizard contract", () => {
}
});
it("exposes every registered model-picker entry through the shared wizard layer", () => {
it("exposes every model-picker entry through the shared wizard layer", () => {
const entries = resolveProviderModelPickerEntries({ config: {}, env: process.env });
expect(
entries.map((entry) => entry.value).toSorted((left, right) => left.localeCompare(right)),
).toEqual(resolveExpectedModelPickerValues(uniqueProviderContractProviders));
).toEqual(resolveExpectedModelPickerValues(TEST_PROVIDERS));
for (const entry of entries) {
const resolved = resolveProviderPluginChoice({
providers: uniqueProviderContractProviders,
providers: TEST_PROVIDERS,
choice: entry.value,
});
expect(resolved).not.toBeNull();

View File

@@ -7,7 +7,7 @@ import type {
SessionBindingAdapter,
SessionBindingRecord,
} from "../infra/outbound/session-binding-service.js";
import { createEmptyPluginRegistry } from "./registry.js";
import { createEmptyPluginRegistry } from "./registry-empty.js";
import { setActivePluginRegistry } from "./runtime.js";
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-binding-"));