chore: checkpoint assessment and inbox integration
This commit is contained in:
1 parent
88a31ba0d5
commit
5c52fd8b91
31 files changed
+4608
-181
No files matched your search
@@ -32,6 +32,7 @@ type canonicalAttemptFinalizeBody struct {
|
||||
type AssessmentAttemptResult struct {
|
||||
Attempt domain.AssessmentAttemptPublicSnapshot
|
||||
Outcome domain.AssessmentAttemptOutcome
|
||||
CategoryDecision *domain.AssessmentCategoryDecisionSnapshot
|
||||
NotDeterminedReason string
|
||||
BasicScore *domain.AssessmentBasicScore
|
||||
Limitations []string
|
||||
@@ -148,6 +149,20 @@ func lockAttemptForFinalize(
|
||||
if err := lockSessionConsent(ctx, unit, command.ActorID, kind); err != nil {
|
||||
return domain.AssessmentAttempt{}, fmt.Errorf("%s - authorize finalization: %w", location, err)
|
||||
}
|
||||
selected, err := repository.GetForCandidate(ctx, command.ActorID, command.AttemptID)
|
||||
if err != nil {
|
||||
if errors.Is(err, outbound.ErrAssessmentAttemptNotFound) {
|
||||
return domain.AssessmentAttempt{}, outbound.ErrAssessmentAttemptNotFound
|
||||
}
|
||||
return domain.AssessmentAttempt{}, fmt.Errorf("%s - read candidate scope before attempt lock: %w", location, err)
|
||||
}
|
||||
selectedSnapshot := selected.Snapshot()
|
||||
if selected.Kind() != kind {
|
||||
return domain.AssessmentAttempt{}, fmt.Errorf("%s - immutable attempt kind changed before lock: %w", location, domain.ErrInvalidAssessmentAttempt)
|
||||
}
|
||||
if err := repository.LockScope(ctx, command.ActorID, selectedSnapshot.Specialization); err != nil {
|
||||
return domain.AssessmentAttempt{}, fmt.Errorf("%s - lock candidate and specialization scope: %w", location, err)
|
||||
}
|
||||
current, err := repository.GetForCandidateForUpdate(ctx, command.ActorID, command.AttemptID)
|
||||
if err != nil {
|
||||
if errors.Is(err, outbound.ErrAssessmentAttemptNotFound) {
|
||||
@@ -155,8 +170,9 @@ func lockAttemptForFinalize(
|
||||
}
|
||||
return domain.AssessmentAttempt{}, fmt.Errorf("%s - lock owner-scoped attempt: %w", location, err)
|
||||
}
|
||||
if current.Kind() != kind {
|
||||
return domain.AssessmentAttempt{}, fmt.Errorf("%s - immutable attempt kind changed: %w", location, domain.ErrInvalidAssessmentAttempt)
|
||||
if current.Kind() != kind || current.Snapshot().Specialization == nil && selectedSnapshot.Specialization != nil ||
|
||||
current.Snapshot().Specialization != nil && (selectedSnapshot.Specialization == nil || *current.Snapshot().Specialization != *selectedSnapshot.Specialization) {
|
||||
return domain.AssessmentAttempt{}, fmt.Errorf("%s - immutable attempt scope changed: %w", location, domain.ErrInvalidAssessmentAttempt)
|
||||
}
|
||||
return current, nil
|
||||
}
|
||||
@@ -228,10 +244,10 @@ func (service *AttemptService) finalizeActiveAttempt(
|
||||
}
|
||||
return fmt.Errorf("%s - calculate pinned decision: %w", location, finalizeErr)
|
||||
}
|
||||
return persistFinalizedAttempt(ctx, repository, scope, command, current, updated, changed, decision, result)
|
||||
return service.persistFinalizedAttempt(ctx, repository, scope, command, current, updated, changed, decision, policy, result)
|
||||
}
|
||||
|
||||
func persistFinalizedAttempt(
|
||||
func (service *AttemptService) persistFinalizedAttempt(
|
||||
ctx context.Context,
|
||||
repository outbound.AssessmentAttemptRepository,
|
||||
scope outbound.AssessmentAttemptIdempotencyScope,
|
||||
@@ -239,6 +255,7 @@ func persistFinalizedAttempt(
|
||||
current, updated domain.AssessmentAttempt,
|
||||
changed bool,
|
||||
decision domain.AssessmentAttemptDecision,
|
||||
policy domain.PolicyVersion,
|
||||
result *outbound.AssessmentAttemptCommandResult,
|
||||
) error {
|
||||
const location = "AttemptService.persistFinalizedAttempt"
|
||||
@@ -251,8 +268,22 @@ func persistFinalizedAttempt(
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s - build immutable result snapshot: %w", location, err)
|
||||
}
|
||||
if err := repository.SaveResult(ctx, command.ActorID, storedResult); err != nil {
|
||||
return fmt.Errorf("%s - persist immutable result snapshot: %w", location, err)
|
||||
categoryPlan, err := service.categoryDecisions.PrepareFinalizedResult(
|
||||
ctx, repository, updated, storedResult, policy,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s - prepare immutable category result: %w", location, err)
|
||||
}
|
||||
if err := repository.SaveResultHistoryEntry(ctx, command.ActorID, categoryPlan.Result); err != nil {
|
||||
return fmt.Errorf("%s - persist immutable result history entry: %w", location, err)
|
||||
}
|
||||
if categoryPlan.ReplaceCurrent {
|
||||
if categoryPlan.CurrentCategory == nil {
|
||||
return fmt.Errorf("%s - category plan lacks assigned current value: %w", location, domain.ErrInvalidAssessmentCategory)
|
||||
}
|
||||
if err := repository.SaveCandidateAssessmentCategory(ctx, *categoryPlan.CurrentCategory); err != nil {
|
||||
return fmt.Errorf("%s - persist current category: %w", location, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
outcome := outbound.AssessmentAttemptCommandOutcome{StatusCode: 200, Response: updated.PublicSnapshot()}
|
||||
@@ -343,14 +374,20 @@ func readCompletedAttemptResult(
|
||||
attempt domain.AssessmentAttempt,
|
||||
) (AssessmentAttemptResult, error) {
|
||||
const location = "AttemptService.readCompletedAttemptResult"
|
||||
stored, err := unit.AssessmentAttempts().GetResult(ctx, userID, attemptID)
|
||||
stored, err := unit.AssessmentAttempts().GetResultHistoryEntry(ctx, userID, attemptID)
|
||||
if err != nil {
|
||||
return AssessmentAttemptResult{}, fmt.Errorf("%s - read immutable result: %w", location, err)
|
||||
}
|
||||
if !assessmentResultMatchesAttempt(stored, attempt) {
|
||||
if !assessmentResultMatchesAttempt(stored.Result, attempt) {
|
||||
return AssessmentAttemptResult{}, fmt.Errorf("%s - immutable result does not match its attempt: %w", location, domain.ErrInvalidAssessmentAttempt)
|
||||
}
|
||||
return assessmentAttemptResultFromSnapshot(stored), nil
|
||||
entry, err := domain.RestoreAssessmentAttemptResultHistoryEntry(stored)
|
||||
if err != nil {
|
||||
return AssessmentAttemptResult{}, fmt.Errorf("%s - restore stored category result: %w", location, err)
|
||||
}
|
||||
result := assessmentAttemptResultFromSnapshot(entry.Result)
|
||||
result.CategoryDecision = entry.CategoryDecision
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func terminalAttemptResult(attempt domain.AssessmentAttempt) (AssessmentAttemptResult, error) {
|
||||
|
||||
Reference in new issue
Block a user