feat: add assessment, privacy and support flows

This commit is contained in:
TakuyaYagam1 committed 2026-10-08 08:08:25 +03:00
1 parent ee3738ee73
commit e4f24fa202
339 files changed
+56454 -1126

No files matched your search

+129 -5
View File
@@ -62,6 +62,12 @@ const (
maxSameGradeRetryInterval = CalendarDays(365)
maxAssessmentAttemptsPerWindow = 20
maxAssessmentAttemptWindow = CalendarDays(730)
maxAssessmentLifetime = Hours(30 * 24)
maxAssessmentIdleTimeoutSeconds = 24 * 60 * 60
maxAssessmentSessions = 10
minAssessmentExpressSeconds = 180
maxAssessmentExpressSeconds = 300
maxAssessmentExpressItems = 20
maxPromotionInterval = CalendarDays(730)
maxScoredItems = 200
maxSeedItems = 20
@@ -84,6 +90,9 @@ type ProductPolicy struct {
Assessment AssessmentPolicy
Identity IdentityPolicy
SearchStatus SearchStatusPolicy
// Support is absent only in immutable policy documents that predate the
// support section. New demo policies should set it explicitly.
Support *SupportPolicy
}
// Validate checks every section. A zero value is never valid, so a section
@@ -100,6 +109,11 @@ func (policy ProductPolicy) Validate() error {
return err
}
}
if policy.Support != nil {
if err := policy.Support.Validate(); err != nil {
return fmt.Errorf("ProductPolicy.Validate - support section: %w: %w", ErrInvalidPolicy, err)
}
}
return nil
}
@@ -108,6 +122,18 @@ func (policy ProductPolicy) Validate() error {
func (policy ProductPolicy) clone() ProductPolicy {
copied := policy
copied.Invitations.ResponseDeadlineOptions = slices.Clone(policy.Invitations.ResponseDeadlineOptions)
if attempt := policy.Assessment.Attempt; attempt != nil {
attemptCopy := *attempt
copied.Assessment.Attempt = &attemptCopy
}
if training := policy.Assessment.Training; training != nil {
trainingCopy := *training
copied.Assessment.Training = &trainingCopy
}
if support := policy.Support; support != nil {
supportCopy := *support
copied.Support = &supportCopy
}
return copied
}
@@ -276,10 +302,9 @@ type AssessmentPolicy struct {
// SameGradeRetryAfter is the pause before another attempt at the same
// grade.
SameGradeRetryAfter CalendarDays
// MaxAttemptsPerWindow limits attempts in any AttemptWindow. Whether the
// limit counts per grade, per specialty, or across all assessments of a
// candidate is an open question for attempt accounting;
// the policy stores only the number.
// MaxAttemptsPerWindow limits a candidate's root attempts across all
// specializations in any AttemptWindow. Corrective and training attempts
// do not reserve another root slot.
MaxAttemptsPerWindow int32
AttemptWindow CalendarDays
// PromotionMinInterval is the minimum time between grade promotions.
@@ -292,6 +317,92 @@ type AssessmentPolicy struct {
// scored attempt.
PracticeRequired bool
StopRule AssessmentStopRule
// Attempt is nil in legacy policy documents that predate the attempt
// contract. Attempt creation must fail closed when it is nil; readers keep
// those policy versions available for records created under them.
Attempt *AssessmentAttemptPolicy
// Training is an explicit non-qualification policy section. It is nil in
// immutable legacy policies and never inherits real assessment settings.
Training *AssessmentTrainingPolicy
}
// AssessmentAttemptPolicy holds the versioned execution limits for a newly
// started attempt. It is optional only for immutable legacy policy versions;
// callers cannot infer missing values from defaults.
type AssessmentAttemptPolicy struct {
Lifetime Hours
ChainDeadline Hours
MaxSessions int32
IdleTimeoutSeconds int32
RealMode AssessmentRealMode
BasicPassMark BasisPoints
}
// AssessmentTrainingPolicy holds settings for a separate training run. Its
// bank source is pinned independently from real category openings.
type AssessmentTrainingPolicy struct {
DemoExpressDurationSeconds int32
DemoExpressItemCount int32
MaxSessions int32
IdleTimeoutSeconds int32
}
// AssessmentRealMode is a server-selected mode for a real assessment.
type AssessmentRealMode string
const (
AssessmentRealModeDemoBasic AssessmentRealMode = "demo_basic"
AssessmentRealModeAdaptive AssessmentRealMode = "adaptive"
)
func (policy AssessmentAttemptPolicy) validate(calibration AssessmentCalibration) error {
const location = "AssessmentAttemptPolicy.Validate"
if err := firstError(
checkRange(location, "assessment.attempt.lifetime_hours", policy.Lifetime, 1, maxAssessmentLifetime),
checkRange(location, "assessment.attempt.chain_deadline_hours", policy.ChainDeadline, 1, maxAssessmentLifetime),
checkRange(location, "assessment.attempt.max_sessions", policy.MaxSessions, 1, maxAssessmentSessions),
checkRange(location, "assessment.attempt.idle_timeout_seconds", policy.IdleTimeoutSeconds, 60, maxAssessmentIdleTimeoutSeconds),
); err != nil {
return err
}
if policy.ChainDeadline > policy.Lifetime {
return invalidPolicy(location, "assessment.attempt.chain_deadline_hours must not exceed lifetime_hours")
}
if int64(policy.IdleTimeoutSeconds) > int64(policy.Lifetime)*60*60 {
return invalidPolicy(location, "assessment.attempt.idle_timeout_seconds must not exceed lifetime_hours")
}
switch policy.RealMode {
case AssessmentRealModeDemoBasic:
if err := checkRange(location, "assessment.attempt.basic_pass_mark_bp", policy.BasicPassMark, 1, basisPointsPerUnit); err != nil {
return err
}
case AssessmentRealModeAdaptive:
if policy.BasicPassMark != 0 {
return invalidPolicy(location, "assessment.attempt.basic_pass_mark_bp must be zero in adaptive mode")
}
if calibration != AssessmentCalibrationCalibrated {
return invalidPolicy(location, "adaptive assessment mode requires a calibrated assessment policy")
}
default:
return invalidPolicy(location, "assessment.attempt.real_mode must be demo_basic or adaptive")
}
return nil
}
func (policy AssessmentTrainingPolicy) validate() error {
const location = "AssessmentTrainingPolicy.Validate"
if err := firstError(
checkRange(location, "assessment.training.demo_express_duration_seconds", policy.DemoExpressDurationSeconds, minAssessmentExpressSeconds, maxAssessmentExpressSeconds),
checkRange(location, "assessment.training.demo_express_item_count", policy.DemoExpressItemCount, 1, maxAssessmentExpressItems),
checkRange(location, "assessment.training.max_sessions", policy.MaxSessions, 1, maxAssessmentSessions),
checkRange(location, "assessment.training.idle_timeout_seconds", policy.IdleTimeoutSeconds, 60, maxAssessmentIdleTimeoutSeconds),
); err != nil {
return err
}
if policy.IdleTimeoutSeconds > policy.DemoExpressDurationSeconds {
return invalidPolicy(location, "assessment.training.idle_timeout_seconds must not exceed demo_express_duration_seconds")
}
return nil
}
// AssessmentStopRule ends an adaptive attempt. After MinScoredItems the
@@ -328,7 +439,20 @@ func (policy AssessmentPolicy) Validate() error {
if policy.HighStrengthThreshold < policy.ConfirmationThreshold {
return invalidPolicy(location, "assessment.high_strength_threshold_bp must not be below the confirmation threshold")
}
return policy.StopRule.validate(location, policy.ConfirmationThreshold)
if err := policy.StopRule.validate(location, policy.ConfirmationThreshold); err != nil {
return err
}
if policy.Attempt != nil {
if err := policy.Attempt.validate(policy.Calibration); err != nil {
return err
}
}
if policy.Training != nil {
if err := policy.Training.validate(); err != nil {
return err
}
}
return nil
}
func (rule AssessmentStopRule) validate(location string, confirmation BasisPoints) error {