feat(assessment): record capture hints and keep one window per attempt

This commit is contained in:
shira committed 2026-10-11 13:16:52 +03:00
1 parent c975a0d506
commit bb917bf62e
108 files changed
+6649 -139

No files matched your search

+15
View File
@@ -710,6 +710,21 @@ Implemented for real attempts (root and corrective). A training run (`demo_expre
- Accessibility. Some speech synthesizers and braille displays may announce zero-width characters or break a word at them; this was not tested with a real screen reader. The page therefore puts every run of invisible characters in an `aria-hidden` element: the accessibility tree holds the words only (a Playwright check reads the tree with `ariaSnapshot`, and a Vitest check strips the hidden elements from the markup), while the document keeps the characters so that anything copied from it carries the mark. The wordings are ordinary words, and no whitespace variants are used, because a non-breaking space is not guaranteed to be silent everywhere.
- What it does not do. A screenshot, a photo of the screen, or retyping cannot be prevented in a browser. The watermark is evidence for a manual review and an appeal, never an automatic decision; no operation shows it to an employer, and the candidate sees only the code of their own attempt.
### Capture hints, one open window, and what they cannot do
Implemented for real attempts (root and corrective). A training run (`demo_express`) has none of it. Hardened proctoring here has no camera, no microphone, no screen recording, no screenshots, and no clipboard contents; it consists of weak signals for a manual review and one rule about open windows. Code: `backend/internal/domain/assessment_signal.go`, `assessment_signal_review.go`, `assessment_signal_policy.go`, and `assessment_work_lease.go`; `backend/internal/usecase/assessment/work_session.go` and the observer in `signal_review.go`; migration `backend/db/migrations/00050_add_assessment_work_leases_and_capture_signals.sql`; the operations `HoldMyAssessmentWorkSession` and `ReleaseMyAssessmentWorkSession`; and `frontend/src/features/assessment-signals/` and `frontend/src/features/assessment-work-session/`.
- A screenshot or a phone photo cannot be prevented. A browser page cannot block the operating system or another program from capturing the screen, cannot see a camera, and cannot see a second device, a remote desktop, or a virtual machine. The page therefore never tries: it does not cancel a key, does not blank the page on a key, and does not read any image. What it can do is report that a screenshot key was pressed, tie a leaked statement or screenshot back to its attempt (see [Watermark of the task text](#watermark-of-the-task-text)), and send both to a manual review.
- Signals lead to a review and an appeal, never to an automatic downgrade. The signals only raise the review band, which changes no result, category, or quota; the employer never sees a signal or a band, and the candidate sees no band. Notice version 4 says all of this plainly.
- Screenshot keys. The page reports `screenshot_key` when it sees PrintScreen (also with Alt), Cmd+Shift+3, 4, or 5 (macOS), or Win+Shift+S, on the key press or release, once per second at most. The operating system takes many of these keys before the page, a key-less screenshot sends nothing, and holding a key is not told from pressing it, so the event proves only that a key was pressed. It carries the item and a client timestamp and no measurement.
- Developer tools. The page reports `devtools_open` when the outer window becomes more than 160 px larger than the page in width or height, which is what a docked panel does, on a resize and on a two-second timer, at most once per minute. It is a heuristic with false positives (a sidebar, zoom, a resized window) and false negatives (a detached panel, other windows), so it too is only a weak hint.
- Policy and band. Both kinds are stored as events (the check constraints of `assessment_signal_events` allow them without a measurement) and counted per attempt (`client_screenshot_keys`, `client_devtools_opens` in `assessment_attempt_reviews`). Thresholds are optional fields of the policy section `assessment.signals`: `client_screenshot_keys_attention` and `client_devtools_attention` are client thresholds, so they raise a normal band to attention and never above it, and `extra_agents_attention` with `extra_agents_review` joins the weak group of parallel sessions and extra networks, which alone reaches attention at most and review only beside a strong signal. A zero or absent threshold leaves the signal out, so a version published before these fields keeps its band, its document, and its content hash (a test checks that its document does not contain the new keys and re-encodes unchanged). The demo policies are not edited; `DemoAssessmentSignalPolicyWithCaptureHints` in `assessment_signal_policy.go` lists agreed starting values (three screenshot keys, one detection, two extra User-Agents), which no study supports, and the integration test publishes them in its own policy version.
- User-Agent digest. The HTTP boundary cuts the User-Agent to 512 bytes and hands it to the usecase, which stores only `HMAC-SHA-256` of it under a key derived from `IDENTITY_KEY_SECRET` (label `lincodex/assessment/signal-agent/v1`) bound to the attempt, in the new column `agent_digest` of `assessment_attempt_origin_marks`. The raw value is never stored or logged. A mark is written when the session, the network, or the User-Agent differs from the last mark, so the list stays short; `extra_agents` counts the distinct digests beyond the first. A browser that updates itself during an attempt, or a candidate who moves to another device, adds one, so it is a weak signal.
- One open window. `assessment_attempt_work_leases` holds one row per real attempt: a keyed digest of an identifier that each open page generates when it loads (`X-Attempt-Client`, 16 to 64 characters of `A-Za-z0-9_-`), when it took the session, when it last renewed it, and when it released it. `PUT .../work-session` holds or renews the session for 120 seconds (`domain.AssessmentWorkLeaseDuration`) and tells the page to renew every 15 seconds; `DELETE .../work-session` releases it and answers 204 whatever it did. The page holds the session before it starts or resumes work, renews it while it works, releases it when it leaves or closes (`pagehide`), and stops with an explanation if a renewal is refused. While another page holds the session, the session start and the answer of any other page, or of a request without the header (one anonymous page), answer 409 `state_conflict` and change nothing; the check runs under the attempt row lock after the database time is read, before any attempt change, and the refusal is not stored under the idempotency key, so the holder can reuse the key. An attempt that nobody holds, a released hold, and a hold that stopped renewing (after at most two minutes) admit every page, and `StartSession` and `SubmitAnswer` of a service built without work sessions are unchanged.
- How it relates to `MaxSessions` and `IdleTimeoutSeconds`. Those attempt policy limits describe the sequential work sessions of an attempt: a new one starts only after the idle timeout, and the count is bounded. The hold is the concurrency dimension inside the current work session. It starts, extends, and consumes no work session of that policy, does not change the attempt version, and is not stored in the attempt row.
- Limits of the rule. It is a one-page-at-a-time rule, not a security boundary: a client that never holds the session is refused only while another page holds it, a candidate can always continue after the hold is released or has expired, and two windows of one candidate are not told from two people. The hold is renewed by a page timer, so a browser that throttles a background tab to one tick a minute still renews within the two minutes.
- Operator reading. `make -C backend assessment-review ARGS='inspect ...'` prints the new counts `extra_agents`, `client_screenshot_keys`, and `client_devtools_opens` next to the old ones; the note at its end repeats that browser signals can be forged and that a screenshot or a phone photo cannot be prevented or seen by the page.
### Skill evidence
Implemented as a stored projection of the immutable assessment results, with two reads: the candidate's own list and the permitted projection of a currently visible card. The match search reads the organization projection (see [Matching and explanations](#matching-and-explanations)); no percentile reads it yet.