Skip to content

Commit

Permalink
Fix processed study comparison (#1272)
Browse files Browse the repository at this point in the history
Fix generating summary:
`JSON.stringify` can't deal with BigInt.

The test covered this part of code, but they didn't have any bigInt
field.
  • Loading branch information
atuchin-m authored Nov 22, 2024
1 parent 5c7eb50 commit 84348c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/core/study_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ export class ProcessedStudy {
this.postProcessStudy(options);
}

equals(other: ProcessedStudy): boolean {
const jsonEquals = (a: unknown, b: unknown) =>
JSON.stringify(a) === JSON.stringify(b);

return (
Study.equals(this.study, other.study) &&
jsonEquals(this.studyDetails, other.studyDetails) &&
jsonEquals(this.affectedFeatures, other.affectedFeatures)
);
}

getPriority(): StudyPriority {
return this.studyDetails.getPriority();
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export function makeSummary(

const oldStudy: ProcessedStudy[] = oldMap.get(key) ?? [];
const newStudy: ProcessedStudy[] = newMap.get(key) ?? [];
const isChanged = JSON.stringify(oldStudy) !== JSON.stringify(newStudy);
const isEqual =
oldStudy.length == newStudy.length &&
oldStudy.every((v, i) => v.equals(newStudy[i]));

const item = new SummaryItem();
item.oldPriority = getOverallPriority(oldStudy);
Expand Down Expand Up @@ -170,7 +172,7 @@ export function makeSummary(
item.action = ItemAction.Down;
}
} else {
if (isChanged) {
if (!isEqual) {
item.action = ItemAction.Change;
} else {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/finch_tracker/tracker_lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ describe('summary', () => {
filter: {
channel: [Study_Channel.STABLE],
platform: [Study_Platform.WINDOWS],
start_date: BigInt(Math.floor(new Date().getTime() / 1000) - 1000),
end_date: BigInt(Math.floor(new Date().getTime() / 1000) + 1000),
},
};
const oldStudy = Study.create({
Expand Down

0 comments on commit 84348c2

Please sign in to comment.