{"record":{"id":"7bb5c2c8df2e952a","repo":"linshenkx/prompt-optimizer","slug":"unsupported-test-type-7bb5c2","errorCode":"UNSUPPORTED_TEST_TYPE","errorMessage":"UNSUPPORTED_TEST_TYPE","messagePattern":"UNSUPPORTED_TEST_TYPE","errorType":"error_code","errorClass":"ImageError","httpStatus":null,"severity":"warning","filePath":"packages/core/src/services/image/adapters/siliconflow.ts","lineNumber":265,"sourceCode":"    if (testType === 'text2image') {\n      return {\n        prompt: 'a flower',\n        count: 1\n      }\n    }\n\n    if (testType === 'image2image') {\n      return {\n        prompt: 'make it red',\n        count: 1,\n        inputImage: {\n          b64: AbstractImageProviderAdapter.TEST_IMAGE_BASE64.split(',')[1], // 去掉data:前缀\n          mimeType: 'image/png'\n        }\n      }\n    }\n\n    throw new ImageError(IMAGE_ERROR_CODES.UNSUPPORTED_TEST_TYPE, undefined, { testType })\n  }\n\n  protected async doGenerate(request: ImageRequest, config: ImageModelConfig): Promise<ImageResult> {\n    // 构建请求体，隐藏多图相关参数并固定为单图\n    const mergedParams: Record<string, any> = {\n      // 使用默认参数和覆盖参数\n      ...config.paramOverrides,\n      ...request.paramOverrides\n    }\n    delete mergedParams.n\n    delete mergedParams.batch_size\n\n    const response = await this.apiCall(config, '/images/generations', {\n      method: 'POST',\n      headers: {\n        'Authorization': `Bearer ${config.connectionConfig?.apiKey}`,\n        'Content-Type': 'application/json'\n      },","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/image/adapters/siliconflow.ts#L247-L283","documentation":"The SiliconFlow adapter only implements test image requests for 'text2image' and 'image2image'. getTestImageRequest returns a request for those two types and throws UNSUPPORTED_TEST_TYPE for anything else.","triggerScenarios":"Calling getTestImageRequest with a testType other than the literal 'text2image' or 'image2image' — e.g. 'video', 'inpaint', a typo like 'text-to-image', or an unvalidated string from user input.","commonSituations":"New test type added to UI without adapter support; string constants drifted between caller and adapter; dynamically-built testType from a config enum that includes more variants.","solutions":["Restrict the caller to the two supported literals: 'text2image' | 'image2image'","Add a check before calling: if (testType !== 'text2image' && testType !== 'image2image') return","If a new test type is genuinely needed, implement its branch in getTestImageRequest"],"exampleFix":"// before\nconst req = adapter.getTestImageRequest(userSelectedType as any)\n\n// after\nconst SUPPORTED = ['text2image', 'image2image'] as const\nif (!SUPPORTED.includes(testType)) {\n  throw new Error(`Unsupported test type: ${testType}`)\n}\nconst req = adapter.getTestImageRequest(testType)","handlingStrategy":"type-guard","validationCode":"const SUPPORTED_TEST_TYPES = ['text2image', 'image2image'] as const\nif (!SUPPORTED_TEST_TYPES.includes(testType)) {\n  throw new Error(`Test type must be one of ${SUPPORTED_TEST_TYPES.join(', ')}`)\n}","typeGuard":"function isSupportedTestType(t: unknown): t is 'text2image' | 'image2image' {\n  return t === 'text2image' || t === 'image2image'\n}","tryCatchPattern":"try {\n  const req = adapter.getTestImageRequest(testType)\n} catch (e) {\n  if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.UNSUPPORTED_TEST_TYPE) {\n    hideTestOption(testType); return\n  }\n  throw e\n}","preventionTips":["Type the testType parameter as the literal union, not string","Derive UI test options from the same constant list the adapter supports"],"tags":["siliconflow","unsupported-operation","validation","test"],"backgroundTag":"unsupported-request-type","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}