feat(api): add support case and manual assessment request contract

This commit is contained in:
shira committed 2026-10-06 10:57:36 +03:00
1 parent 2db585fbff
commit ad4bb94426
65 files changed
+14629 -23

No files matched your search

@@ -74,6 +74,97 @@ type Handler interface {
//
// POST /api/v1/me/assessment-attempts
CreateMyAssessmentAttempt(ctx context.Context, req *AssessmentAttemptCreate, params CreateMyAssessmentAttemptParams) (CreateMyAssessmentAttemptRes, error)
// CreateMySupportCase implements CreateMySupportCase operation.
//
// Requires the session cookie, the CSRF token of that session in X-CSRF-Token, an allowed Origin, and
// an Idempotency-Key. The author is the account of the session; the body has no user, account, or
// organization field. A case is reachable from any screen, including a screen that denies access to an
// assessment: being refused an action never removes the path to a case about it.
//
// The client sends only what the user states: `type`, a non-blank `description`, and the fields of the
// type. It never sets the status, the decision, the outcome, the priority, the response target, the
// rubric, the assignee, or the moderator: every variant has `additionalProperties: false`, so such
// fields answer 400. Attachments are not part of the MVP; they are planned as an optional field and
// change no existing one.
//
// Types, accounts, and allowed references:
//
// Type | Accounts | Object reference | Other fields
// --------------------+---------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------
// `support` | candidate, employer | optional; `assessment_attempt` of the caller, an `organization` that the caller can see, an `invitation` addressed to the caller, or another `support_case` of the caller | optional `assessment_target`
// `complaint` | candidate | required; an `organization` that the caller can see or an `invitation` addressed to the caller | required `complaint_reason`; `offer_content` and `salary_terms_violation` require an invitation
// `grade_appeal` | candidate | required; `assessment_attempt` of the caller in a terminal state, so it has a result, or a `support_case` of the caller of type `manual_assessment` that is `resolved` with the outcome `assessed`, for a category that an expert assigned without an attempt | none
// `anticheat_appeal` | candidate | required; `assessment_attempt` of the caller with an anti-cheat review decision | none
// `manual_assessment` | candidate | optional; a prior `assessment_attempt` of the caller in the same specialization | required `assessment_target`
//
// An organization is visible to a candidate when it sent the candidate an invitation or when the
// organization contract (TASK-077) shows the candidate its profile, and to an employer account when
// the account has an active membership in it. Invitations are not in the contract yet, so until they
// are, every `invitation` reference answers 404 not_found; anti-cheat review decisions are not either,
// so until TASK-173 every anti-cheat appeal answers 409 state_conflict. The schema rejects an object
// type that the case type does not accept, for example an organization in a grade appeal.
//
// Ownership of the reference: the server checks the object against the session account on every
// create. An unknown object and an object of someone else, such as another candidate's attempt,
// another account's case, or an invitation addressed to another person, both answer 404 not_found, so
// a reference never reveals whether a foreign object exists. An own case that a grade appeal cannot
// dispute, because it is not a manual assessment, is not resolved yet, or was resolved with another
// outcome, answers 409 state_conflict. An identifier that is not a UUID fails validation with the
// whole-body pointer, because the decoder does not record the path inside the selected variant. The
// case stores only the type and the identifier of the object.
//
// Limits: an attempt and a resolved manual assessment each accept at most one grade appeal, and an
// attempt at most one anti-cheat appeal, in any status; a disagreement with the decision goes into a
// support case that references the appeal as `support_case`. A specialization accepts one open manual
// assessment, and an object accepts one open complaint; open means not `resolved` or `closed`. A
// second one answers 409 state_conflict. A grade appeal of an attempt that is still active also
// answers 409. Every create that passed authentication, validation, and the account scenario counts
// against a per-account limit from the product policy, including replays, 404, and 409, so the limit
// also bounds probing of references; over the limit the server answers 429 with Retry-After and
// creates nothing.
//
// Description check: the schema pattern `\S` uses the ECMAScript white space set in both generated
// validators (ogen converts it for Go), so a description of spaces such as U+00A0 or U+3000 already
// fails validation with the pointer `/description`. ECMAScript white space omits U+0085 (NEL), which
// Go `unicode.IsSpace` includes, so the server also applies a domain check: a description whose every
// character is `unicode.IsSpace` or U+FEFF answers 400 validation_failed with the pointer
// `/description`. This check comes with the implementation; generated Zod accepts a description of
// NEL, and the server stays authoritative.
//
// The new case gets a number and the status `submitted`. A grade appeal, an anti-cheat appeal, and a
// manual assessment are moved to `waiting_expert` by a `system` event in the same transaction, so the
// 201 already shows that status with both events; a support case and a complaint stay `submitted`.
// Each case gets a response target from the product policy version and the configured business
// calendar: 5 business days for a manual assessment and 10 for an appeal (PRD FR18 and C3), and a
// policy value for support and complaints. The target is an operational goal, not a deadline set by
// law. A manual assessment fixes the published rubric version of the category, or null when the
// category has none yet; the expert assesses with the same rubric as the automated assessment, and the
// request assigns no category by itself. Creating a case never grants, revokes, or changes a consent,
// a grade, or an attempt.
//
// Replies: the case itself is the channel. Support replies and decisions appear in the public
// `history` and `decision`. The server may also notify the verified email address of the account that
// the case changed, with the case number and a link, never with the description, the reply, or
// assessment details. No request field names another address or contact, so the operation cannot send
// mail to an address that the user typed.
//
// Idempotency: a retry with the same key and body within 24 hours replays the stored 201 with the same
// number and creates nothing, so a lost response never opens a second case. The replay is the snapshot
// stored at creation, following the repository convention; the client reads the current status and
// history with GetMySupportCase. 404 and 409 state_conflict are stored and replayed as well. A
// different body with the same key answers 422 idempotency_key_reused. 400, 403, and 429 are never
// stored.
//
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
// account scenario (403 forbidden for an employer account with a type other than `support`), the
// per-account case limit (429), the Idempotency-Key (422, 409 idempotency_in_progress, replay), domain
// rules (400 with the pointer `/description` for a text of only Unicode spaces or `/object/type` for a
// complaint reason that requires an invitation), the object reference (404 not_found), then the state
// of the object and the limits (409 state_conflict). The general rate limit can answer 429 with
// Retry-After before any check.
//
// POST /api/v1/me/support-cases
CreateMySupportCase(ctx context.Context, req SupportCaseCreate, params CreateMySupportCaseParams) (CreateMySupportCaseRes, error)
// CreateOrganizationNeed implements CreateOrganizationNeed operation.
//
// Requires the session cookie of an employer account with an active membership in `org_id`, the CSRF
@@ -287,6 +378,28 @@ type Handler interface {
//
// GET /api/v1/me/questionnaire
GetMyQuestionnaire(ctx context.Context) (GetMyQuestionnaireRes, error)
// GetMySupportCase implements GetMySupportCase operation.
//
// Requires the session cookie of a candidate or an employer account. Returns the case with its number,
// type, object reference, status, response target, decision, and public history. The owner reads the
// case whatever happened to the object since then: a revoked access, a closed invitation, or a refused
// test never hides the case from its author.
//
// The case never contains the identity of a moderator, an expert, or a support agent, internal notes,
// evidence, assessment answers, anti-cheat or risk signals, or contact data of another person.
// `decision` is null until the case is `resolved`.
//
// The history lists every public event and is never truncated: the server keeps a case within 200
// events by rejecting a staff event that would leave no room for the terminal one.
//
// The case must belong to the account of the session: a case of another account, including another
// member of the same organization, answers 404 not_found, the same as an unknown identifier, so
// identifiers cannot be probed. TASK-314 says forbidden for a foreign case URL; the contract answers
// 404 instead, so the client shows the same "not found" state for a foreign and an unknown case. A
// malformed `case_id` answers 400 validation_failed with the path pointer.
//
// GET /api/v1/me/support-cases/{case_id}
GetMySupportCase(ctx context.Context, params GetMySupportCaseParams) (GetMySupportCaseRes, error)
// GetOrganizationNeed implements GetOrganizationNeed operation.
//
// Requires the session cookie of an employer account with an active membership in `org_id`. The
@@ -338,6 +451,21 @@ type Handler interface {
//
// GET /api/v1/specializations
GetSpecializationCatalog(ctx context.Context) (*SpecializationCatalog, error)
// ListMySupportCases implements ListMySupportCases operation.
//
// Requires the session cookie of a candidate or an employer account. Returns a page of the cases that
// this account created, newest first by creation time with the identifier as the tie-breaker, with
// cursor pagination. Each item is a summary with the number, type, status, object reference, category,
// response target, and decision outcome; it has no description and no history, which GetMySupportCase
// returns with the full case. Cases of other accounts are never listed, including cases of other
// members of the same organization.
//
// Access: a missing, unknown, expired, or revoked session answers 401 unauthenticated. A malformed
// `limit` or `cursor` answers 400 validation_failed. Filters by status and type are planned and add
// optional parameters.
//
// GET /api/v1/me/support-cases
ListMySupportCases(ctx context.Context, params ListMySupportCasesParams) (ListMySupportCasesRes, error)
// ListOrganizationNeeds implements ListOrganizationNeeds operation.
//
// Requires the session cookie of an employer account with an active membership in `org_id`. The