{"record":{"id":"5dfd9626d92cd7eb","repo":"linshenkx/prompt-optimizer","slug":"compare-evaluation-requires-at-least-one-test-case","errorCode":null,"errorMessage":"Compare evaluation requires at least one test case.","messagePattern":"Compare evaluation requires at least one test case\\.","errorType":"validation","errorClass":"EvaluationValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/evaluation/service.ts","lineNumber":491,"sourceCode":"        this.validateSnapshot(request.snapshot, 'Result evaluation snapshot');\n        if (request.snapshot.testCaseId !== request.testCase.id) {\n          throw new EvaluationValidationError(\n            'Result evaluation snapshot testCaseId must match testCase.id.'\n          );\n        }\n        if (this.isImageText2ImageMode(request) && !this.hasSnapshotOutputMedia(request.snapshot)) {\n          throw new EvaluationValidationError(\n            'Image result evaluation requires at least one output image evidence item.'\n          );\n        }\n        break;\n\n      case 'compare':\n        if (!request.target?.workspacePrompt?.trim()) {\n          throw new EvaluationValidationError('Workspace prompt must not be empty.');\n        }\n        if (!Array.isArray(request.testCases) || request.testCases.length < 1) {\n          throw new EvaluationValidationError('Compare evaluation requires at least one test case.');\n        }\n        if (!Array.isArray(request.snapshots) || request.snapshots.length < 2) {\n          throw new EvaluationValidationError('Compare evaluation requires at least two snapshots.');\n        }\n\n        const testCaseIds = new Set<string>();\n        request.testCases.forEach((testCase, index) => {\n          this.validateTestCase(testCase, `Compare test case #${index + 1}`);\n          if (testCaseIds.has(testCase.id)) {\n            throw new EvaluationValidationError(\n              `Compare test case #${index + 1} id must be unique.`\n            );\n          }\n          testCaseIds.add(testCase.id);\n        });\n\n        request.snapshots.forEach((snapshot, index) => {\n          this.validateSnapshot(snapshot, `Compare snapshot #${index + 1}`);","sourceCodeStart":473,"sourceCodeEnd":509,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/evaluation/service.ts#L473-L509","documentation":"Thrown for type:'compare' when request.testCases is not an array or has zero entries. Compare evaluation judges multiple snapshots grouped by test case, so at least one test case is required. It is an EvaluationValidationError raised in validateRequest before execution.","triggerScenarios":"evaluate({type:'compare'}) with testCases omitted, null, set to [], or not an array (e.g. an object map of test cases).","commonSituations":"Passing a singular testCase (the 'result' shape) to a compare request; filter that removed all test cases (none selected in UI); test cases loaded asynchronously and still empty when evaluate fired.","solutions":["Populate request.testCases with at least one valid test case before calling evaluate","If you only have one test case and one snapshot, use type:'result' instead of 'compare'","Guard the compare action in the UI until a test case is selected"],"exampleFix":"// before\nawait svc.evaluate({ type: 'compare', testCases: [], snapshots, ... });\n\n// after\nawait svc.evaluate({ type: 'compare', testCases: [tc], snapshots, ... });","handlingStrategy":"validation","validationCode":"if (!Array.isArray(req.testCases) || req.testCases.length < 1) throw new Error('Select at least one test case to compare');\nawait svc.evaluate(req);","typeGuard":"const hasTestCases = (r: unknown): r is CompareRequest =>\n  Array.isArray((r as CompareRequest).testCases) && (r as CompareRequest).testCases!.length >= 1;","tryCatchPattern":null,"preventionTips":["Use type:'result' for single-case evaluations","Gate compare UI on selection count"],"tags":["evaluation","validation","compare","test-case"],"backgroundTag":"empty-collection-argument","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}