mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 12:11:23 +00:00
test(onboard): table-drive custom api flag rejection cases
This commit is contained in:
@@ -198,27 +198,30 @@ describe("promptCustomApiConfig", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("applyCustomApiConfig", () => {
|
describe("applyCustomApiConfig", () => {
|
||||||
it("rejects invalid compatibility values at runtime", () => {
|
it.each([
|
||||||
expect(() =>
|
{
|
||||||
applyCustomApiConfig({
|
name: "invalid compatibility values at runtime",
|
||||||
|
params: {
|
||||||
config: {},
|
config: {},
|
||||||
baseUrl: "https://llm.example.com/v1",
|
baseUrl: "https://llm.example.com/v1",
|
||||||
modelId: "foo-large",
|
modelId: "foo-large",
|
||||||
compatibility: "invalid" as unknown as "openai",
|
compatibility: "invalid" as unknown as "openai",
|
||||||
}),
|
},
|
||||||
).toThrow('Custom provider compatibility must be "openai" or "anthropic".');
|
expectedMessage: 'Custom provider compatibility must be "openai" or "anthropic".',
|
||||||
});
|
},
|
||||||
|
{
|
||||||
it("rejects explicit provider ids that normalize to empty", () => {
|
name: "explicit provider ids that normalize to empty",
|
||||||
expect(() =>
|
params: {
|
||||||
applyCustomApiConfig({
|
|
||||||
config: {},
|
config: {},
|
||||||
baseUrl: "https://llm.example.com/v1",
|
baseUrl: "https://llm.example.com/v1",
|
||||||
modelId: "foo-large",
|
modelId: "foo-large",
|
||||||
compatibility: "openai",
|
compatibility: "openai" as const,
|
||||||
providerId: "!!!",
|
providerId: "!!!",
|
||||||
}),
|
},
|
||||||
).toThrow("Custom provider ID must include letters, numbers, or hyphens.");
|
expectedMessage: "Custom provider ID must include letters, numbers, or hyphens.",
|
||||||
|
},
|
||||||
|
])("rejects $name", ({ params, expectedMessage }) => {
|
||||||
|
expect(() => applyCustomApiConfig(params)).toThrow(expectedMessage);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -240,31 +243,31 @@ describe("parseNonInteractiveCustomApiFlags", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects missing required flags", () => {
|
it.each([
|
||||||
expect(() =>
|
{
|
||||||
parseNonInteractiveCustomApiFlags({
|
name: "missing required flags",
|
||||||
baseUrl: "https://llm.example.com/v1",
|
flags: { baseUrl: "https://llm.example.com/v1" },
|
||||||
}),
|
expectedMessage: 'Auth choice "custom-api-key" requires a base URL and model ID.',
|
||||||
).toThrow('Auth choice "custom-api-key" requires a base URL and model ID.');
|
},
|
||||||
});
|
{
|
||||||
|
name: "invalid compatibility values",
|
||||||
it("rejects invalid compatibility values", () => {
|
flags: {
|
||||||
expect(() =>
|
|
||||||
parseNonInteractiveCustomApiFlags({
|
|
||||||
baseUrl: "https://llm.example.com/v1",
|
baseUrl: "https://llm.example.com/v1",
|
||||||
modelId: "foo-large",
|
modelId: "foo-large",
|
||||||
compatibility: "xmlrpc",
|
compatibility: "xmlrpc",
|
||||||
}),
|
},
|
||||||
).toThrow('Invalid --custom-compatibility (use "openai" or "anthropic").');
|
expectedMessage: 'Invalid --custom-compatibility (use "openai" or "anthropic").',
|
||||||
});
|
},
|
||||||
|
{
|
||||||
it("rejects invalid explicit provider ids", () => {
|
name: "invalid explicit provider ids",
|
||||||
expect(() =>
|
flags: {
|
||||||
parseNonInteractiveCustomApiFlags({
|
|
||||||
baseUrl: "https://llm.example.com/v1",
|
baseUrl: "https://llm.example.com/v1",
|
||||||
modelId: "foo-large",
|
modelId: "foo-large",
|
||||||
providerId: "!!!",
|
providerId: "!!!",
|
||||||
}),
|
},
|
||||||
).toThrow("Custom provider ID must include letters, numbers, or hyphens.");
|
expectedMessage: "Custom provider ID must include letters, numbers, or hyphens.",
|
||||||
|
},
|
||||||
|
])("rejects $name", ({ flags, expectedMessage }) => {
|
||||||
|
expect(() => parseNonInteractiveCustomApiFlags(flags)).toThrow(expectedMessage);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user