Skip to content

Feat/explainable violation metadata - #1156

Open
kanth071 wants to merge 2 commits into
vicharanashala:mainfrom
kanth071:feat/explainable-violation-metadata
Open

kanth071 wants to merge 2 commits into
vicharanashala:mainfrom
kanth071:feat/explainable-violation-metadata

Conversation

@kanth071

Copy link
Copy Markdown

Description

This PR implements the schema, validation, and database plumbing for storing explainable, confidence-weighted violation metadata alongside proctoring anomalies.

Project Philosophy Alignment: "Trust, Not Surveillance"

In alignment with the core project philosophy of "trust, not surveillance," this change replaces opaque black-box proctoring flags with auditable, explainable data structures. Instead of storing raw biometric geometry or using unexplainable signals, every violation record now supports a plain-English reason string, consecutive frame count, signal duration, and signal strength. This ensures instructors can review flagged students fairly and transparently.

Changes Introduced:

  • ViolationMetadata Schema: Created a structured interface on both backend (Anomaly.ts) and frontend (reportanomaly.types.ts) to store:
    • reason (Plain-English explanation of why the anomaly triggered).
    • durationMs (How long the signal was continuously active).
    • consecutiveFrames (Number of frames showing the violation).
    • signalStrength (System confidence score between 0 and 1).
    • detectedAt (ISO timestamp when the signal started).
  • Data Persistence: Added optional metadata field to the IAnomalyData class and constructor logic to save metadata directly into MongoDB records.
  • DTO Validation: Integrated the metadata field in NewAnomalyData with the class-transformer @Transform decorator to correctly parse JSON-encoded form fields sent during multipart webcam/image uploads.
  • Test Coverage: Added integration tests in AnomalyController.test.ts to verify backward compatibility (saving anomalies without metadata) and verify successful round-trip persistence of anomaly metadata.

Related Issues

Closes #

kanth071 added 2 commits July 10, 2026 23:31
…emoryReplSet

- Replace MongoMemoryServer (standalone, no transactions) with
  MongoMemoryReplSet so MongoDB transactions used by CourseService and
  AnomalyService work correctly in the test environment.

- Fix InversifyJS container wiring for tests: use unbind()+bind() instead
  of the removed rebind() chain, and rebind GLOBAL_TYPES.Database so a
  fresh MongoDatabase is constructed with the correct in-memory URI
  (bypassing the hardcoded ssl/tls options).

- Break circular dep: import CourseSetting directly from its transformer
  file instead of the setting barrel index to avoid the
  'CourseSetting is not a constructor' Vite SSR error caused by the
  courses <-> setting circular import chain.

- Fix multipart request format: send NewAnomalyData fields as individual
  form fields (.field('courseId', ...)) rather than a single JSON-encoded
  'data' field that bypassed class-validator.

- Mock CloudStorageService.uploadAnomaly to prevent calls to GCS during
  tests (no credentials in CI).

- Replace bogus error scenario ('Input buffer contains unsupported image
  format') with realistic 400 Bad Request tests: missing required fields
  and an invalid AnomalyType enum value.

- Add afterAll teardown guard: suppress expected MongoDB shutdown-race
  unhandled rejections (MongoClientClosedError, MongoWriteConcernError
  ShutdownInProgress, MongoServerError InterruptedAtShutdown) that the
  driver emits when the in-memory replica set is stopped.
…n metadata

Introduce ViolationMetadata schema and plumbing to store plain-English reasons, duration, consecutive frame counts, and signal strength with violation anomalies. This ensures that instructors reviewing violation logs can easily understand why a violation was flagged without needing to understand raw biometric geometry or detector internals.

This commit respects the 'trust, not surveillance' project philosophy by replacing opaque black-box flagging with structured, auditable, and human-readable metadata explanations.

PR 1:
- Add ViolationMetadata interface to backend Anomaly.ts and frontend reportanomaly.types.ts.
- Add optional metadata field to backend IAnomalyData class (persisted to DB in constructor).
- Add metadata field to NewAnomalyData validator DTO with class-transformer @Transform to parse incoming stringified JSON metadata in multipart requests.
- Add integration tests verifying successful metadata persistence and round-tripping through POST /anomalies/record/image.
@github-actions github-actions Bot added frontend Changes to the frontend of the project backend labels Jul 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend frontend Changes to the frontend of the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant