diff --git a/packages/core/src/store/retrySubstore.ts b/packages/core/src/store/retrySubstore.ts index d865a08a14f..e69a52fe5a3 100644 --- a/packages/core/src/store/retrySubstore.ts +++ b/packages/core/src/store/retrySubstore.ts @@ -99,7 +99,14 @@ export class RetrySubstore { return; } - results.push(testResult); + const existingIndex = results.findIndex((attempt) => attempt.id === testResult.id); + + if (existingIndex !== -1) { + results.splice(existingIndex, 1, testResult); + } else { + results.push(testResult); + } + results.sort((first, second) => this.#compareResults(first, second)); results.forEach((attempt, index) => { diff --git a/packages/core/test/store/retrySubstore.test.ts b/packages/core/test/store/retrySubstore.test.ts index dc5ab41cd73..6d6457c1e5f 100644 --- a/packages/core/test/store/retrySubstore.test.ts +++ b/packages/core/test/store/retrySubstore.test.ts @@ -253,6 +253,20 @@ describe("RetrySubstore", () => { expect(other.isRetry).toBe(true); }); + it("does not return a duplicate retry when the same id is upserted again", () => { + const rs = new RetrySubstore(); + const first = { ...makeTr("same"), start: 100 }; + const other = { ...makeTr("other"), start: 200 }; + + upsertInOrder(rs, first, other); + + const updated = { ...first, start: 500 }; + + rs.upsert(updated); + + expect(rs.retriesByTr(updated).map(({ id }) => id)).toEqual(["other"]); + }); + it("does not index attempts without retryHash", () => { const rs = new RetrySubstore(); const tr = { ...makeTr("solo"), retryHash: undefined };