feat(assessment): define corrective and training attempt contracts
This commit is contained in:
1 parent
fade4e76e4
commit
20c03288d6
71 files changed
+14786
-1743
No files matched your search
@@ -12,6 +12,9 @@ const demoResult = {
|
||||
attempt_id: "01928f7a-3c4d-7e5f-8a9b-0c1d2e3f4a5b",
|
||||
specialization: "backend",
|
||||
target_grade: "junior",
|
||||
kind: "root",
|
||||
root_attempt_id: null,
|
||||
chain_deadline: null,
|
||||
task_language: "go",
|
||||
mode: "demo_basic",
|
||||
versions: {
|
||||
@@ -35,12 +38,52 @@ const demoResult = {
|
||||
decided_at: "2026-10-08T10:24:00Z",
|
||||
};
|
||||
|
||||
const correctiveResult = {
|
||||
...demoResult,
|
||||
target_grade: "middle",
|
||||
kind: "corrective",
|
||||
root_attempt_id: "01928f7b-1111-7a2b-8c3d-4e5f6a7b8c9d",
|
||||
chain_deadline: "2026-11-23T09:00:00Z",
|
||||
};
|
||||
|
||||
const expressResult = {
|
||||
attempt_id: "01928f7f-9999-7a2b-8c3d-4e5f6a7b8c9d",
|
||||
specialization: null,
|
||||
target_grade: null,
|
||||
task_language: null,
|
||||
kind: "demo_express",
|
||||
mode: "demo_express",
|
||||
versions: {
|
||||
policy_version: 1,
|
||||
bank_version: "express-demo.2026-10.1",
|
||||
algorithm_version: "express-interactive.1",
|
||||
},
|
||||
outcome: "demonstration",
|
||||
not_determined_reason: null,
|
||||
confirmed_grade: null,
|
||||
previous_confirmed_grade: null,
|
||||
strength: null,
|
||||
calibration_status: "uncalibrated",
|
||||
limitations: ["demonstration_only"],
|
||||
uncertainty: null,
|
||||
basic_score: null,
|
||||
practices: [],
|
||||
gaps: [],
|
||||
durations: { items_seconds: 260, practice_seconds: null },
|
||||
next_steps: [],
|
||||
summary: "This short run demonstrates the task flow.",
|
||||
decided_at: "2026-10-08T10:05:00Z",
|
||||
};
|
||||
|
||||
const pendingPracticeAttempt = {
|
||||
id: "01928f7b-1111-7a2b-8c3d-4e5f6a7b8c9d",
|
||||
version: 7,
|
||||
kind: "root",
|
||||
specialization: "backend",
|
||||
target_grade: "middle",
|
||||
task_language: "python",
|
||||
root_attempt_id: null,
|
||||
chain_deadline: null,
|
||||
mode: "adaptive",
|
||||
state: "practice_pending",
|
||||
versions: {
|
||||
@@ -66,6 +109,13 @@ const pendingPracticeAttempt = {
|
||||
],
|
||||
};
|
||||
|
||||
const correctivePracticeAttempt = {
|
||||
...pendingPracticeAttempt,
|
||||
kind: "corrective",
|
||||
root_attempt_id: "01928f7b-2222-7a2b-8c3d-4e5f6a7b8c9d",
|
||||
chain_deadline: "2026-11-23T09:00:00Z",
|
||||
};
|
||||
|
||||
describe("generated AssessmentResult", () => {
|
||||
it("accepts a demo result without uncertainty or strength numbers", () => {
|
||||
const parsed = AssessmentResult.parse(demoResult);
|
||||
@@ -75,6 +125,55 @@ describe("generated AssessmentResult", () => {
|
||||
expect(parsed.strength).toBeNull();
|
||||
});
|
||||
|
||||
it("requires an explicit null pair for a root result", () => {
|
||||
expect(AssessmentResult.parse(demoResult)).toMatchObject({
|
||||
kind: "root",
|
||||
root_attempt_id: null,
|
||||
chain_deadline: null,
|
||||
});
|
||||
|
||||
const missingPair: Record<string, unknown> = { ...demoResult };
|
||||
delete missingPair.chain_deadline;
|
||||
|
||||
expect(AssessmentResult.safeParse(missingPair).success).toBe(false);
|
||||
expect(
|
||||
AssessmentResult.safeParse({
|
||||
...demoResult,
|
||||
root_attempt_id: "01928f7b-1111-7a2b-8c3d-4e5f6a7b8c9d",
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("requires both correction-chain values together", () => {
|
||||
expect(AssessmentResult.parse(correctiveResult).kind).toBe("corrective");
|
||||
expect(AssessmentResult.safeParse({ ...correctiveResult, root_attempt_id: null }).success).toBe(
|
||||
false,
|
||||
);
|
||||
expect(AssessmentResult.safeParse({ ...correctiveResult, chain_deadline: null }).success).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps demo_express training results from confirming qualification", () => {
|
||||
const parsed = AssessmentResult.parse(expressResult);
|
||||
|
||||
expect(parsed).toMatchObject({
|
||||
kind: "demo_express",
|
||||
outcome: "demonstration",
|
||||
confirmed_grade: null,
|
||||
specialization: null,
|
||||
target_grade: null,
|
||||
uncertainty: null,
|
||||
basic_score: null,
|
||||
});
|
||||
expect(
|
||||
AssessmentResult.safeParse({ ...expressResult, confirmed_grade: "junior" }).success,
|
||||
).toBe(false);
|
||||
expect(AssessmentResult.safeParse({ ...expressResult, outcome: "confirmed" }).success).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects a result without calibration_status", () => {
|
||||
const result: Record<string, unknown> = { ...demoResult };
|
||||
delete result.calibration_status;
|
||||
@@ -82,18 +181,16 @@ describe("generated AssessmentResult", () => {
|
||||
const parsed = AssessmentResult.safeParse(result);
|
||||
|
||||
expect(parsed.success).toBe(false);
|
||||
expect(parsed.error?.issues).toEqual([
|
||||
expect.objectContaining({ path: ["calibration_status"] }),
|
||||
]);
|
||||
expect(parsed.error?.issues[0]).toMatchObject({ code: "invalid_union" });
|
||||
expect(JSON.stringify(parsed.error?.issues)).toContain('"calibration_status"');
|
||||
});
|
||||
|
||||
it("rejects an unknown calibration status", () => {
|
||||
const parsed = AssessmentResult.safeParse({ ...demoResult, calibration_status: "estimated" });
|
||||
|
||||
expect(parsed.success).toBe(false);
|
||||
expect(parsed.error?.issues).toEqual([
|
||||
expect.objectContaining({ code: "invalid_value", path: ["calibration_status"] }),
|
||||
]);
|
||||
expect(parsed.error?.issues[0]).toMatchObject({ code: "invalid_union" });
|
||||
expect(JSON.stringify(parsed.error?.issues)).toContain('"calibration_status"');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -105,18 +202,28 @@ describe("generated AssessmentAttempt", () => {
|
||||
expect(parsed.practices[0]?.verdict).toBeNull();
|
||||
});
|
||||
|
||||
it("requires both correction-chain values together", () => {
|
||||
expect(AssessmentAttempt.parse(correctivePracticeAttempt).kind).toBe("corrective");
|
||||
expect(
|
||||
AssessmentAttempt.safeParse({ ...correctivePracticeAttempt, root_attempt_id: null }).success,
|
||||
).toBe(false);
|
||||
expect(
|
||||
AssessmentAttempt.safeParse({ ...correctivePracticeAttempt, chain_deadline: null }).success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects an unknown attempt state", () => {
|
||||
const parsed = AssessmentAttempt.safeParse({ ...pendingPracticeAttempt, state: "paused" });
|
||||
|
||||
expect(parsed.success).toBe(false);
|
||||
expect(parsed.error?.issues).toEqual([
|
||||
expect.objectContaining({ code: "invalid_value", path: ["state"] }),
|
||||
]);
|
||||
expect(parsed.error?.issues[0]).toMatchObject({ code: "invalid_union" });
|
||||
expect(JSON.stringify(parsed.error?.issues)).toContain('"state"');
|
||||
});
|
||||
});
|
||||
|
||||
it("types allow null instead of fabricated numbers", () => {
|
||||
type Practice = AssessmentAttempt["practices"][number];
|
||||
type ExpressResult = Extract<AssessmentResult, { kind: "demo_express" }>;
|
||||
|
||||
expectTypeOf<null>().toExtend<AssessmentResult["uncertainty"]>();
|
||||
expectTypeOf<null>().toExtend<AssessmentResult["basic_score"]>();
|
||||
@@ -124,4 +231,9 @@ it("types allow null instead of fabricated numbers", () => {
|
||||
expectTypeOf<null>().toExtend<Practice["verdict"]>();
|
||||
expectTypeOf<"uncalibrated">().toExtend<AssessmentResult["calibration_status"]>();
|
||||
expectTypeOf<"pending">().toExtend<Practice["status"]>();
|
||||
expectTypeOf<ExpressResult["confirmed_grade"]>().toEqualTypeOf<null>();
|
||||
expectTypeOf<ExpressResult["target_grade"]>().toEqualTypeOf<null>();
|
||||
expectTypeOf<
|
||||
Extract<keyof ExpressResult, "percentile" | "qualification_evidence">
|
||||
>().toEqualTypeOf<never>();
|
||||
});
|
||||
Reference in new issue
Block a user