feat(assessment): assign the demonstration category and keep result history
This commit is contained in:
1 parent
b3c6dc870b
commit
8277133712
61 files changed
+4338
-268
No files matched your search
@@ -302,6 +302,9 @@ func TestAnonymousCardReachesNoProfileOrContactSchema(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
for reached := range reachableSchemas(index, mustJSONValue(t, schema)) {
|
||||
if searchResultMayReachCardBand(name, reached) {
|
||||
continue
|
||||
}
|
||||
if isPrivacySchema(reached) && reached != "AnonymousCardContent" && reached != "CardCategory" && reached != "CardField" && reached != "CardFieldSet" {
|
||||
t.Errorf("%s reaches the candidate-private schema %s", name, reached)
|
||||
}
|
||||
@@ -320,6 +323,9 @@ func TestAnonymousCardReachesNoProfileOrContactSchema(t *testing.T) {
|
||||
}, reached) {
|
||||
continue
|
||||
}
|
||||
if path == "/api/v1/organizations/{org_id}/matches" && searchResultMayReachCardBand("Match", reached) {
|
||||
continue
|
||||
}
|
||||
if isPrivacySchema(reached) {
|
||||
t.Errorf("%s reaches the candidate-private schema %s", path, reached)
|
||||
}
|
||||
@@ -332,6 +338,18 @@ func TestAnonymousCardReachesNoProfileOrContactSchema(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// searchResultMayReachCardBand reports whether a match search schema reaches
|
||||
// one of the two coarse leaves that the anonymous card itself carries: the
|
||||
// salary compatibility (a compatible or not_compatible verdict, never an
|
||||
// amount) and the experience band (a coarse bucket, never a date). The search
|
||||
// contract reuses the card content, so its filters and results legitimately
|
||||
// name these leaves. Only match schemas get this allowance; no other
|
||||
// organization-visible schema may reach a privacy schema.
|
||||
func searchResultMayReachCardBand(schema, reached string) bool {
|
||||
return strings.HasPrefix(schema, "Match") &&
|
||||
(reached == "CandidateSalaryCompatibility" || reached == "CandidateExperienceBand")
|
||||
}
|
||||
|
||||
// The generated request DTOs carry only what the candidate may choose: no
|
||||
// consent identifier, time, interval, or policy version.
|
||||
func TestGeneratedPrivacyDTOsCarryNoServerOwnedFields(t *testing.T) {
|
||||
|
||||
@@ -36,6 +36,10 @@ var ownerCompanyOperations = map[apiadapter.OperationName]struct{}{
|
||||
apiadapter.GetOrganizationInvitationContactsOperation: {},
|
||||
apiadapter.WithdrawOrganizationInvitationOperation: {},
|
||||
apiadapter.RaiseOrganizationInvitationSalaryOperation: {},
|
||||
// The match search contract requires an active owner membership. The
|
||||
// operation has no handler yet; classifying it here keeps it closed to
|
||||
// every other role when the handler arrives.
|
||||
apiadapter.SearchOrganizationMatchesOperation: {},
|
||||
}
|
||||
|
||||
// NewCompanyContextMiddleware verifies every owner-scoped company operation
|
||||
|
||||
@@ -124,8 +124,8 @@ func TestCompanyContextOperationInventoryMatchesOpenAPI(t *testing.T) {
|
||||
if err := yaml.Unmarshal(data, &document); err != nil {
|
||||
t.Fatalf("decode OpenAPI bundle: %v", err)
|
||||
}
|
||||
if len(ownerCompanyOperations) != 14 {
|
||||
t.Fatalf("owner operation inventory has %d entries, want 14", len(ownerCompanyOperations))
|
||||
if len(ownerCompanyOperations) != 15 {
|
||||
t.Fatalf("owner operation inventory has %d entries, want 15", len(ownerCompanyOperations))
|
||||
}
|
||||
candidateExceptions := map[string]string{
|
||||
"HideOrganization": "/api/v1/me/privacy/hidden-organizations/{org_id}",
|
||||
|
||||
@@ -507,25 +507,40 @@ func assessmentResultResponse(result assessmentusecase.AssessmentAttemptResult)
|
||||
NextSteps: []api.AssessmentNextStep{}, Summary: result.Summary, DecidedAt: api.Timestamp(result.DecidedAt),
|
||||
}), nil
|
||||
}
|
||||
if result.Attempt.Kind != domain.AssessmentAttemptKindRoot && result.Attempt.Kind != domain.AssessmentAttemptKindCorrective {
|
||||
return api.AssessmentResult{}, errors.New("real result kind is invalid")
|
||||
}
|
||||
if result.Attempt.Specialization == nil || result.Attempt.TargetGrade == nil || result.DecidedAt.IsZero() {
|
||||
return api.AssessmentResult{}, errors.New("real result track or decision time is incomplete")
|
||||
}
|
||||
fields, err := assessmentRealResultFields(result)
|
||||
realResult, err := assessmentRealResultResponse(result)
|
||||
if err != nil {
|
||||
return api.AssessmentResult{}, err
|
||||
}
|
||||
if realResult.Type == api.AssessmentQualifiedResultAssessmentRealResult {
|
||||
return api.NewAssessmentQualifiedResultAssessmentResult(realResult.AssessmentQualifiedResult), nil
|
||||
}
|
||||
return api.NewAssessmentCorrectiveResultAssessmentResult(realResult.AssessmentCorrectiveResult), nil
|
||||
}
|
||||
|
||||
// assessmentRealResultResponse maps a completed root or corrective result. It
|
||||
// serves both the single result read and the owner's history, so the two never
|
||||
// describe the same stored result differently.
|
||||
func assessmentRealResultResponse(result assessmentusecase.AssessmentAttemptResult) (api.AssessmentRealResult, error) {
|
||||
if result.Attempt.Kind != domain.AssessmentAttemptKindRoot && result.Attempt.Kind != domain.AssessmentAttemptKindCorrective {
|
||||
return api.AssessmentRealResult{}, errors.New("real result kind is invalid")
|
||||
}
|
||||
if result.Attempt.Specialization == nil || result.Attempt.TargetGrade == nil || result.DecidedAt.IsZero() {
|
||||
return api.AssessmentRealResult{}, errors.New("real result track or decision time is incomplete")
|
||||
}
|
||||
fields, err := assessmentRealResultFields(result)
|
||||
if err != nil {
|
||||
return api.AssessmentRealResult{}, err
|
||||
}
|
||||
if result.Attempt.Kind == domain.AssessmentAttemptKindRoot {
|
||||
return api.NewAssessmentQualifiedResultAssessmentResult(api.AssessmentQualifiedResult{
|
||||
return api.NewAssessmentQualifiedResultAssessmentRealResult(api.AssessmentQualifiedResult{
|
||||
AttemptID: result.Attempt.ID.UUID(), Specialization: api.SpecializationCode(*result.Attempt.Specialization),
|
||||
TargetGrade: api.GradeCode(*result.Attempt.TargetGrade), RootAttemptID: fields.rootAttemptID,
|
||||
ChainDeadline: fields.chainDeadline, TaskLanguage: fields.taskLanguage,
|
||||
Kind: api.AssessmentQualifiedResultKindRoot, Mode: api.AssessmentQualifiedResultMode(result.Attempt.Mode),
|
||||
Versions: assessmentResultVersions(result.Attempt), Outcome: fields.outcome,
|
||||
NotDeterminedReason: fields.reason, ConfirmedGrade: fields.confirmedGrade,
|
||||
PreviousConfirmedGrade: fields.previousGrade, Strength: fields.strength,
|
||||
PreviousConfirmedGrade: fields.previousGrade, CategoryDecision: fields.categoryDecision,
|
||||
Strength: fields.strength,
|
||||
CalibrationStatus: api.CalibrationStatusUncalibrated, Limitations: fields.limitations,
|
||||
Uncertainty: fields.uncertainty, BasicScore: fields.basicScore, Practices: []api.AssessmentPracticeResult{},
|
||||
Gaps: []api.AssessmentGap{}, Durations: api.AssessmentDurations{ItemsSeconds: assessmentItemsSeconds(result), PracticeSeconds: nilInt32()},
|
||||
@@ -533,16 +548,17 @@ func assessmentResultResponse(result assessmentusecase.AssessmentAttemptResult)
|
||||
}), nil
|
||||
}
|
||||
if result.Attempt.RootAttemptID == nil || result.Attempt.ChainDeadline == nil {
|
||||
return api.AssessmentResult{}, errors.New("corrective result chain is incomplete")
|
||||
return api.AssessmentRealResult{}, errors.New("corrective result chain is incomplete")
|
||||
}
|
||||
return api.NewAssessmentCorrectiveResultAssessmentResult(api.AssessmentCorrectiveResult{
|
||||
return api.NewAssessmentCorrectiveResultAssessmentRealResult(api.AssessmentCorrectiveResult{
|
||||
AttemptID: result.Attempt.ID.UUID(), Specialization: api.SpecializationCode(*result.Attempt.Specialization),
|
||||
TargetGrade: api.GradeCode(*result.Attempt.TargetGrade), RootAttemptID: fields.rootAttemptID,
|
||||
ChainDeadline: fields.chainDeadline, TaskLanguage: fields.taskLanguage,
|
||||
Kind: api.AssessmentCorrectiveResultKindCorrective, Mode: api.AssessmentCorrectiveResultMode(result.Attempt.Mode),
|
||||
Versions: assessmentResultVersions(result.Attempt), Outcome: fields.outcome,
|
||||
NotDeterminedReason: fields.reason, ConfirmedGrade: fields.confirmedGrade,
|
||||
PreviousConfirmedGrade: fields.previousGrade, Strength: fields.strength,
|
||||
PreviousConfirmedGrade: fields.previousGrade, CategoryDecision: fields.categoryDecision,
|
||||
Strength: fields.strength,
|
||||
CalibrationStatus: api.CalibrationStatusUncalibrated, Limitations: fields.limitations,
|
||||
Uncertainty: fields.uncertainty, BasicScore: fields.basicScore, Practices: []api.AssessmentPracticeResult{},
|
||||
Gaps: []api.AssessmentGap{}, Durations: api.AssessmentDurations{ItemsSeconds: assessmentItemsSeconds(result), PracticeSeconds: nilInt32()},
|
||||
@@ -558,10 +574,13 @@ type assessmentRealResultResponseFields struct {
|
||||
reason api.NilAssessmentNotDeterminedReason
|
||||
confirmedGrade api.NilGradeCode
|
||||
previousGrade api.NilGradeCode
|
||||
strength api.NilAssessmentStrength
|
||||
limitations []api.AssessmentLimitation
|
||||
uncertainty api.NilAssessmentUncertainty
|
||||
basicScore api.NilBasicScore
|
||||
// categoryDecision is absent for a legacy result stored before category
|
||||
// decisions existed; its grade is never inferred from the current state.
|
||||
categoryDecision api.OptAssessmentCategoryDecisionView
|
||||
strength api.NilAssessmentStrength
|
||||
limitations []api.AssessmentLimitation
|
||||
uncertainty api.NilAssessmentUncertainty
|
||||
basicScore api.NilBasicScore
|
||||
}
|
||||
|
||||
func assessmentRealResultFields(result assessmentusecase.AssessmentAttemptResult) (assessmentRealResultResponseFields, error) {
|
||||
@@ -588,8 +607,7 @@ func assessmentRealResultFields(result assessmentusecase.AssessmentAttemptResult
|
||||
} else {
|
||||
fields.reason.SetTo(api.AssessmentNotDeterminedReason(result.NotDeterminedReason))
|
||||
}
|
||||
fields.confirmedGrade.SetToNull()
|
||||
fields.previousGrade.SetToNull()
|
||||
setAssessmentCategoryFields(&fields, result.CategoryDecision)
|
||||
fields.strength.SetToNull()
|
||||
fields.uncertainty.SetToNull()
|
||||
if result.BasicScore == nil {
|
||||
@@ -605,6 +623,45 @@ func assessmentRealResultFields(result assessmentusecase.AssessmentAttemptResult
|
||||
return fields, nil
|
||||
}
|
||||
|
||||
// setAssessmentCategoryFields copies the stored category decision. A result
|
||||
// confirms its target grade only when a reviewed synthetic source accepted the
|
||||
// outcome (assigned, or unchanged because the grade was not higher); a passing
|
||||
// score without such a source claims no category.
|
||||
func setAssessmentCategoryFields(fields *assessmentRealResultResponseFields, decision *domain.AssessmentCategoryDecisionSnapshot) {
|
||||
fields.confirmedGrade.SetToNull()
|
||||
fields.previousGrade.SetToNull()
|
||||
if decision == nil {
|
||||
return
|
||||
}
|
||||
view := api.AssessmentCategoryDecisionView{Status: api.AssessmentCategoryDecisionViewStatus(decision.Status)}
|
||||
view.PreviousConfirmedGrade.SetToNull()
|
||||
view.CurrentConfirmedGrade.SetToNull()
|
||||
view.Method.SetToNull()
|
||||
view.Source.SetToNull()
|
||||
view.CalibrationStatus.SetToNull()
|
||||
if decision.PreviousGrade != nil {
|
||||
fields.previousGrade.SetTo(api.GradeCode(*decision.PreviousGrade))
|
||||
view.PreviousConfirmedGrade.SetTo(api.GradeCode(*decision.PreviousGrade))
|
||||
}
|
||||
if decision.CurrentGrade != nil {
|
||||
view.CurrentConfirmedGrade.SetTo(api.GradeCode(*decision.CurrentGrade))
|
||||
}
|
||||
if decision.Method != "" {
|
||||
view.Method.SetTo(api.AssessmentCategoryDecisionViewMethod(decision.Method))
|
||||
}
|
||||
if decision.Source != "" {
|
||||
view.Source.SetTo(api.AssessmentCategoryDecisionViewSource(decision.Source))
|
||||
}
|
||||
if decision.CalibrationStatus != "" {
|
||||
view.CalibrationStatus.SetTo(api.CalibrationStatus(decision.CalibrationStatus))
|
||||
}
|
||||
if (decision.Status == domain.AssessmentCategoryDecisionAssigned || decision.Status == domain.AssessmentCategoryDecisionUnchanged) &&
|
||||
decision.AttemptedGrade != nil {
|
||||
fields.confirmedGrade.SetTo(api.GradeCode(*decision.AttemptedGrade))
|
||||
}
|
||||
fields.categoryDecision.SetTo(view)
|
||||
}
|
||||
|
||||
func assessmentResultVersions(snapshot domain.AssessmentAttemptPublicSnapshot) api.AssessmentVersions {
|
||||
return api.AssessmentVersions{
|
||||
PolicyVersion: snapshot.PolicyVersion, BankVersion: api.AssessmentVersionLabel(snapshot.BankVersion),
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
"lincodex/backend/internal/adapter/primary/http/problem"
|
||||
assessmentusecase "lincodex/backend/internal/usecase/assessment"
|
||||
)
|
||||
|
||||
// AssessmentResultOperations reads the candidate's immutable result history.
|
||||
// An employer has no operation here; the current category reaches an employer
|
||||
// only through the anonymous card.
|
||||
type AssessmentResultOperations interface {
|
||||
ListMyResults(ctx context.Context, userID uuid.UUID, cursor string, limit int32) (assessmentusecase.AssessmentResultHistoryPage, error)
|
||||
}
|
||||
|
||||
func (handler *Handler) ListMyAssessmentResults(
|
||||
ctx context.Context,
|
||||
params api.ListMyAssessmentResultsParams,
|
||||
) (api.ListMyAssessmentResultsRes, error) {
|
||||
if handler.assessment == nil {
|
||||
return handler.UnimplementedHandler.ListMyAssessmentResults(ctx, params)
|
||||
}
|
||||
return handler.assessment.ListMyAssessmentResults(ctx, params)
|
||||
}
|
||||
|
||||
// ListMyAssessmentResults serves the owner-only history. The operations of
|
||||
// AssessmentHandler provide it as an optional capability, like GetMyResult.
|
||||
func (handler *AssessmentHandler) ListMyAssessmentResults(
|
||||
ctx context.Context,
|
||||
params api.ListMyAssessmentResultsParams,
|
||||
) (api.ListMyAssessmentResultsRes, error) {
|
||||
const location = "AssessmentHandler.ListMyAssessmentResults"
|
||||
principal, ok := PrincipalFromContext(ctx)
|
||||
if !ok {
|
||||
return (*api.ListMyAssessmentResultsUnauthorized)(&problem.New(ctx, api.ProblemCodeUnauthenticated).Response), nil
|
||||
}
|
||||
operations, ok := handler.operations.(AssessmentResultOperations)
|
||||
if !ok {
|
||||
return nil, errors.New(location + " - result history operation is unavailable")
|
||||
}
|
||||
// The generated validator has already bounded limit to the contract range.
|
||||
page, err := operations.ListMyResults(ctx, principal.UserID, params.Cursor.Or(""), params.Limit.Or(0))
|
||||
if err != nil {
|
||||
return assessmentResultsFailure(ctx, err)
|
||||
}
|
||||
items := make([]api.AssessmentRealResult, 0, len(page.Entries))
|
||||
for _, entry := range page.Entries {
|
||||
item, err := assessmentRealResultResponse(assessmentusecase.AssessmentAttemptResultFromHistoryEntry(entry))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - map stored result: %w", location, err)
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
next := api.NilString{}
|
||||
if page.NextCursor == "" {
|
||||
next.SetToNull()
|
||||
} else {
|
||||
next.SetTo(page.NextCursor)
|
||||
}
|
||||
return &api.AssessmentResultHistoryPageHeaders{
|
||||
CacheControl: api.CacheControlNoStoreNoStore,
|
||||
Response: api.AssessmentResultHistoryPage{Items: items, Page: api.PageInfo{HasMore: page.NextCursor != "", NextCursor: next}},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func assessmentResultsFailure(ctx context.Context, err error) (api.ListMyAssessmentResultsRes, error) {
|
||||
switch {
|
||||
case errors.Is(err, assessmentusecase.ErrInvalidAssessmentResultHistoryRequest):
|
||||
return (*api.ListMyAssessmentResultsBadRequest)(&problem.InvalidField(ctx, api.ProblemFieldLocationQuery, "/cursor").Response), nil
|
||||
case errors.Is(err, assessmentusecase.ErrAttemptForbidden), errors.Is(err, assessmentusecase.ErrAttemptEmailNotVerified):
|
||||
return (*api.ListMyAssessmentResultsForbidden)(&problem.New(ctx, api.ProblemCodeForbidden).Response), nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
func gradePtr(grade domain.GradeCode) *domain.GradeCode { return &grade }
|
||||
|
||||
func TestAssessmentCategoryFieldsClaimAGradeOnlyForAReviewedConfirmation(t *testing.T) {
|
||||
specialization := domain.SpecializationBackend
|
||||
reviewed := func(status domain.AssessmentCategoryDecisionStatus, attempted domain.GradeCode, previous, current *domain.GradeCode) *domain.AssessmentCategoryDecisionSnapshot {
|
||||
return &domain.AssessmentCategoryDecisionSnapshot{
|
||||
AttemptID: domain.AssessmentAttemptID(uuid.New()), Specialization: &specialization, AttemptedGrade: gradePtr(attempted),
|
||||
PreviousGrade: previous, CurrentGrade: current, Status: status,
|
||||
Method: domain.AssessmentCategoryDecisionDemoBasicPassMark, Source: domain.AssessmentCategorySourceSyntheticDemo,
|
||||
CalibrationStatus: domain.AssessmentCategoryCalibrationUncalibrated, DecidedAt: time.Date(2026, 10, 1, 0, 0, 0, 0, time.UTC),
|
||||
}
|
||||
}
|
||||
notEligible := &domain.AssessmentCategoryDecisionSnapshot{
|
||||
AttemptID: domain.AssessmentAttemptID(uuid.New()), Specialization: &specialization, AttemptedGrade: gradePtr(domain.GradeJunior),
|
||||
PreviousGrade: gradePtr(domain.GradeIntern), CurrentGrade: gradePtr(domain.GradeIntern),
|
||||
Status: domain.AssessmentCategoryDecisionNotEligible,
|
||||
}
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
decision *domain.AssessmentCategoryDecisionSnapshot
|
||||
wantConfirmed string
|
||||
wantPrevious string
|
||||
wantView bool
|
||||
}{
|
||||
{name: "legacy result without a decision", decision: nil},
|
||||
{name: "assigned", decision: reviewed(domain.AssessmentCategoryDecisionAssigned, domain.GradeJunior, gradePtr(domain.GradeIntern), gradePtr(domain.GradeJunior)),
|
||||
wantConfirmed: "junior", wantPrevious: "intern", wantView: true},
|
||||
{name: "unchanged", decision: reviewed(domain.AssessmentCategoryDecisionUnchanged, domain.GradeIntern, gradePtr(domain.GradeMiddle), gradePtr(domain.GradeMiddle)),
|
||||
wantConfirmed: "intern", wantPrevious: "middle", wantView: true},
|
||||
{name: "not confirmed keeps the previous grade", decision: reviewed(domain.AssessmentCategoryDecisionNotConfirmed, domain.GradeJunior, gradePtr(domain.GradeIntern), gradePtr(domain.GradeIntern)),
|
||||
wantPrevious: "intern", wantView: true},
|
||||
{name: "not eligible claims no grade", decision: notEligible, wantPrevious: "intern", wantView: true},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var fields assessmentRealResultResponseFields
|
||||
setAssessmentCategoryFields(&fields, test.decision)
|
||||
confirmed, confirmedSet := fields.confirmedGrade.Get()
|
||||
previous, previousSet := fields.previousGrade.Get()
|
||||
if (test.wantConfirmed == "") == confirmedSet || confirmedSet && string(confirmed) != test.wantConfirmed {
|
||||
t.Fatalf("confirmed_grade = %q (set %v), want %q", confirmed, confirmedSet, test.wantConfirmed)
|
||||
}
|
||||
if (test.wantPrevious == "") == previousSet || previousSet && string(previous) != test.wantPrevious {
|
||||
t.Fatalf("previous_confirmed_grade = %q (set %v), want %q", previous, previousSet, test.wantPrevious)
|
||||
}
|
||||
if fields.categoryDecision.IsSet() != test.wantView {
|
||||
t.Fatalf("category_decision present = %v, want %v", fields.categoryDecision.IsSet(), test.wantView)
|
||||
}
|
||||
if view, ok := fields.categoryDecision.Get(); ok && test.decision.Status == domain.AssessmentCategoryDecisionNotEligible {
|
||||
_, hasMethod := view.Method.Get()
|
||||
_, hasSource := view.Source.Get()
|
||||
if hasMethod || hasSource {
|
||||
t.Fatalf("not eligible view names a method or source: %+v", view)
|
||||
}
|
||||
}
|
||||
if view, ok := fields.categoryDecision.Get(); ok && string(view.Status) != string(test.decision.Status) {
|
||||
t.Fatalf("view status = %s, want %s", view.Status, test.decision.Status)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user