feat(assessment): record capture hints and keep one window per attempt
This commit is contained in:
1 parent
c975a0d506
commit
bb917bf62e
108 files changed
+6649
-139
No files matched your search
@@ -0,0 +1,145 @@
|
||||
-- +goose Up
|
||||
-- Three additive pieces of the attempt proctoring that needs no camera:
|
||||
--
|
||||
-- 1. The hold of the single active work session of a real attempt. One open
|
||||
-- page at a time holds it; the holder is a keyed digest of an identifier the
|
||||
-- page generated, never the identifier. The row is one per attempt and is
|
||||
-- changed in place under the attempt row lock that the usecase already takes.
|
||||
-- 2. Two weak client signals: a screenshot key and open developer tools. They
|
||||
-- carry no measurement.
|
||||
-- 3. A keyed digest of the User-Agent in the origin marks and three counters in
|
||||
-- the review. The raw User-Agent is never stored.
|
||||
|
||||
CREATE TABLE assessment_attempt_work_leases (
|
||||
attempt_id uuid NOT NULL REFERENCES assessment_attempts (id) ON DELETE CASCADE,
|
||||
holder_digest bytea NOT NULL,
|
||||
key_version smallint NOT NULL,
|
||||
acquired_at timestamptz NOT NULL,
|
||||
renewed_at timestamptz NOT NULL,
|
||||
released_at timestamptz,
|
||||
CONSTRAINT assessment_attempt_work_leases_pkey PRIMARY KEY (attempt_id),
|
||||
CONSTRAINT assessment_attempt_work_leases_holder CHECK (octet_length(holder_digest) = 32),
|
||||
CONSTRAINT assessment_attempt_work_leases_key_version CHECK (key_version > 0),
|
||||
CONSTRAINT assessment_attempt_work_leases_times CHECK (
|
||||
renewed_at >= acquired_at AND (released_at IS NULL OR released_at >= acquired_at)
|
||||
)
|
||||
);
|
||||
|
||||
-- The two new kinds are facts without a measurement, like a fullscreen exit.
|
||||
ALTER TABLE assessment_signal_events
|
||||
DROP CONSTRAINT assessment_signal_events_kind,
|
||||
DROP CONSTRAINT assessment_signal_events_measurement;
|
||||
|
||||
ALTER TABLE assessment_signal_events
|
||||
ADD CONSTRAINT assessment_signal_events_kind CHECK (
|
||||
kind IN ('focus_loss', 'copy', 'paste', 'cut', 'fullscreen_exit', 'screenshot_key', 'devtools_open')
|
||||
),
|
||||
ADD CONSTRAINT assessment_signal_events_measurement CHECK (
|
||||
(kind = 'focus_loss' AND duration_ms IS NOT NULL AND duration_ms BETWEEN 1 AND 259200000 AND size_bytes IS NULL)
|
||||
OR (kind IN ('copy', 'paste', 'cut') AND duration_ms IS NULL AND size_bytes IS NOT NULL AND size_bytes BETWEEN 0 AND 2147483647)
|
||||
OR (kind IN ('fullscreen_exit', 'screenshot_key', 'devtools_open') AND duration_ms IS NULL AND size_bytes IS NULL)
|
||||
);
|
||||
|
||||
-- The mark of a request that holds the work session is written like the marks
|
||||
-- of answers and signal batches, when the session, the network, or the
|
||||
-- User-Agent differs from the last mark.
|
||||
ALTER TABLE assessment_attempt_origin_marks
|
||||
ADD COLUMN agent_digest bytea,
|
||||
DROP CONSTRAINT assessment_attempt_origin_marks_source;
|
||||
|
||||
ALTER TABLE assessment_attempt_origin_marks
|
||||
ADD CONSTRAINT assessment_attempt_origin_marks_source CHECK (source IN ('answer', 'signals', 'work_session')),
|
||||
ADD CONSTRAINT assessment_attempt_origin_marks_agent CHECK (
|
||||
agent_digest IS NULL OR octet_length(agent_digest) = 32
|
||||
);
|
||||
|
||||
ALTER TABLE assessment_attempt_reviews
|
||||
ADD COLUMN extra_agents integer NOT NULL DEFAULT 0,
|
||||
ADD COLUMN client_screenshot_keys integer NOT NULL DEFAULT 0,
|
||||
ADD COLUMN client_devtools_opens integer NOT NULL DEFAULT 0,
|
||||
DROP CONSTRAINT assessment_attempt_reviews_reasons,
|
||||
DROP CONSTRAINT assessment_attempt_reviews_counts;
|
||||
|
||||
ALTER TABLE assessment_attempt_reviews
|
||||
ADD CONSTRAINT assessment_attempt_reviews_reasons CHECK (
|
||||
reasons <@ ARRAY['fast_answers', 'deviating_answers', 'parallel_sessions', 'extra_networks',
|
||||
'extra_agents', 'duplicate_answers', 'client_signals']::text[]
|
||||
),
|
||||
ADD CONSTRAINT assessment_attempt_reviews_counts CHECK (
|
||||
answered_items >= 0 AND fast_answers >= 0 AND deviating_answers >= 0 AND parallel_alternations >= 0
|
||||
AND extra_networks >= 0 AND matched_integer_items >= 0 AND matched_sequence_items >= 0
|
||||
AND duplicate_evidence_bits >= 0 AND client_focus_loss_ms >= 0 AND client_clipboard_events >= 0
|
||||
AND client_fullscreen_exits >= 0 AND extra_agents >= 0 AND client_screenshot_keys >= 0
|
||||
AND client_devtools_opens >= 0
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
-- The new facts are evidence of a manual review. Rolling the schema back must
|
||||
-- not drop them as a side effect: an operator exports or resolves them first.
|
||||
-- +goose StatementBegin
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM assessment_signal_events WHERE kind IN ('screenshot_key', 'devtools_open')
|
||||
) OR EXISTS (
|
||||
SELECT 1 FROM assessment_attempt_origin_marks WHERE source = 'work_session' OR agent_digest IS NOT NULL
|
||||
) OR EXISTS (
|
||||
SELECT 1 FROM assessment_attempt_reviews
|
||||
WHERE extra_agents > 0 OR client_screenshot_keys > 0 OR client_devtools_opens > 0
|
||||
OR 'extra_agents' = ANY (reasons)
|
||||
) THEN
|
||||
RAISE EXCEPTION USING
|
||||
ERRCODE = 'integrity_constraint_violation',
|
||||
CONSTRAINT = 'assessment_capture_signals_retained',
|
||||
MESSAGE = 'capture signal facts must be retained before rollback';
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
-- +goose StatementEnd
|
||||
|
||||
ALTER TABLE assessment_attempt_reviews
|
||||
DROP CONSTRAINT assessment_attempt_reviews_reasons,
|
||||
DROP CONSTRAINT assessment_attempt_reviews_counts;
|
||||
|
||||
ALTER TABLE assessment_attempt_reviews
|
||||
DROP COLUMN extra_agents,
|
||||
DROP COLUMN client_screenshot_keys,
|
||||
DROP COLUMN client_devtools_opens;
|
||||
|
||||
ALTER TABLE assessment_attempt_reviews
|
||||
ADD CONSTRAINT assessment_attempt_reviews_reasons CHECK (
|
||||
reasons <@ ARRAY['fast_answers', 'deviating_answers', 'parallel_sessions', 'extra_networks',
|
||||
'duplicate_answers', 'client_signals']::text[]
|
||||
),
|
||||
ADD CONSTRAINT assessment_attempt_reviews_counts CHECK (
|
||||
answered_items >= 0 AND fast_answers >= 0 AND deviating_answers >= 0 AND parallel_alternations >= 0
|
||||
AND extra_networks >= 0 AND matched_integer_items >= 0 AND matched_sequence_items >= 0
|
||||
AND duplicate_evidence_bits >= 0 AND client_focus_loss_ms >= 0 AND client_clipboard_events >= 0
|
||||
AND client_fullscreen_exits >= 0
|
||||
);
|
||||
|
||||
ALTER TABLE assessment_attempt_origin_marks
|
||||
DROP CONSTRAINT assessment_attempt_origin_marks_agent,
|
||||
DROP CONSTRAINT assessment_attempt_origin_marks_source;
|
||||
|
||||
ALTER TABLE assessment_attempt_origin_marks
|
||||
DROP COLUMN agent_digest;
|
||||
|
||||
ALTER TABLE assessment_attempt_origin_marks
|
||||
ADD CONSTRAINT assessment_attempt_origin_marks_source CHECK (source IN ('answer', 'signals'));
|
||||
|
||||
ALTER TABLE assessment_signal_events
|
||||
DROP CONSTRAINT assessment_signal_events_kind,
|
||||
DROP CONSTRAINT assessment_signal_events_measurement;
|
||||
|
||||
ALTER TABLE assessment_signal_events
|
||||
ADD CONSTRAINT assessment_signal_events_kind CHECK (
|
||||
kind IN ('focus_loss', 'copy', 'paste', 'cut', 'fullscreen_exit')
|
||||
),
|
||||
ADD CONSTRAINT assessment_signal_events_measurement CHECK (
|
||||
(kind = 'focus_loss' AND duration_ms IS NOT NULL AND duration_ms BETWEEN 1 AND 259200000 AND size_bytes IS NULL)
|
||||
OR (kind IN ('copy', 'paste', 'cut') AND duration_ms IS NULL AND size_bytes IS NOT NULL AND size_bytes BETWEEN 0 AND 2147483647)
|
||||
OR (kind = 'fullscreen_exit' AND duration_ms IS NULL AND size_bytes IS NULL)
|
||||
);
|
||||
|
||||
DROP TABLE assessment_attempt_work_leases;
|
||||
Reference in new issue
Block a user