feat(assessment): assign the demonstration category and keep result history

This commit is contained in:
shira committed 2026-10-09 00:35:13 +03:00
1 parent b3c6dc870b
commit 8277133712
61 files changed
+4338 -268

No files matched your search

+22 -26
View File
@@ -292,40 +292,36 @@ func newRealCategoryDecision(
}
func eligibleSyntheticCategoryPolicy(policy PolicyVersion, result AssessmentAttemptResultSnapshot) bool {
product := policy.Policy()
return policy.Kind() == PolicyKindDemo && policy.Key() == ProductPolicyKey &&
sameAssessmentPolicy(product.Assessment, DemoProductPolicyV2().Assessment) &&
return completeDemoBasicPolicy(policy) &&
result.Attempt.Mode == AssessmentAttemptModeDemoBasic && result.Rationale.Rule == assessmentResultRuleBasicPassMark &&
int32(product.Assessment.Attempt.BasicPassMark) == result.Rationale.PassMarkBasisPoints &&
int32(policy.Policy().Assessment.Attempt.BasicPassMark) == result.Rationale.PassMarkBasisPoints &&
(result.Outcome == AssessmentAttemptOutcomeConfirmed || result.Outcome == AssessmentAttemptOutcomeNotConfirmed)
}
func sameAssessmentPolicy(left, right AssessmentPolicy) bool {
return sameAssessmentPolicyRules(left, right) &&
sameOptionalAssessmentAttemptPolicy(left.Attempt, right.Attempt) &&
sameOptionalAssessmentTrainingPolicy(left.Training, right.Training)
}
func sameAssessmentPolicyRules(left, right AssessmentPolicy) bool {
return left.Calibration == right.Calibration && left.SameGradeRetryAfter == right.SameGradeRetryAfter &&
left.MaxAttemptsPerWindow == right.MaxAttemptsPerWindow && left.AttemptWindow == right.AttemptWindow &&
left.PromotionMinInterval == right.PromotionMinInterval && left.ConfirmationThreshold == right.ConfirmationThreshold &&
left.HighStrengthThreshold == right.HighStrengthThreshold && left.PracticeRequired == right.PracticeRequired &&
left.StopRule == right.StopRule
}
func sameOptionalAssessmentAttemptPolicy(left, right *AssessmentAttemptPolicy) bool {
if left == nil || right == nil {
return left == right
// completeDemoBasicPolicy reports whether a stored policy version is a demo
// policy whose assessment section is complete for the demo_basic mode: explicit
// attempt and training settings and an uncalibrated method. The stored version
// has already passed policy validation, so its own pass mark is the threshold;
// no fixed value is compared.
func completeDemoBasicPolicy(policy PolicyVersion) bool {
if policy.IsZero() || policy.Key() != ProductPolicyKey || policy.Kind() != PolicyKindDemo {
return false
}
return *left == *right
assessment := policy.Policy().Assessment
return assessment.Calibration == AssessmentCalibrationUncalibratedInitial &&
assessment.Attempt != nil && assessment.Attempt.RealMode == AssessmentRealModeDemoBasic &&
assessment.Training != nil
}
func sameOptionalAssessmentTrainingPolicy(left, right *AssessmentTrainingPolicy) bool {
if left == nil || right == nil {
return left == right
// ValidateSyntheticCategoryPolicy reports whether a policy version is a
// complete demonstration policy with the demo_basic mode, the only kind of
// policy under which a synthetic demonstration category may be attested.
func ValidateSyntheticCategoryPolicy(policy PolicyVersion) error {
const location = "domain.ValidateSyntheticCategoryPolicy"
if !completeDemoBasicPolicy(policy) {
return fmt.Errorf("%s - the policy is not a complete demo_basic demonstration policy: %w", location, ErrInvalidAssessmentCategory)
}
return *left == *right
return nil
}
func reviewMatchesCategoryAttempt(
@@ -227,25 +227,41 @@ func TestDecideAssessmentCategoryIsDefaultOffEvenWithReviewedSource(t *testing.T
}
}
func TestSyntheticCategoryPolicyRequiresTheCompleteAcceptedAssessmentPolicy(t *testing.T) {
accepted := DemoProductPolicyV2().Assessment
if !sameAssessmentPolicy(accepted, DemoProductPolicyV2().Assessment) {
t.Fatal("sameAssessmentPolicy(accepted) = false, want exact accepted policy")
func categoryTestPolicyVersion(t *testing.T, policy ProductPolicy, version int32) PolicyVersion {
t.Helper()
draft, err := NewPolicyVersionDraft(NewPolicyVersionDraftInput{
Key: ProductPolicyKey, Kind: PolicyKindDemo, Author: DemoPolicySeedAuthor,
EffectiveAt: testPolicyEffectiveAt, Policy: policy,
})
if err != nil {
t.Fatalf("NewPolicyVersionDraft() error = %v", err)
}
changed := DemoProductPolicyV2().Assessment
changed.StopRule.SeedItems++
if sameAssessmentPolicy(changed, accepted) {
t.Fatal("sameAssessmentPolicy(changed stop rule) = true, want false")
numbered, err := draft.WithVersion(version)
if err != nil {
t.Fatalf("WithVersion() error = %v", err)
}
changed = DemoProductPolicyV2().Assessment
changed.Attempt.IdleTimeoutSeconds++
if sameAssessmentPolicy(changed, accepted) {
t.Fatal("sameAssessmentPolicy(changed session settings) = true, want false")
return mustRestore(t, storedFrom(numbered))
}
func TestSyntheticCategoryPolicyIsAnyCompleteDemoBasicPolicyWithItsOwnThreshold(t *testing.T) {
if err := ValidateSyntheticCategoryPolicy(testCategoryPolicyVersion(t)); err != nil {
t.Fatalf("ValidateSyntheticCategoryPolicy(demo v2) error = %v", err)
}
changed = DemoProductPolicyV2().Assessment
changed.Training = nil
if sameAssessmentPolicy(changed, accepted) {
t.Fatal("sameAssessmentPolicy(missing training settings) = true, want false")
stricter := DemoProductPolicyV2()
stricter.Assessment.Attempt.BasicPassMark = 9000
if err := ValidateSyntheticCategoryPolicy(categoryTestPolicyVersion(t, stricter, 3)); err != nil {
t.Fatalf("ValidateSyntheticCategoryPolicy(pass mark 9000) error = %v, want the policy's own threshold accepted", err)
}
if err := ValidateSyntheticCategoryPolicy(PolicyVersion{}); !errors.Is(err, ErrInvalidAssessmentCategory) {
t.Fatalf("ValidateSyntheticCategoryPolicy(zero) error = %v, want invalid category", err)
}
if err := ValidateSyntheticCategoryPolicy(categoryTestPolicyVersion(t, DemoProductPolicyV1(), 1)); !errors.Is(err, ErrInvalidAssessmentCategory) {
t.Fatalf("ValidateSyntheticCategoryPolicy(no attempt settings) error = %v, want invalid category", err)
}
noTraining := DemoProductPolicyV2()
noTraining.Assessment.Training = nil
if err := ValidateSyntheticCategoryPolicy(categoryTestPolicyVersion(t, noTraining, 4)); !errors.Is(err, ErrInvalidAssessmentCategory) {
t.Fatalf("ValidateSyntheticCategoryPolicy(no training settings) error = %v, want invalid category", err)
}
}