fix(qa-lab): wrap malformed model catalog json · openclaw/openclaw@b02de2e
vincentkoc
·
2026-05-14
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -55,6 +55,7 @@ Docs: https://docs.openclaw.ai
|
55 | 55 | - Realtime transcription: report malformed provider websocket JSON frames with owned parser errors instead of leaking raw `SyntaxError` objects. |
56 | 56 | - Microsoft Foundry: report malformed Azure CLI token JSON with owned auth errors instead of leaking raw parser failures. |
57 | 57 | - Gateway/model pricing: report malformed external pricing catalog JSON with source-owned errors instead of leaking raw parser failures. |
| 58 | +- QA Lab: report malformed model-catalog subprocess JSON with an owned error and ignore invalid catalog rows. |
58 | 59 | - Models config/auth: stop inferring provider env-var markers from broad `^[A-Z_][A-Z0-9_]*$` strings, and resolve config-backed provider `apiKey` values only through structured env SecretRefs (`secrets.providers[id]` / `secrets.defaults`), so unrelated env vars cannot accidentally become provider credentials. Thanks @sallyom. |
59 | 60 | - Media fetch: skip allocating and buffering the response body for bodyless media responses (HEAD probes and 204-style empty bodies), avoiding wasted heap on streams that carry no payload. Thanks @shakkernerd. |
60 | 61 | - CLI/onboarding: forward provider-specific auth flags (e.g. `--openai-api-key`) through the onboarding wizard so they reach provider auth methods via `ctx.opts`, letting `--openai-api-key "$OPENAI_API_KEY"` skip the redundant "use existing env var?" prompt in non-interactive harnesses. (#81669) Thanks @sjf. |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | | -import { selectQaRunnerModelOptions } from "./model-catalog.runtime.js"; |
| 2 | +import { |
| 3 | +parseQaRunnerModelOptionsOutput, |
| 4 | +selectQaRunnerModelOptions, |
| 5 | +} from "./model-catalog.runtime.js"; |
3 | 6 | |
4 | 7 | describe("qa runner model catalog", () => { |
5 | 8 | it("filters to available rows and prefers gpt-5.5 first", () => { |
@@ -29,4 +32,29 @@ describe("qa runner model catalog", () => {
|
29 | 32 | ]).map((entry) => entry.key), |
30 | 33 | ).toEqual(["openai/gpt-5.5", "anthropic/claude-sonnet-4-6"]); |
31 | 34 | }); |
| 35 | + |
| 36 | +it("reports malformed catalog JSON with an owned error", () => { |
| 37 | +expect(() => parseQaRunnerModelOptionsOutput("{not json")).toThrow( |
| 38 | +"qa model catalog returned malformed JSON", |
| 39 | +); |
| 40 | +}); |
| 41 | + |
| 42 | +it("ignores invalid catalog rows without failing the model picker", () => { |
| 43 | +expect( |
| 44 | +parseQaRunnerModelOptionsOutput( |
| 45 | +JSON.stringify({ |
| 46 | +models: [ |
| 47 | +null, |
| 48 | +{ |
| 49 | +key: "openai/gpt-5.5", |
| 50 | +name: "gpt-5.5", |
| 51 | +input: "text,image", |
| 52 | +available: true, |
| 53 | +missing: false, |
| 54 | +}, |
| 55 | +], |
| 56 | +}), |
| 57 | +).map((entry) => entry.key), |
| 58 | +).toEqual(["openai/gpt-5.5"]); |
| 59 | +}); |
32 | 60 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -68,6 +68,34 @@ export function selectQaRunnerModelOptions(rows: ModelRow[]): QaRunnerModelOptio
|
68 | 68 | }); |
69 | 69 | } |
70 | 70 | |
| 71 | +function isModelRow(value: unknown): value is ModelRow { |
| 72 | +if (!value || typeof value !== "object") { |
| 73 | +return false; |
| 74 | +} |
| 75 | +const row = value as Partial<ModelRow>; |
| 76 | +return ( |
| 77 | +typeof row.key === "string" && |
| 78 | +typeof row.name === "string" && |
| 79 | +typeof row.input === "string" && |
| 80 | +(row.available === true || row.available === false || row.available === null) && |
| 81 | +typeof row.missing === "boolean" |
| 82 | +); |
| 83 | +} |
| 84 | + |
| 85 | +export function parseQaRunnerModelOptionsOutput(stdout: string): QaRunnerModelOption[] { |
| 86 | +let payload: unknown; |
| 87 | +try { |
| 88 | +payload = JSON.parse(stdout) as unknown; |
| 89 | +} catch { |
| 90 | +throw new Error("qa model catalog returned malformed JSON"); |
| 91 | +} |
| 92 | +if (!payload || typeof payload !== "object" || Array.isArray(payload)) { |
| 93 | +throw new Error("qa model catalog returned invalid JSON payload"); |
| 94 | +} |
| 95 | +const rows = (payload as { models?: unknown }).models; |
| 96 | +return selectQaRunnerModelOptions(Array.isArray(rows) ? rows.filter(isModelRow) : []); |
| 97 | +} |
| 98 | + |
71 | 99 | const CATALOG_ABORT_ERROR_MESSAGE = "qa model catalog aborted"; |
72 | 100 | |
73 | 101 | function createCatalogAbortError() { |
@@ -199,8 +227,7 @@ export async function loadQaRunnerModelOptions(params: { repoRoot: string; signa
|
199 | 227 | }); |
200 | 228 | }); |
201 | 229 | |
202 | | -const payload = JSON.parse(Buffer.concat(stdout).toString("utf8")) as { models?: ModelRow[] }; |
203 | | -return selectQaRunnerModelOptions(payload.models ?? []); |
| 230 | +return parseQaRunnerModelOptionsOutput(Buffer.concat(stdout).toString("utf8")); |
204 | 231 | } finally { |
205 | 232 | await fs.rm(tempRoot, { recursive: true, force: true }); |
206 | 233 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。