From e08e420581fd99b34cd8243e691fb87ed01bf74f Mon Sep 17 00:00:00 2001 From: Xudong Guo Date: Tue, 3 Nov 2026 10:49:03 +0800 Subject: [PATCH] check: accept quota-only providers without model transport (#654) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scripts/check.mjs accepts a provider that declares auth.usage, an empty model map and no npm or api (a quota-only provider). Its loader is still required, and a provider with models, npm or api is still checked as before. Tests in scripts/check.test.mjs cover the accepted case, the three incomplete configurations and a missing loader. (sunny0826, split out of #653 as asked there.) Run at the reviewed head bc57c1362e, rebased on main d40a074, on mote (Bun 1.4.2, temp HOME): - bun test scripts/check.test.mjs: 11 pass, 0 fail - bun test (whole repo): 4890 pass, 14 skip, 0 fail - bun scripts/check.mjs: exit 0, no package marked ✗ - Broken by hand: dropping `&& !usageOnly` from the condition turns the quota-only test red (10 pass, 1 fail). --- scripts/check.mjs | 3 ++- scripts/check.test.mjs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/scripts/check.mjs b/scripts/check.mjs index c07428c..0ac0a44 100644 --- a/scripts/check.mjs +++ b/scripts/check.mjs @@ -70,7 +70,8 @@ for (const name of readdirSync(root)) { await hooks.config(cfg) const p = cfg.provider[auth.provider] const signInOnly = hooks.tool && p?.models && !Object.keys(p.models).length && !p.npm - if (p && !signInOnly) { + const usageOnly = typeof auth.usage === "function" && p?.models && !Object.keys(p.models).length && !p.npm && !p.api + if (p && !signInOnly && !usageOnly) { needsLoader = true if (!p.npm || !p.models || !Object.keys(p.models).length) problems.push(`${fn.name}: config gives ${auth.provider} no npm or models`) } diff --git a/scripts/check.test.mjs b/scripts/check.test.mjs index 30a08c4..7b0d117 100644 --- a/scripts/check.test.mjs +++ b/scripts/check.test.mjs @@ -61,6 +61,36 @@ test("check still requires loaders for providers, including providers with tools const fine = `export const Plugin = async () => ({ tool: ${tool} })` +test("check accepts quota-only providers with a loader and no model transport", () => { + const result = check(`export const Plugin = async () => ({ + auth: {...${auth}, usage: async () => ({windows: []}), loader: async () => ({})}, + config: async (cfg) => { cfg.provider.fixture = {name: "Fixture", models: {}} } + })`) + expect(result.code).toBe(0) + expect(result.output).toContain("✓ fixture") +}) + +test("quota hooks do not exempt incomplete model providers or missing loaders", () => { + for (const config of [ + `{models: {}, api: "https://example.invalid/v1"}`, + `{models: {}, npm: "@ai-sdk/openai"}`, + `{models: {example: {}}}`, + ]) { + const result = check(`export const Plugin = async () => ({ + auth: {...${auth}, usage: async () => ({windows: []}), loader: async () => ({})}, + config: async (cfg) => { cfg.provider.fixture = ${config} } + })`) + expect(result.code).toBe(1) + expect(result.output).toContain("no npm or models") + } + const result = check(`export const Plugin = async () => ({ + auth: {...${auth}, usage: async () => ({windows: []})}, + config: async (cfg) => { cfg.provider.fixture = {models: {}} } + })`) + expect(result.code).toBe(1) + expect(result.output).toContain("auth.loader") +}) + test("check passes this repository's own registry.json", () => { expect(registryProblems(readFileSync(new URL("../registry.json", import.meta.url), "utf8"))).toEqual([]) })