Skip to content

Commit fe0904b

Browse files
authored
Merge branch 'monkeytypegame:master' into fix-sanitize-string
2 parents 331910c + 617976e commit fe0904b

3 files changed

Lines changed: 47 additions & 6 deletions

File tree

backend/src/api/controllers/result.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,33 @@ export async function reportCompletedEventMismatch(
189189
req: MonkeyRequest<undefined, ReportCompletedEventMismatchRequest>,
190190
): Promise<MonkeyResponse> {
191191
const { uid } = req.ctx.decodedToken;
192-
const { notMatching, mode, mode2, difficulty, duration } = req.body;
192+
const {
193+
notMatching,
194+
mismatchedKeys,
195+
groupKey,
196+
language,
197+
mode,
198+
mode2,
199+
difficulty,
200+
duration,
201+
} = req.body;
193202
// Logger.warning(
194203
// `Completed event mismatch for uid ${uid}: ${notMatching.join(", ")}`,
195204
// );
196205
// Logger.warning(`Old CE: ${JSON.stringify(ce)}`);
197206
// Logger.warning(`New CE: ${JSON.stringify(ce2)}`);
198207
void addLog(
199208
"completed_event_mismatch",
200-
{ notMatching, mode, mode2, difficulty, duration },
209+
{
210+
notMatching,
211+
mismatchedKeys,
212+
groupKey,
213+
language,
214+
mode,
215+
mode2,
216+
difficulty,
217+
duration,
218+
},
201219
uid,
202220
);
203221
return new MonkeyResponse("Mismatch reported", null);

frontend/src/ts/test/test-logic.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ function compareCompletedEvents(
914914

915915
//compare ce and ce2, log differences
916916
const notMatching: string[] = [];
917+
const mismatchedKeys: string[] = [];
917918
const ceKeys = Object.keys(ce) as (keyof typeof ce)[];
918919
for (const key of ceKeys) {
919920
let val1 = ce[key];
@@ -938,6 +939,7 @@ function compareCompletedEvents(
938939
console.debug(`Completed event match on key ${key}:`, a);
939940
} else {
940941
notMatching.push(`${key} (${mismatchCount}/${total} elements differ)`);
942+
mismatchedKeys.push(key);
941943
console.error(
942944
`Completed event mismatch on key ${key}: ${mismatchCount}/${total} elements differ`,
943945
a,
@@ -962,6 +964,7 @@ function compareCompletedEvents(
962964
console.debug(`Completed event match on key charStats:`, a);
963965
} else {
964966
notMatching.push(`charStats (${diffs.join(", ")})`);
967+
mismatchedKeys.push("charStats");
965968
console.error(`Completed event mismatch on key charStats:`, a, b);
966969
}
967970
continue;
@@ -1022,6 +1025,7 @@ function compareCompletedEvents(
10221025
);
10231026
} else {
10241027
notMatching.push("chartData (one is 'toolong' and the other is not)");
1028+
mismatchedKeys.push("chartData");
10251029
console.error(
10261030
`Completed event mismatch on key chartData: one is "toolong" and the other is not`,
10271031
v1,
@@ -1045,6 +1049,7 @@ function compareCompletedEvents(
10451049
console.debug(`Completed event match on key chartData.${field}:`, a);
10461050
} else {
10471051
notMatching.push(`chartData.${field} (values differ)`);
1052+
mismatchedKeys.push(`chartData.${field}`);
10481053
console.error(
10491054
`Completed event mismatch on key chartData.${field}:`,
10501055
a,
@@ -1063,6 +1068,7 @@ function compareCompletedEvents(
10631068
);
10641069
} else {
10651070
notMatching.push(`keypressCountHistory (values differ)`);
1071+
mismatchedKeys.push("keypressCountHistory");
10661072
console.error(
10671073
`Completed event mismatch on key keypressCountHistory:`,
10681074
a,
@@ -1084,6 +1090,7 @@ function compareCompletedEvents(
10841090
const diff = Numbers.roundTo2(Math.abs(a - b));
10851091
const dir = a > b ? "ce1 larger" : "ce2 larger";
10861092
notMatching.push(`${key} (off by ${diff}, ${dir})`);
1093+
mismatchedKeys.push(key);
10871094
console.error(`Completed event mismatch on key ${key}:`, a, b);
10881095
}
10891096
} else if (typeof val1 === "number" && typeof val2 === "number") {
@@ -1093,12 +1100,14 @@ function compareCompletedEvents(
10931100
const diff = Numbers.roundTo2(Math.abs(a - b));
10941101
const dir = a > b ? "ce1 larger" : "ce2 larger";
10951102
notMatching.push(`${key} (off by ${diff}, ${dir})`);
1103+
mismatchedKeys.push(key);
10961104
console.error(`Completed event mismatch on key ${key}:`, a, b);
10971105
} else {
10981106
console.debug(`Completed event match on key ${key}:`, a);
10991107
}
11001108
} else if (JSON.stringify(val1) !== JSON.stringify(val2)) {
11011109
notMatching.push(`${key} (values differ)`);
1110+
mismatchedKeys.push(key);
11021111
console.error(`Completed event mismatch on key ${key}:`, val1, val2);
11031112
} else {
11041113
console.debug(`Completed event match on key ${key}:`, val1);
@@ -1112,10 +1121,15 @@ function compareCompletedEvents(
11121121
// `Completed event mismatch: ${notMatching.join(", ")}`,
11131122
// { important: true },
11141123
// );
1124+
mismatchedKeys.sort();
1125+
const groupKey = mismatchedKeys.join(",");
11151126
Ape.results
11161127
.reportCompletedEventMismatch({
11171128
body: {
11181129
notMatching,
1130+
mismatchedKeys,
1131+
groupKey,
1132+
language: ce.language,
11191133
mode: ce.mode,
11201134
mode2: ce.mode2,
11211135
difficulty: ce.difficulty,

packages/contracts/src/results.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import {
1313
ResultMinifiedSchema,
1414
ResultSchema,
1515
} from "@monkeytype/schemas/results";
16+
import { LanguageSchema } from "@monkeytype/schemas/languages";
17+
import {
18+
DifficultySchema,
19+
Mode2Schema,
20+
ModeSchema,
21+
} from "@monkeytype/schemas/shared";
1622
import { IdSchema } from "@monkeytype/schemas/util";
1723

1824
export const GetResultsQuerySchema = z.object({
@@ -61,10 +67,13 @@ export type AddResultRequest = z.infer<typeof AddResultRequestSchema>;
6167

6268
export const ReportCompletedEventMismatchRequestSchema = z.object({
6369
notMatching: z.array(z.string().max(100)).max(50),
64-
mode: z.string().optional(),
65-
mode2: z.string().optional(),
66-
difficulty: z.string().optional(),
67-
duration: z.number().optional(),
70+
mismatchedKeys: z.array(z.string().max(100)).max(50),
71+
groupKey: z.string().max(500),
72+
language: LanguageSchema.optional(),
73+
mode: ModeSchema.optional(),
74+
mode2: Mode2Schema.optional(),
75+
difficulty: DifficultySchema.optional(),
76+
duration: z.number().max(200).optional(),
6877
// ce: z.record(z.unknown()),
6978
// ce2: z.record(z.unknown()),
7079
});

0 commit comments

Comments
 (0)