{"record":{"id":"67e8f700b331f5b9","repo":"linshenkx/prompt-optimizer","slug":"compare-test-case-index-1-id-must-be-unique","errorCode":null,"errorMessage":"Compare test case #${index + 1} id must be unique.","messagePattern":"Compare test case #(.+?) id must be unique\\.","errorType":"validation","errorClass":"EvaluationValidationError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/evaluation/service.ts","lineNumber":501,"sourceCode":"        }\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}`);\n          if (!testCaseIds.has(snapshot.testCaseId)) {\n            throw new EvaluationValidationError(\n              `Compare snapshot #${index + 1} references unknown testCaseId \"${snapshot.testCaseId}\".`\n            );\n          }\n        });\n        if (this.isImageText2ImageMode(request)) {\n          const snapshotsWithMedia = request.snapshots.filter((snapshot) =>\n            this.hasSnapshotOutputMedia(snapshot)\n          );","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/evaluation/service.ts#L483-L519","documentation":"Thrown during compare validation when two entries in request.testCases share the same id. The service builds a Set of test case ids to map snapshots to cases; a duplicate would make the mapping ambiguous. The message names the 1-based index of the duplicate entry (Compare test case #N).","triggerScenarios":"evaluate({type:'compare', testCases:[a, b]}) where a.id === b.id, including the same object passed twice.","commonSituations":"Selecting the same test case twice in a multi-select UI; concatenating test case lists that overlap without dedupe; cloning test case fixtures without regenerating ids.","solutions":["Deduplicate test cases by id before calling evaluate","Fix the selection logic so the same test case cannot be selected twice","Regenerate ids when cloning test case objects"],"exampleFix":"// before\nconst testCases = [tc, tc];\nawait svc.evaluate({ type: 'compare', testCases, snapshots, ... });\n\n// after\nconst testCases = [...new Map(selected.map(tc => [tc.id, tc])).values()];\nawait svc.evaluate({ type: 'compare', testCases, snapshots, ... });","handlingStrategy":"validation","validationCode":"const ids = new Set(testCases.map(tc => tc.id));\nif (ids.size !== testCases.length) throw new Error('Duplicate test case ids');\nawait svc.evaluate({ ...req, testCases });","typeGuard":"const allIdsUnique = (tcs: EvaluationTestCase[]) => new Set(tcs.map(t => t.id)).size === tcs.length;","tryCatchPattern":null,"preventionTips":["Deduplicate by id at selection time","Regenerate ids when cloning fixtures"],"tags":["evaluation","validation","compare","duplicate-id"],"backgroundTag":"duplicate-identifier","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}