|
| 1 | +import { readFileSync } from "node:fs"; |
| 2 | +import { resolve } from "node:path"; |
| 3 | +import { |
| 4 | + registerProviderPlugin, |
| 5 | + requireRegisteredProvider, |
| 6 | +} from "openclaw/plugin-sdk/plugin-test-runtime"; |
| 7 | +import { describe, expect, it } from "vitest"; |
| 8 | +import stepfunPlugin from "./index.js"; |
| 9 | + |
| 10 | +type StepFunManifest = { |
| 11 | + setup?: { |
| 12 | + providers?: Array<{ |
| 13 | + id?: string; |
| 14 | + authMethods?: string[]; |
| 15 | + envVars?: string[]; |
| 16 | + }>; |
| 17 | + }; |
| 18 | + providerAuthChoices?: Array<{ |
| 19 | + provider?: string; |
| 20 | + method?: string; |
| 21 | + choiceId?: string; |
| 22 | + }>; |
| 23 | +}; |
| 24 | + |
| 25 | +function readManifest(): StepFunManifest { |
| 26 | + return JSON.parse(readFileSync(resolve(import.meta.dirname, "openclaw.plugin.json"), "utf-8")); |
| 27 | +} |
| 28 | + |
| 29 | +describe("stepfun provider registration", () => { |
| 30 | + it("keeps manifest auth choices aligned with runtime provider methods", async () => { |
| 31 | + const { providers } = await registerProviderPlugin({ |
| 32 | + plugin: stepfunPlugin, |
| 33 | + id: "stepfun", |
| 34 | + name: "StepFun", |
| 35 | + }); |
| 36 | + const manifest = readManifest(); |
| 37 | + const runtimeChoices = ["stepfun", "stepfun-plan"].flatMap((providerId) => { |
| 38 | + const provider = requireRegisteredProvider(providers, providerId); |
| 39 | + return provider.auth.map((method) => ({ |
| 40 | + provider: provider.id, |
| 41 | + method: method.id, |
| 42 | + choiceId: method.wizard?.choiceId, |
| 43 | + })); |
| 44 | + }); |
| 45 | + |
| 46 | + const manifestChoices = manifest.providerAuthChoices?.map((choice) => ({ |
| 47 | + provider: choice.provider, |
| 48 | + method: choice.method, |
| 49 | + choiceId: choice.choiceId, |
| 50 | + })); |
| 51 | + |
| 52 | + expect(runtimeChoices).toEqual(manifestChoices); |
| 53 | + expect(manifest.setup?.providers).toEqual([ |
| 54 | + { |
| 55 | + id: "stepfun", |
| 56 | + envVars: ["STEPFUN_API_KEY"], |
| 57 | + }, |
| 58 | + { |
| 59 | + id: "stepfun-plan", |
| 60 | + envVars: ["STEPFUN_API_KEY"], |
| 61 | + }, |
| 62 | + ]); |
| 63 | + }); |
| 64 | +}); |
0 commit comments