From 6bfd7098c385f9d0ac50cfbe867a603204787878 Mon Sep 17 00:00:00 2001 From: shira Date: Thu, 8 Oct 2026 21:12:37 +0300 Subject: [PATCH] fix(assessment): add the missing result summary and format imports --- .../usecase/assessment/category_history.go | 2 +- .../assessment/model/result-summary.test.ts | 74 +++++++++++++++++++ .../assessment/model/result-summary.ts | 69 +++++++++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 frontend/src/entities/assessment/model/result-summary.test.ts create mode 100644 frontend/src/entities/assessment/model/result-summary.ts diff --git a/backend/internal/usecase/assessment/category_history.go b/backend/internal/usecase/assessment/category_history.go index 73d34df..9762971 100644 --- a/backend/internal/usecase/assessment/category_history.go +++ b/backend/internal/usecase/assessment/category_history.go @@ -1,8 +1,8 @@ package assessment import ( - "crypto/hmac" "context" + "crypto/hmac" "encoding/base64" "encoding/binary" "errors" diff --git a/frontend/src/entities/assessment/model/result-summary.test.ts b/frontend/src/entities/assessment/model/result-summary.test.ts new file mode 100644 index 0000000..cf883e0 --- /dev/null +++ b/frontend/src/entities/assessment/model/result-summary.test.ts @@ -0,0 +1,74 @@ +import { describe, expect, it } from "vitest"; + +import type { AssessmentResult } from "../../../shared/api/schemas"; +import { assessmentResultSummary } from "./result-summary"; + +const base = { + attempt_id: "0199b4f2-7c1e-7d3a-9f00-aabbccddeeff", + specialization: "backend", + target_grade: "middle", + root_attempt_id: null, + chain_deadline: null, + task_language: "go", + kind: "root", + mode: "demo_basic", + not_determined_reason: null, + confirmed_grade: null, + previous_confirmed_grade: null, + strength: null, + calibration_status: "uncalibrated", + limitations: [], + uncertainty: null, + basic_score: null, + practices: [], + gaps: [], + durations: { items_seconds: 60, practice_seconds: null }, + next_steps: [], +} as const; + +function result(patch: Record): AssessmentResult { + return { ...base, ...patch } as unknown as AssessmentResult; +} + +describe("assessmentResultSummary", () => { + it("restates a confirmed grade without deriving one", () => { + const summary = assessmentResultSummary( + result({ outcome: "confirmed", confirmed_grade: "middle" }), + ); + expect(summary.text).toBe("Уровень подтвержден: Backend, Middle."); + expect(summary.reason).toBeNull(); + expect(summary.isDemonstration).toBe(false); + }); + + it("keeps the previous grade when nothing was confirmed", () => { + const summary = assessmentResultSummary( + result({ outcome: "not_confirmed", previous_confirmed_grade: "junior" }), + ); + expect(summary.text).toBe("Уровень пока не подтвержден: Backend, Middle."); + expect(summary.reason).toBe("Прежний подтвержденный уровень Junior сохраняется."); + }); + + it("explains why no decision was made", () => { + const summary = assessmentResultSummary( + result({ outcome: "not_determined", not_determined_reason: "expired" }), + ); + expect(summary.text).toBe("Результат не определен: Backend, Middle."); + expect(summary.reason).toBe("Время попытки истекло до завершения заданий."); + }); + + it("marks express training as a demonstration", () => { + const summary = assessmentResultSummary( + result({ + kind: "demo_express", + mode: "demo_express", + specialization: null, + target_grade: null, + task_language: null, + outcome: "demonstration", + limitations: ["demonstration_only"], + }), + ); + expect(summary.isDemonstration).toBe(true); + expect(summary.reason).toBeNull(); + }); +}); diff --git a/frontend/src/entities/assessment/model/result-summary.ts b/frontend/src/entities/assessment/model/result-summary.ts new file mode 100644 index 0000000..29d35a4 --- /dev/null +++ b/frontend/src/entities/assessment/model/result-summary.ts @@ -0,0 +1,69 @@ +import type { AssessmentResult } from "../../../shared/api/schemas"; +import { gradeLabels, outcomeLabels, specializationLabels } from "./labels"; + +export type AssessmentResultSummary = { + /** One sentence with the decision of the attempt as the server recorded it. */ + readonly text: string; + /** Why no decision was made, or what stays in force; null when nothing to add. */ + readonly reason: string | null; + /** True for training results that never confirm a grade. */ + readonly isDemonstration: boolean; +}; + +type NotDeterminedReason = NonNullable< + Exclude["not_determined_reason"] +>; + +const notDeterminedReasons: Readonly> = { + expired: "Время попытки истекло до завершения заданий.", + practice_incomplete: "Практическое задание не было отправлено до окончания срока.", + insufficient_bank: "Банк заданий не смог обеспечить нужное покрытие.", + sandbox_unavailable: "Проверка практического решения была недоступна по технической причине.", +}; + +/** + * Builds the text shown for a finished attempt. It only restates fields of + * the server result and never derives a grade on its own. + */ +export function assessmentResultSummary(result: AssessmentResult): AssessmentResultSummary { + if (result.kind === "demo_express") { + return { + text: "Демонстрационный экспресс-запуск завершен.", + reason: null, + isDemonstration: true, + }; + } + const isDemonstration = false; + + const specialization = specializationLabels[result.specialization]; + const keptGrade = result.previous_confirmed_grade + ? `Прежний подтвержденный уровень ${gradeLabels[result.previous_confirmed_grade]} сохраняется.` + : null; + + switch (result.outcome) { + case "confirmed": { + const grade = result.confirmed_grade ?? result.target_grade; + return { + text: `${outcomeLabels.confirmed}: ${specialization}, ${gradeLabels[grade]}.`, + reason: null, + isDemonstration, + }; + } + case "not_confirmed": + return { + text: `${outcomeLabels.not_confirmed}: ${specialization}, ${gradeLabels[result.target_grade]}.`, + reason: keptGrade, + isDemonstration, + }; + case "not_determined": { + const why = result.not_determined_reason + ? notDeterminedReasons[result.not_determined_reason] + : null; + return { + text: `${outcomeLabels.not_determined}: ${specialization}, ${gradeLabels[result.target_grade]}.`, + reason: [why, keptGrade].filter(Boolean).join(" ") || null, + isDemonstration, + }; + } + } +}