496 lines
22 KiB
Go
496 lines
22 KiB
Go
package domain
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func TestDecideAssessmentCategoryUsesReviewedPinnedThreshold(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
previous := testCurrentAssessmentCategory(t, uuid.New(), GradeIntern, policy)
|
|
userID := previous.snapshot.CandidateID
|
|
|
|
failedAttempt := newCategoryTestAttempt(t, policy, GradeJunior, userID)
|
|
failedAttempt, failedResult := finishCategoryTestAttempt(t, failedAttempt, policy, 18)
|
|
failedReview := categoryReviewForAttempt(t, failedAttempt, policy)
|
|
failed, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: failedAttempt, Result: failedResult, Policy: policy, Review: &failedReview, Current: &previous,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecideAssessmentCategory(k-1) error = %v", err)
|
|
}
|
|
if snapshot := failed.Snapshot(); snapshot.Status != AssessmentCategoryDecisionNotConfirmed ||
|
|
snapshot.PreviousGrade == nil || *snapshot.PreviousGrade != GradeIntern ||
|
|
snapshot.CurrentGrade == nil || *snapshot.CurrentGrade != GradeIntern || failed.ShouldUpdateCurrent() {
|
|
t.Fatalf("k-1 decision = %+v, want failed attempt preserving the current intern grade", snapshot)
|
|
}
|
|
if current, ok := failed.CurrentCategory(); !ok || current.Snapshot().Grade != GradeIntern {
|
|
t.Fatalf("current category after k-1 = (%+v, %v), want the previous grade", current.Snapshot(), ok)
|
|
}
|
|
|
|
passingAttempt := newCategoryTestAttempt(t, policy, GradeJunior, userID)
|
|
passingAttempt, passingResult := finishCategoryTestAttempt(t, passingAttempt, policy, 19)
|
|
passingReview := categoryReviewForAttempt(t, passingAttempt, policy)
|
|
passing, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: passingAttempt, Result: passingResult, Policy: policy, Review: &passingReview, Current: &previous,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecideAssessmentCategory(k) error = %v", err)
|
|
}
|
|
snapshot := passing.Snapshot()
|
|
if snapshot.Status != AssessmentCategoryDecisionAssigned || snapshot.Method != AssessmentCategoryDecisionDemoBasicPassMark ||
|
|
snapshot.PreviousGrade == nil || *snapshot.PreviousGrade != GradeIntern ||
|
|
snapshot.CurrentGrade == nil || *snapshot.CurrentGrade != GradeJunior ||
|
|
snapshot.CalibrationStatus != AssessmentCategoryCalibrationUncalibrated ||
|
|
snapshot.Source != AssessmentCategorySourceSyntheticDemo || !passing.ShouldUpdateCurrent() {
|
|
t.Fatalf("k decision = %+v, want explicit uncalibrated synthetic assignment", snapshot)
|
|
}
|
|
current, ok := passing.CurrentCategory()
|
|
if !ok || current.Snapshot().Grade != GradeJunior || current.Snapshot().SourceReviewID != passingReview.Snapshot().ID {
|
|
t.Fatalf("assigned current category = (%+v, %v), want the reviewed junior grade", current.Snapshot(), ok)
|
|
}
|
|
}
|
|
|
|
func TestDecideAssessmentCategoryRejectsReviewAfterResult(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
attempt := newCategoryTestAttempt(t, policy, GradeJunior, uuid.New())
|
|
attempt, result := finishCategoryTestAttempt(t, attempt, policy, 19)
|
|
review := categoryReviewForAttempt(t, attempt, policy)
|
|
reviewSnapshot := review.Snapshot()
|
|
reviewSnapshot.ReviewedAt = result.DecidedAt
|
|
boundaryReview, err := RestoreAssessmentSyntheticCategoryReview(reviewSnapshot)
|
|
if err != nil {
|
|
t.Fatalf("RestoreAssessmentSyntheticCategoryReview(at decision time) error = %v", err)
|
|
}
|
|
boundary, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: policy, Review: &boundaryReview,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil || boundary.Snapshot().Status != AssessmentCategoryDecisionAssigned {
|
|
t.Fatalf("DecideAssessmentCategory(review at decision time) = (%+v, %v), want assignment", boundary.Snapshot(), err)
|
|
}
|
|
|
|
reviewSnapshot.ReviewedAt = result.DecidedAt.Add(time.Microsecond)
|
|
futureReview, err := RestoreAssessmentSyntheticCategoryReview(reviewSnapshot)
|
|
if err != nil {
|
|
t.Fatalf("RestoreAssessmentSyntheticCategoryReview(after decision time) error = %v", err)
|
|
}
|
|
future, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: policy, Review: &futureReview,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil || future.Snapshot().Status != AssessmentCategoryDecisionNotEligible || future.ShouldUpdateCurrent() {
|
|
t.Fatalf("DecideAssessmentCategory(review after decision time) = (%+v, %v), want no assignment", future.Snapshot(), err)
|
|
}
|
|
}
|
|
|
|
func TestDecideAssessmentCategoryFailsClosedWithoutMatchingReview(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
attempt := newCategoryTestAttempt(t, policy, GradeJunior, uuid.New())
|
|
attempt, result := finishCategoryTestAttempt(t, attempt, policy, 19)
|
|
|
|
decision, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: policy, SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecideAssessmentCategory(no review) error = %v", err)
|
|
}
|
|
if snapshot := decision.Snapshot(); snapshot.Status != AssessmentCategoryDecisionNotEligible ||
|
|
snapshot.CurrentGrade != nil || snapshot.ReviewID != uuid.Nil || decision.ShouldUpdateCurrent() {
|
|
t.Fatalf("unreviewed decision = %+v, want no category evidence", snapshot)
|
|
}
|
|
|
|
review := categoryReviewForAttempt(t, attempt, policy)
|
|
reviewSnapshot := review.Snapshot()
|
|
reviewSnapshot.ProductPolicyVersion++
|
|
wrongPolicyReview, err := RestoreAssessmentSyntheticCategoryReview(reviewSnapshot)
|
|
if err != nil {
|
|
t.Fatalf("RestoreAssessmentSyntheticCategoryReview(wrong policy) error = %v", err)
|
|
}
|
|
decision, err = DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: policy, Review: &wrongPolicyReview,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil || decision.Snapshot().Status != AssessmentCategoryDecisionNotEligible || decision.ShouldUpdateCurrent() {
|
|
t.Fatalf("DecideAssessmentCategory(mismatched review) = (%+v, %v), want no assignment", decision.Snapshot(), err)
|
|
}
|
|
|
|
otherPolicy := testCategoryPolicyVersion(t)
|
|
if _, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: otherPolicy, Review: &review,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
}); !errors.Is(err, ErrInvalidAssessmentCategory) {
|
|
t.Fatalf("DecideAssessmentCategory(unpinned policy) error = %v, want invalid category", err)
|
|
}
|
|
}
|
|
|
|
func TestDecideAssessmentCategoryNeverLowersCurrentGrade(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
userID := uuid.New()
|
|
current := testCurrentAssessmentCategory(t, userID, GradeMiddle, policy)
|
|
attempt := newCategoryTestAttempt(t, policy, GradeJunior, userID)
|
|
attempt, result := finishCategoryTestAttempt(t, attempt, policy, 19)
|
|
review := categoryReviewForAttempt(t, attempt, policy)
|
|
decision, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: policy, Review: &review, Current: ¤t,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecideAssessmentCategory(lower passing grade) error = %v", err)
|
|
}
|
|
if snapshot := decision.Snapshot(); snapshot.Status != AssessmentCategoryDecisionUnchanged ||
|
|
snapshot.PreviousGrade == nil || *snapshot.PreviousGrade != GradeMiddle ||
|
|
snapshot.CurrentGrade == nil || *snapshot.CurrentGrade != GradeMiddle || decision.ShouldUpdateCurrent() {
|
|
t.Fatalf("lower-grade decision = %+v, want the existing middle grade unchanged", snapshot)
|
|
}
|
|
unchanged, ok := decision.CurrentCategory()
|
|
if !ok || unchanged.Snapshot().Grade != GradeMiddle || unchanged.Snapshot().SourceAttemptID != current.Snapshot().SourceAttemptID {
|
|
t.Fatalf("current category changed after a lower pass: %+v", unchanged.Snapshot())
|
|
}
|
|
}
|
|
|
|
func TestDecideAssessmentCategoryAllowsCorrectiveDemoBasic(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
userID := uuid.New()
|
|
root := newCategoryTestAttempt(t, policy, GradeSenior, userID)
|
|
root, _ = finishCategoryTestAttempt(t, root, policy, 18)
|
|
corrective := newCategoryTestAttemptAt(
|
|
t, policy, AssessmentAttemptKindCorrective, GradeMiddle, userID, []AssessmentAttempt{root},
|
|
root.Snapshot().UpdatedAt.Add(time.Second),
|
|
)
|
|
corrective, result := finishCategoryTestAttempt(t, corrective, policy, 19)
|
|
review := categoryReviewForAttempt(t, corrective, policy)
|
|
decision, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: corrective, Result: result, Policy: policy, Review: &review,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecideAssessmentCategory(corrective) error = %v", err)
|
|
}
|
|
if snapshot := decision.Snapshot(); snapshot.Status != AssessmentCategoryDecisionAssigned ||
|
|
snapshot.CurrentGrade == nil || *snapshot.CurrentGrade != GradeMiddle {
|
|
t.Fatalf("corrective decision = %+v, want a middle-grade assignment", snapshot)
|
|
}
|
|
}
|
|
|
|
func TestDecideAssessmentCategoryExpressNeverCreatesEvidence(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
userID := uuid.New()
|
|
current := testCurrentAssessmentCategory(t, userID, GradeJunior, policy)
|
|
attempt, err := NewAssessmentAttempt(NewAssessmentAttemptInput{
|
|
UserID: userID, Kind: AssessmentAttemptKindDemoExpress, BankCategory: "unit-training",
|
|
Versions: testTrainingAssessmentAttemptVersions(policy), Policy: policy,
|
|
CreatedAt: testAssessmentAttemptCreatedAt, Items: testAssessmentAttemptItems(t, 3),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("NewAssessmentAttempt(express) error = %v", err)
|
|
}
|
|
attempt, result := finishCategoryTestAttempt(t, attempt, policy, 3)
|
|
decision, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: policy, Current: ¤t,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecideAssessmentCategory(express) error = %v", err)
|
|
}
|
|
if snapshot := decision.Snapshot(); snapshot.Status != AssessmentCategoryDecisionTrainingOnly ||
|
|
snapshot.Specialization != nil || snapshot.AttemptedGrade != nil || snapshot.ReviewID != uuid.Nil ||
|
|
decision.ShouldUpdateCurrent() {
|
|
t.Fatalf("express decision = %+v, want no category fields or update", snapshot)
|
|
}
|
|
unchanged, ok := decision.CurrentCategory()
|
|
if !ok || unchanged.Snapshot().Grade != GradeJunior || unchanged.Snapshot().SourceAttemptID != current.Snapshot().SourceAttemptID {
|
|
t.Fatalf("express changed current category: %+v", unchanged.Snapshot())
|
|
}
|
|
}
|
|
|
|
func TestDecideAssessmentCategoryIsDefaultOffEvenWithReviewedSource(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
attempt := newCategoryTestAttempt(t, policy, GradeJunior, uuid.New())
|
|
attempt, result := finishCategoryTestAttempt(t, attempt, policy, 19)
|
|
review := categoryReviewForAttempt(t, attempt, policy)
|
|
|
|
decision, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: policy, Review: &review,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecideAssessmentCategory(default gate) error = %v", err)
|
|
}
|
|
if snapshot := decision.Snapshot(); snapshot.Status != AssessmentCategoryDecisionNotEligible ||
|
|
snapshot.ReviewID != uuid.Nil || snapshot.CurrentGrade != nil || decision.ShouldUpdateCurrent() {
|
|
t.Fatalf("default-off decision = %+v, want no assignment without an explicit feature gate", snapshot)
|
|
}
|
|
}
|
|
|
|
func TestSyntheticCategoryPolicyRequiresTheCompleteAcceptedAssessmentPolicy(t *testing.T) {
|
|
accepted := DemoProductPolicyV2().Assessment
|
|
if !sameAssessmentPolicy(accepted, DemoProductPolicyV2().Assessment) {
|
|
t.Fatal("sameAssessmentPolicy(accepted) = false, want exact accepted policy")
|
|
}
|
|
changed := DemoProductPolicyV2().Assessment
|
|
changed.StopRule.SeedItems++
|
|
if sameAssessmentPolicy(changed, accepted) {
|
|
t.Fatal("sameAssessmentPolicy(changed stop rule) = true, want false")
|
|
}
|
|
changed = DemoProductPolicyV2().Assessment
|
|
changed.Attempt.IdleTimeoutSeconds++
|
|
if sameAssessmentPolicy(changed, accepted) {
|
|
t.Fatal("sameAssessmentPolicy(changed session settings) = true, want false")
|
|
}
|
|
changed = DemoProductPolicyV2().Assessment
|
|
changed.Training = nil
|
|
if sameAssessmentPolicy(changed, accepted) {
|
|
t.Fatal("sameAssessmentPolicy(missing training settings) = true, want false")
|
|
}
|
|
}
|
|
|
|
func TestAssessmentAttemptResultHistoryKeepsV1CategoryUnknown(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
userID := uuid.New()
|
|
current := testCurrentAssessmentCategory(t, userID, GradeMiddle, policy)
|
|
attempt := newCategoryTestAttempt(t, policy, GradeSenior, userID)
|
|
attempt, result := finishCategoryTestAttempt(t, attempt, policy, 19)
|
|
review := categoryReviewForAttempt(t, attempt, policy)
|
|
decision, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: policy, Review: &review, Current: ¤t,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecideAssessmentCategory() error = %v", err)
|
|
}
|
|
|
|
legacy, err := NewLegacyAssessmentAttemptResultHistoryEntry(result)
|
|
if err != nil {
|
|
t.Fatalf("NewLegacyAssessmentAttemptResultHistoryEntry() error = %v", err)
|
|
}
|
|
if legacy.SchemaVersion != AssessmentAttemptResultHistorySchemaV1 || legacy.CategoryDecision != nil || legacy.CurrentConfirmedGrade != nil {
|
|
t.Fatalf("legacy history entry = %+v, want v1 with category grade unknown", legacy)
|
|
}
|
|
|
|
v2, err := NewCategoryAssessmentAttemptResultHistoryEntry(result, decision.Snapshot())
|
|
if err != nil {
|
|
t.Fatalf("NewCategoryAssessmentAttemptResultHistoryEntry() error = %v", err)
|
|
}
|
|
if v2.SchemaVersion != AssessmentAttemptResultHistorySchemaV2 || v2.CurrentConfirmedGrade == nil ||
|
|
*v2.CurrentConfirmedGrade != GradeSenior || v2.CategoryDecision == nil ||
|
|
v2.CategoryDecision.PreviousGrade == nil || *v2.CategoryDecision.PreviousGrade != GradeMiddle ||
|
|
v2.CategoryDecision.CurrentGrade == nil || *v2.CategoryDecision.CurrentGrade != GradeSenior {
|
|
t.Fatalf("v2 history entry = %+v, want previous middle and captured current senior", v2)
|
|
}
|
|
}
|
|
|
|
func TestAssessmentAttemptResultHistoryRejectsInventedLegacyGradeAndMismatchedV2(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
attempt := newCategoryTestAttempt(t, policy, GradeJunior, uuid.New())
|
|
attempt, result := finishCategoryTestAttempt(t, attempt, policy, 3)
|
|
review := categoryReviewForAttempt(t, attempt, policy)
|
|
decision, err := DecideAssessmentCategory(AssessmentCategoryDecisionInput{
|
|
Attempt: attempt, Result: result, Policy: policy, Review: &review,
|
|
SyntheticDemoCategoryAssignmentEnabled: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("DecideAssessmentCategory() error = %v", err)
|
|
}
|
|
|
|
legacy, err := NewLegacyAssessmentAttemptResultHistoryEntry(result)
|
|
if err != nil {
|
|
t.Fatalf("NewLegacyAssessmentAttemptResultHistoryEntry() error = %v", err)
|
|
}
|
|
legacy.CurrentConfirmedGrade = pointer(GradeIntern)
|
|
if _, err := RestoreAssessmentAttemptResultHistoryEntry(legacy); !errors.Is(err, ErrInvalidAssessmentCategory) {
|
|
t.Fatalf("RestoreAssessmentAttemptResultHistoryEntry(v1 with inferred grade) error = %v, want invalid category", err)
|
|
}
|
|
|
|
v2, err := NewCategoryAssessmentAttemptResultHistoryEntry(result, decision.Snapshot())
|
|
if err != nil {
|
|
t.Fatalf("NewCategoryAssessmentAttemptResultHistoryEntry() error = %v", err)
|
|
}
|
|
v2.CategoryDecision.OpeningManifestHash = testManifestHash(200)
|
|
if _, err := RestoreAssessmentAttemptResultHistoryEntry(v2); !errors.Is(err, ErrInvalidAssessmentCategory) {
|
|
t.Fatalf("RestoreAssessmentAttemptResultHistoryEntry(mismatched pins) error = %v, want invalid category", err)
|
|
}
|
|
}
|
|
|
|
func TestAssessmentCategorySnapshotsRejectUnknownOrIncompleteProvenance(t *testing.T) {
|
|
policy := testCategoryPolicyVersion(t)
|
|
current := testCurrentAssessmentCategory(t, uuid.New(), GradeJunior, policy)
|
|
corrupt := current.Snapshot()
|
|
corrupt.SourceReviewID = uuid.Nil
|
|
if _, err := RestoreCandidateAssessmentCategory(corrupt); !errors.Is(err, ErrInvalidAssessmentCategory) {
|
|
t.Fatalf("RestoreCandidateAssessmentCategory(missing review) error = %v, want invalid category", err)
|
|
}
|
|
|
|
operator, err := ParseAssessmentOperator("operator:assessment-reviewer")
|
|
if err != nil {
|
|
t.Fatalf("ParseAssessmentOperator() error = %v", err)
|
|
}
|
|
if _, err := RestoreAssessmentSyntheticCategoryReview(AssessmentSyntheticCategoryReviewSnapshot{
|
|
ID: uuid.New(), OpeningID: uuid.New(), Category: "backend", Source: AssessmentCategorySourceSyntheticDemo,
|
|
OpeningManifestHash: testManifestHash(1),
|
|
ProductPolicyVersionID: policy.ID(), ProductPolicyVersion: policy.Version(), ReviewedBy: operator,
|
|
}); !errors.Is(err, ErrInvalidAssessmentCategory) {
|
|
t.Fatalf("RestoreAssessmentSyntheticCategoryReview(missing time) error = %v, want invalid category", err)
|
|
}
|
|
if _, err := RestoreAssessmentSyntheticCategoryReview(AssessmentSyntheticCategoryReviewSnapshot{
|
|
ID: uuid.New(), OpeningID: uuid.New(), Category: "backend", OpeningManifestHash: testManifestHash(1),
|
|
ProductPolicyVersionID: policy.ID(), ProductPolicyVersion: policy.Version(), ReviewedBy: operator,
|
|
ReviewedAt: testAssessmentAttemptCreatedAt,
|
|
}); !errors.Is(err, ErrInvalidAssessmentCategory) {
|
|
t.Fatalf("RestoreAssessmentSyntheticCategoryReview(missing source) error = %v, want invalid category", err)
|
|
}
|
|
if _, err := RestoreAssessmentSyntheticCategoryReview(AssessmentSyntheticCategoryReviewSnapshot{
|
|
ID: uuid.New(), OpeningID: uuid.New(), Category: "backend", Source: AssessmentCategorySource("operator_import"),
|
|
OpeningManifestHash: testManifestHash(1), ProductPolicyVersionID: policy.ID(), ProductPolicyVersion: policy.Version(),
|
|
ReviewedBy: operator, ReviewedAt: testAssessmentAttemptCreatedAt,
|
|
}); !errors.Is(err, ErrInvalidAssessmentCategory) {
|
|
t.Fatalf("RestoreAssessmentSyntheticCategoryReview(wrong source) error = %v, want invalid category", err)
|
|
}
|
|
}
|
|
|
|
func testCategoryPolicyVersion(t *testing.T) PolicyVersion {
|
|
t.Helper()
|
|
policy := DemoProductPolicyV2()
|
|
draft, err := NewPolicyVersionDraft(NewPolicyVersionDraftInput{
|
|
Key: ProductPolicyKey, Kind: PolicyKindDemo, Author: DemoPolicySeedAuthor,
|
|
EffectiveAt: testPolicyEffectiveAt, Policy: policy,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("NewPolicyVersionDraft(category policy) error = %v", err)
|
|
}
|
|
numbered, err := draft.WithVersion(2)
|
|
if err != nil {
|
|
t.Fatalf("PolicyVersionDraft.WithVersion(category policy) error = %v", err)
|
|
}
|
|
return mustRestore(t, storedFrom(numbered))
|
|
}
|
|
|
|
func newCategoryTestAttempt(
|
|
t *testing.T,
|
|
policy PolicyVersion,
|
|
grade GradeCode,
|
|
userID uuid.UUID,
|
|
) AssessmentAttempt {
|
|
t.Helper()
|
|
return newCategoryTestAttemptAt(t, policy, AssessmentAttemptKindRoot, grade, userID, nil, testAssessmentAttemptCreatedAt)
|
|
}
|
|
|
|
func newCategoryTestAttemptAt(
|
|
t *testing.T,
|
|
policy PolicyVersion,
|
|
kind AssessmentAttemptKind,
|
|
grade GradeCode,
|
|
userID uuid.UUID,
|
|
chain []AssessmentAttempt,
|
|
createdAt time.Time,
|
|
) AssessmentAttempt {
|
|
t.Helper()
|
|
specialization := SpecializationBackend
|
|
attempt, err := NewAssessmentAttempt(NewAssessmentAttemptInput{
|
|
UserID: userID, Kind: kind, BankCategory: "unit-category", Specialization: &specialization,
|
|
TargetGrade: &grade, Chain: chain, Versions: testAssessmentAttemptVersions(t, policy),
|
|
Policy: policy, CreatedAt: createdAt, Items: testAssessmentAttemptItems(t, int(policy.Policy().Assessment.StopRule.MaxScoredItems+policy.Policy().Assessment.StopRule.SeedItems)),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("NewAssessmentAttempt(category test) error = %v", err)
|
|
}
|
|
return attempt
|
|
}
|
|
|
|
func finishCategoryTestAttempt(
|
|
t *testing.T,
|
|
attempt AssessmentAttempt,
|
|
policy PolicyVersion,
|
|
correctCount int,
|
|
) (AssessmentAttempt, AssessmentAttemptResultSnapshot) {
|
|
t.Helper()
|
|
items := attempt.Snapshot().Items
|
|
if correctCount < 0 || correctCount > len(items) {
|
|
t.Fatalf("correct count %d outside %d attempt items", correctCount, len(items))
|
|
}
|
|
startedAt := attempt.Snapshot().CreatedAt
|
|
for index, item := range items {
|
|
answer := incorrectAssessmentTestAnswer(t, item.Variant)
|
|
if index < correctCount {
|
|
answer = correctAssessmentTestAnswer(t, item.Variant)
|
|
}
|
|
updated, changed, err := attempt.SubmitAnswer(attempt.Version(), item.ID, answer, startedAt.Add(time.Duration(index+1)*time.Second))
|
|
if err != nil || !changed {
|
|
t.Fatalf("SubmitAnswer(category item %d) = changed %v, error %v", index, changed, err)
|
|
}
|
|
attempt = updated
|
|
}
|
|
finalized, changed, answerDecision, err := attempt.FinalizeDemo(
|
|
attempt.Version(), policy.Policy().Assessment, startedAt.Add(time.Duration(len(items)+1)*time.Second),
|
|
)
|
|
if err != nil || !changed {
|
|
t.Fatalf("FinalizeDemo(category attempt) = changed %v, error %v", changed, err)
|
|
}
|
|
summary := ""
|
|
limitations := []string{"uncalibrated_thresholds"}
|
|
if finalized.Kind() == AssessmentAttemptKindDemoExpress {
|
|
summary = "This training run is educational only."
|
|
limitations = []string{"demonstration_only"}
|
|
}
|
|
result, err := NewAssessmentAttemptResultSnapshot(finalized, answerDecision, summary, limitations)
|
|
if err != nil {
|
|
t.Fatalf("NewAssessmentAttemptResultSnapshot(category attempt) error = %v", err)
|
|
}
|
|
return finalized, result
|
|
}
|
|
|
|
func categoryReviewForAttempt(
|
|
t *testing.T,
|
|
attempt AssessmentAttempt,
|
|
policy PolicyVersion,
|
|
) AssessmentSyntheticCategoryReview {
|
|
t.Helper()
|
|
reviewer, err := ParseAssessmentOperator("operator:assessment-reviewer")
|
|
if err != nil {
|
|
t.Fatalf("ParseAssessmentOperator() error = %v", err)
|
|
}
|
|
snapshot := attempt.Snapshot()
|
|
review, err := NewAssessmentSyntheticCategoryReview(AssessmentSyntheticCategoryReviewSnapshot{
|
|
ID: uuid.New(), OpeningID: snapshot.Versions.OpeningID, Category: snapshot.BankCategory,
|
|
Source: AssessmentCategorySourceSyntheticDemo,
|
|
OpeningManifestHash: snapshot.Versions.OpeningManifestHash,
|
|
ProductPolicyVersionID: policy.ID(), ProductPolicyVersion: policy.Version(),
|
|
ReviewedBy: reviewer, ReviewedAt: testAssessmentAttemptCreatedAt,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("NewAssessmentSyntheticCategoryReview() error = %v", err)
|
|
}
|
|
return review
|
|
}
|
|
|
|
func testCurrentAssessmentCategory(
|
|
t *testing.T,
|
|
userID uuid.UUID,
|
|
grade GradeCode,
|
|
policy PolicyVersion,
|
|
) CandidateAssessmentCategory {
|
|
t.Helper()
|
|
return restoredTestCategory(t, CandidateAssessmentCategorySnapshot{
|
|
CandidateID: userID, Specialization: SpecializationBackend, Grade: grade,
|
|
SourceAttemptID: AssessmentAttemptID(uuid.New()), SourceReviewID: uuid.New(),
|
|
ProductPolicyVersionID: policy.ID(), ProductPolicyVersion: policy.Version(),
|
|
OpeningID: uuid.New(), OpeningManifestHash: testManifestHash(9),
|
|
Source: AssessmentCategorySourceSyntheticDemo,
|
|
CalibrationStatus: AssessmentCategoryCalibrationUncalibrated,
|
|
AssignedAt: testAssessmentAttemptCreatedAt,
|
|
})
|
|
}
|
|
|
|
func restoredTestCategory(t *testing.T, snapshot CandidateAssessmentCategorySnapshot) CandidateAssessmentCategory {
|
|
t.Helper()
|
|
category, err := RestoreCandidateAssessmentCategory(snapshot)
|
|
if err != nil {
|
|
t.Fatalf("RestoreCandidateAssessmentCategory() error = %v", err)
|
|
}
|
|
return category
|
|
}
|