From 63e3f5a147a92f79b58a3e1b390dd88c03b1a16c Mon Sep 17 00:00:00 2001 From: Gyoo Date: Tue, 27 Aug 2024 09:22:11 +0000 Subject: [PATCH 1/2] feat: add chart parameter to ScoreValidator --- server/src/game-implementations/games/_common.ts | 6 ++++-- server/src/game-implementations/games/arcaea.test.ts | 8 +++++--- server/src/game-implementations/types.ts | 3 ++- .../framework/score-importing/validate-score.ts | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/server/src/game-implementations/games/_common.ts b/server/src/game-implementations/games/_common.ts index c5396bd22..d2e268090 100644 --- a/server/src/game-implementations/games/_common.ts +++ b/server/src/game-implementations/games/_common.ts @@ -32,6 +32,7 @@ import type { SpecificUserGameStats, GPTString, ScoreDocument, + ChartDocument, } from "tachi-common"; export const EX_SCORE_CHECK: ChartSpecificMetricValidator = (exScore, chart) => { @@ -335,12 +336,13 @@ export function GradeGoalFormatter( */ export function RunValidators( validators: Array>, - score: ScoreDocument + score: ScoreDocument, + chart: ChartDocument ) { const errs = []; for (const validator of validators) { - const err = validator(score); + const err = validator(score, chart); if (err !== undefined) { errs.push(err); diff --git a/server/src/game-implementations/games/arcaea.test.ts b/server/src/game-implementations/games/arcaea.test.ts index 10654ce0d..58421ad8a 100644 --- a/server/src/game-implementations/games/arcaea.test.ts +++ b/server/src/game-implementations/games/arcaea.test.ts @@ -9,7 +9,7 @@ import { dmf, mkMockPB, mkMockScore } from "test-utils/misc"; import ResetDBState from "test-utils/resets"; import { TestSnapshot } from "test-utils/single-process-snapshot"; import { TestingArcaeaSheriruthFTR } from "test-utils/test-data"; -import type { ProvidedMetrics, ScoreData, ScoreDocument } from "tachi-common"; +import type { ProvidedMetrics, ScoreData, ScoreDocument, ChartDocument } from "tachi-common"; import type { DeepPartial } from "utils/types"; const baseMetrics: ProvidedMetrics["arcaea:Touch"] = { @@ -168,8 +168,10 @@ t.test("Arcaea Implementation", (t) => { }); t.test("Score Validations", (t) => { - const f = (s: DeepPartial>) => - RunValidators(ARCAEA_IMPL.scoreValidators, dmf(mockScore, s)); + const f = ( + s: DeepPartial>, + chart: ChartDocument<"arcaea:Touch"> = TestingArcaeaSheriruthFTR + ) => RunValidators(ARCAEA_IMPL.scoreValidators, dmf(mockScore, s), chart); t.strictSame( f({ diff --git a/server/src/game-implementations/types.ts b/server/src/game-implementations/types.ts index b4e00e774..e298ecf65 100644 --- a/server/src/game-implementations/types.ts +++ b/server/src/game-implementations/types.ts @@ -164,7 +164,8 @@ export type GPTGoalProgressFormatters = { * indicating what the error was on failure. */ export type ScoreValidator = ( - score: ScoreDocument + score: ScoreDocument, + chart: ChartDocument ) => string | undefined; export interface GPTServerImplementation { diff --git a/server/src/lib/score-import/framework/score-importing/validate-score.ts b/server/src/lib/score-import/framework/score-importing/validate-score.ts index cabb408a0..121cf3f10 100644 --- a/server/src/lib/score-import/framework/score-importing/validate-score.ts +++ b/server/src/lib/score-import/framework/score-importing/validate-score.ts @@ -58,7 +58,7 @@ function ValidateScoreGameSpecific(score: ScoreDocument, chart: ChartDocument): true ); - const moreErrors = RunValidators(gptImpl.scoreValidators as any, score); + const moreErrors = RunValidators(gptImpl.scoreValidators as any, score, chart); if (moreErrors) { errs.push(...moreErrors); From 6b538ca763dfe2cd9e73f9f64124f01aa10015a4 Mon Sep 17 00:00:00 2001 From: Gyoo Date: Tue, 27 Aug 2024 09:42:34 +0000 Subject: [PATCH 2/2] fix: non compiling tests --- server/src/game-implementations/games/arcaea.test.ts | 12 +++++++----- server/src/game-implementations/games/wacca.test.ts | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/server/src/game-implementations/games/arcaea.test.ts b/server/src/game-implementations/games/arcaea.test.ts index 58421ad8a..30c2f7b99 100644 --- a/server/src/game-implementations/games/arcaea.test.ts +++ b/server/src/game-implementations/games/arcaea.test.ts @@ -8,7 +8,7 @@ import t from "tap"; import { dmf, mkMockPB, mkMockScore } from "test-utils/misc"; import ResetDBState from "test-utils/resets"; import { TestSnapshot } from "test-utils/single-process-snapshot"; -import { TestingArcaeaSheriruthFTR } from "test-utils/test-data"; +import { TestingArcaeaSheriruthFTR, TestingWaccaPupaExp } from "test-utils/test-data"; import type { ProvidedMetrics, ScoreData, ScoreDocument, ChartDocument } from "tachi-common"; import type { DeepPartial } from "utils/types"; @@ -168,10 +168,12 @@ t.test("Arcaea Implementation", (t) => { }); t.test("Score Validations", (t) => { - const f = ( - s: DeepPartial>, - chart: ChartDocument<"arcaea:Touch"> = TestingArcaeaSheriruthFTR - ) => RunValidators(ARCAEA_IMPL.scoreValidators, dmf(mockScore, s), chart); + const f = (s: DeepPartial>) => + RunValidators( + ARCAEA_IMPL.scoreValidators, + dmf(mockScore, s), + TestingArcaeaSheriruthFTR + ); t.strictSame( f({ diff --git a/server/src/game-implementations/games/wacca.test.ts b/server/src/game-implementations/games/wacca.test.ts index 3817bec55..bc2853f65 100644 --- a/server/src/game-implementations/games/wacca.test.ts +++ b/server/src/game-implementations/games/wacca.test.ts @@ -172,7 +172,7 @@ t.test("WACCA Implementation", (t) => { t.test("Score Validations", (t) => { const f = (s: DeepPartial>) => - RunValidators(WACCA_IMPL.scoreValidators, dmf(mockScore, s)); + RunValidators(WACCA_IMPL.scoreValidators, dmf(mockScore, s), TestingWaccaPupaExp); t.strictSame(f({ scoreData: { lamp: "ALL MARVELOUS", score: 1_000_000 } }), undefined); t.strictSame(f({ scoreData: { lamp: "FULL COMBO", judgements: { miss: 0 } } }), undefined);