fix(assessment): return confirmed categories with their basis and label demonstration categories
This commit is contained in:
1 parent
623d41b969
commit
d4903a3796
77 files changed
+1441
-288
No files matched your search
@@ -339,6 +339,29 @@ func (repository assessmentAttemptRepository) GetCandidateCategory(
|
||||
return category, true, nil
|
||||
}
|
||||
|
||||
func (repository assessmentAttemptRepository) ListCandidateCategories(
|
||||
ctx context.Context,
|
||||
candidateID uuid.UUID,
|
||||
) ([]domain.CandidateAssessmentCategory, error) {
|
||||
const location = "assessmentAttemptRepository.ListCandidateCategories"
|
||||
if candidateID == uuid.Nil {
|
||||
return nil, fmt.Errorf("%s - candidate scope is invalid: %w", location, domain.ErrInvalidAssessmentCategory)
|
||||
}
|
||||
rows, err := repository.queries.ListCandidateAssessmentCategories(ctx, pgUUID(candidateID))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - select current categories: %w", location, mapAssessmentAttemptError(err))
|
||||
}
|
||||
categories := make([]domain.CandidateAssessmentCategory, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
category, err := restoreCandidateAssessmentCategory(row)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s - stored category is invalid: %w", location, err)
|
||||
}
|
||||
categories = append(categories, category)
|
||||
}
|
||||
return categories, nil
|
||||
}
|
||||
|
||||
func restoreCandidateAssessmentCategory(row sqlc.CandidateAssessmentCategory) (domain.CandidateAssessmentCategory, error) {
|
||||
manifestHash, err := assessmentManifestHash(row.OpeningManifestSha256)
|
||||
if err != nil || !row.CandidateID.Valid || !row.SourceAttemptID.Valid || !row.SourceReviewID.Valid ||
|
||||
|
||||
@@ -154,16 +154,18 @@ func newPrivacyCohortCandidate(
|
||||
const privacyCohortCategoryStrength = domain.CandidateViewStrengthStandard
|
||||
|
||||
// privacyCohortConfirmedCategories reads the current categories selected by
|
||||
// the cohort query: only a specialization and a grade of each, never the
|
||||
// attempt, score, policy, or review that produced it.
|
||||
// the cohort query: a specialization, a grade, and the basis of each, never the
|
||||
// attempt, score, policy, or review that produced it. A category without a
|
||||
// known basis is rejected rather than shown as a real confirmation.
|
||||
func privacyCohortConfirmedCategories(value any) ([]domain.CandidateViewConfirmedCategoryInput, error) {
|
||||
encoded, err := privacyCohortEncodedJSONBytes(value)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid confirmed categories: %w", domain.ErrInvalidCandidateViewSource)
|
||||
}
|
||||
var stored []struct {
|
||||
Specialization domain.SpecializationCode `json:"specialization"`
|
||||
Grade domain.GradeCode `json:"grade"`
|
||||
Specialization domain.SpecializationCode `json:"specialization"`
|
||||
Grade domain.GradeCode `json:"grade"`
|
||||
Source domain.AssessmentCategorySource `json:"source"`
|
||||
}
|
||||
decoder := json.NewDecoder(bytes.NewReader(encoded))
|
||||
decoder.DisallowUnknownFields()
|
||||
@@ -172,8 +174,12 @@ func privacyCohortConfirmedCategories(value any) ([]domain.CandidateViewConfirme
|
||||
}
|
||||
categories := make([]domain.CandidateViewConfirmedCategoryInput, 0, len(stored))
|
||||
for _, category := range stored {
|
||||
if !category.Source.IsKnown() {
|
||||
return nil, fmt.Errorf("confirmed category has an unknown basis: %w", domain.ErrInvalidCandidateViewSource)
|
||||
}
|
||||
categories = append(categories, domain.CandidateViewConfirmedCategoryInput{
|
||||
Specialization: category.Specialization, Grade: category.Grade, Strength: privacyCohortCategoryStrength,
|
||||
Specialization: category.Specialization, Grade: category.Grade,
|
||||
Strength: privacyCohortCategoryStrength, Basis: category.Source,
|
||||
})
|
||||
}
|
||||
return categories, nil
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
func TestPrivacyCohortConfirmedCategoriesCarryTheStoredBasis(t *testing.T) {
|
||||
categories, err := privacyCohortConfirmedCategories(`[{"specialization":"backend","grade":"junior","source":"synthetic_demo"}]`)
|
||||
if err != nil {
|
||||
t.Fatalf("privacyCohortConfirmedCategories() error = %v", err)
|
||||
}
|
||||
if len(categories) != 1 || categories[0].Specialization != domain.SpecializationBackend ||
|
||||
categories[0].Grade != domain.GradeJunior || categories[0].Basis != domain.AssessmentCategorySourceSyntheticDemo {
|
||||
t.Fatalf("categories = %+v, want the backend junior category with its synthetic basis", categories)
|
||||
}
|
||||
}
|
||||
|
||||
// A category whose basis is missing or unknown must not reach a card as if it
|
||||
// were a real confirmation, so the projection fails instead of guessing.
|
||||
func TestPrivacyCohortConfirmedCategoriesRejectAnUnknownBasis(t *testing.T) {
|
||||
for name, value := range map[string]string{
|
||||
"missing basis": `[{"specialization":"backend","grade":"junior"}]`,
|
||||
"unknown basis": `[{"specialization":"backend","grade":"junior","source":"real"}]`,
|
||||
"unknown property": `[{"specialization":"backend","grade":"junior","source":"synthetic_demo","score":9}]`,
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if _, err := privacyCohortConfirmedCategories(value); !errors.Is(err, domain.ErrInvalidCandidateViewSource) {
|
||||
t.Fatalf("privacyCohortConfirmedCategories() error = %v, want invalid candidate view source", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -244,6 +244,49 @@ func (q *Queries) InsertSyntheticCategoryReview(ctx context.Context, arg InsertS
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const listCandidateAssessmentCategories = `-- name: ListCandidateAssessmentCategories :many
|
||||
SELECT candidate_id, specialization, grade, source_attempt_id, source_review_id,
|
||||
product_policy_version_id, product_policy_version, grading_policy_version_id,
|
||||
opening_id, opening_manifest_sha256, source, calibration_status, assigned_at
|
||||
FROM candidate_assessment_categories
|
||||
WHERE candidate_id = $1
|
||||
ORDER BY specialization
|
||||
`
|
||||
|
||||
func (q *Queries) ListCandidateAssessmentCategories(ctx context.Context, candidateID pgtype.UUID) ([]CandidateAssessmentCategory, error) {
|
||||
rows, err := q.db.Query(ctx, listCandidateAssessmentCategories, candidateID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []CandidateAssessmentCategory
|
||||
for rows.Next() {
|
||||
var i CandidateAssessmentCategory
|
||||
if err := rows.Scan(
|
||||
&i.CandidateID,
|
||||
&i.Specialization,
|
||||
&i.Grade,
|
||||
&i.SourceAttemptID,
|
||||
&i.SourceReviewID,
|
||||
&i.ProductPolicyVersionID,
|
||||
&i.ProductPolicyVersion,
|
||||
&i.GradingPolicyVersionID,
|
||||
&i.OpeningID,
|
||||
&i.OpeningManifestSha256,
|
||||
&i.Source,
|
||||
&i.CalibrationStatus,
|
||||
&i.AssignedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listCandidateAssessmentResults = `-- name: ListCandidateAssessmentResults :many
|
||||
SELECT attempt_id, user_id, schema_version, result_snapshot::text,
|
||||
COALESCE(category_decision::text, '')::text AS category_decision, current_confirmed_grade, decided_at
|
||||
|
||||
@@ -57,7 +57,11 @@ SELECT
|
||||
COALESCE(
|
||||
(
|
||||
SELECT jsonb_agg(
|
||||
jsonb_build_object('specialization', category.specialization, 'grade', category.grade)
|
||||
jsonb_build_object(
|
||||
'specialization', category.specialization,
|
||||
'grade', category.grade,
|
||||
'source', category.source
|
||||
)
|
||||
ORDER BY category.specialization
|
||||
)::text
|
||||
FROM candidate_assessment_categories AS category
|
||||
@@ -286,7 +290,11 @@ SELECT
|
||||
COALESCE(
|
||||
(
|
||||
SELECT jsonb_agg(
|
||||
jsonb_build_object('specialization', category.specialization, 'grade', category.grade)
|
||||
jsonb_build_object(
|
||||
'specialization', category.specialization,
|
||||
'grade', category.grade,
|
||||
'source', category.source
|
||||
)
|
||||
ORDER BY category.specialization
|
||||
)::text
|
||||
FROM candidate_assessment_categories AS category
|
||||
|
||||
@@ -656,6 +656,7 @@ type Querier interface {
|
||||
ListAssessmentOriginMarks(ctx context.Context, attemptID pgtype.UUID) ([]AssessmentAttemptOriginMark, error)
|
||||
// Reads the exact family membership pinned by a training binding.
|
||||
ListAssessmentTrainingBindingFamilies(ctx context.Context, bindingID pgtype.UUID) ([]ListAssessmentTrainingBindingFamiliesRow, error)
|
||||
ListCandidateAssessmentCategories(ctx context.Context, candidateID pgtype.UUID) ([]CandidateAssessmentCategory, error)
|
||||
// The caller validates and signs an opaque owner-bound cursor. This query
|
||||
// applies the keyset to the same stable order and fetches one extra row.
|
||||
ListCandidateAssessmentResults(ctx context.Context, arg ListCandidateAssessmentResultsParams) ([]ListCandidateAssessmentResultsRow, error)
|
||||
|
||||
Reference in new issue
Block a user