check: accept quota-only providers without model transport (#654)
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).
This commit is contained in:
+2
-1
@@ -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`)
|
||||
}
|
||||
|
||||
@@ -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([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user