mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 23:10:24 +00:00
test: dedupe plugin runtime utility suites
This commit is contained in:
@@ -22,12 +22,9 @@ function makeProvider(overrides: Partial<ProviderPlugin>): ProviderPlugin {
|
||||
}
|
||||
|
||||
describe("normalizeRegisteredProvider", () => {
|
||||
it("drops invalid and duplicate auth methods, and clears bad wizard method bindings", () => {
|
||||
const { diagnostics, pushDiagnostic } = collectDiagnostics();
|
||||
|
||||
const provider = normalizeRegisteredProvider({
|
||||
pluginId: "demo-plugin",
|
||||
source: "/tmp/demo/index.ts",
|
||||
it.each([
|
||||
{
|
||||
name: "drops invalid and duplicate auth methods, and clears bad wizard method bindings",
|
||||
provider: makeProvider({
|
||||
id: " demo ",
|
||||
label: " Demo Provider ",
|
||||
@@ -68,66 +65,58 @@ describe("normalizeRegisteredProvider", () => {
|
||||
},
|
||||
},
|
||||
}),
|
||||
pushDiagnostic,
|
||||
});
|
||||
|
||||
expect(provider).toMatchObject({
|
||||
id: "demo",
|
||||
label: "Demo Provider",
|
||||
aliases: ["alias-one"],
|
||||
deprecatedProfileIds: ["demo:legacy"],
|
||||
envVars: ["DEMO_API_KEY"],
|
||||
auth: [
|
||||
{
|
||||
id: "primary",
|
||||
label: "Primary",
|
||||
wizard: {
|
||||
choiceId: "demo-primary",
|
||||
modelAllowlist: {
|
||||
allowedKeys: ["demo/model"],
|
||||
initialSelections: ["demo/model"],
|
||||
message: "Demo models",
|
||||
expectedProvider: {
|
||||
id: "demo",
|
||||
label: "Demo Provider",
|
||||
aliases: ["alias-one"],
|
||||
deprecatedProfileIds: ["demo:legacy"],
|
||||
envVars: ["DEMO_API_KEY"],
|
||||
auth: [
|
||||
{
|
||||
id: "primary",
|
||||
label: "Primary",
|
||||
wizard: {
|
||||
choiceId: "demo-primary",
|
||||
modelAllowlist: {
|
||||
allowedKeys: ["demo/model"],
|
||||
initialSelections: ["demo/model"],
|
||||
message: "Demo models",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
wizard: {
|
||||
setup: {
|
||||
choiceId: "demo-choice",
|
||||
},
|
||||
modelPicker: {
|
||||
label: "Demo models",
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedDiagnostics: [
|
||||
{
|
||||
level: "error",
|
||||
message: 'provider "demo" auth method duplicated id "primary"',
|
||||
},
|
||||
{
|
||||
level: "error",
|
||||
message: 'provider "demo" auth method missing id',
|
||||
},
|
||||
{
|
||||
level: "warn",
|
||||
message:
|
||||
'provider "demo" setup method "missing" not found; falling back to available methods',
|
||||
},
|
||||
{
|
||||
level: "warn",
|
||||
message:
|
||||
'provider "demo" model-picker method "missing" not found; falling back to available methods',
|
||||
},
|
||||
],
|
||||
wizard: {
|
||||
setup: {
|
||||
choiceId: "demo-choice",
|
||||
},
|
||||
modelPicker: {
|
||||
label: "Demo models",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(diagnostics.map((diag) => ({ level: diag.level, message: diag.message }))).toEqual([
|
||||
{
|
||||
level: "error",
|
||||
message: 'provider "demo" auth method duplicated id "primary"',
|
||||
},
|
||||
{
|
||||
level: "error",
|
||||
message: 'provider "demo" auth method missing id',
|
||||
},
|
||||
{
|
||||
level: "warn",
|
||||
message:
|
||||
'provider "demo" setup method "missing" not found; falling back to available methods',
|
||||
},
|
||||
{
|
||||
level: "warn",
|
||||
message:
|
||||
'provider "demo" model-picker method "missing" not found; falling back to available methods',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("drops wizard metadata when a provider has no auth methods", () => {
|
||||
const { diagnostics, pushDiagnostic } = collectDiagnostics();
|
||||
|
||||
const provider = normalizeRegisteredProvider({
|
||||
pluginId: "demo-plugin",
|
||||
source: "/tmp/demo/index.ts",
|
||||
},
|
||||
{
|
||||
name: "drops wizard metadata when a provider has no auth methods",
|
||||
provider: makeProvider({
|
||||
wizard: {
|
||||
setup: {
|
||||
@@ -138,15 +127,39 @@ describe("normalizeRegisteredProvider", () => {
|
||||
},
|
||||
},
|
||||
}),
|
||||
pushDiagnostic,
|
||||
});
|
||||
assert: (
|
||||
provider: ReturnType<typeof normalizeRegisteredProvider>,
|
||||
diagnostics: PluginDiagnostic[],
|
||||
) => {
|
||||
expect(provider?.wizard).toBeUndefined();
|
||||
expect(diagnostics.map((diag) => diag.message)).toEqual([
|
||||
'provider "demo" setup metadata ignored because it has no auth methods',
|
||||
'provider "demo" model-picker metadata ignored because it has no auth methods',
|
||||
]);
|
||||
},
|
||||
},
|
||||
] as const)(
|
||||
"$name",
|
||||
({ provider: inputProvider, expectedProvider, expectedDiagnostics, assert }) => {
|
||||
const { diagnostics, pushDiagnostic } = collectDiagnostics();
|
||||
const provider = normalizeRegisteredProvider({
|
||||
pluginId: "demo-plugin",
|
||||
source: "/tmp/demo/index.ts",
|
||||
provider: inputProvider,
|
||||
pushDiagnostic,
|
||||
});
|
||||
|
||||
expect(provider?.wizard).toBeUndefined();
|
||||
expect(diagnostics.map((diag) => diag.message)).toEqual([
|
||||
'provider "demo" setup metadata ignored because it has no auth methods',
|
||||
'provider "demo" model-picker metadata ignored because it has no auth methods',
|
||||
]);
|
||||
});
|
||||
if (assert) {
|
||||
assert(provider, diagnostics);
|
||||
return;
|
||||
}
|
||||
|
||||
expect(provider).toMatchObject(expectedProvider);
|
||||
expect(diagnostics.map((diag) => ({ level: diag.level, message: diag.message }))).toEqual(
|
||||
expectedDiagnostics,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("prefers catalog when a provider registers both catalog and discovery", () => {
|
||||
const { diagnostics, pushDiagnostic } = collectDiagnostics();
|
||||
|
||||
Reference in New Issue
Block a user