mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 15:47:28 +00:00
test: tighten provider validation assertions
This commit is contained in:
@@ -50,13 +50,13 @@ function normalizeProviderFixture(provider: ProviderPlugin) {
|
||||
|
||||
function expectNormalizedProviderFixture(params: {
|
||||
provider: ProviderPlugin;
|
||||
expectedProvider?: Record<string, unknown>;
|
||||
expectedProvider?: ProviderPlugin | null;
|
||||
expectedDiagnostics?: ReadonlyArray<{ level: PluginDiagnostic["level"]; message: string }>;
|
||||
expectedDiagnosticText?: readonly string[];
|
||||
}) {
|
||||
const result = normalizeProviderFixture(params.provider);
|
||||
if (params.expectedProvider) {
|
||||
expect(result.provider).toMatchObject(params.expectedProvider);
|
||||
expect(result.provider).toEqual(params.expectedProvider);
|
||||
}
|
||||
if (params.expectedDiagnostics) {
|
||||
expectDiagnosticMessages(result.diagnostics, params.expectedDiagnostics);
|
||||
@@ -69,19 +69,22 @@ function expectNormalizedProviderFixture(params: {
|
||||
|
||||
function expectProviderNormalizationResult(params: {
|
||||
provider: ProviderPlugin;
|
||||
expectedProvider?: Record<string, unknown>;
|
||||
expectedProvider?: ProviderPlugin | null;
|
||||
expectedDiagnostics?: ReadonlyArray<{ level: PluginDiagnostic["level"]; message: string }>;
|
||||
expectedDiagnosticText?: readonly string[];
|
||||
assert?: (
|
||||
provider: ReturnType<typeof normalizeRegisteredProvider>,
|
||||
diagnostics: PluginDiagnostic[],
|
||||
inputProvider: ProviderPlugin,
|
||||
) => void;
|
||||
}) {
|
||||
const { diagnostics, provider } = expectNormalizedProviderFixture(params);
|
||||
params.assert?.(provider, diagnostics);
|
||||
params.assert?.(provider, diagnostics, params.provider);
|
||||
}
|
||||
|
||||
describe("normalizeRegisteredProvider", () => {
|
||||
const primaryAuthRun = async () => ({ profiles: [] });
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "drops invalid and duplicate auth methods, and clears bad wizard method bindings",
|
||||
@@ -105,7 +108,7 @@ describe("normalizeRegisteredProvider", () => {
|
||||
message: " Demo models ",
|
||||
},
|
||||
},
|
||||
run: async () => ({ profiles: [] }),
|
||||
run: primaryAuthRun,
|
||||
},
|
||||
{
|
||||
id: "primary",
|
||||
@@ -136,6 +139,7 @@ describe("normalizeRegisteredProvider", () => {
|
||||
{
|
||||
id: "primary",
|
||||
label: "Primary",
|
||||
kind: "custom",
|
||||
wizard: {
|
||||
choiceId: "demo-primary",
|
||||
modelAllowlist: {
|
||||
@@ -145,6 +149,7 @@ describe("normalizeRegisteredProvider", () => {
|
||||
message: "Demo models",
|
||||
},
|
||||
},
|
||||
run: primaryAuthRun,
|
||||
},
|
||||
],
|
||||
wizard: {
|
||||
@@ -218,12 +223,20 @@ describe("normalizeRegisteredProvider", () => {
|
||||
expectedDiagnosticText: [
|
||||
'provider "demo" registered both catalog and discovery; using catalog',
|
||||
],
|
||||
assert: (provider: ReturnType<typeof normalizeRegisteredProvider>) => {
|
||||
assert: (
|
||||
provider: ReturnType<typeof normalizeRegisteredProvider>,
|
||||
_diagnostics: PluginDiagnostic[],
|
||||
inputProvider: ProviderPlugin,
|
||||
) => {
|
||||
if (!provider) {
|
||||
throw new Error("expected provider");
|
||||
}
|
||||
expect(typeof provider.catalog?.run).toBe("function");
|
||||
expect(provider.discovery).toBeUndefined();
|
||||
expect(provider).toEqual({
|
||||
id: "demo",
|
||||
label: "Demo",
|
||||
auth: [],
|
||||
catalog: inputProvider.catalog,
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -242,11 +255,20 @@ describe("normalizeRegisteredProvider", () => {
|
||||
expectedDiagnosticText: [
|
||||
'provider "legacy-discovery-only" uses deprecated discovery; use catalog',
|
||||
],
|
||||
assert: (provider: ReturnType<typeof normalizeRegisteredProvider>) => {
|
||||
assert: (
|
||||
provider: ReturnType<typeof normalizeRegisteredProvider>,
|
||||
_diagnostics: PluginDiagnostic[],
|
||||
inputProvider: ProviderPlugin,
|
||||
) => {
|
||||
if (!provider) {
|
||||
throw new Error("expected provider");
|
||||
}
|
||||
expect(provider).toMatchObject({ discovery: { run: expect.any(Function) } });
|
||||
expect(provider).toEqual({
|
||||
id: "legacy-discovery-only",
|
||||
label: "Demo",
|
||||
auth: [],
|
||||
discovery: inputProvider.discovery,
|
||||
});
|
||||
},
|
||||
},
|
||||
] as const)(
|
||||
|
||||
Reference in New Issue
Block a user