@@ -30,10 +30,31 @@ export const getFallbackHistoryId = (tr: Pick<TestResult, "labels" | "parameters
3030 return `${ fallbackTestCaseId } .${ md5 ( stringifyHistoryParams ( tr . parameters ?? [ ] ) ) } ` ;
3131} ;
3232
33- export const getHistoryIdCandidates = ( tr : Pick < TestResult , "historyId" | "labels" | "parameters" > ) : string [ ] => {
33+ /**
34+ * Same formula as retry grouping: md5(`${testCaseId}:${parametersHash}:${environmentId ?? "default"}`).
35+ */
36+ export const calculateHistoryHash = (
37+ testCaseId : string | undefined ,
38+ parametersHash : string ,
39+ environmentId : string | undefined ,
40+ ) : string | undefined => {
41+ if ( ! testCaseId ) {
42+ return undefined ;
43+ }
44+
45+ return md5 ( `${ testCaseId } :${ parametersHash } :${ environmentId ?? "default" } ` ) ;
46+ } ;
47+
48+ export const getHistoryHashCandidates = (
49+ tr : Pick < TestResult , "historyHash" | "historyId" | "labels" | "parameters" > ,
50+ ) : string [ ] => {
3451 const result : string [ ] = [ ] ;
3552
36- if ( tr . historyId ) {
53+ if ( tr . historyHash ) {
54+ result . push ( tr . historyHash ) ;
55+ }
56+
57+ if ( tr . historyId && ! result . includes ( tr . historyId ) ) {
3758 result . push ( tr . historyId ) ;
3859 }
3960
@@ -46,18 +67,37 @@ export const getHistoryIdCandidates = (tr: Pick<TestResult, "historyId" | "label
4667 return result ;
4768} ;
4869
70+ /**
71+ * @deprecated Use {@link getHistoryHashCandidates}.
72+ */
73+ export const getHistoryIdCandidates = getHistoryHashCandidates ;
74+
75+ const getHistoryTestResultKeyCandidates = ( htr : HistoryTestResult ) : string [ ] => {
76+ const result : string [ ] = [ ] ;
77+
78+ if ( htr . historyHash ) {
79+ result . push ( htr . historyHash ) ;
80+ }
81+
82+ if ( htr . historyId && ! result . includes ( htr . historyId ) ) {
83+ result . push ( htr . historyId ) ;
84+ }
85+
86+ return result ;
87+ } ;
88+
4989export const filterUnknownByKnownIssues = (
5090 trs : TestResult [ ] ,
5191 knownIssueHistoryIds : ReadonlySet < string > ,
5292) : TestResult [ ] => {
5393 return trs . filter ( ( tr ) => {
54- const historyIdCandidates = getHistoryIdCandidates ( tr ) ;
94+ const historyKeyCandidates = getHistoryHashCandidates ( tr ) ;
5595
56- if ( historyIdCandidates . length === 0 ) {
96+ if ( historyKeyCandidates . length === 0 ) {
5797 return true ;
5898 }
5999
60- return historyIdCandidates . every ( ( historyId ) => ! knownIssueHistoryIds . has ( historyId ) ) ;
100+ return historyKeyCandidates . every ( ( historyKey ) => ! knownIssueHistoryIds . has ( historyKey ) ) ;
61101 } ) ;
62102} ;
63103
@@ -97,15 +137,15 @@ export const normalizeHistoryDataPointUrls = (historyDataPoint: HistoryDataPoint
97137
98138export const selectHistoryTestResults = (
99139 historyDataPoints : HistoryDataPoint [ ] ,
100- historyIdCandidates : readonly string [ ] ,
140+ historyKeyCandidates : readonly string [ ] ,
101141) : HistoryTestResult [ ] => {
102- if ( historyIdCandidates . length === 0 ) {
142+ if ( historyKeyCandidates . length === 0 ) {
103143 return [ ] ;
104144 }
105145
106146 return historyDataPoints . reduce ( ( acc , historyDataPoint ) => {
107- for ( const historyId of historyIdCandidates ) {
108- const historyTestResult = historyDataPoint . testResults [ historyId ] ;
147+ for ( const historyKey of historyKeyCandidates ) {
148+ const historyTestResult = historyDataPoint . testResults [ historyKey ] ;
109149
110150 if ( ! historyTestResult ) {
111151 continue ;
@@ -126,9 +166,8 @@ export const selectHistoryTestResults = (
126166 * @returns The history test results array.
127167 */
128168export const htrsByTr = ( hdps : HistoryDataPoint [ ] , tr : TestResult | HistoryTestResult ) : HistoryTestResult [ ] => {
129- if ( ! tr ?. historyId ) {
130- return [ ] ;
131- }
169+ const candidates =
170+ "parameters" in tr ? getHistoryHashCandidates ( tr ) : getHistoryTestResultKeyCandidates ( tr as HistoryTestResult ) ;
132171
133- return selectHistoryTestResults ( hdps , [ tr . historyId ] ) ;
172+ return selectHistoryTestResults ( hdps , candidates ) ;
134173} ;
0 commit comments