Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions backend/src/api/controllers/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,33 @@ export async function reportCompletedEventMismatch(
req: MonkeyRequest<undefined, ReportCompletedEventMismatchRequest>,
): Promise<MonkeyResponse> {
const { uid } = req.ctx.decodedToken;
const { notMatching, mode, mode2, difficulty, duration } = req.body;
const {
notMatching,
mismatchedKeys,
groupKey,
language,
mode,
mode2,
difficulty,
duration,
} = req.body;
// Logger.warning(
// `Completed event mismatch for uid ${uid}: ${notMatching.join(", ")}`,
// );
// Logger.warning(`Old CE: ${JSON.stringify(ce)}`);
// Logger.warning(`New CE: ${JSON.stringify(ce2)}`);
void addLog(
"completed_event_mismatch",
{ notMatching, mode, mode2, difficulty, duration },
{
notMatching,
mismatchedKeys,
groupKey,
language,
mode,
mode2,
difficulty,
duration,
},
uid,
);
return new MonkeyResponse("Mismatch reported", null);
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ function compareCompletedEvents(

//compare ce and ce2, log differences
const notMatching: string[] = [];
const mismatchedKeys: string[] = [];
const ceKeys = Object.keys(ce) as (keyof typeof ce)[];
for (const key of ceKeys) {
let val1 = ce[key];
Expand All @@ -938,6 +939,7 @@ function compareCompletedEvents(
console.debug(`Completed event match on key ${key}:`, a);
} else {
notMatching.push(`${key} (${mismatchCount}/${total} elements differ)`);
mismatchedKeys.push(key);
console.error(
`Completed event mismatch on key ${key}: ${mismatchCount}/${total} elements differ`,
a,
Expand All @@ -962,6 +964,7 @@ function compareCompletedEvents(
console.debug(`Completed event match on key charStats:`, a);
} else {
notMatching.push(`charStats (${diffs.join(", ")})`);
mismatchedKeys.push("charStats");
console.error(`Completed event mismatch on key charStats:`, a, b);
}
continue;
Expand Down Expand Up @@ -1022,6 +1025,7 @@ function compareCompletedEvents(
);
} else {
notMatching.push("chartData (one is 'toolong' and the other is not)");
mismatchedKeys.push("chartData");
console.error(
`Completed event mismatch on key chartData: one is "toolong" and the other is not`,
v1,
Expand All @@ -1045,6 +1049,7 @@ function compareCompletedEvents(
console.debug(`Completed event match on key chartData.${field}:`, a);
} else {
notMatching.push(`chartData.${field} (values differ)`);
mismatchedKeys.push(`chartData.${field}`);
console.error(
`Completed event mismatch on key chartData.${field}:`,
a,
Expand All @@ -1063,6 +1068,7 @@ function compareCompletedEvents(
);
} else {
notMatching.push(`keypressCountHistory (values differ)`);
mismatchedKeys.push("keypressCountHistory");
console.error(
`Completed event mismatch on key keypressCountHistory:`,
a,
Expand All @@ -1084,6 +1090,7 @@ function compareCompletedEvents(
const diff = Numbers.roundTo2(Math.abs(a - b));
const dir = a > b ? "ce1 larger" : "ce2 larger";
notMatching.push(`${key} (off by ${diff}, ${dir})`);
mismatchedKeys.push(key);
console.error(`Completed event mismatch on key ${key}:`, a, b);
}
} else if (typeof val1 === "number" && typeof val2 === "number") {
Expand All @@ -1093,12 +1100,14 @@ function compareCompletedEvents(
const diff = Numbers.roundTo2(Math.abs(a - b));
const dir = a > b ? "ce1 larger" : "ce2 larger";
notMatching.push(`${key} (off by ${diff}, ${dir})`);
mismatchedKeys.push(key);
console.error(`Completed event mismatch on key ${key}:`, a, b);
} else {
console.debug(`Completed event match on key ${key}:`, a);
}
} else if (JSON.stringify(val1) !== JSON.stringify(val2)) {
notMatching.push(`${key} (values differ)`);
mismatchedKeys.push(key);
console.error(`Completed event mismatch on key ${key}:`, val1, val2);
} else {
console.debug(`Completed event match on key ${key}:`, val1);
Expand All @@ -1112,10 +1121,15 @@ function compareCompletedEvents(
// `Completed event mismatch: ${notMatching.join(", ")}`,
// { important: true },
// );
mismatchedKeys.sort();
const groupKey = mismatchedKeys.join(",");
Ape.results
.reportCompletedEventMismatch({
body: {
notMatching,
mismatchedKeys,
groupKey,
language: ce.language,
mode: ce.mode,
mode2: ce.mode2,
difficulty: ce.difficulty,
Expand Down
17 changes: 13 additions & 4 deletions packages/contracts/src/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import {
ResultMinifiedSchema,
ResultSchema,
} from "@monkeytype/schemas/results";
import { LanguageSchema } from "@monkeytype/schemas/languages";
import {
DifficultySchema,
Mode2Schema,
ModeSchema,
} from "@monkeytype/schemas/shared";
import { IdSchema } from "@monkeytype/schemas/util";

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

export const ReportCompletedEventMismatchRequestSchema = z.object({
notMatching: z.array(z.string().max(100)).max(50),
mode: z.string().optional(),
mode2: z.string().optional(),
difficulty: z.string().optional(),
duration: z.number().optional(),
mismatchedKeys: z.array(z.string().max(100)).max(50),
groupKey: z.string().max(500),
language: LanguageSchema.optional(),
mode: ModeSchema.optional(),
mode2: Mode2Schema.optional(),
difficulty: DifficultySchema.optional(),
duration: z.number().max(200).optional(),
// ce: z.record(z.unknown()),
// ce2: z.record(z.unknown()),
});
Expand Down
Loading