From ce32b9ecf85e4bce335911f903eb9bb89da2b27f Mon Sep 17 00:00:00 2001 From: meganemura Date: Fri, 28 Aug 2026 07:22:14 +0900 Subject: [PATCH] fix(core): replace stale entry in RetrySubstore.upsert instead of pushing a duplicate Re-upserting the same test result id appended a second array entry instead of replacing the first, so retriesByTr could list a test as its own retry. Co-Authored-By: Claude Sonnet 5 --- packages/core/src/store/retrySubstore.ts | 9 ++++++++- packages/core/test/store/retrySubstore.test.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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 };